import { spawnSync } from 'node:child_process';
import { join, resolve } from 'node:path';
export const ROOT = resolve(import.meta.dirname, '..');
export const FX = (p: string) => join(ROOT, 'fixtures', p);
export function cli(args: string[]) {
const r = spawnSync(process.execPath, [join(ROOT, 'bin/aiax-validate.js'), ...args], { encoding: 'utf8', cwd: ROOT });
return { code: r.status, out: r.stdout, err: r.stderr };
}
/** A fetch from an in memory map of path -> body (string) or status (number); counts calls; never the network. */
export function memFetch(files: Record<string, string | number>) {
const calls: string[] = [];
const f = async (u: string | URL) => {
const url = new URL(String(u)); calls.push(url.toString());
const v = files[url.pathname];
if (v === undefined) return new Response('not found', { status: 404 });
if (typeof v === 'number') return new Response('x', { status: v });
return new Response(v, { status: 200 });
};
return Object.assign(f as unknown as typeof fetch, { calls });
}
agentgate-source: code mirror on Cloudflare Pages. All repos