@dataparade/cli 0.0.34 → 0.1.0

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 (125) 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/third-party-data-flow.js +5 -4
  6. package/dist/src/cli.js +9 -3
  7. package/dist/src/facts/build-facts.d.ts +2 -0
  8. package/dist/src/facts/build-facts.js +14 -0
  9. package/dist/src/facts/layout.d.ts +4 -0
  10. package/dist/src/facts/layout.js +5 -1
  11. package/dist/src/facts/scan-stamps.d.ts +7 -0
  12. package/dist/src/facts/scan-stamps.js +30 -0
  13. package/dist/src/facts/schema.d.ts +74 -0
  14. package/dist/src/facts/schema.js +32 -1
  15. package/dist/src/output/scan-output-excludes.js +2 -0
  16. package/dist/src/output/write-scan-knowledge.d.ts +5 -1
  17. package/dist/src/output/write-scan-knowledge.js +21 -0
  18. package/dist/src/threat-model/build-threat-model.d.ts +3 -0
  19. package/dist/src/threat-model/build-threat-model.js +71 -0
  20. package/dist/src/threat-model/carry-forward-person-set-statuses.d.ts +8 -0
  21. package/dist/src/threat-model/carry-forward-person-set-statuses.js +87 -0
  22. package/dist/src/threat-model/io.d.ts +19 -0
  23. package/dist/src/threat-model/io.js +63 -0
  24. package/dist/src/threat-model/schema.d.ts +214 -0
  25. package/dist/src/threat-model/schema.js +75 -0
  26. package/dist/src/ui/scan-progress-renderer.d.ts +8 -1
  27. package/dist/src/ui/scan-progress-renderer.js +20 -1
  28. package/dist/src/upload/collect-scan-sidecars.d.ts +2 -1
  29. package/dist/src/upload/collect-scan-sidecars.js +3 -1
  30. package/dist/tests/cli/cli.spec.js +10 -1
  31. package/dist/tests/helpers/facts-fixture.js +16 -16
  32. package/dist/tests/schema/scan-result.schema.spec.js +1 -1
  33. package/dist/tests/unit/ai-enrichment/third-party-data-flow.spec.js +5 -5
  34. package/dist/tests/unit/core/graph-mapping.spec.js +4 -3
  35. package/dist/tests/unit/discoveries/write-ocsf-discoveries-long-ids.spec.js +3 -3
  36. package/dist/tests/unit/export/export-ocsf.spec.js +4 -4
  37. package/dist/tests/unit/facts/apply-answers.spec.js +20 -20
  38. package/dist/tests/unit/facts/build-facts.spec.js +126 -45
  39. package/dist/tests/unit/facts/identity.spec.js +13 -0
  40. package/dist/tests/unit/facts/scan-stamps.spec.js +32 -0
  41. package/dist/tests/unit/facts/slug.spec.js +2 -0
  42. package/dist/tests/unit/kb/answer-fingerprint.spec.js +9 -9
  43. package/dist/tests/unit/kb/kb-interview-loop.spec.js +3 -3
  44. package/dist/tests/unit/output/scan-output-excludes.spec.js +1 -1
  45. package/dist/tests/unit/threat-model/build-threat-model.spec.d.ts +1 -0
  46. package/dist/tests/unit/threat-model/build-threat-model.spec.js +184 -0
  47. package/dist/tests/unit/threat-model/carry-forward-person-set-statuses.spec.d.ts +1 -0
  48. package/dist/tests/unit/threat-model/carry-forward-person-set-statuses.spec.js +163 -0
  49. package/dist/tests/unit/threat-model/io.spec.d.ts +1 -0
  50. package/dist/tests/unit/threat-model/io.spec.js +103 -0
  51. package/dist/tests/unit/threat-model/schema.spec.d.ts +1 -0
  52. package/dist/tests/unit/threat-model/schema.spec.js +42 -0
  53. package/dist/tests/unit/ui/scan-progress-renderer.spec.js +58 -0
  54. package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +8 -5
  55. package/dist/vendor/scanner/dist/src/analyze/code-navigator.d.ts +1 -1
  56. package/dist/vendor/scanner/dist/src/analyze/code-navigator.js +4 -0
  57. package/dist/vendor/scanner/dist/src/analyze/column-catalog.d.ts +1 -1
  58. package/dist/vendor/scanner/dist/src/analyze/column-catalog.js +2 -2
  59. package/dist/vendor/scanner/dist/src/analyze/concept-profile.d.ts +2 -2
  60. package/dist/vendor/scanner/dist/src/analyze/concept-profile.js +5 -3
  61. package/dist/vendor/scanner/dist/src/classifier/component-factory.js +20 -0
  62. package/dist/vendor/scanner/dist/src/core/pipeline/build-scan-personal-data-layers.js +1 -1
  63. package/dist/vendor/scanner/dist/src/core/pipeline/deterministic-scan.js +43 -0
  64. package/dist/vendor/scanner/dist/src/core/pipeline/graph-mapping.js +23 -2
  65. package/dist/vendor/scanner/dist/src/core/pipeline/mixed-app-terraform-scan.js +1 -0
  66. package/dist/vendor/scanner/dist/src/core/pipeline/orchestrator-result.d.ts +2 -2
  67. package/dist/vendor/scanner/dist/src/core/pipeline/terraform-minimal-services.js +1 -0
  68. package/dist/vendor/scanner/dist/src/core/schema/scan-result.schema.d.ts +160 -2
  69. package/dist/vendor/scanner/dist/src/core/schema/scan-result.schema.js +24 -0
  70. package/dist/vendor/scanner/dist/src/core/types/data-flow.d.ts +48 -0
  71. package/dist/vendor/scanner/dist/src/core/types/data-flow.js +53 -0
  72. package/dist/vendor/scanner/dist/src/data-flow/detect.js +1 -0
  73. package/dist/vendor/scanner/dist/src/data-flow/ensure-hub-linked-assets.js +1 -0
  74. package/dist/vendor/scanner/dist/src/data-flow/ensure-manifest-declared-flows.js +1 -0
  75. package/dist/vendor/scanner/dist/src/data-flow/flow-authentication.d.ts +30 -0
  76. package/dist/vendor/scanner/dist/src/data-flow/flow-authentication.js +277 -0
  77. package/dist/vendor/scanner/dist/src/data-flow/flow-builder.js +6 -0
  78. package/dist/vendor/scanner/dist/src/data-flow/flow-controls.d.ts +24 -0
  79. package/dist/vendor/scanner/dist/src/data-flow/flow-controls.js +238 -0
  80. package/dist/vendor/scanner/dist/src/data-flow/flow-data-categories.d.ts +22 -0
  81. package/dist/vendor/scanner/dist/src/data-flow/flow-data-categories.js +69 -0
  82. package/dist/vendor/scanner/dist/src/data-flow/flow-interaction-description.d.ts +13 -0
  83. package/dist/vendor/scanner/dist/src/data-flow/flow-interaction-description.js +263 -0
  84. package/dist/vendor/scanner/dist/src/data-flow/hub-link-policy.d.ts +2 -1
  85. package/dist/vendor/scanner/dist/src/data-flow/hub-link-policy.js +3 -0
  86. package/dist/vendor/scanner/dist/src/data-flow/human-interaction-channels.d.ts +37 -0
  87. package/dist/vendor/scanner/dist/src/data-flow/human-interaction-channels.js +483 -0
  88. package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.d.ts +3 -0
  89. package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.js +12 -17
  90. package/dist/vendor/scanner/dist/src/data-flow/terraform-flows.js +5 -1
  91. package/dist/vendor/scanner/dist/src/data-flow/transformation-patterns.d.ts +5 -1
  92. package/dist/vendor/scanner/dist/src/data-flow/transformation-patterns.js +17 -37
  93. package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.d.ts +36 -5
  94. package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.js +53 -60
  95. package/dist/vendor/scanner/dist/src/eval/canonical/graph/endpoints.js +2 -9
  96. package/dist/vendor/scanner/dist/src/eval/canonical/scanner/personal-data.js +10 -7
  97. package/dist/vendor/scanner/dist/src/graph/build-dataparade-graph.js +3 -1
  98. package/dist/vendor/scanner/dist/src/index.d.ts +6 -0
  99. package/dist/vendor/scanner/dist/src/index.js +16 -1
  100. package/dist/vendor/scanner/dist/src/patterns/detectors/python.js +11 -1
  101. package/dist/vendor/scanner/dist/src/patterns/engine.js +1 -0
  102. package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.d.ts +1 -1
  103. package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.js +2 -2
  104. package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.d.ts +3 -3
  105. package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.js +12 -11
  106. package/dist/vendor/scanner/dist/src/pii-signals/personal-data-taxonomy.d.ts +44 -0
  107. package/dist/vendor/scanner/dist/src/pii-signals/personal-data-taxonomy.js +167 -0
  108. package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-aliases.js +43 -43
  109. package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-rules.d.ts +12 -1
  110. package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-rules.js +28 -7
  111. package/dist/vendor/scanner/dist/src/pii-signals/signal-token.js +1 -1
  112. package/dist/vendor/scanner/dist/src/threats/stride.d.ts +98 -0
  113. package/dist/vendor/scanner/dist/src/threats/stride.js +179 -0
  114. package/dist/vendor/scanner/package.json +2 -2
  115. package/dist/vendor/scanner/patterns/concept-profiles.yaml +2 -2
  116. package/dist/vendor/scanner/patterns/flow-authentication.rules.yaml +75 -0
  117. package/dist/vendor/scanner/patterns/flow-controls.rules.yaml +68 -0
  118. package/dist/vendor/scanner/patterns/personal-data-taxonomy.yaml +155 -0
  119. package/dist/vendor/scanner/patterns/pii-signals.rules.yaml +38 -49
  120. package/dist/vendor/scanner/patterns/python.patterns.yaml +2 -2
  121. package/dist/vendor/scanner/patterns/stride.rules.yaml +86 -0
  122. package/package.json +4 -4
  123. package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.validate.d.ts +0 -17
  124. package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.validate.js +0 -108
  125. package/dist/vendor/scanner/patterns/personal-data-concept-map.yaml +0 -76
@@ -13,29 +13,29 @@ const layout_1 = require("../../src/facts/layout");
13
13
  /** A small scan: an API, Sendgrid, a customer, two flows, and an email data item with two groups. */
14
14
  function sampleFacts() {
15
15
  const groups = [
16
- { id: "group:email:customer", label: "customer", basis: "column", occurrenceCount: 2, handledBy: ["cmp_api"] },
17
- { id: "group:email:staff", label: "staff", basis: "name", occurrenceCount: 1, handledBy: ["cmp_api", "cmp_mail"] },
16
+ { id: "group:pd:EmailAddress:customer", label: "customer", basis: "column", occurrenceCount: 2, handledBy: ["cmp_api"] },
17
+ { id: "group:pd:EmailAddress:staff", label: "staff", basis: "name", occurrenceCount: 1, handledBy: ["cmp_api", "cmp_mail"] },
18
18
  ];
19
19
  const emailFile = {
20
20
  schemaVersion: 1,
21
- id: "data_item:email",
22
- name: "email",
23
- labels: ["contact"],
21
+ id: "data_item:pd:EmailAddress",
22
+ name: "pd:EmailAddress",
23
+ labels: ["pd:EmailAddress"],
24
24
  groups,
25
25
  occurrences: [
26
- { id: "occurrence:email:src/a.ts:3", groupId: "group:email:customer", filePath: "src/a.ts", startLine: 3, endLine: 3, code: "email", labels: ["contact"], codeRefs: [] },
27
- { id: "occurrence:email:src/b.ts:9", groupId: "group:email:customer", filePath: "src/b.ts", startLine: 9, endLine: 9, labels: ["contact"], codeRefs: [] },
28
- { id: "occurrence:email:src/c.ts:1", groupId: "group:email:staff", filePath: "src/c.ts", startLine: 1, endLine: 1, labels: [], codeRefs: [] },
26
+ { id: "occurrence:pd:EmailAddress:src/a.ts:3", groupId: "group:pd:EmailAddress:customer", filePath: "src/a.ts", startLine: 3, endLine: 3, code: "email", labels: ["pd:EmailAddress"], codeRefs: [] },
27
+ { id: "occurrence:pd:EmailAddress:src/b.ts:9", groupId: "group:pd:EmailAddress:customer", filePath: "src/b.ts", startLine: 9, endLine: 9, labels: ["pd:EmailAddress"], codeRefs: [] },
28
+ { id: "occurrence:pd:EmailAddress:src/c.ts:1", groupId: "group:pd:EmailAddress:staff", filePath: "src/c.ts", startLine: 1, endLine: 1, labels: [], codeRefs: [] },
29
29
  ],
30
30
  };
31
31
  const phoneFile = {
32
32
  schemaVersion: 1,
33
- id: "data_item:phone",
34
- name: "phone",
33
+ id: "data_item:pd:TelephoneNumber",
34
+ name: "pd:TelephoneNumber",
35
35
  labels: [],
36
- groups: [{ id: "group:phone:customer", label: "customer", occurrenceCount: 1, handledBy: ["cmp_api"] }],
36
+ groups: [{ id: "group:pd:TelephoneNumber:customer", label: "customer", occurrenceCount: 1, handledBy: ["cmp_api"] }],
37
37
  occurrences: [
38
- { id: "occurrence:phone:src/a.ts:7", groupId: "group:phone:customer", filePath: "src/a.ts", startLine: 7, endLine: 7, labels: [], codeRefs: [] },
38
+ { id: "occurrence:pd:TelephoneNumber:src/a.ts:7", groupId: "group:pd:TelephoneNumber:customer", filePath: "src/a.ts", startLine: 7, endLine: 7, labels: [], codeRefs: [] },
39
39
  ],
40
40
  };
41
41
  const facts = {
@@ -51,13 +51,13 @@ function sampleFacts() {
51
51
  { id: "flow_login", sourceComponentId: "cmp_user", targetComponentId: "cmp_api", type: "api_call", confidence: 0.9, sourceLocations: [], codeRefs: [] },
52
52
  ],
53
53
  dataItems: [
54
- { id: "data_item:email", name: "email", labels: ["contact"], occurrenceCount: 3, file: "data-items/email.json", groups },
55
- { id: "data_item:phone", name: "phone", labels: [], occurrenceCount: 1, file: "data-items/phone.json", groups: phoneFile.groups },
54
+ { id: "data_item:pd:EmailAddress", name: "pd:EmailAddress", labels: ["pd:EmailAddress"], occurrenceCount: 3, file: "data-items/pd-emailaddress.json", groups },
55
+ { id: "data_item:pd:TelephoneNumber", name: "pd:TelephoneNumber", labels: [], occurrenceCount: 1, file: "data-items/pd-telephonenumber.json", groups: phoneFile.groups },
56
56
  ],
57
57
  relations: [
58
58
  { type: "sends", source: "cmp_api", target: "flow_mail", confidence: "EXTRACTED", basis: null },
59
59
  { type: "delivers_to", source: "flow_mail", target: "cmp_mail", confidence: "EXTRACTED", basis: null },
60
- { type: "handled_by", source: "group:email:staff", target: "cmp_mail", confidence: "INFERRED", basis: "same_file" },
60
+ { type: "handled_by", source: "group:pd:EmailAddress:staff", target: "cmp_mail", confidence: "INFERRED", basis: "same_file" },
61
61
  ],
62
62
  };
63
63
  return { facts, files: [emailFile, phoneFile] };
@@ -66,7 +66,7 @@ function sampleFacts() {
66
66
  function makeKbDir() {
67
67
  const layout = (0, layout_1.layoutForDir)(fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dp-kb-")));
68
68
  const { facts, files } = sampleFacts();
69
- (0, io_1.writeFactsOutput)(layout, facts, new Map(files.map((file) => [`data-items/${file.name}.json`, file])));
69
+ (0, io_1.writeFactsOutput)(layout, facts, new Map(files.map((file) => [facts.dataItems.find((item) => item.id === file.id).file, file])));
70
70
  fs_1.default.writeFileSync(layout.dataflowPath, JSON.stringify({ schemaVersion: "1.0", graph: { nodes: [], edges: [] }, metadata: { projectName: "demo" } }));
71
71
  return layout;
72
72
  }
@@ -148,7 +148,7 @@ describe("scanResultSchema", () => {
148
148
  dataShared: [
149
149
  {
150
150
  category: "credentials",
151
- labels: ["user_email", "user_password"],
151
+ labels: ["pd:EmailAddress", "pd:Password"],
152
152
  },
153
153
  ],
154
154
  confidence: 0.89,
@@ -433,8 +433,8 @@ describe("buildThirdPartyDataFlowSummary", () => {
433
433
  const entry = summary.entries[0];
434
434
  expect(entry).toBeDefined();
435
435
  const labels = entry?.dataShared.map((x) => x.labels).flat() ?? [];
436
- expect(labels).toContain("first_name");
437
- expect(labels).toContain("last_name");
436
+ expect(labels).toContain("dpx:FirstName");
437
+ expect(labels).toContain("dpx:LastName");
438
438
  });
439
439
  it("does not detect passport_number from Passport auth framework names", () => {
440
440
  const summary = (0, third_party_data_flow_1.buildThirdPartyDataFlowSummary)({
@@ -515,7 +515,7 @@ describe("buildThirdPartyDataFlowSummary", () => {
515
515
  const entry = summary.entries[0];
516
516
  expect(entry).toBeDefined();
517
517
  const labels = entry?.dataShared.map((x) => x.labels).flat() ?? [];
518
- expect(labels).not.toContain("address");
518
+ expect(labels).not.toContain("pd:PhysicalAddress");
519
519
  });
520
520
  it("does not classify OAuth state parameter as profile address", () => {
521
521
  const summary = (0, third_party_data_flow_1.buildThirdPartyDataFlowSummary)({
@@ -555,7 +555,7 @@ describe("buildThirdPartyDataFlowSummary", () => {
555
555
  const entry = summary.entries[0];
556
556
  expect(entry).toBeDefined();
557
557
  const labels = entry?.dataShared.map((x) => x.labels).flat() ?? [];
558
- expect(labels).not.toContain("address");
558
+ expect(labels).not.toContain("pd:PhysicalAddress");
559
559
  });
560
560
  it("derives dataShared from provider evidence reasons when scan signals are missing", () => {
561
561
  const summary = (0, third_party_data_flow_1.buildThirdPartyDataFlowSummary)({
@@ -671,7 +671,7 @@ describe("buildThirdPartyDataFlowSummary", () => {
671
671
  const entry = summary.entries[0];
672
672
  expect(entry).toBeDefined();
673
673
  const labels = entry?.dataShared.map((x) => x.labels).flat() ?? [];
674
- expect(labels).not.toContain("address");
674
+ expect(labels).not.toContain("pd:PhysicalAddress");
675
675
  });
676
676
  it("attributes shared prompt assembly to all AI providers in the same handler file", () => {
677
677
  const handlerPath = "app/api/assistant/route.ts";
@@ -82,7 +82,7 @@ describe("core/pipeline/graph-mapping - DP-P0-CLI-402", () => {
82
82
  },
83
83
  method: "GET",
84
84
  endpoint: "/health",
85
- dataCategories: ["personal_identifiers"],
85
+ dataCategories: ["pd:EmailAddress"],
86
86
  dataSubjectCategories: ["customers"],
87
87
  processingPurpose: ["service_provision"],
88
88
  actions: ["read"],
@@ -131,11 +131,12 @@ describe("core/pipeline/graph-mapping - DP-P0-CLI-402", () => {
131
131
  return;
132
132
  const properties = edge.data.properties;
133
133
  expect(properties.engineering.transferType).toBe("api_call");
134
- expect(properties.engineering.protocol).toBe("rest");
134
+ // A method and endpoint alone no longer set a protocol (scanner DATAP-937).
135
+ expect(properties.engineering.protocol).toBeUndefined();
135
136
  expect(properties.engineering.name).toContain("Test Application");
136
137
  expect(properties.engineering.actions).toEqual(["read"]);
137
138
  expect(properties.privacy.dataCategories).toEqual([
138
- "personal_identifiers",
139
+ "pd:EmailAddress",
139
140
  ]);
140
141
  expect(properties.privacy.dataSubjectCategories).toEqual(["customers"]);
141
142
  expect(properties.privacy.processingPurpose).toEqual([
@@ -13,18 +13,18 @@ describe("OCSF discovery files for long ids", () => {
13
13
  it("keeps file names under the filesystem limit and loads every record back", () => {
14
14
  const scanPath = `/Users/someone/${"deeply-nested-checkout/".repeat(8)}repo`;
15
15
  const occurrence = {
16
- id: `occurrence:phone_number:${"app/actions/contact/".repeat(4)}identify_action.rb:13`,
16
+ id: `occurrence:pd:TelephoneNumber:${"app/actions/contact/".repeat(4)}identify_action.rb:13`,
17
17
  filePath: "app/actions/contact/identify_action.rb",
18
18
  startLine: 13,
19
19
  endLine: 13,
20
- labels: ["phone_number"],
20
+ labels: ["pd:TelephoneNumber"],
21
21
  };
22
22
  const records = (0, scan_discovery_to_ocsf_1.landScanDiscoveryToOcsfRecords)({
23
23
  scanPath,
24
24
  components: [],
25
25
  dataFlows: [],
26
26
  occurrences: [occurrence],
27
- dataItems: [{ id: "data_item:phone_number", occurrenceIds: [occurrence.id], labels: ["phone_number"] }],
27
+ dataItems: [{ id: "data_item:pd:TelephoneNumber", occurrenceIds: [occurrence.id], labels: ["pd:TelephoneNumber"] }],
28
28
  }, { assertedAt: "2026-10-05T00:00:00.000Z" });
29
29
  const dir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dp-ocsf-long-"));
30
30
  try {
@@ -30,19 +30,19 @@ describe("export ocsf", () => {
30
30
  const { records } = (0, load_ocsf_discoveries_1.loadOcsfDiscoveriesFromDir)(out);
31
31
  expect(records).toHaveLength(result.records);
32
32
  expect(slot(records, "name").sort()).toEqual(["Customer", "Sendgrid", "backend"]);
33
- expect(records.some((r) => r.dataparade.asserts === "dp:scan/entity/occurrence:email:src/a.ts:3")).toBe(true);
34
- expect(records.some((r) => r.dataparade.asserts === "dp:scan/entity/data_item:email")).toBe(true);
33
+ expect(records.some((r) => r.dataparade.asserts === "dp:scan/entity/occurrence:pd:EmailAddress:src/a.ts:3")).toBe(true);
34
+ expect(records.some((r) => r.dataparade.asserts === "dp:scan/entity/data_item:pd:EmailAddress")).toBe(true);
35
35
  expect(JSON.stringify(records)).not.toContain("/Users/");
36
36
  });
37
37
  it("exports the applied state: overrides in, removed Facts out", () => {
38
38
  (0, land_1.landReviewAnswer)(paths, { target: "cmp_mail", action: "set", property: "name", value: "SendGrid Inc", reviewer: "dev@example.com" });
39
- (0, land_1.landReviewAnswer)(paths, { target: "data_item:phone", action: "remove", reviewer: "dev@example.com" });
39
+ (0, land_1.landReviewAnswer)(paths, { target: "data_item:pd:TelephoneNumber", action: "remove", reviewer: "dev@example.com" });
40
40
  (0, export_ocsf_1.exportOcsf)(paths, out);
41
41
  const { records } = (0, load_ocsf_discoveries_1.loadOcsfDiscoveriesFromDir)(out);
42
42
  expect(slot(records, "name")).toContain("SendGrid Inc");
43
43
  expect(slot(records, "name")).not.toContain("Sendgrid");
44
44
  const asserted = records.map((r) => r.dataparade.asserts);
45
- expect(asserted.some((a) => a.includes("phone"))).toBe(false);
45
+ expect(asserted.some((a) => a.includes("pd:TelephoneNumber"))).toBe(false);
46
46
  });
47
47
  it("exports interview answers as interview records that supersede the earlier answer", () => {
48
48
  fs_1.default.mkdirSync(paths.evidenceDir, { recursive: true });
@@ -42,16 +42,16 @@ describe("applyAnswers", () => {
42
42
  });
43
43
  it("sets a data item in facts.json and in its file, and a group in both", () => {
44
44
  const state = (0, apply_answers_1.applyAnswers)(facts, files, [
45
- answer({ factId: "data_item:email", action: "set", property: "labels", value: ["contact", "pii"] }),
46
- answer({ factId: "group:email:staff", action: "set", property: "label", value: "employees" }),
45
+ answer({ factId: "data_item:pd:EmailAddress", action: "set", property: "labels", value: ["contact", "pii"] }),
46
+ answer({ factId: "group:pd:EmailAddress:staff", action: "set", property: "label", value: "employees" }),
47
47
  ]);
48
48
  expect(state.facts.dataItems[0].labels).toEqual(["contact", "pii"]);
49
49
  expect(state.dataItemFiles[0].labels).toEqual(["contact", "pii"]);
50
- expect(state.facts.dataItems[0].groups.find((g) => g.id === "group:email:staff")?.label).toBe("employees");
51
- expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:email:staff")?.label).toBe("employees");
50
+ expect(state.facts.dataItems[0].groups.find((g) => g.id === "group:pd:EmailAddress:staff")?.label).toBe("employees");
51
+ expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:pd:EmailAddress:staff")?.label).toBe("employees");
52
52
  });
53
53
  it("sets a property of an occurrence", () => {
54
- const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "occurrence:email:src/a.ts:3", action: "set", property: "labels", value: ["verified"] })]);
54
+ const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "occurrence:pd:EmailAddress:src/a.ts:3", action: "set", property: "labels", value: ["verified"] })]);
55
55
  expect(state.dataItemFiles[0].occurrences[0].labels).toEqual(["verified"]);
56
56
  });
57
57
  it("keeps answers about the system apart from Facts", () => {
@@ -80,35 +80,35 @@ describe("applyAnswers", () => {
80
80
  const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "cmp_mail", action: "remove" })]);
81
81
  expect(state.facts.components.map((c) => c.id)).toEqual(["cmp_api", "cmp_user"]);
82
82
  expect(state.facts.dataFlows.map((f) => f.id)).toEqual(["flow_login"]);
83
- const staff = state.facts.dataItems[0].groups.find((g) => g.id === "group:email:staff");
83
+ const staff = state.facts.dataItems[0].groups.find((g) => g.id === "group:pd:EmailAddress:staff");
84
84
  expect(staff?.handledBy).toEqual(["cmp_api"]);
85
- expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:email:staff")?.handledBy).toEqual(["cmp_api"]);
85
+ expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:pd:EmailAddress:staff")?.handledBy).toEqual(["cmp_api"]);
86
86
  expect(state.facts.relations).toEqual([]);
87
87
  });
88
88
  it("drops a data item with its occurrences, its file and its entry in facts.json", () => {
89
- const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "data_item:email", action: "remove" })]);
90
- expect(state.facts.dataItems.map((i) => i.id)).toEqual(["data_item:phone"]);
91
- expect(state.dataItemFiles.map((f) => f.id)).toEqual(["data_item:phone"]);
92
- expect(state.facts.relations.some((r) => r.source.startsWith("group:email"))).toBe(false);
89
+ const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "data_item:pd:EmailAddress", action: "remove" })]);
90
+ expect(state.facts.dataItems.map((i) => i.id)).toEqual(["data_item:pd:TelephoneNumber"]);
91
+ expect(state.dataItemFiles.map((f) => f.id)).toEqual(["data_item:pd:TelephoneNumber"]);
92
+ expect(state.facts.relations.some((r) => r.source.startsWith("group:pd:EmailAddress"))).toBe(false);
93
93
  });
94
94
  it("drops a group with its occurrences and fixes the counts", () => {
95
- const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "group:email:customer", action: "remove" })]);
96
- expect(state.dataItemFiles[0].occurrences.map((o) => o.id)).toEqual(["occurrence:email:src/c.ts:1"]);
95
+ const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "group:pd:EmailAddress:customer", action: "remove" })]);
96
+ expect(state.dataItemFiles[0].occurrences.map((o) => o.id)).toEqual(["occurrence:pd:EmailAddress:src/c.ts:1"]);
97
97
  expect(state.facts.dataItems[0].occurrenceCount).toBe(1);
98
- expect(state.facts.dataItems[0].groups.map((g) => g.id)).toEqual(["group:email:staff"]);
98
+ expect(state.facts.dataItems[0].groups.map((g) => g.id)).toEqual(["group:pd:EmailAddress:staff"]);
99
99
  });
100
100
  it("drops one occurrence and fixes the counts", () => {
101
- const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "occurrence:email:src/a.ts:3", action: "remove" })]);
101
+ const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "occurrence:pd:EmailAddress:src/a.ts:3", action: "remove" })]);
102
102
  expect(state.dataItemFiles[0].occurrences).toHaveLength(2);
103
103
  expect(state.facts.dataItems[0].occurrenceCount).toBe(2);
104
- expect(state.facts.dataItems[0].groups.find((g) => g.id === "group:email:customer")?.occurrenceCount).toBe(1);
105
- expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:email:customer")?.occurrenceCount).toBe(1);
104
+ expect(state.facts.dataItems[0].groups.find((g) => g.id === "group:pd:EmailAddress:customer")?.occurrenceCount).toBe(1);
105
+ expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:pd:EmailAddress:customer")?.occurrenceCount).toBe(1);
106
106
  });
107
107
  it("is final: a later set about a removed Fact is ignored, also through its parent", () => {
108
108
  const state = (0, apply_answers_1.applyAnswers)(facts, files, [
109
- answer({ factId: "data_item:phone", action: "remove" }),
110
- answer({ factId: "data_item:phone", action: "set", property: "labels", value: ["x"] }),
111
- answer({ factId: "occurrence:phone:src/a.ts:7", action: "set", property: "labels", value: ["x"] }),
109
+ answer({ factId: "data_item:pd:TelephoneNumber", action: "remove" }),
110
+ answer({ factId: "data_item:pd:TelephoneNumber", action: "set", property: "labels", value: ["x"] }),
111
+ answer({ factId: "occurrence:pd:TelephoneNumber:src/a.ts:7", action: "set", property: "labels", value: ["x"] }),
112
112
  ]);
113
113
  expect(state.ignored).toHaveLength(2);
114
114
  expect(state.applied).toHaveLength(1);
@@ -25,13 +25,13 @@ function scanResult() {
25
25
  files: [],
26
26
  findings: [],
27
27
  occurrences: [
28
- { id: "occurrence:email:src/api.ts:4", filePath: "src/api.ts", startLine: 4, endLine: 4, code: "const email", labels: ["contact"], group: "email:customer", groupBasis: "column", declaration: { line: 3, kind: "const" } },
29
- { id: "occurrence:email:src/api.ts:3", filePath: "src/api.ts", startLine: 3, endLine: 3, labels: [], group: "email:customer", groupBasis: "column" },
30
- { id: `occurrence:email:${ROOT}/src/abs.ts:9`, filePath: `${ROOT}/src/abs.ts`, startLine: 9, endLine: 9, labels: [] },
28
+ { id: "occurrence:pd:EmailAddress:src/api.ts:4", filePath: "src/api.ts", startLine: 4, endLine: 4, code: "const email", labels: ["pd:EmailAddress"], group: "pd:EmailAddress:customer", groupBasis: "column", declaration: { line: 3, kind: "const" } },
29
+ { id: "occurrence:pd:EmailAddress:src/api.ts:3", filePath: "src/api.ts", startLine: 3, endLine: 3, labels: [], group: "pd:EmailAddress:customer", groupBasis: "column" },
30
+ { id: `occurrence:pd:EmailAddress:${ROOT}/src/abs.ts:9`, filePath: `${ROOT}/src/abs.ts`, startLine: 9, endLine: 9, labels: [] },
31
31
  { id: "occurrence:Credit Card:src/pay.ts:2", filePath: "src/pay.ts", startLine: 2, endLine: 2, labels: [], location: "comment" },
32
32
  ],
33
33
  dataItems: [
34
- { id: "data_item:email", labels: ["contact"], occurrenceIds: ["occurrence:email:src/api.ts:4", "occurrence:email:src/api.ts:3", `occurrence:email:${ROOT}/src/abs.ts:9`], groups: [{ id: "email:customer", occurrenceIds: ["occurrence:email:src/api.ts:4", "occurrence:email:src/api.ts:3"] }] },
34
+ { id: "data_item:pd:EmailAddress", labels: ["pd:EmailAddress"], occurrenceIds: ["occurrence:pd:EmailAddress:src/api.ts:4", "occurrence:pd:EmailAddress:src/api.ts:3", `occurrence:pd:EmailAddress:${ROOT}/src/abs.ts:9`], groups: [{ id: "pd:EmailAddress:customer", occurrenceIds: ["occurrence:pd:EmailAddress:src/api.ts:4", "occurrence:pd:EmailAddress:src/api.ts:3"] }] },
35
35
  { id: "data_item:Credit Card", labels: [], occurrenceIds: ["occurrence:Credit Card:src/pay.ts:2"] },
36
36
  ],
37
37
  };
@@ -44,14 +44,14 @@ function graph() {
44
44
  graph: { schema: "dataparade-graph/1" },
45
45
  nodes: [],
46
46
  links: [
47
- { ...base, source: "dp::occurrence:email:src/api.ts:4", target: "src_api_ts_handler", relation: "occurs_in", target_kind: "function", target_file: "src/api.ts", target_line: 3 },
47
+ { ...base, source: "dp::occurrence:pd:EmailAddress:src/api.ts:4", target: "src_api_ts_handler", relation: "occurs_in", target_kind: "function", target_file: "src/api.ts", target_line: 3 },
48
48
  { ...base, source: "dp::cmp_api", target: `${ROOT}/src/api.ts`, relation: "defined_in", target_kind: "file", target_file: `${ROOT}/src/api.ts`, target_line: 1 },
49
49
  { ...base, source: "dp::flow_mail", target: "src_api_ts_send", relation: "observed_in", target_kind: "function", target_file: "src/api.ts", target_line: 5 },
50
- { ...base, source: "dp::occurrence:email:src/api.ts:4", target: "dp::occurrence:email:src/api.ts:3", relation: "declared_by", declaration_kind: "const" },
51
- { ...base, source: "dp::occurrence:email:src/api.ts:4", target: "dp::group:email:customer", relation: "occurrence_of" },
52
- { ...base, source: "dp::group:email:customer", target: "dp::data_item:email", relation: "part_of" },
53
- { ...base, source: "dp::group:email:customer", target: "dp::cmp_api", relation: "handled_by", confidence: "INFERRED", confidence_score: 0.65, basis: "same_file" },
54
- { ...base, source: "dp::group:email:customer", target: "dp::cmp_api", relation: "handled_by", confidence: "INFERRED", confidence_score: 0.65, basis: "same_file" },
50
+ { ...base, source: "dp::occurrence:pd:EmailAddress:src/api.ts:4", target: "dp::occurrence:pd:EmailAddress:src/api.ts:3", relation: "declared_by", declaration_kind: "const" },
51
+ { ...base, source: "dp::occurrence:pd:EmailAddress:src/api.ts:4", target: "dp::group:pd:EmailAddress:customer", relation: "occurrence_of" },
52
+ { ...base, source: "dp::group:pd:EmailAddress:customer", target: "dp::data_item:pd:EmailAddress", relation: "part_of" },
53
+ { ...base, source: "dp::group:pd:EmailAddress:customer", target: "dp::cmp_api", relation: "handled_by", confidence: "INFERRED", confidence_score: 0.65, basis: "same_file" },
54
+ { ...base, source: "dp::group:pd:EmailAddress:customer", target: "dp::cmp_api", relation: "handled_by", confidence: "INFERRED", confidence_score: 0.65, basis: "same_file" },
55
55
  { ...base, source: "dp::cmp_api", target: "dp::flow_mail", relation: "sends" },
56
56
  { ...base, source: "dp::flow_mail", target: "dp::cmp_mail", relation: "delivers_to" },
57
57
  ],
@@ -82,45 +82,45 @@ describe("buildFacts", () => {
82
82
  it("summarises data items with groups, and points to one file per item", () => {
83
83
  expect(facts.dataItems.map((i) => [i.id, i.file, i.occurrenceCount])).toEqual([
84
84
  ["data_item:Credit Card", "data-items/credit-card.json", 1],
85
- ["data_item:email", "data-items/email.json", 3],
85
+ ["data_item:pd:EmailAddress", "data-items/pd-emailaddress.json", 3],
86
86
  ]);
87
- const email = facts.dataItems.find((i) => i.name === "email");
87
+ const email = facts.dataItems.find((i) => i.name === "pd:EmailAddress");
88
88
  expect(email?.groups).toEqual([
89
89
  {
90
- id: "group:email:customer",
91
- identity: { kind: "group", key: "email:customer", parts: { dataItem: "email", qualifier: "customer" } },
90
+ id: "group:pd:EmailAddress:customer",
91
+ identity: { kind: "group", key: "pd:EmailAddress:customer", parts: { dataItem: "pd:EmailAddress", qualifier: "customer" } },
92
92
  label: "customer",
93
93
  basis: "column",
94
94
  occurrenceCount: 2,
95
95
  handledBy: ["cmp_api"],
96
96
  },
97
97
  ]);
98
- expect([...dataItemFiles.keys()].sort()).toEqual(["data-items/credit-card.json", "data-items/email.json"]);
98
+ expect([...dataItemFiles.keys()].sort()).toEqual(["data-items/credit-card.json", "data-items/pd-emailaddress.json"]);
99
99
  });
100
100
  it("puts every occurrence once, in its data item file, with group, code refs and declaration", () => {
101
- const email = dataItemFiles.get("data-items/email.json");
102
- expect(email?.groups).toEqual(facts.dataItems.find((i) => i.name === "email")?.groups);
101
+ const email = dataItemFiles.get("data-items/pd-emailaddress.json");
102
+ expect(email?.groups).toEqual(facts.dataItems.find((i) => i.name === "pd:EmailAddress")?.groups);
103
103
  expect(email?.occurrences.map((o) => o.id)).toEqual([
104
- "occurrence:email:src/abs.ts:9",
105
- "occurrence:email:src/api.ts:3",
106
- "occurrence:email:src/api.ts:4",
104
+ "occurrence:pd:EmailAddress:src/abs.ts:9",
105
+ "occurrence:pd:EmailAddress:src/api.ts:3",
106
+ "occurrence:pd:EmailAddress:src/api.ts:4",
107
107
  ]);
108
- const first = email?.occurrences.find((o) => o.id === "occurrence:email:src/api.ts:4");
108
+ const first = email?.occurrences.find((o) => o.id === "occurrence:pd:EmailAddress:src/api.ts:4");
109
109
  expect(first).toMatchObject({
110
- groupId: "group:email:customer",
110
+ groupId: "group:pd:EmailAddress:customer",
111
111
  filePath: "src/api.ts",
112
112
  code: "const email",
113
113
  codeRefs: [{ nodeId: "src_api_ts_handler", kind: "function", filePath: "src/api.ts", line: 3 }],
114
- declaredBy: { id: "occurrence:email:src/api.ts:3", kind: "const" },
114
+ declaredBy: { id: "occurrence:pd:EmailAddress:src/api.ts:3", kind: "const" },
115
115
  });
116
116
  expect(email?.occurrences.find((o) => o.id.endsWith("abs.ts:9"))?.groupId).toBeNull();
117
117
  expect(dataItemFiles.get("data-items/credit-card.json")?.occurrences[0].location).toBe("comment");
118
- expect(JSON.stringify(facts)).not.toContain("occurrence:email:src/api.ts:4");
118
+ expect(JSON.stringify(facts)).not.toContain("occurrence:pd:EmailAddress:src/api.ts:4");
119
119
  });
120
120
  it("keeps the non-occurrence links as relations, once, without code or structure links", () => {
121
121
  expect(facts.relations.map((r) => `${r.type} ${r.source} ${r.target}`)).toEqual([
122
122
  "delivers_to flow_mail cmp_mail",
123
- "handled_by group:email:customer cmp_api",
123
+ "handled_by group:pd:EmailAddress:customer cmp_api",
124
124
  "sends cmp_api flow_mail",
125
125
  ]);
126
126
  });
@@ -131,39 +131,39 @@ describe("buildFacts", () => {
131
131
  parts: { scheme: "app", section: "<unsectioned>", type: "asset", subType: "service", file: "src/api.ts", name: "api" },
132
132
  });
133
133
  expect(facts.dataFlows[0].identity).toMatchObject({ kind: "dataFlow", parts: { source: "app:<unsectioned>|asset|service|src/api.ts|api", file: "src/api.ts" } });
134
- const email = facts.dataItems.find((d) => d.name === "email");
135
- expect(email?.identity).toEqual({ kind: "dataItem", key: "email", parts: { name: "email" } });
136
- expect(email?.groups[0].identity).toEqual({ kind: "group", key: "email:customer", parts: { dataItem: "email", qualifier: "customer" } });
134
+ const email = facts.dataItems.find((d) => d.name === "pd:EmailAddress");
135
+ expect(email?.identity).toEqual({ kind: "dataItem", key: "pd:EmailAddress", parts: { name: "pd:EmailAddress" } });
136
+ expect(email?.groups[0].identity).toEqual({ kind: "group", key: "pd:EmailAddress:customer", parts: { dataItem: "pd:EmailAddress", qualifier: "customer" } });
137
137
  expect(dataItemFiles.get(email.file)?.identity).toEqual(email?.identity);
138
138
  });
139
139
  it("drops the line from a declaration-named group's key, and numbers groups that share a key", () => {
140
140
  const result = scanResult();
141
141
  const occurrences = [
142
- { id: "occurrence:phone:src/a.ts:12", filePath: `${ROOT}/src/a.ts`, startLine: 12, endLine: 12, labels: [] },
143
- { id: "occurrence:phone:src/a.ts:30", filePath: "src/a.ts", startLine: 30, endLine: 30, labels: [] },
144
- { id: "occurrence:phone:src/a.ts:7", filePath: "src/a.ts", startLine: 7, endLine: 7, labels: [] },
142
+ { id: "occurrence:pd:TelephoneNumber:src/a.ts:12", filePath: `${ROOT}/src/a.ts`, startLine: 12, endLine: 12, labels: [] },
143
+ { id: "occurrence:pd:TelephoneNumber:src/a.ts:30", filePath: "src/a.ts", startLine: 30, endLine: 30, labels: [] },
144
+ { id: "occurrence:pd:TelephoneNumber:src/a.ts:7", filePath: "src/a.ts", startLine: 7, endLine: 7, labels: [] },
145
145
  ];
146
146
  result.occurrences.push(...occurrences);
147
147
  result.dataItems.push({
148
- id: "data_item:phone",
148
+ id: "data_item:pd:TelephoneNumber",
149
149
  labels: [],
150
150
  occurrenceIds: occurrences.map((o) => o.id),
151
151
  groups: [
152
- { id: `phone@${ROOT}/src/a.ts:12#phone`, occurrenceIds: [occurrences[0].id] },
153
- { id: "phone@src/a.ts:30", occurrenceIds: [occurrences[1].id] },
154
- { id: "phone@src/a.ts:7", occurrenceIds: [occurrences[2].id] },
152
+ { id: `pd:TelephoneNumber@${ROOT}/src/a.ts:12#phone`, occurrenceIds: [occurrences[0].id] },
153
+ { id: "pd:TelephoneNumber@src/a.ts:30", occurrenceIds: [occurrences[1].id] },
154
+ { id: "pd:TelephoneNumber@src/a.ts:7", occurrenceIds: [occurrences[2].id] },
155
155
  ],
156
156
  });
157
- const groups = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta }).facts.dataItems.find((i) => i.name === "phone").groups;
157
+ const groups = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta }).facts.dataItems.find((i) => i.name === "pd:TelephoneNumber").groups;
158
158
  const byId = new Map(groups.map((g) => [g.id, g.identity]));
159
- expect(byId.get("group:phone@src/a.ts:12#phone")).toEqual({
159
+ expect(byId.get("group:pd:TelephoneNumber@src/a.ts:12#phone")).toEqual({
160
160
  kind: "group",
161
- key: "phone@src/a.ts#phone",
162
- parts: { dataItem: "phone", declarationFile: "src/a.ts", declarationName: "phone" },
161
+ key: "pd:TelephoneNumber@src/a.ts#phone",
162
+ parts: { dataItem: "pd:TelephoneNumber", declarationFile: "src/a.ts", declarationName: "phone" },
163
163
  });
164
164
  // Two unnamed declarations in one file share a key; the earlier line keeps it.
165
- expect(byId.get("group:phone@src/a.ts:7")).toEqual({ kind: "group", key: "phone@src/a.ts", parts: { dataItem: "phone", declarationFile: "src/a.ts" } });
166
- expect(byId.get("group:phone@src/a.ts:30")).toMatchObject({ key: "phone@src/a.ts#2", duplicateIndex: 2 });
165
+ expect(byId.get("group:pd:TelephoneNumber@src/a.ts:7")).toEqual({ kind: "group", key: "pd:TelephoneNumber@src/a.ts", parts: { dataItem: "pd:TelephoneNumber", declarationFile: "src/a.ts" } });
166
+ expect(byId.get("group:pd:TelephoneNumber@src/a.ts:30")).toMatchObject({ key: "pd:TelephoneNumber@src/a.ts#2", duplicateIndex: 2 });
167
167
  });
168
168
  it("writes scan stamps when given, and leaves them out otherwise (DATAP-876)", () => {
169
169
  expect(facts.scan).not.toHaveProperty("stamps");
@@ -183,11 +183,77 @@ describe("buildFacts", () => {
183
183
  expect(stamped.scan.stamps).toEqual(stamps);
184
184
  expect(() => schema_1.factsFileSchema.parse(stamped)).not.toThrow();
185
185
  });
186
+ it("carries the data categories the scanner observed on each flow (DATAP-856)", () => {
187
+ const result = scanResult();
188
+ result.scanResult.dataFlows[0].dataCategories = ["pd:TelephoneNumber", "pd:EmailAddress"];
189
+ result.scanResult.dataFlows.push({ id: "flow_ping", sourceComponentId: "cmp_api", targetComponentId: "cmp_mail", type: "webhook", confidence: 0.8, dataCategories: [] });
190
+ result.scanResult.dataFlows.push({ id: "flow_unchecked", sourceComponentId: "cmp_mail", targetComponentId: "cmp_api", type: "webhook", confidence: 0.8 });
191
+ const built = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta }).facts;
192
+ const flow = (id) => built.dataFlows.find((f) => f.id === id);
193
+ expect(flow("flow_mail")?.dataCategories).toEqual(["pd:EmailAddress", "pd:TelephoneNumber"]);
194
+ expect(flow("flow_ping")?.dataCategories).toEqual([]);
195
+ expect(flow("flow_unchecked")).not.toHaveProperty("dataCategories");
196
+ expect(() => schema_1.factsFileSchema.parse(built)).not.toThrow();
197
+ expect(schema_1.factsFileSchema.parse(built).dataFlows.find((f) => f.id === "flow_mail")?.dataCategories).toEqual(["pd:EmailAddress", "pd:TelephoneNumber"]);
198
+ });
199
+ it("copies flow controls with paths relative to the scan root (DATAP-915)", () => {
200
+ const result = scanResult();
201
+ result.scanResult.dataFlows[0].controls = [
202
+ { control: "tls", effect: "mitigates", filePath: `${ROOT}/src/api.ts`, line: 2 },
203
+ { control: "timeout", effect: "mitigates", filePath: `${ROOT}/src/api.ts`, line: 5 },
204
+ ];
205
+ const { facts } = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta });
206
+ const flow = facts.dataFlows[0];
207
+ expect(flow.controls).toEqual([
208
+ { control: "tls", effect: "mitigates", filePath: "src/api.ts", line: 2 },
209
+ { control: "timeout", effect: "mitigates", filePath: "src/api.ts", line: 5 },
210
+ ]);
211
+ expect(schema_1.factsFileSchema.safeParse(facts).success).toBe(true);
212
+ });
213
+ it("records the Git branch in the scan block, and leaves it out when not given (DATAP-925)", () => {
214
+ const withBranch = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta, gitBranch: "feature/threats" }).facts;
215
+ expect(withBranch.scan.gitBranch).toBe("feature/threats");
216
+ expect(schema_1.factsFileSchema.parse(withBranch).scan.gitBranch).toBe("feature/threats");
217
+ const detached = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta, gitBranch: null }).facts;
218
+ expect(detached.scan.gitBranch).toBeNull();
219
+ expect(schema_1.factsFileSchema.safeParse(detached).success).toBe(true);
220
+ const withoutBranch = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta }).facts;
221
+ expect(withoutBranch.scan).not.toHaveProperty("gitBranch");
222
+ });
223
+ it("writes no threats in facts.json (DATAP-920)", () => {
224
+ const result = scanResult();
225
+ result.scanResult.dataFlows[0].controls = [{ control: "tls", effect: "mitigates", filePath: `${ROOT}/src/api.ts`, line: 2 }];
226
+ const { facts } = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta });
227
+ for (const component of facts.components)
228
+ expect(component).not.toHaveProperty("threats");
229
+ for (const dataFlow of facts.dataFlows)
230
+ expect(dataFlow).not.toHaveProperty("threats");
231
+ expect(JSON.stringify(facts)).not.toContain('"threats"');
232
+ });
233
+ it("copies flow authentication evidence with paths relative to the scan root (DATAP-912)", () => {
234
+ const result = scanResult();
235
+ result.scanResult.dataFlows[0].authentication = {
236
+ status: "seen",
237
+ kinds: ["api_key"],
238
+ evidence: [{ kind: "api_key", filePath: `${ROOT}/src/mail.ts`, line: 12 }],
239
+ };
240
+ const { facts } = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta });
241
+ expect(facts.dataFlows[0].authentication).toEqual({
242
+ status: "seen",
243
+ kinds: ["api_key"],
244
+ evidence: [{ kind: "api_key", filePath: "src/mail.ts", line: 12 }],
245
+ });
246
+ expect(schema_1.factsFileSchema.safeParse(facts).success).toBe(true);
247
+ });
248
+ it("leaves authentication out when the scanner did not check the flow", () => {
249
+ const { facts } = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta });
250
+ expect(facts.dataFlows[0].authentication).toBeUndefined();
251
+ });
186
252
  it("works without a knowledge graph", () => {
187
253
  const bare = (0, build_facts_1.buildFacts)({ result: scanResult(), ...meta });
188
254
  expect(bare.facts.relations).toEqual([]);
189
255
  expect(bare.facts.components[0].codeRefs).toEqual([]);
190
- expect(bare.facts.dataItems.find((i) => i.name === "email")?.groups[0].handledBy).toEqual([]);
256
+ expect(bare.facts.dataItems.find((i) => i.name === "pd:EmailAddress")?.groups[0].handledBy).toEqual([]);
191
257
  });
192
258
  });
193
259
  describe("writing and reading Facts", () => {
@@ -201,10 +267,25 @@ describe("writing and reading Facts", () => {
201
267
  const built = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta });
202
268
  (0, io_1.writeFactsOutput)(layout, built.facts, built.dataItemFiles);
203
269
  expect(fs_1.default.readdirSync(dir).sort()).toEqual(["data-items", "facts.json"]);
204
- expect(fs_1.default.readdirSync(layout.dataItemsDir).sort()).toEqual(["credit-card.json", "email.json"]);
270
+ expect(fs_1.default.readdirSync(layout.dataItemsDir).sort()).toEqual(["credit-card.json", "pd-emailaddress.json"]);
205
271
  const facts = (0, io_1.readFacts)(layout);
206
272
  expect(facts).toEqual(built.facts);
207
- expect((0, io_1.readDataItemFiles)(layout, facts).map((f) => f.name)).toEqual(["Credit Card", "email"]);
273
+ expect((0, io_1.readDataItemFiles)(layout, facts).map((f) => f.name)).toEqual(["Credit Card", "pd:EmailAddress"]);
274
+ });
275
+ it("reads a facts.json from an unreleased build that still has threats, without them (DATAP-920)", () => {
276
+ const layout = (0, layout_1.layoutForDir)(dir);
277
+ const built = (0, build_facts_1.buildFacts)({ result: scanResult(), ...meta });
278
+ (0, io_1.writeFactsOutput)(layout, built.facts, built.dataItemFiles);
279
+ const legacyThreats = [{ framework: "stride", category: "S", status: "unknown", ruleId: "stride/v2/process" }];
280
+ const onDisk = JSON.parse(fs_1.default.readFileSync(layout.factsPath, "utf8"));
281
+ onDisk.components[0].threats = legacyThreats;
282
+ onDisk.dataFlows[0].threats = legacyThreats;
283
+ fs_1.default.writeFileSync(layout.factsPath, JSON.stringify(onDisk));
284
+ const facts = (0, io_1.readFacts)(layout);
285
+ for (const component of facts.components)
286
+ expect(component).not.toHaveProperty("threats");
287
+ for (const dataFlow of facts.dataFlows)
288
+ expect(dataFlow).not.toHaveProperty("threats");
208
289
  });
209
290
  it("replaces facts.json and removes stale data item files on a rescan, but keeps answers.json", () => {
210
291
  const layout = (0, layout_1.layoutForDir)(dir);
@@ -216,7 +297,7 @@ describe("writing and reading Facts", () => {
216
297
  next.dataItems = next.dataItems.slice(0, 1);
217
298
  const second = (0, build_facts_1.buildFacts)({ result: next, ...meta, scannedAt: "2026-10-11T00:00:00.000Z" });
218
299
  (0, io_1.writeFactsOutput)(layout, second.facts, second.dataItemFiles);
219
- expect(fs_1.default.readdirSync(layout.dataItemsDir)).toEqual(["email.json"]);
300
+ expect(fs_1.default.readdirSync(layout.dataItemsDir)).toEqual(["pd-emailaddress.json"]);
220
301
  expect((0, io_1.readFacts)(layout).scan.scannedAt).toBe("2026-10-11T00:00:00.000Z");
221
302
  expect(fs_1.default.readFileSync(layout.answersPath, "utf8")).toBe(answersBefore);
222
303
  expect((0, io_1.readAnswers)(layout).answers).toHaveLength(1);
@@ -124,6 +124,19 @@ describe("data item and group identities", () => {
124
124
  it("keys a data item by its name", () => {
125
125
  expect((0, identity_1.dataItemIdentity)("Credit Card")).toEqual({ kind: "dataItem", key: "Credit Card", parts: { name: "Credit Card" } });
126
126
  });
127
+ it("splits group ids whose data item is a DPV CURIE at the end of the type, not its first colon (DATAP-947)", () => {
128
+ expect((0, identity_1.dataItemIdentity)("pd:EmailAddress")).toEqual({ kind: "dataItem", key: "pd:EmailAddress", parts: { name: "pd:EmailAddress" } });
129
+ expect((0, identity_1.groupIdentity)("pd:EmailAddress", "pd:EmailAddress:customer")).toEqual({
130
+ kind: "group",
131
+ key: "pd:EmailAddress:customer",
132
+ parts: { dataItem: "pd:EmailAddress", qualifier: "customer" },
133
+ });
134
+ expect((0, identity_1.groupIdentity)("pd:EmailAddress", "pd:EmailAddress@src/a.js:12#email")).toEqual({
135
+ kind: "group",
136
+ key: "pd:EmailAddress@src/a.js#email",
137
+ parts: { dataItem: "pd:EmailAddress", declarationFile: "src/a.js", declarationName: "email" },
138
+ });
139
+ });
127
140
  it("splits group ids into the data item and the qualifier or column", () => {
128
141
  expect((0, identity_1.groupIdentity)("email", "email:customer")).toEqual({ kind: "group", key: "email:customer", parts: { dataItem: "email", qualifier: "customer" } });
129
142
  expect((0, identity_1.groupIdentity)("email", "email@contact_email")).toEqual({ kind: "group", key: "email@contact_email", parts: { dataItem: "email", column: "contact_email" } });
@@ -80,6 +80,38 @@ describe("readGitStamps", () => {
80
80
  expect((0, scan_stamps_1.readGitStamps)(plain, null)).toEqual({ commitSha: null, dirty: null, rootCommitSha: null, scanRoot: null });
81
81
  });
82
82
  });
83
+ describe("readGitBranch (DATAP-925)", () => {
84
+ let work;
85
+ let repo;
86
+ const noContinuousIntegration = {};
87
+ beforeEach(() => {
88
+ work = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "git-branch-"));
89
+ repo = path_1.default.join(work, "repo");
90
+ fs_1.default.mkdirSync(path_1.default.join(repo, "services"), { recursive: true });
91
+ git(repo, "init", "-q");
92
+ git(repo, "checkout", "-q", "-b", "feature/threats");
93
+ commit(repo, "first");
94
+ });
95
+ afterEach(() => fs_1.default.rmSync(work, { recursive: true, force: true }));
96
+ it("reads the checked-out branch, also from a subfolder", () => {
97
+ expect((0, scan_stamps_1.readGitBranch)(repo, noContinuousIntegration)).toBe("feature/threats");
98
+ expect((0, scan_stamps_1.readGitBranch)(path_1.default.join(repo, "services"), noContinuousIntegration)).toBe("feature/threats");
99
+ });
100
+ it("is null on a detached HEAD, unless a CI branch variable names the branch", () => {
101
+ git(repo, "checkout", "-q", "--detach");
102
+ expect((0, scan_stamps_1.readGitBranch)(repo, noContinuousIntegration)).toBeNull();
103
+ expect((0, scan_stamps_1.readGitBranch)(repo, { GITHUB_HEAD_REF: "pr-branch", GITHUB_REF_NAME: "12/merge", GITHUB_REF_TYPE: "branch" })).toBe("pr-branch");
104
+ expect((0, scan_stamps_1.readGitBranch)(repo, { GITHUB_REF_NAME: "main", GITHUB_REF_TYPE: "branch" })).toBe("main");
105
+ expect((0, scan_stamps_1.readGitBranch)(repo, { GITHUB_REF_NAME: "v1.0.0", GITHUB_REF_TYPE: "tag" })).toBeNull();
106
+ expect((0, scan_stamps_1.readGitBranch)(repo, { CI_COMMIT_REF_NAME: "develop" })).toBe("develop");
107
+ expect((0, scan_stamps_1.readGitBranch)(repo, { CI_COMMIT_REF_NAME: "v1.0.0", CI_COMMIT_TAG: "v1.0.0" })).toBeNull();
108
+ });
109
+ it("is null outside Git", () => {
110
+ const plain = path_1.default.join(work, "plain");
111
+ fs_1.default.mkdirSync(plain);
112
+ expect((0, scan_stamps_1.readGitBranch)(plain, { GITHUB_REF_NAME: "main", GITHUB_REF_TYPE: "branch" })).toBeNull();
113
+ });
114
+ });
83
115
  describe("buildScanStamps", () => {
84
116
  it("matches the schema", () => {
85
117
  const stamps = (0, scan_stamps_1.buildScanStamps)({