feat(metering): included and extra targets, and why each scan ran (t72) #927

Merged
sharang merged 1 commits from feat/t72-attribution into main 2026-11-06 14:30:09 +00:00
Owner

First part of t72, Prüfwerk metering (LB §2 Abs. 4–5, §7). This PR records what a scan is metered by. Nothing is counted or enforced yet; counters, the 6-per-day limit and the Prüftag cap come in the next PR.

What changes

  • Included vs extra targets. Each target stores billing: included | extra.

    • The oldest active targets by created_at are included, up to the plan's limits.included_targets from the registry entitlement. The rest are extra.
    • The split is refreshed before each scan and when a target is created. Archiving an included target moves the oldest extra one up.
    • A plan without that key includes every target, which is every plan until the registry sends the limits. So this PR changes nothing for existing tenants.
  • Run attribution. Each run records an attribution:

    • request: the customer started it (dashboard or API).
    • support: staff started it.
    • change: something the customer changed, i.e. new commits, other uploads, or a live URL.
    • rescan: only the Prüfwerk build changed.

    For scheduled and webhook scans it's set where change detection decides, so our rescan after an update is no longer counted as a customer change. uploads_changed / content_changed don't depend on UPLOAD_CHANGE_SKIP.

  • chargeable. Says whether the run counts once it completes:

    • a request always counts;
    • a change counts only on an extra target;
    • rescans and support scans never count.

    scan.completed now carries attribution and counted as properties.

  • Dashboard. The targets list shows a "Zusätzliches Prüfobjekt" badge on an extra target.

Tests

  • Core: the included/extra split, attribution, and the contract table of what counts.
  • Agent: content_changed/uploads_changed, the included_targets limit, reading a stored target's billing, and a Mongo integration test (tests/target_billing.rs): the oldest are included, and an extra target moves up on archive.

Not built locally, per the CI-only rule; CI is the compiler here.

🤖 Generated with Claude Code

First part of t72, Prüfwerk metering (LB §2 Abs. 4–5, §7). This PR records what a scan is metered by. Nothing is counted or enforced yet; counters, the 6-per-day limit and the Prüftag cap come in the next PR. ## What changes - **Included vs extra targets.** Each target stores `billing: included | extra`. - The oldest active targets by `created_at` are included, up to the plan's `limits.included_targets` from the registry entitlement. The rest are extra. - The split is refreshed before each scan and when a target is created. Archiving an included target moves the oldest extra one up. - A plan without that key includes every target, which is every plan until the registry sends the limits. So this PR changes nothing for existing tenants. - **Run attribution.** Each run records an `attribution`: - `request`: the customer started it (dashboard or API). - `support`: staff started it. - `change`: something the customer changed, i.e. new commits, other uploads, or a live URL. - `rescan`: only the Prüfwerk build changed. For scheduled and webhook scans it's set where change detection decides, so our rescan after an update is no longer counted as a customer change. `uploads_changed` / `content_changed` don't depend on `UPLOAD_CHANGE_SKIP`. - **`chargeable`.** Says whether the run counts once it completes: - a request always counts; - a change counts only on an extra target; - rescans and support scans never count. `scan.completed` now carries `attribution` and `counted` as properties. - **Dashboard.** The targets list shows a "Zusätzliches Prüfobjekt" badge on an extra target. ## Tests - **Core:** the included/extra split, attribution, and the contract table of what counts. - **Agent:** `content_changed`/`uploads_changed`, the `included_targets` limit, reading a stored target's billing, and a Mongo integration test (`tests/target_billing.rs`): the oldest are included, and an extra target moves up on archive. Not built locally, per the CI-only rule; CI is the compiler here. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 1 commit 2026-11-06 13:39:58 +00:00
feat(metering): included and extra targets, and why each scan ran (t72)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 3m59s
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 / Check (pull_request) Successful in 17m33s
a1726433fe
The first part of Prüfwerk metering (LB §2 Abs. 4-5, §7): what a scan
is metered by, without counting or enforcing anything yet.

- A target is included or extra (`billing`). The oldest active targets
  are included, up to the plan's `limits.included_targets` from the
  registry; the rest are extra. The split is stored, refreshed before
  each scan and when a target is created, so archiving an included
  target moves the oldest extra one up. A plan without the limit (all
  plans today) includes every target.
- Each scan run records its `attribution`: request (the customer
  started it), support, change (new commits, other uploads, a live
  URL) or rescan (only the Prüfwerk build changed). Change detection
  sets it for scheduled and webhook scans, so our rescan after an
  update is told apart from a customer's change.
- `chargeable` says whether the run counts once it completes: a
  request always, a change only on an extra target, a rescan or a
  support scan never. scan.completed carries both as properties.
- The targets list badges an extra target.

Counters, the daily limit and the cap follow in the next PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang merged commit ce786b716b into main 2026-11-06 14:30:09 +00:00
Sign in to join this conversation.