zimakri / tree / test/helpers.ts ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
import { mkdtempSync, readFileSync, existsSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { spawnSync } from 'node:child_process';
export const ROOT = resolve(import.meta.dirname, '..');
export const tmp = (p = 'zimakri-') => mkdtempSync(join(tmpdir(), p));
export const NO_NET = join(ROOT, 'test/no-network.mjs');
export function cli(args: string[], opts: { cwd?: string; bin?: string; netLog?: string } = {}) {
  const r = spawnSync(process.execPath, ['--import', NO_NET, opts.bin ?? join(ROOT, 'bin/zimakri.js'), ...args], {
    cwd: opts.cwd ?? ROOT, encoding: 'utf8', env: { ...process.env, ZIMAKRI_NET_LOG: opts.netLog ?? '' },
  });
  return { code: r.status, out: r.stdout, err: r.stderr };
}
export const json = (p: string) => JSON.parse(readFileSync(p, 'utf8'));
export { existsSync, readFileSync, join };

agentgate-source: code mirror on Cloudflare Pages. All repos