Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(scripts): decode the repository root with fileURLToPath (#6845)
time-attack68b195d04163
diff --git a/scripts/check-core-guard-coverage.mjs b/scripts/check-core-guard-coverage.mjsindex 20c3a9c162..1cffa739dc 100644--- a/scripts/check-core-guard-coverage.mjs+++ b/scripts/check-core-guard-coverage.mjs@@ -16,9 +16,10 @@*/import { readFileSync, readdirSync, statSync } from 'node:fs';import { join, relative } from 'node:path';+import { fileURLToPath } from 'node:url';// Fixture root for scripts/guard-self-test.sh: argv[2] or GBRAIN_GUARD_ROOT.-const ROOT = process.argv[2] ?? process.env.GBRAIN_GUARD_ROOT ?? new URL('..', import.meta.url).pathname;+const ROOT = process.argv[2] ?? process.env.GBRAIN_GUARD_ROOT ?? fileURLToPath(new URL('..', import.meta.url));/** Reviewed: preparers that publish without the core guard, and why that is safe. */const EXEMPT = {diff --git a/src/commands/schema.ts b/src/commands/schema.tsindex f96ac69cf4..7fdabbedc9 100644--- a/src/commands/schema.ts+++ b/src/commands/schema.ts@@ -20,6 +20,7 @@ import { assertManagedFilesystemWrite } from '../core/persistence/filesystem-guaimport { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';import { dirname, join } from 'node:path';+import { fileURLToPath } from 'node:url';import { parseArgs } from 'node:util';import {addAliasToType,@@ -405,7 +406,7 @@ function packPathByName(name: string): string | null {const asset = bundledPackPath(name);if (asset) return asset;// Resolve bundled YAML — import.meta fallback, try a few locations.- const here = dirname(new URL(import.meta.url).pathname);+ const here = dirname(fileURLToPath(import.meta.url));const candidates = [join(here, '..', 'core', 'schema-pack', 'base', `${name}.yaml`),join(here, '..', '..', 'src', 'core', 'schema-pack', 'base', `${name}.yaml`),diff --git a/test/scripts/check-core-guard-coverage-root.test.ts b/test/scripts/check-core-guard-coverage-root.test.tsnew file mode 100644index 0000000000..cec5a0e09c--- /dev/null+++ b/test/scripts/check-core-guard-coverage-root.test.ts@@ -0,0 +1,37 @@+/**+ * #6845: scripts/check-core-guard-coverage.mjs derives its repository root+ * from import.meta.url. URL.pathname keeps percent-encoding, so a checkout+ * whose path has a space or a non-ASCII character scanned a directory that+ * doesn't exist and failed. The root must be the decoded file path.+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { spawnSync } from 'node:child_process';+import { copyFileSync, mkdirSync, mkdtempSync, rmSync, symlinkSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';++const REPO = join(import.meta.dir, '..', '..');+let parent: string;+let root: string;++beforeAll(() => {+ parent = mkdtempSync(join(tmpdir(), 'gbrain-guard-root-'));+ root = join(parent, 'wt dir é');+ mkdirSync(join(root, 'scripts'), { recursive: true });+ copyFileSync(join(REPO, 'scripts', 'check-core-guard-coverage.mjs'), join(root, 'scripts', 'check-core-guard-coverage.mjs'));+ symlinkSync(join(REPO, 'src'), join(root, 'src'));+});++afterAll(() => {+ rmSync(parent, { recursive: true, force: true });+});++describe('#6845 core guard coverage check in a path with a space and an accent', () => {+ test('scans the checkout it sits in without GBRAIN_GUARD_ROOT', () => {+ const env = { ...process.env };+ delete env.GBRAIN_GUARD_ROOT;+ const r = spawnSync('node', [join(root, 'scripts', 'check-core-guard-coverage.mjs')], { cwd: root, env, encoding: 'utf8' });+ expect(r.stderr).not.toContain('ENOENT');+ expect(r.status).toBe(0);+ });+});