@delegance/claude-autopilot 7.7.0 → 7.8.0
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/CHANGELOG.md +52 -0
- package/README.md +19 -0
- package/bin/_launcher.js +310 -6
- package/dist/src/cli/dashboard/missing-package.d.ts +48 -0
- package/dist/src/cli/dashboard/missing-package.js +85 -0
- package/dist/src/cli/dashboard/upload.d.ts +1 -1
- package/dist/src/cli/dashboard/upload.js +20 -1
- package/dist/src/cli/help-text.d.ts +1 -1
- package/dist/src/cli/help-text.js +11 -1
- package/dist/src/cli/index.js +30 -0
- package/dist/src/cli/tsx-resolver.d.ts +42 -0
- package/dist/src/cli/tsx-resolver.js +376 -0
- package/package.json +4 -7
- package/scripts/autoregress.ts +0 -402
- package/scripts/snapshots/impact-selector.ts +0 -60
- package/scripts/snapshots/import-scanner.ts +0 -44
- package/scripts/snapshots/serializer.ts +0 -24
- package/tests/snapshots/baselines/.gitkeep +0 -0
- package/tests/snapshots/baselines/src-formatters-sarif.json +0 -210
- package/tests/snapshots/baselines/src-snapshots-impact-selector.json +0 -32
- package/tests/snapshots/baselines/src-snapshots-import-scanner.json +0 -21
- package/tests/snapshots/baselines/src-snapshots-serializer.json +0 -39
- package/tests/snapshots/import-map.json +0 -138
- package/tests/snapshots/index.json +0 -14
- package/tests/snapshots/src-formatters-sarif.snap.ts +0 -132
- package/tests/snapshots/src-snapshots-impact-selector.snap.ts +0 -95
- package/tests/snapshots/src-snapshots-import-scanner.snap.ts +0 -126
- package/tests/snapshots/src-snapshots-serializer.snap.ts +0 -64
package/scripts/autoregress.ts
DELETED
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// scripts/autoregress.ts
|
|
3
|
-
import * as fs from 'node:fs';
|
|
4
|
-
import * as path from 'node:path';
|
|
5
|
-
import * as os from 'node:os';
|
|
6
|
-
import { spawnSync } from 'node:child_process';
|
|
7
|
-
import { fileURLToPath } from 'node:url';
|
|
8
|
-
import { selectSnapshots } from './snapshots/impact-selector.ts';
|
|
9
|
-
import { loadOpenAI } from '../src/adapters/sdk-loader.ts';
|
|
10
|
-
import { buildImportMap } from './snapshots/import-scanner.ts';
|
|
11
|
-
|
|
12
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
const ROOT = path.resolve(__dirname, '..');
|
|
14
|
-
const SNAPSHOTS_DIR = path.join(ROOT, 'tests', 'snapshots');
|
|
15
|
-
const INDEX_PATH = path.join(SNAPSHOTS_DIR, 'index.json');
|
|
16
|
-
const IMPORT_MAP_PATH = path.join(SNAPSHOTS_DIR, 'import-map.json');
|
|
17
|
-
const BASELINES_DIR = path.join(SNAPSHOTS_DIR, 'baselines');
|
|
18
|
-
|
|
19
|
-
function loadJson<T>(p: string, fallback: T): T {
|
|
20
|
-
try { return JSON.parse(fs.readFileSync(p, 'utf8')) as T; } catch { return fallback; }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function diffBaselines(baselineJson: string, currentJson: string): string[] {
|
|
24
|
-
if (baselineJson === currentJson) return [];
|
|
25
|
-
const baselineLines = baselineJson.split('\n');
|
|
26
|
-
const currentLines = currentJson.split('\n');
|
|
27
|
-
const lines: string[] = [];
|
|
28
|
-
const maxLen = Math.max(baselineLines.length, currentLines.length);
|
|
29
|
-
for (let i = 0; i < maxLen; i++) {
|
|
30
|
-
const bLine = baselineLines[i];
|
|
31
|
-
const cLine = currentLines[i];
|
|
32
|
-
if (bLine === cLine) continue;
|
|
33
|
-
if (bLine !== undefined) lines.push(`- ${bLine}`);
|
|
34
|
-
if (cLine !== undefined) lines.push(`+ ${cLine}`);
|
|
35
|
-
}
|
|
36
|
-
return lines;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function getChangedFiles(since?: string): string[] | null {
|
|
40
|
-
try {
|
|
41
|
-
let base = since;
|
|
42
|
-
if (!base) {
|
|
43
|
-
const r = spawnSync('git', ['merge-base', 'origin/main', 'HEAD'], { cwd: ROOT, encoding: 'utf8' });
|
|
44
|
-
if (r.status !== 0) return null;
|
|
45
|
-
base = r.stdout.trim();
|
|
46
|
-
}
|
|
47
|
-
const r = spawnSync('git', ['diff', base, 'HEAD', '--name-only'], { cwd: ROOT, encoding: 'utf8' });
|
|
48
|
-
if (r.status !== 0) return null;
|
|
49
|
-
return r.stdout.trim().split('\n').filter(Boolean);
|
|
50
|
-
} catch { return null; }
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function allSnapFiles(): string[] {
|
|
54
|
-
if (!fs.existsSync(SNAPSHOTS_DIR)) return [];
|
|
55
|
-
return fs.readdirSync(SNAPSHOTS_DIR)
|
|
56
|
-
.filter(f => f.endsWith('.snap.ts'))
|
|
57
|
-
.map(f => path.join('tests', 'snapshots', f));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function runSnapshot(snapFile: string, capture: boolean): 'pass' | 'fail' | 'baseline-missing' | 'stale' {
|
|
61
|
-
const absSnap = path.join(ROOT, snapFile);
|
|
62
|
-
const content = fs.readFileSync(absSnap, 'utf8');
|
|
63
|
-
const forMatch = content.match(/@snapshot-for:\s*(.+)/);
|
|
64
|
-
if (forMatch) {
|
|
65
|
-
const src = forMatch[1]!.trim();
|
|
66
|
-
if (!fs.existsSync(path.join(ROOT, src))) {
|
|
67
|
-
console.warn(` [warn] stale — source gone: ${src}`);
|
|
68
|
-
return 'stale';
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const slug = path.basename(snapFile, '.snap.ts');
|
|
73
|
-
const baselinePath = path.join(BASELINES_DIR, `${slug}.json`);
|
|
74
|
-
if (!capture && !fs.existsSync(baselinePath)) {
|
|
75
|
-
console.error(` [fail] baseline missing: ${baselinePath}`);
|
|
76
|
-
return 'baseline-missing';
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const env = { ...process.env };
|
|
80
|
-
if (capture) env.CAPTURE_BASELINE = '1';
|
|
81
|
-
else delete env.CAPTURE_BASELINE;
|
|
82
|
-
|
|
83
|
-
const result = spawnSync('node', ['--test', '--import', 'tsx', absSnap], {
|
|
84
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
85
|
-
cwd: ROOT,
|
|
86
|
-
env,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
if (result.status === 0) return 'pass';
|
|
90
|
-
if (capture) return 'pass';
|
|
91
|
-
console.error(` ${(result.stderr?.toString() ?? '') || (result.stdout?.toString() ?? '')}`);
|
|
92
|
-
return 'fail';
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function cmdRun(args: string[]): number {
|
|
96
|
-
const runAll = args.includes('--all');
|
|
97
|
-
const sinceIdx = args.indexOf('--since');
|
|
98
|
-
const since = sinceIdx >= 0 ? args[sinceIdx + 1] : undefined;
|
|
99
|
-
const index = loadJson<Record<string, string[]>>(INDEX_PATH, {});
|
|
100
|
-
const importMap = loadJson<Record<string, string[]>>(IMPORT_MAP_PATH, {});
|
|
101
|
-
const snapFiles = allSnapFiles();
|
|
102
|
-
|
|
103
|
-
let selected: string[];
|
|
104
|
-
if (runAll || snapFiles.length === 0) {
|
|
105
|
-
selected = snapFiles;
|
|
106
|
-
console.log(`[autoregress run] --all: running ${snapFiles.length} snapshot(s)`);
|
|
107
|
-
} else {
|
|
108
|
-
const changed = getChangedFiles(since);
|
|
109
|
-
if (!changed) {
|
|
110
|
-
console.warn('[autoregress run] merge-base resolution failed — running all');
|
|
111
|
-
selected = snapFiles;
|
|
112
|
-
} else {
|
|
113
|
-
const r = selectSnapshots(changed, snapFiles, index, importMap);
|
|
114
|
-
selected = r.selected;
|
|
115
|
-
console.log(`[autoregress run] ${r.reason} (${selected.length}/${snapFiles.length})`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (selected.length === 0) {
|
|
120
|
-
console.log('[autoregress run] no snapshots to run — pass');
|
|
121
|
-
return 0;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
let passed = 0, failed = 0, missing = 0, stale = 0;
|
|
125
|
-
for (const snap of selected) {
|
|
126
|
-
process.stdout.write(` ${snap} ... `);
|
|
127
|
-
const v = runSnapshot(snap, false);
|
|
128
|
-
if (v === 'pass') { passed++; console.log('pass'); }
|
|
129
|
-
else if (v === 'fail') { failed++; console.log('FAIL'); }
|
|
130
|
-
else if (v === 'baseline-missing') { missing++; console.log('BASELINE MISSING'); }
|
|
131
|
-
else { stale++; console.log('stale (skipped)'); }
|
|
132
|
-
}
|
|
133
|
-
console.log(`\n ${passed} passed ${failed} failed ${missing} baseline-missing ${stale} stale`);
|
|
134
|
-
return failed > 0 || missing > 0 ? 1 : 0;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function cmdUpdate(args: string[]): number {
|
|
138
|
-
const snapIdx = args.indexOf('--snapshot');
|
|
139
|
-
const slug = snapIdx >= 0 ? args[snapIdx + 1] : undefined;
|
|
140
|
-
const snapFiles = slug
|
|
141
|
-
? [path.join('tests', 'snapshots', `${slug}.snap.ts`)]
|
|
142
|
-
: allSnapFiles();
|
|
143
|
-
console.log(`[autoregress update] rewriting ${snapFiles.length} baseline(s)`);
|
|
144
|
-
let failed = 0;
|
|
145
|
-
for (const snap of snapFiles) {
|
|
146
|
-
const absSnap = path.join(ROOT, snap);
|
|
147
|
-
if (!fs.existsSync(absSnap)) {
|
|
148
|
-
console.error(` [error] snapshot file not found: ${snap}`);
|
|
149
|
-
failed++;
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
process.stdout.write(` ${snap} ... `);
|
|
153
|
-
const slug2 = path.basename(snap, '.snap.ts');
|
|
154
|
-
const baselinePath = path.join(BASELINES_DIR, `${slug2}.json`);
|
|
155
|
-
const beforeMtime = fs.existsSync(baselinePath) ? fs.statSync(baselinePath).mtimeMs : 0;
|
|
156
|
-
runSnapshot(snap, true);
|
|
157
|
-
const captured = fs.existsSync(baselinePath) && fs.statSync(baselinePath).mtimeMs > beforeMtime;
|
|
158
|
-
if (captured) {
|
|
159
|
-
console.log('updated');
|
|
160
|
-
} else {
|
|
161
|
-
console.error('CAPTURE FAILED (baseline not written)');
|
|
162
|
-
failed++;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return failed > 0 ? 1 : 0;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const GENERATOR_VERSION = '1.0.0-alpha.6';
|
|
169
|
-
|
|
170
|
-
const GENERATE_PROMPT = `You are generating a behavioral snapshot test for a TypeScript module.
|
|
171
|
-
|
|
172
|
-
Module path: {filePath}
|
|
173
|
-
Module contents:
|
|
174
|
-
{fileContents}
|
|
175
|
-
|
|
176
|
-
Write a snapshot test file. Requirements:
|
|
177
|
-
1. Header comments at top:
|
|
178
|
-
// @snapshot-for: {filePath}
|
|
179
|
-
// @generated-at: {generatedAt}
|
|
180
|
-
// @source-commit: {sourceCommit}
|
|
181
|
-
// @generator-version: {version}
|
|
182
|
-
2. Import the module's exported functions under test
|
|
183
|
-
3. Import { normalizeSnapshot } from '../../scripts/snapshots/serializer.ts'
|
|
184
|
-
4. Import fs from 'node:fs', describe/it from 'node:test', assert from 'node:assert/strict'
|
|
185
|
-
5. Baseline loading pattern (use slug {slug}):
|
|
186
|
-
const SLUG = '{slug}';
|
|
187
|
-
import { fileURLToPath } from 'node:url';
|
|
188
|
-
import * as path from 'node:path';
|
|
189
|
-
const baselineRaw = process.env.CAPTURE_BASELINE === '1' ? '{}' : fs.readFileSync(fileURLToPath(new URL('./baselines/{slug}.json', import.meta.url)), 'utf8');
|
|
190
|
-
const baseline = JSON.parse(baselineRaw);
|
|
191
|
-
const captured: Record<string, unknown> = {};
|
|
192
|
-
process.on('exit', () => {
|
|
193
|
-
if (process.env.CAPTURE_BASELINE === '1') {
|
|
194
|
-
const p = process.env.AUTOREGRESS_TEMP_BASELINE_DIR
|
|
195
|
-
? path.join(process.env.AUTOREGRESS_TEMP_BASELINE_DIR, '{slug}.json')
|
|
196
|
-
: fileURLToPath(new URL('./baselines/{slug}.json', import.meta.url));
|
|
197
|
-
fs.writeFileSync(p, JSON.stringify(captured, null, 2), 'utf8');
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
6. In each test: if (process.env.CAPTURE_BASELINE === '1') { captured['test-name'] = result; return; }
|
|
201
|
-
Else: assert.equal(normalizeSnapshot(result), normalizeSnapshot(baseline['test-name']));
|
|
202
|
-
7. Write 2-4 it() tests covering representative behaviors
|
|
203
|
-
8. Output ONLY the TypeScript file contents, no markdown fences, no explanation`;
|
|
204
|
-
|
|
205
|
-
async function cmdGenerate(args: string[]): Promise<number> {
|
|
206
|
-
const apiKey = process.env.OPENAI_API_KEY;
|
|
207
|
-
if (!apiKey) { console.error('[autoregress generate] OPENAI_API_KEY not set'); return 1; }
|
|
208
|
-
|
|
209
|
-
const sinceIdx = args.indexOf('--since');
|
|
210
|
-
const since = sinceIdx >= 0 ? args[sinceIdx + 1] : undefined;
|
|
211
|
-
const filesIdx = args.indexOf('--files');
|
|
212
|
-
const filesArg = filesIdx >= 0 ? args[filesIdx + 1] : undefined;
|
|
213
|
-
|
|
214
|
-
let srcFiles: string[];
|
|
215
|
-
if (filesArg) {
|
|
216
|
-
srcFiles = filesArg.split(',').map(f => f.trim()).filter(f => f.startsWith('src/') && f.endsWith('.ts'));
|
|
217
|
-
if (srcFiles.length === 0) {
|
|
218
|
-
console.error('[autoregress generate] --files must contain at least one src/*.ts path');
|
|
219
|
-
return 1;
|
|
220
|
-
}
|
|
221
|
-
} else {
|
|
222
|
-
const changed = getChangedFiles(since);
|
|
223
|
-
if (!changed) { console.error('[autoregress generate] could not determine changed files'); return 1; }
|
|
224
|
-
srcFiles = changed.filter(f => f.startsWith('src/') && f.endsWith('.ts'));
|
|
225
|
-
if (srcFiles.length === 0) {
|
|
226
|
-
console.log('[autoregress generate] no src/*.ts files changed — nothing to generate');
|
|
227
|
-
return 0;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
console.log(`[autoregress generate] generating snapshots for ${srcFiles.length} file(s)`);
|
|
232
|
-
|
|
233
|
-
const OpenAI = await loadOpenAI();
|
|
234
|
-
const client = new OpenAI({ apiKey });
|
|
235
|
-
let sourceCommit = 'unknown';
|
|
236
|
-
try {
|
|
237
|
-
const r = spawnSync('git', ['rev-parse', '--short', 'HEAD'], { cwd: ROOT, encoding: 'utf8' });
|
|
238
|
-
if (r.status === 0) sourceCommit = r.stdout.trim();
|
|
239
|
-
} catch {}
|
|
240
|
-
const generatedAt = new Date().toISOString();
|
|
241
|
-
|
|
242
|
-
for (const srcFile of srcFiles) {
|
|
243
|
-
const absFile = path.join(ROOT, srcFile);
|
|
244
|
-
if (!fs.existsSync(absFile)) { console.warn(` skip (not found): ${srcFile}`); continue; }
|
|
245
|
-
|
|
246
|
-
const fileContents = fs.readFileSync(absFile, 'utf8');
|
|
247
|
-
const slug = srcFile.replace(/[/\\]/g, '-').replace(/\.ts$/, '');
|
|
248
|
-
|
|
249
|
-
process.stdout.write(` ${srcFile} → ${slug}.snap.ts ... `);
|
|
250
|
-
|
|
251
|
-
const prompt = GENERATE_PROMPT
|
|
252
|
-
.replace(/{filePath}/g, srcFile)
|
|
253
|
-
.replace(/{fileContents}/g, fileContents)
|
|
254
|
-
.replace(/{slug}/g, slug)
|
|
255
|
-
.replace(/{version}/g, GENERATOR_VERSION)
|
|
256
|
-
.replace(/{generatedAt}/g, generatedAt)
|
|
257
|
-
.replace(/{sourceCommit}/g, sourceCommit);
|
|
258
|
-
|
|
259
|
-
let snapContent: string;
|
|
260
|
-
try {
|
|
261
|
-
const response = await client.responses.create({
|
|
262
|
-
model: process.env.CODEX_MODEL ?? 'gpt-5.5',
|
|
263
|
-
instructions: 'You write TypeScript snapshot tests. Output ONLY the file contents, no markdown fences.',
|
|
264
|
-
input: prompt,
|
|
265
|
-
max_output_tokens: 2000,
|
|
266
|
-
});
|
|
267
|
-
snapContent = (response.output_text ?? '').replace(/^```typescript\n?/m, '').replace(/```$/m, '').trim();
|
|
268
|
-
} catch (err) {
|
|
269
|
-
console.error(`LLM error: ${err instanceof Error ? err.message : String(err)}`);
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const snapPath = path.join(SNAPSHOTS_DIR, `${slug}.snap.ts`);
|
|
274
|
-
fs.writeFileSync(snapPath, snapContent + '\n', 'utf8');
|
|
275
|
-
|
|
276
|
-
const captureResult = spawnSync('node', ['--test', '--import', 'tsx', snapPath], {
|
|
277
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
278
|
-
cwd: ROOT,
|
|
279
|
-
env: { ...process.env, CAPTURE_BASELINE: '1' },
|
|
280
|
-
});
|
|
281
|
-
const baselinePath = path.join(BASELINES_DIR, `${slug}.json`);
|
|
282
|
-
console.log(fs.existsSync(baselinePath) ? 'generated + baseline captured' :
|
|
283
|
-
`generated (capture failed: ${captureResult.stderr?.toString().slice(0, 60)})`);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// Rebuild index.json from @snapshot-for headers
|
|
287
|
-
const newIndex: Record<string, string[]> = {};
|
|
288
|
-
for (const f of fs.readdirSync(SNAPSHOTS_DIR).filter(x => x.endsWith('.snap.ts'))) {
|
|
289
|
-
const snapRelPath = path.join('tests', 'snapshots', f);
|
|
290
|
-
const content = fs.readFileSync(path.join(SNAPSHOTS_DIR, f), 'utf8');
|
|
291
|
-
const sources = [...content.matchAll(/@snapshot-for:\s*(.+)/g)].map(m => m[1]!.trim());
|
|
292
|
-
if (sources.length) newIndex[snapRelPath] = sources;
|
|
293
|
-
}
|
|
294
|
-
fs.writeFileSync(INDEX_PATH, JSON.stringify(newIndex, null, 2) + '\n', 'utf8');
|
|
295
|
-
|
|
296
|
-
// Rebuild import-map.json — prefix keys/values with 'src/' to match repo-relative git diff paths
|
|
297
|
-
const rawImportMap = buildImportMap(path.join(ROOT, 'src'));
|
|
298
|
-
const newImportMap: Record<string, string[]> = {};
|
|
299
|
-
for (const [dep, importers] of Object.entries(rawImportMap)) {
|
|
300
|
-
newImportMap[`src/${dep}`] = importers.map(i => `src/${i}`);
|
|
301
|
-
}
|
|
302
|
-
fs.writeFileSync(IMPORT_MAP_PATH, JSON.stringify(newImportMap, null, 2) + '\n', 'utf8');
|
|
303
|
-
|
|
304
|
-
console.log('\n[autoregress generate] index.json + import-map.json rebuilt');
|
|
305
|
-
return 0;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
function cmdDiff(args: string[]): number {
|
|
309
|
-
const runAll = args.includes('--all');
|
|
310
|
-
const snapIdx = args.indexOf('--snapshot');
|
|
311
|
-
const slug = snapIdx >= 0 ? args[snapIdx + 1] : undefined;
|
|
312
|
-
const sinceIdx = args.indexOf('--since');
|
|
313
|
-
const since = sinceIdx >= 0 ? args[sinceIdx + 1] : undefined;
|
|
314
|
-
|
|
315
|
-
const index = loadJson<Record<string, string[]>>(INDEX_PATH, {});
|
|
316
|
-
const importMap = loadJson<Record<string, string[]>>(IMPORT_MAP_PATH, {});
|
|
317
|
-
const snapFiles = slug
|
|
318
|
-
? [path.join('tests', 'snapshots', `${slug}.snap.ts`)]
|
|
319
|
-
: allSnapFiles();
|
|
320
|
-
|
|
321
|
-
let selected: string[];
|
|
322
|
-
if (runAll || slug || snapFiles.length === 0) {
|
|
323
|
-
selected = snapFiles;
|
|
324
|
-
} else {
|
|
325
|
-
const changed = getChangedFiles(since);
|
|
326
|
-
selected = changed ? selectSnapshots(changed, snapFiles, index, importMap).selected : snapFiles;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (selected.length === 0) {
|
|
330
|
-
console.log('[autoregress diff] no snapshots to diff');
|
|
331
|
-
return 0;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
335
|
-
const red = useColor ? '\x1b[31m' : '';
|
|
336
|
-
const green = useColor ? '\x1b[32m' : '';
|
|
337
|
-
const reset = useColor ? '\x1b[0m' : '';
|
|
338
|
-
|
|
339
|
-
let changedCount = 0;
|
|
340
|
-
for (const snap of selected) {
|
|
341
|
-
const slug_ = path.basename(snap, '.snap.ts');
|
|
342
|
-
const baselinePath = path.join(BASELINES_DIR, `${slug_}.json`);
|
|
343
|
-
|
|
344
|
-
if (!fs.existsSync(baselinePath)) {
|
|
345
|
-
console.log(` ${snap} — ${red}no baseline${reset}`);
|
|
346
|
-
continue;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const tmpBaselinesDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ar-diff-'));
|
|
350
|
-
const tmpBaselinePath = path.join(tmpBaselinesDir, `${slug_}.json`);
|
|
351
|
-
fs.copyFileSync(baselinePath, tmpBaselinePath);
|
|
352
|
-
|
|
353
|
-
const absSnap = path.join(ROOT, snap);
|
|
354
|
-
const captureResult = spawnSync('node', ['--test', '--import', 'tsx', absSnap], {
|
|
355
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
356
|
-
cwd: ROOT,
|
|
357
|
-
env: { ...process.env, CAPTURE_BASELINE: '1', AUTOREGRESS_TEMP_BASELINE_DIR: tmpBaselinesDir },
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
const baselineJson = fs.readFileSync(baselinePath, 'utf8');
|
|
361
|
-
const captureOk = fs.existsSync(tmpBaselinePath);
|
|
362
|
-
const currentJson = captureOk ? fs.readFileSync(tmpBaselinePath, 'utf8') : null;
|
|
363
|
-
if (!captureOk && captureResult.status !== 0) {
|
|
364
|
-
const stderr = captureResult.stderr?.toString().trim();
|
|
365
|
-
if (stderr) console.error(` ${stderr.slice(0, 120)}`);
|
|
366
|
-
}
|
|
367
|
-
fs.rmSync(tmpBaselinesDir, { recursive: true, force: true });
|
|
368
|
-
|
|
369
|
-
if (!currentJson) {
|
|
370
|
-
console.log(` ${snap} — ${red}capture failed${reset}`);
|
|
371
|
-
continue;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const diffLines = diffBaselines(baselineJson, currentJson);
|
|
375
|
-
if (diffLines.length === 0) {
|
|
376
|
-
console.log(` ${snap} — ${green}✓ no changes${reset}`);
|
|
377
|
-
} else {
|
|
378
|
-
changedCount++;
|
|
379
|
-
console.log(` ${snap}`);
|
|
380
|
-
for (const line of diffLines) {
|
|
381
|
-
if (line.startsWith('-')) console.log(` ${red}${line}${reset}`);
|
|
382
|
-
else if (line.startsWith('+')) console.log(` ${green}${line}${reset}`);
|
|
383
|
-
else console.log(` ${line}`);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return changedCount > 0 ? 1 : 0;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1] ?? '')) {
|
|
392
|
-
const [,, subcmd, ...rest] = process.argv;
|
|
393
|
-
switch (subcmd) {
|
|
394
|
-
case 'run': process.exit(cmdRun(rest)); break;
|
|
395
|
-
case 'update': process.exit(cmdUpdate(rest)); break;
|
|
396
|
-
case 'generate': process.exit(await cmdGenerate(rest)); break;
|
|
397
|
-
case 'diff': process.exit(cmdDiff(rest)); break;
|
|
398
|
-
default:
|
|
399
|
-
console.error(`[autoregress] unknown subcommand: ${subcmd ?? '(none)'}`);
|
|
400
|
-
process.exit(1);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const HIGH_IMPACT_PATTERNS = [
|
|
2
|
-
/^src\/core\/pipeline\//,
|
|
3
|
-
/^src\/adapters\//,
|
|
4
|
-
/^src\/core\/findings\//,
|
|
5
|
-
/^src\/core\/config\//,
|
|
6
|
-
];
|
|
7
|
-
|
|
8
|
-
export interface SelectResult {
|
|
9
|
-
selected: string[];
|
|
10
|
-
fullRun: boolean;
|
|
11
|
-
reason: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function selectSnapshots(
|
|
15
|
-
changedFiles: string[],
|
|
16
|
-
allSnapshotFiles: string[],
|
|
17
|
-
index: Record<string, string[]>,
|
|
18
|
-
importMap: Record<string, string[]>,
|
|
19
|
-
options: { highImpactPatterns?: RegExp[]; volumeThreshold?: number } = {},
|
|
20
|
-
): SelectResult {
|
|
21
|
-
const patterns = options.highImpactPatterns ?? HIGH_IMPACT_PATTERNS;
|
|
22
|
-
const volumeThreshold = options.volumeThreshold ?? 10;
|
|
23
|
-
|
|
24
|
-
if (changedFiles.length > volumeThreshold) {
|
|
25
|
-
return { selected: allSnapshotFiles, fullRun: true, reason: 'volume override (>10 files changed)' };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
for (const f of changedFiles) {
|
|
29
|
-
for (const p of patterns) {
|
|
30
|
-
if (p.test(f)) {
|
|
31
|
-
return { selected: allSnapshotFiles, fullRun: true, reason: `high-impact path matched: ${f}` };
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Build: sourceFile → snapFiles that cover it
|
|
37
|
-
const sourceToSnaps: Record<string, string[]> = {};
|
|
38
|
-
for (const [snapFile, sources] of Object.entries(index)) {
|
|
39
|
-
for (const src of sources) {
|
|
40
|
-
if (!sourceToSnaps[src]) sourceToSnaps[src] = [];
|
|
41
|
-
sourceToSnaps[src]!.push(snapFile);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const selected = new Set<string>();
|
|
46
|
-
for (const changed of changedFiles) {
|
|
47
|
-
for (const snap of sourceToSnaps[changed] ?? []) selected.add(snap);
|
|
48
|
-
for (const importer of importMap[changed] ?? []) {
|
|
49
|
-
for (const snap of sourceToSnaps[importer] ?? []) selected.add(snap);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
selected: [...selected],
|
|
55
|
-
fullRun: false,
|
|
56
|
-
reason: selected.size === 0
|
|
57
|
-
? 'no snapshots matched changed files'
|
|
58
|
-
: `${selected.size} snapshot(s) selected`,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
|
|
4
|
-
const IMPORT_RE = /^(?:import|export)\s+(?:.*?from\s+)?['"]([^'"]+)['"]/gm;
|
|
5
|
-
|
|
6
|
-
function allTsFiles(dir: string): string[] {
|
|
7
|
-
const results: string[] = [];
|
|
8
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
9
|
-
const full = path.join(dir, entry.name);
|
|
10
|
-
if (entry.isDirectory()) results.push(...allTsFiles(full));
|
|
11
|
-
else if (entry.isFile() && entry.name.endsWith('.ts')) results.push(full);
|
|
12
|
-
}
|
|
13
|
-
return results;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function resolveImport(importer: string, specifier: string, srcDir: string): string | null {
|
|
17
|
-
if (!specifier.startsWith('.')) return null;
|
|
18
|
-
const abs = path.resolve(path.dirname(importer), specifier);
|
|
19
|
-
const withExt = abs.endsWith('.ts') ? abs : abs + '.ts';
|
|
20
|
-
const rel = path.relative(srcDir, withExt).replace(/\\/g, '/');
|
|
21
|
-
if (rel.startsWith('..')) return null;
|
|
22
|
-
return rel;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function buildImportMap(srcDir: string): Record<string, string[]> {
|
|
26
|
-
const absDir = path.resolve(srcDir);
|
|
27
|
-
const files = allTsFiles(absDir);
|
|
28
|
-
const map: Record<string, string[]> = {};
|
|
29
|
-
|
|
30
|
-
for (const file of files) {
|
|
31
|
-
const relImporter = path.relative(absDir, file).replace(/\\/g, '/');
|
|
32
|
-
const content = fs.readFileSync(file, 'utf8');
|
|
33
|
-
let m: RegExpExecArray | null;
|
|
34
|
-
IMPORT_RE.lastIndex = 0;
|
|
35
|
-
while ((m = IMPORT_RE.exec(content)) !== null) {
|
|
36
|
-
const resolved = resolveImport(file, m[1]!, absDir);
|
|
37
|
-
if (!resolved) continue;
|
|
38
|
-
if (!map[resolved]) map[resolved] = [];
|
|
39
|
-
if (!map[resolved]!.includes(relImporter)) map[resolved]!.push(relImporter);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return map;
|
|
44
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const ISO_TS_RE = /^\d{4}-\d{2}-\d{2}T/;
|
|
2
|
-
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-/i;
|
|
3
|
-
|
|
4
|
-
function normalizeValue(value: unknown, cwd?: string): unknown {
|
|
5
|
-
if (typeof value === 'string') {
|
|
6
|
-
if (ISO_TS_RE.test(value)) return '<timestamp>';
|
|
7
|
-
if (UUID_RE.test(value)) return '<uuid>';
|
|
8
|
-
if (cwd && value.startsWith(cwd + '/')) return value.slice(cwd.length + 1);
|
|
9
|
-
return value;
|
|
10
|
-
}
|
|
11
|
-
if (Array.isArray(value)) return value.map(v => normalizeValue(v, cwd));
|
|
12
|
-
if (value !== null && typeof value === 'object') {
|
|
13
|
-
const sorted: Record<string, unknown> = {};
|
|
14
|
-
for (const key of Object.keys(value as object).sort()) {
|
|
15
|
-
sorted[key] = normalizeValue((value as Record<string, unknown>)[key], cwd);
|
|
16
|
-
}
|
|
17
|
-
return sorted;
|
|
18
|
-
}
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function normalizeSnapshot(value: unknown, cwd?: string): string {
|
|
23
|
-
return JSON.stringify(normalizeValue(value, cwd), null, 2);
|
|
24
|
-
}
|
|
File without changes
|