MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / ensureTestDist

Function ensureTestDist

__tests__/global-setup-dist.ts:61–87  ·  view source on GitHub ↗
(root: string, runBuild: BuildRunner = build)

Source from the content-addressed store, hash-verified

59
60/** Exported for isolated filesystem fixtures; Vitest calls the default wrapper. */
61export function ensureTestDist(root: string, runBuild: BuildRunner = build): void {
62 for (const part of ['engine', 'viewer'] as const) {
63 const stamp = path.join(root, 'dist', `.test-build-${part}.json`);
64 const inputs = inputFingerprint(root, part);
65 const outputs = outputSnapshot(root, part);
66 let current = false;
67 try {
68 const previous = JSON.parse(fs.readFileSync(stamp, 'utf8'));
69 current = previous.inputs === inputs && Object.keys(outputs).length > 0
70 && JSON.stringify(previous.outputs) === JSON.stringify(outputs);
71 } catch { /* No valid successful-build record: rebuild. */ }
72 if (current) continue;
73
74 process.stderr.write(`[test setup] ${part} build is missing or stale; rebuilding\n`);
75 // Never leave a successful stamp behind after a partially failed rebuild.
76 fs.rmSync(stamp, { force: true });
77 try {
78 runBuild(part, root);
79 const built = outputSnapshot(root, part);
80 const sentinel = part === 'engine' ? 'dist/bin/codegraph.js' : 'dist/viewer/index.html';
81 if (!fs.existsSync(path.join(root, sentinel))) throw new Error(`Build did not produce ${sentinel}`);
82 fs.writeFileSync(stamp, JSON.stringify({ inputs, outputs: built }));
83 } catch (error) {
84 throw new Error(`[test setup] ${part} build failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
85 }
86 }
87}
88
89export default function setup(): void {
90 ensureTestDist(ROOT);

Callers 3

setupFunction · 0.90
setupFunction · 0.85

Calls 5

inputFingerprintFunction · 0.85
outputSnapshotFunction · 0.85
parseMethod · 0.80
writeMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected