@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.
Files changed (36) hide show
  1. package/README.md +12 -10
  2. package/dist/package.json +2 -1
  3. package/dist/src/ai-enrichment/providers/platform-proxy-provider.d.ts +4 -1
  4. package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +44 -18
  5. package/dist/src/cli.js +100 -52
  6. package/dist/src/config/scan-env.d.ts +5 -0
  7. package/dist/src/config/scan-env.js +12 -1
  8. package/dist/src/core/pipeline/scan-pipeline.d.ts +2 -1
  9. package/dist/src/core/pipeline/scan-pipeline.js +7 -4
  10. package/dist/src/platform-api/fetch-failure.d.ts +11 -0
  11. package/dist/src/platform-api/fetch-failure.js +85 -0
  12. package/dist/src/ui/brand.d.ts +28 -0
  13. package/dist/src/ui/brand.js +72 -0
  14. package/dist/src/ui/scan-progress-renderer.d.ts +69 -0
  15. package/dist/src/ui/scan-progress-renderer.js +386 -0
  16. package/dist/src/ui/teaching-lines.d.ts +9 -0
  17. package/dist/src/ui/teaching-lines.js +144 -0
  18. package/dist/src/ui/types.d.ts +33 -0
  19. package/dist/src/ui/types.js +2 -0
  20. package/dist/src/upload/run-upload.d.ts +1 -1
  21. package/dist/src/upload/run-upload.js +21 -16
  22. package/dist/src/upload/types.d.ts +4 -0
  23. package/dist/tests/cli/cli.spec.js +77 -40
  24. package/dist/tests/unit/ai-enrichment/platform-proxy-provider.spec.js +118 -47
  25. package/dist/tests/unit/cli/scan-quota-flow.spec.js +9 -0
  26. package/dist/tests/unit/config/scan-env-debug.spec.js +17 -8
  27. package/dist/tests/unit/platform-api/fetch-failure.spec.d.ts +1 -0
  28. package/dist/tests/unit/platform-api/fetch-failure.spec.js +16 -0
  29. package/dist/tests/unit/ui/brand.spec.d.ts +1 -0
  30. package/dist/tests/unit/ui/brand.spec.js +52 -0
  31. package/dist/tests/unit/ui/scan-progress-renderer.spec.d.ts +1 -0
  32. package/dist/tests/unit/ui/scan-progress-renderer.spec.js +275 -0
  33. package/dist/tests/unit/ui/teaching-lines.spec.d.ts +1 -0
  34. package/dist/tests/unit/ui/teaching-lines.spec.js +62 -0
  35. package/dist/tests/unit/upload/run-upload.spec.js +29 -27
  36. package/package.json +2 -1
@@ -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("PlatformProxyProvider", () => {
4
+ describe('PlatformProxyProvider', () => {
5
5
  const originalFetch = global.fetch;
6
6
  afterEach(() => {
7
7
  global.fetch = originalFetch;
8
8
  });
9
- it("submits a task and polls until completed", async () => {
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 ?? "GET";
13
+ const method = init?.method ?? 'GET';
14
14
  calls.push({ url, method });
15
- if (url.endsWith("/api/scans/cli/ai/infer/tasks") && method === "POST") {
15
+ if (url.endsWith('/api/scans/cli/ai/infer/tasks') &&
16
+ method === 'POST') {
16
17
  return new Response(JSON.stringify({
17
- tasks: [{ taskId: "t-1", status: "pending" }],
18
+ tasks: [{ taskId: 't-1', status: 'pending' }],
18
19
  }), { status: 202 });
19
20
  }
20
- if (url.includes("/api/scans/cli/ai/infer/tasks?") && method === "GET") {
21
- const done = calls.filter((c) => c.method === "GET").length >= 2;
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: "t-1",
26
- status: done ? "completed" : "running",
27
- proposals: [{ kind: "setProperties", candidateType: "component" }],
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("not found", { status: 404 });
37
+ return new Response('not found', { status: 404 });
34
38
  });
35
39
  const provider = new platform_proxy_provider_1.PlatformProxyProvider({
36
- apiBaseUrl: "https://api.example.com",
37
- workspaceApiKey: "dp_test",
38
- jobId: "job-1",
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: "test",
44
- model: "gpt-4o-mini",
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 === "POST")).toBe(true);
49
- expect(calls.filter((c) => c.method === "GET").length).toBeGreaterThanOrEqual(1);
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("retries when a task fails because Lambda is still initializing", async () => {
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 ?? "GET";
56
- if (url.endsWith("/api/scans/cli/ai/infer/tasks") && method === "POST") {
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: "pending" }],
64
+ tasks: [{ taskId: `t-${posts}`, status: 'pending' }],
60
65
  }), { status: 202 });
61
66
  }
62
- if (url.includes("taskIds=t-1") && method === "GET") {
67
+ if (url.includes('taskIds=t-1') && method === 'GET') {
63
68
  return new Response(JSON.stringify({
64
69
  tasks: [
65
70
  {
66
- taskId: "t-1",
67
- status: "failed",
68
- errorMessage: "ERROR: Lambda is initializing your function. It will be ready to invoke shortly.",
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("taskIds=t-2") && method === "GET") {
78
+ if (url.includes('taskIds=t-2') && method === 'GET') {
74
79
  return new Response(JSON.stringify({
75
80
  tasks: [
76
81
  {
77
- taskId: "t-2",
78
- status: "completed",
79
- proposals: [{ kind: "setProperties", candidateType: "component" }],
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("not found", { status: 404 });
92
+ return new Response('not found', { status: 404 });
86
93
  });
87
94
  const provider = new platform_proxy_provider_1.PlatformProxyProvider({
88
- apiBaseUrl: "https://api.example.com",
89
- workspaceApiKey: "dp_test",
90
- jobId: "job-1",
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: "test",
98
- model: "gpt-4o-mini",
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("does not leak the AWS INIT message after retries are exhausted", async () => {
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 ?? "GET";
107
- if (url.endsWith("/api/scans/cli/ai/infer/tasks") && method === "POST") {
108
- return new Response(JSON.stringify({ tasks: [{ taskId: "t-1", status: "pending" }] }), { status: 202 });
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: "t-1",
114
- status: "failed",
115
- errorMessage: "ERROR: Lambda is initializing your function. It will be ready to invoke shortly.",
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: "https://api.example.com",
122
- workspaceApiKey: "dp_test",
123
- jobId: "job-1",
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: "test", model: "gpt-4o-mini" })).rejects.toThrow("Platform AI is still starting");
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
  });
@@ -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("isScanAiDebugEnabled", () => {
5
- it("accepts SCAN_AI_DEBUG", () => {
6
- expect((0, scan_env_1.isScanAiDebugEnabled)({ SCAN_AI_DEBUG: "true" })).toBe(true);
4
+ describe('isScanAiDebugEnabled', () => {
5
+ afterEach(() => {
6
+ (0, scan_env_1.setScanAiDebugSuppressed)(false);
7
7
  });
8
- it("ignores legacy DATAPARADE_AI_DEBUG", () => {
9
- expect((0, scan_env_1.isScanAiDebugEnabled)({ DATAPARADE_AI_DEBUG: "1" })).toBe(false);
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("uses SCAN_AI_DEBUG only when legacy is also present", () => {
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: "false",
14
- DATAPARADE_AI_DEBUG: "true",
22
+ SCAN_AI_DEBUG: 'false',
23
+ DATAPARADE_AI_DEBUG: 'true',
15
24
  })).toBe(false);
16
25
  });
17
26
  });
@@ -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
+ });
@@ -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,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
+ });