@dataparade/cli 0.0.26 → 0.0.29
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.
- package/README.md +56 -13
- package/dist/package.json +7 -7
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +0 -1
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.js +102 -68
- package/dist/src/discoveries/contract/ocsf-discovery-record.d.ts +1 -1
- package/dist/src/discoveries/load-ocsf-discoveries.d.ts +0 -8
- package/dist/src/discoveries/load-ocsf-discoveries.js +0 -31
- package/dist/src/discoveries/write-ocsf-discoveries.d.ts +0 -8
- package/dist/src/discoveries/write-ocsf-discoveries.js +0 -38
- package/dist/src/evals/run-model-matrix.js +0 -1
- package/dist/src/export/export-ocsf.d.ts +18 -0
- package/dist/src/export/export-ocsf.js +104 -0
- package/dist/src/export/register-export-commands.d.ts +2 -0
- package/dist/src/export/register-export-commands.js +30 -0
- package/dist/src/facts/apply-answers.d.ts +29 -0
- package/dist/src/facts/apply-answers.js +202 -0
- package/dist/src/facts/build-facts.d.ts +24 -0
- package/dist/src/facts/build-facts.js +198 -0
- package/dist/src/facts/io.d.ts +17 -0
- package/dist/src/facts/io.js +67 -0
- package/dist/src/facts/layout.d.ts +29 -0
- package/dist/src/facts/layout.js +38 -0
- package/dist/src/facts/schema.d.ts +265 -0
- package/dist/src/facts/schema.js +122 -0
- package/dist/src/facts/slug.d.ts +7 -0
- package/dist/src/facts/slug.js +47 -0
- package/dist/src/kb/brief.d.ts +1 -2
- package/dist/src/kb/brief.js +2 -4
- package/dist/src/kb/interview-record.d.ts +18 -0
- package/dist/src/kb/interview-record.js +70 -0
- package/dist/src/kb/kb-store.d.ts +24 -18
- package/dist/src/kb/kb-store.js +89 -28
- package/dist/src/kb/land.d.ts +32 -12
- package/dist/src/kb/land.js +97 -90
- package/dist/src/kb/migrate.d.ts +23 -0
- package/dist/src/kb/migrate.js +91 -0
- package/dist/src/kb/project-diagram.js +4 -4
- package/dist/src/kb/register-kb-commands.js +71 -20
- package/dist/src/observability/scan-sentry.js +0 -1
- package/dist/src/output/scan-output-excludes.d.ts +1 -1
- package/dist/src/output/scan-output-excludes.js +14 -5
- package/dist/src/output/write-scan-knowledge.d.ts +33 -0
- package/dist/src/output/write-scan-knowledge.js +115 -0
- package/dist/src/platform-api/estimate-scan-footprint.d.ts +31 -0
- package/dist/src/platform-api/estimate-scan-footprint.js +75 -2
- package/dist/src/platform-api/fetch-failure.d.ts +5 -0
- package/dist/src/platform-api/fetch-failure.js +13 -0
- package/dist/src/platform-api/upload-client.d.ts +5 -0
- package/dist/src/platform-api/upload-client.js +11 -1
- package/dist/src/ui/scan-progress-renderer.d.ts +16 -0
- package/dist/src/ui/scan-progress-renderer.js +29 -3
- package/dist/src/ui/teaching-lines.js +18 -6
- package/dist/src/upload/collect-scan-sidecars.d.ts +2 -27
- package/dist/src/upload/collect-scan-sidecars.js +25 -121
- package/dist/src/upload/run-upload.js +0 -3
- package/dist/tests/cli/cli.spec.js +30 -13
- package/dist/tests/helpers/facts-fixture.d.ts +9 -0
- package/dist/tests/helpers/facts-fixture.js +72 -0
- package/dist/tests/unit/cli/scan-ai-session-fallback.spec.js +156 -0
- package/dist/tests/unit/export/export-ocsf.spec.js +72 -0
- package/dist/tests/unit/facts/apply-answers.spec.d.ts +1 -0
- package/dist/tests/unit/facts/apply-answers.spec.js +128 -0
- package/dist/tests/unit/facts/build-facts.spec.d.ts +1 -0
- package/dist/tests/unit/facts/build-facts.spec.js +161 -0
- package/dist/tests/unit/facts/slug.spec.d.ts +1 -0
- package/dist/tests/unit/facts/slug.spec.js +30 -0
- package/dist/tests/unit/kb/kb-interview-loop.spec.js +83 -35
- package/dist/tests/unit/kb/migrate.spec.d.ts +1 -0
- package/dist/tests/unit/kb/migrate.spec.js +108 -0
- package/dist/tests/unit/output/graphify-cache-dir.spec.d.ts +1 -0
- package/dist/tests/unit/output/graphify-cache-dir.spec.js +20 -0
- package/dist/tests/unit/output/scan-output-excludes.spec.js +4 -2
- package/dist/tests/unit/platform-api/estimate-scan-footprint.spec.js +77 -0
- package/dist/tests/unit/platform-api/upload-client.spec.js +2 -2
- package/dist/tests/unit/ui/scan-progress-renderer.spec.js +21 -0
- package/dist/tests/unit/ui/teaching-lines.spec.js +16 -0
- package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +46 -46
- package/dist/tests/unit/upload/pack-scan-upload.spec.js +6 -6
- package/dist/vendor/scanner/dist/src/classifier/component-factory.js +6 -14
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +1 -0
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +32 -1
- package/dist/vendor/scanner/dist/src/classifier/naming.d.ts +5 -0
- package/dist/vendor/scanner/dist/src/classifier/naming.js +8 -4
- package/dist/vendor/scanner/dist/src/core/pipeline/build-scan-personal-data-layers.js +26 -14
- package/dist/vendor/scanner/dist/src/core/pipeline/enrich-personal-data-layers.js +3 -1
- package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.d.ts +18 -0
- package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.js +125 -66
- package/dist/vendor/scanner/dist/src/index.d.ts +2 -0
- package/dist/vendor/scanner/dist/src/index.js +7 -2
- package/dist/vendor/scanner/dist/src/ingest/file-system.d.ts +5 -0
- package/dist/vendor/scanner/dist/src/ingest/file-system.js +5 -0
- package/dist/vendor/scanner/dist/src/ingest/gitignore.d.ts +17 -0
- package/dist/vendor/scanner/dist/src/ingest/gitignore.js +47 -9
- package/dist/vendor/scanner/dist/src/ingest/schema-files.d.ts +10 -2
- package/dist/vendor/scanner/dist/src/ingest/schema-files.js +24 -7
- package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.d.ts +3 -0
- package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.js +45 -0
- package/dist/vendor/scanner/dist/src/patterns/scan-exclusions.js +7 -0
- package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.d.ts +24 -0
- package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.js +19 -6
- package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.js +5 -2
- package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-aliases.js +5 -2
- package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +8 -0
- package/dist/vendor/scanner/patterns/third-party.patterns.yaml +9 -0
- package/package.json +7 -7
- package/dist/src/discoveries/project-collected-diagram.d.ts +0 -7
- package/dist/src/discoveries/project-collected-diagram.js +0 -182
- package/dist/src/discoveries/project-ocsf-to-discoveries-document.d.ts +0 -16
- package/dist/src/discoveries/project-ocsf-to-discoveries-document.js +0 -269
- package/dist/src/discoveries/scan-result-to-discovery-input.d.ts +0 -13
- package/dist/src/discoveries/scan-result-to-discovery-input.js +0 -60
- package/dist/src/output/write-knowledge-graph.d.ts +0 -20
- package/dist/src/output/write-knowledge-graph.js +0 -53
- package/dist/src/output/write-scan-discoveries.d.ts +0 -17
- package/dist/src/output/write-scan-discoveries.js +0 -61
- package/dist/tests/unit/discoveries/project-collected-diagram.spec.js +0 -97
- package/dist/tests/unit/discoveries/rescan-replaces-scan-records.spec.js +0 -89
- /package/dist/tests/unit/{discoveries/project-collected-diagram.spec.d.ts → cli/scan-ai-session-fallback.spec.d.ts} +0 -0
- /package/dist/tests/unit/{discoveries/rescan-replaces-scan-records.spec.d.ts → export/export-ocsf.spec.d.ts} +0 -0
|
@@ -4,47 +4,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const os_1 = __importDefault(require("os"));
|
|
8
7
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const
|
|
10
|
-
const scan_entity_uri_1 = require("../../../src/discoveries/scan-entity-uri");
|
|
11
|
-
const write_ocsf_discoveries_1 = require("../../../src/discoveries/write-ocsf-discoveries");
|
|
8
|
+
const io_1 = require("../../../src/facts/io");
|
|
12
9
|
const brief_1 = require("../../../src/kb/brief");
|
|
13
10
|
const kb_store_1 = require("../../../src/kb/kb-store");
|
|
14
11
|
const land_1 = require("../../../src/kb/land");
|
|
15
12
|
const project_diagram_1 = require("../../../src/kb/project-diagram");
|
|
16
|
-
const
|
|
13
|
+
const facts_fixture_1 = require("../../helpers/facts-fixture");
|
|
17
14
|
const SKILL_SHA = "f".repeat(40);
|
|
18
15
|
const REVIEWER = "dev@example.com";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
{ id: "cmp_mail", name: "Sendgrid", type: "third_party", subType: "email", confidence: 0.9, sourceLocations: [] },
|
|
25
|
-
{ id: "cmp_user", name: "Customer", type: "actor", subType: "", confidence: 0.8, sourceLocations: [] },
|
|
26
|
-
],
|
|
27
|
-
dataFlows: [
|
|
28
|
-
{ id: "flow_mail", sourceComponentId: "cmp_api", targetComponentId: "cmp_mail", type: "api_call", confidence: 0.9 },
|
|
29
|
-
{ id: "flow_login", sourceComponentId: "cmp_user", targetComponentId: "cmp_api", type: "api_call", confidence: 0.9 },
|
|
30
|
-
].filter((f) => flows.includes(f.id)),
|
|
31
|
-
occurrences: [],
|
|
32
|
-
dataItems: [],
|
|
33
|
-
}, { assertedAt: "2026-10-09T00:00:00.000Z" });
|
|
34
|
-
(0, write_ocsf_discoveries_1.removeScanRecordsForScanPath)(paths.discoveriesDir, SCAN_PATH);
|
|
35
|
-
(0, write_ocsf_discoveries_1.writeOcsfDiscoveryRecordsToDir)(records, paths.discoveriesDir);
|
|
16
|
+
/** A rescan: Facts are replaced, answers.json is not touched. */
|
|
17
|
+
function rescan(paths, keepFlows = ["flow_mail", "flow_login"]) {
|
|
18
|
+
const { facts, files } = (0, facts_fixture_1.sampleFacts)();
|
|
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])));
|
|
36
21
|
}
|
|
37
22
|
describe("live interview loop: brief → land → project", () => {
|
|
38
23
|
let paths;
|
|
39
24
|
let evidence;
|
|
40
25
|
beforeEach(() => {
|
|
41
|
-
paths = (0,
|
|
42
|
-
writeScan(paths);
|
|
26
|
+
paths = (0, facts_fixture_1.makeKbDir)();
|
|
43
27
|
fs_1.default.mkdirSync(paths.evidenceDir, { recursive: true });
|
|
44
28
|
evidence = "evidence/2026-10-09-session.md";
|
|
45
|
-
fs_1.default.writeFileSync(path_1.default.join(paths.
|
|
29
|
+
fs_1.default.writeFileSync(path_1.default.join(paths.dir, evidence), "Q: What goes to Sendgrid?\nA: Customer email addresses, to send receipts.\n");
|
|
46
30
|
});
|
|
47
|
-
afterEach(() => fs_1.default.rmSync(paths.
|
|
31
|
+
afterEach(() => fs_1.default.rmSync(paths.dir, { recursive: true, force: true }));
|
|
48
32
|
const land = (brief, target, slot, value, extra = {}) => (0, land_1.landInterviewAnswer)(paths, { briefSha: brief, target, slot, value, reviewer: REVIEWER, evidence, skillSha: SKILL_SHA, ...extra });
|
|
49
33
|
it("orders questions: scope, outbound third-party flows, then people only", () => {
|
|
50
34
|
const { brief, sha } = (0, brief_1.writeKbBrief)(paths);
|
|
@@ -86,11 +70,12 @@ describe("live interview loop: brief → land → project", () => {
|
|
|
86
70
|
});
|
|
87
71
|
it("records a correction that supersedes the earlier answer", () => {
|
|
88
72
|
const { sha } = (0, brief_1.writeKbBrief)(paths);
|
|
89
|
-
const first = land(sha, "flow_mail", "purpose", "marketing");
|
|
90
|
-
const second = land(sha, "flow_mail", "purpose", "service_provision");
|
|
91
|
-
expect(second.supersedes).toBe(first.
|
|
92
|
-
expect(second.
|
|
93
|
-
|
|
73
|
+
const first = land(sha, "flow_mail", "purpose", "marketing", { now: new Date(Date.now() - 1000) });
|
|
74
|
+
const second = land(sha, "flow_mail", "purpose", "service_provision", { now: new Date(Date.now() + 1000) });
|
|
75
|
+
expect(second.supersedes).toBe(first.id);
|
|
76
|
+
expect(second.id).not.toBe(first.id);
|
|
77
|
+
expect((0, io_1.readAnswers)(paths).answers).toHaveLength(2);
|
|
78
|
+
const flow = (0, kb_store_1.loadKbState)(paths).document.dataFlows.find((f) => f.id === "flow_mail");
|
|
94
79
|
expect(flow?.purpose).toBe("service_provision");
|
|
95
80
|
});
|
|
96
81
|
it.each([
|
|
@@ -112,17 +97,17 @@ describe("live interview loop: brief → land → project", () => {
|
|
|
112
97
|
expect(() => land("0".repeat(40), "flow_mail", "purpose", "security")).toThrow(/No brief/);
|
|
113
98
|
const { sha, path: briefPath } = (0, brief_1.writeKbBrief)(paths);
|
|
114
99
|
const edited = JSON.parse(fs_1.default.readFileSync(briefPath, "utf8"));
|
|
115
|
-
edited.questions.push({ asserts:
|
|
100
|
+
edited.questions.push({ asserts: "cmp_mail", slot: "actor_kind", shape: "D4", status: "unknown", about: "" });
|
|
116
101
|
fs_1.default.writeFileSync(briefPath, JSON.stringify(edited));
|
|
117
102
|
expect(() => (0, brief_1.readKbBrief)(paths, sha)).toThrow(/edited after it was written/);
|
|
118
103
|
});
|
|
119
104
|
it("keeps an answer about a flow the next scan no longer has, without breaking projection", () => {
|
|
120
105
|
const { sha } = (0, brief_1.writeKbBrief)(paths);
|
|
121
106
|
land(sha, "flow_mail", "purpose", "security");
|
|
122
|
-
|
|
107
|
+
rescan(paths, ["flow_login"]); // re-scan: flow_mail is gone
|
|
123
108
|
const state = (0, kb_store_1.loadKbState)(paths);
|
|
124
109
|
expect(state.orphans).toHaveLength(1);
|
|
125
|
-
expect(state.
|
|
110
|
+
expect(state.answers.filter((a) => a.source === "interview")).toHaveLength(1);
|
|
126
111
|
expect(() => (0, project_diagram_1.writeKbDiagram)(paths)).not.toThrow();
|
|
127
112
|
expect((0, brief_1.writeKbBrief)(paths).orphanCount).toBe(1);
|
|
128
113
|
});
|
|
@@ -130,6 +115,69 @@ describe("live interview loop: brief → land → project", () => {
|
|
|
130
115
|
const { sha } = (0, brief_1.writeKbBrief)(paths);
|
|
131
116
|
const result = land(sha, "flow_mail", "purpose", "security", { dryRun: true });
|
|
132
117
|
expect(result.path).toBeNull();
|
|
133
|
-
expect(
|
|
118
|
+
expect(fs_1.default.existsSync(paths.answersPath)).toBe(false);
|
|
119
|
+
});
|
|
120
|
+
it("stores the who, when and evidence of an interview answer, with a category list as a list", () => {
|
|
121
|
+
const { sha } = (0, brief_1.writeKbBrief)(paths);
|
|
122
|
+
const landed = land(sha, "flow_mail", "data_categories", "identifiers, contact", { now: new Date("2026-10-10T12:00:00.000Z") });
|
|
123
|
+
expect(landed.path).toBe(paths.answersPath);
|
|
124
|
+
expect((0, io_1.readAnswers)(paths).answers).toEqual([
|
|
125
|
+
{
|
|
126
|
+
id: landed.id,
|
|
127
|
+
factId: "flow_mail",
|
|
128
|
+
action: "set",
|
|
129
|
+
property: "data_categories",
|
|
130
|
+
value: ["contact", "identifiers"],
|
|
131
|
+
by: REVIEWER,
|
|
132
|
+
at: "2026-10-10T12:00:00.000Z",
|
|
133
|
+
source: "interview",
|
|
134
|
+
evidence,
|
|
135
|
+
briefSha: sha,
|
|
136
|
+
skillSha: SKILL_SHA,
|
|
137
|
+
},
|
|
138
|
+
]);
|
|
139
|
+
});
|
|
140
|
+
it("does not change facts.json when answers land, and a rescan keeps answers.json", () => {
|
|
141
|
+
const { sha } = (0, brief_1.writeKbBrief)(paths);
|
|
142
|
+
land(sha, "flow_mail", "purpose", "security");
|
|
143
|
+
const factsBefore = fs_1.default.readFileSync(paths.factsPath, "utf8");
|
|
144
|
+
expect(factsBefore).not.toContain("security");
|
|
145
|
+
const answersBefore = fs_1.default.readFileSync(paths.answersPath, "utf8");
|
|
146
|
+
rescan(paths);
|
|
147
|
+
expect(fs_1.default.readFileSync(paths.answersPath, "utf8")).toBe(answersBefore);
|
|
148
|
+
expect((0, kb_store_1.loadKbState)(paths).document.dataFlows.find((f) => f.id === "flow_mail")?.purpose).toBe("security");
|
|
149
|
+
});
|
|
150
|
+
describe("review answers", () => {
|
|
151
|
+
const review = (input) => (0, land_1.landReviewAnswer)(paths, { action: "set", reviewer: REVIEWER, ...input });
|
|
152
|
+
it("removes a Fact and sets a property, and the applied state shows both", () => {
|
|
153
|
+
review({ target: "flow_login", action: "remove", evidence: "not a real flow" });
|
|
154
|
+
review({ target: "cmp_mail", property: "name", value: "SendGrid Inc" });
|
|
155
|
+
const state = (0, kb_store_1.loadKbState)(paths);
|
|
156
|
+
expect(state.applied.facts.dataFlows.map((f) => f.id)).toEqual(["flow_mail"]);
|
|
157
|
+
expect(state.document.components.find((c) => c.id === "cmp_mail")?.name).toBe("SendGrid Inc");
|
|
158
|
+
const [removed, set] = (0, io_1.readAnswers)(paths).answers;
|
|
159
|
+
expect(removed).toMatchObject({ factId: "flow_login", action: "remove", source: "review", by: REVIEWER, evidence: "not a real flow" });
|
|
160
|
+
expect(set).toMatchObject({ factId: "cmp_mail", action: "set", property: "name", value: "SendGrid Inc" });
|
|
161
|
+
// The removed flow is no longer asked about.
|
|
162
|
+
expect((0, brief_1.writeKbBrief)(paths).brief.flows.map((f) => f.id)).toEqual(["flow_mail"]);
|
|
163
|
+
});
|
|
164
|
+
it("reads a JSON value for lists", () => {
|
|
165
|
+
review({ target: "data_item:email", property: "labels", value: '["contact","pii"]' });
|
|
166
|
+
expect((0, kb_store_1.loadKbState)(paths).applied.facts.dataItems[0].labels).toEqual(["contact", "pii"]);
|
|
167
|
+
});
|
|
168
|
+
it.each([
|
|
169
|
+
["an unknown Fact", { target: "flow_nope", action: "remove" }, /not a Fact in this scan/],
|
|
170
|
+
["a protected property", { target: "cmp_api", property: "id", value: "x" }, /can't be changed/],
|
|
171
|
+
["a set without a value", { target: "cmp_api", property: "name" }, /needs both a property and a value/],
|
|
172
|
+
["a remove with a value", { target: "cmp_api", action: "remove", value: "x" }, /takes no property or value/],
|
|
173
|
+
["a model as reviewer", { target: "cmp_api", property: "name", value: "x", reviewer: "claude-code" }, /reviewer must be the developer/],
|
|
174
|
+
])("refuses %s", (_label, input, message) => {
|
|
175
|
+
expect(() => review(input)).toThrow(message);
|
|
176
|
+
expect(fs_1.default.existsSync(paths.answersPath)).toBe(false);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
it("needs a scan first", () => {
|
|
180
|
+
fs_1.default.rmSync(paths.factsPath);
|
|
181
|
+
expect(() => (0, brief_1.writeKbBrief)(paths)).toThrow(/No facts\.json/);
|
|
134
182
|
});
|
|
135
183
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
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 scan_discovery_to_ocsf_1 = require("../../../src/discoveries/scan-discovery-to-ocsf");
|
|
10
|
+
const scan_entity_uri_1 = require("../../../src/discoveries/scan-entity-uri");
|
|
11
|
+
const write_ocsf_discoveries_1 = require("../../../src/discoveries/write-ocsf-discoveries");
|
|
12
|
+
const io_1 = require("../../../src/facts/io");
|
|
13
|
+
const interview_record_1 = require("../../../src/kb/interview-record");
|
|
14
|
+
const kb_store_1 = require("../../../src/kb/kb-store");
|
|
15
|
+
const migrate_1 = require("../../../src/kb/migrate");
|
|
16
|
+
const facts_fixture_1 = require("../../helpers/facts-fixture");
|
|
17
|
+
const SCAN_PATH = "/Users/dev/repo";
|
|
18
|
+
const SHA = "a".repeat(40);
|
|
19
|
+
/** What CLI 0.0.26 left in ocsf-discoveries/: scan records and interview records. */
|
|
20
|
+
function writeOldFolder(dir) {
|
|
21
|
+
const scan = (0, scan_discovery_to_ocsf_1.landScanDiscoveryToOcsfRecords)({
|
|
22
|
+
scanPath: SCAN_PATH,
|
|
23
|
+
components: [{ id: "cmp_mail", name: "Sendgrid", type: "third_party", subType: "email", confidence: 0.9, sourceLocations: [] }],
|
|
24
|
+
dataFlows: [],
|
|
25
|
+
occurrences: [],
|
|
26
|
+
dataItems: [],
|
|
27
|
+
}, { assertedAt: "2026-10-09T00:00:00.000Z" });
|
|
28
|
+
const interview = (id, factId, slot, value, at) => {
|
|
29
|
+
const record = (0, interview_record_1.buildInterviewOcsfRecord)({
|
|
30
|
+
uid: `dp:discovery/interview/${id}`,
|
|
31
|
+
answer: { id, factId, action: "set", property: slot, value, by: "dev@example.com", at, source: "interview", evidence: "evidence/session.md" },
|
|
32
|
+
slot,
|
|
33
|
+
briefSha: SHA,
|
|
34
|
+
skillSha: SHA,
|
|
35
|
+
});
|
|
36
|
+
const asserts = (0, scan_entity_uri_1.scanEntityAsserts)(SCAN_PATH, factId);
|
|
37
|
+
return { ...record, resources: [{ ...record.resources[0], uid: asserts }], dataparade: { ...record.dataparade, asserts } };
|
|
38
|
+
};
|
|
39
|
+
(0, write_ocsf_discoveries_1.writeOcsfDiscoveryRecordsToDir)([
|
|
40
|
+
...scan,
|
|
41
|
+
interview("flow_mail_purpose_20261009", "flow_mail", "purpose", "marketing", "2026-10-09T10:00:00.000Z"),
|
|
42
|
+
interview("flow_mail_categories_20261009", "flow_mail", "data_categories", '["contact"]', "2026-10-09T11:00:00.000Z"),
|
|
43
|
+
], dir);
|
|
44
|
+
}
|
|
45
|
+
describe("kb migrate", () => {
|
|
46
|
+
let paths;
|
|
47
|
+
let oldDir;
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
paths = (0, facts_fixture_1.makeKbDir)();
|
|
50
|
+
oldDir = path_1.default.join(paths.dir, "ocsf-discoveries");
|
|
51
|
+
writeOldFolder(oldDir);
|
|
52
|
+
});
|
|
53
|
+
afterEach(() => fs_1.default.rmSync(paths.dir, { recursive: true, force: true }));
|
|
54
|
+
it("turns interview records into answers and drops scan records", () => {
|
|
55
|
+
const result = (0, migrate_1.migrateInterviewRecords)(paths);
|
|
56
|
+
expect(result).toMatchObject({ migrated: 2, alreadyMigrated: 0, dryRun: false });
|
|
57
|
+
expect(result.scanRecordsDropped).toBeGreaterThan(0);
|
|
58
|
+
const answers = (0, io_1.readAnswers)(paths).answers;
|
|
59
|
+
expect(answers).toHaveLength(2);
|
|
60
|
+
const purpose = answers.find((a) => a.property === "purpose");
|
|
61
|
+
expect(purpose).toMatchObject({
|
|
62
|
+
factId: "flow_mail",
|
|
63
|
+
action: "set",
|
|
64
|
+
value: "marketing",
|
|
65
|
+
by: "dev@example.com",
|
|
66
|
+
at: "2026-10-09T10:00:00.000Z",
|
|
67
|
+
source: "interview",
|
|
68
|
+
evidence: "evidence/session.md",
|
|
69
|
+
briefSha: SHA,
|
|
70
|
+
skillSha: SHA,
|
|
71
|
+
});
|
|
72
|
+
expect(answers.find((a) => a.property === "data_categories")?.value).toEqual(["contact"]);
|
|
73
|
+
expect(JSON.stringify(answers)).not.toContain(SCAN_PATH);
|
|
74
|
+
});
|
|
75
|
+
it("makes the old answers show up in the applied state", () => {
|
|
76
|
+
(0, migrate_1.migrateInterviewRecords)(paths);
|
|
77
|
+
const flow = (0, kb_store_1.loadKbState)(paths).applied.facts.dataFlows.find((f) => f.id === "flow_mail");
|
|
78
|
+
expect(flow.purpose).toBe("marketing");
|
|
79
|
+
expect(flow.data_categories).toEqual(["contact"]);
|
|
80
|
+
});
|
|
81
|
+
it("is safe to run twice", () => {
|
|
82
|
+
(0, migrate_1.migrateInterviewRecords)(paths);
|
|
83
|
+
const again = (0, migrate_1.migrateInterviewRecords)(paths);
|
|
84
|
+
expect(again).toMatchObject({ migrated: 0, alreadyMigrated: 2 });
|
|
85
|
+
expect((0, io_1.readAnswers)(paths).answers).toHaveLength(2);
|
|
86
|
+
});
|
|
87
|
+
it("writes nothing on --dry-run, and leaves the old folder alone", () => {
|
|
88
|
+
const before = fs_1.default.readdirSync(oldDir).length;
|
|
89
|
+
expect((0, migrate_1.migrateInterviewRecords)(paths, { dryRun: true })).toMatchObject({ migrated: 2, dryRun: true });
|
|
90
|
+
expect(fs_1.default.existsSync(paths.answersPath)).toBe(false);
|
|
91
|
+
expect(fs_1.default.readdirSync(oldDir)).toHaveLength(before);
|
|
92
|
+
});
|
|
93
|
+
it("reads from another folder", () => {
|
|
94
|
+
const elsewhere = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dp-old-"));
|
|
95
|
+
try {
|
|
96
|
+
writeOldFolder(elsewhere);
|
|
97
|
+
fs_1.default.rmSync(oldDir, { recursive: true });
|
|
98
|
+
expect((0, migrate_1.migrateInterviewRecords)(paths, { from: elsewhere }).migrated).toBe(2);
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
fs_1.default.rmSync(elsewhere, { recursive: true, force: true });
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
it("says what is missing when there is no old folder", () => {
|
|
105
|
+
fs_1.default.rmSync(oldDir, { recursive: true });
|
|
106
|
+
expect(() => (0, migrate_1.migrateInterviewRecords)(paths)).toThrow(/--from/);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
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 path_1 = __importDefault(require("path"));
|
|
7
|
+
const write_scan_knowledge_1 = require("../../../src/output/write-scan-knowledge");
|
|
8
|
+
describe('graphifyCacheDir', () => {
|
|
9
|
+
it('is outside the scan root, per scan root, and stable', () => {
|
|
10
|
+
const one = (0, write_scan_knowledge_1.graphifyCacheDir)('/repo/a', { XDG_CACHE_HOME: '/cache' });
|
|
11
|
+
expect(one).toBe((0, write_scan_knowledge_1.graphifyCacheDir)('/repo/a', { XDG_CACHE_HOME: '/cache' }));
|
|
12
|
+
expect(one).not.toBe((0, write_scan_knowledge_1.graphifyCacheDir)('/repo/b', { XDG_CACHE_HOME: '/cache' }));
|
|
13
|
+
expect(one.startsWith(path_1.default.join('/cache', 'dataparade', 'graphify') + path_1.default.sep)).toBe(true);
|
|
14
|
+
expect(path_1.default.basename(one)).toMatch(/^[0-9a-f]{16}$/);
|
|
15
|
+
});
|
|
16
|
+
it('can be moved with DATAPARADE_CACHE_DIR', () => {
|
|
17
|
+
const dir = (0, write_scan_knowledge_1.graphifyCacheDir)('/repo/a', { DATAPARADE_CACHE_DIR: '/elsewhere', XDG_CACHE_HOME: '/cache' });
|
|
18
|
+
expect(dir.startsWith(path_1.default.join('/elsewhere', 'graphify'))).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const scan_output_excludes_1 = require("../../../src/output/scan-output-excludes");
|
|
4
4
|
describe("scanOutputExcludes", () => {
|
|
5
|
-
it("excludes
|
|
5
|
+
it("excludes the default .dataparade folder inside the scanned repo", () => {
|
|
6
6
|
expect((0, scan_output_excludes_1.scanOutputExcludes)("/repo", "/repo/.dataparade/dataflow.json")).toEqual([".dataparade/**"]);
|
|
7
7
|
expect((0, scan_output_excludes_1.scanOutputExcludes)("/repo", "/repo/out/kb/dataflow.json")).toEqual(["out/kb/**"]);
|
|
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", "
|
|
11
|
+
expect(globs).toEqual(expect.arrayContaining(["dataflow.json", "facts.json", "data-items/**", "graphify.json", "answers.json", "briefs/**", "evidence/**"]));
|
|
12
|
+
// Output of CLI 0.0.26 and earlier is still kept out of a rescan.
|
|
13
|
+
expect(globs).toEqual(expect.arrayContaining(["ocsf-discoveries/**", "graphify-out/**", "dataparade-graph.json"]));
|
|
12
14
|
});
|
|
13
15
|
it("adds nothing when the output is outside the repo", () => {
|
|
14
16
|
expect((0, scan_output_excludes_1.scanOutputExcludes)("/repo", "/tmp/kb/dataflow.json")).toEqual([]);
|
|
@@ -37,6 +37,10 @@ const fs = __importStar(require("fs"));
|
|
|
37
37
|
const os = __importStar(require("os"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const estimate_scan_footprint_1 = require("../../../src/platform-api/estimate-scan-footprint");
|
|
40
|
+
async function write(root, rel, content = "x") {
|
|
41
|
+
await fs.promises.mkdir(path.dirname(path.join(root, rel)), { recursive: true });
|
|
42
|
+
await fs.promises.writeFile(path.join(root, rel), content);
|
|
43
|
+
}
|
|
40
44
|
describe("estimateScanFootprint", () => {
|
|
41
45
|
it("counts files and bytes under scan root", async () => {
|
|
42
46
|
const root = await fs.promises.mkdtemp(path.join(os.tmpdir(), "dp-footprint-"));
|
|
@@ -47,4 +51,77 @@ describe("estimateScanFootprint", () => {
|
|
|
47
51
|
expect(footprint.fileCount).toBeGreaterThanOrEqual(1);
|
|
48
52
|
expect(footprint.bytesIngested).toBeGreaterThanOrEqual(5);
|
|
49
53
|
});
|
|
54
|
+
it("counts files and folders without entering excluded or ignored ones", async () => {
|
|
55
|
+
const root = await fs.promises.mkdtemp(path.join(os.tmpdir(), "dp-tree-"));
|
|
56
|
+
try {
|
|
57
|
+
await write(root, ".gitignore", "generated/\n");
|
|
58
|
+
await write(root, "app/api/users/route.ts");
|
|
59
|
+
await write(root, "app/page.tsx");
|
|
60
|
+
await write(root, "lib/db.ts");
|
|
61
|
+
await write(root, "lib/db.test.ts");
|
|
62
|
+
await write(root, "docs/guide/a.json");
|
|
63
|
+
for (const skipped of [
|
|
64
|
+
"node_modules/pkg/index.js",
|
|
65
|
+
".next/server/chunk.js",
|
|
66
|
+
".git/HEAD",
|
|
67
|
+
"dist/index.js",
|
|
68
|
+
"build/index.js",
|
|
69
|
+
"coverage/lcov.info",
|
|
70
|
+
"generated/prisma/index.js",
|
|
71
|
+
]) {
|
|
72
|
+
await write(root, skipped);
|
|
73
|
+
}
|
|
74
|
+
const readdir = jest.spyOn(fs.promises, "readdir");
|
|
75
|
+
let summary;
|
|
76
|
+
try {
|
|
77
|
+
summary = await (0, estimate_scan_footprint_1.summarizeScanTree)(root, ["docs/**"]);
|
|
78
|
+
const visited = readdir.mock.calls.map(([dir]) => path.relative(root, String(dir)));
|
|
79
|
+
for (const pruned of ["node_modules", ".next", ".git", "dist", "build", "coverage", "generated", "docs"]) {
|
|
80
|
+
expect(visited).not.toContain(pruned);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
readdir.mockRestore();
|
|
85
|
+
}
|
|
86
|
+
// route.ts, page.tsx, db.ts and the 11-byte .gitignore; db.test.ts is a default exclude.
|
|
87
|
+
expect(summary).toEqual({
|
|
88
|
+
fileCount: 4,
|
|
89
|
+
directoryCount: 4,
|
|
90
|
+
bytes: 14,
|
|
91
|
+
capped: false,
|
|
92
|
+
topLevelFolders: [
|
|
93
|
+
{ name: "app", fileCount: 2, bytes: 2 },
|
|
94
|
+
{ name: "lib", fileCount: 1, bytes: 1 },
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
await fs.promises.rm(root, { recursive: true, force: true });
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
it("warns about a large tree and names its biggest folders", () => {
|
|
103
|
+
const small = (0, estimate_scan_footprint_1.describeScanTree)({
|
|
104
|
+
fileCount: 352,
|
|
105
|
+
directoryCount: 40,
|
|
106
|
+
bytes: 2 * 1024 * 1024,
|
|
107
|
+
capped: false,
|
|
108
|
+
topLevelFolders: [{ name: "lib", fileCount: 352, bytes: 2 * 1024 * 1024 }],
|
|
109
|
+
});
|
|
110
|
+
expect(small).toEqual({ line: "Scanning 352 files in 40 folders (2 MB)." });
|
|
111
|
+
const large = (0, estimate_scan_footprint_1.describeScanTree)({
|
|
112
|
+
fileCount: estimate_scan_footprint_1.LARGE_TREE_FILE_COUNT + 1,
|
|
113
|
+
directoryCount: 3_000,
|
|
114
|
+
bytes: 150 * 1024 * 1024,
|
|
115
|
+
capped: false,
|
|
116
|
+
topLevelFolders: [
|
|
117
|
+
{ name: "public", fileCount: 12_000, bytes: 1 },
|
|
118
|
+
{ name: "messages", fileCount: 5_000, bytes: 1 },
|
|
119
|
+
{ name: "app", fileCount: 2_000, bytes: 1 },
|
|
120
|
+
{ name: "lib", fileCount: 1_001, bytes: 1 },
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
expect(large.line).toBe("Scanning 20,001 files in 3,000 folders (150 MB).");
|
|
124
|
+
expect(large.warning).toContain("public/ (12,000 files), messages/ (5,000 files), app/ (2,000 files)");
|
|
125
|
+
expect(large.warning).toContain("--exclude 'public/**' 'messages/**' 'app/**'");
|
|
126
|
+
});
|
|
50
127
|
});
|
|
@@ -83,7 +83,7 @@ describe('cliUploadPreview', () => {
|
|
|
83
83
|
dataflow: { schemaVersion: '1.0', graph: { nodes: [], edges: [] } },
|
|
84
84
|
files: [
|
|
85
85
|
{
|
|
86
|
-
relativePath: 'graphify
|
|
86
|
+
relativePath: 'graphify.json',
|
|
87
87
|
content: '{"nodes":[]}',
|
|
88
88
|
},
|
|
89
89
|
],
|
|
@@ -94,7 +94,7 @@ describe('cliUploadPreview', () => {
|
|
|
94
94
|
const filesUrl = global.fetch.mock.calls[1][0];
|
|
95
95
|
expect(filesUrl).toContain('/api/scans/cli/upload/draft-3/files');
|
|
96
96
|
const filesBody = JSON.parse(global.fetch.mock.calls[1][1].body);
|
|
97
|
-
expect(filesBody.files[0]?.relativePath).toBe('graphify
|
|
97
|
+
expect(filesBody.files[0]?.relativePath).toBe('graphify.json');
|
|
98
98
|
});
|
|
99
99
|
it('throws with API error message', async () => {
|
|
100
100
|
global.fetch = jest.fn().mockResolvedValue({
|
|
@@ -129,6 +129,27 @@ describe('ScanProgressRenderer', () => {
|
|
|
129
129
|
expect(joined).not.toContain('Your preview is ready whenever you are');
|
|
130
130
|
expect(ui.usesClackChrome).toBe(false);
|
|
131
131
|
});
|
|
132
|
+
it('plain finish reports a failed upload instead of the success line', async () => {
|
|
133
|
+
const { lines, writeLine } = captureLines();
|
|
134
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
135
|
+
isTTY: false,
|
|
136
|
+
noColor: true,
|
|
137
|
+
writeLine,
|
|
138
|
+
});
|
|
139
|
+
ui.onUploadFailed({
|
|
140
|
+
reason: 'Too many anonymous CLI scans from this IP (max 3)',
|
|
141
|
+
retryCommand: 'dataparade upload .dataparade/dataflow.json',
|
|
142
|
+
hint: 'Set DATAPARADE_WORKSPACE_API_KEY.',
|
|
143
|
+
});
|
|
144
|
+
ui.finish();
|
|
145
|
+
const joined = lines.join('\n');
|
|
146
|
+
expect(joined).toContain('The upload did not complete: Too many anonymous CLI scans from this IP (max 3).');
|
|
147
|
+
expect(joined).toContain('dataparade upload .dataparade/dataflow.json');
|
|
148
|
+
expect(joined).toContain('Set DATAPARADE_WORKSPACE_API_KEY.');
|
|
149
|
+
expect(joined).toContain('Scan finished. The upload did not complete.');
|
|
150
|
+
expect(joined).not.toContain('All done — nice work.');
|
|
151
|
+
expect(joined).not.toContain('Jump into DataParade');
|
|
152
|
+
});
|
|
132
153
|
it('formats the preview link with ANSI when color is on', () => {
|
|
133
154
|
const plain = (0, scan_progress_renderer_1.formatPreviewLink)('https://example.test/preview', false);
|
|
134
155
|
expect(plain).toBe('https://example.test/preview');
|
|
@@ -59,4 +59,20 @@ describe('buildTeachingLineGroups', () => {
|
|
|
59
59
|
const groups = (0, teaching_lines_1.buildTeachingLineGroups)([], []);
|
|
60
60
|
expect((0, teaching_lines_1.flattenTeachingLines)(groups)).toEqual([]);
|
|
61
61
|
});
|
|
62
|
+
it('counts every Next.js spelling as one framework and skips manifest hints', () => {
|
|
63
|
+
const groups = (0, teaching_lines_1.buildTeachingLineGroups)([
|
|
64
|
+
finding('express_route', { framework: 'next_or_react_route' }),
|
|
65
|
+
finding('express_route', { framework: 'nextjs' }),
|
|
66
|
+
finding('express_route', { framework: 'next' }),
|
|
67
|
+
finding('express_route', {
|
|
68
|
+
framework: 'nextjs',
|
|
69
|
+
sourceContext: 'dependency_manifest',
|
|
70
|
+
}),
|
|
71
|
+
], []);
|
|
72
|
+
expect(groups.routes).toEqual(['Found 3 Next.js routes']);
|
|
73
|
+
});
|
|
74
|
+
it('turns underscores in vendor names into title-cased words', () => {
|
|
75
|
+
const groups = (0, teaching_lines_1.buildTeachingLineGroups)([], [thirdParty('Google_identity'), thirdParty('stripe')]);
|
|
76
|
+
expect(groups.outbound).toEqual(['Calls out to Google Identity and Stripe']);
|
|
77
|
+
});
|
|
62
78
|
});
|
|
@@ -7,60 +7,60 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
7
7
|
const os_1 = __importDefault(require("os"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const collect_scan_sidecars_1 = require("../../../src/upload/collect-scan-sidecars");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
dataparade: {
|
|
13
|
-
asserts: `dp:scan/entity/${entityId}`,
|
|
14
|
-
...(slot ? { asserted_slot: slot, asserted_value: value } : {}),
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
describe('collectScanSidecars', () => {
|
|
10
|
+
const pack_scan_upload_1 = require("../../../src/upload/pack-scan-upload");
|
|
11
|
+
describe('collectScanUploadFiles', () => {
|
|
19
12
|
let dir;
|
|
20
13
|
beforeEach(() => {
|
|
21
|
-
dir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'scan-
|
|
14
|
+
dir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'scan-upload-files-'));
|
|
22
15
|
fs_1.default.writeFileSync(path_1.default.join(dir, 'dataflow.json'), '{}\n');
|
|
23
16
|
});
|
|
24
17
|
afterEach(() => {
|
|
25
18
|
fs_1.default.rmSync(dir, { recursive: true, force: true });
|
|
26
19
|
});
|
|
27
|
-
it('sends
|
|
28
|
-
fs_1.default.
|
|
29
|
-
fs_1.default.
|
|
30
|
-
fs_1.default.writeFileSync(path_1.default.join(dir, '
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
fs_1.default.writeFileSync(path_1.default.join(discoveries, 'occurrence.json'), JSON.stringify(fact('occurrence:email:src/api.ts:4', 'file_path', 'src/api.ts')));
|
|
44
|
-
fs_1.default.writeFileSync(path_1.default.join(discoveries, 'data-item.json'), JSON.stringify(fact('data_item:email', 'occurrence_ids', '["occurrence:email:src/api.ts:4"]')));
|
|
45
|
-
const sidecars = (0, collect_scan_sidecars_1.collectScanSidecars)(path_1.default.join(dir, 'dataflow.json'));
|
|
46
|
-
expect(sidecars.graphifyGraph).toEqual({ nodes: [{ id: 'src/api.ts' }] });
|
|
47
|
-
expect(sidecars.dataparadeGraph).toMatchObject({
|
|
48
|
-
links: [
|
|
49
|
-
expect.objectContaining({
|
|
50
|
-
relation: 'occurs_in',
|
|
51
|
-
target: 'src/api.ts',
|
|
52
|
-
}),
|
|
53
|
-
],
|
|
54
|
-
});
|
|
55
|
-
expect(sidecars.facts).toHaveLength(2);
|
|
56
|
-
expect(JSON.stringify(sidecars.facts)).toContain('occurrence:email');
|
|
57
|
-
expect(JSON.stringify(sidecars.facts)).toContain('data_item:email');
|
|
58
|
-
expect(JSON.stringify(sidecars.facts)).not.toContain('cmp_orders');
|
|
20
|
+
it('sends facts.json, the data item files, graphify.json and answers.json, in that order', () => {
|
|
21
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'facts.json'), '{"schemaVersion":1}');
|
|
22
|
+
fs_1.default.mkdirSync(path_1.default.join(dir, 'data-items'));
|
|
23
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'data-items', 'phone.json'), '{"id":"data_item:phone"}');
|
|
24
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'data-items', 'email.json'), '{"id":"data_item:email"}');
|
|
25
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'graphify.json'), '{"nodes":[]}');
|
|
26
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'answers.json'), '{"schemaVersion":1,"answers":[]}');
|
|
27
|
+
const files = (0, collect_scan_sidecars_1.collectScanUploadFiles)(path_1.default.join(dir, 'dataflow.json'));
|
|
28
|
+
expect(files.map((file) => file.relativePath)).toEqual([
|
|
29
|
+
'facts.json',
|
|
30
|
+
'data-items/email.json',
|
|
31
|
+
'data-items/phone.json',
|
|
32
|
+
'graphify.json',
|
|
33
|
+
'answers.json',
|
|
34
|
+
]);
|
|
35
|
+
expect(files[0].content).toBe('{"schemaVersion":1}');
|
|
59
36
|
});
|
|
60
|
-
it('
|
|
37
|
+
it('leaves out answers.json and graphify.json when they do not exist', () => {
|
|
38
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'facts.json'), '{"schemaVersion":1}');
|
|
39
|
+
const files = (0, collect_scan_sidecars_1.collectScanUploadFiles)(path_1.default.join(dir, 'dataflow.json'));
|
|
40
|
+
expect(files.map((file) => file.relativePath)).toEqual(['facts.json']);
|
|
41
|
+
});
|
|
42
|
+
it('skips a file that is not a JSON object, and ignores the old layout', () => {
|
|
43
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'facts.json'), 'not json');
|
|
61
44
|
fs_1.default.mkdirSync(path_1.default.join(dir, 'ocsf-discoveries'));
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
expect(
|
|
45
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'ocsf-discoveries', 'a.json'), '{}');
|
|
46
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'dataparade-graph.json'), '{}');
|
|
47
|
+
expect((0, collect_scan_sidecars_1.collectScanUploadFiles)(path_1.default.join(dir, 'dataflow.json'))).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
it('packs many small data item files into few requests and splits a large graphify.json', () => {
|
|
50
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'facts.json'), '{"schemaVersion":1}');
|
|
51
|
+
fs_1.default.mkdirSync(path_1.default.join(dir, 'data-items'));
|
|
52
|
+
for (let index = 0; index < 5; index += 1) {
|
|
53
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'data-items', `item-${index}.json`), `{"n":${index}}`);
|
|
54
|
+
}
|
|
55
|
+
const big = JSON.stringify({ nodes: [{ id: 'x'.repeat(pack_scan_upload_1.SCAN_UPLOAD_MAX_JSON_BYTES * 2) }] });
|
|
56
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'graphify.json'), big);
|
|
57
|
+
const requests = (0, pack_scan_upload_1.packScanUploadRequests)((0, collect_scan_sidecars_1.collectScanUploadFiles)(path_1.default.join(dir, 'dataflow.json')));
|
|
58
|
+
const batches = requests.filter((request) => 'files' in request);
|
|
59
|
+
const parts = requests.filter((request) => 'part' in request);
|
|
60
|
+
expect(batches[0].files.map((file) => file.relativePath)).toEqual(expect.arrayContaining(['facts.json', 'data-items/item-0.json', 'data-items/item-4.json']));
|
|
61
|
+
expect(parts.length).toBeGreaterThanOrEqual(3);
|
|
62
|
+
for (const request of requests) {
|
|
63
|
+
expect(Buffer.byteLength(JSON.stringify(request), 'utf8')).toBeLessThanOrEqual(pack_scan_upload_1.SCAN_UPLOAD_MAX_JSON_BYTES);
|
|
64
|
+
}
|
|
65
65
|
});
|
|
66
66
|
});
|
|
@@ -4,14 +4,14 @@ const pack_scan_upload_1 = require("../../../src/upload/pack-scan-upload");
|
|
|
4
4
|
describe('packScanUploadRequests', () => {
|
|
5
5
|
it('keeps small files together and splits a file that does not fit', () => {
|
|
6
6
|
const requests = (0, pack_scan_upload_1.packScanUploadRequests)([
|
|
7
|
-
{ relativePath: '
|
|
8
|
-
{ relativePath: '
|
|
9
|
-
{ relativePath: 'graphify
|
|
7
|
+
{ relativePath: 'data-items/a.json', content: 'aa' },
|
|
8
|
+
{ relativePath: 'data-items/b.json', content: 'bb' },
|
|
9
|
+
{ relativePath: 'graphify.json', content: 'x'.repeat(200) },
|
|
10
10
|
], 200);
|
|
11
11
|
expect(requests[0]).toEqual({
|
|
12
12
|
files: [
|
|
13
|
-
{ relativePath: '
|
|
14
|
-
{ relativePath: '
|
|
13
|
+
{ relativePath: 'data-items/a.json', content: 'aa' },
|
|
14
|
+
{ relativePath: 'data-items/b.json', content: 'bb' },
|
|
15
15
|
],
|
|
16
16
|
});
|
|
17
17
|
const parts = requests.slice(1);
|
|
@@ -29,7 +29,7 @@ describe('packScanUploadRequests', () => {
|
|
|
29
29
|
expect(pack_scan_upload_1.SCAN_UPLOAD_MAX_JSON_BYTES).toBeLessThanOrEqual(4_000_000);
|
|
30
30
|
const requests = (0, pack_scan_upload_1.packScanUploadRequests)([
|
|
31
31
|
{
|
|
32
|
-
relativePath: 'graphify
|
|
32
|
+
relativePath: 'graphify.json',
|
|
33
33
|
content: 'x'.repeat(pack_scan_upload_1.SCAN_UPLOAD_MAX_JSON_BYTES),
|
|
34
34
|
},
|
|
35
35
|
]);
|