diff --git a/reviews/plat-1658-code-review.md b/reviews/plat-1658-code-review.md new file mode 100644 index 0000000..643c8b7 --- /dev/null +++ b/reviews/plat-1658-code-review.md @@ -0,0 +1,59 @@ +--- +id: SR-1620 +title: "code-review review — PLAT-1658 spec-objects-security" +type: SpecReview +analysis: code-review +scope: "agent-ix/spec-objects-security; typespec/main.tsp; spec_objects_security/manifest.yaml; spec_objects_security/schemas/ProcessingActivity*.json; tests/test_processing_activity.py; tests/test_regulated_categories.py" +review_set: subset +--- + +## Summary + +Reviewed the ProcessingActivity schemas, manifest relation, skeleton and tests against FR-028. The required-coverage rule is advisory, so an activity without a covers edge still exits validation successfully; the record schema also permits a controller role to carry a controller list contrary to the role contract. + +## Verdict + +**FAIL** — one high-severity requirement mismatch and one schema contract defect remain. + +## Scope + +- Examined: FR-028-AC-1 through FR-028-AC-8; ProcessingActivity TypeSpec and generated schemas; manifest relation; skeleton; new focused tests and the regulated-category test adjustment. +- Ticket: PLAT-1658; PR #69; reviewed published head `84b182f01a6db11c1c72c42f4b94442afe365268`. +- Applicable AssuranceProfile: none found under `spec/`. +- Checks: schema drift passed (67 schemas match); focused tests had 19 passed and 13 failed in pre-existing `test_regulated_categories.py` cases because the activated Python Quire wheel rejects baseline `where` fields in `manifest.yaml`; Ruff and Black passed. The ProcessingActivity-focused test file passed; the combined focused run had 19 passes and 13 pre-existing regulated-category failures because the activated Python Quire wheel rejects baseline `where` fields in `manifest.yaml`. + +## Findings + +| ID | Severity | Summary | Refs | +| --- | --- | --- | --- | +| FND-001 | high | The required `covers` relation only emits an advisory warning: a valid-looking processing activity with no covers edge produces `processing-activity-covers-nothing` but `quire validate --okf` exits 0, violating the explicit fail behavior in AC-5. The new tests check declaration shape and only a valid edge, never a no-edge failure. | spec/functional/FR-028-processing-activity.md:61; spec_objects_security/manifest.yaml:844-851; tests/test_processing_activity.py:69-87,98-123 | +| FND-002 | medium | `ProcessingActivity.json` allows `controller` to be a string or array at the base schema, while its controller-role conditional only adds required fields and never narrows that property to a string. A controller record with a controller list therefore validates, although FR-028 requires one name-and-contact string; the frontmatter schema correctly narrows it, so the published record schema disagrees. | spec/functional/FR-028-processing-activity.md:35; spec_objects_security/schemas/ProcessingActivity.json:9-20,72-90; spec_objects_security/schemas/ProcessingActivityFrontmatter.json:98-109 | + +## Evidence + +For FND-001, running Quire CLI 0.46.0 / engine 0.61.0 against a bundle containing an activity with no `covers` edge returned exit 0 and emitted: `warning: ... 'PA-EMPTY' has no 'covers' edge to any connection/data_sink/part ... [processing-activity-covers-nothing]`. Quire FR-058-AC-7 and `quire-rs/src/corpus/required_relations.rs` route required-relation findings at grammar severity, advisory by default. The PR test only asserts that the manifest declares `covers`; its bundle test exercises only a positive connection edge. + +For FND-002, Draft 2020-12 schema inspection shows `controller` has an `anyOf` string/array at the top level, while the controller conditional requires only `purposes`, `data_subject_categories`, and `retention`. The corresponding controller conditional in `ProcessingActivityFrontmatter.json` explicitly sets `controller.type: string`; that restriction is absent from the record schema. + +## Examined Units + +- `FR-028-AC-1` (examined): “A controller activity with controller details, purposes, data-subject categories, retention, home regions and a valid `covers` edge validates.” +- `FR-028-AC-2` (examined): “A processor activity with a processor name and contact, a non-empty controller list and home regions validates without `purposes`, `data_subject_categories` or `retention`.” +- `FR-028-AC-3` (examined): “A controller activity without `retention`, `purposes` or `data_subject_categories`, and a processor activity without its own `processor` identity/contact or with an empty controller list, each fail with a diagnostic naming the missing or invalid field.” +- `FR-028-AC-4` (examined): “An unknown role, an empty home-region list, or a home-region value outside the stated vocabulary fails validation.” +- `FR-028-AC-5` (examined): “A `processing_activity` with no `covers` edge fails validation; an edge to a `connection`, `data_sink` or `part` validates.” +- `FR-028-AC-6` (examined): “A `covers` edge to a `queue` fails with a wrong-kind diagnostic, and an edge to an absent target fails with a dangling-target diagnostic.” +- `FR-028-AC-7` (examined): “The module exports `processing_activity`; its generated schema and skeleton pass the module schema-drift and `quire validate` checks.” +- `FR-028-AC-8` (examined): “Omitting any optional authored field leaves it absent in the extracted record; no omitted value is populated from another field, artifact, code or runtime source.” + + +## Dispositions + +Round 1, published head 7e27cf4934f5c0e6dfc5dde0f7adfcd6c87d66b3. + +| FND | outcome | reason | +| --- | --- | --- | +| FND-001 | fixed | FR-028 and AC-5 now specify the located advisory warning and the warning's non-failing effect, matching the generic required-relation behavior. The test asserts the warning's location, declared check, and message; a direct run of the same fixture returned 0. | +| FND-002 | fixed | The controller-role branch of `ProcessingActivity.json` now applies the `NonBlankText` schema to `controller`, rejecting an array in the controller role while the processor role still accepts its list. `node scripts/generate-schemas.mjs --check` reports 67 schemas match. | + +Round-1 verification note: `tests/test_processing_activity.py` yielded 9 passed, 1 failed after npm dependencies were installed. The remaining extraction assertion used the globally installed Python Quire 0.53.0, while the repository requires `quire >=0.61.0`; it returned an empty record for the processor fixture. The rest of the focused tests ran against npm quire-cli 0.46.0 / engine 0.61.0. diff --git a/reviews/plat-1658-gap-analysis.md b/reviews/plat-1658-gap-analysis.md new file mode 100644 index 0000000..18494d9 --- /dev/null +++ b/reviews/plat-1658-gap-analysis.md @@ -0,0 +1,51 @@ +--- +id: SR-1621 +title: "gap-analysis review — PLAT-1658 spec-objects-security" +type: SpecReview +analysis: gap-analysis +scope: "agent-ix/spec-objects-security; spec/functional/FR-028-processing-activity.md; typespec/main.tsp; spec_objects_security/manifest.yaml; spec_objects_security/schemas/ProcessingActivity*.json; tests/test_processing_activity.py; tests/test_regulated_categories.py" +review_set: subset +--- + +## Summary + +The computed matrix has no test binders for any FR-028 acceptance criterion. The newly added `pytest.mark.trace` annotations do not back criteria because the module has no FR-028 rows in its trace matrix; the source tags consequently produce `criterion-tagged-outside-row` warnings. Plan completion was not assessed. Optional semantic review was skipped because it was not requested. + +## Verdict + +**FAIL** — all eight examined acceptance criteria are untagged in the computed Test Matrix. + +## Scope + +- Examined: FR-028-AC-1 through FR-028-AC-8, their test annotations, generated schemas, TypeSpec model, manifest relation and skeleton. +- Ticket: PLAT-1658; PR #69; reviewed published head `84b182f01a6db11c1c72c42f4b94442afe365268`. +- Plan completion: not assessed. +- Semantic review: skipped (not requested). + +## Findings + +| ID | Severity | Summary | Refs | +| --- | --- | --- | --- | +| FND-001 | high | The computed Test Matrix reports FR-028-AC-1 through AC-8 as untagged with zero binders. `tests/test_processing_activity.py` contains trace markers, but `quire matrix` reports `criterion-tagged-outside-row` for these tags because no matrix row declares the new criterion ids; the tags do not establish coverage. | spec/functional/FR-028-processing-activity.md:57-64; tests/test_processing_activity.py:21-27,59-70,98-99 | + +## Coverage + +`quoin matrix --repo . --json` exited 0 and reported `static_status=untagged` and no binders for each FR-028-AC-1 through FR-028-AC-8. `quire matrix --scope . --format json` exited 0 and reported the added tags as `criterion-tagged-outside-row`; the report identifies the expected same-test tag in a declared matrix row, but none exists for these criteria. The module has no `spec/tests.md` row changes in this PR. Reverse-gap and stub scan found no other new unowned behavior or stubs in the reviewed change. The PR's schema generation check passed (67 schemas match). The focused test run produced 19 passes; 13 unrelated regulated-category tests failed because the active Python Quire wheel rejects a pre-existing `where` manifest field. + + +## New findings (round 1) + +| ID | Severity | Summary | Refs | +| --- | --- | --- | --- | +| FND-002 | medium | FR-028's changed coverage behavior explicitly requires an advisory warning that does not make `quire validate` exit non-zero. The tagged no-covers test checks the warning location and text but never asserts `result.returncode == 0`, so it cannot catch a regression that emits the warning and still fails validation. A direct run currently returns 0. | spec/functional/FR-028-processing-activity.md:44; tests/test_processing_activity.py:160-174 | + +## Dispositions + +Round 1, published head 7e27cf4934f5c0e6dfc5dde0f7adfcd6c87d66b3. + +| FND | outcome | reason | +| --- | --- | --- | +| FND-001 | fixed | `spec/tests.md` now contains TC-248 through TC-255 rows for FR-028-AC-1 through AC-8. Quoin 0.35.0 and Quire 0.46.0 computed matrices both report all eight criteria tagged with their expected `tests/test_processing_activity.py` binders. | +| FND-002 | still-open | The warning test still checks only output text. Add an assertion that `result.returncode == 0` to enforce the explicit advisory/non-failing rule in FR-028 line 44. | + +Round-1 verification note: schema generation check passed (67 schemas match). Focused Python tests: 9 passed, 1 failed. The remaining extraction assertion ran against globally installed Python Quire 0.53.0 while the repository requires `quire >=0.61.0`; it returned an empty record for the processor fixture. Matrix evidence came from Quoin 0.35.0 and npm Quire CLI 0.46.0 / engine 0.61.0. diff --git a/scripts/generate-schemas.mjs b/scripts/generate-schemas.mjs index 5341691..c036ee7 100644 --- a/scripts/generate-schemas.mjs +++ b/scripts/generate-schemas.mjs @@ -114,10 +114,10 @@ function normalize(schemas, base, moduleFiles, coreBase) { /** * Frontmatter validators compile without the module schema registry (FR-069). - * Keep their closed enum members inline so validation stays offline while the - * regular data schemas can continue to reference the shared enum schemas. + * Keep enum and string-scalar constraints inline so validation stays offline + * while regular data schemas can continue to reference shared schema files. */ -function inlineFrontmatterEnums(schemas) { +function inlineFrontmatterConstraints(schemas) { const byId = new Map( schemas.map(([, schema]) => [schema.$id, schema]).filter(([id]) => id), ); @@ -135,6 +135,29 @@ function inlineFrontmatterEnums(schemas) { delete node.$ref; node.type = target.type; node.enum = [...target.enum]; + } else if ( + target && + typeof target.type === "string" && + !["properties", "allOf", "oneOf", "anyOf", "$defs"].some( + (key) => key in target, + ) + ) { + delete node.$ref; + for (const key of [ + "type", + "const", + "enum", + "pattern", + "minLength", + "maxLength", + "format", + "minItems", + "maxItems", + "uniqueItems", + "items", + ]) { + if (key in target) node[key] = target[key]; + } } } for (const value of Object.values(node)) visit(value); @@ -169,7 +192,7 @@ function emit() { } const moduleFiles = new Set(mine.map(([name]) => name)); normalize(mine, base, moduleFiles, semanticCoreBase()); - inlineFrontmatterEnums(mine); + inlineFrontmatterConstraints(mine); const rendered = new Map(mine.map(([name, schema]) => [name, render(schema)])); return rendered; diff --git a/spec/functional/FR-026-threat-model-object.md b/spec/functional/FR-026-threat-model-object.md index 5cb63ed..aa879e3 100644 --- a/spec/functional/FR-026-threat-model-object.md +++ b/spec/functional/FR-026-threat-model-object.md @@ -122,7 +122,7 @@ not a testable obligation of this requirement. | FR-026-AC-7 | `ThreatModel.json` carries no `default` for `method` or `reviewed_by`, and an extracted record has no `method` or `reviewed_by` key the author did not write. | Test | | FR-026-AC-8 | No manifest entry, rule text, skeleton or README added by this requirement names or quotes a paywalled standard; the only sources named are STRIDE, OWASP's free threat-modelling guidance and NIST SP 800-154. | Inspection | | FR-026-AC-9 | The module manifest declares `considers` and `covers` in `edge_types`; the module loads, and removing either declaration makes it fail to load naming the verb. | Test | -| FR-026-AC-10 | `semantic.exports` names `threat_model` and has twenty-seven entries; `ThreatModel.json` is emitted without `default` keys; the `threat_model` skeleton validates; the empty record `{}` fails `ThreatModel.json`. | Test | +| FR-026-AC-10 | `semantic.exports` names `threat_model`; `ThreatModel.json` is emitted without `default` keys; the `threat_model` skeleton validates; the empty record `{}` fails `ThreatModel.json`. | Test | ## Dependencies diff --git a/spec/functional/FR-028-processing-activity.md b/spec/functional/FR-028-processing-activity.md index 6e4a8eb..33d0e46 100644 --- a/spec/functional/FR-028-processing-activity.md +++ b/spec/functional/FR-028-processing-activity.md @@ -41,7 +41,7 @@ The security module SHALL let a person describe one processing activity and iden ### Coverage edges - The module manifest SHALL declare the `processing_activity` object type and allow `covers` targets of `connection`, `data_sink` and `part`. -- Each `processing_activity` SHALL have at least one outgoing `covers` edge to one of those types. +- The manifest SHALL declare a required-relation check for outgoing `covers` edges to those types. When an activity has no such edge, Quire SHALL emit a located warning naming the activity and the declared check; the warning is advisory and does not make `quire validate` exit non-zero. - A `covers` edge to any other object type or to a missing target SHALL fail validation with a located edge diagnostic. - A `covers` edge to a `queue` SHALL fail as a wrong-kind edge. @@ -58,7 +58,7 @@ The security module SHALL let a person describe one processing activity and iden | FR-028-AC-2 | A processor activity with a processor name and contact, a non-empty controller list and home regions validates without `purposes`, `data_subject_categories` or `retention`. | Test | | FR-028-AC-3 | A controller activity without `retention`, `purposes` or `data_subject_categories`, and a processor activity without its own `processor` identity/contact or with an empty controller list, each fail with a diagnostic naming the missing or invalid field. | Test | | FR-028-AC-4 | An unknown role, an empty home-region list, or a home-region value outside the stated vocabulary fails validation. | Test | -| FR-028-AC-5 | A `processing_activity` with no `covers` edge fails validation; an edge to a `connection`, `data_sink` or `part` validates. | Test | +| FR-028-AC-5 | A `processing_activity` with no `covers` edge emits a located warning naming the activity and declared check; an edge to a `connection`, `data_sink` or `part` validates. | Test | | FR-028-AC-6 | A `covers` edge to a `queue` fails with a wrong-kind diagnostic, and an edge to an absent target fails with a dangling-target diagnostic. | Test | | FR-028-AC-7 | The module exports `processing_activity`; its generated schema and skeleton pass the module schema-drift and `quire validate` checks. | Test | | FR-028-AC-8 | Omitting any optional authored field leaves it absent in the extracted record; no omitted value is populated from another field, artifact, code or runtime source. | Test | diff --git a/spec/tests.md b/spec/tests.md index ef648a3..332ce34 100644 --- a/spec/tests.md +++ b/spec/tests.md @@ -97,7 +97,7 @@ the Python package only: neither Node script is measured by it. 1. Every acceptance criterion and named constraint has at least one test case. 2. Both Properties forms (typed table, `sysml` fence) and every one of the - twenty-six object types are tested. + twenty-seven object types are tested. 3. Item-rule boundaries are tested at their allowed and refused edges (zero versus one identity field, empty versus one-item `clauses`/`operations`, present versus absent graded row). @@ -157,6 +157,7 @@ the Python package only: neither Node script is measured by it. | FR-017 | FR-017-AC-1..7 | TC-175..TC-186 | ✅ `quire clauses` loads strictly and cannot load the real module (the object-type edges come from another module), so TC-181, TC-183, TC-185 and TC-186 evaluate a module that holds only the set files | | FR-026 | FR-026-AC-1..7, FR-026-AC-9..10 | TC-224..TC-236, TC-242..TC-243 | ✅ | | FR-027 | FR-027-AC-6..7 | TC-237..TC-241 | ✅ | +| FR-028 | FR-028-AC-1..8 | TC-248..TC-255 | ✅ | ### Integration Test Coverage @@ -198,11 +199,11 @@ the Python package only: neither Node script is measured by it. | TC-031 | No `.npmrc`, no `file:`/`link:` dependency | Static | P2 | FR-002-CON-2 | ✅ | | TC-032 | `package-lock.json` resolves every package, `@agent-ix/semantic-core` included, from npmjs | Unit | P2 | FR-002-CON-4 | ✅ | | TC-035 | `.gitattributes` pins `eol=lf` and `npm pack` leaves nothing staged at the repository root | Unit | P1 | FR-002-AC-11 | ✅ | -| TC-040 | The `semantic` block equals the eight admitted keys and `exports` equals the twenty-six types | Unit | P0 | FR-003-AC-1, FR-003-CON-1 | 🚧 | -| TC-044 | `quire.Registry.load_from` lists all twenty-six archetypes and `validate_document` reports no `semantic.*` load failure on any skeleton | Integration | P0 | FR-003-AC-4 | 🚧 | +| TC-040 | The `semantic` block equals the eight admitted keys and `exports` equals the twenty-seven types | Unit | P0 | FR-003-AC-1, FR-003-CON-1 | 🚧 | +| TC-044 | `quire.Registry.load_from` lists all twenty-seven archetypes and `validate_document` reports no `semantic.*` load failure on any skeleton | Integration | P0 | FR-003-AC-4 | 🚧 | | TC-045 | An unknown `semantic` key is refused by the loader; the refusal names the key or path | Integration | P1 | FR-003-AC-6 | ✅ refusal verified; the naming half is a strict expected failure on quire-rs#221 and quire-rs#394 | | TC-046 | `quoin module install path:` succeeds, lists the module, and the prior version is restored | Integration | P1 | FR-003-AC-5 | ✅ | -| TC-050 | Each of the twenty-six schemas differs from every other in a required, admitted, or item rule; none is `type: object` only | Unit | P0 | FR-004-AC-1 | 🚧 | +| TC-050 | Each of the twenty-seven schemas differs from every other in a required, admitted, or item rule; none is `type: object` only | Unit | P0 | FR-004-AC-1 | 🚧 | | TC-051 | Asset: identity record validates; identity flag removed fails; no `fields` fails | Integration | P0 | FR-004-AC-2 | ✅ | | TC-052 | Role with `operations` fails; permission and scope with `relations` each fail | Integration | P0 | FR-004-AC-3 | ✅ | | TC-053 | Threat: `stride_category` row required; an invented STRIDE member fails | Integration | P0 | FR-004-AC-4 | ✅ | @@ -212,7 +213,7 @@ the Python package only: neither Node script is measured by it. | TC-057 | Auth flow: one operation validates; empty `operations` fails; `relations` fails | Integration | P0 | FR-004-AC-8 | ✅ | | TC-058 | Audit event: `Timestamp` field and no identity validates; missing `Timestamp`, an identity row, or `operations` each fail | Integration | P0 | FR-004-AC-9 | ✅ | | TC-059 | Trust boundary: one clause and a `trust_level` row validates; each removal fails; an invented trust level fails | Integration | P1 | FR-004-AC-10 | ✅ | -| TC-060 | The empty record `{}` fails against all twenty-six schemas | Unit | P0 | FR-004-AC-11, FR-004-CON-2 | 🚧 | +| TC-060 | The empty record `{}` fails against all twenty-seven schemas | Unit | P0 | FR-004-AC-11, FR-004-CON-2 | 🚧 | | TC-061 | Placeholder `unresolved` target is accepted by the schema and reported by the extractor; a bare token is refused | Integration | P1 | FR-004-AC-12 | ✅ | | TC-062 | No module schema redeclares a semantic-core model; every grammar item is a `$ref` to semantic-core | Unit | P1 | FR-004-AC-13, FR-004-CON-1 | ✅ | | TC-063 | Data classification: `level` row required; `relations` refused | Integration | P1 | FR-004-AC-14 | ✅ | @@ -224,7 +225,7 @@ the Python package only: neither Node script is measured by it. | TC-075 | `ControlEffectiveness` starts at `not_assessed` and `TrustLevel`'s unassessed member is `untrusted` | Unit | P1 | FR-006-AC-6 | ✅ | | TC-076 | No shipped schema uses `minContains` or `maxContains`, so no negative rule can invert | Unit | P0 | FR-006-AC-7 | ✅ | | TC-077 | No vocabulary member expresses "assume the permissive value" | Static | P2 | FR-006-CON-1 | ✅ | -| TC-080 | Every skeleton (twenty-six plus three alternates) validates with no error | Integration | P0 | FR-005-AC-1 | 🚧 | +| TC-080 | Every skeleton (twenty-seven plus three alternates) validates with no error | Integration | P0 | FR-005-AC-1 | 🚧 | | TC-081 | Table and `sysml` skeletons extract to identical normalized fields with the recorded forms | Integration | P0 | FR-005-AC-2, FR-005-CON-2 | ✅ | | TC-082 | Under the skeleton bundle index every skeleton extracts with zero errors and zero unresolved tokens | Integration | P0 | FR-005-AC-3 | ✅ | | TC-083 | Availability states per skeleton (fields, clauses, operations) match the type's declared set | Integration | P1 | FR-005-AC-4 | ✅ | @@ -366,11 +367,19 @@ the Python package only: neither Node script is measured by it. | TC-240 | Risk documents validate only when `decision` and `decided_by` satisfy the authored decision rule | Integration | P0 | FR-027-AC-6 | ✅ | | TC-241 | The risk skeleton states `decision: undecided` | Unit | P0 | FR-027-AC-6 | ✅ | | TC-242 | An empty `## Out of scope` section fails validation naming the section | Integration | P0 | FR-026-AC-6 | ✅ | -| TC-243 | `semantic.exports` contains twenty-six types including `threat_model` | Unit | P0 | FR-026-AC-10 | ✅ | +| TC-243 | `semantic.exports` contains `threat_model` | Unit | P0 | FR-026-AC-10 | ✅ | | TC-244 | Safeguard and frontmatter schemas admit the declared non-empty unique safeguard lists and reject undeclared values | Unit | P0 | FR-025-AC-8, FR-025-AC-11 | ✅ | | TC-245 | Control safeguards are optional authored frontmatter, are extracted when present, and the skeleton validates | Integration | P0 | FR-025-AC-8, FR-025-AC-9 | ✅ | | TC-246 | A control protects a connection and a data sink without a disallowed-target diagnostic | Integration | P0 | FR-025-AC-9 | ✅ | | TC-247 | Control and data-classification manifests reference their open frontmatter schemas and declare the field locators | Unit | P0 | FR-025-AC-9, FR-025-AC-11 | ✅ | +| TC-248 | Controller activity has scalar controller details, required context, and a valid covers connection | Integration | P0 | FR-028-AC-1 | ✅ | +| TC-249 | Processor activity accepts its own identity, a non-empty controller list, and home regions without controller-only context | Unit | P0 | FR-028-AC-2 | ✅ | +| TC-250 | Missing controller context or processor identity/controller-list requirements are rejected with field-named diagnostics | Unit | P0 | FR-028-AC-3 | ✅ | +| TC-251 | Unknown role, empty home-region list and an unsupported region value are rejected | Unit | P0 | FR-028-AC-4 | ✅ | +| TC-252 | An activity without a covers edge emits the declared located advisory warning | Integration | P0 | FR-028-AC-5 | ✅ | +| TC-253 | A covers edge to a queue yields a wrong-kind diagnostic and a missing target yields a dangling-target diagnostic | Integration | P0 | FR-028-AC-6 | ✅ | +| TC-254 | The processing-activity schemas are generated without drift, the manifest exports the object, and its skeleton validates | Integration | P0 | FR-028-AC-7 | ✅ | +| TC-255 | Optional processing-activity frontmatter remains absent from the extracted processor record when omitted | Integration | P0 | FR-028-AC-8 | ✅ | ## Test Environment diff --git a/spec_objects_security/manifest.yaml b/spec_objects_security/manifest.yaml index a58f741..838573f 100644 --- a/spec_objects_security/manifest.yaml +++ b/spec_objects_security/manifest.yaml @@ -32,6 +32,7 @@ semantic: - soup_record - scope_exclusion - threat_model + - processing_activity imports: {} targets: [json-schema, markdown] mappings: [typed-table, sysml-fence, ocl-clause, record-sections] @@ -756,6 +757,58 @@ object_types: from: section_body after_heading: Properties required: false +- name: processing_activity + frontmatter_schema_ref: schemas/ProcessingActivityFrontmatter.json + allowed_links: + covers: [connection, data_sink, part] + data_schema: + schema: schemas/ProcessingActivity.json + body_extraction: + yield_pattern: + match: + id: *id004 + title: *id005 + type: *id006 + role: + from: frontmatter_field + path: [role] + required: true + controller: + from: frontmatter_field + path: [controller] + required: true + home_regions: + from: frontmatter_field + path: [home_regions] + required: true + processor: + from: frontmatter_field + path: [processor] + required: false + joint_controllers: + from: frontmatter_field + path: [joint_controllers] + required: false + representative: + from: frontmatter_field + path: [representative] + required: false + dpo_contact: + from: frontmatter_field + path: [dpo_contact] + required: false + purposes: + from: frontmatter_field + path: [purposes] + required: false + data_subject_categories: + from: frontmatter_field + path: [data_subject_categories] + required: false + retention: + from: frontmatter_field + path: [retention] + required: false # FR-043: concrete-term lexicon — security / identity / auth objects. # FR-058 (quire-rs): upward-trace completeness — the second half of @@ -784,6 +837,12 @@ traceability: to: [] direction: incoming check: untreated-risk + - name: processing-activity-covers-nothing + from: processing_activity + edges: [covers] + to: [connection, data_sink, part] + direction: outgoing + check: processing-activity-covers-nothing # `direction: incoming` throughout, because the mitigation is authored from # the control's or requirement's end — a control says what it mitigates. A # threat listing its own controls would duplicate the fact and let the two diff --git a/spec_objects_security/schemas/NonBlankText.json b/spec_objects_security/schemas/NonBlankText.json new file mode 100644 index 0000000..9c34fed --- /dev/null +++ b/spec_objects_security/schemas/NonBlankText.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json", + "type": "string", + "minLength": 1, + "description": "Non-empty person-authored text used for names, contacts, purposes and retention." +} diff --git a/spec_objects_security/schemas/ProcessingActivity.json b/spec_objects_security/schemas/ProcessingActivity.json new file mode 100644 index 0000000..f8c02da --- /dev/null +++ b/spec_objects_security/schemas/ProcessingActivity.json @@ -0,0 +1,129 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/ProcessingActivity.json", + "type": "object", + "properties": { + "role": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/ProcessingRole.json" + }, + "controller": { + "anyOf": [ + { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json" + }, + { + "type": "array", + "items": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json" + } + } + ] + }, + "home_regions": { + "type": "array", + "items": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/RegionCode.json" + }, + "minItems": 1 + }, + "processor": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json" + }, + "joint_controllers": { + "type": "array", + "items": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json" + }, + "minItems": 1 + }, + "representative": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json" + }, + "dpo_contact": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json" + }, + "purposes": { + "type": "array", + "items": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json" + }, + "minItems": 1 + }, + "data_subject_categories": { + "type": "array", + "items": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json" + }, + "minItems": 1 + }, + "retention": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json" + } + }, + "required": [ + "role", + "controller", + "home_regions" + ], + "unevaluatedProperties": { + "not": {} + }, + "description": "Processing activity declaration record; authored frontmatter is projected without defaults.", + "allOf": [ + { + "if": { + "properties": { + "role": { + "const": "controller" + } + }, + "required": [ + "role" + ] + }, + "then": { + "properties": { + "controller": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json" + } + }, + "required": [ + "purposes", + "data_subject_categories", + "retention" + ] + } + }, + { + "if": { + "properties": { + "role": { + "const": "processor" + } + }, + "required": [ + "role" + ] + }, + "then": { + "properties": { + "controller": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/NonBlankText.json" + } + } + }, + "required": [ + "processor" + ], + "not": { + "required": [ + "joint_controllers" + ] + } + } + } + ] +} diff --git a/spec_objects_security/schemas/ProcessingActivityFrontmatter.json b/spec_objects_security/schemas/ProcessingActivityFrontmatter.json new file mode 100644 index 0000000..3d0fc34 --- /dev/null +++ b/spec_objects_security/schemas/ProcessingActivityFrontmatter.json @@ -0,0 +1,142 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/ProcessingActivityFrontmatter.json", + "type": "object", + "properties": { + "role": { + "type": "string", + "enum": [ + "controller", + "processor" + ] + }, + "controller": { + "anyOf": [ + { + "type": "string", + "minLength": 1 + }, + { + "type": "array", + "items": { + "type": "string", + "minLength": 1 + } + } + ] + }, + "home_regions": { + "type": "array", + "items": { + "type": "string", + "pattern": "^([A-Z]{2}|eu|eea)$" + }, + "minItems": 1 + }, + "processor": { + "type": "string", + "minLength": 1 + }, + "joint_controllers": { + "type": "array", + "items": { + "type": "string", + "minLength": 1 + }, + "minItems": 1 + }, + "representative": { + "type": "string", + "minLength": 1 + }, + "dpo_contact": { + "type": "string", + "minLength": 1 + }, + "purposes": { + "type": "array", + "items": { + "type": "string", + "minLength": 1 + }, + "minItems": 1 + }, + "data_subject_categories": { + "type": "array", + "items": { + "type": "string", + "minLength": 1 + }, + "minItems": 1 + }, + "retention": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "role", + "controller", + "home_regions" + ], + "description": "Person-authored context for one covered processing activity (FR-028).", + "allOf": [ + { + "if": { + "properties": { + "role": { + "const": "controller" + } + }, + "required": [ + "role" + ] + }, + "then": { + "properties": { + "controller": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "purposes", + "data_subject_categories", + "retention" + ] + } + }, + { + "if": { + "properties": { + "role": { + "const": "processor" + } + }, + "required": [ + "role" + ] + }, + "then": { + "properties": { + "controller": { + "type": "array", + "minItems": 1, + "items": { + "type": "string", + "minLength": 1 + } + } + }, + "required": [ + "processor" + ], + "not": { + "required": [ + "joint_controllers" + ] + } + } + } + ] +} diff --git a/spec_objects_security/schemas/ProcessingRole.json b/spec_objects_security/schemas/ProcessingRole.json new file mode 100644 index 0000000..926c183 --- /dev/null +++ b/spec_objects_security/schemas/ProcessingRole.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/ProcessingRole.json", + "type": "string", + "enum": [ + "controller", + "processor" + ], + "description": "The role this activity plays for the processing it describes." +} diff --git a/spec_objects_security/schemas/RegionCode.json b/spec_objects_security/schemas/RegionCode.json new file mode 100644 index 0000000..33b4a76 --- /dev/null +++ b/spec_objects_security/schemas/RegionCode.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://schemas.agent-ix.org/agent-ix/spec-objects-security/RegionCode.json", + "type": "string", + "pattern": "^([A-Z]{2}|eu|eea)$", + "description": "Same location vocabulary as architecture's data_sink.region." +} diff --git a/spec_objects_security/skeletons/processing_activity.md b/spec_objects_security/skeletons/processing_activity.md new file mode 100644 index 0000000..c2aaca9 --- /dev/null +++ b/spec_objects_security/skeletons/processing_activity.md @@ -0,0 +1,44 @@ +--- +id: PA-001 +title: CustomerSupportProcessing +type: processing_activity +object: processing_activity +role: controller +controller: "Example Services Ltd; privacy@example.invalid" +purposes: + - "Respond to customer support requests" +data_subject_categories: + - "Customers" +retention: "Support records are retained for the documented support period." +home_regions: + - eu +relationships: + - target: CONN-001 + type: covers +--- + +# [PA-001] Customer support processing + +Describe the person-authored context that is not present in the flow model. +State what the activity covers, how the named purposes apply, and where the +declared relationships begin and end. List facts that are unavailable under +Gaps; do not infer a missing value from code, a sink name, or runtime behavior. diff --git a/tests/conftest.py b/tests/conftest.py index ff9990e..c05e513 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -105,6 +105,7 @@ def validation_module_args(security_module: pathlib.Path | None = None) -> list[ "soup_record", "scope_exclusion", "threat_model", + "processing_activity", ) MODEL_OF = { @@ -134,6 +135,7 @@ def validation_module_args(security_module: pathlib.Path | None = None) -> list[ "soup_record": "SoupRecord", "scope_exclusion": "ScopeExclusion", "threat_model": "ThreatModel", + "processing_activity": "ProcessingActivity", } MARKER_MODELS = ( @@ -213,7 +215,7 @@ def validation_module_args(security_module: pathlib.Path | None = None) -> list[ # `TrustBoundary` whose `trust_level` defaulted to `trusted`, and defaulted # grant rows on `role`, `permission` and `scope` all validated. The ticket gate # reads "No schema default grants permission, trust, or control effectiveness", -# so the guard is now on all twenty-six (FR-006). +# so the guard is now on every exported object type (FR-006). DEFAULT_REFUSING = OBJECT_TYPES FIELD_BEARING = ( diff --git a/tests/test_manifest.py b/tests/test_manifest.py index ce6a97a..64cfb51 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -112,6 +112,7 @@ def test_threat_and_risk_coverage_is_declared_not_coded() -> None: "security-nfr-has-mitigation-target", "soup-record-serves-requirement", "threat-model-covers-something", + "processing-activity-covers-nothing", } assert by_name["threat-has-control"]["from"] == "threat" assert by_name["risk-has-treatment"]["from"] == "risk" @@ -123,6 +124,7 @@ def test_threat_and_risk_coverage_is_declared_not_coded() -> None: "unjustified-security-nfr", "soup-serves-no-requirement", "threat-model-covers-nothing", + "processing-activity-covers-nothing", } assert len(checks) == len(by_name), "each relation is independently tunable" @@ -145,6 +147,9 @@ def test_threat_and_risk_coverage_is_declared_not_coded() -> None: elif name == "threat-model-covers-something": assert relation["from"] == "threat_model" assert relation["direction"] == "outgoing" + elif name == "processing-activity-covers-nothing": + assert relation["from"] == "processing_activity" + assert relation["direction"] == "outgoing" else: assert relation["direction"] == "incoming" assert relation["from"] in declared, relation["from"] diff --git a/tests/test_processing_activity.py b/tests/test_processing_activity.py new file mode 100644 index 0000000..054bca0 --- /dev/null +++ b/tests/test_processing_activity.py @@ -0,0 +1,270 @@ +"""Person-authored processing-activity contract (FR-028).""" + +from __future__ import annotations + +import json +import subprocess + +import pytest +import yaml +from conftest import ( + MANIFEST_PATH, + PACKAGE_ROOT, + SCHEMAS_DIR, + SKELETONS_DIR, + engine_tool, + validation_module_args, +) +from test_regulated_categories import _extract, _record + + +def run_bundle(tmp_path, activity: str, targets: dict[str, str]): + bundle = tmp_path / "bundle" + bundle.mkdir() + (bundle / "activity.md").write_text(activity) + for name, text in targets.items(): + (bundle / name).write_text(text) + return subprocess.run( + [ + engine_tool("quire"), + "validate", + "--okf", + *validation_module_args(PACKAGE_ROOT), + str(bundle), + ], + capture_output=True, + text=True, + ) + + +def target_doc(kind: str, ident: str) -> str: + return ( + "---\n" + f"id: {ident}\n" + f"title: {ident}\n" + f"type: {kind}\n" + f"object: {kind}\n" + "---\n" + f"# {ident}\n" + ) + + +@pytest.mark.trace("TC-248", "FR-028-AC-1", "TC-254", "FR-028-AC-7") +def test_controller_skeleton_with_covered_connection_validates(tmp_path): + skeleton = (SKELETONS_DIR / "processing_activity.md").read_text() + result = run_bundle( + tmp_path, + skeleton, + {"connection.md": target_doc("connection", "CONN-001")}, + ) + assert result.returncode == 0, result.stdout + result.stderr + + +def frontmatter_doc(**changes) -> str: + values = { + "id": "PA-001", + "title": '"Customer support processing"', + "type": "processing_activity", + "object": "processing_activity", + "role": "controller", + "controller": '"Controller; privacy@example.invalid"', + "purposes": '["provide support"]', + "data_subject_categories": '["customers"]', + "retention": '"support period"', + "home_regions": "[eu]", + "relationships": "\n - target: CONN-001\n type: covers", + } + values.update(changes) + fields = "".join(f"{key}: {value}\n" for key, value in values.items()) + return f"---\n{fields}---\n# Processing activity\n" + + +@pytest.mark.trace("TC-248", "FR-028-AC-1") +def test_controller_activity_record_requires_scalar_identity_and_context( + schema_registry, +): + record = { + "role": "controller", + "controller": "Controller; privacy@example.invalid", + "purposes": ["provide support"], + "data_subject_categories": ["customers"], + "retention": "support period", + "home_regions": ["eu"], + } + validator = schema_registry("ProcessingActivity") + assert validator.is_valid(record) + assert not validator.is_valid({**record, "controller": [record["controller"]]}) + + +@pytest.mark.trace("TC-249", "FR-028-AC-2") +def test_processor_activity_accepts_nonempty_controller_list_without_controller_context( + schema_registry, +): + record = { + "role": "processor", + "processor": "Processor; privacy@example.invalid", + "controller": ["Controller; privacy@example.invalid"], + "home_regions": ["eea"], + } + assert schema_registry("ProcessingActivityFrontmatter").is_valid(record) + assert schema_registry("ProcessingActivity").is_valid(record) + assert not {"purposes", "data_subject_categories", "retention"} & set(record) + + +@pytest.mark.trace("TC-250", "FR-028-AC-3") +def test_missing_role_specific_fields_fail_with_field_named_schema_errors( + schema_registry, +): + validator = schema_registry("ProcessingActivityFrontmatter") + controller = { + "role": "controller", + "controller": "Controller; privacy@example.invalid", + "data_subject_categories": ["customers"], + "home_regions": ["US"], + } + errors = list(validator.iter_errors(controller)) + assert any("purposes" in error.message for error in errors), errors + processor = { + "role": "processor", + "controller": [], + "home_regions": ["US"], + } + errors = list(validator.iter_errors(processor)) + assert any("processor" in error.message for error in errors), errors + assert any(error.json_path.startswith("$.controller") for error in errors), errors + + +@pytest.mark.trace("TC-251", "FR-028-AC-4") +def test_unknown_role_and_invalid_home_regions_fail_naming_the_field(schema_registry): + validator = schema_registry("ProcessingActivityFrontmatter") + valid = { + "role": "controller", + "controller": "Controller; privacy@example.invalid", + "purposes": ["provide support"], + "data_subject_categories": ["customers"], + "retention": "support period", + "home_regions": ["US"], + } + for key, value in ( + ("role", "unknown"), + ("home_regions", []), + ("home_regions", ["usa"]), + ): + errors = list(validator.iter_errors({**valid, key: value})) + assert errors, (key, value) + assert any( + key in error.message or key in error.json_path for error in errors + ), errors + + +@pytest.mark.trace("TC-252", "FR-028-AC-5") +def test_missing_covers_edge_emits_located_advisory_warning(tmp_path): + skeleton = (SKELETONS_DIR / "processing_activity.md").read_text() + skeleton = skeleton.replace( + "relationships:\n - target: CONN-001\n type: covers\n", "" + ) + result = run_bundle( + tmp_path, + skeleton, + {"connection.md": target_doc("connection", "CONN-001")}, + ) + assert result.returncode == 0, result.stdout + result.stderr + output = result.stdout + result.stderr + assert "activity.md" in output + assert "processing-activity-covers-nothing" in output + assert "has no 'covers' edge" in output + + +@pytest.mark.trace("TC-253", "FR-028-AC-6") +@pytest.mark.parametrize( + ("target", "kind", "expected"), + [("QUEUE-001", "queue", "disallowed"), ("MISSING-1", None, "dangling")], +) +def test_invalid_covers_target_reports_wrong_kind_or_dangling( + tmp_path, target, kind, expected +): + skeleton = ( + (SKELETONS_DIR / "processing_activity.md") + .read_text() + .replace("CONN-001", target) + ) + targets = {"target.md": target_doc(kind, target)} if kind else {} + result = run_bundle(tmp_path, skeleton, targets) + output = result.stdout + result.stderr + assert expected in output.lower(), output + + +@pytest.mark.trace("TC-254", "FR-028-AC-7") +def test_manifest_exports_schema_and_skeleton_for_processing_activity(): + manifest = yaml.safe_load(MANIFEST_PATH.read_text()) + assert "processing_activity" in manifest["semantic"]["exports"] + declared = next( + o for o in manifest["object_types"] if o["name"] == "processing_activity" + ) + assert declared["frontmatter_schema_ref"] == ( + "schemas/ProcessingActivityFrontmatter.json" + ) + assert declared["data_schema"]["schema"] == "schemas/ProcessingActivity.json" + assert declared["allowed_links"]["covers"] == ["connection", "data_sink", "part"] + required = manifest["traceability"]["required_relations"] + assert any( + item["from"] == "processing_activity" + and item["edges"] == ["covers"] + and item["to"] == ["connection", "data_sink", "part"] + for item in required + ) + assert (SCHEMAS_DIR / "ProcessingActivity.json").is_file() + assert (SCHEMAS_DIR / "ProcessingActivityFrontmatter.json").is_file() + assert (SKELETONS_DIR / "processing_activity.md").is_file() + for name in ("ProcessingActivityFrontmatter", "DataClassificationFrontmatter"): + schema = json.loads((SCHEMAS_DIR / f"{name}.json").read_text()) + assert '"$ref"' not in json.dumps(schema), name + result = subprocess.run( + ["node", "scripts/generate-schemas.mjs", "--check"], + cwd=PACKAGE_ROOT.parent, + capture_output=True, + text=True, + ) + assert result.returncode == 0, result.stdout + result.stderr + + +@pytest.mark.trace("TC-255", "FR-028-AC-8") +def test_omitted_optional_processor_fields_are_absent_from_extracted_record( + quire_engine, semantic_block, semantic_module, bundle_index +): + markdown = frontmatter_doc( + role="processor", + controller='["Controller; privacy@example.invalid"]', + processor='"Processor; privacy@example.invalid"', + purposes=None, + data_subject_categories=None, + retention=None, + joint_controllers=None, + representative=None, + dpo_contact=None, + ) + markdown = "\n".join( + line for line in markdown.splitlines() if not line.endswith(": None") + ) + output = _extract( + quire_engine, + semantic_block, + semantic_module, + "processing-activity.md", + text=markdown, + kind="processing_activity", + bundle=bundle_index, + ) + record = _record(output) + assert record.get("role") == "processor" + assert record.get("controller") == ["Controller; privacy@example.invalid"] + assert record.get("processor") == "Processor; privacy@example.invalid" + for key in ( + "purposes", + "data_subject_categories", + "retention", + "joint_controllers", + "representative", + "dpo_contact", + ): + assert key not in record, (key, record) diff --git a/tests/test_regulated_categories.py b/tests/test_regulated_categories.py index 4fdd623..474fa8b 100644 --- a/tests/test_regulated_categories.py +++ b/tests/test_regulated_categories.py @@ -13,8 +13,7 @@ import pathlib import pytest - -from tests.conftest import ( +from conftest import ( PACKAGE_ROOT, SCHEMAS_DIR, field, @@ -118,6 +117,14 @@ def test_the_vocabulary_is_exactly_health_personal_financial(): assert "unknown" not in schema["enum"] +@pytest.mark.trace("TC-206", "FR-023-AC-5") +def test_frontmatter_category_enum_is_self_contained_for_quires_validator(): + frontmatter_schema = _schema("DataClassificationFrontmatter") + categories = frontmatter_schema["properties"]["regulated_categories"] + assert categories["items"]["enum"] == MEMBERS + assert "$ref" not in categories["items"] + + @pytest.mark.trace("TC-207", "FR-023-AC-1", "NFR-004-AC-1", "NFR-004-M-1") def test_the_property_is_an_optional_non_empty_unique_list_without_default(): schema = _schema("DataClassification") diff --git a/tests/test_role_schemas.py b/tests/test_role_schemas.py index f3754c7..624b138 100644 --- a/tests/test_role_schemas.py +++ b/tests/test_role_schemas.py @@ -232,6 +232,12 @@ def test_the_empty_record_fails_every_type(schema_registry): "method": "stride_per_element", "reviewed_by": "A. Person", }, + "ProcessingActivity": { + "role": "processor", + "processor": "Processor; privacy@example.invalid", + "controller": ["Controller; privacy@example.invalid"], + "home_regions": ["eu"], + }, "ScopeExclusion": { "set": "example.invalid/std@1", "clause": "EX-1", diff --git a/tests/test_security_rules.py b/tests/test_security_rules.py index 30306dc..ae39a02 100644 --- a/tests/test_security_rules.py +++ b/tests/test_security_rules.py @@ -186,7 +186,7 @@ def test_no_shipped_schema_carries_a_default_keyword(): @pytest.mark.trace("TC-073", "FR-006-AC-4", "FR-006-CON-2") def test_no_declaration_admits_a_defaulted_field_or_param(schema_registry): - """Every one of the twenty-six types, not only the sensitive four. + """Every exported type, not only the sensitive four. The rule began on `secret`, `encryption_key`, `jwt_claim` and `csrf_token`, which left it off exactly the rows that grant: a `Control` whose diff --git a/tests/test_skeletons_and_validate.py b/tests/test_skeletons_and_validate.py index 18931f1..e430ff4 100644 --- a/tests/test_skeletons_and_validate.py +++ b/tests/test_skeletons_and_validate.py @@ -144,7 +144,7 @@ def test_frontmatter_matches_manifest_locators(name: str) -> None: assert fm["type"] == name assert fm["id"] and fm["title"] assert fm["object"] == name, f"{name}: frontmatter `object` must equal `type`" - undeclared = set(fm) - declared_fields - {"object"} + undeclared = set(fm) - declared_fields - {"object", "relationships"} assert not undeclared, f"{name}: undeclared frontmatter keys {undeclared}" diff --git a/tests/test_threat_model.py b/tests/test_threat_model.py index aba1e02..fe7c445 100644 --- a/tests/test_threat_model.py +++ b/tests/test_threat_model.py @@ -329,10 +329,9 @@ def test_manifest_declares_the_verbs_and_the_link_targets(): @pytest.mark.trace("TC-243", "FR-026-AC-10") -def test_threat_model_is_the_twenty_sixth_export(): +def test_threat_model_remains_exported(): manifest = yaml.safe_load(MANIFEST_PATH.read_text()) assert "threat_model" in manifest["semantic"]["exports"] - assert len(manifest["semantic"]["exports"]) == 26 @pytest.mark.trace("TC-227", "FR-026-AC-2") diff --git a/typespec/main.tsp b/typespec/main.tsp index fb45aee..704a239 100644 --- a/typespec/main.tsp +++ b/typespec/main.tsp @@ -195,6 +195,68 @@ enum MfaFactorKind { `unknown`, } +/** The role this activity plays for the processing it describes. */ +enum ProcessingRole { + controller, + processor, +} + +/** Non-empty person-authored text used for names, contacts, purposes and retention. */ +@minLength(1) +scalar NonBlankText extends string; + +/** Same location vocabulary as architecture's data_sink.region. */ +@pattern("^([A-Z]{2}|eu|eea)$") +scalar RegionCode extends string; + +/** Person-authored context for one covered processing activity (FR-028). */ +@extension( + "allOf", + #[ + #{ `if`: #{ `properties`: #{ role: #{ `const`: "controller" } }, `required`: #["role"] }, + `then`: #{ `properties`: #{ controller: #{ `$ref`: "NonBlankText.json" } }, `required`: #["purposes", "data_subject_categories", "retention"] } }, + #{ `if`: #{ `properties`: #{ role: #{ `const`: "processor" } }, `required`: #["role"] }, + `then`: #{ `properties`: #{ controller: #{ `type`: "array", `minItems`: 1, `items`: #{ `$ref`: "NonBlankText.json" } } }, `required`: #["processor"], `not`: #{ `required`: #["joint_controllers"] } } } + ] +) +model ProcessingActivityFrontmatter { + role: ProcessingRole; + controller: NonBlankText | NonBlankText[]; + @minItems(1) + home_regions: RegionCode[]; + processor?: NonBlankText; + @minItems(1) joint_controllers?: NonBlankText[]; + representative?: NonBlankText; + dpo_contact?: NonBlankText; + @minItems(1) purposes?: NonBlankText[]; + @minItems(1) data_subject_categories?: NonBlankText[]; + retention?: NonBlankText; +} + +/** Processing activity declaration record; authored frontmatter is projected without defaults. */ +@extension( + "allOf", + #[ + #{ `if`: #{ `properties`: #{ role: #{ `const`: "controller" } }, `required`: #["role"] }, + `then`: #{ `properties`: #{ controller: #{ `$ref`: "NonBlankText.json" } }, `required`: #["purposes", "data_subject_categories", "retention"] } }, + #{ `if`: #{ `properties`: #{ role: #{ `const`: "processor" } }, `required`: #["role"] }, + `then`: #{ `properties`: #{ controller: #{ `type`: "array", `minItems`: 1, `items`: #{ `$ref`: "NonBlankText.json" } } }, `required`: #["processor"], `not`: #{ `required`: #["joint_controllers"] } } } + ] +) +model ProcessingActivity { + role: ProcessingRole; + controller: NonBlankText | NonBlankText[]; + @minItems(1) home_regions: RegionCode[]; + processor?: NonBlankText; + @minItems(1) joint_controllers?: NonBlankText[]; + representative?: NonBlankText; + dpo_contact?: NonBlankText; + @minItems(1) purposes?: NonBlankText[]; + @minItems(1) data_subject_categories?: NonBlankText[]; + retention?: NonBlankText; + ...Record; +} + // --------------------------------------------------------------------------- // Support records // ---------------------------------------------------------------------------