@dataparade/cli 0.0.20 → 0.0.22
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 +12 -10
- package/dist/package.json +2 -1
- package/dist/src/ai-enrichment/agent-orchestrator.d.ts +8 -2
- package/dist/src/ai-enrichment/agent-orchestrator.js +140 -70
- package/dist/src/ai-enrichment/provider-prompt.js +36 -2
- package/dist/src/cli.js +98 -51
- package/dist/src/config/scan-env.d.ts +5 -0
- package/dist/src/config/scan-env.js +12 -1
- package/dist/src/core/pipeline/scan-pipeline.d.ts +2 -1
- package/dist/src/core/pipeline/scan-pipeline.js +7 -4
- package/dist/src/ui/brand.d.ts +28 -0
- package/dist/src/ui/brand.js +72 -0
- package/dist/src/ui/scan-progress-renderer.d.ts +69 -0
- package/dist/src/ui/scan-progress-renderer.js +386 -0
- package/dist/src/ui/teaching-lines.d.ts +9 -0
- package/dist/src/ui/teaching-lines.js +144 -0
- package/dist/src/ui/types.d.ts +33 -0
- package/dist/src/ui/types.js +2 -0
- package/dist/src/upload/run-upload.d.ts +1 -1
- package/dist/src/upload/run-upload.js +21 -16
- package/dist/src/upload/types.d.ts +4 -0
- package/dist/tests/cli/cli.spec.js +77 -40
- package/dist/tests/unit/ai-enrichment/agent-orchestrator.spec.js +227 -147
- package/dist/tests/unit/ai-enrichment/provider-prompt.spec.js +35 -0
- package/dist/tests/unit/cli/scan-quota-flow.spec.js +9 -0
- package/dist/tests/unit/config/scan-env-debug.spec.js +17 -8
- package/dist/tests/unit/ui/brand.spec.d.ts +1 -0
- package/dist/tests/unit/ui/brand.spec.js +52 -0
- package/dist/tests/unit/ui/scan-progress-renderer.spec.d.ts +1 -0
- package/dist/tests/unit/ui/scan-progress-renderer.spec.js +275 -0
- package/dist/tests/unit/ui/teaching-lines.spec.d.ts +1 -0
- package/dist/tests/unit/ui/teaching-lines.spec.js +62 -0
- package/dist/tests/unit/upload/run-upload.spec.js +29 -27
- package/package.json +2 -1
|
@@ -37,6 +37,41 @@ describe('provider-prompt', () => {
|
|
|
37
37
|
expect(slim.sparsePropertyKeys).not.toContain('inference_status');
|
|
38
38
|
expect(slim.sparsePropertyKeys[0]).toBe('encrypt_at_rest');
|
|
39
39
|
});
|
|
40
|
+
it('slimComponentForLlm drops scanner evidence and caps oversized set values', () => {
|
|
41
|
+
const evidence = Array.from({ length: 2_000 }, (_, i) => ({
|
|
42
|
+
filePath: `backend/src/entities/e${i}.ts`,
|
|
43
|
+
startLine: i,
|
|
44
|
+
endLine: i,
|
|
45
|
+
reason: 'property.patterns.yaml:database_connection',
|
|
46
|
+
}));
|
|
47
|
+
const c = {
|
|
48
|
+
id: 'cmp_orm',
|
|
49
|
+
name: 'Typeorm',
|
|
50
|
+
type: 'asset',
|
|
51
|
+
confidence: 0.9,
|
|
52
|
+
detectedFrom: [],
|
|
53
|
+
sourceLocations: [],
|
|
54
|
+
properties: {
|
|
55
|
+
propertyEvidence: { audit_logging_enabled: evidence },
|
|
56
|
+
dataActions: [
|
|
57
|
+
{ action: 'store', source: 'deterministic', evidence },
|
|
58
|
+
{ action: 'combine', source: 'deterministic', evidence },
|
|
59
|
+
{ action: 'store', source: 'deterministic', evidence },
|
|
60
|
+
],
|
|
61
|
+
data_categories: Array.from({ length: 2_000 }, (_, i) => `cat_${i}`),
|
|
62
|
+
vendor: null,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
const slim = (0, provider_prompt_1.slimComponentForLlm)(c);
|
|
66
|
+
const propertiesSet = slim.propertiesSet;
|
|
67
|
+
expect(propertiesSet.propertyEvidence).toBeUndefined();
|
|
68
|
+
expect(slim.sparsePropertyKeys).not.toContain('propertyEvidence');
|
|
69
|
+
expect(propertiesSet.dataActions).toEqual(['store', 'combine']);
|
|
70
|
+
const categories = propertiesSet.data_categories;
|
|
71
|
+
expect(categories.length).toBeGreaterThan(0);
|
|
72
|
+
expect(categories.length).toBeLessThan(2_000);
|
|
73
|
+
expect(JSON.stringify(slim).length).toBeLessThan(10_000);
|
|
74
|
+
});
|
|
40
75
|
it('buildProviderPromptPayload includes componentContext for queued componentIds', () => {
|
|
41
76
|
const components = [
|
|
42
77
|
{
|
|
@@ -104,6 +104,9 @@ describe('scan quota flow', () => {
|
|
|
104
104
|
it('prints ready-for-new-scan message after platform scan completes', async () => {
|
|
105
105
|
process.env.DATAPARADE_WORKSPACE_API_KEY = 'dp_live_test';
|
|
106
106
|
process.env.DATAPARADE_SKIP_AUTO_UPLOAD = 'true';
|
|
107
|
+
// Plain TTY (no Clack chrome): the Clack outro replaces this line.
|
|
108
|
+
const previousNoColor = process.env.NO_COLOR;
|
|
109
|
+
process.env.NO_COLOR = '1';
|
|
107
110
|
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
|
|
108
111
|
const isTty = Object.getOwnPropertyDescriptor(process.stdout, 'isTTY');
|
|
109
112
|
Object.defineProperty(process.stdout, 'isTTY', {
|
|
@@ -128,6 +131,12 @@ describe('scan quota flow', () => {
|
|
|
128
131
|
else {
|
|
129
132
|
delete process.stdout.isTTY;
|
|
130
133
|
}
|
|
134
|
+
if (previousNoColor === undefined) {
|
|
135
|
+
delete process.env.NO_COLOR;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
process.env.NO_COLOR = previousNoColor;
|
|
139
|
+
}
|
|
131
140
|
logSpy.mockRestore();
|
|
132
141
|
});
|
|
133
142
|
});
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const scan_env_1 = require("../../../src/config/scan-env");
|
|
4
|
-
describe(
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
describe('isScanAiDebugEnabled', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
(0, scan_env_1.setScanAiDebugSuppressed)(false);
|
|
7
7
|
});
|
|
8
|
-
it(
|
|
9
|
-
|
|
8
|
+
it('is off while suppressed, even with SCAN_AI_DEBUG=true', () => {
|
|
9
|
+
(0, scan_env_1.setScanAiDebugSuppressed)(true);
|
|
10
|
+
expect((0, scan_env_1.isScanAiDebugEnabled)({ SCAN_AI_DEBUG: 'true' })).toBe(false);
|
|
11
|
+
(0, scan_env_1.setScanAiDebugSuppressed)(false);
|
|
12
|
+
expect((0, scan_env_1.isScanAiDebugEnabled)({ SCAN_AI_DEBUG: 'true' })).toBe(true);
|
|
10
13
|
});
|
|
11
|
-
it(
|
|
14
|
+
it('accepts SCAN_AI_DEBUG', () => {
|
|
15
|
+
expect((0, scan_env_1.isScanAiDebugEnabled)({ SCAN_AI_DEBUG: 'true' })).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
it('ignores legacy DATAPARADE_AI_DEBUG', () => {
|
|
18
|
+
expect((0, scan_env_1.isScanAiDebugEnabled)({ DATAPARADE_AI_DEBUG: '1' })).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
it('uses SCAN_AI_DEBUG only when legacy is also present', () => {
|
|
12
21
|
expect((0, scan_env_1.isScanAiDebugEnabled)({
|
|
13
|
-
SCAN_AI_DEBUG:
|
|
14
|
-
DATAPARADE_AI_DEBUG:
|
|
22
|
+
SCAN_AI_DEBUG: 'false',
|
|
23
|
+
DATAPARADE_AI_DEBUG: 'true',
|
|
15
24
|
})).toBe(false);
|
|
16
25
|
});
|
|
17
26
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const brand_1 = require("../../../src/ui/brand");
|
|
4
|
+
const scan_progress_renderer_1 = require("../../../src/ui/scan-progress-renderer");
|
|
5
|
+
describe('renderBrandHeader', () => {
|
|
6
|
+
it('prints the figlet with version and tagline on a wide color TTY', () => {
|
|
7
|
+
const lines = (0, brand_1.renderBrandHeader)({
|
|
8
|
+
version: '1.2.3',
|
|
9
|
+
color: true,
|
|
10
|
+
colorDepth: 24,
|
|
11
|
+
columns: 120,
|
|
12
|
+
showLogo: true,
|
|
13
|
+
});
|
|
14
|
+
const plain = lines.map(scan_progress_renderer_1.stripAnsi);
|
|
15
|
+
expect(plain[0]).toContain('____');
|
|
16
|
+
expect(plain.at(-1)).toBe(` v1.2.3 ${brand_1.DATAPARADE_TAGLINE}`);
|
|
17
|
+
// Truecolor gradient ending on --color-brand #0c7377.
|
|
18
|
+
expect(lines[4]).toContain('38;2;12;115;119');
|
|
19
|
+
});
|
|
20
|
+
it('falls back to 256 colors and basic cyan on shallower terminals', () => {
|
|
21
|
+
const [first256] = (0, brand_1.renderBrandHeader)({
|
|
22
|
+
color: true,
|
|
23
|
+
colorDepth: 8,
|
|
24
|
+
showLogo: true,
|
|
25
|
+
});
|
|
26
|
+
expect(first256).toContain('38;5;');
|
|
27
|
+
const [first16] = (0, brand_1.renderBrandHeader)({
|
|
28
|
+
color: true,
|
|
29
|
+
colorDepth: 4,
|
|
30
|
+
showLogo: true,
|
|
31
|
+
});
|
|
32
|
+
expect(first16).toContain('[36m');
|
|
33
|
+
});
|
|
34
|
+
it('uses one line on narrow terminals', () => {
|
|
35
|
+
const lines = (0, brand_1.renderBrandHeader)({
|
|
36
|
+
version: '1.2.3',
|
|
37
|
+
color: false,
|
|
38
|
+
columns: brand_1.BRAND_LOGO_MIN_COLUMNS - 1,
|
|
39
|
+
showLogo: true,
|
|
40
|
+
});
|
|
41
|
+
expect(lines).toEqual([`DataParade v1.2.3 · ${brand_1.DATAPARADE_TAGLINE}`]);
|
|
42
|
+
});
|
|
43
|
+
it('skips the figlet and ANSI in CI / non-TTY', () => {
|
|
44
|
+
const lines = (0, brand_1.renderBrandHeader)({
|
|
45
|
+
version: '1.2.3',
|
|
46
|
+
color: false,
|
|
47
|
+
showLogo: false,
|
|
48
|
+
});
|
|
49
|
+
expect(lines).toHaveLength(1);
|
|
50
|
+
expect((0, scan_progress_renderer_1.hasAnsi)(lines[0])).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
jest.mock('@clack/prompts', () => {
|
|
37
|
+
const spin = {
|
|
38
|
+
start: jest.fn(),
|
|
39
|
+
stop: jest.fn(),
|
|
40
|
+
message: jest.fn(),
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
intro: jest.fn(),
|
|
44
|
+
outro: jest.fn(),
|
|
45
|
+
note: jest.fn(),
|
|
46
|
+
spinner: jest.fn(() => spin),
|
|
47
|
+
log: {
|
|
48
|
+
message: jest.fn(),
|
|
49
|
+
success: jest.fn(),
|
|
50
|
+
step: jest.fn(),
|
|
51
|
+
warn: jest.fn(),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
const scan_progress_renderer_1 = require("../../../src/ui/scan-progress-renderer");
|
|
56
|
+
const prompts = __importStar(require("@clack/prompts"));
|
|
57
|
+
function captureLines() {
|
|
58
|
+
const lines = [];
|
|
59
|
+
return {
|
|
60
|
+
lines,
|
|
61
|
+
writeLine: (line) => {
|
|
62
|
+
lines.push(line);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
describe('ScanProgressRenderer', () => {
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
jest.clearAllMocks();
|
|
69
|
+
});
|
|
70
|
+
it('non-TTY output has no spinner frames and no ANSI', async () => {
|
|
71
|
+
const { lines, writeLine } = captureLines();
|
|
72
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
73
|
+
isTTY: false,
|
|
74
|
+
noColor: false,
|
|
75
|
+
writeLine,
|
|
76
|
+
projectLabel: '/tmp/demo',
|
|
77
|
+
});
|
|
78
|
+
ui.start();
|
|
79
|
+
ui.onProgress({
|
|
80
|
+
phase: 'ingest',
|
|
81
|
+
filesProcessed: 0,
|
|
82
|
+
totalFiles: 0,
|
|
83
|
+
progress: 0.05,
|
|
84
|
+
message: 'Ingesting...',
|
|
85
|
+
});
|
|
86
|
+
ui.onProgress({
|
|
87
|
+
phase: 'analyze',
|
|
88
|
+
filesProcessed: 1,
|
|
89
|
+
totalFiles: 1,
|
|
90
|
+
progress: 0.25,
|
|
91
|
+
message: 'Analyzing...',
|
|
92
|
+
});
|
|
93
|
+
ui.onRecognition({
|
|
94
|
+
findings: [
|
|
95
|
+
{
|
|
96
|
+
pattern: 'express_route',
|
|
97
|
+
name: 'route',
|
|
98
|
+
confidence: 0.9,
|
|
99
|
+
location: { filePath: 'a.ts', startLine: 1, endLine: 1 },
|
|
100
|
+
properties: { framework: 'express' },
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
components: [
|
|
104
|
+
{
|
|
105
|
+
id: 'tp-1',
|
|
106
|
+
name: 'stripe',
|
|
107
|
+
type: 'third_party',
|
|
108
|
+
confidence: 0.9,
|
|
109
|
+
detectedFrom: [],
|
|
110
|
+
properties: { serviceName: 'stripe' },
|
|
111
|
+
sourceLocations: [],
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
});
|
|
115
|
+
ui.onWroteDataflow('/tmp/out.json');
|
|
116
|
+
ui.onPreviewUrl('https://example.test/preview');
|
|
117
|
+
ui.finish();
|
|
118
|
+
const joined = lines.join('\n');
|
|
119
|
+
expect((0, scan_progress_renderer_1.hasAnsi)(joined)).toBe(false);
|
|
120
|
+
expect(joined).not.toMatch(/[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]/);
|
|
121
|
+
expect(joined).toContain('Map privacy data flows from your code');
|
|
122
|
+
expect(joined).toContain('Found 1 Express route');
|
|
123
|
+
expect(joined).toContain('Calls out to Stripe');
|
|
124
|
+
expect(joined).toContain("Here's what stood out");
|
|
125
|
+
expect(joined).toContain('Saved your data-flow map');
|
|
126
|
+
expect(joined).toContain('What to do next');
|
|
127
|
+
expect(joined).toContain('Open your diagram:');
|
|
128
|
+
expect(joined).toContain('https://example.test/preview');
|
|
129
|
+
expect(joined).not.toContain('Your preview is ready whenever you are');
|
|
130
|
+
expect(ui.usesClackChrome).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
it('formats the preview link with ANSI when color is on', () => {
|
|
133
|
+
const plain = (0, scan_progress_renderer_1.formatPreviewLink)('https://example.test/preview', false);
|
|
134
|
+
expect(plain).toBe('https://example.test/preview');
|
|
135
|
+
expect((0, scan_progress_renderer_1.hasAnsi)(plain)).toBe(false);
|
|
136
|
+
const colored = (0, scan_progress_renderer_1.formatPreviewLink)('https://example.test/preview', true);
|
|
137
|
+
expect(colored).toContain('https://example.test/preview');
|
|
138
|
+
expect((0, scan_progress_renderer_1.hasAnsi)(colored)).toBe(true);
|
|
139
|
+
// No underline (SGR 4): it reads as broken next to the terminal's own link styling.
|
|
140
|
+
expect(colored).not.toMatch(/\[[0-9;]*\b4\b[0-9;]*m/);
|
|
141
|
+
});
|
|
142
|
+
it('TTY finish prints What to do next without a wrapping box', async () => {
|
|
143
|
+
const { writeLine } = captureLines();
|
|
144
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
145
|
+
isTTY: true,
|
|
146
|
+
noColor: false,
|
|
147
|
+
writeLine,
|
|
148
|
+
prompts,
|
|
149
|
+
});
|
|
150
|
+
const longUrl = 'http://localhost:3001/dashboard?importDraft=8ff8d852-b39a-4973-947b-dd1425bb4f99&cliSession=2ca5b9c6-c173-4a7a-bcbf-242f0479ecf7';
|
|
151
|
+
ui.onPreviewUrl(longUrl);
|
|
152
|
+
ui.finish();
|
|
153
|
+
expect(prompts.note).not.toHaveBeenCalled();
|
|
154
|
+
expect(prompts.log.step).toHaveBeenCalledWith('What to do next');
|
|
155
|
+
const body = String(prompts.log.message.mock.calls.at(-1)?.[0]);
|
|
156
|
+
expect(body).toContain('Open your diagram:');
|
|
157
|
+
expect((0, scan_progress_renderer_1.hasAnsi)(body)).toBe(true);
|
|
158
|
+
const urlLine = (0, scan_progress_renderer_1.stripAnsi)(body)
|
|
159
|
+
.split('\n')
|
|
160
|
+
.find((line) => line.includes('http'));
|
|
161
|
+
expect(urlLine).toBe(longUrl);
|
|
162
|
+
});
|
|
163
|
+
it('TTY shows AI inference as its own step with one result line', async () => {
|
|
164
|
+
const { lines, writeLine } = captureLines();
|
|
165
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
166
|
+
isTTY: true,
|
|
167
|
+
noColor: false,
|
|
168
|
+
writeLine,
|
|
169
|
+
prompts,
|
|
170
|
+
});
|
|
171
|
+
const spin = prompts.spinner();
|
|
172
|
+
prompts.spinner.mockClear();
|
|
173
|
+
ui.onProgress({
|
|
174
|
+
phase: 'ai_enrichment',
|
|
175
|
+
filesProcessed: 1,
|
|
176
|
+
totalFiles: 1,
|
|
177
|
+
progress: 0.85,
|
|
178
|
+
message: 'Running LLM inference...',
|
|
179
|
+
});
|
|
180
|
+
expect(prompts.spinner).toHaveBeenCalledTimes(1);
|
|
181
|
+
expect(spin.start).toHaveBeenLastCalledWith('Filling in details with AI');
|
|
182
|
+
ui.onAiResult({ proposalsApplied: 5 });
|
|
183
|
+
expect(spin.stop).toHaveBeenLastCalledWith('Filling in details with AI');
|
|
184
|
+
expect(prompts.log.message).toHaveBeenLastCalledWith('Filled in 5 details from your code');
|
|
185
|
+
expect(lines.some((line) => line.includes('[dataparade-ai]'))).toBe(false);
|
|
186
|
+
});
|
|
187
|
+
it('non-TTY shows the AI step and its result as plain lines', async () => {
|
|
188
|
+
const { lines, writeLine } = captureLines();
|
|
189
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
190
|
+
isTTY: false,
|
|
191
|
+
noColor: false,
|
|
192
|
+
writeLine,
|
|
193
|
+
});
|
|
194
|
+
ui.onProgress({
|
|
195
|
+
phase: 'ai_enrichment',
|
|
196
|
+
filesProcessed: 1,
|
|
197
|
+
totalFiles: 1,
|
|
198
|
+
progress: 0.85,
|
|
199
|
+
});
|
|
200
|
+
ui.onAiResult({ proposalsApplied: 0 });
|
|
201
|
+
expect(lines).toContain('… Filling in details with AI');
|
|
202
|
+
expect(lines).toContain('✓ Filling in details with AI');
|
|
203
|
+
expect(lines).toContain(' · Nothing new to add from AI');
|
|
204
|
+
});
|
|
205
|
+
it('ignores an AI result when the AI step never started', async () => {
|
|
206
|
+
const { lines, writeLine } = captureLines();
|
|
207
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
208
|
+
isTTY: false,
|
|
209
|
+
noColor: false,
|
|
210
|
+
writeLine,
|
|
211
|
+
});
|
|
212
|
+
ui.onAiResult({ proposalsApplied: 3 });
|
|
213
|
+
expect(lines.some((line) => line.includes('AI'))).toBe(false);
|
|
214
|
+
});
|
|
215
|
+
it('NO_COLOR disables Clack chrome and strips ANSI from plain writes', async () => {
|
|
216
|
+
const { lines, writeLine } = captureLines();
|
|
217
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
218
|
+
isTTY: true,
|
|
219
|
+
noColor: true,
|
|
220
|
+
writeLine,
|
|
221
|
+
});
|
|
222
|
+
ui.start();
|
|
223
|
+
ui.onProgress({
|
|
224
|
+
phase: 'ingest',
|
|
225
|
+
filesProcessed: 0,
|
|
226
|
+
totalFiles: 0,
|
|
227
|
+
progress: 0.05,
|
|
228
|
+
});
|
|
229
|
+
ui.onWroteDataflow();
|
|
230
|
+
expect(ui.usesClackChrome).toBe(false);
|
|
231
|
+
const joined = lines.join('\n');
|
|
232
|
+
expect((0, scan_progress_renderer_1.hasAnsi)(joined)).toBe(false);
|
|
233
|
+
expect((0, scan_progress_renderer_1.stripAnsi)(joined)).toBe(joined);
|
|
234
|
+
expect(joined).toContain('Map privacy data flows from your code');
|
|
235
|
+
expect(joined).toContain('Saved your data-flow map');
|
|
236
|
+
});
|
|
237
|
+
it('TTY keeps technical lines inside Clack instead of raw [scan] logs', async () => {
|
|
238
|
+
const { lines, writeLine } = captureLines();
|
|
239
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
240
|
+
isTTY: true,
|
|
241
|
+
noColor: false,
|
|
242
|
+
writeLine,
|
|
243
|
+
prompts,
|
|
244
|
+
});
|
|
245
|
+
ui.onWroteDataflow(`${process.cwd()}/outputs/out.json`);
|
|
246
|
+
ui.warn('ai-provider: request failed');
|
|
247
|
+
ui.showTechnicalDetails('Scan details', [
|
|
248
|
+
'[scan] ai-usage: provider_calls=1 tokens_total=10',
|
|
249
|
+
]);
|
|
250
|
+
ui.onPreviewUrl('https://example.test/preview', 'Claim uses 1 scan slot.');
|
|
251
|
+
ui.finish();
|
|
252
|
+
const success = String(prompts.log.success.mock.calls.at(-1)?.[0]);
|
|
253
|
+
expect((0, scan_progress_renderer_1.stripAnsi)(success)).toContain('./outputs/out.json');
|
|
254
|
+
expect(prompts.log.warn).toHaveBeenCalledWith('ai-provider: request failed');
|
|
255
|
+
const notes = prompts.note.mock.calls;
|
|
256
|
+
const details = notes.find((call) => call[1] === 'Scan details');
|
|
257
|
+
expect((0, scan_progress_renderer_1.stripAnsi)(String(details?.[0]))).toBe('ai-usage: provider_calls=1 tokens_total=10');
|
|
258
|
+
expect(String(prompts.log.message.mock.calls.at(-1)?.[0])).toContain('Claim uses 1 scan slot.');
|
|
259
|
+
expect(lines.some((line) => line.includes('[scan]'))).toBe(false);
|
|
260
|
+
});
|
|
261
|
+
it('non-TTY prints technical lines verbatim for scripts', async () => {
|
|
262
|
+
const { lines, writeLine } = captureLines();
|
|
263
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
264
|
+
isTTY: false,
|
|
265
|
+
noColor: false,
|
|
266
|
+
writeLine,
|
|
267
|
+
});
|
|
268
|
+
ui.showTechnicalDetails('Scan details', [
|
|
269
|
+
'[scan] ai-usage: provider_calls=1 tokens_total=10',
|
|
270
|
+
]);
|
|
271
|
+
expect(lines).toEqual([
|
|
272
|
+
'[scan] ai-usage: provider_calls=1 tokens_total=10',
|
|
273
|
+
]);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const teaching_lines_1 = require("../../../src/ui/teaching-lines");
|
|
4
|
+
function finding(pattern, properties) {
|
|
5
|
+
return {
|
|
6
|
+
pattern,
|
|
7
|
+
name: pattern,
|
|
8
|
+
confidence: 0.9,
|
|
9
|
+
location: { filePath: 'x.ts', startLine: 1, endLine: 1 },
|
|
10
|
+
properties,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function thirdParty(serviceName) {
|
|
14
|
+
return {
|
|
15
|
+
id: `tp-${serviceName}`,
|
|
16
|
+
name: serviceName,
|
|
17
|
+
type: 'third_party',
|
|
18
|
+
confidence: 0.9,
|
|
19
|
+
detectedFrom: [],
|
|
20
|
+
properties: { serviceName },
|
|
21
|
+
sourceLocations: [],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
describe('buildTeachingLineGroups', () => {
|
|
25
|
+
it('counts routes by framework', () => {
|
|
26
|
+
const groups = (0, teaching_lines_1.buildTeachingLineGroups)([
|
|
27
|
+
finding('express_route', { framework: 'express' }),
|
|
28
|
+
finding('express_route', { framework: 'express' }),
|
|
29
|
+
finding('express_route', { framework: 'nest' }),
|
|
30
|
+
], []);
|
|
31
|
+
expect(groups.routes).toEqual([
|
|
32
|
+
'Found 2 Express routes',
|
|
33
|
+
'Found 1 Nest route',
|
|
34
|
+
]);
|
|
35
|
+
});
|
|
36
|
+
it('formats data stores from client and databaseType without inventing Postgres', () => {
|
|
37
|
+
const groups = (0, teaching_lines_1.buildTeachingLineGroups)([
|
|
38
|
+
finding('database_connection', {
|
|
39
|
+
client: 'typeorm',
|
|
40
|
+
databaseType: 'sql',
|
|
41
|
+
}),
|
|
42
|
+
finding('database_connection', {
|
|
43
|
+
client: 'pg',
|
|
44
|
+
databaseType: 'postgres',
|
|
45
|
+
}),
|
|
46
|
+
], []);
|
|
47
|
+
expect(groups.stores).toEqual([
|
|
48
|
+
'Talks to SQL (TypeORM)',
|
|
49
|
+
'Talks to Postgres (pg)',
|
|
50
|
+
]);
|
|
51
|
+
});
|
|
52
|
+
it('coalesces outbound vendors from components and external_api_call findings', () => {
|
|
53
|
+
const groups = (0, teaching_lines_1.buildTeachingLineGroups)([finding('external_api_call', { serviceName: 'sentry' })], [thirdParty('stripe'), thirdParty('Stripe'), thirdParty('openai')]);
|
|
54
|
+
expect(groups.outbound).toEqual([
|
|
55
|
+
'Calls out to OpenAI, Sentry, and Stripe',
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
it('returns empty groups when nothing recognized', () => {
|
|
59
|
+
const groups = (0, teaching_lines_1.buildTeachingLineGroups)([], []);
|
|
60
|
+
expect((0, teaching_lines_1.flattenTeachingLines)(groups)).toEqual([]);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -1,61 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const run_upload_1 = require("../../../src/upload/run-upload");
|
|
4
|
-
jest.mock(
|
|
4
|
+
jest.mock('../../../src/platform-api/upload-client', () => ({
|
|
5
5
|
cliUploadAnonymousPreview: jest.fn(),
|
|
6
6
|
cliUploadPreview: jest.fn(),
|
|
7
7
|
}));
|
|
8
|
-
jest.mock(
|
|
8
|
+
jest.mock('../../../src/platform-api/telemetry-client', () => ({
|
|
9
9
|
reportCliUsageEvent: jest.fn().mockResolvedValue(undefined),
|
|
10
10
|
}));
|
|
11
|
-
jest.mock(
|
|
11
|
+
jest.mock('../../../src/upload/build-preview-url', () => ({
|
|
12
12
|
buildAnonymousCliPreviewUrl: jest.fn((token) => `https://app.example/preview/cli/${token}`),
|
|
13
13
|
buildImportPreviewUrl: jest.fn((draftId) => `https://app.example/dashboard?importDraft=${draftId}`),
|
|
14
14
|
}));
|
|
15
15
|
const upload_client_1 = require("../../../src/platform-api/upload-client");
|
|
16
16
|
const telemetry_client_1 = require("../../../src/platform-api/telemetry-client");
|
|
17
|
-
describe(
|
|
18
|
-
const logSpy = jest.spyOn(console,
|
|
17
|
+
describe('runDataflowUpload anonymous path', () => {
|
|
18
|
+
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => undefined);
|
|
19
19
|
afterEach(() => {
|
|
20
20
|
jest.clearAllMocks();
|
|
21
21
|
});
|
|
22
22
|
afterAll(() => {
|
|
23
23
|
logSpy.mockRestore();
|
|
24
24
|
});
|
|
25
|
-
it(
|
|
25
|
+
it('passes scanJobId to anonymous upload and mentions claim quota', async () => {
|
|
26
26
|
upload_client_1.cliUploadAnonymousPreview.mockResolvedValue({
|
|
27
|
-
claimToken:
|
|
27
|
+
claimToken: 'claim-1',
|
|
28
28
|
expiresAt: new Date().toISOString(),
|
|
29
|
-
projectName:
|
|
29
|
+
projectName: 'Proj',
|
|
30
30
|
});
|
|
31
31
|
const result = await (0, run_upload_1.runDataflowUpload)({
|
|
32
|
-
dataflow: { schemaVersion:
|
|
33
|
-
projectName:
|
|
34
|
-
scanJobId:
|
|
35
|
-
logPrefix:
|
|
32
|
+
dataflow: { schemaVersion: '1.0' },
|
|
33
|
+
projectName: 'Proj',
|
|
34
|
+
scanJobId: 'job-anon-1',
|
|
35
|
+
logPrefix: '[scan]',
|
|
36
36
|
});
|
|
37
37
|
expect(upload_client_1.cliUploadAnonymousPreview).toHaveBeenCalledWith({
|
|
38
|
-
dataflow: { schemaVersion:
|
|
39
|
-
projectName:
|
|
40
|
-
scanJobId:
|
|
38
|
+
dataflow: { schemaVersion: '1.0' },
|
|
39
|
+
projectName: 'Proj',
|
|
40
|
+
scanJobId: 'job-anon-1',
|
|
41
41
|
cliUsageSessionId: undefined,
|
|
42
|
-
command:
|
|
42
|
+
command: 'scan',
|
|
43
43
|
});
|
|
44
44
|
expect(upload_client_1.cliUploadPreview).not.toHaveBeenCalled();
|
|
45
|
-
expect(result.previewUrl).toContain(
|
|
46
|
-
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(
|
|
47
|
-
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(
|
|
45
|
+
expect(result.previewUrl).toContain('claim-1');
|
|
46
|
+
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('[scan] Preview ready:'));
|
|
47
|
+
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(result.previewUrl));
|
|
48
|
+
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('You can view the diagram now. Claiming it to your account uses 1 scan slot'));
|
|
49
|
+
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('platform AI tokens'));
|
|
48
50
|
});
|
|
49
|
-
it(
|
|
50
|
-
upload_client_1.cliUploadAnonymousPreview.mockRejectedValue(new Error(
|
|
51
|
+
it('reports upload_failed and rethrows', async () => {
|
|
52
|
+
upload_client_1.cliUploadAnonymousPreview.mockRejectedValue(new Error('network down'));
|
|
51
53
|
await expect((0, run_upload_1.runDataflowUpload)({
|
|
52
|
-
dataflow: { schemaVersion:
|
|
53
|
-
cliUsageSessionId:
|
|
54
|
-
logPrefix:
|
|
55
|
-
})).rejects.toThrow(
|
|
54
|
+
dataflow: { schemaVersion: '1.0' },
|
|
55
|
+
cliUsageSessionId: '11111111-1111-4111-8111-111111111111',
|
|
56
|
+
logPrefix: '[scan]',
|
|
57
|
+
})).rejects.toThrow('network down');
|
|
56
58
|
expect(telemetry_client_1.reportCliUsageEvent).toHaveBeenCalledWith(expect.objectContaining({
|
|
57
|
-
event:
|
|
58
|
-
errorCode:
|
|
59
|
+
event: 'upload_failed',
|
|
60
|
+
errorCode: 'upload_failed',
|
|
59
61
|
}));
|
|
60
62
|
});
|
|
61
63
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataparade/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "dataPARADE CLI — scan codebases for privacy and security data flows",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"eval:models": "pnpm exec node dist/src/evals/run-model-matrix.js"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
+
"@clack/prompts": "^1.8.1",
|
|
57
58
|
"@dataparade/scanner": "github:DataParade-io/scanner#e66e1bcaef55b61214d170c617df529bd300fc89",
|
|
58
59
|
"@sentry/node": "^10.38.0",
|
|
59
60
|
"commander": "^12.1.0",
|