feat(offers): the customer is offered a supplier's release and answers it (#1028) #1064

Merged
sharang merged 3 commits from feat/sbom-offers into main 2026-11-19 13:10:21 +00:00
Owner

Part of #1028 (phase 4), step 5, first half: the customer's side of a release. Based on main (#1063 is merged).

What it adds

Call What it does
POST /api/v1/targets/{id}/releases (changed) After the registry confirms again that the connection joins exactly these two workspaces (ConnectionState::peer_of), writes an offer into the customer's database. If the offer can't be written, the release is taken back.
GET /api/v1/sbom-offers The workspace's offers, open ones first. Each shows the supplier's name and its product, nothing else of the supplier's.
POST /api/v1/sbom-offers/{id}/accept Into an existing supplier component (target_id), or a new one (name, project_ids; named after the product when no name is given). The connection is checked again first; if it has ended, the offer ends and nothing is created. Refusals: 409 answered, 409 ended, 409 target_taken, 422 not_supplier_component.
POST /api/v1/sbom-offers/{id}/decline Declines; 409 answered if already answered
POST …/releases/{release}/end (changed) Also ends the customer's offer
  • The supplier sees the answer: answer on each release (accepted or declined).

  • Tenant ids: the release keeps the customer's tenant id and the offer keeps the supplier's. They are used internally for writing across; neither is ever shown.

  • New components count like any other target: a component created on accepting goes through the same insert as POST /api/v1/targets. That insert is now the shared onboarding::insert_target, which handles CSAF refresh and the target.added usage event.

  • Audit: pruefwerk.sbom_offer_accepted and pruefwerk.sbom_offer_declined.

  • Docs: guide/sbom, the customer's side.

  • Concurrency and deletes:

    • Claim first: accepting claims the offer atomically before it creates anything. If the insert fails, the claim is given back. If the supplier ends the release between claim and insert, the still-empty component is removed and the answer is 409 ended.
    • One release per component: if two acceptances race into one component, neither keeps it (target_taken), and the next one finds the component free. Ids are compared canonically.
    • Release must be live: an offer is accepted only while the supplier's release exists and hasn't ended, as well as the connection being active.
    • Peer must hold Prüfwerk: a release to a workspace without Prüfwerk, or a halted or archived one, gives 422 peer_not_entitled. No database is created for it.
    • Deleting either side ends the offer: if the supplier deletes the target, its releases end at the customers. If the customer deletes the component, offers into it end, and the supplier sees ended.
  • Plan: there is no hard target cap. A component created on accepting is a target like one made by POST /api/v1/targets, billed as included or extra under t72.

Delivering published versions to accepted offers is the second half (next PR).

Tests (tests/connections.rs, fake registry)

  • Full round trip:
    • the supplier releases and the customer sees the offer, never with the supplier's tenant id;
    • accepting into a component of the customer's own is refused (not_supplier_component);
    • accepting into a new component names it and records the supplier product;
    • accepting twice gives 409 answered;
    • the supplier sees accepted;
    • ending the release ends the offer;
    • a second release is listed first while open, declined, and the supplier sees declined.
  • Ended connection: an offer over an ended connection gives 409 ended, and no target is created.
  • No Prüfwerk: a release to a workspace without Prüfwerk is refused, and no database appears for it.
  • Deletes:
    • the supplier deletes the target: the offer is ended, and accepting gives 409 ended;
    • the customer deletes the component: the supplier sees ended.
  • One component, two releases: the second acceptance gives target_taken even with the id in another case, and that offer stays open.
  • Checks: the OpenAPI, route and role gates pass; the e2e releases and onboarding tests pass; clippy is clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9

Part of #1028 (phase 4), step 5, first half: the customer's side of a release. Based on `main` (#1063 is merged). ## What it adds | Call | What it does | |---|---| | `POST /api/v1/targets/{id}/releases` (changed) | After the registry confirms again that the connection joins exactly these two workspaces (`ConnectionState::peer_of`), writes an offer into the customer's database. If the offer can't be written, the release is taken back. | | `GET /api/v1/sbom-offers` | The workspace's offers, open ones first. Each shows the supplier's name and its product, nothing else of the supplier's. | | `POST /api/v1/sbom-offers/{id}/accept` | Into an existing supplier component (`target_id`), or a new one (`name`, `project_ids`; named after the product when no name is given). The connection is checked again first; if it has ended, the offer ends and nothing is created. Refusals: `409 answered`, `409 ended`, `409 target_taken`, `422 not_supplier_component`. | | `POST /api/v1/sbom-offers/{id}/decline` | Declines; `409 answered` if already answered | | `POST …/releases/{release}/end` (changed) | Also ends the customer's offer | - **The supplier sees the answer:** `answer` on each release (`accepted` or `declined`). - **Tenant ids:** the release keeps the customer's tenant id and the offer keeps the supplier's. They are used internally for writing across; neither is ever shown. - **New components count like any other target:** a component created on accepting goes through the same insert as `POST /api/v1/targets`. That insert is now the shared `onboarding::insert_target`, which handles CSAF refresh and the `target.added` usage event. - **Audit:** `pruefwerk.sbom_offer_accepted` and `pruefwerk.sbom_offer_declined`. - **Docs:** `guide/sbom`, the customer's side. - **Concurrency and deletes:** - **Claim first:** accepting claims the offer atomically before it creates anything. If the insert fails, the claim is given back. If the supplier ends the release between claim and insert, the still-empty component is removed and the answer is `409 ended`. - **One release per component:** if two acceptances race into one component, neither keeps it (`target_taken`), and the next one finds the component free. Ids are compared canonically. - **Release must be live:** an offer is accepted only while the supplier's release exists and hasn't ended, as well as the connection being active. - **Peer must hold Prüfwerk:** a release to a workspace without Prüfwerk, or a halted or archived one, gives `422 peer_not_entitled`. No database is created for it. - **Deleting either side ends the offer:** if the supplier deletes the target, its releases end at the customers. If the customer deletes the component, offers into it end, and the supplier sees `ended`. - **Plan:** there is no hard target cap. A component created on accepting is a target like one made by `POST /api/v1/targets`, billed as included or extra under t72. Delivering published versions to accepted offers is the second half (next PR). ## Tests (`tests/connections.rs`, fake registry) - **Full round trip:** - the supplier releases and the customer sees the offer, never with the supplier's tenant id; - accepting into a component of the customer's own is refused (`not_supplier_component`); - accepting into a new component names it and records the supplier product; - accepting twice gives `409 answered`; - the supplier sees `accepted`; - ending the release ends the offer; - a second release is listed first while open, declined, and the supplier sees `declined`. - **Ended connection:** an offer over an ended connection gives `409 ended`, and no target is created. - **No Prüfwerk:** a release to a workspace without Prüfwerk is refused, and no database appears for it. - **Deletes:** - the supplier deletes the target: the offer is `ended`, and accepting gives `409 ended`; - the customer deletes the component: the supplier sees `ended`. - **One component, two releases:** the second acceptance gives `target_taken` even with the id in another case, and that offer stays open. - **Checks:** the OpenAPI, route and role gates pass; the e2e releases and onboarding tests pass; clippy is clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
sharang changed target branch from feat/sbom-releases to main 2026-11-19 12:35:07 +00:00
sharang added 2 commits 2026-11-19 12:36:46 +00:00
The first half of phase 4's customer side (step 5 of the plan on #1028):

- releasing a target (#1063) now writes an offer into the customer's
  database, right after the registry confirms the connection joins exactly
  the two workspaces (`ConnectionState::peer_of`, #1062); without the offer
  the release is taken back;
- `GET /api/v1/sbom-offers`: the workspace's offers, open first, naming the
  supplier and its product only;
- `POST /api/v1/sbom-offers/{id}/accept`: into an existing supplier
  component, or a new one (named after the product unless named, in the
  given projects); the connection is checked again first, and an ended one
  ends the offer and creates nothing; a new component goes through the same
  insert as `POST /api/v1/targets` (`insert_target`), so it is counted;
- `POST /api/v1/sbom-offers/{id}/decline`;
- the answer is written back to the supplier's release (`answer`); ending a
  release ends the customer's offer; accepting and declining are audited.

Delivering published versions to accepted offers is the second half.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
fix(offers): claim before creating, live releases, entitled peers, deletes on both sides (#1028)
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 5m54s
CI / Check (pull_request) Failing after 7m23s
79dd08977d
- accepting claims the offer first (offered -> accepted, atomically) and
  only then creates the component, giving the claim back when that fails;
  an end that lands in between removes the still-empty component; of two
  acceptances into one component neither keeps it (`target_taken`), and
  the id is compared canonically;
- an offer is acceptable only while the supplier's release still exists
  and has not ended, besides the connection joining the two;
- a release is refused (`peer_not_entitled`) when the other workspace does
  not hold Prüfwerk or is halted or archived, so no database is created for
  it;
- deleting a target ends its releases at their customers and ends offers
  accepted into it, with `ended` as the answer the supplier sees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
sharang force-pushed feat/sbom-offers from 8444ddc52d to 79dd08977d 2026-11-19 12:36:46 +00:00 Compare
sharang added 1 commit 2026-11-19 12:46:54 +00:00
fix(offers): the release check reads as clippy 1.94 wants it (#1028)
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 5m14s
CI / Check (pull_request) Successful in 22m34s
7bd2d784e9
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
sharang merged commit 20d56d2301 into main 2026-11-19 13:10:21 +00:00
sharang deleted branch feat/sbom-offers 2026-11-19 13:10:21 +00:00
Sign in to join this conversation.