Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci(guard): check:file-url-pathname fails verify on a file URL .pathname in test/ (#6845)

garrytan40c464ae2e56
diff --git a/docs/architecture/key-files/ci-health-and-test-guards.md b/docs/architecture/key-files/ci-health-and-test-guards.md
index 15de9d7897..4fac6d307d 100644
--- a/docs/architecture/key-files/ci-health-and-test-guards.md
+++ b/docs/architecture/key-files/ci-health-and-test-guards.md
@@ -31,3 +31,4 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `.github/workflows/fix-wave-closeout.yml` + `scripts/fix-wave-closeout.ts` — closes what a merged fix wave superseded. `pull_request_target` on master (`closed`); the job runs only when the PR merged and its head repository is `garrytan/gbrain`, and sparse-checks-out only the script from the default branch. `supersededNumbers()` (pure) reads the PR numbers listed right after a line-leading `Supersedes` keyword; `runCloseout()` skips non-PRs and closed PRs, posts `closeoutMessage()` once per PR (keyed by `COMMENT_MARKER`, crediting the contributor only when the wave body says `Contributed by @handle`), closes it, caps a run at `MAX_CLOSES`, and turns a failed close into a warning. `--dry-run` reads without writing. Tests: `test/scripts/fix-wave-closeout.test.ts`. Process: `docs/RELEASING.md#fix-wave-closeout`.
- `scripts/check-skill-refs.mjs` + `scripts/portable-skill-links.ts` + `scripts/skills-commit-gate.sh` — skills-tree integrity gate (`bun run check:skill-refs`, in verify and the skills commit gate). Fails on dangling backtick `skills/` refs, `./`/`../` links, `composes:` and RESOLVER dispatcher slugs; donor-workspace paths outside the shrink-only allowlist; any `gbrain <cmd>` in a fenced line or inline code span (command position only: line/span start, after a shell separator, `nohup`/env prefixes) that is not a real command (union of `--tools-json`, `CLI_FLAG_REGISTRY`, `src/cli.ts` dispatch, the command table and op `cliHints`), plus curated known-bad subcommands (`embed refresh`); and a relative link that resolves outside the skills root, in `skills/` and in the generated `plugin/skills` and `plugin-variants/*/skills` trees (`skills/migrations/**` exempt). W4.7: a tools-json load failure FAILS the CLI lane (`--no-cli-refs` skips it deliberately); links are read in every form (`](./x)`, bare `](x.md)` unless a placeholder, `](<x>)`, titled, `[id]: x` definitions); a `[paid-consent]` lane, migrations included, fails a paid `gbrain` command carrying `--yes`/`--max-usd`/`--max-cost[-usd]` with no ask/agree/approve/consent/confirm/permission wording on its line or the 8 before. `portable-skill-links.ts` is that rule's fix: it points `docs/protocol/AGENT_OPERATOR_v1.md` links at the bundled `skills/conventions/agent-operator-protocol.md` and other repo files at absolute blob URLs derived from `LLMS_REPO_BASE` (raw.githubusercontent base → github.com blob base; default `garrytan/gbrain/blob/master`; a non-https or credentialed value throws via `repoBaseOrThrow`, as in `scripts/llms-config.ts`), retargeting default-base links for forks; `--check` reports pending rewrites. Tests: `test/check-skill-refs.test.ts`, `test/skills-portable-links.test.ts` (scaffold `--all` into a tmp host: 0 broken local links).
+- `scripts/check-file-url-pathname.sh` — `check:file-url-pathname` (in verify, #6845): no `.pathname` of a file URL (`import.meta.url).pathname`, `pathToFileURL(...).pathname`) in test/, which keeps `%20` and breaks a checkout under a path with a space; use `fileURLToPath` or `import.meta.dir`. Self-tested via `GBRAIN_GUARD_ROOT` fixtures; skips `test/fixtures/guards/`.
diff --git a/package.json b/package.json
index 6359b0e90b..74dfdd3527 100644
--- a/package.json
+++ b/package.json
@@ -74,6 +74,7 @@
"check:admin-scope-drift": "bash scripts/check-admin-scope-drift.sh",
"check:cli-exec": "bash scripts/check-cli-executable.sh",
"check:engine-dynamic-import": "bash scripts/check-engine-dynamic-import.sh",
+ "check:file-url-pathname": "bash scripts/check-file-url-pathname.sh",
"check:grok-pin": "bash scripts/check-grok-pin.sh",
"check:opencode-pin": "bash scripts/check-opencode-pin.sh",
"check:pin-doc-privacy": "bash scripts/check-pin-doc-privacy.sh",
diff --git a/scripts/check-file-url-pathname.sh b/scripts/check-file-url-pathname.sh
new file mode 100755
index 0000000000..c786f90cf7
--- /dev/null
+++ b/scripts/check-file-url-pathname.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+# Guard (#6845): no `.pathname` of a file URL in test code.
+#
+# `new URL(rel, import.meta.url).pathname` keeps the URL percent-encoding, so
+# a checkout under a path with a space (or any other escaped character) turns
+# `/tmp/gb space/` into `/tmp/gb%20space/` and the file is not found. Use
+# `fileURLToPath(new URL(rel, import.meta.url))` from node:url, or
+# `import.meta.dir` / `import.meta.path`.
+#
+# Scans test/ (*.ts, *.mts, *.js, *.mjs), except the guard fixtures under
+# test/fixtures/guards/. Flags `import.meta.url).pathname`,
+# `import.meta.url.pathname` and `pathToFileURL(...).pathname` on one line.
+#
+# Usage: bash scripts/check-file-url-pathname.sh
+# Self-test seam: GBRAIN_GUARD_ROOT points at a fixture tree.
+# Exit: 0 when clean, 1 with one line per finding.
+
+set -uo pipefail
+
+ROOT="${GBRAIN_GUARD_ROOT:-$(git -C "$(dirname "$0")/.." rev-parse --show-toplevel 2>/dev/null || (cd "$(dirname "$0")/.." && pwd))}"
+cd "$ROOT" || exit 1
+if [ ! -d test ]; then
+ echo "check-file-url-pathname: no test/ directory under $ROOT" >&2
+ exit 1
+fi
+
+PATTERN='import\.meta\.url\)?\.pathname|pathToFileURL\([^)]*\)\.pathname'
+hits=$(grep -rnE --include='*.ts' --include='*.mts' --include='*.js' --include='*.mjs' "$PATTERN" test | grep -v '^test/fixtures/guards/' || true)
+if [ -n "$hits" ]; then
+ echo "$hits"
+ echo "check-file-url-pathname: FAIL. A file URL's .pathname keeps %20 and other escapes, so the path breaks under a directory with a space."
+ echo "Fix: fileURLToPath(new URL(rel, import.meta.url)) from node:url, or import.meta.dir / import.meta.path (#6845)."
+ exit 1
+fi
+echo "check-file-url-pathname: ok"
diff --git a/scripts/guards-manifest.tsv b/scripts/guards-manifest.tsv
index f29d3587a2..9b839592d0 100644
--- a/scripts/guards-manifest.tsv
+++ b/scripts/guards-manifest.tsv
@@ -97,3 +97,4 @@ check-weight-coverage.ts scanner yes C2 (GBRA-47): weight-map entries naming mis
check-recipe-pricing.ts scanner yes X1 (wave 9 lane A, D22): every model a recipe touchpoint lists resolves through isModelPriceable or is named in the recipe's unpriced_models; stale markers fail; GBRAIN_GUARD_ROOT seam reads <root>/recipes.json against the real price tables
check-write-gate-regex.ts scanner yes #5575 ENG-16: write-gate detector patterns (WRITE_GATE_PATTERNS) are bounded (no * + {n,}, bound <= 200, no nested repeats, no backrefs), longest match <= MAX_MATCH_CHARS, preceded contexts $-anchored and <= MAX_PRECEDING_CHARS, non-global with lowercase anchors; GBRAIN_GUARD_ROOT reads <root>/patterns.json
check-chunk-visibility.ts scanner yes Wave B segmented storage (spec 4.2, TS AST): every FROM/JOIN content_chunks statement in src uses chunkVisibleFilter (or its generation siblings) or carries -- chunk-visibility-ok: <reason>; per-file uncovered counts in scripts/chunk-visibility-baseline.tsv only shrink; --prune lowers rows
+check-file-url-pathname.sh scanner yes #6845: a file URL .pathname in test/ keeps %20 escapes; GBRAIN_GUARD_ROOT seam; skips test/fixtures/guards/
diff --git a/scripts/run-verify-parallel.sh b/scripts/run-verify-parallel.sh
index 4ed1f75a54..47828342c4 100755
--- a/scripts/run-verify-parallel.sh
+++ b/scripts/run-verify-parallel.sh
@@ -147,6 +147,7 @@ CHECKS=(
"check:no-double-retry"
"check:batch-audit-site"
"check:engine-dynamic-import"
+ "check:file-url-pathname"
"check:grok-pin"
"check:opencode-pin"
"check:pin-doc-privacy"
diff --git a/test/fixtures/guards/check-file-url-pathname.sh/bad-path-to-file-url/test/helpers/cli.ts b/test/fixtures/guards/check-file-url-pathname.sh/bad-path-to-file-url/test/helpers/cli.ts
new file mode 100644
index 0000000000..86628b317a
--- /dev/null
+++ b/test/fixtures/guards/check-file-url-pathname.sh/bad-path-to-file-url/test/helpers/cli.ts
@@ -0,0 +1,2 @@
+import { pathToFileURL } from 'node:url';
+export const CLI = pathToFileURL('src/cli.ts').pathname;
diff --git a/test/fixtures/guards/check-file-url-pathname.sh/bad/test/repo-root.ts b/test/fixtures/guards/check-file-url-pathname.sh/bad/test/repo-root.ts
new file mode 100644
index 0000000000..b05b684d5a
--- /dev/null
+++ b/test/fixtures/guards/check-file-url-pathname.sh/bad/test/repo-root.ts
@@ -0,0 +1 @@
+export const REPO = new URL('..', import.meta.url).pathname;
diff --git a/test/fixtures/guards/check-file-url-pathname.sh/good/test/repo-root.ts b/test/fixtures/guards/check-file-url-pathname.sh/good/test/repo-root.ts
new file mode 100644
index 0000000000..d494612da3
--- /dev/null
+++ b/test/fixtures/guards/check-file-url-pathname.sh/good/test/repo-root.ts
@@ -0,0 +1,4 @@
+import { fileURLToPath } from 'node:url';
+export const REPO = fileURLToPath(new URL('..', import.meta.url));
+export const HERE = import.meta.dir;
+export const route = (url: URL) => url.pathname;