@dataparade/cli 0.0.18 → 0.0.20
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 +2 -2
- 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 +2 -1
- package/dist/src/platform-api/fetch-failure.d.ts +11 -0
- package/dist/src/platform-api/fetch-failure.js +85 -0
- package/dist/tests/unit/ai-enrichment/platform-proxy-provider.spec.js +118 -47
- 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/tracing/langsmith-tracing.spec.js +27 -23
- package/package.json +2 -2
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataparade/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "dataPARADE CLI — scan codebases for privacy and security data flows",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"eval:models": "pnpm exec node dist/src/evals/run-model-matrix.js"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@dataparade/scanner": "github:DataParade-io/scanner#
|
|
57
|
+
"@dataparade/scanner": "github:DataParade-io/scanner#e66e1bcaef55b61214d170c617df529bd300fc89",
|
|
58
58
|
"@sentry/node": "^10.38.0",
|
|
59
59
|
"commander": "^12.1.0",
|
|
60
60
|
"dotenv": "^16.4.7",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AiProvider, AiProviderRequest, AiProviderResult } from
|
|
1
|
+
import type { AiProvider, AiProviderRequest, AiProviderResult } from './types';
|
|
2
2
|
export type PlatformProxyProviderConfig = {
|
|
3
3
|
apiBaseUrl: string;
|
|
4
4
|
workspaceApiKey: string;
|
|
@@ -9,6 +9,8 @@ export type PlatformProxyProviderConfig = {
|
|
|
9
9
|
pollTimeoutMs?: number;
|
|
10
10
|
/** Backoff delays when a task fails because the helper Lambda is still INIT. */
|
|
11
11
|
lambdaInitRetryDelaysMs?: number[];
|
|
12
|
+
/** Backoff delays after a dropped connection. Each entry is one retry. */
|
|
13
|
+
networkRetryDelaysMs?: number[];
|
|
12
14
|
sleep?: (ms: number) => Promise<void>;
|
|
13
15
|
};
|
|
14
16
|
export declare class PlatformProxyProvider implements AiProvider {
|
|
@@ -21,5 +23,6 @@ export declare class PlatformProxyProvider implements AiProvider {
|
|
|
21
23
|
private wait;
|
|
22
24
|
private throwPlatformError;
|
|
23
25
|
infer(request: AiProviderRequest): Promise<AiProviderResult>;
|
|
26
|
+
private fetchPlatform;
|
|
24
27
|
private inferOnce;
|
|
25
28
|
}
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlatformProxyProvider = void 0;
|
|
4
4
|
const lambda_init_error_1 = require("../lambda-init-error");
|
|
5
|
+
const fetch_failure_1 = require("../../platform-api/fetch-failure");
|
|
6
|
+
const DEFAULT_NETWORK_RETRY_DELAYS_MS = [1000, 2000];
|
|
5
7
|
function resolvePollTimeoutMs(configured) {
|
|
6
|
-
if (typeof configured ===
|
|
8
|
+
if (typeof configured === 'number' &&
|
|
9
|
+
Number.isFinite(configured) &&
|
|
10
|
+
configured > 0) {
|
|
7
11
|
return Math.floor(configured);
|
|
8
12
|
}
|
|
9
|
-
const fromEnv = Number(process.env.SCAN_AI_HTTP_TIMEOUT_MS ??
|
|
13
|
+
const fromEnv = Number(process.env.SCAN_AI_HTTP_TIMEOUT_MS ?? '');
|
|
10
14
|
if (Number.isFinite(fromEnv) && fromEnv > 0)
|
|
11
15
|
return Math.floor(fromEnv);
|
|
12
16
|
return 180_000;
|
|
@@ -17,25 +21,25 @@ function sleep(ms) {
|
|
|
17
21
|
class PlatformProxyProvider {
|
|
18
22
|
constructor(config) {
|
|
19
23
|
this.config = config;
|
|
20
|
-
this.id =
|
|
24
|
+
this.id = 'openai';
|
|
21
25
|
}
|
|
22
26
|
authHeaders() {
|
|
23
27
|
return {
|
|
24
28
|
Authorization: `Bearer ${this.config.workspaceApiKey}`,
|
|
25
|
-
|
|
29
|
+
'Content-Type': 'application/json',
|
|
26
30
|
};
|
|
27
31
|
}
|
|
28
32
|
apiBase() {
|
|
29
|
-
return this.config.apiBaseUrl.replace(/\/$/,
|
|
33
|
+
return this.config.apiBaseUrl.replace(/\/$/, '');
|
|
30
34
|
}
|
|
31
35
|
async readErrorMessage(res) {
|
|
32
36
|
let message = `Platform AI infer failed (${res.status})`;
|
|
33
37
|
try {
|
|
34
38
|
const body = (await res.json());
|
|
35
|
-
if (typeof body.message ===
|
|
39
|
+
if (typeof body.message === 'string')
|
|
36
40
|
message = body.message;
|
|
37
41
|
else if (Array.isArray(body.message))
|
|
38
|
-
message = body.message.join(
|
|
42
|
+
message = body.message.join(', ');
|
|
39
43
|
}
|
|
40
44
|
catch {
|
|
41
45
|
// ignore
|
|
@@ -51,7 +55,7 @@ class PlatformProxyProvider {
|
|
|
51
55
|
}
|
|
52
56
|
if (res.status >= 500) {
|
|
53
57
|
const detail = message === `Platform AI infer failed (${res.status})`
|
|
54
|
-
?
|
|
58
|
+
? 'Internal server error'
|
|
55
59
|
: message;
|
|
56
60
|
throw new Error(`Platform AI service error (${res.status}): ${detail}. If this persists, redeploy the API with the CLI bundle and verify SCAN_WORKER_LLM_API_KEY.`);
|
|
57
61
|
}
|
|
@@ -76,9 +80,31 @@ class PlatformProxyProvider {
|
|
|
76
80
|
}
|
|
77
81
|
throw (0, lambda_init_error_1.toUserFacingLambdaInitError)(lastErr);
|
|
78
82
|
}
|
|
83
|
+
async fetchPlatform(url, init) {
|
|
84
|
+
const delays = this.config.networkRetryDelaysMs ?? [
|
|
85
|
+
...DEFAULT_NETWORK_RETRY_DELAYS_MS,
|
|
86
|
+
];
|
|
87
|
+
const method = init.method ?? 'GET';
|
|
88
|
+
let lastErr;
|
|
89
|
+
for (let attempt = 0; attempt <= delays.length; attempt += 1) {
|
|
90
|
+
try {
|
|
91
|
+
return await fetch(url, init);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
lastErr = err;
|
|
95
|
+
if (attempt >= delays.length || !(0, fetch_failure_1.isTransientFetchError)(err)) {
|
|
96
|
+
throw (0, fetch_failure_1.toApiReachabilityError)(err, url, method, attempt + 1);
|
|
97
|
+
}
|
|
98
|
+
// eslint-disable-next-line no-console
|
|
99
|
+
console.warn(`[dataparade-ai] ${(0, fetch_failure_1.describeRequestTarget)(url, method)} failed (${(0, fetch_failure_1.fetchFailureDetail)(err)}). Retrying (${attempt + 1}/${delays.length}).`);
|
|
100
|
+
await this.wait(delays[attempt] ?? 0);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
throw (0, fetch_failure_1.toApiReachabilityError)(lastErr, url, method, delays.length + 1);
|
|
104
|
+
}
|
|
79
105
|
async inferOnce(request) {
|
|
80
|
-
const submitRes = await
|
|
81
|
-
method:
|
|
106
|
+
const submitRes = await this.fetchPlatform(`${this.apiBase()}/api/scans/cli/ai/infer/tasks`, {
|
|
107
|
+
method: 'POST',
|
|
82
108
|
headers: this.authHeaders(),
|
|
83
109
|
body: JSON.stringify({
|
|
84
110
|
jobId: this.config.jobId,
|
|
@@ -98,13 +124,13 @@ class PlatformProxyProvider {
|
|
|
98
124
|
const submitBody = (await submitRes.json());
|
|
99
125
|
const task = submitBody.tasks?.[0];
|
|
100
126
|
if (!task?.taskId) {
|
|
101
|
-
throw new Error(
|
|
127
|
+
throw new Error('Platform AI infer submit returned no task id');
|
|
102
128
|
}
|
|
103
129
|
const pollIntervalMs = Math.max(500, Math.floor(this.config.pollIntervalMs ?? 1500));
|
|
104
130
|
const deadline = Date.now() + resolvePollTimeoutMs(this.config.pollTimeoutMs);
|
|
105
131
|
while (Date.now() < deadline) {
|
|
106
|
-
const pollRes = await
|
|
107
|
-
method:
|
|
132
|
+
const pollRes = await this.fetchPlatform(`${this.apiBase()}/api/scans/cli/ai/infer/tasks?jobId=${encodeURIComponent(this.config.jobId)}&taskIds=${encodeURIComponent(task.taskId)}`, {
|
|
133
|
+
method: 'GET',
|
|
108
134
|
headers: this.authHeaders(),
|
|
109
135
|
});
|
|
110
136
|
if (!pollRes.ok) {
|
|
@@ -114,14 +140,14 @@ class PlatformProxyProvider {
|
|
|
114
140
|
const pollBody = (await pollRes.json());
|
|
115
141
|
const current = pollBody.tasks?.[0];
|
|
116
142
|
if (!current) {
|
|
117
|
-
throw new Error(
|
|
143
|
+
throw new Error('Platform AI infer poll returned no task');
|
|
118
144
|
}
|
|
119
|
-
if (current.status ===
|
|
145
|
+
if (current.status === 'completed') {
|
|
120
146
|
const proposals = (Array.isArray(current.proposals) ? current.proposals : []);
|
|
121
147
|
const usage = current.usage;
|
|
122
148
|
return {
|
|
123
149
|
proposals,
|
|
124
|
-
usage: usage && typeof usage.totalTokens ===
|
|
150
|
+
usage: usage && typeof usage.totalTokens === 'number'
|
|
125
151
|
? {
|
|
126
152
|
inputTokens: Math.max(0, usage.inputTokens ?? 0),
|
|
127
153
|
outputTokens: Math.max(0, usage.outputTokens ?? 0),
|
|
@@ -130,9 +156,9 @@ class PlatformProxyProvider {
|
|
|
130
156
|
: undefined,
|
|
131
157
|
};
|
|
132
158
|
}
|
|
133
|
-
if (current.status ===
|
|
159
|
+
if (current.status === 'failed') {
|
|
134
160
|
throw new Error(current.errorMessage?.trim() ||
|
|
135
|
-
|
|
161
|
+
'Platform AI infer task failed without details');
|
|
136
162
|
}
|
|
137
163
|
await this.wait(pollIntervalMs);
|
|
138
164
|
}
|
package/dist/src/cli.js
CHANGED
|
@@ -52,6 +52,7 @@ const resolve_1 = require("./config/resolve");
|
|
|
52
52
|
const scan_env_1 = require("./config/scan-env");
|
|
53
53
|
const validate_scan_ai_1 = require("./config/validate-scan-ai");
|
|
54
54
|
const scan_sentry_1 = require("./observability/scan-sentry");
|
|
55
|
+
const fetch_failure_1 = require("./platform-api/fetch-failure");
|
|
55
56
|
const telemetry_client_1 = require("./platform-api/telemetry-client");
|
|
56
57
|
const cli_scan_failure_report_1 = require("./platform-api/cli-scan-failure-report");
|
|
57
58
|
const scan_config_schema_1 = require("./core/schema/scan-config.schema");
|
|
@@ -581,7 +582,7 @@ function createProgram() {
|
|
|
581
582
|
}
|
|
582
583
|
}
|
|
583
584
|
catch (err) {
|
|
584
|
-
const message =
|
|
585
|
+
const message = (0, fetch_failure_1.describeThrownError)(err);
|
|
585
586
|
fallbackFailureMessage = message;
|
|
586
587
|
const { CliScanQuotaExceededError, CliScanAlreadyRunningError } = await Promise.resolve().then(() => __importStar(require('./platform-api/scan-quota-client')));
|
|
587
588
|
const quotaBlocked = err instanceof CliScanQuotaExceededError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Socket-level fetch failures (no HTTP response), including Node's "fetch failed". */
|
|
2
|
+
export declare function isTransientFetchError(err: unknown): boolean;
|
|
3
|
+
/** Code plus cause text, without repeating the generic "fetch failed" wrapper. */
|
|
4
|
+
export declare function fetchFailureDetail(err: unknown): string;
|
|
5
|
+
export declare function describeRequestTarget(url: string, method: string): string;
|
|
6
|
+
export declare function toApiReachabilityError(err: unknown, url: string, method: string, attempts: number): Error;
|
|
7
|
+
/**
|
|
8
|
+
* Scan-command message. Unwraps a bare "fetch failed" when a caller did not
|
|
9
|
+
* already attach the request target.
|
|
10
|
+
*/
|
|
11
|
+
export declare function describeThrownError(err: unknown): string;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTransientFetchError = isTransientFetchError;
|
|
4
|
+
exports.fetchFailureDetail = fetchFailureDetail;
|
|
5
|
+
exports.describeRequestTarget = describeRequestTarget;
|
|
6
|
+
exports.toApiReachabilityError = toApiReachabilityError;
|
|
7
|
+
exports.describeThrownError = describeThrownError;
|
|
8
|
+
const TRANSIENT_CAUSE_CODES = new Set([
|
|
9
|
+
'ECONNRESET',
|
|
10
|
+
'ECONNREFUSED',
|
|
11
|
+
'EPIPE',
|
|
12
|
+
'ETIMEDOUT',
|
|
13
|
+
'EAI_AGAIN',
|
|
14
|
+
'ENOTFOUND',
|
|
15
|
+
'EHOSTUNREACH',
|
|
16
|
+
'ENETUNREACH',
|
|
17
|
+
'UND_ERR_SOCKET',
|
|
18
|
+
'UND_ERR_CONNECT_TIMEOUT',
|
|
19
|
+
'UND_ERR_HEADERS_TIMEOUT',
|
|
20
|
+
'UND_ERR_BODY_TIMEOUT',
|
|
21
|
+
]);
|
|
22
|
+
function readCause(err) {
|
|
23
|
+
if (!(err instanceof Error))
|
|
24
|
+
return undefined;
|
|
25
|
+
const cause = err.cause;
|
|
26
|
+
if (!cause || typeof cause !== 'object') {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const record = cause;
|
|
30
|
+
return {
|
|
31
|
+
code: typeof record.code === 'string' ? record.code : undefined,
|
|
32
|
+
message: typeof record.message === 'string' ? record.message : undefined,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Socket-level fetch failures (no HTTP response), including Node's "fetch failed". */
|
|
36
|
+
function isTransientFetchError(err) {
|
|
37
|
+
if (!(err instanceof Error))
|
|
38
|
+
return false;
|
|
39
|
+
const message = err.message.toLowerCase();
|
|
40
|
+
if (message === 'fetch failed' || message.includes('network'))
|
|
41
|
+
return true;
|
|
42
|
+
const code = readCause(err)?.code;
|
|
43
|
+
return Boolean(code && TRANSIENT_CAUSE_CODES.has(code));
|
|
44
|
+
}
|
|
45
|
+
/** Code plus cause text, without repeating the generic "fetch failed" wrapper. */
|
|
46
|
+
function fetchFailureDetail(err) {
|
|
47
|
+
if (!(err instanceof Error))
|
|
48
|
+
return String(err);
|
|
49
|
+
const cause = readCause(err);
|
|
50
|
+
const parts = [cause?.code, cause?.message].filter((part) => Boolean(part && part !== err.message));
|
|
51
|
+
if (parts.length === 0)
|
|
52
|
+
return err.message;
|
|
53
|
+
return parts.join(': ');
|
|
54
|
+
}
|
|
55
|
+
function describeRequestTarget(url, method) {
|
|
56
|
+
const verb = method.toUpperCase();
|
|
57
|
+
try {
|
|
58
|
+
const parsed = new URL(url);
|
|
59
|
+
return `${verb} ${parsed.origin}${parsed.pathname}`;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return `${verb} ${url}`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function toApiReachabilityError(err, url, method, attempts) {
|
|
66
|
+
const where = describeRequestTarget(url, method);
|
|
67
|
+
const detail = fetchFailureDetail(err);
|
|
68
|
+
const tries = attempts > 1 ? ` Tried ${attempts} times.` : '';
|
|
69
|
+
return new Error(`Could not reach the DataParade API (${where}): ${detail}.${tries} Run the scan again.`);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Scan-command message. Unwraps a bare "fetch failed" when a caller did not
|
|
73
|
+
* already attach the request target.
|
|
74
|
+
*/
|
|
75
|
+
function describeThrownError(err) {
|
|
76
|
+
if (!(err instanceof Error))
|
|
77
|
+
return 'Unknown error during scan.';
|
|
78
|
+
if (err.message !== 'fetch failed')
|
|
79
|
+
return err.message;
|
|
80
|
+
const detail = fetchFailureDetail(err);
|
|
81
|
+
if (detail === err.message) {
|
|
82
|
+
return 'Could not reach the DataParade API: fetch failed. Run the scan again.';
|
|
83
|
+
}
|
|
84
|
+
return `Could not reach the DataParade API: ${detail}. Run the scan again.`;
|
|
85
|
+
}
|
|
@@ -1,131 +1,202 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const platform_proxy_provider_1 = require("../../../src/ai-enrichment/providers/platform-proxy-provider");
|
|
4
|
-
describe(
|
|
4
|
+
describe('PlatformProxyProvider', () => {
|
|
5
5
|
const originalFetch = global.fetch;
|
|
6
6
|
afterEach(() => {
|
|
7
7
|
global.fetch = originalFetch;
|
|
8
8
|
});
|
|
9
|
-
it(
|
|
9
|
+
it('submits a task and polls until completed', async () => {
|
|
10
10
|
const calls = [];
|
|
11
11
|
global.fetch = jest.fn(async (input, init) => {
|
|
12
12
|
const url = String(input);
|
|
13
|
-
const method = init?.method ??
|
|
13
|
+
const method = init?.method ?? 'GET';
|
|
14
14
|
calls.push({ url, method });
|
|
15
|
-
if (url.endsWith(
|
|
15
|
+
if (url.endsWith('/api/scans/cli/ai/infer/tasks') &&
|
|
16
|
+
method === 'POST') {
|
|
16
17
|
return new Response(JSON.stringify({
|
|
17
|
-
tasks: [{ taskId:
|
|
18
|
+
tasks: [{ taskId: 't-1', status: 'pending' }],
|
|
18
19
|
}), { status: 202 });
|
|
19
20
|
}
|
|
20
|
-
if (url.includes(
|
|
21
|
-
|
|
21
|
+
if (url.includes('/api/scans/cli/ai/infer/tasks?') &&
|
|
22
|
+
method === 'GET') {
|
|
23
|
+
const done = calls.filter((c) => c.method === 'GET').length >= 2;
|
|
22
24
|
return new Response(JSON.stringify({
|
|
23
25
|
tasks: [
|
|
24
26
|
{
|
|
25
|
-
taskId:
|
|
26
|
-
status: done ?
|
|
27
|
-
proposals: [
|
|
27
|
+
taskId: 't-1',
|
|
28
|
+
status: done ? 'completed' : 'running',
|
|
29
|
+
proposals: [
|
|
30
|
+
{ kind: 'setProperties', candidateType: 'component' },
|
|
31
|
+
],
|
|
28
32
|
usage: { inputTokens: 1, outputTokens: 2, totalTokens: 3 },
|
|
29
33
|
},
|
|
30
34
|
],
|
|
31
35
|
}), { status: 200 });
|
|
32
36
|
}
|
|
33
|
-
return new Response(
|
|
37
|
+
return new Response('not found', { status: 404 });
|
|
34
38
|
});
|
|
35
39
|
const provider = new platform_proxy_provider_1.PlatformProxyProvider({
|
|
36
|
-
apiBaseUrl:
|
|
37
|
-
workspaceApiKey:
|
|
38
|
-
jobId:
|
|
40
|
+
apiBaseUrl: 'https://api.example.com',
|
|
41
|
+
workspaceApiKey: 'dp_test',
|
|
42
|
+
jobId: 'job-1',
|
|
39
43
|
pollIntervalMs: 1,
|
|
40
44
|
pollTimeoutMs: 5000,
|
|
41
45
|
});
|
|
42
46
|
const result = await provider.infer({
|
|
43
|
-
prompt:
|
|
44
|
-
model:
|
|
47
|
+
prompt: 'test',
|
|
48
|
+
model: 'gpt-4o-mini',
|
|
45
49
|
});
|
|
46
50
|
expect(result.proposals).toHaveLength(1);
|
|
47
51
|
expect(result.usage?.totalTokens).toBe(3);
|
|
48
|
-
expect(calls.some((c) => c.method ===
|
|
49
|
-
expect(calls.filter((c) => c.method ===
|
|
52
|
+
expect(calls.some((c) => c.method === 'POST')).toBe(true);
|
|
53
|
+
expect(calls.filter((c) => c.method === 'GET').length).toBeGreaterThanOrEqual(1);
|
|
50
54
|
});
|
|
51
|
-
it(
|
|
55
|
+
it('retries when a task fails because Lambda is still initializing', async () => {
|
|
52
56
|
let posts = 0;
|
|
53
57
|
global.fetch = jest.fn(async (input, init) => {
|
|
54
58
|
const url = String(input);
|
|
55
|
-
const method = init?.method ??
|
|
56
|
-
if (url.endsWith(
|
|
59
|
+
const method = init?.method ?? 'GET';
|
|
60
|
+
if (url.endsWith('/api/scans/cli/ai/infer/tasks') &&
|
|
61
|
+
method === 'POST') {
|
|
57
62
|
posts += 1;
|
|
58
63
|
return new Response(JSON.stringify({
|
|
59
|
-
tasks: [{ taskId: `t-${posts}`, status:
|
|
64
|
+
tasks: [{ taskId: `t-${posts}`, status: 'pending' }],
|
|
60
65
|
}), { status: 202 });
|
|
61
66
|
}
|
|
62
|
-
if (url.includes(
|
|
67
|
+
if (url.includes('taskIds=t-1') && method === 'GET') {
|
|
63
68
|
return new Response(JSON.stringify({
|
|
64
69
|
tasks: [
|
|
65
70
|
{
|
|
66
|
-
taskId:
|
|
67
|
-
status:
|
|
68
|
-
errorMessage:
|
|
71
|
+
taskId: 't-1',
|
|
72
|
+
status: 'failed',
|
|
73
|
+
errorMessage: 'ERROR: Lambda is initializing your function. It will be ready to invoke shortly.',
|
|
69
74
|
},
|
|
70
75
|
],
|
|
71
76
|
}), { status: 200 });
|
|
72
77
|
}
|
|
73
|
-
if (url.includes(
|
|
78
|
+
if (url.includes('taskIds=t-2') && method === 'GET') {
|
|
74
79
|
return new Response(JSON.stringify({
|
|
75
80
|
tasks: [
|
|
76
81
|
{
|
|
77
|
-
taskId:
|
|
78
|
-
status:
|
|
79
|
-
proposals: [
|
|
82
|
+
taskId: 't-2',
|
|
83
|
+
status: 'completed',
|
|
84
|
+
proposals: [
|
|
85
|
+
{ kind: 'setProperties', candidateType: 'component' },
|
|
86
|
+
],
|
|
80
87
|
usage: { inputTokens: 1, outputTokens: 2, totalTokens: 3 },
|
|
81
88
|
},
|
|
82
89
|
],
|
|
83
90
|
}), { status: 200 });
|
|
84
91
|
}
|
|
85
|
-
return new Response(
|
|
92
|
+
return new Response('not found', { status: 404 });
|
|
86
93
|
});
|
|
87
94
|
const provider = new platform_proxy_provider_1.PlatformProxyProvider({
|
|
88
|
-
apiBaseUrl:
|
|
89
|
-
workspaceApiKey:
|
|
90
|
-
jobId:
|
|
95
|
+
apiBaseUrl: 'https://api.example.com',
|
|
96
|
+
workspaceApiKey: 'dp_test',
|
|
97
|
+
jobId: 'job-1',
|
|
91
98
|
pollIntervalMs: 1,
|
|
92
99
|
pollTimeoutMs: 5000,
|
|
93
100
|
lambdaInitRetryDelaysMs: [0],
|
|
94
101
|
sleep: async () => undefined,
|
|
95
102
|
});
|
|
96
103
|
const result = await provider.infer({
|
|
97
|
-
prompt:
|
|
98
|
-
model:
|
|
104
|
+
prompt: 'test',
|
|
105
|
+
model: 'gpt-4o-mini',
|
|
99
106
|
});
|
|
100
107
|
expect(result.proposals).toHaveLength(1);
|
|
101
108
|
expect(posts).toBe(2);
|
|
102
109
|
});
|
|
103
|
-
it(
|
|
110
|
+
it('does not leak the AWS INIT message after retries are exhausted', async () => {
|
|
104
111
|
global.fetch = jest.fn(async (input, init) => {
|
|
105
112
|
const url = String(input);
|
|
106
|
-
const method = init?.method ??
|
|
107
|
-
if (url.endsWith(
|
|
108
|
-
|
|
113
|
+
const method = init?.method ?? 'GET';
|
|
114
|
+
if (url.endsWith('/api/scans/cli/ai/infer/tasks') &&
|
|
115
|
+
method === 'POST') {
|
|
116
|
+
return new Response(JSON.stringify({ tasks: [{ taskId: 't-1', status: 'pending' }] }), { status: 202 });
|
|
109
117
|
}
|
|
110
118
|
return new Response(JSON.stringify({
|
|
111
119
|
tasks: [
|
|
112
120
|
{
|
|
113
|
-
taskId:
|
|
114
|
-
status:
|
|
115
|
-
errorMessage:
|
|
121
|
+
taskId: 't-1',
|
|
122
|
+
status: 'failed',
|
|
123
|
+
errorMessage: 'ERROR: Lambda is initializing your function. It will be ready to invoke shortly.',
|
|
116
124
|
},
|
|
117
125
|
],
|
|
118
126
|
}), { status: 200 });
|
|
119
127
|
});
|
|
120
128
|
const provider = new platform_proxy_provider_1.PlatformProxyProvider({
|
|
121
|
-
apiBaseUrl:
|
|
122
|
-
workspaceApiKey:
|
|
123
|
-
jobId:
|
|
129
|
+
apiBaseUrl: 'https://api.example.com',
|
|
130
|
+
workspaceApiKey: 'dp_test',
|
|
131
|
+
jobId: 'job-1',
|
|
124
132
|
pollIntervalMs: 1,
|
|
125
133
|
pollTimeoutMs: 5000,
|
|
126
134
|
lambdaInitRetryDelaysMs: [0],
|
|
127
135
|
sleep: async () => undefined,
|
|
128
136
|
});
|
|
129
|
-
await expect(provider.infer({ prompt:
|
|
137
|
+
await expect(provider.infer({ prompt: 'test', model: 'gpt-4o-mini' })).rejects.toThrow('Platform AI is still starting');
|
|
138
|
+
});
|
|
139
|
+
it('retries a dropped connection and then completes the task', async () => {
|
|
140
|
+
let posts = 0;
|
|
141
|
+
global.fetch = jest.fn(async (input, init) => {
|
|
142
|
+
const url = String(input);
|
|
143
|
+
const method = init?.method ?? 'GET';
|
|
144
|
+
if (url.endsWith('/api/scans/cli/ai/infer/tasks') &&
|
|
145
|
+
method === 'POST') {
|
|
146
|
+
posts += 1;
|
|
147
|
+
if (posts === 1) {
|
|
148
|
+
const err = new TypeError('fetch failed');
|
|
149
|
+
err.cause = Object.assign(new Error('other side closed'), {
|
|
150
|
+
code: 'ECONNRESET',
|
|
151
|
+
});
|
|
152
|
+
throw err;
|
|
153
|
+
}
|
|
154
|
+
return new Response(JSON.stringify({ tasks: [{ taskId: 't-1', status: 'pending' }] }), { status: 202 });
|
|
155
|
+
}
|
|
156
|
+
return new Response(JSON.stringify({
|
|
157
|
+
tasks: [
|
|
158
|
+
{
|
|
159
|
+
taskId: 't-1',
|
|
160
|
+
status: 'completed',
|
|
161
|
+
proposals: [
|
|
162
|
+
{ kind: 'setProperties', candidateType: 'component' },
|
|
163
|
+
],
|
|
164
|
+
usage: { inputTokens: 1, outputTokens: 2, totalTokens: 3 },
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
}), { status: 200 });
|
|
168
|
+
});
|
|
169
|
+
const provider = new platform_proxy_provider_1.PlatformProxyProvider({
|
|
170
|
+
apiBaseUrl: 'http://localhost:3000',
|
|
171
|
+
workspaceApiKey: 'dp_anon_test',
|
|
172
|
+
jobId: 'job-1',
|
|
173
|
+
pollIntervalMs: 1,
|
|
174
|
+
pollTimeoutMs: 5000,
|
|
175
|
+
networkRetryDelaysMs: [0],
|
|
176
|
+
sleep: async () => undefined,
|
|
177
|
+
});
|
|
178
|
+
const result = await provider.infer({
|
|
179
|
+
prompt: 'test',
|
|
180
|
+
model: 'gpt-4o-mini',
|
|
181
|
+
});
|
|
182
|
+
expect(posts).toBe(2);
|
|
183
|
+
expect(result.usage?.totalTokens).toBe(3);
|
|
184
|
+
});
|
|
185
|
+
it('reports the socket cause after connection retries are exhausted', async () => {
|
|
186
|
+
global.fetch = jest.fn(async () => {
|
|
187
|
+
const err = new TypeError('fetch failed');
|
|
188
|
+
err.cause = Object.assign(new Error('other side closed'), {
|
|
189
|
+
code: 'ECONNRESET',
|
|
190
|
+
});
|
|
191
|
+
throw err;
|
|
192
|
+
});
|
|
193
|
+
const provider = new platform_proxy_provider_1.PlatformProxyProvider({
|
|
194
|
+
apiBaseUrl: 'http://localhost:3000',
|
|
195
|
+
workspaceApiKey: 'dp_anon_test',
|
|
196
|
+
jobId: 'job-1',
|
|
197
|
+
networkRetryDelaysMs: [0, 0],
|
|
198
|
+
sleep: async () => undefined,
|
|
199
|
+
});
|
|
200
|
+
await expect(provider.infer({ prompt: 'test', model: 'gpt-4o-mini' })).rejects.toThrow('Could not reach the DataParade API (POST http://localhost:3000/api/scans/cli/ai/infer/tasks): ECONNRESET: other side closed. Tried 3 times. Run the scan again.');
|
|
130
201
|
});
|
|
131
202
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fetch_failure_1 = require("../../../src/platform-api/fetch-failure");
|
|
4
|
+
describe('describeThrownError', () => {
|
|
5
|
+
it('unwraps a bare fetch failure and includes the socket cause', () => {
|
|
6
|
+
const err = new TypeError('fetch failed');
|
|
7
|
+
err.cause = Object.assign(new Error('other side closed'), {
|
|
8
|
+
code: 'ECONNRESET',
|
|
9
|
+
});
|
|
10
|
+
expect((0, fetch_failure_1.describeThrownError)(err)).toBe('Could not reach the DataParade API: ECONNRESET: other side closed. Run the scan again.');
|
|
11
|
+
});
|
|
12
|
+
it('keeps an error that already names the request', () => {
|
|
13
|
+
const err = new Error('Could not reach the DataParade API (POST http://localhost:3000/api/scans/cli/ai/infer/tasks): ECONNRESET: other side closed. Tried 3 times. Run the scan again.');
|
|
14
|
+
expect((0, fetch_failure_1.describeThrownError)(err)).toBe(err.message);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const langsmith_tracing_1 = require("../../../src/tracing/langsmith-tracing");
|
|
4
|
-
describe(
|
|
4
|
+
describe('tracing/langsmith-tracing', () => {
|
|
5
5
|
const originalEnv = process.env;
|
|
6
6
|
beforeEach(() => {
|
|
7
7
|
process.env = { ...originalEnv };
|
|
@@ -13,27 +13,31 @@ describe("tracing/langsmith-tracing", () => {
|
|
|
13
13
|
afterAll(() => {
|
|
14
14
|
process.env = originalEnv;
|
|
15
15
|
});
|
|
16
|
-
it(
|
|
16
|
+
it('isLangSmithTracingEnabled requires key and tracing flag', () => {
|
|
17
17
|
expect((0, langsmith_tracing_1.isLangSmithTracingEnabled)()).toBe(false);
|
|
18
|
-
process.env.LANGSMITH_API_KEY =
|
|
18
|
+
process.env.LANGSMITH_API_KEY = 'test-key';
|
|
19
19
|
expect((0, langsmith_tracing_1.isLangSmithTracingEnabled)()).toBe(false);
|
|
20
|
-
process.env.LANGCHAIN_TRACING_V2 =
|
|
20
|
+
process.env.LANGCHAIN_TRACING_V2 = 'true';
|
|
21
21
|
expect((0, langsmith_tracing_1.isLangSmithTracingEnabled)()).toBe(true);
|
|
22
22
|
});
|
|
23
|
-
it(
|
|
23
|
+
it('buildLangSmithScanTraceSummary omits full component payloads', () => {
|
|
24
24
|
const result = {
|
|
25
25
|
files: [],
|
|
26
|
-
findings: [
|
|
26
|
+
findings: [
|
|
27
|
+
{ pattern: 'x', name: 'n', confidence: 1, properties: {} },
|
|
28
|
+
],
|
|
29
|
+
occurrences: [],
|
|
30
|
+
dataItems: [],
|
|
27
31
|
scanResult: {
|
|
28
32
|
components: [
|
|
29
33
|
{
|
|
30
|
-
id:
|
|
31
|
-
name:
|
|
32
|
-
type:
|
|
34
|
+
id: 'cmp_1',
|
|
35
|
+
name: 'Payments API',
|
|
36
|
+
type: 'asset',
|
|
33
37
|
confidence: 0.9,
|
|
34
38
|
detectedFrom: [],
|
|
35
39
|
sourceLocations: [],
|
|
36
|
-
properties: { section_id:
|
|
40
|
+
properties: { section_id: 'packages/server' },
|
|
37
41
|
},
|
|
38
42
|
],
|
|
39
43
|
dataFlows: [],
|
|
@@ -41,7 +45,7 @@ describe("tracing/langsmith-tracing", () => {
|
|
|
41
45
|
filesSkipped: 1,
|
|
42
46
|
totalLines: 100,
|
|
43
47
|
scanDurationMs: 500,
|
|
44
|
-
warnings: [
|
|
48
|
+
warnings: ['w1'],
|
|
45
49
|
errors: [],
|
|
46
50
|
aiInferenceSummary: {
|
|
47
51
|
ran: true,
|
|
@@ -57,8 +61,8 @@ describe("tracing/langsmith-tracing", () => {
|
|
|
57
61
|
inputTokens: 10,
|
|
58
62
|
outputTokens: 5,
|
|
59
63
|
totalTokens: 15,
|
|
60
|
-
aiProvider:
|
|
61
|
-
aiModel:
|
|
64
|
+
aiProvider: 'mock',
|
|
65
|
+
aiModel: 'heuristic',
|
|
62
66
|
},
|
|
63
67
|
},
|
|
64
68
|
};
|
|
@@ -66,19 +70,19 @@ describe("tracing/langsmith-tracing", () => {
|
|
|
66
70
|
expect(summary.filesScanned).toBe(42);
|
|
67
71
|
expect(summary.componentCount).toBe(1);
|
|
68
72
|
expect(summary.findingCount).toBe(1);
|
|
69
|
-
expect(summary.sectionIds).toEqual([
|
|
70
|
-
expect(summary).not.toHaveProperty(
|
|
73
|
+
expect(summary.sectionIds).toEqual(['packages/server']);
|
|
74
|
+
expect(summary).not.toHaveProperty('components');
|
|
71
75
|
expect(summary.aiInference.proposalsGenerated).toBe(2);
|
|
72
76
|
});
|
|
73
|
-
it(
|
|
77
|
+
it('buildLangSmithInferencePipelineTraceSummary summarizes pipeline output', () => {
|
|
74
78
|
const summary = (0, langsmith_tracing_1.buildLangSmithInferencePipelineTraceSummary)({
|
|
75
|
-
candidates: [{ id:
|
|
79
|
+
candidates: [{ id: 'c1' }],
|
|
76
80
|
plan: { queues: [], droppedCandidates: [] },
|
|
77
|
-
proposals: [{ id:
|
|
81
|
+
proposals: [{ id: 'p1', proposal: {} }],
|
|
78
82
|
mergeResult: {
|
|
79
83
|
components: [],
|
|
80
84
|
dataFlows: [],
|
|
81
|
-
appliedProposalIds: [
|
|
85
|
+
appliedProposalIds: ['p1'],
|
|
82
86
|
rejectedProposalIds: [],
|
|
83
87
|
provenanceByTarget: {},
|
|
84
88
|
},
|
|
@@ -94,7 +98,7 @@ describe("tracing/langsmith-tracing", () => {
|
|
|
94
98
|
expect(summary.appliedProposalCount).toBe(1);
|
|
95
99
|
expect(summary.usageSummary).toEqual(expect.objectContaining({ providerCalls: 2, totalTokens: 150 }));
|
|
96
100
|
});
|
|
97
|
-
it(
|
|
101
|
+
it('buildLangSmithAiInferenceTraceSummary copies summary counters', () => {
|
|
98
102
|
const summary = (0, langsmith_tracing_1.buildLangSmithAiInferenceTraceSummary)({
|
|
99
103
|
ran: true,
|
|
100
104
|
candidatesConsidered: 5,
|
|
@@ -109,10 +113,10 @@ describe("tracing/langsmith-tracing", () => {
|
|
|
109
113
|
inputTokens: 20,
|
|
110
114
|
outputTokens: 10,
|
|
111
115
|
totalTokens: 30,
|
|
112
|
-
aiProvider:
|
|
113
|
-
aiModel:
|
|
116
|
+
aiProvider: 'openai',
|
|
117
|
+
aiModel: 'gpt-4',
|
|
114
118
|
});
|
|
115
119
|
expect(summary.proposalsGenerated).toBe(4);
|
|
116
|
-
expect(summary.aiProvider).toBe(
|
|
120
|
+
expect(summary.aiProvider).toBe('openai');
|
|
117
121
|
});
|
|
118
122
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataparade/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "dataPARADE CLI — scan codebases for privacy and security data flows",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"eval:models": "pnpm exec node dist/src/evals/run-model-matrix.js"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@dataparade/scanner": "github:DataParade-io/scanner#
|
|
57
|
+
"@dataparade/scanner": "github:DataParade-io/scanner#e66e1bcaef55b61214d170c617df529bd300fc89",
|
|
58
58
|
"@sentry/node": "^10.38.0",
|
|
59
59
|
"commander": "^12.1.0",
|
|
60
60
|
"dotenv": "^16.4.7",
|