@dataparade/cli 0.0.32 → 0.0.34
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/cli.js +47 -4
- package/dist/src/diff/register-diff-command.d.ts +4 -0
- package/dist/src/diff/register-diff-command.js +99 -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 +8 -0
- package/dist/src/output/git-context.js +18 -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/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.js +19 -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/classifier/application-injection.js +5 -0
- 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/index.d.ts +1 -1
- package/dist/vendor/scanner/dist/src/index.js +4 -2
- package/dist/vendor/scanner/package.json +3 -1
- package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +10 -0
- package/dist/vendor/scanner/patterns/component-taxonomy.yaml +1 -1
- package/dist/vendor/scanner/patterns/third-party.patterns.yaml +25 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -42,6 +42,61 @@ dataparade scan path/to/your/project --output scan-my-project-dataflow.json
|
|
|
42
42
|
|
|
43
43
|
List commands and options: `dataparade --help` and `dataparade scan --help`.
|
|
44
44
|
|
|
45
|
+
## Sensitive information scans
|
|
46
|
+
|
|
47
|
+
`dataparade scan <path>` runs LeftBlock alongside the data-flow scan. Install
|
|
48
|
+
[Gitleaks](https://github.com/gitleaks/gitleaks#installing) and a
|
|
49
|
+
[LeftBlock](https://github.com/DataParade-io/LeftBlock) version with
|
|
50
|
+
`leftblock scan --format report` on your `PATH`. To use a separate Python
|
|
51
|
+
environment, set `DATAPARADE_LEFTBLOCK` to its LeftBlock executable.
|
|
52
|
+
|
|
53
|
+
The integration was tested with Gitleaks 8.30.1. For a development build,
|
|
54
|
+
install the tested LeftBlock revision in a separate environment so it does
|
|
55
|
+
not replace the LeftBlock executable used by Git hooks:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
python3 -m venv ~/.local/share/dataparade/leftblock
|
|
59
|
+
~/.local/share/dataparade/leftblock/bin/pip install \
|
|
60
|
+
'leftblock @ git+https://github.com/DataParade-io/LeftBlock.git@1b87eeb0f3a2cc142cac25046a3fb0ddd57808cc'
|
|
61
|
+
export DATAPARADE_LEFTBLOCK="$HOME/.local/share/dataparade/leftblock/bin/leftblock"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The local `sensitive-findings.json` file reports findings and the status of
|
|
65
|
+
each pass. DataParade does not upload this file. The scan does not sanitize the
|
|
66
|
+
existing data-flow artifacts. Findings do not change the project scan's exit
|
|
67
|
+
code. If the rule scan cannot run, DataParade warns and continues.
|
|
68
|
+
|
|
69
|
+
LeftBlock scans UTF-8 project files within the scan path, including supported
|
|
70
|
+
source, configuration, and documentation files. The project scan honors
|
|
71
|
+
`--exclude`, the scan configuration, and repository ignore rules. It skips
|
|
72
|
+
symbolic links, hidden directories, generated files, dependencies, output files,
|
|
73
|
+
and the scanner's default exclusions, including `.env` files. The report records
|
|
74
|
+
the 1 MiB file and 64 MiB scan limits if they affect coverage.
|
|
75
|
+
|
|
76
|
+
Both sensitive information scans try Privacy Filter only when its files and
|
|
77
|
+
dependencies are available locally. Follow LeftBlock's model setup instructions
|
|
78
|
+
to prepare it. If the model cannot run, DataParade warns and keeps the rule
|
|
79
|
+
findings. Use `--privacy-filter off` for a rules-only scan. Use
|
|
80
|
+
`--no-sensitive-scan` on the project command to skip both passes.
|
|
81
|
+
|
|
82
|
+
Install a [BotSpy](https://github.com/DataParade-io/BotSpy) version with
|
|
83
|
+
`botspy privacy-audit` to scan coding sessions. DataParade uses `botspy` from
|
|
84
|
+
`PATH`, or the executable set in `DATAPARADE_BOTSPY`.
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
dataparade sessions scan # this project, last 7 days
|
|
88
|
+
dataparade sessions scan ./service --source claude_code --since 24h
|
|
89
|
+
dataparade sessions scan --source codex --session SESSION_ID
|
|
90
|
+
dataparade sessions scan --all --since 24h --format json --fail-on-findings
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The session scan reads local agent histories. It does not create a transcript
|
|
94
|
+
index or send session data to a remote service. It reports source coverage and
|
|
95
|
+
finding locations without matched values. Output goes to stdout and warnings go
|
|
96
|
+
to stderr. A completed audit exits 0, or 1 with `--fail-on-findings` when it finds
|
|
97
|
+
sensitive information. An incomplete audit exits 2. An unavailable model alone
|
|
98
|
+
does not change the exit code.
|
|
99
|
+
|
|
45
100
|
---
|
|
46
101
|
|
|
47
102
|
## Upload to dashboard
|
|
@@ -75,7 +130,7 @@ By default, a scan writes these files to `./.dataparade/`:
|
|
|
75
130
|
| `graphify.json` | The code-structure graph from [Graphify](https://github.com/Graphify-Labs/graphify), when it is installed. |
|
|
76
131
|
| `answers.json` | People's decisions (interview answers, reviews). A scan never writes or changes it. |
|
|
77
132
|
|
|
78
|
-
`-o` / `--output` is the path of `dataflow.json`; the other files go in the same folder. Scans skip this folder, so rescanning does not read old output.
|
|
133
|
+
`-o` / `--output` is the path of `dataflow.json`; the other files go in the same folder. Scans skip this folder, so rescanning does not read old output. Committing `.dataparade/` is optional: DataParade keeps uploaded scans and answers by commit. The scan files can be regenerated; `answers.json` holds people's decisions, so keep it if you do not upload.
|
|
79
134
|
|
|
80
135
|
Graphify's cache lives outside the output, in `~/.cache/dataparade/graphify/` (set `DATAPARADE_CACHE_DIR` to move it).
|
|
81
136
|
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataparade/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "dataPARADE CLI — scan codebases for privacy and security data flows",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -45,11 +45,12 @@
|
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"ensure-scanner": "node scripts/ensure-scanner-built.mjs",
|
|
48
|
-
"build": "node scripts/ensure-scanner-built.mjs && pnpm exec tsc -p tsconfig.json && node scripts/vendor-scanner.mjs",
|
|
48
|
+
"build": "node scripts/ensure-scanner-built.mjs && pnpm --dir ../packages/kb-compare build && pnpm exec tsc -p tsconfig.json && node scripts/vendor-scanner.mjs && node scripts/vendor-kb-compare.mjs",
|
|
49
49
|
"prepublishOnly": "pnpm run build && pnpm run test",
|
|
50
50
|
"lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
51
51
|
"pretest": "pnpm run build",
|
|
52
52
|
"test": "jest",
|
|
53
|
+
"check:determinism": "node scripts/check-determinism.mjs",
|
|
53
54
|
"scan": "node dist/bin/cli.js scan",
|
|
54
55
|
"eval:models": "pnpm exec node dist/src/evals/run-model-matrix.js"
|
|
55
56
|
},
|
|
@@ -66,7 +67,7 @@
|
|
|
66
67
|
"zod": "^4.3.5"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
|
-
"@dataparade/scanner": "github:DataParade-io/scanner#
|
|
70
|
+
"@dataparade/scanner": "github:DataParade-io/scanner#175f7366ab54b8bf8c56998a21198d9aaa6858e0",
|
|
70
71
|
"@eslint/js": "^9.18.0",
|
|
71
72
|
"@types/jest": "^30.0.0",
|
|
72
73
|
"@types/node": "^22.0.0",
|
package/dist/src/cli.js
CHANGED
|
@@ -48,6 +48,8 @@ const git_context_1 = require("./output/git-context");
|
|
|
48
48
|
const write_scan_knowledge_1 = require("./output/write-scan-knowledge");
|
|
49
49
|
const layout_1 = require("./facts/layout");
|
|
50
50
|
const register_kb_commands_1 = require("./kb/register-kb-commands");
|
|
51
|
+
const register_diff_command_1 = require("./diff/register-diff-command");
|
|
52
|
+
const scan_stamps_1 = require("./facts/scan-stamps");
|
|
51
53
|
const register_export_commands_1 = require("./export/register-export-commands");
|
|
52
54
|
const scan_output_excludes_1 = require("./output/scan-output-excludes");
|
|
53
55
|
const dataflow_wrapper_schema_1 = require("./core/schema/dataflow-wrapper.schema");
|
|
@@ -67,6 +69,14 @@ const scan_config_schema_1 = require("./core/schema/scan-config.schema");
|
|
|
67
69
|
const scanner_1 = require("../vendor/scanner/dist/src/index.js");
|
|
68
70
|
const scan_interrupt_handlers_1 = require("./cli/scan-interrupt-handlers");
|
|
69
71
|
const scan_progress_renderer_1 = require("./ui/scan-progress-renderer");
|
|
72
|
+
const project_1 = require("./sensitive-scan/project");
|
|
73
|
+
const sessions_1 = require("./sensitive-scan/sessions");
|
|
74
|
+
/** The full scanner commit the CLI pins (devDependency `github:...#<sha>`). */
|
|
75
|
+
function scannerCommitFromPackage() {
|
|
76
|
+
const scannerPackage = ['@dataparade', 'scanner'].join('/');
|
|
77
|
+
const spec = package_json_1.default.devDependencies?.[scannerPackage];
|
|
78
|
+
return spec?.split('#')[1] ?? 'unknown';
|
|
79
|
+
}
|
|
70
80
|
/** The scanner is vendored into the CLI; its version is the commit the CLI depends on. */
|
|
71
81
|
function scannerVersionFromPackage() {
|
|
72
82
|
// Built from parts: the vendor step rewrites the scanner's package name in string literals.
|
|
@@ -161,6 +171,9 @@ function createProgram() {
|
|
|
161
171
|
.description('Scan a directory (or a single supported source file) for data flow components')
|
|
162
172
|
.option('-o, --output <file>', `Write dataflow.json to the given file; facts.json, data-items/ and graphify.json go next to it (default: ./${layout_1.DEFAULT_DATAFLOW_OUTPUT})`)
|
|
163
173
|
.option('--exclude <pattern...>', 'One or more glob patterns to exclude from scanning')
|
|
174
|
+
.option('--no-sensitive-scan', 'Skip the local LeftBlock rules and Privacy Filter')
|
|
175
|
+
.addOption(new commander_1.Option('--privacy-filter <mode>', 'Use the local Privacy Filter when available')
|
|
176
|
+
.choices(['auto', 'off']).default('auto'))
|
|
164
177
|
.option('--minimum-confidence <number>', 'Minimum confidence (0-1) for including detections')
|
|
165
178
|
.option('--language <language...>', 'Limit scanning to specific languages (e.g. typescript, javascript, python, go, java, kotlin, cpp, csharp, terraform)')
|
|
166
179
|
.option('--project-name <name>', 'Override the inferred project name used for the application asset')
|
|
@@ -307,6 +320,8 @@ function createProgram() {
|
|
|
307
320
|
}
|
|
308
321
|
parsedGitContext ??=
|
|
309
322
|
(0, git_context_1.detectGitContext)(scanEntry.scanRootDir) ?? undefined;
|
|
323
|
+
// Read before the scan writes anything, so its own output never counts as a change (DATAP-876).
|
|
324
|
+
const gitStamps = (0, scan_stamps_1.readGitStamps)(scanEntry.scanRootDir, path_1.default.dirname(path_1.default.resolve(process.cwd(), options.output ?? layout_1.DEFAULT_DATAFLOW_OUTPUT)), parsedGitContext?.commitSha);
|
|
310
325
|
const [{ createDefaultScanConfiguration }, { runScanPipeline }, { buildDiagramGraphFromScanResult },] = await Promise.all([
|
|
311
326
|
Promise.resolve().then(() => __importStar(require('./core/pipeline/orchestrator'))),
|
|
312
327
|
Promise.resolve().then(() => __importStar(require('./core/pipeline/scan-pipeline'))),
|
|
@@ -326,11 +341,9 @@ function createProgram() {
|
|
|
326
341
|
// Technical meters, shown as one block after the scan (TTY) or
|
|
327
342
|
// printed as before (non-TTY).
|
|
328
343
|
const technicalLines = [];
|
|
344
|
+
const outputExcludes = (0, scan_output_excludes_1.scanOutputExcludes)(resolvedScanRoot, path_1.default.resolve(process.cwd(), options.output ?? layout_1.DEFAULT_DATAFLOW_OUTPUT));
|
|
329
345
|
const flags = {
|
|
330
|
-
exclude: [
|
|
331
|
-
...(options.exclude ?? []),
|
|
332
|
-
...(0, scan_output_excludes_1.scanOutputExcludes)(resolvedScanRoot, path_1.default.resolve(process.cwd(), options.output ?? layout_1.DEFAULT_DATAFLOW_OUTPUT)),
|
|
333
|
-
],
|
|
346
|
+
exclude: [...(options.exclude ?? []), ...outputExcludes],
|
|
334
347
|
minimumConfidence: typeof options.minimumConfidence === 'string'
|
|
335
348
|
? Number(options.minimumConfidence)
|
|
336
349
|
: undefined,
|
|
@@ -639,7 +652,29 @@ function createProgram() {
|
|
|
639
652
|
projectName: resolvedProjectName,
|
|
640
653
|
cliVersion: package_json_1.default.version,
|
|
641
654
|
scannerVersion: scannerVersionFromPackage(),
|
|
655
|
+
stamps: (0, scan_stamps_1.buildScanStamps)({
|
|
656
|
+
cliVersion: package_json_1.default.version,
|
|
657
|
+
scanner: (0, scan_stamps_1.scannerBuildInfo)((0, scan_stamps_1.findCliPackageRoot)(__dirname), scannerCommitFromPackage()),
|
|
658
|
+
// Where the output goes is not a setting of the scan (DATAP-876).
|
|
659
|
+
config: { ...config, excludePaths: config.excludePaths?.filter((p) => !outputExcludes.includes(p)) },
|
|
660
|
+
aiInference: config.enableAiInference === true,
|
|
661
|
+
structureGraph: Boolean(knowledge.result.structureGraph),
|
|
662
|
+
git: gitStamps,
|
|
663
|
+
}),
|
|
642
664
|
});
|
|
665
|
+
if (options.sensitiveScan !== false) {
|
|
666
|
+
ui.sensitiveScanMessage('Scanning for sensitive information with LeftBlock');
|
|
667
|
+
}
|
|
668
|
+
const sensitiveFindings = await (0, project_1.writeProjectSensitiveScan)(dataflowOutputPath, {
|
|
669
|
+
root: scanEntry.scanRootDir,
|
|
670
|
+
target: scanEntry.ingestTarget,
|
|
671
|
+
excludes: config.excludePaths ?? [],
|
|
672
|
+
modelMode: options.privacyFilter,
|
|
673
|
+
enabled: options.sensitiveScan !== false,
|
|
674
|
+
}, message => ui.warn(message));
|
|
675
|
+
if (sensitiveFindings !== undefined) {
|
|
676
|
+
ui.sensitiveScanMessage(`LeftBlock reported ${sensitiveFindings} sensitive information finding(s).`);
|
|
677
|
+
}
|
|
643
678
|
// Friendly TTY/plain progress line (additive).
|
|
644
679
|
ui.onWroteDataflow(dataflowOutputPath);
|
|
645
680
|
// Machine line for scripts / CI (non-TTY). The friendly TTY UI
|
|
@@ -669,6 +704,7 @@ function createProgram() {
|
|
|
669
704
|
cliUsageSessionId: usageSessionId,
|
|
670
705
|
command: 'scan',
|
|
671
706
|
files,
|
|
707
|
+
repositoryDir: scanEntry.scanRootDir,
|
|
672
708
|
quiet: friendlyTty,
|
|
673
709
|
});
|
|
674
710
|
if (uploadResult.previewUrl) {
|
|
@@ -881,6 +917,7 @@ function createProgram() {
|
|
|
881
917
|
cliUsageSessionId: usageSessionId,
|
|
882
918
|
command: 'upload',
|
|
883
919
|
files,
|
|
920
|
+
repositoryDir: path_1.default.dirname(filePath),
|
|
884
921
|
});
|
|
885
922
|
}
|
|
886
923
|
catch (err) {
|
|
@@ -925,7 +962,13 @@ function createProgram() {
|
|
|
925
962
|
}
|
|
926
963
|
});
|
|
927
964
|
(0, register_kb_commands_1.registerKbCommands)(program);
|
|
965
|
+
// The scan cache of `diff` is keyed by these stamps (DATAP-878).
|
|
966
|
+
(0, register_diff_command_1.registerDiffCommand)(program, () => ({
|
|
967
|
+
cliVersion: package_json_1.default.version,
|
|
968
|
+
...(0, scan_stamps_1.scannerBuildInfo)((0, scan_stamps_1.findCliPackageRoot)(__dirname), scannerCommitFromPackage()),
|
|
969
|
+
}));
|
|
928
970
|
(0, register_export_commands_1.registerExportCommands)(program);
|
|
971
|
+
(0, sessions_1.registerSessionScan)(program);
|
|
929
972
|
return program;
|
|
930
973
|
}
|
|
931
974
|
async function run(argv) {
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
exports.registerDiffCommand = registerDiffCommand;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const kb_compare_1 = require("../../vendor/kb-compare/dist/src/index.js");
|
|
11
|
+
const scan_env_1 = require("../config/scan-env");
|
|
12
|
+
const run_diff_1 = require("./run-diff");
|
|
13
|
+
const build_preview_url_1 = require("../upload/build-preview-url");
|
|
14
|
+
const upload_diff_1 = require("./upload-diff");
|
|
15
|
+
/** Scans a folder by running this CLI's own `scan` command, with AI off and no upload. */
|
|
16
|
+
function scanWithThisCli() {
|
|
17
|
+
const entry = process.argv[1];
|
|
18
|
+
return (dir, outDir) => {
|
|
19
|
+
try {
|
|
20
|
+
(0, child_process_1.execFileSync)(process.execPath, [
|
|
21
|
+
entry,
|
|
22
|
+
'scan',
|
|
23
|
+
dir,
|
|
24
|
+
'--no-ai-inference',
|
|
25
|
+
'-o',
|
|
26
|
+
path_1.default.join(outDir, 'dataflow.json'),
|
|
27
|
+
], {
|
|
28
|
+
env: {
|
|
29
|
+
...process.env,
|
|
30
|
+
DATAPARADE_SKIP_AUTO_UPLOAD: '1',
|
|
31
|
+
SCAN_AI_INFERENCE: 'false',
|
|
32
|
+
},
|
|
33
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
34
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
35
|
+
});
|
|
36
|
+
return JSON.parse(fs_1.default.readFileSync(path_1.default.join(outDir, 'facts.json'), 'utf8'));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const stderr = error.stderr?.toString().trim();
|
|
40
|
+
throw new run_diff_1.DiffError('SCAN_FAILED', `The scan of ${dir} failed${stderr ? `:\n${stderr.split('\n').slice(-5).join('\n')}` : '.'}`);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Hidden for now (DATAP-852): compares two Git revisions of one repository. */
|
|
45
|
+
function registerDiffCommand(program, tools) {
|
|
46
|
+
program
|
|
47
|
+
.command('diff <repo> <base> <head>', { hidden: true })
|
|
48
|
+
.description('Compare two Git revisions of a repository and write the change set (AI off)')
|
|
49
|
+
.option('-o, --output <dir>', 'Folder for change-set.json, summary.txt and renames.json', 'dataparade-diff')
|
|
50
|
+
.option('--no-cache', 'Scan both revisions again instead of reusing cached scans')
|
|
51
|
+
.option('--upload', 'Upload both scans, the rename map and the root commit, so the backend compares them (needs a workspace API key)')
|
|
52
|
+
.option('--workspace-api-key <key>', 'DataParade workspace API key for --upload (env: DATAPARADE_WORKSPACE_API_KEY)')
|
|
53
|
+
.action(async (repo, base, head, options) => {
|
|
54
|
+
const apiKey = options.workspaceApiKey?.trim() ||
|
|
55
|
+
(0, scan_env_1.resolveWorkspaceApiKey)(process.env);
|
|
56
|
+
if (options.upload && !apiKey) {
|
|
57
|
+
console.error('--upload needs a workspace API key: pass --workspace-api-key or set DATAPARADE_WORKSPACE_API_KEY.');
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const result = (0, run_diff_1.runDiff)({
|
|
63
|
+
repo,
|
|
64
|
+
base,
|
|
65
|
+
head,
|
|
66
|
+
outputDir: path_1.default.resolve(options.output),
|
|
67
|
+
scan: scanWithThisCli(),
|
|
68
|
+
tools: tools(),
|
|
69
|
+
cacheDir: options.cache ? (0, run_diff_1.defaultCacheDir)() : null,
|
|
70
|
+
keepScans: Boolean(options.upload),
|
|
71
|
+
log: (line) => console.error(line),
|
|
72
|
+
});
|
|
73
|
+
console.log(`${result.baseSha.slice(0, 8)}..${result.headSha.slice(0, 8)}`);
|
|
74
|
+
console.log(result.summary);
|
|
75
|
+
console.log(`\nWrote ${result.files.changeSet}`);
|
|
76
|
+
if (options.upload) {
|
|
77
|
+
const uploaded = await (0, upload_diff_1.uploadDiffScans)({
|
|
78
|
+
apiKey: apiKey,
|
|
79
|
+
repo,
|
|
80
|
+
result,
|
|
81
|
+
log: (line) => console.error(line),
|
|
82
|
+
});
|
|
83
|
+
console.log((0, upload_diff_1.describeUploadedComparison)(uploaded));
|
|
84
|
+
console.log(`Open the head scan: ${(0, build_preview_url_1.buildImportPreviewUrl)(uploaded.head.draftId, undefined, uploaded.head.appUrl)}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (error instanceof kb_compare_1.ComparisonRefused) {
|
|
89
|
+
// DATAP-877: the two scans cannot be compared; say why, with the reason code.
|
|
90
|
+
console.error(`Cannot compare these scans (${error.reason}): ${error.message}`);
|
|
91
|
+
process.exitCode = 3;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
95
|
+
process.exitCode =
|
|
96
|
+
error instanceof run_diff_1.DiffError && error.code === 'DIRTY_TREE' ? 2 : 1;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type ChangeSet } from "../../vendor/kb-compare/dist/src/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* `dataparade diff <repo> <base> <head>` (DATAP-852): scans two Git revisions of one repository
|
|
4
|
+
* and writes the change set between them. AI is off and nothing is uploaded.
|
|
5
|
+
*
|
|
6
|
+
* - Refuses a working tree with changes that are not committed.
|
|
7
|
+
* - Exports each revision with `git archive` into a temporary folder named after the repository,
|
|
8
|
+
* so the user's checkout is never touched.
|
|
9
|
+
* - Scans both revisions with the head's `dataparade.config.json`.
|
|
10
|
+
* - Reuses a cached scan only when it was made from the same commit and configuration by the same
|
|
11
|
+
* CLI, scanner and pattern catalog (DATAP-878); the cached scan's own stamps are checked too.
|
|
12
|
+
* - Writes `change-set.json`, `summary.txt` and `renames.json` (rename map and root commit).
|
|
13
|
+
* - With `keepScans` (`--upload`, DATAP-886), keeps each revision's whole scan output in
|
|
14
|
+
* `base/` and `head/`, with the commit, root commit and a clean tree in its facts.json stamps:
|
|
15
|
+
* the scan ran on a `git archive` export, which has no .git to read them from.
|
|
16
|
+
*/
|
|
17
|
+
export declare class DiffError extends Error {
|
|
18
|
+
readonly code: "NOT_A_REPO" | "DIRTY_TREE" | "UNKNOWN_REVISION" | "SCAN_FAILED";
|
|
19
|
+
constructor(code: "NOT_A_REPO" | "DIRTY_TREE" | "UNKNOWN_REVISION" | "SCAN_FAILED", message: string);
|
|
20
|
+
}
|
|
21
|
+
export declare const CONFIG_FILE = "dataparade.config.json";
|
|
22
|
+
export interface Rename {
|
|
23
|
+
from: string;
|
|
24
|
+
to: string;
|
|
25
|
+
similarity: number;
|
|
26
|
+
}
|
|
27
|
+
/** Scans `dir`, writes the scan output (dataflow.json, facts.json, ...) into `outDir`, and returns its facts.json, parsed. */
|
|
28
|
+
export type ScanFn = (dir: string, outDir: string) => unknown;
|
|
29
|
+
/** The scan stamps that describe the tools (DATAP-876). */
|
|
30
|
+
export interface ToolStamps {
|
|
31
|
+
cliVersion: string;
|
|
32
|
+
scannerCommit: string;
|
|
33
|
+
catalogHash: string;
|
|
34
|
+
}
|
|
35
|
+
/** True when a scan's stamps say it was made by these tools. Scans without stamps never match. */
|
|
36
|
+
export declare function madeBy(facts: unknown, tools: ToolStamps): boolean;
|
|
37
|
+
export interface RunDiffOptions {
|
|
38
|
+
repo: string;
|
|
39
|
+
base: string;
|
|
40
|
+
head: string;
|
|
41
|
+
/** Folder for change-set.json, summary.txt and renames.json. Created if missing. */
|
|
42
|
+
outputDir: string;
|
|
43
|
+
scan: ScanFn;
|
|
44
|
+
/** The tools that make the scans: part of the cache key, and checked against a cached scan's stamps. */
|
|
45
|
+
tools: ToolStamps;
|
|
46
|
+
/** Scan cache folder; scans are not cached when null. */
|
|
47
|
+
cacheDir: string | null;
|
|
48
|
+
/** Keep each revision's whole scan output in `<outputDir>/base` and `<outputDir>/head`, for upload. */
|
|
49
|
+
keepScans?: boolean;
|
|
50
|
+
log?: (line: string) => void;
|
|
51
|
+
}
|
|
52
|
+
export interface RunDiffResult {
|
|
53
|
+
changeSet: ChangeSet;
|
|
54
|
+
summary: string;
|
|
55
|
+
baseSha: string;
|
|
56
|
+
headSha: string;
|
|
57
|
+
rootCommit: string;
|
|
58
|
+
renames: Rename[];
|
|
59
|
+
files: {
|
|
60
|
+
changeSet: string;
|
|
61
|
+
summary: string;
|
|
62
|
+
renames: string;
|
|
63
|
+
};
|
|
64
|
+
/** The kept scan output folders, with `keepScans`. */
|
|
65
|
+
scanDirs?: {
|
|
66
|
+
base: string;
|
|
67
|
+
head: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** The repository's root commit (the oldest one when there are several). */
|
|
71
|
+
export declare function rootCommit(repo: string, sha: string): string;
|
|
72
|
+
/** Renamed files between two commits, from `git diff -M`. */
|
|
73
|
+
export declare function renameMap(repo: string, base: string, head: string): Rename[];
|
|
74
|
+
/**
|
|
75
|
+
* Writes the Git stamps of an exported revision into a kept scan's facts.json: the export has no
|
|
76
|
+
* .git, so the scan recorded no commit. The export is exactly that commit, so the tree is clean.
|
|
77
|
+
*/
|
|
78
|
+
export declare function stampCommit(factsPath: string, commitSha: string, rootCommitSha: string): void;
|
|
79
|
+
export declare function defaultCacheDir(): string;
|
|
80
|
+
export declare function runDiff(options: RunDiffOptions): RunDiffResult;
|
|
@@ -0,0 +1,206 @@
|
|
|
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
|
+
exports.CONFIG_FILE = exports.DiffError = void 0;
|
|
7
|
+
exports.madeBy = madeBy;
|
|
8
|
+
exports.rootCommit = rootCommit;
|
|
9
|
+
exports.renameMap = renameMap;
|
|
10
|
+
exports.stampCommit = stampCommit;
|
|
11
|
+
exports.defaultCacheDir = defaultCacheDir;
|
|
12
|
+
exports.runDiff = runDiff;
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
14
|
+
const crypto_1 = require("crypto");
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const os_1 = __importDefault(require("os"));
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const kb_compare_1 = require("../../vendor/kb-compare/dist/src/index.js");
|
|
19
|
+
/**
|
|
20
|
+
* `dataparade diff <repo> <base> <head>` (DATAP-852): scans two Git revisions of one repository
|
|
21
|
+
* and writes the change set between them. AI is off and nothing is uploaded.
|
|
22
|
+
*
|
|
23
|
+
* - Refuses a working tree with changes that are not committed.
|
|
24
|
+
* - Exports each revision with `git archive` into a temporary folder named after the repository,
|
|
25
|
+
* so the user's checkout is never touched.
|
|
26
|
+
* - Scans both revisions with the head's `dataparade.config.json`.
|
|
27
|
+
* - Reuses a cached scan only when it was made from the same commit and configuration by the same
|
|
28
|
+
* CLI, scanner and pattern catalog (DATAP-878); the cached scan's own stamps are checked too.
|
|
29
|
+
* - Writes `change-set.json`, `summary.txt` and `renames.json` (rename map and root commit).
|
|
30
|
+
* - With `keepScans` (`--upload`, DATAP-886), keeps each revision's whole scan output in
|
|
31
|
+
* `base/` and `head/`, with the commit, root commit and a clean tree in its facts.json stamps:
|
|
32
|
+
* the scan ran on a `git archive` export, which has no .git to read them from.
|
|
33
|
+
*/
|
|
34
|
+
class DiffError extends Error {
|
|
35
|
+
constructor(code, message) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.code = code;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.DiffError = DiffError;
|
|
41
|
+
exports.CONFIG_FILE = "dataparade.config.json";
|
|
42
|
+
/** True when a scan's stamps say it was made by these tools. Scans without stamps never match. */
|
|
43
|
+
function madeBy(facts, tools) {
|
|
44
|
+
const stamps = facts?.scan?.stamps;
|
|
45
|
+
return Boolean(stamps) && stamps.cliVersion === tools.cliVersion && stamps.scannerCommit === tools.scannerCommit && stamps.catalogHash === tools.catalogHash;
|
|
46
|
+
}
|
|
47
|
+
function git(repo, args) {
|
|
48
|
+
return (0, child_process_1.execFileSync)("git", ["-C", repo, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 64 * 1024 * 1024 });
|
|
49
|
+
}
|
|
50
|
+
function repoRoot(repo) {
|
|
51
|
+
try {
|
|
52
|
+
return git(repo, ["rev-parse", "--show-toplevel"]).trim();
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
throw new DiffError("NOT_A_REPO", `${repo} is not inside a Git repository.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function resolveCommit(repo, revision) {
|
|
59
|
+
try {
|
|
60
|
+
return git(repo, ["rev-parse", "--verify", "--quiet", `${revision}^{commit}`]).trim();
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw new DiffError("UNKNOWN_REVISION", `'${revision}' is not a commit in ${repo}.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The repository's root commit (the oldest one when there are several). */
|
|
67
|
+
function rootCommit(repo, sha) {
|
|
68
|
+
const roots = git(repo, ["rev-list", "--max-parents=0", sha]).trim().split("\n").filter(Boolean);
|
|
69
|
+
return roots[roots.length - 1];
|
|
70
|
+
}
|
|
71
|
+
/** Renamed files between two commits, from `git diff -M`. */
|
|
72
|
+
function renameMap(repo, base, head) {
|
|
73
|
+
const out = git(repo, ["diff", "-M", "--name-status", "-z", base, head]);
|
|
74
|
+
const fields = out.split("\0");
|
|
75
|
+
const renames = [];
|
|
76
|
+
for (let i = 0; i < fields.length;) {
|
|
77
|
+
const status = fields[i];
|
|
78
|
+
if (!status)
|
|
79
|
+
break;
|
|
80
|
+
if (status.startsWith("R")) {
|
|
81
|
+
renames.push({ from: fields[i + 1], to: fields[i + 2], similarity: Number(status.slice(1)) || 0 });
|
|
82
|
+
i += 3;
|
|
83
|
+
}
|
|
84
|
+
else if (status.startsWith("C")) {
|
|
85
|
+
i += 3;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
i += 2;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return renames.sort((a, b) => (a.from < b.from ? -1 : a.from > b.from ? 1 : 0));
|
|
92
|
+
}
|
|
93
|
+
function configAt(repo, sha) {
|
|
94
|
+
try {
|
|
95
|
+
return git(repo, ["show", `${sha}:${exports.CONFIG_FILE}`]);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Writes the tree of `sha` into `dir`, with the head's configuration in place of its own. */
|
|
102
|
+
function exportRevision(repo, sha, dir, headConfig) {
|
|
103
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
104
|
+
(0, child_process_1.execFileSync)("sh", ["-c", 'git -C "$1" archive --format=tar "$2" | tar -x -C "$3"', "sh", repo, sha, dir], { stdio: ["ignore", "ignore", "pipe"] });
|
|
105
|
+
const configPath = path_1.default.join(dir, exports.CONFIG_FILE);
|
|
106
|
+
if (headConfig === null)
|
|
107
|
+
fs_1.default.rmSync(configPath, { force: true });
|
|
108
|
+
else
|
|
109
|
+
fs_1.default.writeFileSync(configPath, headConfig);
|
|
110
|
+
}
|
|
111
|
+
const sha256 = (text) => (0, crypto_1.createHash)("sha256").update(text, "utf8").digest("hex");
|
|
112
|
+
/**
|
|
113
|
+
* Writes the Git stamps of an exported revision into a kept scan's facts.json: the export has no
|
|
114
|
+
* .git, so the scan recorded no commit. The export is exactly that commit, so the tree is clean.
|
|
115
|
+
*/
|
|
116
|
+
function stampCommit(factsPath, commitSha, rootCommitSha) {
|
|
117
|
+
const facts = JSON.parse(fs_1.default.readFileSync(factsPath, "utf8"));
|
|
118
|
+
const stamps = facts.scan?.stamps;
|
|
119
|
+
if (!stamps)
|
|
120
|
+
return;
|
|
121
|
+
facts.scan.stamps = { ...stamps, commitSha, dirty: false, rootCommitSha };
|
|
122
|
+
fs_1.default.writeFileSync(factsPath, `${JSON.stringify(facts, null, 2)}\n`);
|
|
123
|
+
}
|
|
124
|
+
function defaultCacheDir() {
|
|
125
|
+
return process.env.DATAPARADE_CACHE_DIR?.trim() || path_1.default.join(os_1.default.homedir(), ".cache", "dataparade", "diff-scans");
|
|
126
|
+
}
|
|
127
|
+
function runDiff(options) {
|
|
128
|
+
const log = options.log ?? (() => { });
|
|
129
|
+
const repo = repoRoot(path_1.default.resolve(options.repo));
|
|
130
|
+
if (git(repo, ["status", "--porcelain"]).trim() !== "") {
|
|
131
|
+
throw new DiffError("DIRTY_TREE", `${repo} has changes that are not committed. Commit or stash them, then run diff again.`);
|
|
132
|
+
}
|
|
133
|
+
const baseSha = resolveCommit(repo, options.base);
|
|
134
|
+
const headSha = resolveCommit(repo, options.head);
|
|
135
|
+
const root = rootCommit(repo, headSha);
|
|
136
|
+
const headConfig = configAt(repo, headSha);
|
|
137
|
+
const configChanged = configAt(repo, baseSha) !== headConfig;
|
|
138
|
+
const toolsKey = sha256(JSON.stringify([options.tools.cliVersion, options.tools.scannerCommit, options.tools.catalogHash, headConfig ?? ""])).slice(0, 16);
|
|
139
|
+
const cacheKey = (sha) => `${sha}-${toolsKey}`;
|
|
140
|
+
const folderName = path_1.default.basename(repo);
|
|
141
|
+
const keepDir = (side) => path_1.default.join(options.outputDir, side);
|
|
142
|
+
/** The scan of `sha`; with `keepScans`, its whole output is also left in `keep`. */
|
|
143
|
+
const scanRevision = (sha, keep) => {
|
|
144
|
+
const cacheFolder = options.cacheDir ? path_1.default.join(options.cacheDir, root, cacheKey(sha)) : null;
|
|
145
|
+
const cached = cacheFolder ? path_1.default.join(cacheFolder, "facts.json") : null;
|
|
146
|
+
// A cache entry from before --upload holds facts.json only; an upload needs the whole output.
|
|
147
|
+
const usable = cached && fs_1.default.existsSync(cached) && (!keep || fs_1.default.existsSync(path_1.default.join(cacheFolder, "dataflow.json")));
|
|
148
|
+
if (usable) {
|
|
149
|
+
const facts = JSON.parse(fs_1.default.readFileSync(cached, "utf8"));
|
|
150
|
+
if (madeBy(facts, options.tools)) {
|
|
151
|
+
log(`Reusing the scan of ${sha.slice(0, 8)}.`);
|
|
152
|
+
if (keep)
|
|
153
|
+
fs_1.default.cpSync(cacheFolder, keep, { recursive: true });
|
|
154
|
+
return facts;
|
|
155
|
+
}
|
|
156
|
+
log(`The cached scan of ${sha.slice(0, 8)} was made by other tools; scanning again.`);
|
|
157
|
+
}
|
|
158
|
+
const work = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dataparade-diff-"));
|
|
159
|
+
try {
|
|
160
|
+
const dir = path_1.default.join(work, folderName);
|
|
161
|
+
const out = keep ?? path_1.default.join(work, "out");
|
|
162
|
+
exportRevision(repo, sha, dir, headConfig);
|
|
163
|
+
fs_1.default.mkdirSync(out, { recursive: true });
|
|
164
|
+
log(`Scanning ${sha.slice(0, 8)}...`);
|
|
165
|
+
const facts = options.scan(dir, out);
|
|
166
|
+
if (cacheFolder) {
|
|
167
|
+
fs_1.default.rmSync(cacheFolder, { recursive: true, force: true });
|
|
168
|
+
fs_1.default.mkdirSync(cacheFolder, { recursive: true });
|
|
169
|
+
fs_1.default.cpSync(out, cacheFolder, { recursive: true });
|
|
170
|
+
fs_1.default.writeFileSync(cached, JSON.stringify(facts));
|
|
171
|
+
}
|
|
172
|
+
return facts;
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
fs_1.default.rmSync(work, { recursive: true, force: true });
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
if (options.keepScans) {
|
|
179
|
+
for (const side of ["base", "head"])
|
|
180
|
+
fs_1.default.rmSync(keepDir(side), { recursive: true, force: true });
|
|
181
|
+
}
|
|
182
|
+
const baseFacts = scanRevision(baseSha, options.keepScans ? keepDir("base") : null);
|
|
183
|
+
const headFacts = headSha === baseSha ? baseFacts : scanRevision(headSha, options.keepScans ? keepDir("head") : null);
|
|
184
|
+
let scanDirs;
|
|
185
|
+
if (options.keepScans) {
|
|
186
|
+
if (headSha === baseSha)
|
|
187
|
+
fs_1.default.cpSync(keepDir("base"), keepDir("head"), { recursive: true });
|
|
188
|
+
scanDirs = { base: keepDir("base"), head: keepDir("head") };
|
|
189
|
+
stampCommit(path_1.default.join(scanDirs.base, "facts.json"), baseSha, root);
|
|
190
|
+
stampCommit(path_1.default.join(scanDirs.head, "facts.json"), headSha, root);
|
|
191
|
+
}
|
|
192
|
+
// The rename map makes renamed and moved elements "renamed" instead of removed plus added (DATAP-866).
|
|
193
|
+
const renames = renameMap(repo, baseSha, headSha);
|
|
194
|
+
const changeSet = (0, kb_compare_1.compareScans)(baseFacts, headFacts, { configChanged, renames });
|
|
195
|
+
const summary = (0, kb_compare_1.summarizeChangeSet)(changeSet);
|
|
196
|
+
fs_1.default.mkdirSync(options.outputDir, { recursive: true });
|
|
197
|
+
const files = {
|
|
198
|
+
changeSet: path_1.default.join(options.outputDir, "change-set.json"),
|
|
199
|
+
summary: path_1.default.join(options.outputDir, "summary.txt"),
|
|
200
|
+
renames: path_1.default.join(options.outputDir, "renames.json"),
|
|
201
|
+
};
|
|
202
|
+
fs_1.default.writeFileSync(files.changeSet, `${JSON.stringify(changeSet, null, 2)}\n`);
|
|
203
|
+
fs_1.default.writeFileSync(files.summary, `${summary}\n`);
|
|
204
|
+
fs_1.default.writeFileSync(files.renames, `${JSON.stringify({ rootCommit: root, base: baseSha, head: headSha, renames }, null, 2)}\n`);
|
|
205
|
+
return { changeSet, summary, baseSha, headSha, rootCommit: root, renames, files, ...(scanDirs ? { scanDirs } : {}) };
|
|
206
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { cliUploadPreview, type CliUploadComparison, type CliUploadPreviewResponse } from "../platform-api/upload-client";
|
|
2
|
+
import type { RunDiffResult } from "./run-diff";
|
|
3
|
+
/**
|
|
4
|
+
* `dataparade diff --upload` (DATAP-886, DATAP-890): uploads the base and head scans of a diff
|
|
5
|
+
* through the normal upload path, so the backend stores a comparable pair. The head's completion
|
|
6
|
+
* call carries the rename map and root commit; the backend stores the map as renames.json beside
|
|
7
|
+
* the head's facts.json and compares the head with the base (DATAP-891).
|
|
8
|
+
*/
|
|
9
|
+
export type UploadFn = typeof cliUploadPreview;
|
|
10
|
+
export interface UploadDiffOptions {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
/** The scanned repository, for its origin remote. */
|
|
13
|
+
repo: string;
|
|
14
|
+
result: Pick<RunDiffResult, "baseSha" | "headSha" | "rootCommit" | "renames" | "scanDirs">;
|
|
15
|
+
upload?: UploadFn;
|
|
16
|
+
log?: (line: string) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface UploadDiffResult {
|
|
19
|
+
base: CliUploadPreviewResponse;
|
|
20
|
+
head: CliUploadPreviewResponse;
|
|
21
|
+
/** The backend's comparison of the pair; null when the head completion failed or did not compare. */
|
|
22
|
+
comparison: CliUploadComparison | null;
|
|
23
|
+
}
|
|
24
|
+
export declare function uploadDiffScans(options: UploadDiffOptions): Promise<UploadDiffResult>;
|
|
25
|
+
/** One line on what the backend did with the pair, for the terminal. */
|
|
26
|
+
export declare function describeUploadedComparison(upload: UploadDiffResult): string;
|