@dataparade/cli 0.0.20 → 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.
@@ -6,96 +6,133 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const child_process_1 = require("child_process");
7
7
  const fs_1 = require("fs");
8
8
  const path_1 = __importDefault(require("path"));
9
- const cliDistPath = path_1.default.join(__dirname, "../../dist/bin/cli.js");
10
- const cliCwd = path_1.default.join(__dirname, "../../");
11
- const scanFixturePath = path_1.default.join(cliCwd, "tests/fixtures/typescript-basic");
12
- describe("CLI", () => {
9
+ const cliDistPath = path_1.default.join(__dirname, '../../dist/bin/cli.js');
10
+ const cliCwd = path_1.default.join(__dirname, '../../');
11
+ const scanFixturePath = path_1.default.join(cliCwd, 'tests/fixtures/typescript-basic');
12
+ describe('CLI', () => {
13
13
  beforeAll(() => {
14
14
  if (!(0, fs_1.existsSync)(cliDistPath)) {
15
15
  throw new Error(`CLI not built. Run 'pnpm build' first. Expected: ${cliDistPath}`);
16
16
  }
17
17
  });
18
- it("scan <path> writes a dataflow.json wrapper to the current directory and exits 0", () => {
19
- const result = (0, child_process_1.spawnSync)("node", [
18
+ it('scan <path> writes a dataflow.json wrapper to the current directory and exits 0', () => {
19
+ const result = (0, child_process_1.spawnSync)('node', [
20
20
  cliDistPath,
21
- "scan",
21
+ 'scan',
22
22
  scanFixturePath,
23
- "--no-ai-inference",
24
- "--skip-auto-upload",
23
+ '--no-ai-inference',
24
+ '--skip-auto-upload',
25
25
  ], {
26
- encoding: "utf-8",
26
+ encoding: 'utf-8',
27
27
  cwd: cliCwd,
28
28
  });
29
29
  expect(result.status).toBe(0);
30
- const outputPath = path_1.default.join(cliCwd, "dataflow.json");
30
+ const outputPath = path_1.default.join(cliCwd, 'dataflow.json');
31
31
  const exists = (0, fs_1.existsSync)(outputPath);
32
32
  expect(exists).toBe(true);
33
- const contents = (0, fs_1.readFileSync)(outputPath, "utf8").trim();
33
+ const contents = (0, fs_1.readFileSync)(outputPath, 'utf8').trim();
34
34
  const dataflow = JSON.parse(contents);
35
35
  expect(dataflow.schemaVersion).toBeDefined();
36
36
  expect(dataflow.graph).toBeDefined();
37
37
  expect(Array.isArray(dataflow.graph.nodes)).toBe(true);
38
38
  expect(Array.isArray(dataflow.graph.edges)).toBe(true);
39
39
  });
40
- it("scan fixture produces a dataflow.json wrapper with at least one node", () => {
41
- const result = (0, child_process_1.spawnSync)("node", [
40
+ it('scan fixture produces a dataflow.json wrapper with at least one node', () => {
41
+ const result = (0, child_process_1.spawnSync)('node', [
42
42
  cliDistPath,
43
- "scan",
43
+ 'scan',
44
44
  scanFixturePath,
45
- "--no-ai-inference",
46
- "--skip-auto-upload",
45
+ '--no-ai-inference',
46
+ '--skip-auto-upload',
47
47
  ], {
48
- encoding: "utf-8",
48
+ encoding: 'utf-8',
49
49
  cwd: cliCwd,
50
50
  });
51
51
  expect(result.status).toBe(0);
52
- const outputPath = path_1.default.join(cliCwd, "dataflow.json");
53
- const contents = (0, fs_1.readFileSync)(outputPath, "utf8").trim();
52
+ const outputPath = path_1.default.join(cliCwd, 'dataflow.json');
53
+ const contents = (0, fs_1.readFileSync)(outputPath, 'utf8').trim();
54
54
  const dataflow = JSON.parse(contents);
55
55
  expect(Array.isArray(dataflow.graph.nodes)).toBe(true);
56
56
  expect(dataflow.graph.nodes.length).toBeGreaterThan(0);
57
57
  });
58
- it("scan fixture --output writes a dataflow.json wrapper to the given file and prints a short message", () => {
59
- const outputFile = "scan-fixture-summary.json";
60
- const result = (0, child_process_1.spawnSync)("node", [
58
+ it('scan fixture --output writes a dataflow.json wrapper to the given file and prints a short message', () => {
59
+ const outputFile = 'scan-fixture-summary.json';
60
+ const result = (0, child_process_1.spawnSync)('node', [
61
61
  cliDistPath,
62
- "scan",
62
+ 'scan',
63
63
  scanFixturePath,
64
- "--output",
64
+ '--output',
65
65
  outputFile,
66
- "--no-ai-inference",
67
- "--skip-auto-upload",
66
+ '--no-ai-inference',
67
+ '--skip-auto-upload',
68
68
  ], {
69
- encoding: "utf-8",
69
+ encoding: 'utf-8',
70
70
  cwd: cliCwd,
71
71
  });
72
72
  expect(result.status).toBe(0);
73
73
  expect(result.stdout).toContain(`[scan] dataflow.json written to ${path_1.default.join(cliCwd, outputFile)}`);
74
- const fileContents = (0, fs_1.readFileSync)(path_1.default.join(cliCwd, outputFile), "utf8").trim();
74
+ const fileContents = (0, fs_1.readFileSync)(path_1.default.join(cliCwd, outputFile), 'utf8').trim();
75
75
  const dataflow = JSON.parse(fileContents);
76
76
  expect(dataflow.graph).toBeDefined();
77
77
  expect(Array.isArray(dataflow.graph.nodes)).toBe(true);
78
78
  });
79
- it("unknown command shows usage and exits non-zero", () => {
80
- const result = (0, child_process_1.spawnSync)("node", [cliDistPath, "unknowncommand"], {
81
- encoding: "utf-8",
79
+ it('scan mixed-language fixture prints teaching lines before dataflow.json written', () => {
80
+ const teachingFixture = path_1.default.join(cliCwd, 'tests/fixtures/mixed-language-basic');
81
+ const outputFile = 'scan-teaching-progress.json';
82
+ const result = (0, child_process_1.spawnSync)('node', [
83
+ cliDistPath,
84
+ 'scan',
85
+ teachingFixture,
86
+ '--output',
87
+ outputFile,
88
+ '--no-ai-inference',
89
+ '--skip-auto-upload',
90
+ ], {
91
+ encoding: 'utf-8',
92
+ cwd: cliCwd,
93
+ env: {
94
+ ...process.env,
95
+ // Force plain progress (no spinner/ANSI) for stable assertions.
96
+ NO_COLOR: '1',
97
+ },
98
+ });
99
+ expect(result.status).toBe(0);
100
+ const writtenMarker = `[scan] dataflow.json written to ${path_1.default.join(cliCwd, outputFile)}`;
101
+ expect(result.stdout).toContain(writtenMarker);
102
+ const beforeWrite = result.stdout.split(writtenMarker)[0] ?? '';
103
+ expect(beforeWrite).toMatch(/Map privacy data flows from your code/);
104
+ const teachingHits = [
105
+ /Found \d+ .+ routes?/i,
106
+ /Talks to /i,
107
+ /Calls out to /i,
108
+ /Stripe|OpenAI|Sentry|Postgres|Express|FastAPI/i,
109
+ ].filter((re) => re.test(beforeWrite));
110
+ expect(teachingHits.length).toBeGreaterThanOrEqual(2);
111
+ // Non-TTY / NO_COLOR: no ANSI escape codes and no braille spinner frames.
112
+ // eslint-disable-next-line no-control-regex -- asserting absence of ESC CSI sequences
113
+ expect(result.stdout).not.toMatch(/\x1b\[[0-9;]*m/);
114
+ expect(result.stdout).not.toMatch(/[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]/);
115
+ });
116
+ it('unknown command shows usage and exits non-zero', () => {
117
+ const result = (0, child_process_1.spawnSync)('node', [cliDistPath, 'unknowncommand'], {
118
+ encoding: 'utf-8',
82
119
  cwd: cliCwd,
83
120
  });
84
121
  expect(result.status).not.toBe(0);
85
122
  expect(result.stderr).toMatch(/Unknown command|error|usage|Usage/i);
86
123
  });
87
- it("--help shows usage", () => {
88
- const result = (0, child_process_1.spawnSync)("node", [cliDistPath, "--help"], {
89
- encoding: "utf-8",
124
+ it('--help shows usage', () => {
125
+ const result = (0, child_process_1.spawnSync)('node', [cliDistPath, '--help'], {
126
+ encoding: 'utf-8',
90
127
  cwd: cliCwd,
91
128
  });
92
129
  expect(result.status).toBe(0);
93
- expect(result.stdout).toContain("dataparade");
94
- expect(result.stdout).toContain("scan");
130
+ expect(result.stdout).toContain('dataparade');
131
+ expect(result.stdout).toContain('scan');
95
132
  });
96
- it("scan --help shows scan usage", () => {
97
- const result = (0, child_process_1.spawnSync)("node", [cliDistPath, "scan", "--help"], {
98
- encoding: "utf-8",
133
+ it('scan --help shows scan usage', () => {
134
+ const result = (0, child_process_1.spawnSync)('node', [cliDistPath, 'scan', '--help'], {
135
+ encoding: 'utf-8',
99
136
  cwd: cliCwd,
100
137
  });
101
138
  expect(result.status).toBe(0);
@@ -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 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const teaching_lines_1 = require("../../../src/ui/teaching-lines");
4
+ function finding(pattern, properties) {
5
+ return {
6
+ pattern,
7
+ name: pattern,
8
+ confidence: 0.9,
9
+ location: { filePath: 'x.ts', startLine: 1, endLine: 1 },
10
+ properties,
11
+ };
12
+ }
13
+ function thirdParty(serviceName) {
14
+ return {
15
+ id: `tp-${serviceName}`,
16
+ name: serviceName,
17
+ type: 'third_party',
18
+ confidence: 0.9,
19
+ detectedFrom: [],
20
+ properties: { serviceName },
21
+ sourceLocations: [],
22
+ };
23
+ }
24
+ describe('buildTeachingLineGroups', () => {
25
+ it('counts routes by framework', () => {
26
+ const groups = (0, teaching_lines_1.buildTeachingLineGroups)([
27
+ finding('express_route', { framework: 'express' }),
28
+ finding('express_route', { framework: 'express' }),
29
+ finding('express_route', { framework: 'nest' }),
30
+ ], []);
31
+ expect(groups.routes).toEqual([
32
+ 'Found 2 Express routes',
33
+ 'Found 1 Nest route',
34
+ ]);
35
+ });
36
+ it('formats data stores from client and databaseType without inventing Postgres', () => {
37
+ const groups = (0, teaching_lines_1.buildTeachingLineGroups)([
38
+ finding('database_connection', {
39
+ client: 'typeorm',
40
+ databaseType: 'sql',
41
+ }),
42
+ finding('database_connection', {
43
+ client: 'pg',
44
+ databaseType: 'postgres',
45
+ }),
46
+ ], []);
47
+ expect(groups.stores).toEqual([
48
+ 'Talks to SQL (TypeORM)',
49
+ 'Talks to Postgres (pg)',
50
+ ]);
51
+ });
52
+ it('coalesces outbound vendors from components and external_api_call findings', () => {
53
+ const groups = (0, teaching_lines_1.buildTeachingLineGroups)([finding('external_api_call', { serviceName: 'sentry' })], [thirdParty('stripe'), thirdParty('Stripe'), thirdParty('openai')]);
54
+ expect(groups.outbound).toEqual([
55
+ 'Calls out to OpenAI, Sentry, and Stripe',
56
+ ]);
57
+ });
58
+ it('returns empty groups when nothing recognized', () => {
59
+ const groups = (0, teaching_lines_1.buildTeachingLineGroups)([], []);
60
+ expect((0, teaching_lines_1.flattenTeachingLines)(groups)).toEqual([]);
61
+ });
62
+ });