feat(metering): a plan can allow no extra targets (entry plan) #1079

Merged
sharang merged 2 commits from feat/entry-plan-target-limit into main 2026-11-28 22:09:20 +00:00
Owner

The entry plan ("einstieg") refuses targets beyond its included ones. This PR is the Prüfwerk side. The registry side (pruefwerkLimits sends the key for the entry plan only) is in tenant-registry. The go-ahead reached this session through the platform session, so the merge waits for Sharang's own OK. That OK covers both commits; answers a–d came the same way.

Contract

  • limits.extra_targets: a non-negative integer. It says how many targets beyond included_targets may be active at once, and the entry plan sends 0. It applies only when included_targets is also set; the cap is included_targets + extra_targets.
  • When the key is missing or null, behaviour is as today: extra targets are allowed and billed.
  • Refusal: 409 {"error": "target_limit"}. The dashboard shows "Ihr Tarif enthält keine weiteren Prüfobjekte. Archivieren Sie ein Prüfobjekt, um ein neues anzulegen, oder wechseln Sie den Tarif." (EN alike).
  • Counted: all active (not archived) targets except demo targets. Archiving one frees its place.
  • Billing (second commit, Sharang's answer a): when extra_targets is 0, no target is ever billed as extra. Every active target is billed as included, including targets already beyond the included ones when a workspace moves to the entry plan. So there is no extra-target line and no counted change scans on them. A swap on such a plan is refused as unlimited.
  • Demo targets (second commit, Sharang's answer b): the seeder marks its targets demo: true. The cap neither counts nor refuses them.

Every way of adding a target

  • Onboarding wizard / POST /api/v1/targets: 409, and the wizard shows the text.
  • Accepting a supplier's SBOM release as a new component: 409 target_limit, the offer stays open, and the offers page shows the text.
  • Managed Git: the repository gets no target; a sync logs it at info and tries again next time, and a webhook delivery is ignored with the reason.
  • Demo seed: never refused (see above).

All of them go through targets::create_target, which reads the plan once for the cap and the billing. Before this PR, the API and offers path did not assign billing at creation; it now does, like the others.

Not covered

  • A workspace already over the cap keeps its targets; only new ones are refused (they are billed as included, see above).
  • If the registry does not answer, the target is added (fail-open), as scans then run unmetered (Sharang: keep).
  • Managed Git un-archiving a returning repository is not refused. Two adds at the same moment can both pass (count, then insert). Sharang: accept.
  • Demo targets seeded before this PR have no mark and count as before.
  • Open for Sharang: a demo target can still be renamed and repointed at other artifacts (PUT /api/v1/targets/{id}). Because the seeder matches by name, a renamed one can then be seeded again. That lets a workspace hold targets outside the cap. This PR does not close the gap.
  • No UI change beyond the refusal text: the "Neues Prüfobjekt" button is not disabled up front; that would need a mockup.

Tests: tests/target_limit.rs (fake registry, live Mongo): the entry plan refuses the third target, archiving frees a place, and a plan without the key adds an extra target. It also checks that targets already beyond the entry plan are never billed extra, and that demo targets are neither counted nor refused. Unit tests cover the key, the cap and the billing rule. Agent and core 1656 pass (live Mongo, nothing skipped), and dashboard 235 pass; clippy is clean (agent, dashboard server and web); fmt is clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9

The entry plan ("einstieg") refuses targets beyond its included ones. This PR is the Prüfwerk side. The registry side (`pruefwerkLimits` sends the key for the entry plan only) is in tenant-registry. The go-ahead reached this session through the platform session, so the merge waits for Sharang's own OK. That OK covers both commits; answers a–d came the same way. **Contract** - `limits.extra_targets`: a non-negative integer. It says how many targets beyond `included_targets` may be active at once, and the entry plan sends `0`. It applies only when `included_targets` is also set; the cap is `included_targets + extra_targets`. - When the key is missing or null, behaviour is as today: extra targets are allowed and billed. - Refusal: `409 {"error": "target_limit"}`. The dashboard shows "Ihr Tarif enthält keine weiteren Prüfobjekte. Archivieren Sie ein Prüfobjekt, um ein neues anzulegen, oder wechseln Sie den Tarif." (EN alike). - Counted: all active (not archived) targets except demo targets. Archiving one frees its place. - Billing (second commit, Sharang's answer a): when `extra_targets` is `0`, no target is ever billed as extra. Every active target is billed as included, including targets already beyond the included ones when a workspace moves to the entry plan. So there is no extra-target line and no counted change scans on them. A swap on such a plan is refused as `unlimited`. - Demo targets (second commit, Sharang's answer b): the seeder marks its targets `demo: true`. The cap neither counts nor refuses them. **Every way of adding a target** - Onboarding wizard / `POST /api/v1/targets`: 409, and the wizard shows the text. - Accepting a supplier's SBOM release as a new component: 409 `target_limit`, the offer stays open, and the offers page shows the text. - Managed Git: the repository gets no target; a sync logs it at info and tries again next time, and a webhook delivery is ignored with the reason. - Demo seed: never refused (see above). All of them go through `targets::create_target`, which reads the plan once for the cap and the billing. Before this PR, the API and offers path did not assign billing at creation; it now does, like the others. **Not covered** - A workspace already over the cap keeps its targets; only new ones are refused (they are billed as included, see above). - If the registry does not answer, the target is added (fail-open), as scans then run unmetered (Sharang: keep). - Managed Git un-archiving a returning repository is not refused. Two adds at the same moment can both pass (count, then insert). Sharang: accept. - Demo targets seeded before this PR have no mark and count as before. - **Open for Sharang:** a demo target can still be renamed and repointed at other artifacts (`PUT /api/v1/targets/{id}`). Because the seeder matches by name, a renamed one can then be seeded again. That lets a workspace hold targets outside the cap. This PR does not close the gap. - No UI change beyond the refusal text: the "Neues Prüfobjekt" button is not disabled up front; that would need a mockup. **Tests:** `tests/target_limit.rs` (fake registry, live Mongo): the entry plan refuses the third target, archiving frees a place, and a plan without the key adds an extra target. It also checks that targets already beyond the entry plan are never billed extra, and that demo targets are neither counted nor refused. Unit tests cover the key, the cap and the billing rule. Agent and core 1656 pass (live Mongo, nothing skipped), and dashboard 235 pass; clippy is clean (agent, dashboard server and web); fmt is clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
sharang added 1 commit 2026-11-28 14:08:10 +00:00
feat(metering): a plan can allow no extra targets (entry plan)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 5m29s
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Check (pull_request) Successful in 22m56s
7ef6387d39
The registry's `limits.extra_targets` caps how many targets beyond the
included ones may be active; the entry plan sends 0. A new target past
included_targets + extra_targets is refused with 409 `target_limit`,
whichever way it is added: the API, accepting a supplier's SBOM release
(the offer stays open), Managed Git (skipped, retried at the next sync)
and the demo seed. A missing or null key keeps today's behaviour: extra
targets are allowed and billed.

All active targets count, as for the included/extra split; archiving
one frees its place. Without an answer from the registry the target is
added, as scans then run unmetered.

Every way of adding a target now goes through targets::create_target,
which reads the plan once for the cap and the billing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
sharang added 1 commit 2026-11-28 18:39:18 +00:00
feat(metering): the entry plan bills no target as extra and leaves demo targets out
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 5m15s
CI / Check (pull_request) Successful in 23m9s
53da41ae94
Sharang's answers to the entry plan's open questions:

- A plan with `extra_targets: 0` bills every active target as included,
  also those already beyond its included ones when a workspace moves to
  it: no extra-target line, no counted change scans on them. Only new
  targets are refused. A swap on such a plan is refused as unlimited.
- The demo seeder marks its targets (`demo: true`); the cap neither
  counts nor refuses them. Demo targets seeded before this count as
  before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
sharang merged commit 1df32d5e1a into main 2026-11-28 22:09:20 +00:00
Sign in to join this conversation.