()
| 33 | } |
| 34 | |
| 35 | function main() { |
| 36 | const root = fs.mkdtempSync(path.join(os.tmpdir(), 'citadel-map-test-')); |
| 37 | writeFile(path.join(root, 'package.json'), JSON.stringify({ |
| 38 | scripts: { |
| 39 | test: 'node test.js', |
| 40 | typecheck: 'tsc --noEmit', |
| 41 | start: 'vite', |
| 42 | }, |
| 43 | }, null, 2)); |
| 44 | writeFile(path.join(root, 'src', 'routes.tsx'), ` |
| 45 | export const routes = [{ path: '/dashboard' }, { path: '/campaigns/:id' }]; |
| 46 | export function CampaignRoute() { return null; } |
| 47 | `); |
| 48 | writeFile(path.join(root, 'src', 'fleet', 'steward.ts'), ` |
| 49 | import { routes } from '../routes'; |
| 50 | export class FleetSteward {} |
| 51 | const internalSymbol = routes; |
| 52 | `); |
| 53 | writeFile(path.join(root, 'scripts', 'verify.js'), ` |
| 54 | module.exports = function verify() { return true; }; |
| 55 | `); |
| 56 | |
| 57 | const output = defaultOutputPath(root); |
| 58 | const index = generateMapIndex(root); |
| 59 | writeMapIndex(index, output); |
| 60 | |
| 61 | assert.strictEqual(index.version, 2); |
| 62 | assert.ok(index.fileCount >= 3, 'expected generated source file records'); |
| 63 | assert.ok(index.sourceSignature, 'expected source signature'); |
| 64 | assert.ok(index.files['src/fleet/steward.ts'].hash, 'expected per-file hash'); |
| 65 | assert.ok(index.routes.some((route) => route.path === '/dashboard'), 'expected extracted route'); |
| 66 | assert.ok(index.verificationCommands.includes('npm run test'), 'expected test script command'); |
| 67 | assert.ok(index.verificationCommands.includes('npm run typecheck'), 'expected typecheck command'); |
| 68 | |
| 69 | const results = queryMapIndex(index, 'fleet steward', 5); |
| 70 | assert.strictEqual(results[0].relPath, 'src/fleet/steward.ts'); |
| 71 | |
| 72 | const slice = createMapSlice(index, 'campaign route', { maxFiles: 5 }); |
| 73 | assert.ok(slice.includes('=== MAP SLICE: campaign route ===')); |
| 74 | assert.ok(slice.includes('Verification: npm run test | npm run typecheck')); |
| 75 | assert.ok(slice.includes('src/routes.tsx')); |
| 76 | |
| 77 | const stats = mapStats(index); |
| 78 | assert.ok(stats.verificationCommands >= 2); |
| 79 | assert.ok(stats.routes >= 2); |
| 80 | |
| 81 | let stale = detectMapStaleness(root, loadMapIndex(output)); |
| 82 | assert.strictEqual(stale.stale, false); |
| 83 | |
| 84 | writeFile(path.join(root, 'src', 'fleet', 'steward.ts'), ` |
| 85 | import { routes } from '../routes'; |
| 86 | export class FleetSteward {} |
| 87 | export function mergeQueue() { return routes; } |
| 88 | `); |
| 89 | stale = detectMapStaleness(root, loadMapIndex(output)); |
| 90 | assert.strictEqual(stale.stale, true); |
| 91 | assert.deepStrictEqual(stale.changed, ['src/fleet/steward.ts']); |
| 92 |
no test coverage detected