Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test: resolve file URLs with fileURLToPath, never .pathname, so test paths survive a checkout path with a space (#6845)

garrytan2a7a194f361b
diff --git a/test/admin-embed-spawn.test.ts b/test/admin-embed-spawn.test.ts
index ac974213e7..5fdf36f877 100644
--- a/test/admin-embed-spawn.test.ts
+++ b/test/admin-embed-spawn.test.ts
@@ -29,8 +29,9 @@ import { join } from 'path';
import { tmpdir } from 'os';
import type { Subprocess } from 'bun';
import { freePort } from './helpers/serve-http.ts';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
interface ServeProc {
proc: Subprocess;
diff --git a/test/agent-install.test.ts b/test/agent-install.test.ts
index 58653315f5..f3e7825e42 100644
--- a/test/agent-install.test.ts
+++ b/test/agent-install.test.ts
@@ -7,6 +7,7 @@ import { renderAgentLauncher } from '../src/core/agent-install/launcher.ts';
import { extractPgliteDump, readBackupArchive, writeBackupArchive } from '../src/core/backup/archive.ts';
import { AGENT_ENV_SHELL_PATTERN, shouldDropAgentEnv } from '../src/core/agent-install/environment.ts';
import { listRecipes } from '../src/core/ai/recipes/index.ts';
+import { fileURLToPath } from 'node:url';
let temporary: string;
beforeEach(() => { temporary = mkdtempSync(join(tmpdir(), 'gbrain-agent-files-')); });
@@ -60,8 +61,8 @@ test('real launcher pairs private configured keys only with private configured p
// Private per-install .env remains usable after ambient provider state is
// scrubbed; a blanket empty-value export would break this supported channel.
writeFileSync(join(home, '.env'), 'OPENAI_API_KEY=private-openai-fixture\n', { mode: 0o600 });
- const gatewayModule = new URL('../src/core/ai/build-gateway-config.ts', import.meta.url).pathname;
- const configModule = new URL('../src/core/config.ts', import.meta.url).pathname;
+ const gatewayModule = fileURLToPath(new URL('../src/core/ai/build-gateway-config.ts', import.meta.url));
+ const configModule = fileURLToPath(new URL('../src/core/config.ts', import.meta.url));
const probe = join(temporary, 'gateway-probe.ts');
writeFileSync(probe, `import { buildGatewayConfig } from ${JSON.stringify(gatewayModule)};
import { loadConfig } from ${JSON.stringify(configModule)};
diff --git a/test/amends-link.test.ts b/test/amends-link.test.ts
index 2d75a6690d..12f56b1a17 100644
--- a/test/amends-link.test.ts
+++ b/test/amends-link.test.ts
@@ -12,6 +12,7 @@ import { configureGateway, resetGateway } from '../src/core/ai/gateway.ts';
import { setPackRelationSemantics } from '../src/core/link-validity.ts';
import { linkTypeRanks, NON_RANKING_LINK_TYPES, rankingLinkSql } from '../src/core/link-ranking-policy.ts';
import { loadPackFromFile } from '../src/core/schema-pack/loader.ts';
+import { fileURLToPath } from 'node:url';
import { INVARIANCE_ROWS, amendmentsVersusReplacement, databaseToday, frontmatterRecordsSince, futureAmendsStayVisible,
runInvarianceRow, useExamplePack } from './helpers/amends-ranking-scenarios.ts';
@@ -36,7 +37,7 @@ describe('ranking participation policy', () => {
});
test('the bundled example pack is a valid manifest declaring amends as an event mapped from frontmatter', () => {
- const manifest = loadPackFromFile(new URL('../examples/schema-packs/amends-example/pack.yaml', import.meta.url).pathname);
+ const manifest = loadPackFromFile(fileURLToPath(new URL('../examples/schema-packs/amends-example/pack.yaml', import.meta.url)));
expect(manifest.link_types).toEqual([{ name: 'amends', temporal: 'event' }, { name: 'supersedes' }]);
expect(manifest.frontmatter_links).toEqual([
{ page_type: 'contract', fields: ['amends'], link_type: 'amends' },
diff --git a/test/apply-migrations-list-db-state-cli.test.ts b/test/apply-migrations-list-db-state-cli.test.ts
index 9126d0e57c..0667e691c0 100644
--- a/test/apply-migrations-list-db-state-cli.test.ts
+++ b/test/apply-migrations-list-db-state-cli.test.ts
@@ -12,8 +12,9 @@ import { describe, test, expect } from 'bun:test';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
const SKIP = process.env.GBRAIN_TEST_SKIP_SUBPROCESS === '1';
async function runCli(
diff --git a/test/apply-migrations-pglite-spawn.test.ts b/test/apply-migrations-pglite-spawn.test.ts
index 7e5e6e2c25..e208f9075f 100644
--- a/test/apply-migrations-pglite-spawn.test.ts
+++ b/test/apply-migrations-pglite-spawn.test.ts
@@ -28,8 +28,9 @@ import { describe, test, expect } from 'bun:test';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync, existsSync, chmodSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
/**
* Make a shim `gbrain` binary that routes to `bun run <repo>/src/cli.ts`.
diff --git a/test/apply-migrations-wedged-6696.test.ts b/test/apply-migrations-wedged-6696.test.ts
index 4bba83e5bf..788d192164 100644
--- a/test/apply-migrations-wedged-6696.test.ts
+++ b/test/apply-migrations-wedged-6696.test.ts
@@ -14,8 +14,9 @@ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
/** The newest registered migration: nothing can run past it, so its wedge is outstanding. */
const WEDGED = '0.60.31';
/** Older than migrations that run on a fresh brain (v0.28.0 among them), so its wedge is superseded. */
diff --git a/test/autopilot-positional-args.test.ts b/test/autopilot-positional-args.test.ts
index 77c3e25c06..48fa9ecbef 100644
--- a/test/autopilot-positional-args.test.ts
+++ b/test/autopilot-positional-args.test.ts
@@ -18,6 +18,7 @@ import { mkdtempSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { resolveAutopilotPositionals } from '../src/commands/autopilot.ts';
+import { fileURLToPath } from 'node:url';
describe('resolveAutopilotPositionals (#1525)', () => {
test('maps subcommand spellings onto their canonical flags', () => {
@@ -82,7 +83,7 @@ describe('resolveAutopilotPositionals (#1525)', () => {
});
});
-const REPO = new URL('..', import.meta.url).pathname;
+const REPO = fileURLToPath(new URL('..', import.meta.url));
async function runCli(cliArgs: string[]): Promise<{ code: number; stdout: string; stderr: string }> {
const home = mkdtempSync(join(tmpdir(), 'gbrain-autopilot-pos-'));
diff --git a/test/backlinks-gap-parity.test.ts b/test/backlinks-gap-parity.test.ts
index ecc1ad2f37..c4232e960f 100644
--- a/test/backlinks-gap-parity.test.ts
+++ b/test/backlinks-gap-parity.test.ts
@@ -18,8 +18,9 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { findBacklinkGaps, findBacklinkGapsAsync } from '../src/commands/backlinks.ts';
import { writeBacklinksParityFixture } from './helpers/backlinks-parity-fixture.ts';
+import { fileURLToPath } from 'node:url';
-const GOLDEN = new URL('./fixtures/backlinks-parity/gaps.golden.json', import.meta.url).pathname;
+const GOLDEN = fileURLToPath(new URL('./fixtures/backlinks-parity/gaps.golden.json', import.meta.url));
const roots: string[] = [];
afterEach(() => { while (roots.length) rmSync(roots.pop()!, { recursive: true, force: true }); });
diff --git a/test/backlinks-memory.slow.test.ts b/test/backlinks-memory.slow.test.ts
index dc66419a31..8d01fc6005 100644
--- a/test/backlinks-memory.slow.test.ts
+++ b/test/backlinks-memory.slow.test.ts
@@ -27,8 +27,9 @@ import { afterAll, describe, expect, test } from 'bun:test';
import { mkdtempSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
-const CHILD = new URL('./helpers/backlinks-rss-child.ts', import.meta.url).pathname;
+const CHILD = fileURLToPath(new URL('./helpers/backlinks-rss-child.ts', import.meta.url));
const SIZES_MIB = [48, 192, 384];
const roots: string[] = [];
afterAll(() => { while (roots.length) rmSync(roots.pop()!, { recursive: true, force: true }); });
diff --git a/test/book-mirror.test.ts b/test/book-mirror.test.ts
index b9a7b0f23c..15db27b8e9 100644
--- a/test/book-mirror.test.ts
+++ b/test/book-mirror.test.ts
@@ -24,8 +24,9 @@
import { describe, expect, it } from 'bun:test';
import { readFileSync } from 'fs';
import { join } from 'path';
+import { fileURLToPath } from 'node:url';
-const REPO_ROOT = new URL('..', import.meta.url).pathname;
+const REPO_ROOT = fileURLToPath(new URL('..', import.meta.url));
async function runCli(args: string[]): Promise<{
stdout: string;
diff --git a/test/brain-flag-routing.serial.test.ts b/test/brain-flag-routing.serial.test.ts
index d39c6e3a60..769a2cff31 100644
--- a/test/brain-flag-routing.serial.test.ts
+++ b/test/brain-flag-routing.serial.test.ts
@@ -27,8 +27,9 @@ import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
let home: string;
let mountsPath: string;
diff --git a/test/check-update.test.ts b/test/check-update.test.ts
index 6dfa2b86c7..2fafc2e8bc 100644
--- a/test/check-update.test.ts
+++ b/test/check-update.test.ts
@@ -6,6 +6,7 @@ import {
extractChangelogBetween,
} from '../src/commands/check-update.ts';
import { surfaceSource } from './helpers/source-surface.ts';
+import { fileURLToPath } from 'node:url';
describe('parseSemver', () => {
test('parses standard version', () => {
@@ -172,7 +173,7 @@ describe('check-update CLI', () => {
test('--help prints usage and exits 0', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'check-update', '--help'], {
- cwd: new URL('..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
@@ -184,7 +185,7 @@ describe('check-update CLI', () => {
test('--json returns valid JSON with required fields', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'check-update', '--json'], {
- cwd: new URL('..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
diff --git a/test/child-handler-configuration.test.ts b/test/child-handler-configuration.test.ts
index 0342685f2e..71555c3c5e 100644
--- a/test/child-handler-configuration.test.ts
+++ b/test/child-handler-configuration.test.ts
@@ -3,9 +3,10 @@ import { checkChildReadiness } from '../src/core/minions/child-readiness.ts';
import { runJobInChild } from '../src/core/minions/child-job-runner.ts';
import { LocalConfigurationError } from '../src/core/minions/configuration-error.ts';
import { detectTini } from '../src/core/minions/spawn-helpers.ts';
+import { fileURLToPath } from 'node:url';
test('actual isolated handler fault after healthy readiness preserves typed outcome and confirms supported cleanup', async () => {
- const invocation = { cmd: process.execPath, argsPrefix: [new URL('./fixtures/child-configuration-handler.ts', import.meta.url).pathname] };
+ const invocation = { cmd: process.execPath, argsPrefix: [fileURLToPath(new URL('./fixtures/child-configuration-handler.ts', import.meta.url))] };
const tiniPath = detectTini();
await checkChildReadiness({ invocation, tiniPath });
const events: string[] = [];
diff --git a/test/claude-cli-recipe.test.ts b/test/claude-cli-recipe.test.ts
index cb13a08554..0c92235616 100644
--- a/test/claude-cli-recipe.test.ts
+++ b/test/claude-cli-recipe.test.ts
@@ -22,6 +22,7 @@ import { join } from 'node:path';
import { tmpdir } from 'node:os';
import type { LanguageModelV2CallOptions } from '@ai-sdk/provider';
import { withEnv } from './helpers/with-env.ts';
+import { fileURLToPath } from 'node:url';
const stubDir = join(tmpdir(), `claude-cli-recipe-stub-${process.pid}`);
const stubBin = join(stubDir, 'claude');
@@ -347,7 +348,7 @@ describe('claude-cli LanguageModel — tool use', () => {
// fresh subprocess replayed from an id-stripped transcript cannot avoid
// repeats, which is exactly what collided real dream jobs to death.
const src = readFileSync(
- new URL('../src/core/ai/providers/claude-cli-language-model.ts', import.meta.url).pathname,
+ fileURLToPath(new URL('../src/core/ai/providers/claude-cli-language-model.ts', import.meta.url)),
'utf-8',
);
expect(src).toContain('{"name": "<tool name>", "input":');
diff --git a/test/cli-exit-verdict-pin.test.ts b/test/cli-exit-verdict-pin.test.ts
index 75322ca477..15201a073f 100644
--- a/test/cli-exit-verdict-pin.test.ts
+++ b/test/cli-exit-verdict-pin.test.ts
@@ -13,6 +13,7 @@
import { describe, test, expect } from 'bun:test';
import { execSync } from 'child_process';
+import { fileURLToPath } from 'node:url';
describe('exit-verdict ownership — no raw process.exitCode assignments', () => {
test('every exit-code write in src/ routes through setCliExitVerdict', () => {
@@ -27,7 +28,7 @@ describe('exit-verdict ownership — no raw process.exitCode assignments', () =>
// form — every shape is equally zeroed by the owned-verdict read.
const hits = execSync(
String.raw`grep -rnE "process(\.|\[')exitCode('\])?[[:space:]]*([?|&]{2})?=[^=]" src --include='*.ts' | grep -v "core/cli-force-exit.ts" | grep -v "core/pglite-engine.ts" || true`,
- { encoding: 'utf-8', cwd: new URL('..', import.meta.url).pathname },
+ { encoding: 'utf-8', cwd: fileURLToPath(new URL('..', import.meta.url)) },
).trim();
expect(hits).toBe('');
});
diff --git a/test/cli-help-curated-cli.test.ts b/test/cli-help-curated-cli.test.ts
index 47f843f1d4..e9ea4dc086 100644
--- a/test/cli-help-curated-cli.test.ts
+++ b/test/cli-help-curated-cli.test.ts
@@ -20,8 +20,9 @@ import { mkdtempSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { loadCuratedHelp } from '../src/cli/help/render.ts';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname;
+const REPO = fileURLToPath(new URL('..', import.meta.url));
const CURATED = ['doctor', 'import', 'serve', 'apply-migrations', 'autopilot', 'status', 'onboard'];
async function cli(args: string[]): Promise<{ code: number; stdout: string; stderr: string }> {
diff --git a/test/cli-help-without-brain.test.ts b/test/cli-help-without-brain.test.ts
index 3b79823575..042bfcd986 100644
--- a/test/cli-help-without-brain.test.ts
+++ b/test/cli-help-without-brain.test.ts
@@ -15,8 +15,9 @@ import { describe, test, expect } from 'bun:test';
import { mkdtempSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname;
+const REPO = fileURLToPath(new URL('..', import.meta.url));
/** Answer `--help` before touching the engine. */
const HELP_WITHOUT_BRAIN = [
diff --git a/test/cli.test.ts b/test/cli.test.ts
index 3dfbb644de..d3e07dae4b 100644
--- a/test/cli.test.ts
+++ b/test/cli.test.ts
@@ -3,10 +3,11 @@ import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { surfaceFileSource } from './helpers/source-surface.ts';
+import { fileURLToPath } from 'node:url';
// test-reads-source-ok[structural]: two kept pins need the dispatcher's text: the handleCliOnly case-label census (switch labels cannot be enumerated at runtime) and the local-op normalize call site (bigints only reach it from Postgres, never PGLite).
const cliSource = surfaceFileSource('cli', 'src/cli/main.ts');
-const repoRoot = new URL('..', import.meta.url).pathname;
+const repoRoot = fileURLToPath(new URL('..', import.meta.url));
function isolatedEnv(home: string): Record<string, string> {
const env: Record<string, string> = {};
@@ -215,7 +216,7 @@ describe('ask alias', () => {
test('ask does NOT appear in --tools-json output', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', '--tools-json'], {
- cwd: new URL('..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
@@ -230,7 +231,7 @@ describe('ask alias', () => {
describe('CLI dispatch integration', () => {
test('--version outputs version', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', '--version'], {
- cwd: new URL('..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
@@ -241,7 +242,7 @@ describe('CLI dispatch integration', () => {
test('unknown command prints error and exits 2 (usage)', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'notacommand'], {
- cwd: new URL('..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
diff --git a/test/config-set-unknown-flag.test.ts b/test/config-set-unknown-flag.test.ts
index c3108bc9e4..de80527fad 100644
--- a/test/config-set-unknown-flag.test.ts
+++ b/test/config-set-unknown-flag.test.ts
@@ -24,8 +24,9 @@ import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
const KEY = 'models.tier.subagent';
const BASELINE = 'anthropic:claude-haiku-4-5';
diff --git a/test/consent-table.serial.test.ts b/test/consent-table.serial.test.ts
index 5f5ef84349..cb9771318a 100644
--- a/test/consent-table.serial.test.ts
+++ b/test/consent-table.serial.test.ts
@@ -24,8 +24,9 @@ import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import { BudgetExhausted, BudgetTracker } from '../src/core/budget/budget-tracker.ts';
import { DEFAULT_PAID_CAP_USD, isConsentRefusal, requireConsent, type ConsentRequest } from '../src/core/consent.ts';
import { previewCostAndWait } from '../src/core/brainstorm/orchestrator.ts';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
let home: string;
let brainPath: string;
let notes: string;
diff --git a/test/conversation-parser/timezone.test.ts b/test/conversation-parser/timezone.test.ts
index d290023bd3..42d3b8c4de 100644
--- a/test/conversation-parser/timezone.test.ts
+++ b/test/conversation-parser/timezone.test.ts
@@ -15,6 +15,7 @@ import { describe, expect, test } from 'bun:test';
import { execFileSync } from 'node:child_process';
import { deriveDateContext, localToUtcIso, parseConversation } from '../../src/core/conversation-parser/parse.ts';
import type { Page } from '../../src/core/types.ts';
+import { fileURLToPath } from 'node:url';
function makePage(frontmatter: Record<string, unknown>): Page {
return {
@@ -56,7 +57,7 @@ describe('localToUtcIso', () => {
expect(localToUtcIso('2024-03-15', 9, 0, 'Etc/GMT+5')).toBe('2024-03-15T14:00:00Z');
});
test('independent of the host timezone', () => {
- const script = `import { localToUtcIso } from ${JSON.stringify(new URL('../../src/core/conversation-parser/parse.ts', import.meta.url).pathname)};
+ const script = `import { localToUtcIso } from ${JSON.stringify(fileURLToPath(new URL('../../src/core/conversation-parser/parse.ts', import.meta.url)))};
console.log(JSON.stringify([localToUtcIso('2024-03-15', 9, 0, 'Asia/Tokyo'), localToUtcIso('2024-11-03', 1, 30, 'America/New_York'), localToUtcIso('2024-03-10', 2, 30, 'America/New_York')]));`;
for (const TZ of ['Pacific/Kiritimati', 'America/Anchorage', 'UTC']) {
const out = execFileSync(process.execPath, ['-e', script], { env: { ...process.env, TZ }, encoding: 'utf8' }).trim();
diff --git a/test/cycle-phase-deadline-drift.test.ts b/test/cycle-phase-deadline-drift.test.ts
index ecd0a3a9f8..5aea276f24 100644
--- a/test/cycle-phase-deadline-drift.test.ts
+++ b/test/cycle-phase-deadline-drift.test.ts
@@ -27,11 +27,12 @@ import {
import { CYCLE_DEADLINE_RESERVE_MS } from '../src/core/cycle/base-phase.ts';
import { defaultTimeoutMsFor } from '../src/core/minions/handler-timeouts.ts';
import { resolveAutopilotDispatchTimeoutMs } from '../src/commands/autopilot-timeout.ts';
+import { fileURLToPath } from 'node:url';
const proposeTakesSrc = readFileSync(
- new URL('../src/core/cycle/propose-takes.ts', import.meta.url).pathname, 'utf-8');
+ fileURLToPath(new URL('../src/core/cycle/propose-takes.ts', import.meta.url)), 'utf-8');
const cycleSrc = readFileSync(
- new URL('../src/core/cycle.ts', import.meta.url).pathname, 'utf-8');
+ fileURLToPath(new URL('../src/core/cycle.ts', import.meta.url)), 'utf-8');
describe('propose_takes deadline < job timeout (#4168)', () => {
test('fallback deadline is strictly under the MINIMUM achievable full-cycle job timeout across plausible intervals', () => {
diff --git a/test/doctor-cli-smoke.test.ts b/test/doctor-cli-smoke.test.ts
index 1b3fde1690..6a2bf190f5 100644
--- a/test/doctor-cli-smoke.test.ts
+++ b/test/doctor-cli-smoke.test.ts
@@ -21,8 +21,9 @@ import { describe, test, expect } from 'bun:test';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync, chmodSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
const SKIP = process.env.GBRAIN_TEST_SKIP_SUBPROCESS === '1';
function makeGbrainShim(): { binDir: string; cleanup: () => void } {
diff --git a/test/doctor-no-migrate.test.ts b/test/doctor-no-migrate.test.ts
index 9b9b92702d..af5dcd20c4 100644
--- a/test/doctor-no-migrate.test.ts
+++ b/test/doctor-no-migrate.test.ts
@@ -20,8 +20,9 @@ import { pg_trgm } from '@electric-sql/pglite/contrib/pg_trgm';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
const SKIP = process.env.GBRAIN_TEST_SKIP_SUBPROCESS === '1';
async function runCli(
diff --git a/test/e2e/upgrade.test.ts b/test/e2e/upgrade.test.ts
index 4d8db2982e..1a1e32f73a 100644
--- a/test/e2e/upgrade.test.ts
+++ b/test/e2e/upgrade.test.ts
@@ -10,6 +10,7 @@
import { describe, test, expect } from 'bun:test';
import { VERSION } from '../../src/version.ts';
import { isNewerVersion } from '../../src/commands/check-update.ts';
+import { fileURLToPath } from 'node:url';
// Check if we can reach GitHub
async function hasNetwork(): Promise<boolean> {
@@ -31,7 +32,7 @@ if (skip) {
describeE2E('E2E: Check-Update', () => {
test('check-update --json returns valid JSON with current version', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'check-update', '--json'], {
- cwd: new URL('../..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('../..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
@@ -48,7 +49,7 @@ describeE2E('E2E: Check-Update', () => {
test('check-update without --json prints human-readable output', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'check-update'], {
- cwd: new URL('../..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('../..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
@@ -61,7 +62,7 @@ describeE2E('E2E: Check-Update', () => {
test('check-update --help prints usage', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'check-update', '--help'], {
- cwd: new URL('../..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('../..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
@@ -75,7 +76,7 @@ describeE2E('E2E: Check-Update', () => {
test('check-update --json contract holds regardless of real release state', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'check-update', '--json'], {
- cwd: new URL('../..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('../..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
diff --git a/test/embed-exit-code-3037.serial.test.ts b/test/embed-exit-code-3037.serial.test.ts
index 2b7c95acf3..5692fc9619 100644
--- a/test/embed-exit-code-3037.serial.test.ts
+++ b/test/embed-exit-code-3037.serial.test.ts
@@ -18,8 +18,9 @@ import { describe, test, expect } from 'bun:test';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
const DIMS = 16;
async function runCli(
diff --git a/test/helpers/amends-ranking-scenarios.ts b/test/helpers/amends-ranking-scenarios.ts
index a9246d34ba..37cb64296b 100644
--- a/test/helpers/amends-ranking-scenarios.ts
+++ b/test/helpers/amends-ranking-scenarios.ts
@@ -27,9 +27,10 @@ import { buildEntityCard } from '../../src/core/verbs/entity-card.ts';
import { utcToday } from '../../src/core/link-validity.ts';
import { __setPackLocatorForTests, _resetPackLocatorForTests, _resetPackCacheForTests } from '../../src/core/schema-pack/index.ts';
import { bundledPackPath } from '../../src/core/schema-pack/bundled-assets.ts';
+import { fileURLToPath } from 'node:url';
export const EXAMPLE_PACK = 'amends-example';
-const EXAMPLE_PACK_PATH = new URL('../../examples/schema-packs/amends-example/pack.yaml', import.meta.url).pathname;
+const EXAMPLE_PACK_PATH = fileURLToPath(new URL('../../examples/schema-packs/amends-example/pack.yaml', import.meta.url));
/** Resolve the bundled example pack by name for the duration of a test file. */
export function useExamplePack(): () => void {
diff --git a/test/helpers/cli-help-gate.ts b/test/helpers/cli-help-gate.ts
index 3261fc2a12..ed7440b9cc 100644
--- a/test/helpers/cli-help-gate.ts
+++ b/test/helpers/cli-help-gate.ts
@@ -16,9 +16,10 @@ import { PGLiteEngine } from '../../src/core/pglite-engine.ts';
import { CLI_COMMANDS } from '../../src/cli/command-table.ts';
import { ROUTERS } from '../../src/cli/subcommands.ts';
import { STRICT_SUBCOMMANDS } from '../../src/cli/strict-args.ts';
+import { fileURLToPath } from 'node:url';
export const GATE_PARTS = 4;
-const REPO = new URL('../..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('../..', import.meta.url)).replace(/\/$/, '');
const PROBE = join(REPO, 'test/helpers/cli-side-effect-probe.ts');
/** Files any run may touch without acting: the agent-contract event log is written by the error/exit seam. */
const TREE_ALLOW = [/^\.gbrain\/agent-contract\//];
diff --git a/test/helpers/managed-migration-chain.ts b/test/helpers/managed-migration-chain.ts
index de0e79f877..0883ec5cd7 100644
--- a/test/helpers/managed-migration-chain.ts
+++ b/test/helpers/managed-migration-chain.ts
@@ -14,8 +14,9 @@ import { assertSafeE2eDatabaseUrl } from './db-guard.ts';
import { durableGitRepo } from './git-publication.ts';
import { LEGACY_FILE_SLUG, seedLegacyManagedContent, type LegacySeed } from './managed-legacy-fixture.ts';
import { withEnv } from './with-env.ts';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('../..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('../..', import.meta.url)).replace(/\/$/, '');
const PROVIDER_KEYS = ['OPENAI_API_KEY', 'ANTHROPIC_API_KEY', 'VOYAGE_API_KEY', 'GOOGLE_API_KEY', 'GEMINI_API_KEY',
'OPENROUTER_API_KEY', 'DEEPSEEK_API_KEY', 'GROQ_API_KEY', 'MISTRAL_API_KEY', 'TOGETHER_API_KEY', 'ZEROENTROPY_API_KEY'];
diff --git a/test/import-json-stdout.test.ts b/test/import-json-stdout.test.ts
index 6dea82df62..77d976706c 100644
--- a/test/import-json-stdout.test.ts
+++ b/test/import-json-stdout.test.ts
@@ -30,8 +30,9 @@ import { describe, test, expect } from 'bun:test';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
async function runCli(
args: string[],
diff --git a/test/jobs-subcommand-help.test.ts b/test/jobs-subcommand-help.test.ts
index 3a30e8ec2c..71bb4bd187 100644
--- a/test/jobs-subcommand-help.test.ts
+++ b/test/jobs-subcommand-help.test.ts
@@ -23,8 +23,9 @@ import { describe, test, expect } from 'bun:test';
import { mkdtempSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname;
+const REPO = fileURLToPath(new URL('..', import.meta.url));
const STUB_MARKER = 'run gbrain --help for the full command list';
async function runJobsHelp(args: string[]): Promise<{ code: number; out: string }> {
diff --git a/test/line-grammar.test.ts b/test/line-grammar.test.ts
index 8e2121c303..1c78b87ad1 100644
--- a/test/line-grammar.test.ts
+++ b/test/line-grammar.test.ts
@@ -6,6 +6,7 @@
import { describe, expect, test } from 'bun:test';
import { spawnSync } from 'node:child_process';
import { findLinks, normalizeRelationType, parseEffectiveQualifier, parseLineGrammar } from '../src/core/line-grammar.ts';
+import { fileURLToPath } from 'node:url';
const facts = (text: string) => parseLineGrammar(text).facts;
const relations = (text: string, declared?: string[]) =>
@@ -179,8 +180,8 @@ describe('@effective qualifier', () => {
test('adversarial input stays linear (bounded child process)', () => {
const script = `
- const { parseLineGrammar } = await import(${JSON.stringify(new URL('../src/core/line-grammar.ts', import.meta.url).pathname)});
- const { cpuMs } = await import(${JSON.stringify(new URL('./helpers/cpu-time.ts', import.meta.url).pathname)});
+ const { parseLineGrammar } = await import(${JSON.stringify(fileURLToPath(new URL('../src/core/line-grammar.ts', import.meta.url)))});
+ const { cpuMs } = await import(${JSON.stringify(fileURLToPath(new URL('./helpers/cpu-time.ts', import.meta.url)))});
const evil = ['- ' + '['.repeat(20000) + 'x', '- works_at ' + '('.repeat(20000), '- [a] ' + '(('.repeat(10000) + ')',
'- t ' + '[[a]] '.repeat(5000), '- [idea] @effective[' + ','.repeat(20000)].join('\\n');
console.log(Math.round(cpuMs(() => parseLineGrammar(evil.repeat(5)))));`;
@@ -191,7 +192,7 @@ test('adversarial input stays linear (bounded child process)', () => {
test('long comma, bracket and space runs are parsed in linear time (#6186)', () => {
const script = `
- const { parseLineGrammar } = await import(${JSON.stringify(new URL('../src/core/line-grammar.ts', import.meta.url).pathname)});
+ const { parseLineGrammar } = await import(${JSON.stringify(fileURLToPath(new URL('../src/core/line-grammar.ts', import.meta.url)))});
const lines = (n) => ['- [idea] @effective[' + ','.repeat(n), '- t ' + '[['.repeat(n / 2), '- t ' + '[x]('.repeat(n / 4),
'- [idea] a' + ' '.repeat(n) + 'b', '- [idea] a [Source:' + ' '.repeat(n) + 'b'].join('\\n');
// Process CPU, not cpuMs: thread CPU advances in ~4 ms steps here (small side read 4.0 or 8.0 ms, ratio 3.0-7.0 over 10 idle runs;
diff --git a/test/managed-atoms-cli.slow.test.ts b/test/managed-atoms-cli.slow.test.ts
index 3e78b561ef..fa7cf962bf 100644
--- a/test/managed-atoms-cli.slow.test.ts
+++ b/test/managed-atoms-cli.slow.test.ts
@@ -3,9 +3,10 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { keylessBrainEnv } from './helpers/provider-env.ts';
+import { fileURLToPath } from 'node:url';
-const CLI = new URL('../src/cli.ts', import.meta.url).pathname;
-const FIXTURE = new URL('./fixtures/managed-atoms-cli-brain.ts', import.meta.url).pathname;
+const CLI = fileURLToPath(new URL('../src/cli.ts', import.meta.url));
+const FIXTURE = fileURLToPath(new URL('./fixtures/managed-atoms-cli-brain.ts', import.meta.url));
interface Result { exitCode: number; stdout: string; stderr: string; timedOut: boolean; }
async function run(command: string[], env: Record<string, string>, home: string, timeoutMs = 60_000): Promise<Result> {
diff --git a/test/models-probe-max-output-tokens.serial.test.ts b/test/models-probe-max-output-tokens.serial.test.ts
index 14e71b29ff..5af2496d32 100644
--- a/test/models-probe-max-output-tokens.serial.test.ts
+++ b/test/models-probe-max-output-tokens.serial.test.ts
@@ -28,8 +28,9 @@ import { describe, test, expect } from 'bun:test';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
const DIMS = 16;
/** OpenAI's documented minimum for max_output_tokens. */
diff --git a/test/pglite-hoisted-install.test.ts b/test/pglite-hoisted-install.test.ts
index c9ddac79da..8bb46ee41a 100644
--- a/test/pglite-hoisted-install.test.ts
+++ b/test/pglite-hoisted-install.test.ts
@@ -28,8 +28,9 @@ import { mkdtempSync, mkdirSync, rmSync, copyFileSync, symlinkSync } from 'node:
import { join, dirname } from 'node:path';
import { tmpdir } from 'node:os';
import { createRequire } from 'node:module';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
const nodeRequire = createRequire(import.meta.url);
const REAL_PGLITE_PKG_DIR = dirname(dirname(nodeRequire.resolve('@electric-sql/pglite'))); // <pkg>/dist/index.js -> <pkg>
diff --git a/test/reindex-frontmatter-pglite-spawn.test.ts b/test/reindex-frontmatter-pglite-spawn.test.ts
index f258a09968..f0de9fffad 100644
--- a/test/reindex-frontmatter-pglite-spawn.test.ts
+++ b/test/reindex-frontmatter-pglite-spawn.test.ts
@@ -23,8 +23,9 @@ import { describe, test, expect } from 'bun:test';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
async function runCli(
args: string[],
diff --git a/test/resolve-ipc-rebind.serial.test.ts b/test/resolve-ipc-rebind.serial.test.ts
index 05d79ad5fa..7098f0d89c 100644
--- a/test/resolve-ipc-rebind.serial.test.ts
+++ b/test/resolve-ipc-rebind.serial.test.ts
@@ -28,10 +28,11 @@ import {
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import type { BrainEngine } from '../src/core/engine.ts';
import { withEnv } from './helpers/with-env.ts';
+import { fileURLToPath } from 'node:url';
const INTERVAL_MS = 300;
const cfg = { engine: 'postgres' as const, database_url: 'postgresql://[email protected]:5432/rebind-brain' };
-const BINDING_MODULE = new URL('../src/mcp/resolve-ipc-binding.ts', import.meta.url).pathname;
+const BINDING_MODULE = fileURLToPath(new URL('../src/mcp/resolve-ipc-binding.ts', import.meta.url));
let engine: PGLiteEngine;
let tmp: string;
diff --git a/test/scripts/run-unit-parallel.test.ts b/test/scripts/run-unit-parallel.test.ts
index 81df40a090..fc615d0f9e 100644
--- a/test/scripts/run-unit-parallel.test.ts
+++ b/test/scripts/run-unit-parallel.test.ts
@@ -368,9 +368,10 @@ describe('passing', () => {
});`;
const oomOnce = `import { describe, it, expect } from 'bun:test';
import { existsSync, writeFileSync } from 'fs';
+import { fileURLToPath } from 'node:url';
describe('oom-once', () => {
it('fails with the WASM OOM signature on first run, passes on retry', () => {
- const sentinel = new URL('./oom-sentinel.txt', import.meta.url).pathname;
+ const sentinel = fileURLToPath(new URL('./oom-sentinel.txt', import.meta.url));
if (!existsSync(sentinel)) {
writeFileSync(sentinel, 'ran-once');
console.error('Original error: Out of memory');
diff --git a/test/serve-fail-fast.test.ts b/test/serve-fail-fast.test.ts
index e7618b875d..5c626282f2 100644
--- a/test/serve-fail-fast.test.ts
+++ b/test/serve-fail-fast.test.ts
@@ -12,8 +12,9 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { serveFailFastRequested } from '../src/core/serve-fail-fast.ts';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
let home: string;
beforeAll(() => {
diff --git a/test/skillpack-reference-strict-args.test.ts b/test/skillpack-reference-strict-args.test.ts
index 85f0a53011..daa9a4e343 100644
--- a/test/skillpack-reference-strict-args.test.ts
+++ b/test/skillpack-reference-strict-args.test.ts
@@ -18,8 +18,9 @@ import { join } from 'node:path';
import { strictArgsRefusal } from '../src/cli/strict-args.ts';
import { runSkillpack } from '../src/commands/skillpack.ts';
import * as referenceCore from '../src/core/skillpack/reference.ts';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
const SKILL = 'ask-user';
const created: string[] = [];
afterEach(() => {
diff --git a/test/stdin-silent-readers.test.ts b/test/stdin-silent-readers.test.ts
index 0c40e28359..7a340ce060 100644
--- a/test/stdin-silent-readers.test.ts
+++ b/test/stdin-silent-readers.test.ts
@@ -18,8 +18,9 @@ import { mkdtempSync, readdirSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { stdinFailureMessage } from '../src/core/stdin-read.ts';
+import { fileURLToPath } from 'node:url';
-const REPO = new URL('..', import.meta.url).pathname.replace(/\/$/, '');
+const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');
let home: string;
beforeAll(() => { home = mkdtempSync(join(tmpdir(), 'gbrain-stdin-silent-')); });
diff --git a/test/upgrade.serial.test.ts b/test/upgrade.serial.test.ts
index 83f2be364c..4e91ca3331 100644
--- a/test/upgrade.serial.test.ts
+++ b/test/upgrade.serial.test.ts
@@ -7,6 +7,7 @@ import { resolveBunGlobalRoot } from '../src/commands/upgrade.ts';
import { formatMarker } from '../src/core/self-upgrade.ts';
import type { BinarySelfUpdateResult } from '../src/core/binary-self-update.ts';
import { VERSION } from '../src/version.ts';
+import { fileURLToPath } from 'node:url';
// Install-method detection runs in-process where it spawns nothing (argv[1] /
// execPath patched); PATH-shimmed paths (clawhub, bun-link, bun update) run
@@ -15,7 +16,7 @@ import { VERSION } from '../src/version.ts';
describe('upgrade command', () => {
test('--help prints usage and exits 0', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'upgrade', '--help'], {
- cwd: new URL('..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
@@ -28,7 +29,7 @@ describe('upgrade command', () => {
test('-h also prints usage', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'upgrade', '-h'], {
- cwd: new URL('..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
@@ -169,7 +170,7 @@ describe('post-upgrade behavior (post v0.12.0 merge)', () => {
test('--help prints usage', async () => {
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'post-upgrade', '--help'], {
- cwd: new URL('..', import.meta.url).pathname,
+ cwd: fileURLToPath(new URL('..', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe',
});
@@ -207,7 +208,7 @@ describe('assessUpgradeOutcome (#4366)', () => {
describe('runUpgrade target verification (#4366)', () => {
const TARGET = '99.99.99.0';
const OLD = '0.40.0.0';
- const repoRoot = new URL('..', import.meta.url).pathname;
+ const repoRoot = fileURLToPath(new URL('..', import.meta.url));
/**
* Build a hermetic fake install under a temp HOME and run runUpgrade in a