Files
buzz/scripts/ts-esm-loader.mjs
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 ffc46676c7 fix(scripts): add ts-esm-loader and fix allowlist coverage in run-differential
Phase 2b introduced a transitive extensionless TS import in buzzAgentConfig.ts
("./modelCapabilities") that Node's --experimental-strip-types cannot resolve
without help. Add scripts/ts-esm-loader.mjs — a minimal ESM custom loader that
patches extensionless relative imports to .ts files when the file exists on disk.
Update run-differential.mjs shebang to self-bootstrap with the loader.

Also fix the allowlist coverage gate: totalAllowlisted was declared but never
incremented, so the summary always printed "0 allowlisted" and stale allowlist
entries (which mask future regressions) went undetected. Replace with per-axis hit
tracking via allowlistHits Set; report exercised slot count (N/total) in the
summary; FAIL with STALE_ALLOWLIST if any declared entry fires zero divergences.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
2026-07-31 13:02:16 -04:00

28 lines
1.1 KiB
JavaScript

/**
* Minimal ESM custom loader for the differential harness.
*
* Node's --experimental-strip-types resolves .ts files by absolute URL but
* does NOT add .ts to extensionless relative imports emitted by TypeScript
* source (e.g. `import ... from "./modelCapabilities"`). This loader patches
* that gap: when a relative import has no extension and a same-named .ts file
* exists on disk, it rewrites the specifier to the .ts URL before resolution.
*
* Usage: node --experimental-strip-types --loader scripts/ts-esm-loader.mjs <script>
*/
import { existsSync } from "node:fs";
import { fileURLToPath, pathToFileURL } from "node:url";
import { join, dirname, extname } from "node:path";
export async function resolve(specifier, context, nextResolve) {
if (specifier.startsWith(".") && !extname(specifier)) {
const parentDir = context.parentURL
? dirname(fileURLToPath(context.parentURL))
: process.cwd();
const candidate = join(parentDir, specifier + ".ts");
if (existsSync(candidate)) {
return nextResolve(pathToFileURL(candidate).href, context);
}
}
return nextResolve(specifier, context);
}