@dataparade/cli 0.0.31 → 0.0.33
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 -1
- package/dist/package.json +4 -3
- package/dist/src/ai-enrichment/fallbacks.js +12 -1
- package/dist/src/cli.js +50 -4
- package/dist/src/core/pipeline/omit-internal-implementation.js +13 -6
- package/dist/src/diff/register-diff-command.d.ts +4 -0
- package/dist/src/diff/register-diff-command.js +79 -0
- package/dist/src/diff/run-diff.d.ts +80 -0
- package/dist/src/diff/run-diff.js +206 -0
- package/dist/src/diff/upload-diff.d.ts +26 -0
- package/dist/src/diff/upload-diff.js +69 -0
- package/dist/src/facts/apply-answers.js +1 -1
- package/dist/src/facts/build-facts.d.ts +3 -1
- package/dist/src/facts/build-facts.js +10 -1
- package/dist/src/facts/identity.d.ts +27 -0
- package/dist/src/facts/identity.js +203 -0
- package/dist/src/facts/io.d.ts +2 -0
- package/dist/src/facts/io.js +7 -0
- package/dist/src/facts/scan-stamps.d.ts +55 -0
- package/dist/src/facts/scan-stamps.js +165 -0
- package/dist/src/facts/schema.d.ts +243 -7
- package/dist/src/facts/schema.js +71 -1
- package/dist/src/kb/answer-fingerprint.d.ts +44 -0
- package/dist/src/kb/answer-fingerprint.js +173 -0
- package/dist/src/kb/brief.d.ts +8 -1
- package/dist/src/kb/brief.js +18 -2
- package/dist/src/kb/land.js +3 -0
- package/dist/src/kb/register-kb-commands.js +7 -1
- package/dist/src/output/git-context.d.ts +25 -0
- package/dist/src/output/git-context.js +122 -0
- package/dist/src/output/scan-output-excludes.js +5 -1
- package/dist/src/output/write-scan-knowledge.d.ts +2 -0
- package/dist/src/output/write-scan-knowledge.js +1 -0
- package/dist/src/platform-api/dataparade-app-base-url.d.ts +8 -4
- package/dist/src/platform-api/dataparade-app-base-url.js +10 -5
- package/dist/src/platform-api/upload-client.d.ts +1 -1
- package/dist/src/platform-api/upload-client.js +32 -1
- package/dist/src/platform-api/upload.types.d.ts +55 -0
- package/dist/src/sensitive-scan/process.d.ts +5 -0
- package/dist/src/sensitive-scan/process.js +48 -0
- package/dist/src/sensitive-scan/project.d.ts +12 -0
- package/dist/src/sensitive-scan/project.js +177 -0
- package/dist/src/sensitive-scan/report.d.ts +50 -0
- package/dist/src/sensitive-scan/report.js +32 -0
- package/dist/src/sensitive-scan/sessions.d.ts +2 -0
- package/dist/src/sensitive-scan/sessions.js +120 -0
- package/dist/src/ui/scan-progress-renderer.d.ts +1 -0
- package/dist/src/ui/scan-progress-renderer.js +8 -0
- package/dist/src/upload/build-preview-url.d.ts +2 -2
- package/dist/src/upload/build-preview-url.js +4 -4
- package/dist/src/upload/run-upload.js +6 -2
- package/dist/src/upload/types.d.ts +2 -0
- package/dist/tests/unit/ai-enrichment/fallbacks.spec.js +30 -0
- package/dist/tests/unit/core/omit-internal-implementation.spec.js +21 -0
- package/dist/tests/unit/diff/run-diff.spec.d.ts +1 -0
- package/dist/tests/unit/diff/run-diff.spec.js +189 -0
- package/dist/tests/unit/diff/upload-diff.spec.d.ts +1 -0
- package/dist/tests/unit/diff/upload-diff.spec.js +81 -0
- package/dist/tests/unit/facts/apply-answers.spec.js +1 -1
- package/dist/tests/unit/facts/build-facts.spec.js +67 -1
- package/dist/tests/unit/facts/identity.spec.d.ts +1 -0
- package/dist/tests/unit/facts/identity.spec.js +148 -0
- package/dist/tests/unit/facts/scan-stamps.spec.d.ts +1 -0
- package/dist/tests/unit/facts/scan-stamps.spec.js +95 -0
- package/dist/tests/unit/kb/answer-fingerprint.spec.d.ts +1 -0
- package/dist/tests/unit/kb/answer-fingerprint.spec.js +157 -0
- package/dist/tests/unit/kb/kb-interview-loop.spec.js +16 -0
- package/dist/tests/unit/output/git-context.spec.d.ts +1 -0
- package/dist/tests/unit/output/git-context.spec.js +98 -0
- package/dist/tests/unit/platform-api/dataparade-app-base-url.spec.js +9 -0
- package/dist/tests/unit/platform-api/upload-client.spec.js +101 -1
- package/dist/tests/unit/sensitive-scan/project.spec.d.ts +1 -0
- package/dist/tests/unit/sensitive-scan/project.spec.js +98 -0
- package/dist/tests/unit/upload/build-preview-url.spec.js +4 -0
- package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +1 -0
- package/dist/tests/unit/upload/run-upload.spec.js +32 -0
- package/dist/vendor/kb-compare/dist/src/canonical.d.ts +80 -0
- package/dist/vendor/kb-compare/dist/src/canonical.js +119 -0
- package/dist/vendor/kb-compare/dist/src/change-set.d.ts +144 -0
- package/dist/vendor/kb-compare/dist/src/change-set.js +80 -0
- package/dist/vendor/kb-compare/dist/src/comparable.d.ts +23 -0
- package/dist/vendor/kb-compare/dist/src/comparable.js +48 -0
- package/dist/vendor/kb-compare/dist/src/compare.d.ts +52 -0
- package/dist/vendor/kb-compare/dist/src/compare.js +370 -0
- package/dist/vendor/kb-compare/dist/src/fingerprint.d.ts +40 -0
- package/dist/vendor/kb-compare/dist/src/fingerprint.js +88 -0
- package/dist/vendor/kb-compare/dist/src/index.d.ts +15 -0
- package/dist/vendor/kb-compare/dist/src/index.js +34 -0
- package/dist/vendor/kb-compare/dist/src/input.d.ts +128 -0
- package/dist/vendor/kb-compare/dist/src/input.js +75 -0
- package/dist/vendor/kb-compare/dist/src/slot-rules.d.ts +69 -0
- package/dist/vendor/kb-compare/dist/src/slot-rules.js +203 -0
- package/dist/vendor/kb-compare/dist/src/summary.d.ts +3 -0
- package/dist/vendor/kb-compare/dist/src/summary.js +47 -0
- package/dist/vendor/kb-compare/package.json +6 -0
- package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.d.ts +11 -0
- package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.js +2 -0
- package/dist/vendor/scanner/dist/src/analyzers/registry.d.ts +2 -0
- package/dist/vendor/scanner/dist/src/analyzers/registry.js +3 -2
- package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.d.ts +17 -0
- package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.js +11 -0
- package/dist/vendor/scanner/dist/src/classifier/application-injection.js +5 -0
- package/dist/vendor/scanner/dist/src/classifier/component-factory.js +33 -3
- package/dist/vendor/scanner/dist/src/classifier/enhance.js +14 -0
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +8 -0
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +43 -2
- package/dist/vendor/scanner/dist/src/classifier/postprocessing.js +4 -1
- package/dist/vendor/scanner/dist/src/config/third-party-detection-config.d.ts +41 -0
- package/dist/vendor/scanner/dist/src/config/third-party-detection-config.js +65 -1
- package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.d.ts +8 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.js +11 -1
- package/dist/vendor/scanner/dist/src/core/pipeline/structural-scan.js +2 -0
- package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.d.ts +5 -0
- package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.js +10 -2
- package/dist/vendor/scanner/dist/src/eval/canonical/scanner/data-flows.js +4 -4
- package/dist/vendor/scanner/dist/src/index.d.ts +1 -1
- package/dist/vendor/scanner/dist/src/index.js +4 -2
- package/dist/vendor/scanner/dist/src/patterns/config.js +7 -1
- package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.d.ts +14 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.js +108 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.d.ts +93 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.js +1206 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.d.ts +180 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.js +1022 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python.d.ts +6 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python.js +49 -1
- package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.d.ts +2 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.js +80 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.d.ts +23 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.js +145 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.d.ts +30 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.js +575 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/typescript.js +12 -0
- package/dist/vendor/scanner/dist/src/patterns/engine.js +6 -1
- package/dist/vendor/scanner/package.json +3 -1
- package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +198 -0
- package/dist/vendor/scanner/patterns/component-taxonomy.yaml +1 -1
- package/dist/vendor/scanner/patterns/python.patterns.yaml +10 -0
- package/dist/vendor/scanner/patterns/third-party.patterns.yaml +271 -0
- package/dist/vendor/scanner/patterns/typescript.patterns.yaml +21 -0
- package/package.json +4 -3
|
@@ -172,4 +172,25 @@ describe('omitInternalImplementationNodes', () => {
|
|
|
172
172
|
], [], { readSource: () => undefined });
|
|
173
173
|
expect(result.components).toHaveLength(1);
|
|
174
174
|
});
|
|
175
|
+
it('keeps an HTTP client call whose host is known, such as a Cloud Run service', () => {
|
|
176
|
+
const result = (0, omit_internal_implementation_1.omitInternalImplementationNodes)([
|
|
177
|
+
{
|
|
178
|
+
id: 'cloud-run',
|
|
179
|
+
name: 'orders (Cloud Run)',
|
|
180
|
+
type: 'asset',
|
|
181
|
+
subType: 'api',
|
|
182
|
+
detectedFrom: [{ pattern: 'external_api_call' }],
|
|
183
|
+
properties: {
|
|
184
|
+
client: 'axios',
|
|
185
|
+
host: 'orders-123.us-central1.run.app',
|
|
186
|
+
url: [
|
|
187
|
+
'https://orders-123.us-central1.run.app/health',
|
|
188
|
+
'https://orders-123.us-central1.run.app/v1/chat',
|
|
189
|
+
],
|
|
190
|
+
platform: 'gcp/cloud_run',
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
], []);
|
|
194
|
+
expect(result.components.map((c) => c.id)).toEqual(['cloud-run']);
|
|
195
|
+
});
|
|
175
196
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,189 @@
|
|
|
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 child_process_1 = require("child_process");
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const run_diff_1 = require("../../../src/diff/run-diff");
|
|
11
|
+
function git(repo, ...args) {
|
|
12
|
+
return (0, child_process_1.execFileSync)("git", ["-C", repo, ...args], { encoding: "utf8" }).trim();
|
|
13
|
+
}
|
|
14
|
+
function commitAll(repo, message) {
|
|
15
|
+
git(repo, "add", "-A");
|
|
16
|
+
git(repo, "-c", "user.name=Test", "-c", "user.email=test@example.com", "commit", "-q", "-m", message);
|
|
17
|
+
return git(repo, "rev-parse", "HEAD");
|
|
18
|
+
}
|
|
19
|
+
const STAMPS = {
|
|
20
|
+
scannerCommit: "f".repeat(40),
|
|
21
|
+
cliVersion: "0",
|
|
22
|
+
catalogHash: "sha256:0123456789abcdef",
|
|
23
|
+
configHash: "sha256:fedcba9876543210",
|
|
24
|
+
aiInference: false,
|
|
25
|
+
structureGraph: true,
|
|
26
|
+
commitSha: null,
|
|
27
|
+
dirty: null,
|
|
28
|
+
rootCommitSha: null,
|
|
29
|
+
scanRoot: null,
|
|
30
|
+
};
|
|
31
|
+
const TOOLS = { cliVersion: STAMPS.cliVersion, scannerCommit: STAMPS.scannerCommit, catalogHash: STAMPS.catalogHash };
|
|
32
|
+
const facts = (components, stamps = STAMPS) => ({
|
|
33
|
+
schemaVersion: 1,
|
|
34
|
+
scan: { projectName: "p", scannedAt: "t", cliVersion: "0", scannerVersion: "0", stamps },
|
|
35
|
+
components: components.map((name) => ({
|
|
36
|
+
id: `cmp_${name}`,
|
|
37
|
+
identity: { kind: "component", key: `app:root|third_party||${name}.ts|${name}`, parts: {} },
|
|
38
|
+
name,
|
|
39
|
+
type: "third_party",
|
|
40
|
+
subType: "",
|
|
41
|
+
confidence: 0.9,
|
|
42
|
+
sourceLocations: [],
|
|
43
|
+
codeRefs: [],
|
|
44
|
+
})),
|
|
45
|
+
dataFlows: [],
|
|
46
|
+
dataItems: [],
|
|
47
|
+
relations: [],
|
|
48
|
+
});
|
|
49
|
+
/** A fake scan: one component per `.ts` file at the top of the folder. Records what it saw. */
|
|
50
|
+
function fakeScan(seen, stamps = STAMPS) {
|
|
51
|
+
return (dir) => {
|
|
52
|
+
const files = fs_1.default.readdirSync(dir).sort();
|
|
53
|
+
const configPath = path_1.default.join(dir, run_diff_1.CONFIG_FILE);
|
|
54
|
+
seen.push({ files, config: fs_1.default.existsSync(configPath) ? fs_1.default.readFileSync(configPath, "utf8") : null, folder: path_1.default.basename(dir) });
|
|
55
|
+
return facts(files.filter((f) => f.endsWith(".ts")).map((f) => f.replace(/\.ts$/, "")), stamps);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
describe("runDiff (DATAP-852)", () => {
|
|
59
|
+
let work;
|
|
60
|
+
let repo;
|
|
61
|
+
let base;
|
|
62
|
+
let head;
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
work = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "run-diff-"));
|
|
65
|
+
repo = path_1.default.join(work, "shop");
|
|
66
|
+
fs_1.default.mkdirSync(repo);
|
|
67
|
+
git(repo, "init", "-q");
|
|
68
|
+
fs_1.default.writeFileSync(path_1.default.join(repo, "stripe.ts"), "export const a = 1;\n");
|
|
69
|
+
fs_1.default.writeFileSync(path_1.default.join(repo, "auth0.ts"), "export const b = 2;\n");
|
|
70
|
+
fs_1.default.writeFileSync(path_1.default.join(repo, "mailer.ts"), "export function send() {\n return 'a fairly long body so git sees a rename';\n}\n");
|
|
71
|
+
fs_1.default.writeFileSync(path_1.default.join(repo, run_diff_1.CONFIG_FILE), '{"projectName":"old"}\n');
|
|
72
|
+
base = commitAll(repo, "base");
|
|
73
|
+
fs_1.default.rmSync(path_1.default.join(repo, "auth0.ts"));
|
|
74
|
+
fs_1.default.renameSync(path_1.default.join(repo, "mailer.ts"), path_1.default.join(repo, "email.ts"));
|
|
75
|
+
fs_1.default.writeFileSync(path_1.default.join(repo, run_diff_1.CONFIG_FILE), '{"projectName":"new"}\n');
|
|
76
|
+
head = commitAll(repo, "head");
|
|
77
|
+
});
|
|
78
|
+
afterEach(() => fs_1.default.rmSync(work, { recursive: true, force: true }));
|
|
79
|
+
const run = (scan, extra = {}) => (0, run_diff_1.runDiff)({ repo, base, head, outputDir: path_1.default.join(work, "out"), scan, tools: TOOLS, cacheDir: path_1.default.join(work, "cache"), ...extra });
|
|
80
|
+
it("scans both revisions with the head's configuration and writes the change set", () => {
|
|
81
|
+
const seen = [];
|
|
82
|
+
const result = run(fakeScan(seen));
|
|
83
|
+
expect(seen.map((s) => s.config)).toEqual(['{"projectName":"new"}\n', '{"projectName":"new"}\n']);
|
|
84
|
+
expect(seen.every((s) => s.folder === "shop")).toBe(true);
|
|
85
|
+
expect(result.changeSet.configChanged).toBe(true);
|
|
86
|
+
expect(result.changeSet.changes.map((c) => [c.change, c.name])).toEqual([
|
|
87
|
+
["removed", "auth0"],
|
|
88
|
+
["added", "email"],
|
|
89
|
+
["removed", "mailer"],
|
|
90
|
+
]);
|
|
91
|
+
expect(JSON.parse(fs_1.default.readFileSync(result.files.changeSet, "utf8"))).toEqual(result.changeSet);
|
|
92
|
+
expect(fs_1.default.readFileSync(result.files.summary, "utf8")).toContain("removed: 2 components");
|
|
93
|
+
expect(JSON.parse(fs_1.default.readFileSync(result.files.renames, "utf8"))).toMatchObject({
|
|
94
|
+
rootCommit: base,
|
|
95
|
+
base,
|
|
96
|
+
head,
|
|
97
|
+
renames: [{ from: "mailer.ts", to: "email.ts" }],
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
it("reuses a cached scan only when the commit, configuration and tools are the same (DATAP-878)", () => {
|
|
101
|
+
const seen = [];
|
|
102
|
+
run(fakeScan(seen));
|
|
103
|
+
run(fakeScan(seen));
|
|
104
|
+
expect(seen).toHaveLength(2);
|
|
105
|
+
for (const change of [{ cliVersion: "9" }, { scannerCommit: "e".repeat(40) }, { catalogHash: "sha256:ffffffffffffffff" }]) {
|
|
106
|
+
const before = seen.length;
|
|
107
|
+
run(fakeScan(seen, { ...STAMPS, ...change }), { tools: { ...TOOLS, ...change } });
|
|
108
|
+
expect(seen).toHaveLength(before + 2);
|
|
109
|
+
}
|
|
110
|
+
run(fakeScan(seen), { cacheDir: null });
|
|
111
|
+
expect(seen.length).toBeGreaterThanOrEqual(10);
|
|
112
|
+
});
|
|
113
|
+
it("scans again when a cached scan's stamps do not match the tools", () => {
|
|
114
|
+
const seen = [];
|
|
115
|
+
run(fakeScan(seen, { ...STAMPS, scannerCommit: "e".repeat(40) }));
|
|
116
|
+
expect(seen).toHaveLength(2);
|
|
117
|
+
run(fakeScan(seen));
|
|
118
|
+
expect(seen).toHaveLength(4);
|
|
119
|
+
});
|
|
120
|
+
it("scans once when base and head are the same commit", () => {
|
|
121
|
+
const seen = [];
|
|
122
|
+
const result = run(fakeScan(seen), { base: head });
|
|
123
|
+
expect(seen).toHaveLength(1);
|
|
124
|
+
expect(result.changeSet.unchanged).toBe(true);
|
|
125
|
+
});
|
|
126
|
+
it("refuses a working tree with changes that are not committed", () => {
|
|
127
|
+
fs_1.default.writeFileSync(path_1.default.join(repo, "new.ts"), "x\n");
|
|
128
|
+
expect(() => run(fakeScan([]))).toThrow(expect.objectContaining({ code: "DIRTY_TREE" }));
|
|
129
|
+
});
|
|
130
|
+
it("refuses an unknown revision and a folder outside Git", () => {
|
|
131
|
+
expect(() => run(fakeScan([]), { base: "no-such-ref" })).toThrow(expect.objectContaining({ code: "UNKNOWN_REVISION" }));
|
|
132
|
+
expect(() => run(fakeScan([]), { repo: os_1.default.tmpdir() })).toThrow(run_diff_1.DiffError);
|
|
133
|
+
});
|
|
134
|
+
it("passes on a refusal when the two scans cannot be compared (DATAP-877)", () => {
|
|
135
|
+
let call = 0;
|
|
136
|
+
const scan = () => facts(["stripe"], call++ === 0 ? STAMPS : { ...STAMPS, aiInference: true });
|
|
137
|
+
expect(() => run(scan, { cacheDir: null })).toThrow(expect.objectContaining({ name: "ComparisonRefused", reason: "ai_enriched" }));
|
|
138
|
+
});
|
|
139
|
+
/** A fake scan that also writes its output, as the real `scan -o` does. */
|
|
140
|
+
const writingScan = (seen) => {
|
|
141
|
+
const inner = fakeScan(seen);
|
|
142
|
+
return (dir, outDir) => {
|
|
143
|
+
const result = inner(dir, outDir);
|
|
144
|
+
fs_1.default.writeFileSync(path_1.default.join(outDir, "dataflow.json"), JSON.stringify({ metadata: { projectName: "shop" } }));
|
|
145
|
+
fs_1.default.writeFileSync(path_1.default.join(outDir, "facts.json"), JSON.stringify(result));
|
|
146
|
+
return result;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
it("keeps both scans with their commit stamps for --upload (DATAP-886)", () => {
|
|
150
|
+
const seen = [];
|
|
151
|
+
const result = run(writingScan(seen), { keepScans: true });
|
|
152
|
+
expect(result.scanDirs).toEqual({ base: path_1.default.join(work, "out", "base"), head: path_1.default.join(work, "out", "head") });
|
|
153
|
+
for (const [side, sha] of [
|
|
154
|
+
["base", base],
|
|
155
|
+
["head", head],
|
|
156
|
+
]) {
|
|
157
|
+
const kept = JSON.parse(fs_1.default.readFileSync(path_1.default.join(result.scanDirs[side], "facts.json"), "utf8"));
|
|
158
|
+
expect(kept.scan.stamps).toEqual({ ...STAMPS, commitSha: sha, dirty: false, rootCommitSha: base });
|
|
159
|
+
expect(fs_1.default.existsSync(path_1.default.join(result.scanDirs[side], "dataflow.json"))).toBe(true);
|
|
160
|
+
}
|
|
161
|
+
// Both scans used the head's configuration, so the tool stamps match.
|
|
162
|
+
expect(seen.map((s) => s.config)).toEqual(['{"projectName":"new"}\n', '{"projectName":"new"}\n']);
|
|
163
|
+
});
|
|
164
|
+
it("reuses a cached scan for --upload only when the cache holds the whole output", () => {
|
|
165
|
+
const seen = [];
|
|
166
|
+
run(fakeScan(seen));
|
|
167
|
+
expect(seen).toHaveLength(2);
|
|
168
|
+
// The cache from a plain run has no dataflow.json: scan again.
|
|
169
|
+
run(writingScan(seen), { keepScans: true });
|
|
170
|
+
expect(seen).toHaveLength(4);
|
|
171
|
+
const result = run(writingScan(seen), { keepScans: true });
|
|
172
|
+
expect(seen).toHaveLength(4);
|
|
173
|
+
const kept = JSON.parse(fs_1.default.readFileSync(path_1.default.join(result.scanDirs.head, "facts.json"), "utf8"));
|
|
174
|
+
expect(kept.scan.stamps.commitSha).toBe(head);
|
|
175
|
+
// The cache keeps the scan as it was made, without the commit stamps.
|
|
176
|
+
run(writingScan(seen));
|
|
177
|
+
expect(seen).toHaveLength(4);
|
|
178
|
+
});
|
|
179
|
+
it("keeps the same scan as base and head when they are one commit", () => {
|
|
180
|
+
const seen = [];
|
|
181
|
+
const result = run(writingScan(seen), { base: head, keepScans: true });
|
|
182
|
+
expect(seen).toHaveLength(1);
|
|
183
|
+
expect(fs_1.default.existsSync(path_1.default.join(result.scanDirs.base, "dataflow.json"))).toBe(true);
|
|
184
|
+
expect(fs_1.default.existsSync(path_1.default.join(result.scanDirs.head, "dataflow.json"))).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
it("lists renames from git diff -M", () => {
|
|
187
|
+
expect((0, run_diff_1.renameMap)(repo, base, head)).toEqual([expect.objectContaining({ from: "mailer.ts", to: "email.ts" })]);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
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 upload_diff_1 = require("../../../src/diff/upload-diff");
|
|
10
|
+
describe("diff --upload (DATAP-886, DATAP-890)", () => {
|
|
11
|
+
let work;
|
|
12
|
+
const BASE = "b".repeat(40);
|
|
13
|
+
const HEAD = "c".repeat(40);
|
|
14
|
+
const ROOT = "a".repeat(40);
|
|
15
|
+
const renames = [{ from: "mailer.ts", to: "email.ts", similarity: 92 }];
|
|
16
|
+
const writeScan = (dir, commit) => {
|
|
17
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
18
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, "dataflow.json"), JSON.stringify({ metadata: { projectName: "shop" }, commit }));
|
|
19
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, "facts.json"), JSON.stringify({ schemaVersion: 1, scan: { stamps: { commitSha: commit } } }));
|
|
20
|
+
};
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
work = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "upload-diff-"));
|
|
23
|
+
writeScan(path_1.default.join(work, "base"), BASE);
|
|
24
|
+
writeScan(path_1.default.join(work, "head"), HEAD);
|
|
25
|
+
});
|
|
26
|
+
afterEach(() => fs_1.default.rmSync(work, { recursive: true, force: true }));
|
|
27
|
+
const result = () => ({
|
|
28
|
+
baseSha: BASE,
|
|
29
|
+
headSha: HEAD,
|
|
30
|
+
rootCommit: ROOT,
|
|
31
|
+
renames,
|
|
32
|
+
scanDirs: { base: path_1.default.join(work, "base"), head: path_1.default.join(work, "head") },
|
|
33
|
+
});
|
|
34
|
+
const stored = (scanId, comparison) => ({ stored: true, scanId, repositoryId: "repo-1", created: true, comparable: true, ...(comparison ? { comparison } : {}) });
|
|
35
|
+
it("uploads the base, then the head with the rename map and root commit", async () => {
|
|
36
|
+
const comparison = {
|
|
37
|
+
compared: true,
|
|
38
|
+
created: true,
|
|
39
|
+
comparison: { id: "cmp-1", changeSet: { renames: "applied" } },
|
|
40
|
+
bindings: [
|
|
41
|
+
{ answerId: "a1", status: "carried", reason: "unchanged" },
|
|
42
|
+
{ answerId: "a2", status: "carried", reason: "renamed" },
|
|
43
|
+
{ answerId: "a3", status: "reopened", reason: "neighbours_changed" },
|
|
44
|
+
],
|
|
45
|
+
summary: "renamed: 1 component",
|
|
46
|
+
};
|
|
47
|
+
const upload = jest
|
|
48
|
+
.fn()
|
|
49
|
+
.mockResolvedValueOnce({ draftId: "d-base", complete: stored("s-base") })
|
|
50
|
+
.mockResolvedValueOnce({ draftId: "d-head", complete: stored("s-head", comparison) });
|
|
51
|
+
const uploaded = await (0, upload_diff_1.uploadDiffScans)({ apiKey: "key", repo: work, result: result(), upload: upload });
|
|
52
|
+
expect(upload).toHaveBeenCalledTimes(2);
|
|
53
|
+
const [baseCall, headCall] = upload.mock.calls.map((call) => call[0]);
|
|
54
|
+
expect(baseCall).toMatchObject({ apiKey: "key", projectName: "shop", command: "upload", dataflow: { commit: BASE } });
|
|
55
|
+
expect(baseCall.compare).toBeUndefined();
|
|
56
|
+
expect(baseCall.files.map((f) => f.relativePath)).toEqual(["facts.json"]);
|
|
57
|
+
expect(headCall).toMatchObject({ dataflow: { commit: HEAD }, compare: { baseCommitSha: BASE, rootCommitSha: ROOT, renames } });
|
|
58
|
+
expect(uploaded.comparison).toEqual(comparison);
|
|
59
|
+
expect((0, upload_diff_1.describeUploadedComparison)(uploaded)).toBe("Stored comparison cmp-1 (answers: 2 carried, 1 reopened).");
|
|
60
|
+
});
|
|
61
|
+
it("says why the backend did not compare", async () => {
|
|
62
|
+
const upload = jest
|
|
63
|
+
.fn()
|
|
64
|
+
.mockResolvedValueOnce({ draftId: "d-base", complete: stored("s-base") })
|
|
65
|
+
.mockResolvedValueOnce({ draftId: "d-head", complete: stored("s-head", { compared: false, reason: "stamps_differ", message: "different cliVersion" }) });
|
|
66
|
+
const uploaded = await (0, upload_diff_1.uploadDiffScans)({ apiKey: "key", repo: work, result: result(), upload: upload });
|
|
67
|
+
expect((0, upload_diff_1.describeUploadedComparison)(uploaded)).toBe("The backend did not compare the scans (stamps_differ): different cliVersion");
|
|
68
|
+
});
|
|
69
|
+
it("says when a scan was not stored", async () => {
|
|
70
|
+
const upload = jest
|
|
71
|
+
.fn()
|
|
72
|
+
.mockResolvedValueOnce({ draftId: "d-base", complete: { stored: false, reason: "no_repository_identity" } })
|
|
73
|
+
.mockResolvedValueOnce({ draftId: "d-head", complete: null });
|
|
74
|
+
const uploaded = await (0, upload_diff_1.uploadDiffScans)({ apiKey: "key", repo: work, result: result(), upload: upload });
|
|
75
|
+
expect(uploaded.comparison).toBeNull();
|
|
76
|
+
expect((0, upload_diff_1.describeUploadedComparison)(uploaded)).toBe("The base scan was uploaded but not stored for comparison (no_repository_identity).");
|
|
77
|
+
});
|
|
78
|
+
it("needs the kept scans", async () => {
|
|
79
|
+
await expect((0, upload_diff_1.uploadDiffScans)({ apiKey: "key", repo: work, result: { ...result(), scanDirs: undefined }, upload: jest.fn() })).rejects.toThrow("kept no scans");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -59,7 +59,7 @@ describe("applyAnswers", () => {
|
|
|
59
59
|
expect(state.system).toEqual({ in_scope: "The web app" });
|
|
60
60
|
expect(state.facts).toEqual(facts);
|
|
61
61
|
});
|
|
62
|
-
it.each(["id", "file", "codeRefs", "groups", "occurrences"])("refuses to change %s", (property) => {
|
|
62
|
+
it.each(["id", "identity", "file", "codeRefs", "groups", "occurrences"])("refuses to change %s", (property) => {
|
|
63
63
|
const a = answer({ factId: "cmp_api", action: "set", property, value: "x" });
|
|
64
64
|
const state = (0, apply_answers_1.applyAnswers)(facts, files, [a]);
|
|
65
65
|
expect(state.ignored).toEqual([a]);
|
|
@@ -86,7 +86,14 @@ describe("buildFacts", () => {
|
|
|
86
86
|
]);
|
|
87
87
|
const email = facts.dataItems.find((i) => i.name === "email");
|
|
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" } },
|
|
92
|
+
label: "customer",
|
|
93
|
+
basis: "column",
|
|
94
|
+
occurrenceCount: 2,
|
|
95
|
+
handledBy: ["cmp_api"],
|
|
96
|
+
},
|
|
90
97
|
]);
|
|
91
98
|
expect([...dataItemFiles.keys()].sort()).toEqual(["data-items/credit-card.json", "data-items/email.json"]);
|
|
92
99
|
});
|
|
@@ -117,6 +124,65 @@ describe("buildFacts", () => {
|
|
|
117
124
|
"sends cmp_api flow_mail",
|
|
118
125
|
]);
|
|
119
126
|
});
|
|
127
|
+
it("gives every component, flow, data item and group an identity", () => {
|
|
128
|
+
expect(facts.components.find((c) => c.id === "cmp_api")?.identity).toEqual({
|
|
129
|
+
kind: "component",
|
|
130
|
+
key: "app:<unsectioned>|asset|service|src/api.ts|api",
|
|
131
|
+
parts: { scheme: "app", section: "<unsectioned>", type: "asset", subType: "service", file: "src/api.ts", name: "api" },
|
|
132
|
+
});
|
|
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" } });
|
|
137
|
+
expect(dataItemFiles.get(email.file)?.identity).toEqual(email?.identity);
|
|
138
|
+
});
|
|
139
|
+
it("drops the line from a declaration-named group's key, and numbers groups that share a key", () => {
|
|
140
|
+
const result = scanResult();
|
|
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: [] },
|
|
145
|
+
];
|
|
146
|
+
result.occurrences.push(...occurrences);
|
|
147
|
+
result.dataItems.push({
|
|
148
|
+
id: "data_item:phone",
|
|
149
|
+
labels: [],
|
|
150
|
+
occurrenceIds: occurrences.map((o) => o.id),
|
|
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] },
|
|
155
|
+
],
|
|
156
|
+
});
|
|
157
|
+
const groups = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta }).facts.dataItems.find((i) => i.name === "phone").groups;
|
|
158
|
+
const byId = new Map(groups.map((g) => [g.id, g.identity]));
|
|
159
|
+
expect(byId.get("group:phone@src/a.ts:12#phone")).toEqual({
|
|
160
|
+
kind: "group",
|
|
161
|
+
key: "phone@src/a.ts#phone",
|
|
162
|
+
parts: { dataItem: "phone", declarationFile: "src/a.ts", declarationName: "phone" },
|
|
163
|
+
});
|
|
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 });
|
|
167
|
+
});
|
|
168
|
+
it("writes scan stamps when given, and leaves them out otherwise (DATAP-876)", () => {
|
|
169
|
+
expect(facts.scan).not.toHaveProperty("stamps");
|
|
170
|
+
const stamps = {
|
|
171
|
+
scannerCommit: "f".repeat(40),
|
|
172
|
+
cliVersion: "0.0.32",
|
|
173
|
+
catalogHash: "sha256:0123456789abcdef",
|
|
174
|
+
configHash: "sha256:fedcba9876543210",
|
|
175
|
+
aiInference: false,
|
|
176
|
+
structureGraph: true,
|
|
177
|
+
commitSha: "a".repeat(40),
|
|
178
|
+
dirty: false,
|
|
179
|
+
rootCommitSha: "b".repeat(40),
|
|
180
|
+
scanRoot: "",
|
|
181
|
+
};
|
|
182
|
+
const stamped = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta, stamps }).facts;
|
|
183
|
+
expect(stamped.scan.stamps).toEqual(stamps);
|
|
184
|
+
expect(() => schema_1.factsFileSchema.parse(stamped)).not.toThrow();
|
|
185
|
+
});
|
|
120
186
|
it("works without a knowledge graph", () => {
|
|
121
187
|
const bare = (0, build_facts_1.buildFacts)({ result: scanResult(), ...meta });
|
|
122
188
|
expect(bare.facts.relations).toEqual([]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const crypto_1 = require("crypto");
|
|
4
|
+
const scanner_1 = require("../../../vendor/scanner/dist/src/index.js");
|
|
5
|
+
const identity_1 = require("../../../src/facts/identity");
|
|
6
|
+
const schema_1 = require("../../../src/facts/schema");
|
|
7
|
+
const ROOT = "/Users/dev/projects/shop";
|
|
8
|
+
const scrub = (value) => value.split(`${ROOT}/`).join("");
|
|
9
|
+
function component(partial) {
|
|
10
|
+
return { confidence: 0.9, detectedFrom: [], sourceLocations: [], properties: {}, ...partial };
|
|
11
|
+
}
|
|
12
|
+
function flow(partial) {
|
|
13
|
+
return { type: "api_call", confidence: 0.9, ...partial };
|
|
14
|
+
}
|
|
15
|
+
/** A scan whose ids the scanner assigned, as in a real run. */
|
|
16
|
+
function stableScan(components, dataFlows) {
|
|
17
|
+
return (0, scanner_1.assignStableEntityIds)({ components, dataFlows });
|
|
18
|
+
}
|
|
19
|
+
const hash = (prefix, key) => `${prefix}${(0, crypto_1.createHash)("sha256").update(key.replace(/#\d+$/, ""), "utf8").digest("hex").slice(0, 12)}`;
|
|
20
|
+
describe("buildScanIdentities", () => {
|
|
21
|
+
const scan = stableScan([
|
|
22
|
+
component({ id: "a", name: "API ", type: "asset", subType: "service", properties: { section_id: "backend" }, sourceLocations: [{ filePath: "src/z.ts", startLine: 9, endLine: 9 }, { filePath: "src/api.ts", startLine: 1, endLine: 2 }] }),
|
|
23
|
+
component({ id: "b", name: "bucket", type: "asset", subType: "object_store", properties: { terraform_address: "aws_s3_bucket.files" } }),
|
|
24
|
+
component({ id: "c", name: "AWS", type: "third_party", subType: "cloud_provider", properties: { section_id: "backend" }, sourceLocations: [{ filePath: "infra/aws.ts", startLine: 1, endLine: 1 }] }),
|
|
25
|
+
component({ id: "d", name: "Postgres", type: "asset", subType: "database", properties: { section_id: "backend", managed_by_provider: "c", managed_service_key: "postgres" } }),
|
|
26
|
+
], [flow({ id: "f", sourceComponentId: "a", targetComponentId: "d", method: "post", endpoint: "/users/", sourceLocations: [{ filePath: "src/api.ts", startLine: 5, endLine: 5 }] })]);
|
|
27
|
+
const ids = (0, identity_1.buildScanIdentities)(scan.components, scan.dataFlows, scrub);
|
|
28
|
+
it("gives every component and flow an identity whose key hashes to its id", () => {
|
|
29
|
+
for (const c of scan.components) {
|
|
30
|
+
const identity = ids.components.get(c.id);
|
|
31
|
+
expect(schema_1.identitySchema.parse(identity)).toBeTruthy();
|
|
32
|
+
expect(c.id).toBe(hash("cmp_", identity.key));
|
|
33
|
+
}
|
|
34
|
+
for (const f of scan.dataFlows) {
|
|
35
|
+
const identity = ids.dataFlows.get(f.id);
|
|
36
|
+
expect(identity.kind).toBe("dataFlow");
|
|
37
|
+
expect(f.id).toBe(hash("flow_", identity.key));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
it("splits component keys into parts for app, terraform and managed components", () => {
|
|
41
|
+
const byName = (name) => ids.components.get(scan.components.find((c) => c.name === name).id);
|
|
42
|
+
expect(byName("API ")).toEqual({
|
|
43
|
+
kind: "component",
|
|
44
|
+
key: "app:backend|asset|service|src/api.ts|api",
|
|
45
|
+
parts: { scheme: "app", section: "backend", type: "asset", subType: "service", file: "src/api.ts", name: "api" },
|
|
46
|
+
});
|
|
47
|
+
expect(byName("bucket").parts).toEqual({ scheme: "tf", terraformAddress: "aws_s3_bucket.files" });
|
|
48
|
+
expect(byName("Postgres")).toMatchObject({
|
|
49
|
+
key: "managed:{app:backend|third_party|cloud_provider|infra/aws.ts|aws}|postgres|backend",
|
|
50
|
+
parts: { scheme: "managed", provider: "app:backend|third_party|cloud_provider|infra/aws.ts|aws", serviceKey: "postgres", section: "backend" },
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it("splits flow keys into parts", () => {
|
|
54
|
+
expect(ids.dataFlows.get(scan.dataFlows[0].id).parts).toEqual({
|
|
55
|
+
source: "app:backend|asset|service|src/api.ts|api",
|
|
56
|
+
target: "managed:{app:backend|third_party|cloud_provider|infra/aws.ts|aws}|postgres|backend",
|
|
57
|
+
type: "api_call",
|
|
58
|
+
method: "POST",
|
|
59
|
+
endpoint: "/users",
|
|
60
|
+
file: "src/api.ts",
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
it("never puts the scan root or a line number in a key", () => {
|
|
64
|
+
const absolute = stableScan([component({ id: "a", name: "api", type: "asset", sourceLocations: [{ filePath: `${ROOT}/src/api.ts`, startLine: 42, endLine: 43 }] })], []);
|
|
65
|
+
const identity = (0, identity_1.buildScanIdentities)(absolute.components, [], scrub).components.get(absolute.components[0].id);
|
|
66
|
+
expect(identity.key).toBe("app:<unsectioned>|asset||src/api.ts|api");
|
|
67
|
+
expect(identity.key).not.toContain("42");
|
|
68
|
+
});
|
|
69
|
+
it("numbers duplicate keys #2, #3 in the scanner's id order", () => {
|
|
70
|
+
const dup = stableScan([
|
|
71
|
+
component({ id: "x", name: "User", type: "actor", sourceLocations: [{ filePath: "src/u.ts", startLine: 20, endLine: 20 }] }),
|
|
72
|
+
component({ id: "y", name: "User", type: "actor", sourceLocations: [{ filePath: "src/u.ts", startLine: 3, endLine: 3 }] }),
|
|
73
|
+
component({ id: "t", name: "Stripe", type: "third_party", sourceLocations: [{ filePath: "src/pay.ts", startLine: 1, endLine: 1 }] }),
|
|
74
|
+
], [
|
|
75
|
+
flow({ id: "f1", sourceComponentId: "x", targetComponentId: "t", sourceLocations: [{ filePath: "src/pay.ts", startLine: 9, endLine: 9 }] }),
|
|
76
|
+
flow({ id: "f2", sourceComponentId: "x", targetComponentId: "t", sourceLocations: [{ filePath: "src/pay.ts", startLine: 2, endLine: 2 }] }),
|
|
77
|
+
]);
|
|
78
|
+
const result = (0, identity_1.buildScanIdentities)(dup.components, dup.dataFlows, scrub);
|
|
79
|
+
const users = dup.components.filter((c) => c.name === "User");
|
|
80
|
+
const plain = users.find((c) => !/_\d+$/.test(c.id.slice(4 + 12)));
|
|
81
|
+
const second = users.find((c) => c !== plain);
|
|
82
|
+
expect(second.id).toBe(`${plain.id}_2`);
|
|
83
|
+
expect(result.components.get(plain.id)).not.toHaveProperty("duplicateIndex");
|
|
84
|
+
expect(result.components.get(second.id)).toMatchObject({ key: `${result.components.get(plain.id).key}#2`, duplicateIndex: 2 });
|
|
85
|
+
// The earlier source position keeps the plain id and key.
|
|
86
|
+
expect(plain.sourceLocations?.[0].startLine).toBe(3);
|
|
87
|
+
const flows = [...dup.dataFlows].sort((a, b) => a.id.localeCompare(b.id));
|
|
88
|
+
expect(flows[1].id).toBe(`${flows[0].id}_2`);
|
|
89
|
+
expect(result.dataFlows.get(flows[0].id)).not.toHaveProperty("duplicateIndex");
|
|
90
|
+
expect(result.dataFlows.get(flows[1].id)).toMatchObject({ duplicateIndex: 2 });
|
|
91
|
+
expect(result.dataFlows.get(flows[1].id).key.endsWith("#2")).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
it("does not take a name ending in #<digits> for a duplicate", () => {
|
|
94
|
+
const one = stableScan([component({ id: "w", name: "Worker #2", type: "asset", sourceLocations: [{ filePath: "src/w.ts", startLine: 1, endLine: 1 }] })], []);
|
|
95
|
+
const identity = (0, identity_1.buildScanIdentities)(one.components, [], scrub).components.get(one.components[0].id);
|
|
96
|
+
expect(identity).not.toHaveProperty("duplicateIndex");
|
|
97
|
+
expect(identity.key).toBe("app:<unsectioned>|asset||src/w.ts|worker #2");
|
|
98
|
+
expect(one.components[0].id).toBe(`cmp_${(0, crypto_1.createHash)("sha256").update(identity.key, "utf8").digest("hex").slice(0, 12)}`);
|
|
99
|
+
});
|
|
100
|
+
it("puts the provider's base key, without #n, in a managed component's parts", () => {
|
|
101
|
+
const scan = stableScan([
|
|
102
|
+
component({ id: "p1", name: "AWS", type: "third_party", sourceLocations: [{ filePath: "infra/aws.ts", startLine: 1, endLine: 1 }] }),
|
|
103
|
+
component({ id: "p2", name: "AWS", type: "third_party", sourceLocations: [{ filePath: "infra/aws.ts", startLine: 9, endLine: 9 }] }),
|
|
104
|
+
component({ id: "db", name: "Postgres", type: "asset", properties: { managed_by_provider: "p2", managed_service_key: "postgres" } }),
|
|
105
|
+
], []);
|
|
106
|
+
const ids = (0, identity_1.buildScanIdentities)(scan.components, [], scrub);
|
|
107
|
+
const db = scan.components.find((c) => c.name === "Postgres");
|
|
108
|
+
const identity = ids.components.get(db.id);
|
|
109
|
+
expect(identity.parts.provider).toBe("app:<unsectioned>|third_party||infra/aws.ts|aws");
|
|
110
|
+
expect(identity.key).toBe(`managed:{${identity.parts.provider}}|postgres|<unsectioned>`);
|
|
111
|
+
expect(db.id).toBe(hash("cmp_", identity.key));
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
describe("root Application named after the scan folder (DATAP-858)", () => {
|
|
115
|
+
it("keys it by the <project> token, in the key and in parts", () => {
|
|
116
|
+
const scan = stableScan([component({ id: "r", name: "my-checkout", type: "asset", subType: "application", properties: { section_id: "root", name_from_project: true } })], []);
|
|
117
|
+
const identity = (0, identity_1.buildScanIdentities)(scan.components, [], scrub).components.get(scan.components[0].id);
|
|
118
|
+
expect(identity.key).toBe("app:root|asset|application||<project>");
|
|
119
|
+
expect(identity.parts.name).toBe("<project>");
|
|
120
|
+
expect(scan.components[0].id).toBe(hash("cmp_", identity.key));
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe("data item and group identities", () => {
|
|
124
|
+
it("keys a data item by its name", () => {
|
|
125
|
+
expect((0, identity_1.dataItemIdentity)("Credit Card")).toEqual({ kind: "dataItem", key: "Credit Card", parts: { name: "Credit Card" } });
|
|
126
|
+
});
|
|
127
|
+
it("splits group ids into the data item and the qualifier or column", () => {
|
|
128
|
+
expect((0, identity_1.groupIdentity)("email", "email:customer")).toEqual({ kind: "group", key: "email:customer", parts: { dataItem: "email", qualifier: "customer" } });
|
|
129
|
+
expect((0, identity_1.groupIdentity)("email", "email@contact_email")).toEqual({ kind: "group", key: "email@contact_email", parts: { dataItem: "email", column: "contact_email" } });
|
|
130
|
+
expect((0, identity_1.groupIdentity)("email", "other")).toEqual({ kind: "group", key: "other", parts: { dataItem: "email", group: "other" } });
|
|
131
|
+
});
|
|
132
|
+
it("drops the line from a declaration-named group", () => {
|
|
133
|
+
expect((0, identity_1.groupIdentity)("email", "email@src/a.js:12#email")).toEqual({
|
|
134
|
+
kind: "group",
|
|
135
|
+
key: "email@src/a.js#email",
|
|
136
|
+
parts: { dataItem: "email", declarationFile: "src/a.js", declarationName: "email" },
|
|
137
|
+
});
|
|
138
|
+
expect((0, identity_1.groupIdentity)("email", "email@src/a.js:12")).toEqual({ kind: "group", key: "email@src/a.js", parts: { dataItem: "email", declarationFile: "src/a.js" } });
|
|
139
|
+
});
|
|
140
|
+
it("numbers groups that share a key by declaration line", () => {
|
|
141
|
+
const pairs = ["email@a.js:40", "email@a.js:5", "email:staff"].map((id) => [id, (0, identity_1.groupIdentity)("email", id)]);
|
|
142
|
+
expect((0, identity_1.numberGroupDuplicates)(pairs).map((i) => [i.key, i.duplicateIndex])).toEqual([
|
|
143
|
+
["email@a.js#2", 2],
|
|
144
|
+
["email@a.js", undefined],
|
|
145
|
+
["email:staff", undefined],
|
|
146
|
+
]);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|