@dataparade/cli 0.0.19 → 0.0.21
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/providers/platform-proxy-provider.d.ts +4 -1
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +44 -18
- package/dist/src/cli.js +100 -52
- 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/platform-api/fetch-failure.d.ts +11 -0
- package/dist/src/platform-api/fetch-failure.js +85 -0
- 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/platform-proxy-provider.spec.js +118 -47
- 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/platform-api/fetch-failure.spec.d.ts +1 -0
- package/dist/tests/unit/platform-api/fetch-failure.spec.js +16 -0
- 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
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildTeachingLineGroups = buildTeachingLineGroups;
|
|
4
|
+
exports.flattenTeachingLines = flattenTeachingLines;
|
|
5
|
+
function asString(value) {
|
|
6
|
+
if (typeof value !== 'string')
|
|
7
|
+
return undefined;
|
|
8
|
+
const trimmed = value.trim();
|
|
9
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
10
|
+
}
|
|
11
|
+
function titleCaseToken(token) {
|
|
12
|
+
if (!token)
|
|
13
|
+
return token;
|
|
14
|
+
if (token === token.toUpperCase() && token.length <= 4)
|
|
15
|
+
return token;
|
|
16
|
+
return token.charAt(0).toUpperCase() + token.slice(1);
|
|
17
|
+
}
|
|
18
|
+
function prettyFramework(framework) {
|
|
19
|
+
const lower = framework.toLowerCase();
|
|
20
|
+
if (lower === 'express')
|
|
21
|
+
return 'Express';
|
|
22
|
+
if (lower === 'nest')
|
|
23
|
+
return 'Nest';
|
|
24
|
+
if (lower === 'next_or_react_route')
|
|
25
|
+
return 'Next.js';
|
|
26
|
+
if (lower === 'fastapi')
|
|
27
|
+
return 'FastAPI';
|
|
28
|
+
if (lower === 'flask')
|
|
29
|
+
return 'Flask';
|
|
30
|
+
if (lower === 'django')
|
|
31
|
+
return 'Django';
|
|
32
|
+
return titleCaseToken(framework.replace(/_/g, ' '));
|
|
33
|
+
}
|
|
34
|
+
function prettyClient(client) {
|
|
35
|
+
const lower = client.toLowerCase();
|
|
36
|
+
if (lower === 'typeorm')
|
|
37
|
+
return 'TypeORM';
|
|
38
|
+
if (lower === 'prisma')
|
|
39
|
+
return 'Prisma';
|
|
40
|
+
if (lower === 'mongoose')
|
|
41
|
+
return 'Mongoose';
|
|
42
|
+
if (lower === 'psycopg2' || lower === 'psycopg')
|
|
43
|
+
return 'psycopg';
|
|
44
|
+
if (lower === 'pg')
|
|
45
|
+
return 'pg';
|
|
46
|
+
if (lower === 'knex')
|
|
47
|
+
return 'Knex';
|
|
48
|
+
return titleCaseToken(client);
|
|
49
|
+
}
|
|
50
|
+
function prettyDatabaseType(databaseType) {
|
|
51
|
+
const lower = databaseType.toLowerCase();
|
|
52
|
+
if (lower === 'postgres' || lower === 'postgresql')
|
|
53
|
+
return 'Postgres';
|
|
54
|
+
if (lower === 'mysql')
|
|
55
|
+
return 'MySQL';
|
|
56
|
+
if (lower === 'mongodb' || lower === 'mongo')
|
|
57
|
+
return 'MongoDB';
|
|
58
|
+
if (lower === 'sqlite')
|
|
59
|
+
return 'SQLite';
|
|
60
|
+
if (lower === 'redis')
|
|
61
|
+
return 'Redis';
|
|
62
|
+
if (lower === 'sql')
|
|
63
|
+
return 'SQL';
|
|
64
|
+
return titleCaseToken(databaseType);
|
|
65
|
+
}
|
|
66
|
+
function prettyVendor(serviceName) {
|
|
67
|
+
const lower = serviceName.toLowerCase();
|
|
68
|
+
const known = {
|
|
69
|
+
stripe: 'Stripe',
|
|
70
|
+
sendgrid: 'Sendgrid',
|
|
71
|
+
sentry: 'Sentry',
|
|
72
|
+
openai: 'OpenAI',
|
|
73
|
+
aws: 'AWS',
|
|
74
|
+
auth0: 'Auth0',
|
|
75
|
+
};
|
|
76
|
+
if (known[lower])
|
|
77
|
+
return known[lower];
|
|
78
|
+
return titleCaseToken(serviceName);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build teaching lines from deterministic findings/components.
|
|
82
|
+
* Empty groups are omitted by the renderer.
|
|
83
|
+
*/
|
|
84
|
+
function buildTeachingLineGroups(findings, components) {
|
|
85
|
+
const routeCounts = new Map();
|
|
86
|
+
for (const finding of findings) {
|
|
87
|
+
if (finding.pattern !== 'express_route')
|
|
88
|
+
continue;
|
|
89
|
+
const framework = asString(finding.properties?.framework) ?? 'framework';
|
|
90
|
+
routeCounts.set(framework, (routeCounts.get(framework) ?? 0) + 1);
|
|
91
|
+
}
|
|
92
|
+
const routes = [...routeCounts.entries()]
|
|
93
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
94
|
+
.map(([framework, count]) => {
|
|
95
|
+
const name = prettyFramework(framework);
|
|
96
|
+
return count === 1
|
|
97
|
+
? `Found 1 ${name} route`
|
|
98
|
+
: `Found ${count} ${name} routes`;
|
|
99
|
+
});
|
|
100
|
+
const storeKeys = new Set();
|
|
101
|
+
const stores = [];
|
|
102
|
+
for (const finding of findings) {
|
|
103
|
+
if (finding.pattern !== 'database_connection')
|
|
104
|
+
continue;
|
|
105
|
+
const client = asString(finding.properties?.client) ?? 'database';
|
|
106
|
+
const databaseType = asString(finding.properties?.databaseType) ?? 'SQL';
|
|
107
|
+
const key = `${client}|${databaseType}`;
|
|
108
|
+
if (storeKeys.has(key))
|
|
109
|
+
continue;
|
|
110
|
+
storeKeys.add(key);
|
|
111
|
+
stores.push(`Talks to ${prettyDatabaseType(databaseType)} (${prettyClient(client)})`);
|
|
112
|
+
}
|
|
113
|
+
const vendorNames = new Set();
|
|
114
|
+
for (const component of components) {
|
|
115
|
+
if (component.type !== 'third_party')
|
|
116
|
+
continue;
|
|
117
|
+
const serviceName = asString(component.properties?.serviceName);
|
|
118
|
+
if (serviceName)
|
|
119
|
+
vendorNames.add(serviceName.toLowerCase());
|
|
120
|
+
}
|
|
121
|
+
for (const finding of findings) {
|
|
122
|
+
if (finding.pattern !== 'external_api_call')
|
|
123
|
+
continue;
|
|
124
|
+
const serviceName = asString(finding.properties?.serviceName);
|
|
125
|
+
if (serviceName)
|
|
126
|
+
vendorNames.add(serviceName.toLowerCase());
|
|
127
|
+
}
|
|
128
|
+
const outboundSorted = [...vendorNames].sort((a, b) => a.localeCompare(b));
|
|
129
|
+
const outboundLabels = outboundSorted.map(prettyVendor);
|
|
130
|
+
const outbound = outboundLabels.length === 0
|
|
131
|
+
? []
|
|
132
|
+
: outboundLabels.length === 1
|
|
133
|
+
? [`Calls out to ${outboundLabels[0]}`]
|
|
134
|
+
: outboundLabels.length === 2
|
|
135
|
+
? [`Calls out to ${outboundLabels[0]} and ${outboundLabels[1]}`]
|
|
136
|
+
: [
|
|
137
|
+
`Calls out to ${outboundLabels.slice(0, -1).join(', ')}, and ${outboundLabels[outboundLabels.length - 1]}`,
|
|
138
|
+
];
|
|
139
|
+
return { routes, stores, outbound };
|
|
140
|
+
}
|
|
141
|
+
/** Flatten groups into display strings (without the leading bullet). */
|
|
142
|
+
function flattenTeachingLines(groups) {
|
|
143
|
+
return [...groups.routes, ...groups.stores, ...groups.outbound];
|
|
144
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DetectedComponent, RawFinding } from '../core/types';
|
|
2
|
+
export type ScanUiStepId = 'scanning_files' | 'analyzing' | 'detecting_frameworks' | 'mapping_data_stores' | 'finding_outbound' | 'ai_enrichment';
|
|
3
|
+
/** What the AI step changed, for its one-line result. */
|
|
4
|
+
export interface ScanAiStepResult {
|
|
5
|
+
proposalsApplied: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ScanRecognitionPayload {
|
|
8
|
+
findings: RawFinding[];
|
|
9
|
+
components: DetectedComponent[];
|
|
10
|
+
}
|
|
11
|
+
export interface ScanProgressRendererOptions {
|
|
12
|
+
/** When false, plain logs only (no Clack spinner / intro chrome). */
|
|
13
|
+
isTTY: boolean;
|
|
14
|
+
/** When true, never emit ANSI escape codes. */
|
|
15
|
+
noColor: boolean;
|
|
16
|
+
/** CLI version shown in the brand header. */
|
|
17
|
+
version?: string;
|
|
18
|
+
/** Terminal width (defaults to process.stdout.columns). */
|
|
19
|
+
columns?: number;
|
|
20
|
+
/** Terminal color depth in bits (defaults to process.stdout.getColorDepth()). */
|
|
21
|
+
colorDepth?: number;
|
|
22
|
+
/** Short path/name shown under the brand header. */
|
|
23
|
+
projectLabel?: string;
|
|
24
|
+
/** Override stdout writes (tests). Defaults to console.log. */
|
|
25
|
+
writeLine?: (line: string) => void;
|
|
26
|
+
/** Injected Clack module. Tests pass a mock; production loads the ESM package. */
|
|
27
|
+
prompts?: typeof import('@clack/prompts');
|
|
28
|
+
}
|
|
29
|
+
export interface TeachingLineGroups {
|
|
30
|
+
routes: string[];
|
|
31
|
+
stores: string[];
|
|
32
|
+
outbound: string[];
|
|
33
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RunDataflowUploadInput, RunDataflowUploadResult } from
|
|
1
|
+
import type { RunDataflowUploadInput, RunDataflowUploadResult } from './types';
|
|
2
2
|
export declare function runDataflowUpload(input: RunDataflowUploadInput): Promise<RunDataflowUploadResult>;
|
|
@@ -5,8 +5,8 @@ const upload_client_1 = require("../platform-api/upload-client");
|
|
|
5
5
|
const telemetry_client_1 = require("../platform-api/telemetry-client");
|
|
6
6
|
const build_preview_url_1 = require("./build-preview-url");
|
|
7
7
|
async function runDataflowUpload(input) {
|
|
8
|
-
const prefix = input.logPrefix ??
|
|
9
|
-
const command = input.command ??
|
|
8
|
+
const prefix = input.logPrefix ?? '[upload]';
|
|
9
|
+
const command = input.command ?? 'scan';
|
|
10
10
|
const sessionId = input.cliUsageSessionId?.trim();
|
|
11
11
|
const apiKey = input.apiKey?.trim();
|
|
12
12
|
try {
|
|
@@ -20,12 +20,14 @@ async function runDataflowUpload(input) {
|
|
|
20
20
|
command,
|
|
21
21
|
});
|
|
22
22
|
const previewUrl = (0, build_preview_url_1.buildImportPreviewUrl)(result.draftId, sessionId);
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (!input.quiet) {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.log(`${prefix} Preview ready: ${previewUrl}`);
|
|
26
|
+
}
|
|
25
27
|
if (sessionId) {
|
|
26
28
|
await (0, telemetry_client_1.reportCliUsageEvent)({
|
|
27
29
|
sessionId,
|
|
28
|
-
event:
|
|
30
|
+
event: 'upload_succeeded',
|
|
29
31
|
command,
|
|
30
32
|
hasApiKey: true,
|
|
31
33
|
apiKey,
|
|
@@ -42,33 +44,36 @@ async function runDataflowUpload(input) {
|
|
|
42
44
|
command,
|
|
43
45
|
});
|
|
44
46
|
const previewUrl = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)(result.claimToken, sessionId);
|
|
45
|
-
|
|
46
|
-
console.log(`${prefix} Preview ready: ${previewUrl}`);
|
|
47
|
-
// eslint-disable-next-line no-console
|
|
48
|
-
console.log(`${prefix} Claiming this preview after signup uses 1 scan slot` +
|
|
47
|
+
const notice = 'You can view the diagram now. Claiming it to your account uses 1 scan slot' +
|
|
49
48
|
(input.scanJobId
|
|
50
|
-
?
|
|
51
|
-
:
|
|
49
|
+
? ' and any platform AI tokens used during the scan.'
|
|
50
|
+
: '.');
|
|
51
|
+
if (!input.quiet) {
|
|
52
|
+
// eslint-disable-next-line no-console
|
|
53
|
+
console.log(`${prefix} Preview ready: ${previewUrl}`);
|
|
54
|
+
// eslint-disable-next-line no-console
|
|
55
|
+
console.log(`${prefix} ${notice}`);
|
|
56
|
+
}
|
|
52
57
|
if (sessionId) {
|
|
53
58
|
await (0, telemetry_client_1.reportCliUsageEvent)({
|
|
54
59
|
sessionId,
|
|
55
|
-
event:
|
|
60
|
+
event: 'upload_succeeded',
|
|
56
61
|
command,
|
|
57
62
|
hasApiKey: false,
|
|
58
63
|
});
|
|
59
64
|
}
|
|
60
|
-
return { previewUrl };
|
|
65
|
+
return { previewUrl, notice };
|
|
61
66
|
}
|
|
62
67
|
catch (error) {
|
|
63
68
|
if (sessionId) {
|
|
64
|
-
const message = error instanceof Error ? error.message :
|
|
69
|
+
const message = error instanceof Error ? error.message : 'Upload failed.';
|
|
65
70
|
await (0, telemetry_client_1.reportCliUsageEvent)({
|
|
66
71
|
sessionId,
|
|
67
|
-
event:
|
|
72
|
+
event: 'upload_failed',
|
|
68
73
|
command,
|
|
69
74
|
hasApiKey: Boolean(apiKey),
|
|
70
75
|
apiKey,
|
|
71
|
-
errorCode:
|
|
76
|
+
errorCode: 'upload_failed',
|
|
72
77
|
errorMessage: message,
|
|
73
78
|
});
|
|
74
79
|
}
|
|
@@ -6,8 +6,12 @@ export type RunDataflowUploadInput = {
|
|
|
6
6
|
logPrefix?: string;
|
|
7
7
|
cliUsageSessionId?: string;
|
|
8
8
|
command?: "scan" | "upload";
|
|
9
|
+
/** Skip the `[prefix] Preview ready` lines (TTY scan renders its own block). */
|
|
10
|
+
quiet?: boolean;
|
|
9
11
|
};
|
|
10
12
|
export type RunDataflowUploadResult = {
|
|
11
13
|
draftId?: string;
|
|
12
14
|
previewUrl: string;
|
|
15
|
+
/** Extra human hint shown with the preview (anonymous claim cost). */
|
|
16
|
+
notice?: string;
|
|
13
17
|
};
|
|
@@ -6,96 +6,133 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const child_process_1 = require("child_process");
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const cliDistPath = path_1.default.join(__dirname,
|
|
10
|
-
const cliCwd = path_1.default.join(__dirname,
|
|
11
|
-
const scanFixturePath = path_1.default.join(cliCwd,
|
|
12
|
-
describe(
|
|
9
|
+
const cliDistPath = path_1.default.join(__dirname, '../../dist/bin/cli.js');
|
|
10
|
+
const cliCwd = path_1.default.join(__dirname, '../../');
|
|
11
|
+
const scanFixturePath = path_1.default.join(cliCwd, 'tests/fixtures/typescript-basic');
|
|
12
|
+
describe('CLI', () => {
|
|
13
13
|
beforeAll(() => {
|
|
14
14
|
if (!(0, fs_1.existsSync)(cliDistPath)) {
|
|
15
15
|
throw new Error(`CLI not built. Run 'pnpm build' first. Expected: ${cliDistPath}`);
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
it(
|
|
19
|
-
const result = (0, child_process_1.spawnSync)(
|
|
18
|
+
it('scan <path> writes a dataflow.json wrapper to the current directory and exits 0', () => {
|
|
19
|
+
const result = (0, child_process_1.spawnSync)('node', [
|
|
20
20
|
cliDistPath,
|
|
21
|
-
|
|
21
|
+
'scan',
|
|
22
22
|
scanFixturePath,
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
'--no-ai-inference',
|
|
24
|
+
'--skip-auto-upload',
|
|
25
25
|
], {
|
|
26
|
-
encoding:
|
|
26
|
+
encoding: 'utf-8',
|
|
27
27
|
cwd: cliCwd,
|
|
28
28
|
});
|
|
29
29
|
expect(result.status).toBe(0);
|
|
30
|
-
const outputPath = path_1.default.join(cliCwd,
|
|
30
|
+
const outputPath = path_1.default.join(cliCwd, 'dataflow.json');
|
|
31
31
|
const exists = (0, fs_1.existsSync)(outputPath);
|
|
32
32
|
expect(exists).toBe(true);
|
|
33
|
-
const contents = (0, fs_1.readFileSync)(outputPath,
|
|
33
|
+
const contents = (0, fs_1.readFileSync)(outputPath, 'utf8').trim();
|
|
34
34
|
const dataflow = JSON.parse(contents);
|
|
35
35
|
expect(dataflow.schemaVersion).toBeDefined();
|
|
36
36
|
expect(dataflow.graph).toBeDefined();
|
|
37
37
|
expect(Array.isArray(dataflow.graph.nodes)).toBe(true);
|
|
38
38
|
expect(Array.isArray(dataflow.graph.edges)).toBe(true);
|
|
39
39
|
});
|
|
40
|
-
it(
|
|
41
|
-
const result = (0, child_process_1.spawnSync)(
|
|
40
|
+
it('scan fixture produces a dataflow.json wrapper with at least one node', () => {
|
|
41
|
+
const result = (0, child_process_1.spawnSync)('node', [
|
|
42
42
|
cliDistPath,
|
|
43
|
-
|
|
43
|
+
'scan',
|
|
44
44
|
scanFixturePath,
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
'--no-ai-inference',
|
|
46
|
+
'--skip-auto-upload',
|
|
47
47
|
], {
|
|
48
|
-
encoding:
|
|
48
|
+
encoding: 'utf-8',
|
|
49
49
|
cwd: cliCwd,
|
|
50
50
|
});
|
|
51
51
|
expect(result.status).toBe(0);
|
|
52
|
-
const outputPath = path_1.default.join(cliCwd,
|
|
53
|
-
const contents = (0, fs_1.readFileSync)(outputPath,
|
|
52
|
+
const outputPath = path_1.default.join(cliCwd, 'dataflow.json');
|
|
53
|
+
const contents = (0, fs_1.readFileSync)(outputPath, 'utf8').trim();
|
|
54
54
|
const dataflow = JSON.parse(contents);
|
|
55
55
|
expect(Array.isArray(dataflow.graph.nodes)).toBe(true);
|
|
56
56
|
expect(dataflow.graph.nodes.length).toBeGreaterThan(0);
|
|
57
57
|
});
|
|
58
|
-
it(
|
|
59
|
-
const outputFile =
|
|
60
|
-
const result = (0, child_process_1.spawnSync)(
|
|
58
|
+
it('scan fixture --output writes a dataflow.json wrapper to the given file and prints a short message', () => {
|
|
59
|
+
const outputFile = 'scan-fixture-summary.json';
|
|
60
|
+
const result = (0, child_process_1.spawnSync)('node', [
|
|
61
61
|
cliDistPath,
|
|
62
|
-
|
|
62
|
+
'scan',
|
|
63
63
|
scanFixturePath,
|
|
64
|
-
|
|
64
|
+
'--output',
|
|
65
65
|
outputFile,
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
'--no-ai-inference',
|
|
67
|
+
'--skip-auto-upload',
|
|
68
68
|
], {
|
|
69
|
-
encoding:
|
|
69
|
+
encoding: 'utf-8',
|
|
70
70
|
cwd: cliCwd,
|
|
71
71
|
});
|
|
72
72
|
expect(result.status).toBe(0);
|
|
73
73
|
expect(result.stdout).toContain(`[scan] dataflow.json written to ${path_1.default.join(cliCwd, outputFile)}`);
|
|
74
|
-
const fileContents = (0, fs_1.readFileSync)(path_1.default.join(cliCwd, outputFile),
|
|
74
|
+
const fileContents = (0, fs_1.readFileSync)(path_1.default.join(cliCwd, outputFile), 'utf8').trim();
|
|
75
75
|
const dataflow = JSON.parse(fileContents);
|
|
76
76
|
expect(dataflow.graph).toBeDefined();
|
|
77
77
|
expect(Array.isArray(dataflow.graph.nodes)).toBe(true);
|
|
78
78
|
});
|
|
79
|
-
it(
|
|
80
|
-
const
|
|
81
|
-
|
|
79
|
+
it('scan mixed-language fixture prints teaching lines before dataflow.json written', () => {
|
|
80
|
+
const teachingFixture = path_1.default.join(cliCwd, 'tests/fixtures/mixed-language-basic');
|
|
81
|
+
const outputFile = 'scan-teaching-progress.json';
|
|
82
|
+
const result = (0, child_process_1.spawnSync)('node', [
|
|
83
|
+
cliDistPath,
|
|
84
|
+
'scan',
|
|
85
|
+
teachingFixture,
|
|
86
|
+
'--output',
|
|
87
|
+
outputFile,
|
|
88
|
+
'--no-ai-inference',
|
|
89
|
+
'--skip-auto-upload',
|
|
90
|
+
], {
|
|
91
|
+
encoding: 'utf-8',
|
|
92
|
+
cwd: cliCwd,
|
|
93
|
+
env: {
|
|
94
|
+
...process.env,
|
|
95
|
+
// Force plain progress (no spinner/ANSI) for stable assertions.
|
|
96
|
+
NO_COLOR: '1',
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
expect(result.status).toBe(0);
|
|
100
|
+
const writtenMarker = `[scan] dataflow.json written to ${path_1.default.join(cliCwd, outputFile)}`;
|
|
101
|
+
expect(result.stdout).toContain(writtenMarker);
|
|
102
|
+
const beforeWrite = result.stdout.split(writtenMarker)[0] ?? '';
|
|
103
|
+
expect(beforeWrite).toMatch(/Map privacy data flows from your code/);
|
|
104
|
+
const teachingHits = [
|
|
105
|
+
/Found \d+ .+ routes?/i,
|
|
106
|
+
/Talks to /i,
|
|
107
|
+
/Calls out to /i,
|
|
108
|
+
/Stripe|OpenAI|Sentry|Postgres|Express|FastAPI/i,
|
|
109
|
+
].filter((re) => re.test(beforeWrite));
|
|
110
|
+
expect(teachingHits.length).toBeGreaterThanOrEqual(2);
|
|
111
|
+
// Non-TTY / NO_COLOR: no ANSI escape codes and no braille spinner frames.
|
|
112
|
+
// eslint-disable-next-line no-control-regex -- asserting absence of ESC CSI sequences
|
|
113
|
+
expect(result.stdout).not.toMatch(/\x1b\[[0-9;]*m/);
|
|
114
|
+
expect(result.stdout).not.toMatch(/[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]/);
|
|
115
|
+
});
|
|
116
|
+
it('unknown command shows usage and exits non-zero', () => {
|
|
117
|
+
const result = (0, child_process_1.spawnSync)('node', [cliDistPath, 'unknowncommand'], {
|
|
118
|
+
encoding: 'utf-8',
|
|
82
119
|
cwd: cliCwd,
|
|
83
120
|
});
|
|
84
121
|
expect(result.status).not.toBe(0);
|
|
85
122
|
expect(result.stderr).toMatch(/Unknown command|error|usage|Usage/i);
|
|
86
123
|
});
|
|
87
|
-
it(
|
|
88
|
-
const result = (0, child_process_1.spawnSync)(
|
|
89
|
-
encoding:
|
|
124
|
+
it('--help shows usage', () => {
|
|
125
|
+
const result = (0, child_process_1.spawnSync)('node', [cliDistPath, '--help'], {
|
|
126
|
+
encoding: 'utf-8',
|
|
90
127
|
cwd: cliCwd,
|
|
91
128
|
});
|
|
92
129
|
expect(result.status).toBe(0);
|
|
93
|
-
expect(result.stdout).toContain(
|
|
94
|
-
expect(result.stdout).toContain(
|
|
130
|
+
expect(result.stdout).toContain('dataparade');
|
|
131
|
+
expect(result.stdout).toContain('scan');
|
|
95
132
|
});
|
|
96
|
-
it(
|
|
97
|
-
const result = (0, child_process_1.spawnSync)(
|
|
98
|
-
encoding:
|
|
133
|
+
it('scan --help shows scan usage', () => {
|
|
134
|
+
const result = (0, child_process_1.spawnSync)('node', [cliDistPath, 'scan', '--help'], {
|
|
135
|
+
encoding: 'utf-8',
|
|
99
136
|
cwd: cliCwd,
|
|
100
137
|
});
|
|
101
138
|
expect(result.status).toBe(0);
|