@dataparade/cli 0.0.35 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/README.md +1 -0
  2. package/dist/package.json +4 -4
  3. package/dist/src/ai-enrichment/pii-signal-rules.d.ts +5 -0
  4. package/dist/src/ai-enrichment/pii-signal-rules.js +2 -3
  5. package/dist/src/ai-enrichment/provider-prompt.js +1 -0
  6. package/dist/src/ai-enrichment/providers/provider-contract.js +2 -44
  7. package/dist/src/ai-enrichment/third-party-data-flow.js +5 -4
  8. package/dist/src/cli.js +9 -3
  9. package/dist/src/discoveries/contract/ocsf-discovery-record.d.ts +4 -1
  10. package/dist/src/discoveries/contract/ocsf-discovery-record.js +1 -1
  11. package/dist/src/discoveries/contract/ontology-pins.d.ts +6 -4
  12. package/dist/src/discoveries/contract/ontology-pins.js +7 -5
  13. package/dist/src/facts/build-facts.d.ts +2 -0
  14. package/dist/src/facts/build-facts.js +18 -0
  15. package/dist/src/facts/layout.d.ts +4 -0
  16. package/dist/src/facts/layout.js +5 -1
  17. package/dist/src/facts/scan-stamps.d.ts +7 -0
  18. package/dist/src/facts/scan-stamps.js +30 -0
  19. package/dist/src/facts/schema.d.ts +178 -0
  20. package/dist/src/facts/schema.js +37 -1
  21. package/dist/src/kb/data-category-catalog.generated.d.ts +34 -0
  22. package/dist/src/kb/data-category-catalog.generated.js +962 -0
  23. package/dist/src/kb/kb-store.js +4 -1
  24. package/dist/src/kb/migrate.js +4 -2
  25. package/dist/src/kb/slot-shapes.d.ts +3 -2
  26. package/dist/src/kb/slot-shapes.js +13 -8
  27. package/dist/src/kb/taxonomy.d.ts +12 -6
  28. package/dist/src/kb/taxonomy.js +13 -18
  29. package/dist/src/output/scan-output-excludes.js +2 -0
  30. package/dist/src/output/write-scan-knowledge.d.ts +5 -1
  31. package/dist/src/output/write-scan-knowledge.js +21 -0
  32. package/dist/src/threat-model/build-threat-model.d.ts +3 -0
  33. package/dist/src/threat-model/build-threat-model.js +71 -0
  34. package/dist/src/threat-model/carry-forward-person-set-statuses.d.ts +8 -0
  35. package/dist/src/threat-model/carry-forward-person-set-statuses.js +87 -0
  36. package/dist/src/threat-model/io.d.ts +19 -0
  37. package/dist/src/threat-model/io.js +63 -0
  38. package/dist/src/threat-model/schema.d.ts +214 -0
  39. package/dist/src/threat-model/schema.js +75 -0
  40. package/dist/src/ui/scan-progress-renderer.d.ts +8 -1
  41. package/dist/src/ui/scan-progress-renderer.js +20 -1
  42. package/dist/src/upload/collect-scan-sidecars.d.ts +2 -1
  43. package/dist/src/upload/collect-scan-sidecars.js +3 -1
  44. package/dist/tests/cli/cli.spec.js +10 -1
  45. package/dist/tests/helpers/facts-fixture.js +16 -16
  46. package/dist/tests/schema/scan-result.schema.spec.js +1 -1
  47. package/dist/tests/unit/ai-enrichment/provider-contract.spec.js +1 -1
  48. package/dist/tests/unit/ai-enrichment/third-party-data-flow.spec.js +5 -5
  49. package/dist/tests/unit/core/graph-mapping.spec.js +4 -3
  50. package/dist/tests/unit/discoveries/write-ocsf-discoveries-long-ids.spec.js +3 -3
  51. package/dist/tests/unit/export/export-ocsf.spec.js +4 -4
  52. package/dist/tests/unit/facts/apply-answers.spec.js +20 -20
  53. package/dist/tests/unit/facts/build-facts.spec.js +143 -45
  54. package/dist/tests/unit/facts/identity.spec.js +13 -0
  55. package/dist/tests/unit/facts/scan-stamps.spec.js +32 -0
  56. package/dist/tests/unit/facts/slug.spec.js +2 -0
  57. package/dist/tests/unit/kb/answer-fingerprint.spec.js +9 -9
  58. package/dist/tests/unit/kb/data-category-catalog.spec.d.ts +1 -0
  59. package/dist/tests/unit/kb/data-category-catalog.spec.js +65 -0
  60. package/dist/tests/unit/kb/kb-interview-loop.spec.js +8 -7
  61. package/dist/tests/unit/kb/migrate.spec.js +2 -2
  62. package/dist/tests/unit/output/scan-output-excludes.spec.js +1 -1
  63. package/dist/tests/unit/threat-model/build-threat-model.spec.d.ts +1 -0
  64. package/dist/tests/unit/threat-model/build-threat-model.spec.js +189 -0
  65. package/dist/tests/unit/threat-model/carry-forward-person-set-statuses.spec.d.ts +1 -0
  66. package/dist/tests/unit/threat-model/carry-forward-person-set-statuses.spec.js +163 -0
  67. package/dist/tests/unit/threat-model/io.spec.d.ts +1 -0
  68. package/dist/tests/unit/threat-model/io.spec.js +103 -0
  69. package/dist/tests/unit/threat-model/schema.spec.d.ts +1 -0
  70. package/dist/tests/unit/threat-model/schema.spec.js +42 -0
  71. package/dist/tests/unit/ui/scan-progress-renderer.spec.js +58 -0
  72. package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +8 -5
  73. package/dist/vendor/scanner/dist/src/analyze/code-navigator.d.ts +1 -1
  74. package/dist/vendor/scanner/dist/src/analyze/code-navigator.js +4 -0
  75. package/dist/vendor/scanner/dist/src/analyze/column-catalog.d.ts +1 -1
  76. package/dist/vendor/scanner/dist/src/analyze/column-catalog.js +2 -2
  77. package/dist/vendor/scanner/dist/src/analyze/concept-profile.d.ts +2 -2
  78. package/dist/vendor/scanner/dist/src/analyze/concept-profile.js +5 -3
  79. package/dist/vendor/scanner/dist/src/core/pipeline/build-scan-personal-data-layers.js +1 -1
  80. package/dist/vendor/scanner/dist/src/core/pipeline/deterministic-scan.js +43 -0
  81. package/dist/vendor/scanner/dist/src/core/pipeline/graph-mapping.js +23 -2
  82. package/dist/vendor/scanner/dist/src/core/pipeline/mixed-app-terraform-scan.js +1 -0
  83. package/dist/vendor/scanner/dist/src/core/pipeline/orchestrator-result.d.ts +2 -2
  84. package/dist/vendor/scanner/dist/src/core/pipeline/terraform-minimal-services.js +1 -0
  85. package/dist/vendor/scanner/dist/src/core/schema/scan-result.schema.d.ts +160 -2
  86. package/dist/vendor/scanner/dist/src/core/schema/scan-result.schema.js +24 -0
  87. package/dist/vendor/scanner/dist/src/core/types/data-flow.d.ts +48 -0
  88. package/dist/vendor/scanner/dist/src/core/types/data-flow.js +53 -0
  89. package/dist/vendor/scanner/dist/src/data-flow/detect.js +1 -0
  90. package/dist/vendor/scanner/dist/src/data-flow/ensure-hub-linked-assets.js +1 -0
  91. package/dist/vendor/scanner/dist/src/data-flow/ensure-manifest-declared-flows.js +1 -0
  92. package/dist/vendor/scanner/dist/src/data-flow/flow-authentication.d.ts +30 -0
  93. package/dist/vendor/scanner/dist/src/data-flow/flow-authentication.js +277 -0
  94. package/dist/vendor/scanner/dist/src/data-flow/flow-builder.js +6 -0
  95. package/dist/vendor/scanner/dist/src/data-flow/flow-controls.d.ts +24 -0
  96. package/dist/vendor/scanner/dist/src/data-flow/flow-controls.js +238 -0
  97. package/dist/vendor/scanner/dist/src/data-flow/flow-data-categories.d.ts +22 -0
  98. package/dist/vendor/scanner/dist/src/data-flow/flow-data-categories.js +69 -0
  99. package/dist/vendor/scanner/dist/src/data-flow/flow-interaction-description.d.ts +13 -0
  100. package/dist/vendor/scanner/dist/src/data-flow/flow-interaction-description.js +263 -0
  101. package/dist/vendor/scanner/dist/src/data-flow/hub-link-policy.d.ts +2 -1
  102. package/dist/vendor/scanner/dist/src/data-flow/hub-link-policy.js +3 -0
  103. package/dist/vendor/scanner/dist/src/data-flow/human-interaction-channels.d.ts +37 -0
  104. package/dist/vendor/scanner/dist/src/data-flow/human-interaction-channels.js +483 -0
  105. package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.d.ts +3 -0
  106. package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.js +12 -17
  107. package/dist/vendor/scanner/dist/src/data-flow/terraform-flows.js +5 -1
  108. package/dist/vendor/scanner/dist/src/data-flow/transformation-patterns.d.ts +5 -1
  109. package/dist/vendor/scanner/dist/src/data-flow/transformation-patterns.js +17 -37
  110. package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.d.ts +36 -5
  111. package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.js +53 -60
  112. package/dist/vendor/scanner/dist/src/eval/canonical/graph/endpoints.js +2 -9
  113. package/dist/vendor/scanner/dist/src/eval/canonical/scanner/personal-data.js +10 -7
  114. package/dist/vendor/scanner/dist/src/graph/build-dataparade-graph.js +3 -1
  115. package/dist/vendor/scanner/dist/src/index.d.ts +6 -0
  116. package/dist/vendor/scanner/dist/src/index.js +16 -1
  117. package/dist/vendor/scanner/dist/src/patterns/engine.js +1 -0
  118. package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.d.ts +1 -1
  119. package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.js +2 -2
  120. package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.d.ts +3 -3
  121. package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.js +12 -11
  122. package/dist/vendor/scanner/dist/src/pii-signals/personal-data-taxonomy.d.ts +44 -0
  123. package/dist/vendor/scanner/dist/src/pii-signals/personal-data-taxonomy.js +167 -0
  124. package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-aliases.js +43 -43
  125. package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-rules.d.ts +12 -1
  126. package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-rules.js +28 -7
  127. package/dist/vendor/scanner/dist/src/pii-signals/signal-token.js +1 -1
  128. package/dist/vendor/scanner/dist/src/threats/stride.d.ts +98 -0
  129. package/dist/vendor/scanner/dist/src/threats/stride.js +179 -0
  130. package/dist/vendor/scanner/package.json +2 -2
  131. package/dist/vendor/scanner/patterns/concept-profiles.yaml +2 -2
  132. package/dist/vendor/scanner/patterns/flow-authentication.rules.yaml +75 -0
  133. package/dist/vendor/scanner/patterns/flow-controls.rules.yaml +68 -0
  134. package/dist/vendor/scanner/patterns/personal-data-taxonomy.yaml +155 -0
  135. package/dist/vendor/scanner/patterns/pii-signals.rules.yaml +38 -49
  136. package/dist/vendor/scanner/patterns/stride.rules.yaml +86 -0
  137. package/package.json +4 -4
  138. package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.validate.d.ts +0 -17
  139. package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.validate.js +0 -108
  140. package/dist/vendor/scanner/patterns/personal-data-concept-map.yaml +0 -76
@@ -17,7 +17,7 @@ const REVIEWER = "dev@example.com";
17
17
  function rescan(paths, keepFlows = ["flow_mail", "flow_login"]) {
18
18
  const { facts, files } = (0, facts_fixture_1.sampleFacts)();
19
19
  facts.dataFlows = facts.dataFlows.filter((f) => keepFlows.includes(f.id));
20
- (0, io_1.writeFactsOutput)(paths, facts, new Map(files.map((file) => [`data-items/${file.name}.json`, file])));
20
+ (0, io_1.writeFactsOutput)(paths, facts, new Map(files.map((file) => [facts.dataItems.find((item) => item.id === file.id).file, file])));
21
21
  }
22
22
  describe("live interview loop: brief → land → project", () => {
23
23
  let paths;
@@ -51,7 +51,7 @@ describe("live interview loop: brief → land → project", () => {
51
51
  const sendgrid = { kind: "component", key: "app:<unsectioned>|third_party||src/mail.ts|sendgrid", parts: { name: "sendgrid" } };
52
52
  facts.dataFlows = facts.dataFlows.map((f) => (f.id === "flow_mail" ? { ...f, identity: mail } : f));
53
53
  facts.components = facts.components.map((c) => (c.id === "cmp_mail" ? { ...c, identity: sendgrid } : c));
54
- (0, io_1.writeFactsOutput)(paths, facts, new Map(files.map((file) => [`data-items/${file.name}.json`, file])));
54
+ (0, io_1.writeFactsOutput)(paths, facts, new Map(files.map((file) => [facts.dataItems.find((item) => item.id === file.id).file, file])));
55
55
  const { brief, sha } = (0, brief_1.writeKbBrief)(paths);
56
56
  const flow = brief.flows.find((f) => f.id === "flow_mail");
57
57
  expect(flow.identity).toEqual(mail);
@@ -62,7 +62,7 @@ describe("live interview loop: brief → land → project", () => {
62
62
  });
63
63
  it("lands confirmed answers and projects them onto the diagram", () => {
64
64
  const { sha } = (0, brief_1.writeKbBrief)(paths);
65
- land(sha, "flow_mail", "data_categories", "contact, identifiers");
65
+ land(sha, "flow_mail", "data_categories", "pd:EmailAddress, dpx:AccessToken");
66
66
  land(sha, "flow_mail", "purpose", "service_provision");
67
67
  land(sha, "cmp_user", "actor_kind", "persona");
68
68
  land(sha, "dp:a0/system", "in_scope", "The DataParade web app and its backend");
@@ -72,7 +72,7 @@ describe("live interview loop: brief → land → project", () => {
72
72
  const { wrapper } = (0, project_diagram_1.writeKbDiagram)(paths, { projectName: "DataParade" });
73
73
  const mail = wrapper.graph.edges.find((e) => e.id === "flow_mail");
74
74
  expect(mail.data.privacy).toMatchObject({
75
- dataCategories: ["contact", "identifiers"],
75
+ dataCategories: ["dpx:AccessToken", "pd:EmailAddress"],
76
76
  purpose: "service_provision",
77
77
  slotStatus: "known",
78
78
  openSlots: [],
@@ -97,6 +97,7 @@ describe("live interview loop: brief → land → project", () => {
97
97
  it.each([
98
98
  ["an invented category", "flow_mail", "data_categories", "emails", {}, /unknown data category/],
99
99
  ["unspecified as a category", "flow_mail", "data_categories", "unspecified", {}, /no 'unspecified'/],
100
+ ["a well-formed concept outside the catalog", "flow_mail", "data_categories", "pd:Invented", {}, /unknown data category/],
100
101
  ["a purpose outside the enum", "flow_mail", "purpose", "billing", {}, /purpose must be one of/],
101
102
  ["two actor kinds", "cmp_user", "actor_kind", "Customer (persona)", {}, /exactly one of/],
102
103
  ["a scan-owned slot", "cmp_mail", "name", "SendGrid Inc", {}, /can't land from an interview/],
@@ -135,7 +136,7 @@ describe("live interview loop: brief → land → project", () => {
135
136
  });
136
137
  it("stores the who, when and evidence of an interview answer, with a category list as a list", () => {
137
138
  const { sha } = (0, brief_1.writeKbBrief)(paths);
138
- const landed = land(sha, "flow_mail", "data_categories", "identifiers, contact", { now: new Date("2026-10-10T12:00:00.000Z") });
139
+ const landed = land(sha, "flow_mail", "data_categories", "identifiers, contact, pd:Password", { now: new Date("2026-10-10T12:00:00.000Z") });
139
140
  expect(landed.path).toBe(paths.answersPath);
140
141
  expect((0, io_1.readAnswers)(paths).answers).toEqual([
141
142
  {
@@ -143,7 +144,7 @@ describe("live interview loop: brief → land → project", () => {
143
144
  factId: "flow_mail",
144
145
  action: "set",
145
146
  property: "data_categories",
146
- value: ["contact", "identifiers"],
147
+ value: ["pd:Contact", "pd:Identifying", "pd:Password"],
147
148
  by: REVIEWER,
148
149
  at: "2026-10-10T12:00:00.000Z",
149
150
  source: "interview",
@@ -178,7 +179,7 @@ describe("live interview loop: brief → land → project", () => {
178
179
  expect((0, brief_1.writeKbBrief)(paths).brief.flows.map((f) => f.id)).toEqual(["flow_mail"]);
179
180
  });
180
181
  it("reads a JSON value for lists", () => {
181
- review({ target: "data_item:email", property: "labels", value: '["contact","pii"]' });
182
+ review({ target: "data_item:pd:EmailAddress", property: "labels", value: '["contact","pii"]' });
182
183
  expect((0, kb_store_1.loadKbState)(paths).applied.facts.dataItems[0].labels).toEqual(["contact", "pii"]);
183
184
  });
184
185
  it.each([
@@ -69,14 +69,14 @@ describe("kb migrate", () => {
69
69
  briefSha: SHA,
70
70
  skillSha: SHA,
71
71
  });
72
- expect(answers.find((a) => a.property === "data_categories")?.value).toEqual(["contact"]);
72
+ expect(answers.find((a) => a.property === "data_categories")?.value).toEqual(["pd:Contact"]);
73
73
  expect(JSON.stringify(answers)).not.toContain(SCAN_PATH);
74
74
  });
75
75
  it("makes the old answers show up in the applied state", () => {
76
76
  (0, migrate_1.migrateInterviewRecords)(paths);
77
77
  const flow = (0, kb_store_1.loadKbState)(paths).applied.facts.dataFlows.find((f) => f.id === "flow_mail");
78
78
  expect(flow.purpose).toBe("marketing");
79
- expect(flow.data_categories).toEqual(["contact"]);
79
+ expect(flow.data_categories).toEqual(["pd:Contact"]);
80
80
  });
81
81
  it("is safe to run twice", () => {
82
82
  (0, migrate_1.migrateInterviewRecords)(paths);
@@ -8,7 +8,7 @@ describe("scanOutputExcludes", () => {
8
8
  });
9
9
  it("excludes the scan's own outputs when writing to the repo root", () => {
10
10
  const globs = (0, scan_output_excludes_1.scanOutputExcludes)("/repo", "/repo/dataflow.json");
11
- expect(globs).toEqual(expect.arrayContaining(["dataflow.json", "facts.json", "data-items/**", "graphify.json", "answers.json", "briefs/**", "evidence/**"]));
11
+ expect(globs).toEqual(expect.arrayContaining(["dataflow.json", "facts.json", "threat-model.json", "threat-model.unreadable.json", "data-items/**", "graphify.json", "answers.json", "briefs/**", "evidence/**"]));
12
12
  // Output of CLI 0.0.26 and earlier is still kept out of a rescan.
13
13
  expect(globs).toEqual(expect.arrayContaining(["ocsf-discoveries/**", "graphify-out/**", "dataparade-graph.json"]));
14
14
  });
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const build_threat_model_1 = require("../../../src/threat-model/build-threat-model");
4
+ const schema_1 = require("../../../src/threat-model/schema");
5
+ const apiComponent = {
6
+ id: "cmp_api",
7
+ identity: { kind: "component", key: "app:<unsectioned>|asset|service|src/api.ts|api", parts: {} },
8
+ name: "api",
9
+ type: "asset",
10
+ subType: "service",
11
+ confidence: 1,
12
+ sourceLocations: [],
13
+ codeRefs: [],
14
+ };
15
+ const mailComponent = {
16
+ id: "cmp_mail",
17
+ name: "mail",
18
+ type: "third_party",
19
+ subType: "",
20
+ confidence: 1,
21
+ sourceLocations: [],
22
+ codeRefs: [],
23
+ };
24
+ const databaseComponent = {
25
+ id: "cmp_db",
26
+ name: "db",
27
+ type: "asset",
28
+ subType: "database",
29
+ confidence: 1,
30
+ sourceLocations: [],
31
+ codeRefs: [],
32
+ };
33
+ function mailFlowWith(overrides = {}) {
34
+ return {
35
+ id: "flow_mail",
36
+ identity: { kind: "dataFlow", key: "flow-key", parts: {} },
37
+ sourceComponentId: "cmp_api",
38
+ targetComponentId: "cmp_mail",
39
+ type: "api_call",
40
+ confidence: 1,
41
+ sourceLocations: [],
42
+ codeRefs: [],
43
+ ...overrides,
44
+ };
45
+ }
46
+ function factsWith(dataFlows, scanOverrides = {}) {
47
+ return {
48
+ schemaVersion: 1,
49
+ scan: {
50
+ projectName: "shop",
51
+ scannedAt: "2026-10-09T00:00:00.000Z",
52
+ cliVersion: "0.0.36",
53
+ scannerVersion: "abc",
54
+ ...scanOverrides,
55
+ },
56
+ components: [apiComponent, mailComponent, databaseComponent],
57
+ dataFlows,
58
+ dataItems: [],
59
+ relations: [],
60
+ };
61
+ }
62
+ function categoriesOfElement(threatModel, elementId) {
63
+ return threatModel.threats
64
+ .filter((threat) => threat.elementId === elementId)
65
+ .map((threat) => threat.category)
66
+ .join("");
67
+ }
68
+ function findThreat(threatModel, elementId, category) {
69
+ return threatModel.threats.find((threat) => threat.elementId === elementId && threat.category === category);
70
+ }
71
+ const flowWithTlsAndTimeoutControls = mailFlowWith({
72
+ controls: [
73
+ { control: "tls", effect: "mitigates", filePath: "src/api.ts", line: 2 },
74
+ { control: "timeout", effect: "mitigates", filePath: "src/api.ts", line: 5 },
75
+ ],
76
+ authentication: { status: "none_seen", kinds: [], evidence: [] },
77
+ });
78
+ describe("buildThreatModel", () => {
79
+ it("gives each component and flow its STRIDE categories, unknown without evidence (DATAP-914)", () => {
80
+ const threatModel = (0, build_threat_model_1.buildThreatModel)(factsWith([mailFlowWith()]));
81
+ expect(categoriesOfElement(threatModel, "cmp_api")).toBe("STRIDE");
82
+ expect(categoriesOfElement(threatModel, "cmp_mail")).toBe("SR");
83
+ expect(categoriesOfElement(threatModel, "cmp_db")).toBe("TRID");
84
+ expect(categoriesOfElement(threatModel, "flow_mail")).toBe("TID");
85
+ for (const flowThreat of threatModel.threats.filter((threat) => threat.elementId === "flow_mail")) {
86
+ expect(flowThreat.ruleStatus).toBe("unknown");
87
+ expect(flowThreat.ruleId).toBe("stride/v3/data_flow");
88
+ expect(flowThreat.evidence).toEqual([]);
89
+ expect(flowThreat).not.toHaveProperty("statusRuleId");
90
+ }
91
+ });
92
+ it("sets rule statuses from flow controls, with the evidence lines (DATAP-915)", () => {
93
+ const threatModel = (0, build_threat_model_1.buildThreatModel)(factsWith([flowWithTlsAndTimeoutControls]));
94
+ expect(findThreat(threatModel, "flow_mail", "I")).toEqual({
95
+ id: "threat:flow_mail:stride:I",
96
+ elementId: "flow_mail",
97
+ elementKind: "dataFlow",
98
+ frameworkElementKind: "data_flow",
99
+ elementIdentityKey: "flow-key",
100
+ framework: "stride",
101
+ category: "I",
102
+ ruleStatus: "mitigated",
103
+ ruleId: "stride/v3/data_flow",
104
+ statusRuleId: "stride/v3/data_flow/I",
105
+ evidence: [{ control: "tls", filePath: "src/api.ts", line: 2 }],
106
+ });
107
+ expect(findThreat(threatModel, "cmp_mail", "S")?.ruleStatus).toBe("mitigated");
108
+ expect(findThreat(threatModel, "cmp_mail", "R")?.ruleStatus).toBe("unknown");
109
+ });
110
+ it("opens a threat when a control is weakened", () => {
111
+ const threatModel = (0, build_threat_model_1.buildThreatModel)(factsWith([
112
+ mailFlowWith({
113
+ controls: [{ control: "plaintext_http", effect: "weakens", filePath: "src/api.ts", line: 9 }],
114
+ }),
115
+ ]));
116
+ const informationDisclosureThreat = findThreat(threatModel, "flow_mail", "I");
117
+ expect(informationDisclosureThreat?.ruleStatus).toBe("open");
118
+ expect(informationDisclosureThreat?.statusRuleId).toBeDefined();
119
+ });
120
+ it("gives a structural flow no threats and leaves it out of its components' threats", () => {
121
+ const threatModel = (0, build_threat_model_1.buildThreatModel)(factsWith([mailFlowWith({ relationship: "uses_in_process", controls: flowWithTlsAndTimeoutControls.controls })]));
122
+ expect(categoriesOfElement(threatModel, "flow_mail")).toBe("");
123
+ expect(findThreat(threatModel, "cmp_mail", "S")?.ruleStatus).toBe("unknown");
124
+ });
125
+ it("names the element by id, kind, framework element kind and identity key", () => {
126
+ const threatModel = (0, build_threat_model_1.buildThreatModel)(factsWith([mailFlowWith()]));
127
+ expect(findThreat(threatModel, "cmp_api", "S")).toMatchObject({
128
+ elementKind: "component",
129
+ frameworkElementKind: "process",
130
+ elementIdentityKey: "app:<unsectioned>|asset|service|src/api.ts|api",
131
+ });
132
+ const mailThreat = findThreat(threatModel, "cmp_mail", "S");
133
+ expect(mailThreat).toMatchObject({ elementKind: "component", frameworkElementKind: "external_entity" });
134
+ expect(mailThreat).not.toHaveProperty("elementIdentityKey");
135
+ expect(findThreat(threatModel, "cmp_db", "T")).toMatchObject({
136
+ elementKind: "component",
137
+ frameworkElementKind: "data_store",
138
+ });
139
+ expect(findThreat(threatModel, "flow_mail", "T")).toMatchObject({
140
+ elementKind: "dataFlow",
141
+ frameworkElementKind: "data_flow",
142
+ });
143
+ });
144
+ it("gives every threat a stable id that is unique in the file", () => {
145
+ const facts = factsWith([mailFlowWith()]);
146
+ const firstThreatIds = (0, build_threat_model_1.buildThreatModel)(facts).threats.map((threat) => threat.id);
147
+ const secondThreatIds = (0, build_threat_model_1.buildThreatModel)(facts).threats.map((threat) => threat.id);
148
+ expect(new Set(firstThreatIds).size).toBe(firstThreatIds.length);
149
+ expect(secondThreatIds).toEqual(firstThreatIds);
150
+ });
151
+ it("copies the scan block of the facts, so the two files can be matched", () => {
152
+ const stamps = {
153
+ scannerCommit: "abc",
154
+ cliVersion: "0.0.36",
155
+ catalogHash: "cat",
156
+ configHash: "cfg",
157
+ aiInference: false,
158
+ structureGraph: false,
159
+ commitSha: null,
160
+ dirty: null,
161
+ rootCommitSha: null,
162
+ scanRoot: null,
163
+ };
164
+ const facts = factsWith([mailFlowWith()], { stamps });
165
+ expect((0, build_threat_model_1.buildThreatModel)(facts).scan).toEqual(facts.scan);
166
+ expect((0, build_threat_model_1.buildThreatModel)(facts).scan.stamps).toEqual(stamps);
167
+ expect((0, build_threat_model_1.buildThreatModel)(factsWith([])).scan.stamps).toBeUndefined();
168
+ });
169
+ it("lists the framework with its rules version and category names", () => {
170
+ const { frameworks } = (0, build_threat_model_1.buildThreatModel)(factsWith([]));
171
+ expect(frameworks).toHaveLength(1);
172
+ expect(frameworks[0]).toMatchObject({ id: "stride", rulesVersion: 3 });
173
+ expect(frameworks[0].categories).toHaveLength(6);
174
+ expect(frameworks[0].categories).toContainEqual({ id: "I", name: "Information disclosure" });
175
+ });
176
+ it("orders component threats before flow threats, in facts order", () => {
177
+ const threatModel = (0, build_threat_model_1.buildThreatModel)(factsWith([mailFlowWith()]));
178
+ const elementIdsInOrder = threatModel.threats
179
+ .map((threat) => threat.elementId)
180
+ .filter((elementId, index, all) => all.indexOf(elementId) === index);
181
+ expect(elementIdsInOrder).toEqual(["cmp_api", "cmp_mail", "cmp_db", "flow_mail"]);
182
+ });
183
+ it("matches the schema and has no person-set statuses", () => {
184
+ const threatModel = (0, build_threat_model_1.buildThreatModel)(factsWith([flowWithTlsAndTimeoutControls]));
185
+ expect(() => schema_1.threatModelFileSchema.parse(threatModel)).not.toThrow();
186
+ expect(threatModel.threats.some((threat) => threat.personSetStatus !== undefined)).toBe(false);
187
+ expect(threatModel.unmatchedPersonSetStatuses).toEqual([]);
188
+ });
189
+ });
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const carry_forward_person_set_statuses_1 = require("../../../src/threat-model/carry-forward-person-set-statuses");
4
+ const schema_1 = require("../../../src/threat-model/schema");
5
+ function buildThreat(overrides = {}) {
6
+ const base = { elementId: "component:api", framework: "stride", category: "spoofing", ...overrides };
7
+ return {
8
+ id: (0, schema_1.threatIdForElementAndCategory)(base),
9
+ elementKind: "component",
10
+ frameworkElementKind: "process",
11
+ ruleStatus: "open",
12
+ ruleId: "rule-spoofing",
13
+ evidence: [],
14
+ ...base,
15
+ };
16
+ }
17
+ function buildThreatModel(threats, scannedAt = "2026-11-01T00:00:00.000Z", unmatchedPersonSetStatuses = []) {
18
+ return {
19
+ schemaVersion: 1,
20
+ scan: { projectName: "demo", scannedAt, cliVersion: "0.0.36", scannerVersion: "1.0.0" },
21
+ frameworks: [{ id: "stride", rulesVersion: 1, categories: [{ id: "spoofing", name: "Spoofing" }] }],
22
+ threats,
23
+ unmatchedPersonSetStatuses,
24
+ };
25
+ }
26
+ const MITIGATED_BY_ALEX = {
27
+ status: "mitigated",
28
+ by: "alex@example.com",
29
+ at: "2026-10-30T10:00:00.000Z",
30
+ note: "Handled by the gateway",
31
+ };
32
+ describe("carryForwardPersonSetStatuses", () => {
33
+ it("returns the fresh threat model unchanged when there is no previous file", () => {
34
+ const fresh = buildThreatModel([buildThreat()]);
35
+ const result = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, undefined);
36
+ expect(result.threatModel).toBe(fresh);
37
+ expect(result.carriedForwardCount).toBe(0);
38
+ expect(result.unmatchedCount).toBe(0);
39
+ });
40
+ it("keeps a person-set status when the same threat is found again", () => {
41
+ const previous = buildThreatModel([buildThreat({ personSetStatus: MITIGATED_BY_ALEX })]);
42
+ const fresh = buildThreatModel([buildThreat()], "2026-11-02T00:00:00.000Z");
43
+ const result = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, previous);
44
+ expect(result.threatModel.threats[0].personSetStatus).toEqual(MITIGATED_BY_ALEX);
45
+ expect(result.carriedForwardCount).toBe(1);
46
+ expect(result.unmatchedCount).toBe(0);
47
+ });
48
+ it("never changes the rule status or evidence of the fresh scan", () => {
49
+ const previous = buildThreatModel([
50
+ buildThreat({ ruleStatus: "open", evidence: [], personSetStatus: MITIGATED_BY_ALEX }),
51
+ ]);
52
+ const freshEvidence = [{ control: "mfa", filePath: "src/auth.ts", line: 4 }];
53
+ const fresh = buildThreatModel([buildThreat({ ruleStatus: "mitigated", evidence: freshEvidence })], "2026-11-02T00:00:00.000Z");
54
+ const { threatModel } = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, previous);
55
+ expect(threatModel.threats[0].ruleStatus).toBe("mitigated");
56
+ expect(threatModel.threats[0].evidence).toEqual(freshEvidence);
57
+ expect(threatModel.scan.scannedAt).toBe("2026-11-02T00:00:00.000Z");
58
+ });
59
+ it("follows an element whose id changed but whose identity key did not", () => {
60
+ const previous = buildThreatModel([
61
+ buildThreat({ elementId: "component:old-id", elementIdentityKey: "service:api", personSetStatus: MITIGATED_BY_ALEX }),
62
+ ]);
63
+ const fresh = buildThreatModel([buildThreat({ elementId: "component:new-id", elementIdentityKey: "service:api" })]);
64
+ const result = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, previous);
65
+ expect(result.threatModel.threats[0].personSetStatus).toEqual(MITIGATED_BY_ALEX);
66
+ expect(result.unmatchedCount).toBe(0);
67
+ });
68
+ it("falls back to the element id when the element has no identity key", () => {
69
+ const previous = buildThreatModel([buildThreat({ personSetStatus: MITIGATED_BY_ALEX })]);
70
+ const fresh = buildThreatModel([buildThreat({ elementIdentityKey: "service:api" })]);
71
+ const result = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, previous);
72
+ expect(result.threatModel.threats[0].personSetStatus).toEqual(MITIGATED_BY_ALEX);
73
+ });
74
+ it("does not carry a status to another category or another framework of the same element", () => {
75
+ const previous = buildThreatModel([buildThreat({ personSetStatus: MITIGATED_BY_ALEX })]);
76
+ const fresh = buildThreatModel([
77
+ buildThreat({ category: "tampering" }),
78
+ buildThreat({ framework: "linddun" }),
79
+ ]);
80
+ const result = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, previous);
81
+ expect(result.threatModel.threats.every((threat) => threat.personSetStatus === undefined)).toBe(true);
82
+ expect(result.carriedForwardCount).toBe(0);
83
+ expect(result.unmatchedCount).toBe(1);
84
+ });
85
+ it("does not carry a component's status to a data flow with the same id", () => {
86
+ const previous = buildThreatModel([buildThreat({ elementId: "shared-id", personSetStatus: MITIGATED_BY_ALEX })]);
87
+ const fresh = buildThreatModel([buildThreat({ elementId: "shared-id", elementKind: "dataFlow" })]);
88
+ const result = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, previous);
89
+ expect(result.threatModel.threats[0].personSetStatus).toBeUndefined();
90
+ expect(result.unmatchedCount).toBe(1);
91
+ });
92
+ it("moves a person-set status whose threat is gone to unmatchedPersonSetStatuses, with the scan it was last matched in", () => {
93
+ const previous = buildThreatModel([buildThreat({ personSetStatus: MITIGATED_BY_ALEX })], "2026-11-01T00:00:00.000Z");
94
+ const fresh = buildThreatModel([], "2026-11-02T00:00:00.000Z");
95
+ const result = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, previous);
96
+ expect(result.unmatchedCount).toBe(1);
97
+ expect(result.threatModel.unmatchedPersonSetStatuses).toEqual([
98
+ {
99
+ threatId: previous.threats[0].id,
100
+ elementId: "component:api",
101
+ elementKind: "component",
102
+ framework: "stride",
103
+ category: "spoofing",
104
+ personSetStatus: MITIGATED_BY_ALEX,
105
+ lastMatchedScannedAt: "2026-11-01T00:00:00.000Z",
106
+ },
107
+ ]);
108
+ });
109
+ it("keeps unmatched person-set statuses across later scans", () => {
110
+ const firstScan = buildThreatModel([buildThreat({ personSetStatus: MITIGATED_BY_ALEX })], "2026-11-01T00:00:00.000Z");
111
+ const secondScan = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(buildThreatModel([], "2026-11-02T00:00:00.000Z"), firstScan).threatModel;
112
+ const thirdScan = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(buildThreatModel([], "2026-11-03T00:00:00.000Z"), secondScan);
113
+ expect(thirdScan.unmatchedCount).toBe(1);
114
+ expect(thirdScan.threatModel.unmatchedPersonSetStatuses[0].lastMatchedScannedAt).toBe("2026-11-01T00:00:00.000Z");
115
+ });
116
+ it("re-attaches an unmatched person-set status when its threat comes back", () => {
117
+ const firstScan = buildThreatModel([buildThreat({ personSetStatus: MITIGATED_BY_ALEX })], "2026-11-01T00:00:00.000Z");
118
+ const secondScan = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(buildThreatModel([], "2026-11-02T00:00:00.000Z"), firstScan).threatModel;
119
+ const thirdScan = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(buildThreatModel([buildThreat()], "2026-11-03T00:00:00.000Z"), secondScan);
120
+ expect(thirdScan.threatModel.threats[0].personSetStatus).toEqual(MITIGATED_BY_ALEX);
121
+ expect(thirdScan.threatModel.unmatchedPersonSetStatuses).toEqual([]);
122
+ expect(thirdScan.carriedForwardCount).toBe(1);
123
+ });
124
+ it("prefers the status on a current threat over an older unmatched one for the same threat", () => {
125
+ const olderUnmatched = {
126
+ threatId: (0, schema_1.threatIdForElementAndCategory)({ elementId: "component:api", framework: "stride", category: "spoofing" }),
127
+ elementId: "component:api",
128
+ elementKind: "component",
129
+ framework: "stride",
130
+ category: "spoofing",
131
+ personSetStatus: { status: "open", note: "older" },
132
+ lastMatchedScannedAt: "2026-10-01T00:00:00.000Z",
133
+ };
134
+ const previous = buildThreatModel([buildThreat({ personSetStatus: MITIGATED_BY_ALEX })], "2026-11-01T00:00:00.000Z", [olderUnmatched]);
135
+ const fresh = buildThreatModel([buildThreat()], "2026-11-02T00:00:00.000Z");
136
+ const result = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, previous);
137
+ expect(result.threatModel.threats[0].personSetStatus).toEqual(MITIGATED_BY_ALEX);
138
+ expect(result.threatModel.unmatchedPersonSetStatuses).toEqual([olderUnmatched]);
139
+ expect(result.carriedForwardCount).toBe(1);
140
+ expect(result.unmatchedCount).toBe(1);
141
+ });
142
+ it("gives the same output for the same inputs, and does not mutate them", () => {
143
+ const previous = buildThreatModel([buildThreat({ personSetStatus: MITIGATED_BY_ALEX }), buildThreat({ elementId: "component:db", personSetStatus: { status: "open" } })], "2026-11-01T00:00:00.000Z");
144
+ const fresh = buildThreatModel([buildThreat()], "2026-11-02T00:00:00.000Z");
145
+ const previousSnapshot = JSON.stringify(previous);
146
+ const freshSnapshot = JSON.stringify(fresh);
147
+ const first = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, previous);
148
+ const second = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, previous);
149
+ expect(JSON.stringify(first)).toBe(JSON.stringify(second));
150
+ expect(JSON.stringify(previous)).toBe(previousSnapshot);
151
+ expect(JSON.stringify(fresh)).toBe(freshSnapshot);
152
+ expect(first.threatModel).not.toBe(fresh);
153
+ });
154
+ it("returns a file that matches the schema", () => {
155
+ const previous = buildThreatModel([
156
+ buildThreat({ personSetStatus: MITIGATED_BY_ALEX }),
157
+ buildThreat({ elementId: "component:gone", personSetStatus: { status: "open" } }),
158
+ ]);
159
+ const fresh = buildThreatModel([buildThreat()], "2026-11-02T00:00:00.000Z");
160
+ const { threatModel } = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(fresh, previous);
161
+ expect(schema_1.threatModelFileSchema.safeParse(threatModel).success).toBe(true);
162
+ });
163
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ const os_1 = __importDefault(require("os"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const layout_1 = require("../../../src/facts/layout");
10
+ const carry_forward_person_set_statuses_1 = require("../../../src/threat-model/carry-forward-person-set-statuses");
11
+ const io_1 = require("../../../src/threat-model/io");
12
+ const schema_1 = require("../../../src/threat-model/schema");
13
+ function buildThreatModel(scannedAt = "2026-11-01T00:00:00.000Z") {
14
+ const identity = { elementId: "component:api", framework: "stride", category: "spoofing" };
15
+ return {
16
+ schemaVersion: 1,
17
+ scan: { projectName: "demo", scannedAt, cliVersion: "0.0.36", scannerVersion: "1.0.0" },
18
+ frameworks: [{ id: "stride", rulesVersion: 1, categories: [{ id: "spoofing", name: "Spoofing" }] }],
19
+ threats: [
20
+ {
21
+ id: (0, schema_1.threatIdForElementAndCategory)(identity),
22
+ elementKind: "component",
23
+ frameworkElementKind: "process",
24
+ ruleStatus: "open",
25
+ ruleId: "rule-spoofing",
26
+ evidence: [],
27
+ ...identity,
28
+ },
29
+ ],
30
+ unmatchedPersonSetStatuses: [],
31
+ };
32
+ }
33
+ describe("threat model file io", () => {
34
+ let temporaryDirectory;
35
+ let layout;
36
+ beforeEach(() => {
37
+ temporaryDirectory = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "threat-model-io-"));
38
+ layout = (0, layout_1.layoutForDir)(path_1.default.join(temporaryDirectory, ".dataparade"));
39
+ });
40
+ afterEach(() => {
41
+ fs_1.default.rmSync(temporaryDirectory, { recursive: true, force: true });
42
+ });
43
+ it("writes threat-model.json and reads it back", () => {
44
+ const threatModel = buildThreatModel();
45
+ (0, io_1.writeThreatModel)(layout, threatModel);
46
+ expect(fs_1.default.existsSync(layout.threatModelPath)).toBe(true);
47
+ expect(fs_1.default.readFileSync(layout.threatModelPath, "utf8").endsWith("\n")).toBe(true);
48
+ expect((0, io_1.readThreatModel)(layout)).toEqual(threatModel);
49
+ });
50
+ it("refuses to write a threat model that does not match the schema", () => {
51
+ const invalidThreatModel = { ...buildThreatModel(), schemaVersion: 2 };
52
+ expect(() => (0, io_1.writeThreatModel)(layout, invalidThreatModel)).toThrow();
53
+ expect(fs_1.default.existsSync(layout.threatModelPath)).toBe(false);
54
+ });
55
+ it("reports absent when there is no previous threat-model.json", () => {
56
+ expect((0, io_1.readPreviousThreatModelForCarryForward)(layout)).toEqual({ outcome: "absent" });
57
+ });
58
+ it("reads the previous threat model for carry-forward", () => {
59
+ const threatModel = buildThreatModel();
60
+ (0, io_1.writeThreatModel)(layout, threatModel);
61
+ expect((0, io_1.readPreviousThreatModelForCarryForward)(layout)).toEqual({ outcome: "read", threatModel });
62
+ });
63
+ it("keeps an unreadable previous file as threat-model.unreadable.json and reports why", () => {
64
+ const unreadableContents = ["{ not json", JSON.stringify({ ...buildThreatModel(), schemaVersion: 2 })];
65
+ for (const contents of unreadableContents) {
66
+ fs_1.default.rmSync(layout.threatModelUnreadableCopyPath, { force: true });
67
+ fs_1.default.mkdirSync(layout.dir, { recursive: true });
68
+ fs_1.default.writeFileSync(layout.threatModelPath, contents, "utf8");
69
+ const result = (0, io_1.readPreviousThreatModelForCarryForward)(layout);
70
+ if (result.outcome !== "unreadable")
71
+ throw new Error("expected an unreadable outcome");
72
+ expect(result.reason.length).toBeGreaterThan(0);
73
+ expect(result.unreadableCopyPath).toBe(layout.threatModelUnreadableCopyPath);
74
+ expect(fs_1.default.readFileSync(layout.threatModelUnreadableCopyPath, "utf8")).toBe(contents);
75
+ }
76
+ });
77
+ it("readThreatModel says to scan first when the file is missing", () => {
78
+ let caught;
79
+ try {
80
+ (0, io_1.readThreatModel)(layout);
81
+ }
82
+ catch (error) {
83
+ caught = error;
84
+ }
85
+ expect(caught).toBeInstanceOf(io_1.ThreatModelError);
86
+ expect(caught.code).toBe("NO_THREAT_MODEL");
87
+ expect(caught.message).toContain("Scan first");
88
+ });
89
+ it("survives a rescan end to end", () => {
90
+ (0, io_1.writeThreatModel)(layout, buildThreatModel("2026-11-01T00:00:00.000Z"));
91
+ const onDisk = JSON.parse(fs_1.default.readFileSync(layout.threatModelPath, "utf8"));
92
+ onDisk.threats[0].personSetStatus = { status: "mitigated" };
93
+ fs_1.default.writeFileSync(layout.threatModelPath, JSON.stringify(onDisk, null, 2), "utf8");
94
+ const previous = (0, io_1.readPreviousThreatModelForCarryForward)(layout);
95
+ if (previous.outcome !== "read")
96
+ throw new Error("expected the previous file to be read");
97
+ const { threatModel } = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)(buildThreatModel("2026-11-05T00:00:00.000Z"), previous.threatModel);
98
+ (0, io_1.writeThreatModel)(layout, threatModel);
99
+ const rewritten = JSON.parse(fs_1.default.readFileSync(layout.threatModelPath, "utf8"));
100
+ expect(rewritten.scan.scannedAt).toBe("2026-11-05T00:00:00.000Z");
101
+ expect(rewritten.threats[0].personSetStatus).toEqual({ status: "mitigated" });
102
+ });
103
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const zod_1 = require("zod");
4
+ const schema_1 = require("../../../src/threat-model/schema");
5
+ describe("threat model schema", () => {
6
+ it("accepts a person-set status with only a status", () => {
7
+ expect(schema_1.personSetThreatStatusSchema.parse({ status: "mitigated" })).toEqual({ status: "mitigated" });
8
+ });
9
+ it("accepts accepted and not_applicable as person-set statuses", () => {
10
+ for (const personSetStatusValue of ["mitigated", "open", "accepted", "not_applicable"]) {
11
+ expect(schema_1.personSetThreatStatusSchema.safeParse({ status: personSetStatusValue }).success).toBe(true);
12
+ }
13
+ });
14
+ it("rejects unknown and other values as a person-set status", () => {
15
+ expect(schema_1.personSetThreatStatusSchema.safeParse({ status: "unknown" }).success).toBe(false);
16
+ expect(schema_1.personSetThreatStatusSchema.safeParse({ status: "ignored" }).success).toBe(false);
17
+ });
18
+ it("keeps framework and category open to other frameworks", () => {
19
+ const parsedThreat = schema_1.threatModelThreatSchema.parse({
20
+ id: "threat:subject_1:linddun:L",
21
+ elementId: "subject_1",
22
+ elementKind: "component",
23
+ frameworkElementKind: "data_subject",
24
+ framework: "linddun",
25
+ category: "L",
26
+ ruleStatus: "unknown",
27
+ ruleId: "linddun/v1/data_subject",
28
+ evidence: [],
29
+ });
30
+ expect(parsedThreat.framework).toBe("linddun");
31
+ expect(parsedThreat.frameworkElementKind).toBe("data_subject");
32
+ });
33
+ it("can be emitted as a JSON Schema", () => {
34
+ const jsonSchema = zod_1.z.toJSONSchema(schema_1.threatModelFileSchema);
35
+ expect(jsonSchema.properties?.threats).toBeDefined();
36
+ });
37
+ it("effectiveThreatStatus prefers the person-set status over the rule status", () => {
38
+ expect((0, schema_1.effectiveThreatStatus)({ ruleStatus: "open", personSetStatus: { status: "mitigated" } })).toBe("mitigated");
39
+ expect((0, schema_1.effectiveThreatStatus)({ ruleStatus: "open" })).toBe("open");
40
+ expect((0, schema_1.effectiveThreatStatus)({ ruleStatus: "open", personSetStatus: { status: "accepted" } })).toBe("accepted");
41
+ });
42
+ });