New package internal/legal/contractdocs: the released contract documents as committed PDFs with pinned SHA-256, checked at startup (the server refuses to start on a mismatch) and in a test. Released now: Leistungsbeschreibung Breakpilot Plattform, Managed Git, Build-Runner, Werkpilot, Firmwerk, Werkmeister 1.0.0 and Prüfwerk 1.0.3. AGB 1.0.0, AVV 1.0.0 (master) and TOM 1.0.0 are not released yet, so they are absent. Releasing one later is a single table line plus its PDF in files/.
GET /v1/tenants/{id}/contracts keeps its fields and gains documents: [{id, kind, title, version, date, sha256, product?, managed_service?, tenant_specific}]. GET /v1/tenants/{id}/contracts/documents/{doc}.pdf serves a listed document byte for byte after the digest check. Auth is the same as the trial terms PDF route (tenants.read, tenant scope).
A tenant's own filled AVV: migration 0027 tenant_contract_documents (insert-only, the newest row per tenant and kind is current). Two staff-only endpoints: GET /v1/admin/tenants/{id}/avv-values and PUT /v1/admin/tenants/{id}/contract-documents/avv. A filled AVV replaces the master in the overview (tenant_specific: true) and is served from the bucket.
Release gate CONTRACT_DOCUMENTS (on/off, default off). While it is off, documents is [] and the PDF route answers 404. Stage gets it via orca-platform later. This PR does not change orca-platform, and prod stays off.
Why
The Vertragsunterlagen page in the portal should show the contract documents themselves, not only their status. The portal PR builds on this one.
Linked milestone: M4.1
How
Which LBs apply (contractHoldings in internal/server/contract_documents.go, plus the conditions in the contractdocs table, both tested):
Plattform: always.
A product's LB: when the tenant has a tenant_products row that is enabled and not expired. A trial row (with expires_at in the future) counts. A staff preview grant does not count (owner decision).
Managed Git / Build-Runner: when the tenant has a managed_services row of kind git / ci-runner, in any status (provisioning, active, restricted, halted).
A test checks that the table only names known products and service kinds.
IDs are stable across versions (lb-pruefwerk, avv). AGB, AVV and TOM use their kind as ID, so a tenant's filled AVV takes the master's place under avv.
avv-values: these values are never logged or audited.
ag_name is companyName plus the form's label of legalForm ("Muster GmbH", owner decision). Nothing is appended when the name already ends with it (case-insensitive; "UG" counts for the UG), or for Einzelunternehmen, Sonstige or no form. The e.V. is written without "(Verein)".
ag_anschrift is "street, ZIP city, country". The country is left out for DE / "Deutschland", codes are written out (AT becomes Österreich, and so on), and other uses headquartersCountryOther.
ag_vertreten lists the holders of r1.geschaeftsleitung (assignments only, no deputies). Member names come from the Keycloak member list, the same way the portal shows them: first and last name, otherwise e-mail. Externals are listed by name. The names are joined with ", " and " und " before the last one.
ag_weisung is "Geschäftsleitung", plus " (legalContactEmail)" when that is set.
Missing data gives an empty string. If Keycloak is down the call answers 503 rather than leaving a blank.
The response also carries values_sha256: the SHA-256 of the JSON object of the four fields, meant for the X-Values-SHA256 header of the upload.
PUT avv: the body is the PDF (at most 5 MB, must start with %PDF), with headers X-Document-Version (x.y.z) and X-Values-SHA256. The bucket key is tenants/<id>/contracts/avv/<uuid>.pdf. The upload is audited as contract_document.uploaded (version and digests only). If the row insert fails, the stored object is deleted.
The admin endpoints are not behind the gate, so staff can prepare filled AVVs before the release.
Purging a tenant also removes its filled documents from the bucket.
CI did not run ./internal/legal/... before, so the existing trialterms pin test never ran in CI. It is now in the test list. Side note: trialterms.Check() is also not called at startup; I left that unchanged.
Test plan
Unit tests added/updated (mapping, gate on/off, master and own AVV, refusals, avv-values incl. no logging, store failures, purge)
Integration tests added/updated (store contract on Postgres via testcontainers; migration up/down, CHECKs, the UPDATE trigger, FK cascade). Ran locally against Postgres 16.
Playwright e2e added/updated (n/a: no user-facing flow in this repo)
Manual smoke on stage after deploy (needs CONTRACT_DOCUMENTS=on in orca-platform for stage)
Regression test added (n/a: not a bug fix)
Also clean locally: gofmt, go vet, golangci-lint v2.12.2.
Risk
Blast radius: single endpoint family (Vertragsunterlagen); prod unaffected while the gate is off.
What could break:
The server refuses to start if an embedded PDF does not match its pin. This is intended, and the test catches it before a merge.
Migration 0027 only adds a table.
Rollback plan: revert the PR and redeploy; down migration drops the table.
Checklist
Docs updated (package and handler docs, OpenAPI)
Audit events emitted for state changes (contract_document.uploaded)
Secrets via Infisical, never in repo
Migration is forward-only + idempotent (or no migration)
Tenant scoping enforced on every DB query (or no DB access)
OpenAPI spec updated (or no API change)
featureFlags.evaluate() used for any toggleable behavior (env gate CONTRACT_DOCUMENTS, like the other registry switches)
CHANGELOG entry under "Unreleased" (generated by git-cliff from the commits)
## What
- New package `internal/legal/contractdocs`: the released contract documents as committed PDFs with pinned SHA-256, checked at startup (the server refuses to start on a mismatch) and in a test. Released now: Leistungsbeschreibung Breakpilot Plattform, Managed Git, Build-Runner, Werkpilot, Firmwerk, Werkmeister 1.0.0 and Prüfwerk 1.0.3. AGB 1.0.0, AVV 1.0.0 (master) and TOM 1.0.0 are not released yet, so they are absent. Releasing one later is a single table line plus its PDF in `files/`.
- `GET /v1/tenants/{id}/contracts` keeps its fields and gains `documents: [{id, kind, title, version, date, sha256, product?, managed_service?, tenant_specific}]`. `GET /v1/tenants/{id}/contracts/documents/{doc}.pdf` serves a listed document byte for byte after the digest check. Auth is the same as the trial terms PDF route (tenants.read, tenant scope).
- A tenant's own filled AVV: migration 0027 `tenant_contract_documents` (insert-only, the newest row per tenant and kind is current). Two staff-only endpoints: `GET /v1/admin/tenants/{id}/avv-values` and `PUT /v1/admin/tenants/{id}/contract-documents/avv`. A filled AVV replaces the master in the overview (`tenant_specific: true`) and is served from the bucket.
- Release gate `CONTRACT_DOCUMENTS` (`on`/`off`, default **off**). While it is off, `documents` is `[]` and the PDF route answers 404. Stage gets it via orca-platform later. This PR does not change orca-platform, and prod stays off.
## Why
The Vertragsunterlagen page in the portal should show the contract documents themselves, not only their status. The portal PR builds on this one.
Linked milestone: **M4.1**
## How
- **Which LBs apply** (`contractHoldings` in `internal/server/contract_documents.go`, plus the conditions in the contractdocs table, both tested):
- Plattform: always.
- A product's LB: when the tenant has a `tenant_products` row that is enabled and not expired. A `trial` row (with `expires_at` in the future) counts. A staff preview grant does **not** count (owner decision).
- Managed Git / Build-Runner: when the tenant has a `managed_services` row of kind `git` / `ci-runner`, in any status (provisioning, active, restricted, halted).
- A test checks that the table only names known products and service kinds.
- **IDs** are stable across versions (`lb-pruefwerk`, `avv`). AGB, AVV and TOM use their kind as ID, so a tenant's filled AVV takes the master's place under `avv`.
- **avv-values**: these values are never logged or audited.
- `ag_name` is `companyName` plus the form's label of `legalForm` ("Muster GmbH", owner decision). Nothing is appended when the name already ends with it (case-insensitive; "UG" counts for the UG), or for Einzelunternehmen, Sonstige or no form. The e.V. is written without "(Verein)".
- `ag_anschrift` is "street, ZIP city, country". The country is left out for DE / "Deutschland", codes are written out (AT becomes Österreich, and so on), and `other` uses `headquartersCountryOther`.
- `ag_vertreten` lists the holders of `r1.geschaeftsleitung` (assignments only, no deputies). Member names come from the Keycloak member list, the same way the portal shows them: first and last name, otherwise e-mail. Externals are listed by name. The names are joined with ", " and " und " before the last one.
- `ag_weisung` is "Geschäftsleitung", plus " (legalContactEmail)" when that is set.
- Missing data gives an empty string. If Keycloak is down the call answers 503 rather than leaving a blank.
- The response also carries `values_sha256`: the SHA-256 of the JSON object of the four fields, meant for the `X-Values-SHA256` header of the upload.
- **PUT avv**: the body is the PDF (at most 5 MB, must start with `%PDF`), with headers `X-Document-Version` (x.y.z) and `X-Values-SHA256`. The bucket key is `tenants/<id>/contracts/avv/<uuid>.pdf`. The upload is audited as `contract_document.uploaded` (version and digests only). If the row insert fails, the stored object is deleted.
- The admin endpoints are **not** behind the gate, so staff can prepare filled AVVs before the release.
- Purging a tenant also removes its filled documents from the bucket.
- CI did not run `./internal/legal/...` before, so the existing trialterms pin test never ran in CI. It is now in the test list. Side note: `trialterms.Check()` is also not called at startup; I left that unchanged.
## Test plan
- [x] Unit tests added/updated (mapping, gate on/off, master and own AVV, refusals, avv-values incl. no logging, store failures, purge)
- [x] Integration tests added/updated (store contract on Postgres via testcontainers; migration up/down, CHECKs, the UPDATE trigger, FK cascade). Ran locally against Postgres 16.
- [ ] Playwright e2e added/updated (n/a: no user-facing flow in this repo)
- [ ] Manual smoke on stage after deploy (needs `CONTRACT_DOCUMENTS=on` in orca-platform for stage)
- [ ] Regression test added (n/a: not a bug fix)
Also clean locally: `gofmt`, `go vet`, golangci-lint v2.12.2.
## Risk
**Blast radius:** single endpoint family (Vertragsunterlagen); prod unaffected while the gate is off.
**What could break:**
- The server refuses to start if an embedded PDF does not match its pin. This is intended, and the test catches it before a merge.
- Migration 0027 only adds a table.
**Rollback plan:** revert the PR and redeploy; down migration drops the table.
## Checklist
- [x] Docs updated (package and handler docs, OpenAPI)
- [x] Audit events emitted for state changes (`contract_document.uploaded`)
- [x] Secrets via Infisical, never in repo
- [x] Migration is forward-only + idempotent (or no migration)
- [x] Tenant scoping enforced on every DB query (or no DB access)
- [x] OpenAPI spec updated (or no API change)
- [ ] `featureFlags.evaluate()` used for any toggleable behavior (env gate `CONTRACT_DOCUMENTS`, like the other registry switches)
- [ ] CHANGELOG entry under "Unreleased" (generated by git-cliff from the commits)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
internal/legal/contractdocs holds the released contract documents as
committed PDFs with pinned SHA-256: the Leistungsbeschreibungen Breakpilot
(Plattform), Managed Git, Build-Runner, Werkpilot, Firmwerk, Werkmeister
1.0.0 and Prüfwerk 1.0.3. AGB, AVV and TOM are added later by one table
line plus their PDF. The table also says which LB applies to whom.
The pins are checked at startup (the server refuses to start on a
mismatch) and by a test; CI now runs ./internal/legal/... too.
CONTRACT_DOCUMENTS ("on"/"off", default off) is the release gate.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tenant_contract_documents records a workspace's own filled contract
document (for now the AVV): master version, PDF SHA-256, bucket key,
digest of the filled-in values and the staff member's Keycloak sub.
Rows are insert-only (an UPDATE trigger refuses changes); the newest per
tenant and kind is current. Memory and Postgres stores, purge with the
tenant.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GET /v1/tenants/{id}/contracts gains "documents": AGB, AVV, TOM and the
Leistungsbeschreibungen that apply to the tenant (platform always;
products booked, on trial or under an active preview grant; Managed Git
and Build-Runner when the tenant has that managed service). A filled AVV
of the tenant replaces the master (tenant_specific).
GET /v1/tenants/{id}/contracts/documents/{doc}.pdf serves the bytes after
the digest check. Both are empty / 404 while CONTRACT_DOCUMENTS is off.
Staff only: GET /v1/admin/tenants/{id}/avv-values derives the AVV details
from the company profile and the role dataset (never logged), PUT
/v1/admin/tenants/{id}/contract-documents/avv stores the filled PDF.
Purging a tenant removes its filled documents from the bucket.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The overview lists it as "Leistungsbeschreibung Breakpilot Plattform"; the
PDF and its pin are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ag_name is the company name with the form's label of its legal form
("Muster GmbH"), not appended when the name already ends with it
(case-insensitive; "UG" counts for the UG), nor for Einzelunternehmen,
Sonstige or no form. The e.V. is written without "(Verein)".
A staff preview grant no longer brings in a product's Leistungsbeschreibung:
only enabled, unexpired bookings and trials count.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang
merged commit 5525759392 into main2026-11-09 12:59:20 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What
internal/legal/contractdocs: the released contract documents as committed PDFs with pinned SHA-256, checked at startup (the server refuses to start on a mismatch) and in a test. Released now: Leistungsbeschreibung Breakpilot Plattform, Managed Git, Build-Runner, Werkpilot, Firmwerk, Werkmeister 1.0.0 and Prüfwerk 1.0.3. AGB 1.0.0, AVV 1.0.0 (master) and TOM 1.0.0 are not released yet, so they are absent. Releasing one later is a single table line plus its PDF infiles/.GET /v1/tenants/{id}/contractskeeps its fields and gainsdocuments: [{id, kind, title, version, date, sha256, product?, managed_service?, tenant_specific}].GET /v1/tenants/{id}/contracts/documents/{doc}.pdfserves a listed document byte for byte after the digest check. Auth is the same as the trial terms PDF route (tenants.read, tenant scope).tenant_contract_documents(insert-only, the newest row per tenant and kind is current). Two staff-only endpoints:GET /v1/admin/tenants/{id}/avv-valuesandPUT /v1/admin/tenants/{id}/contract-documents/avv. A filled AVV replaces the master in the overview (tenant_specific: true) and is served from the bucket.CONTRACT_DOCUMENTS(on/off, default off). While it is off,documentsis[]and the PDF route answers 404. Stage gets it via orca-platform later. This PR does not change orca-platform, and prod stays off.Why
The Vertragsunterlagen page in the portal should show the contract documents themselves, not only their status. The portal PR builds on this one.
Linked milestone: M4.1
How
contractHoldingsininternal/server/contract_documents.go, plus the conditions in the contractdocs table, both tested):tenant_productsrow that is enabled and not expired. Atrialrow (withexpires_atin the future) counts. A staff preview grant does not count (owner decision).managed_servicesrow of kindgit/ci-runner, in any status (provisioning, active, restricted, halted).lb-pruefwerk,avv). AGB, AVV and TOM use their kind as ID, so a tenant's filled AVV takes the master's place underavv.ag_nameiscompanyNameplus the form's label oflegalForm("Muster GmbH", owner decision). Nothing is appended when the name already ends with it (case-insensitive; "UG" counts for the UG), or for Einzelunternehmen, Sonstige or no form. The e.V. is written without "(Verein)".ag_anschriftis "street, ZIP city, country". The country is left out for DE / "Deutschland", codes are written out (AT becomes Österreich, and so on), andotherusesheadquartersCountryOther.ag_vertretenlists the holders ofr1.geschaeftsleitung(assignments only, no deputies). Member names come from the Keycloak member list, the same way the portal shows them: first and last name, otherwise e-mail. Externals are listed by name. The names are joined with ", " and " und " before the last one.ag_weisungis "Geschäftsleitung", plus " (legalContactEmail)" when that is set.values_sha256: the SHA-256 of the JSON object of the four fields, meant for theX-Values-SHA256header of the upload.%PDF), with headersX-Document-Version(x.y.z) andX-Values-SHA256. The bucket key istenants/<id>/contracts/avv/<uuid>.pdf. The upload is audited ascontract_document.uploaded(version and digests only). If the row insert fails, the stored object is deleted../internal/legal/...before, so the existing trialterms pin test never ran in CI. It is now in the test list. Side note:trialterms.Check()is also not called at startup; I left that unchanged.Test plan
CONTRACT_DOCUMENTS=onin orca-platform for stage)Also clean locally:
gofmt,go vet, golangci-lint v2.12.2.Risk
Blast radius: single endpoint family (Vertragsunterlagen); prod unaffected while the gate is off.
What could break:
Rollback plan: revert the PR and redeploy; down migration drops the table.
Checklist
contract_document.uploaded)featureFlags.evaluate()used for any toggleable behavior (env gateCONTRACT_DOCUMENTS, like the other registry switches)🤖 Generated with Claude Code
internal/legal/contractdocs holds the released contract documents as committed PDFs with pinned SHA-256: the Leistungsbeschreibungen Breakpilot (Plattform), Managed Git, Build-Runner, Werkpilot, Firmwerk, Werkmeister 1.0.0 and Prüfwerk 1.0.3. AGB, AVV and TOM are added later by one table line plus their PDF. The table also says which LB applies to whom. The pins are checked at startup (the server refuses to start on a mismatch) and by a test; CI now runs ./internal/legal/... too. CONTRACT_DOCUMENTS ("on"/"off", default off) is the release gate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>GET /v1/tenants/{id}/contracts gains "documents": AGB, AVV, TOM and the Leistungsbeschreibungen that apply to the tenant (platform always; products booked, on trial or under an active preview grant; Managed Git and Build-Runner when the tenant has that managed service). A filled AVV of the tenant replaces the master (tenant_specific). GET /v1/tenants/{id}/contracts/documents/{doc}.pdf serves the bytes after the digest check. Both are empty / 404 while CONTRACT_DOCUMENTS is off. Staff only: GET /v1/admin/tenants/{id}/avv-values derives the AVV details from the company profile and the role dataset (never logged), PUT /v1/admin/tenants/{id}/contract-documents/avv stores the filled PDF. Purging a tenant removes its filled documents from the bucket. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>ag_name is the company name with the form's label of its legal form ("Muster GmbH"), not appended when the name already ends with it (case-insensitive; "UG" counts for the UG), nor for Einzelunternehmen, Sonstige or no form. The e.V. is written without "(Verein)". A staff preview grant no longer brings in a product's Leistungsbeschreibung: only enabled, unexpired bookings and trials count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>