@dataparade/cli 0.0.14 → 0.0.15
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/dist/package.json +1 -1
- package/dist/src/cli.js +84 -8
- package/dist/src/core/schema/dataflow-wrapper.schema.d.ts +33 -1
- package/dist/src/core/schema/dataflow-wrapper.schema.js +19 -3
- package/dist/src/output/json.d.ts +8 -1
- package/dist/src/output/json.js +5 -1
- package/dist/src/platform-api/cli-scan-failure-report.d.ts +9 -0
- package/dist/src/platform-api/cli-scan-failure-report.js +23 -0
- package/dist/tests/schema/dataflow-wrapper.schema.spec.js +142 -21
- package/dist/tests/unit/cli/scan-quota-flow.spec.js +53 -49
- package/dist/tests/unit/platform-api/cli-scan-failure-report.spec.d.ts +1 -0
- package/dist/tests/unit/platform-api/cli-scan-failure-report.spec.js +25 -0
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/src/cli.js
CHANGED
|
@@ -43,6 +43,7 @@ const commander_1 = require("commander");
|
|
|
43
43
|
const crypto_1 = require("crypto");
|
|
44
44
|
const package_json_1 = __importDefault(require("../package.json"));
|
|
45
45
|
const json_1 = require("./output/json");
|
|
46
|
+
const dataflow_wrapper_schema_1 = require("./core/schema/dataflow-wrapper.schema");
|
|
46
47
|
const upload_env_1 = require("./config/upload-env");
|
|
47
48
|
const types_1 = require("./ai-enrichment/types");
|
|
48
49
|
const inference_scope_1 = require("./config/inference-scope");
|
|
@@ -52,6 +53,7 @@ const scan_env_1 = require("./config/scan-env");
|
|
|
52
53
|
const validate_scan_ai_1 = require("./config/validate-scan-ai");
|
|
53
54
|
const scan_sentry_1 = require("./observability/scan-sentry");
|
|
54
55
|
const telemetry_client_1 = require("./platform-api/telemetry-client");
|
|
56
|
+
const cli_scan_failure_report_1 = require("./platform-api/cli-scan-failure-report");
|
|
55
57
|
const scan_config_schema_1 = require("./core/schema/scan-config.schema");
|
|
56
58
|
const scanner_1 = require("@dataparade/scanner");
|
|
57
59
|
function formatEvidence(detail) {
|
|
@@ -155,15 +157,42 @@ function createProgram() {
|
|
|
155
157
|
.option('--byok-provider <provider>', `BYOK LLM provider when using your own API key: ${types_1.AI_PROVIDER_IDS.join('|')}`)
|
|
156
158
|
.option('--byok-model <model>', 'BYOK model name (env: SCAN_BYOK_MODEL)')
|
|
157
159
|
.option('--skip-auto-upload', 'Do not upload dataflow.json to the dashboard after scan (env: DATAPARADE_SKIP_AUTO_UPLOAD)')
|
|
160
|
+
.option('--git-context <json>', 'Git repository context for evidence linking (JSON: {"provider":"github"|"gitlab","repository":"owner/repo","commitSha":"...","baseUrl?":"..."})')
|
|
158
161
|
.action(async (path, options) => {
|
|
159
162
|
let cliQuotaJobId;
|
|
160
163
|
let platformQuotaApiKey;
|
|
161
164
|
let quotaCompletionReported = false;
|
|
162
165
|
let fallbackFailureMessage = 'CLI scan did not complete successfully';
|
|
166
|
+
let reportedFailure;
|
|
163
167
|
let sentryScanRoot;
|
|
164
168
|
let sentryAiMode;
|
|
165
169
|
let sentryAiProvider;
|
|
166
170
|
const isInteractive = process.stdout.isTTY;
|
|
171
|
+
// Parse and validate --git-context if provided
|
|
172
|
+
let parsedGitContext;
|
|
173
|
+
if (options.gitContext) {
|
|
174
|
+
try {
|
|
175
|
+
const rawJson = JSON.parse(options.gitContext);
|
|
176
|
+
const validated = dataflow_wrapper_schema_1.gitContextSchema.safeParse(rawJson);
|
|
177
|
+
if (!validated.success) {
|
|
178
|
+
const errors = validated.error.issues
|
|
179
|
+
.map((i) => `${i.path.join('.') || '<root>'}: ${i.message}`)
|
|
180
|
+
.join('; ');
|
|
181
|
+
// eslint-disable-next-line no-console
|
|
182
|
+
console.error(`[scan] invalid --git-context: ${errors}`);
|
|
183
|
+
process.exitCode = 2;
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
parsedGitContext = validated.data;
|
|
187
|
+
}
|
|
188
|
+
catch (parseErr) {
|
|
189
|
+
const message = parseErr instanceof Error ? parseErr.message : 'Invalid JSON';
|
|
190
|
+
// eslint-disable-next-line no-console
|
|
191
|
+
console.error(`[scan] failed to parse --git-context: ${message}`);
|
|
192
|
+
process.exitCode = 2;
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
167
196
|
const workspaceApiKey = options.workspaceApiKey?.trim() ||
|
|
168
197
|
options.apiKey?.trim() ||
|
|
169
198
|
(0, scan_env_1.resolveWorkspaceApiKey)(process.env);
|
|
@@ -189,6 +218,10 @@ function createProgram() {
|
|
|
189
218
|
catch (err) {
|
|
190
219
|
const message = err instanceof Error ? err.message : 'Path does not exist.';
|
|
191
220
|
sentryScanRoot = resolvedScanRoot;
|
|
221
|
+
reportedFailure = {
|
|
222
|
+
code: 'path_not_found',
|
|
223
|
+
message: (0, cli_scan_failure_report_1.truncateFailureMessage)(message),
|
|
224
|
+
};
|
|
192
225
|
await (0, scan_sentry_1.reportScanCliError)({
|
|
193
226
|
error: err,
|
|
194
227
|
scanRoot: sentryScanRoot,
|
|
@@ -299,7 +332,7 @@ function createProgram() {
|
|
|
299
332
|
}
|
|
300
333
|
else if (!workspaceApiKey &&
|
|
301
334
|
!usesByok &&
|
|
302
|
-
aiMode !==
|
|
335
|
+
aiMode !== 'hosted_worker' &&
|
|
303
336
|
config.enableAiInference) {
|
|
304
337
|
try {
|
|
305
338
|
const { cliAnonymousAiSession } = await Promise.resolve().then(() => __importStar(require('./platform-api/anonymous-ai-session-client')));
|
|
@@ -327,6 +360,10 @@ function createProgram() {
|
|
|
327
360
|
const message = anonSessionError instanceof Error
|
|
328
361
|
? anonSessionError.message
|
|
329
362
|
: 'Anonymous AI session failed.';
|
|
363
|
+
reportedFailure = {
|
|
364
|
+
code: 'anonymous_ai_session_failed',
|
|
365
|
+
message: (0, cli_scan_failure_report_1.truncateFailureMessage)(message),
|
|
366
|
+
};
|
|
330
367
|
// eslint-disable-next-line no-console
|
|
331
368
|
console.error(`[scan] ${message}`);
|
|
332
369
|
process.exitCode =
|
|
@@ -336,6 +373,10 @@ function createProgram() {
|
|
|
336
373
|
}
|
|
337
374
|
const configValidation = (0, scan_config_schema_1.validateScanConfiguration)(config);
|
|
338
375
|
if (!configValidation.ok) {
|
|
376
|
+
reportedFailure = {
|
|
377
|
+
code: 'invalid_configuration',
|
|
378
|
+
message: (0, cli_scan_failure_report_1.truncateFailureMessage)(configValidation.errors.join('; ')),
|
|
379
|
+
};
|
|
339
380
|
await (0, scan_sentry_1.reportScanCliError)({
|
|
340
381
|
error: configValidation.errors.join('\n'),
|
|
341
382
|
scanRoot: sentryScanRoot,
|
|
@@ -399,6 +440,10 @@ function createProgram() {
|
|
|
399
440
|
}
|
|
400
441
|
}
|
|
401
442
|
if (scanResult.errors?.length) {
|
|
443
|
+
reportedFailure = {
|
|
444
|
+
code: 'scan_errors',
|
|
445
|
+
message: (0, cli_scan_failure_report_1.summarizeScanErrors)(scanResult.errors),
|
|
446
|
+
};
|
|
402
447
|
await (0, scan_sentry_1.reportScanCliError)({
|
|
403
448
|
error: scanResult.errors.join('\n'),
|
|
404
449
|
scanRoot: sentryScanRoot,
|
|
@@ -416,6 +461,12 @@ function createProgram() {
|
|
|
416
461
|
diagramGraph = buildDiagramGraphFromScanResult(scanResult);
|
|
417
462
|
}
|
|
418
463
|
catch (graphError) {
|
|
464
|
+
reportedFailure = {
|
|
465
|
+
code: 'graph_build_failed',
|
|
466
|
+
message: (0, cli_scan_failure_report_1.truncateFailureMessage)(graphError instanceof Error
|
|
467
|
+
? graphError.message
|
|
468
|
+
: 'Unknown error while building diagram graph.'),
|
|
469
|
+
};
|
|
419
470
|
await (0, scan_sentry_1.reportScanCliError)({
|
|
420
471
|
error: graphError,
|
|
421
472
|
scanRoot: sentryScanRoot,
|
|
@@ -445,6 +496,7 @@ function createProgram() {
|
|
|
445
496
|
outputPath: dataflowOutputPath,
|
|
446
497
|
projectName: resolvedProjectName,
|
|
447
498
|
redFlags,
|
|
499
|
+
gitContext: parsedGitContext,
|
|
448
500
|
});
|
|
449
501
|
// Always print a short message so non-interactive callers and
|
|
450
502
|
// tests can rely on it.
|
|
@@ -455,7 +507,11 @@ function createProgram() {
|
|
|
455
507
|
if (!skipAutoUpload) {
|
|
456
508
|
try {
|
|
457
509
|
const { runDataflowUpload } = await Promise.resolve().then(() => __importStar(require('./upload/run-upload')));
|
|
458
|
-
const dataflowWrapper = (0, json_1.buildDataflowWrapper)(scanResult, diagramGraph, {
|
|
510
|
+
const dataflowWrapper = (0, json_1.buildDataflowWrapper)(scanResult, diagramGraph, {
|
|
511
|
+
projectName: resolvedProjectName,
|
|
512
|
+
redFlags,
|
|
513
|
+
gitContext: parsedGitContext,
|
|
514
|
+
});
|
|
459
515
|
await runDataflowUpload({
|
|
460
516
|
apiKey: workspaceApiKey,
|
|
461
517
|
dataflow: dataflowWrapper,
|
|
@@ -476,6 +532,12 @@ function createProgram() {
|
|
|
476
532
|
}
|
|
477
533
|
}
|
|
478
534
|
catch (dataflowError) {
|
|
535
|
+
reportedFailure = {
|
|
536
|
+
code: 'dataflow_write_failed',
|
|
537
|
+
message: (0, cli_scan_failure_report_1.truncateFailureMessage)(dataflowError instanceof Error
|
|
538
|
+
? dataflowError.message
|
|
539
|
+
: 'Unknown error while writing dataflow.json.'),
|
|
540
|
+
};
|
|
479
541
|
await (0, scan_sentry_1.reportScanCliError)({
|
|
480
542
|
error: dataflowError,
|
|
481
543
|
scanRoot: sentryScanRoot,
|
|
@@ -504,9 +566,11 @@ function createProgram() {
|
|
|
504
566
|
aiTokensUsed: platformAiMode
|
|
505
567
|
? 0
|
|
506
568
|
: (scanResult.aiInferenceSummary?.totalTokens ?? 0),
|
|
507
|
-
failureCode: exitFailed
|
|
569
|
+
failureCode: exitFailed
|
|
570
|
+
? (reportedFailure?.code ?? 'scan_failed')
|
|
571
|
+
: undefined,
|
|
508
572
|
failureMessage: exitFailed
|
|
509
|
-
?
|
|
573
|
+
? (reportedFailure?.message ?? fallbackFailureMessage)
|
|
510
574
|
: undefined,
|
|
511
575
|
});
|
|
512
576
|
quotaCompletionReported = true;
|
|
@@ -522,6 +586,14 @@ function createProgram() {
|
|
|
522
586
|
const { CliScanQuotaExceededError, CliScanAlreadyRunningError } = await Promise.resolve().then(() => __importStar(require('./platform-api/scan-quota-client')));
|
|
523
587
|
const quotaBlocked = err instanceof CliScanQuotaExceededError;
|
|
524
588
|
const scanInProgress = err instanceof CliScanAlreadyRunningError;
|
|
589
|
+
reportedFailure = {
|
|
590
|
+
code: quotaBlocked
|
|
591
|
+
? 'scan_quota_exceeded'
|
|
592
|
+
: scanInProgress
|
|
593
|
+
? 'scan_already_running'
|
|
594
|
+
: 'scan_exception',
|
|
595
|
+
message: (0, cli_scan_failure_report_1.truncateFailureMessage)(message),
|
|
596
|
+
};
|
|
525
597
|
await (0, scan_sentry_1.reportScanCliError)({
|
|
526
598
|
error: err,
|
|
527
599
|
scanRoot: sentryScanRoot,
|
|
@@ -552,8 +624,12 @@ function createProgram() {
|
|
|
552
624
|
hasApiKey: Boolean(workspaceApiKey),
|
|
553
625
|
apiKey: workspaceApiKey,
|
|
554
626
|
cliVersion: package_json_1.default.version,
|
|
555
|
-
errorCode: scanFailed
|
|
556
|
-
|
|
627
|
+
errorCode: scanFailed
|
|
628
|
+
? (reportedFailure?.code ?? 'scan_failed')
|
|
629
|
+
: undefined,
|
|
630
|
+
errorMessage: scanFailed
|
|
631
|
+
? (reportedFailure?.message ?? fallbackFailureMessage)
|
|
632
|
+
: undefined,
|
|
557
633
|
});
|
|
558
634
|
if (platformQuotaApiKey &&
|
|
559
635
|
cliQuotaJobId &&
|
|
@@ -564,8 +640,8 @@ function createProgram() {
|
|
|
564
640
|
apiKey: platformQuotaApiKey,
|
|
565
641
|
jobId: cliQuotaJobId,
|
|
566
642
|
status: 'failed',
|
|
567
|
-
failureCode: 'scan_failed',
|
|
568
|
-
failureMessage: fallbackFailureMessage,
|
|
643
|
+
failureCode: reportedFailure?.code ?? 'scan_failed',
|
|
644
|
+
failureMessage: reportedFailure?.message ?? fallbackFailureMessage,
|
|
569
645
|
});
|
|
570
646
|
quotaCompletionReported = true;
|
|
571
647
|
if (isInteractive) {
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Git repository context for evidence linking.
|
|
4
|
+
* Enables converting file paths in evidence to clickable GitHub/GitLab URLs.
|
|
5
|
+
*/
|
|
6
|
+
export declare const gitContextSchema: z.ZodObject<{
|
|
7
|
+
provider: z.ZodEnum<{
|
|
8
|
+
github: "github";
|
|
9
|
+
gitlab: "gitlab";
|
|
10
|
+
}>;
|
|
11
|
+
repository: z.ZodString;
|
|
12
|
+
commitSha: z.ZodString;
|
|
13
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export type GitContextSchema = z.infer<typeof gitContextSchema>;
|
|
2
16
|
export declare const dataflowMetadataSchema: z.ZodObject<{
|
|
3
17
|
componentsCount: z.ZodOptional<z.ZodNumber>;
|
|
4
18
|
dataFlowsCount: z.ZodOptional<z.ZodNumber>;
|
|
@@ -14,6 +28,15 @@ export declare const dataflowMetadataSchema: z.ZodObject<{
|
|
|
14
28
|
jsonInputPath: z.ZodOptional<z.ZodString>;
|
|
15
29
|
jsonFindingsMerged: z.ZodNumber;
|
|
16
30
|
}, z.core.$strict>>;
|
|
31
|
+
gitContext: z.ZodOptional<z.ZodObject<{
|
|
32
|
+
provider: z.ZodEnum<{
|
|
33
|
+
github: "github";
|
|
34
|
+
gitlab: "gitlab";
|
|
35
|
+
}>;
|
|
36
|
+
repository: z.ZodString;
|
|
37
|
+
commitSha: z.ZodString;
|
|
38
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strip>>;
|
|
17
40
|
}, z.core.$loose>;
|
|
18
41
|
export declare const dataflowWrapperSchema: z.ZodObject<{
|
|
19
42
|
schemaVersion: z.ZodString;
|
|
@@ -69,6 +92,15 @@ export declare const dataflowWrapperSchema: z.ZodObject<{
|
|
|
69
92
|
jsonInputPath: z.ZodOptional<z.ZodString>;
|
|
70
93
|
jsonFindingsMerged: z.ZodNumber;
|
|
71
94
|
}, z.core.$strict>>;
|
|
95
|
+
gitContext: z.ZodOptional<z.ZodObject<{
|
|
96
|
+
provider: z.ZodEnum<{
|
|
97
|
+
github: "github";
|
|
98
|
+
gitlab: "gitlab";
|
|
99
|
+
}>;
|
|
100
|
+
repository: z.ZodString;
|
|
101
|
+
commitSha: z.ZodString;
|
|
102
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
103
|
+
}, z.core.$strip>>;
|
|
72
104
|
}, z.core.$loose>>;
|
|
73
105
|
}, z.core.$strip>;
|
|
74
106
|
export type DataflowMetadataSchema = z.infer<typeof dataflowMetadataSchema>;
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dataflowWrapperSchema = exports.dataflowMetadataSchema = void 0;
|
|
3
|
+
exports.dataflowWrapperSchema = exports.dataflowMetadataSchema = exports.gitContextSchema = void 0;
|
|
4
4
|
exports.parseDataflowJson = parseDataflowJson;
|
|
5
5
|
exports.validateDataflowJson = validateDataflowJson;
|
|
6
6
|
const zod_1 = require("zod");
|
|
7
7
|
const diagram_graph_schema_1 = require("./diagram-graph.schema");
|
|
8
|
+
/**
|
|
9
|
+
* Git repository context for evidence linking.
|
|
10
|
+
* Enables converting file paths in evidence to clickable GitHub/GitLab URLs.
|
|
11
|
+
*/
|
|
12
|
+
exports.gitContextSchema = zod_1.z.object({
|
|
13
|
+
/** Git provider: github or gitlab */
|
|
14
|
+
provider: zod_1.z.enum(['github', 'gitlab']),
|
|
15
|
+
/** Repository in "owner/repo" format */
|
|
16
|
+
repository: zod_1.z.string().min(1),
|
|
17
|
+
/** Resolved commit SHA (40 character hex string) */
|
|
18
|
+
commitSha: zod_1.z.string().regex(/^[a-f0-9]{40}$/i, 'Must be a 40-character SHA'),
|
|
19
|
+
/** Base URL for self-hosted instances (e.g., "https://gitlab.mycompany.com"). Defaults to public GitHub/GitLab. */
|
|
20
|
+
baseUrl: zod_1.z.string().url().optional(),
|
|
21
|
+
});
|
|
8
22
|
const terraformMetadataSchema = zod_1.z
|
|
9
23
|
.object({
|
|
10
|
-
mode: zod_1.z.enum([
|
|
24
|
+
mode: zod_1.z.enum(['static_tf', 'json_overlay', 'json_only']),
|
|
11
25
|
staticTfFiles: zod_1.z.number().int().nonnegative(),
|
|
12
26
|
jsonInputPath: zod_1.z.string().optional(),
|
|
13
27
|
jsonFindingsMerged: zod_1.z.number().int().nonnegative(),
|
|
@@ -20,6 +34,8 @@ exports.dataflowMetadataSchema = zod_1.z
|
|
|
20
34
|
filesScanned: zod_1.z.number().int().nonnegative().optional(),
|
|
21
35
|
scanDurationMs: zod_1.z.number().int().nonnegative().optional(),
|
|
22
36
|
terraform: terraformMetadataSchema.optional(),
|
|
37
|
+
/** Git repository context for evidence linking (GitHub/GitLab URLs) */
|
|
38
|
+
gitContext: exports.gitContextSchema.optional(),
|
|
23
39
|
})
|
|
24
40
|
.passthrough();
|
|
25
41
|
exports.dataflowWrapperSchema = zod_1.z.object({
|
|
@@ -33,7 +49,7 @@ function parseDataflowJson(input) {
|
|
|
33
49
|
function validateDataflowJson(input) {
|
|
34
50
|
const result = exports.dataflowWrapperSchema.safeParse(input);
|
|
35
51
|
if (!result.success) {
|
|
36
|
-
const errors = result.error.issues.map((issue) => `${issue.path.join(
|
|
52
|
+
const errors = result.error.issues.map((issue) => `${issue.path.join('.') || '<root>'}: ${issue.message}`);
|
|
37
53
|
return { ok: false, errors };
|
|
38
54
|
}
|
|
39
55
|
return { ok: true, value: result.data };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DiagramGraphJsonSchema } from '../core/schema';
|
|
2
|
-
import { type DataflowWrapperSchema } from '../core/schema/dataflow-wrapper.schema';
|
|
2
|
+
import { type DataflowWrapperSchema, type GitContextSchema } from '../core/schema/dataflow-wrapper.schema';
|
|
3
3
|
import type { ScanResult } from '../core/types';
|
|
4
4
|
import type { ScanRedFlag } from '../ai-enrichment/red-flags';
|
|
5
5
|
export interface BuildDataflowWrapperOptions {
|
|
@@ -18,6 +18,11 @@ export interface BuildDataflowWrapperOptions {
|
|
|
18
18
|
* Written under `metadata.redFlags` (passthrough metadata schema).
|
|
19
19
|
*/
|
|
20
20
|
redFlags?: ScanRedFlag[];
|
|
21
|
+
/**
|
|
22
|
+
* Git repository context for evidence linking.
|
|
23
|
+
* When provided, enables converting evidence file paths to clickable GitHub/GitLab URLs.
|
|
24
|
+
*/
|
|
25
|
+
gitContext?: GitContextSchema;
|
|
21
26
|
}
|
|
22
27
|
/**
|
|
23
28
|
* Assemble the top-level `dataflow.json` wrapper object from a scan result and graph.
|
|
@@ -47,6 +52,8 @@ export interface WriteDataflowJsonOptions {
|
|
|
47
52
|
projectName?: string;
|
|
48
53
|
/** Optional connectivity RED flags for `metadata.redFlags`. */
|
|
49
54
|
redFlags?: ScanRedFlag[];
|
|
55
|
+
/** Git repository context for evidence linking. */
|
|
56
|
+
gitContext?: GitContextSchema;
|
|
50
57
|
}
|
|
51
58
|
/**
|
|
52
59
|
* Validate and write a `dataflow.json` wrapper to disk.
|
package/dist/src/output/json.js
CHANGED
|
@@ -34,6 +34,9 @@ function buildDataflowWrapper(scanResult, graph, options = {}) {
|
|
|
34
34
|
if (options.redFlags && options.redFlags.length > 0) {
|
|
35
35
|
metadata.redFlags = options.redFlags;
|
|
36
36
|
}
|
|
37
|
+
if (options.gitContext) {
|
|
38
|
+
metadata.gitContext = options.gitContext;
|
|
39
|
+
}
|
|
37
40
|
return {
|
|
38
41
|
schemaVersion,
|
|
39
42
|
graph,
|
|
@@ -53,11 +56,12 @@ function buildDataflowWrapper(scanResult, graph, options = {}) {
|
|
|
53
56
|
* can emit a non-zero exit code.
|
|
54
57
|
*/
|
|
55
58
|
function writeDataflowJson(options) {
|
|
56
|
-
const { scanResult, graph, outputPath, schemaVersion, projectName, redFlags, } = options;
|
|
59
|
+
const { scanResult, graph, outputPath, schemaVersion, projectName, redFlags, gitContext, } = options;
|
|
57
60
|
const wrapper = buildDataflowWrapper(scanResult, graph, {
|
|
58
61
|
schemaVersion,
|
|
59
62
|
projectName,
|
|
60
63
|
redFlags,
|
|
64
|
+
gitContext,
|
|
61
65
|
});
|
|
62
66
|
const validation = (0, dataflow_wrapper_schema_1.validateDataflowJson)(wrapper);
|
|
63
67
|
if (!validation.ok) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Failure detail reported to the platform so the dashboard can explain what broke. */
|
|
2
|
+
export type CliScanFailureReport = {
|
|
3
|
+
code: string;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
/** Collapses whitespace and caps length so the message stays readable in the activity feed. */
|
|
7
|
+
export declare function truncateFailureMessage(message: string): string;
|
|
8
|
+
/** Reports the first scan error plus how many others followed it. */
|
|
9
|
+
export declare function summarizeScanErrors(errors: string[]): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.truncateFailureMessage = truncateFailureMessage;
|
|
4
|
+
exports.summarizeScanErrors = summarizeScanErrors;
|
|
5
|
+
const MAX_FAILURE_MESSAGE_CHARS = 300;
|
|
6
|
+
/** Collapses whitespace and caps length so the message stays readable in the activity feed. */
|
|
7
|
+
function truncateFailureMessage(message) {
|
|
8
|
+
const normalized = message.replace(/\s+/g, ' ').trim();
|
|
9
|
+
if (normalized.length <= MAX_FAILURE_MESSAGE_CHARS)
|
|
10
|
+
return normalized;
|
|
11
|
+
return `${normalized.slice(0, MAX_FAILURE_MESSAGE_CHARS - 1)}…`;
|
|
12
|
+
}
|
|
13
|
+
/** Reports the first scan error plus how many others followed it. */
|
|
14
|
+
function summarizeScanErrors(errors) {
|
|
15
|
+
const cleaned = errors.map((error) => error.trim()).filter(Boolean);
|
|
16
|
+
if (cleaned.length === 0)
|
|
17
|
+
return 'The scanner reported errors.';
|
|
18
|
+
const remaining = cleaned.length - 1;
|
|
19
|
+
const suffix = remaining > 0
|
|
20
|
+
? ` (+${remaining} more error${remaining > 1 ? 's' : ''})`
|
|
21
|
+
: '';
|
|
22
|
+
return truncateFailureMessage(`${cleaned[0]}${suffix}`);
|
|
23
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const dataflow_wrapper_schema_1 = require("../../src/core/schema/dataflow-wrapper.schema");
|
|
4
|
-
describe(
|
|
5
|
-
it(
|
|
4
|
+
describe('dataflowWrapperSchema', () => {
|
|
5
|
+
it('accepts a valid dataflow.json wrapper', () => {
|
|
6
6
|
const input = {
|
|
7
|
-
schemaVersion:
|
|
7
|
+
schemaVersion: '1.0',
|
|
8
8
|
graph: {
|
|
9
9
|
nodes: [
|
|
10
10
|
{
|
|
11
|
-
id:
|
|
12
|
-
type:
|
|
11
|
+
id: 'n1',
|
|
12
|
+
type: 'asset',
|
|
13
13
|
position: { x: 0, y: 0 },
|
|
14
|
-
data: { label:
|
|
14
|
+
data: { label: 'Node 1', privacy: {} },
|
|
15
15
|
},
|
|
16
16
|
],
|
|
17
17
|
edges: [],
|
|
@@ -27,19 +27,19 @@ describe("dataflowWrapperSchema", () => {
|
|
|
27
27
|
const result = (0, dataflow_wrapper_schema_1.validateDataflowJson)(input);
|
|
28
28
|
expect(result.ok).toBe(true);
|
|
29
29
|
if (result.ok) {
|
|
30
|
-
expect(result.value.graph.nodes[0].id).toBe(
|
|
30
|
+
expect(result.value.graph.nodes[0].id).toBe('n1');
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
|
-
it(
|
|
33
|
+
it('accepts metadata.terraform when shape matches CLI output', () => {
|
|
34
34
|
const input = {
|
|
35
|
-
schemaVersion:
|
|
35
|
+
schemaVersion: '1.0',
|
|
36
36
|
graph: {
|
|
37
37
|
nodes: [
|
|
38
38
|
{
|
|
39
|
-
id:
|
|
40
|
-
type:
|
|
39
|
+
id: 'n1',
|
|
40
|
+
type: 'asset',
|
|
41
41
|
position: { x: 0, y: 0 },
|
|
42
|
-
data: { label:
|
|
42
|
+
data: { label: 'Node 1', privacy: {} },
|
|
43
43
|
},
|
|
44
44
|
],
|
|
45
45
|
edges: [],
|
|
@@ -47,9 +47,9 @@ describe("dataflowWrapperSchema", () => {
|
|
|
47
47
|
metadata: {
|
|
48
48
|
componentsCount: 1,
|
|
49
49
|
terraform: {
|
|
50
|
-
mode:
|
|
50
|
+
mode: 'json_overlay',
|
|
51
51
|
staticTfFiles: 2,
|
|
52
|
-
jsonInputPath:
|
|
52
|
+
jsonInputPath: '/tmp/plan.json',
|
|
53
53
|
jsonFindingsMerged: 1,
|
|
54
54
|
},
|
|
55
55
|
},
|
|
@@ -57,27 +57,27 @@ describe("dataflowWrapperSchema", () => {
|
|
|
57
57
|
const result = (0, dataflow_wrapper_schema_1.validateDataflowJson)(input);
|
|
58
58
|
expect(result.ok).toBe(true);
|
|
59
59
|
});
|
|
60
|
-
it(
|
|
60
|
+
it('rejects wrappers missing schemaVersion or graph', () => {
|
|
61
61
|
const input = {
|
|
62
62
|
graph: {},
|
|
63
63
|
};
|
|
64
64
|
const result = (0, dataflow_wrapper_schema_1.validateDataflowJson)(input);
|
|
65
65
|
expect(result.ok).toBe(false);
|
|
66
66
|
if (!result.ok) {
|
|
67
|
-
const message = result.errors.join(
|
|
67
|
+
const message = result.errors.join(' | ');
|
|
68
68
|
expect(message).toMatch(/schemaVersion/);
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
|
-
it(
|
|
71
|
+
it('rejects invalid graph structures', () => {
|
|
72
72
|
const input = {
|
|
73
|
-
schemaVersion:
|
|
73
|
+
schemaVersion: '1.0',
|
|
74
74
|
graph: {
|
|
75
75
|
nodes: [
|
|
76
76
|
{
|
|
77
|
-
id:
|
|
78
|
-
type:
|
|
77
|
+
id: '',
|
|
78
|
+
type: 'asset',
|
|
79
79
|
position: { x: 0, y: 0 },
|
|
80
|
-
data: { label:
|
|
80
|
+
data: { label: 'Invalid Node', privacy: {} },
|
|
81
81
|
},
|
|
82
82
|
],
|
|
83
83
|
edges: [],
|
|
@@ -86,4 +86,125 @@ describe("dataflowWrapperSchema", () => {
|
|
|
86
86
|
const result = dataflow_wrapper_schema_1.dataflowWrapperSchema.safeParse(input);
|
|
87
87
|
expect(result.success).toBe(false);
|
|
88
88
|
});
|
|
89
|
+
it('accepts metadata.gitContext for evidence linking', () => {
|
|
90
|
+
const input = {
|
|
91
|
+
schemaVersion: '1.0',
|
|
92
|
+
graph: {
|
|
93
|
+
nodes: [
|
|
94
|
+
{
|
|
95
|
+
id: 'n1',
|
|
96
|
+
type: 'asset',
|
|
97
|
+
position: { x: 0, y: 0 },
|
|
98
|
+
data: { label: 'Node 1', privacy: {} },
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
edges: [],
|
|
102
|
+
},
|
|
103
|
+
metadata: {
|
|
104
|
+
componentsCount: 1,
|
|
105
|
+
gitContext: {
|
|
106
|
+
provider: 'github',
|
|
107
|
+
repository: 'dataparade-io/dataparade',
|
|
108
|
+
commitSha: 'abc1234567890abc1234567890abc1234567890a',
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
const result = (0, dataflow_wrapper_schema_1.validateDataflowJson)(input);
|
|
113
|
+
expect(result.ok).toBe(true);
|
|
114
|
+
if (result.ok) {
|
|
115
|
+
expect(result.value.metadata?.gitContext).toEqual({
|
|
116
|
+
provider: 'github',
|
|
117
|
+
repository: 'dataparade-io/dataparade',
|
|
118
|
+
commitSha: 'abc1234567890abc1234567890abc1234567890a',
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
it('accepts metadata.gitContext with baseUrl for self-hosted GitLab', () => {
|
|
123
|
+
const input = {
|
|
124
|
+
schemaVersion: '1.0',
|
|
125
|
+
graph: {
|
|
126
|
+
nodes: [],
|
|
127
|
+
edges: [],
|
|
128
|
+
},
|
|
129
|
+
metadata: {
|
|
130
|
+
gitContext: {
|
|
131
|
+
provider: 'gitlab',
|
|
132
|
+
repository: 'internal/project',
|
|
133
|
+
commitSha: 'def1234567890def1234567890def1234567890d',
|
|
134
|
+
baseUrl: 'https://gitlab.mycompany.com',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
const result = (0, dataflow_wrapper_schema_1.validateDataflowJson)(input);
|
|
139
|
+
expect(result.ok).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
describe('gitContextSchema', () => {
|
|
143
|
+
it('accepts valid GitHub context', () => {
|
|
144
|
+
const result = dataflow_wrapper_schema_1.gitContextSchema.safeParse({
|
|
145
|
+
provider: 'github',
|
|
146
|
+
repository: 'owner/repo',
|
|
147
|
+
commitSha: 'abc1234567890abc1234567890abc1234567890a',
|
|
148
|
+
});
|
|
149
|
+
expect(result.success).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
it('accepts valid GitLab context', () => {
|
|
152
|
+
const result = dataflow_wrapper_schema_1.gitContextSchema.safeParse({
|
|
153
|
+
provider: 'gitlab',
|
|
154
|
+
repository: 'group/project',
|
|
155
|
+
commitSha: 'def1234567890def1234567890def1234567890d',
|
|
156
|
+
});
|
|
157
|
+
expect(result.success).toBe(true);
|
|
158
|
+
});
|
|
159
|
+
it('accepts baseUrl for self-hosted instances', () => {
|
|
160
|
+
const result = dataflow_wrapper_schema_1.gitContextSchema.safeParse({
|
|
161
|
+
provider: 'gitlab',
|
|
162
|
+
repository: 'internal/project',
|
|
163
|
+
commitSha: '1234567890123456789012345678901234567890',
|
|
164
|
+
baseUrl: 'https://gitlab.mycompany.com',
|
|
165
|
+
});
|
|
166
|
+
expect(result.success).toBe(true);
|
|
167
|
+
if (result.success) {
|
|
168
|
+
expect(result.data.baseUrl).toBe('https://gitlab.mycompany.com');
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
it('rejects invalid provider', () => {
|
|
172
|
+
const result = dataflow_wrapper_schema_1.gitContextSchema.safeParse({
|
|
173
|
+
provider: 'bitbucket',
|
|
174
|
+
repository: 'owner/repo',
|
|
175
|
+
commitSha: 'abc1234567890abc1234567890abc1234567890a',
|
|
176
|
+
});
|
|
177
|
+
expect(result.success).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
it('rejects empty repository', () => {
|
|
180
|
+
const result = dataflow_wrapper_schema_1.gitContextSchema.safeParse({
|
|
181
|
+
provider: 'github',
|
|
182
|
+
repository: '',
|
|
183
|
+
commitSha: 'abc1234567890abc1234567890abc1234567890a',
|
|
184
|
+
});
|
|
185
|
+
expect(result.success).toBe(false);
|
|
186
|
+
});
|
|
187
|
+
it('rejects invalid commitSha (not 40 hex chars)', () => {
|
|
188
|
+
const shortSha = dataflow_wrapper_schema_1.gitContextSchema.safeParse({
|
|
189
|
+
provider: 'github',
|
|
190
|
+
repository: 'owner/repo',
|
|
191
|
+
commitSha: 'abc123',
|
|
192
|
+
});
|
|
193
|
+
expect(shortSha.success).toBe(false);
|
|
194
|
+
const invalidChars = dataflow_wrapper_schema_1.gitContextSchema.safeParse({
|
|
195
|
+
provider: 'github',
|
|
196
|
+
repository: 'owner/repo',
|
|
197
|
+
commitSha: 'xyz1234567890xyz1234567890xyz1234567890z',
|
|
198
|
+
});
|
|
199
|
+
expect(invalidChars.success).toBe(false);
|
|
200
|
+
});
|
|
201
|
+
it('rejects invalid baseUrl', () => {
|
|
202
|
+
const result = dataflow_wrapper_schema_1.gitContextSchema.safeParse({
|
|
203
|
+
provider: 'gitlab',
|
|
204
|
+
repository: 'internal/project',
|
|
205
|
+
commitSha: '1234567890123456789012345678901234567890',
|
|
206
|
+
baseUrl: 'not-a-url',
|
|
207
|
+
});
|
|
208
|
+
expect(result.success).toBe(false);
|
|
209
|
+
});
|
|
89
210
|
});
|
|
@@ -11,15 +11,15 @@ function jsonResponse(body, status = 200) {
|
|
|
11
11
|
return {
|
|
12
12
|
ok: status >= 200 && status < 300,
|
|
13
13
|
status,
|
|
14
|
-
statusText: status === 200 ?
|
|
14
|
+
statusText: status === 200 ? 'OK' : 'Error',
|
|
15
15
|
json: async () => body,
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
describe(
|
|
18
|
+
describe('scan quota flow', () => {
|
|
19
19
|
let tempRoot;
|
|
20
20
|
let fetchMock;
|
|
21
21
|
beforeEach(() => {
|
|
22
|
-
tempRoot = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(),
|
|
22
|
+
tempRoot = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'dp-scan-quota-'));
|
|
23
23
|
fetchMock = jest.fn();
|
|
24
24
|
global.fetch = fetchMock;
|
|
25
25
|
process.exitCode = 0;
|
|
@@ -31,95 +31,99 @@ describe("scan quota flow", () => {
|
|
|
31
31
|
delete process.env.SCAN_HOSTED_INFER_PROXY_URL;
|
|
32
32
|
process.exitCode = 0;
|
|
33
33
|
});
|
|
34
|
-
it(
|
|
35
|
-
process.env.SCAN_HOSTED_INFER_PROXY_URL =
|
|
36
|
-
process.env.DATAPARADE_SKIP_AUTO_UPLOAD =
|
|
37
|
-
await (0, cli_1.run)([
|
|
34
|
+
it('skips anonymous AI session when hosted infer proxy is configured', async () => {
|
|
35
|
+
process.env.SCAN_HOSTED_INFER_PROXY_URL = 'http://127.0.0.1:9/infer';
|
|
36
|
+
process.env.DATAPARADE_SKIP_AUTO_UPLOAD = 'true';
|
|
37
|
+
await (0, cli_1.run)(['node', 'cli', 'scan', tempRoot, '--ai-inference']);
|
|
38
38
|
expect(fetchMock).not.toHaveBeenCalled();
|
|
39
39
|
expect(process.exitCode ?? 0).toBe(0);
|
|
40
40
|
});
|
|
41
|
-
it(
|
|
42
|
-
process.env.DATAPARADE_WORKSPACE_API_KEY =
|
|
43
|
-
process.env.DATAPARADE_SKIP_AUTO_UPLOAD =
|
|
44
|
-
await (0, cli_1.run)([
|
|
41
|
+
it('skips quota API when workspace key is present but AI is disabled', async () => {
|
|
42
|
+
process.env.DATAPARADE_WORKSPACE_API_KEY = 'dp_live_test';
|
|
43
|
+
process.env.DATAPARADE_SKIP_AUTO_UPLOAD = 'true';
|
|
44
|
+
await (0, cli_1.run)(['node', 'cli', 'scan', tempRoot, '--no-ai-inference']);
|
|
45
45
|
expect(fetchMock).not.toHaveBeenCalled();
|
|
46
46
|
});
|
|
47
|
-
it(
|
|
48
|
-
process.env.DATAPARADE_WORKSPACE_API_KEY =
|
|
49
|
-
const errorSpy = jest.spyOn(console,
|
|
47
|
+
it('prints workspace quota message when preflight is quota-blocked', async () => {
|
|
48
|
+
process.env.DATAPARADE_WORKSPACE_API_KEY = 'dp_live_test';
|
|
49
|
+
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
|
|
50
50
|
fetchMock.mockResolvedValueOnce(jsonResponse({
|
|
51
|
-
code:
|
|
52
|
-
message:
|
|
51
|
+
code: 'scan_quota_exceeded',
|
|
52
|
+
message: 'No scan slots remaining in this workspace.',
|
|
53
53
|
scansRemaining: 0,
|
|
54
54
|
aiTokensRemaining: 1000,
|
|
55
55
|
}, 403));
|
|
56
|
-
await (0, cli_1.run)([
|
|
57
|
-
expect(errorSpy).toHaveBeenCalledWith(
|
|
56
|
+
await (0, cli_1.run)(['node', 'cli', 'scan', tempRoot, '--ai-inference']);
|
|
57
|
+
expect(errorSpy).toHaveBeenCalledWith('[scan] workspace quota: No scan slots remaining in this workspace.');
|
|
58
58
|
errorSpy.mockRestore();
|
|
59
59
|
});
|
|
60
|
-
it(
|
|
61
|
-
process.env.DATAPARADE_WORKSPACE_API_KEY =
|
|
62
|
-
const errorSpy = jest.spyOn(console,
|
|
60
|
+
it('prints scan in progress message when preflight is blocked by running job', async () => {
|
|
61
|
+
process.env.DATAPARADE_WORKSPACE_API_KEY = 'dp_live_test';
|
|
62
|
+
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
|
|
63
63
|
fetchMock.mockResolvedValueOnce(jsonResponse({
|
|
64
64
|
statusCode: 409,
|
|
65
65
|
message: {
|
|
66
|
-
code:
|
|
67
|
-
message:
|
|
66
|
+
code: 'scan_already_running',
|
|
67
|
+
message: 'Scan in progress — start a new scan after the current one completes.',
|
|
68
68
|
},
|
|
69
69
|
}, 409));
|
|
70
|
-
await (0, cli_1.run)([
|
|
71
|
-
expect(errorSpy).toHaveBeenCalledWith(
|
|
70
|
+
await (0, cli_1.run)(['node', 'cli', 'scan', tempRoot, '--ai-inference']);
|
|
71
|
+
expect(errorSpy).toHaveBeenCalledWith('[scan] scan in progress: Scan in progress — start a new scan after the current one completes.');
|
|
72
72
|
errorSpy.mockRestore();
|
|
73
73
|
});
|
|
74
|
-
it(
|
|
75
|
-
process.env.DATAPARADE_WORKSPACE_API_KEY =
|
|
74
|
+
it('reports failed completion when preflight succeeds but config validation fails', async () => {
|
|
75
|
+
process.env.DATAPARADE_WORKSPACE_API_KEY = 'dp_live_test';
|
|
76
76
|
fetchMock
|
|
77
77
|
.mockResolvedValueOnce(jsonResponse({
|
|
78
78
|
allowed: true,
|
|
79
|
-
jobId:
|
|
79
|
+
jobId: 'job-123',
|
|
80
80
|
scansRemaining: 2,
|
|
81
81
|
aiTokensRemaining: 1000,
|
|
82
82
|
suggestedAiBudgetTokens: 100,
|
|
83
|
-
aiDelivery:
|
|
83
|
+
aiDelivery: 'platform_proxy',
|
|
84
84
|
}))
|
|
85
85
|
.mockResolvedValueOnce(jsonResponse({ ok: true }));
|
|
86
86
|
await (0, cli_1.run)([
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
'node',
|
|
88
|
+
'cli',
|
|
89
|
+
'scan',
|
|
90
90
|
tempRoot,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
'--ai-inference',
|
|
92
|
+
'--ai-temperature',
|
|
93
|
+
'not-a-number',
|
|
94
94
|
]);
|
|
95
95
|
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
96
|
-
expect(String(fetchMock.mock.calls[0][0])).toContain(
|
|
97
|
-
expect(String(fetchMock.mock.calls[1][0])).toContain(
|
|
98
|
-
expect(JSON.parse(String(fetchMock.mock.calls[1][1]?.body))).toEqual(expect.objectContaining({
|
|
96
|
+
expect(String(fetchMock.mock.calls[0][0])).toContain('/api/scans/cli/preflight');
|
|
97
|
+
expect(String(fetchMock.mock.calls[1][0])).toContain('/api/scans/cli/job-123/complete');
|
|
98
|
+
expect(JSON.parse(String(fetchMock.mock.calls[1][1]?.body))).toEqual(expect.objectContaining({
|
|
99
|
+
status: 'failed',
|
|
100
|
+
failureCode: 'invalid_configuration',
|
|
101
|
+
failureMessage: expect.stringContaining('aiTemperature'),
|
|
102
|
+
}));
|
|
99
103
|
});
|
|
100
|
-
it(
|
|
101
|
-
process.env.DATAPARADE_WORKSPACE_API_KEY =
|
|
102
|
-
process.env.DATAPARADE_SKIP_AUTO_UPLOAD =
|
|
103
|
-
const logSpy = jest.spyOn(console,
|
|
104
|
-
const isTty = Object.getOwnPropertyDescriptor(process.stdout,
|
|
105
|
-
Object.defineProperty(process.stdout,
|
|
104
|
+
it('prints ready-for-new-scan message after platform scan completes', async () => {
|
|
105
|
+
process.env.DATAPARADE_WORKSPACE_API_KEY = 'dp_live_test';
|
|
106
|
+
process.env.DATAPARADE_SKIP_AUTO_UPLOAD = 'true';
|
|
107
|
+
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
|
|
108
|
+
const isTty = Object.getOwnPropertyDescriptor(process.stdout, 'isTTY');
|
|
109
|
+
Object.defineProperty(process.stdout, 'isTTY', {
|
|
106
110
|
value: true,
|
|
107
111
|
configurable: true,
|
|
108
112
|
});
|
|
109
113
|
fetchMock
|
|
110
114
|
.mockResolvedValueOnce(jsonResponse({
|
|
111
115
|
allowed: true,
|
|
112
|
-
jobId:
|
|
116
|
+
jobId: 'job-456',
|
|
113
117
|
scansRemaining: 2,
|
|
114
118
|
aiTokensRemaining: 1000,
|
|
115
119
|
suggestedAiBudgetTokens: 100,
|
|
116
|
-
aiDelivery:
|
|
120
|
+
aiDelivery: 'platform_proxy',
|
|
117
121
|
}))
|
|
118
122
|
.mockResolvedValueOnce(jsonResponse({ ok: true }));
|
|
119
|
-
await (0, cli_1.run)([
|
|
120
|
-
expect(logSpy).toHaveBeenCalledWith(
|
|
123
|
+
await (0, cli_1.run)(['node', 'cli', 'scan', tempRoot, '--ai-inference']);
|
|
124
|
+
expect(logSpy).toHaveBeenCalledWith('[scan] Scan finished — you can start a new scan now.');
|
|
121
125
|
if (isTty) {
|
|
122
|
-
Object.defineProperty(process.stdout,
|
|
126
|
+
Object.defineProperty(process.stdout, 'isTTY', isTty);
|
|
123
127
|
}
|
|
124
128
|
else {
|
|
125
129
|
delete process.stdout.isTTY;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cli_scan_failure_report_1 = require("../../../src/platform-api/cli-scan-failure-report");
|
|
4
|
+
describe('cli scan failure report', () => {
|
|
5
|
+
it('keeps a single error as-is', () => {
|
|
6
|
+
expect((0, cli_scan_failure_report_1.summarizeScanErrors)(['parser: unexpected token in user.rb'])).toBe('parser: unexpected token in user.rb');
|
|
7
|
+
});
|
|
8
|
+
it('reports the first error and how many others followed', () => {
|
|
9
|
+
expect((0, cli_scan_failure_report_1.summarizeScanErrors)(['first failure', 'second failure', 'third failure'])).toBe('first failure (+2 more errors)');
|
|
10
|
+
});
|
|
11
|
+
it('uses singular wording for one additional error', () => {
|
|
12
|
+
expect((0, cli_scan_failure_report_1.summarizeScanErrors)(['first failure', 'second failure'])).toBe('first failure (+1 more error)');
|
|
13
|
+
});
|
|
14
|
+
it('falls back when the error list is empty or blank', () => {
|
|
15
|
+
expect((0, cli_scan_failure_report_1.summarizeScanErrors)([])).toBe('The scanner reported errors.');
|
|
16
|
+
expect((0, cli_scan_failure_report_1.summarizeScanErrors)([' '])).toBe('The scanner reported errors.');
|
|
17
|
+
});
|
|
18
|
+
it('collapses whitespace and truncates long messages', () => {
|
|
19
|
+
expect((0, cli_scan_failure_report_1.truncateFailureMessage)(' multi\n line\tmessage ')).toBe('multi line message');
|
|
20
|
+
const long = 'x'.repeat(400);
|
|
21
|
+
const truncated = (0, cli_scan_failure_report_1.truncateFailureMessage)(long);
|
|
22
|
+
expect(truncated).toHaveLength(300);
|
|
23
|
+
expect(truncated.endsWith('…')).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
});
|