Skip to content

fix(tests): use fileURLToPath so source-safety specs pass on checkout paths with spaces#351

Open
hharsha98 wants to merge 1 commit into
Conway-Research:mainfrom
hharsha98:fix/test-source-paths-with-spaces
Open

fix(tests): use fileURLToPath so source-safety specs pass on checkout paths with spaces#351
hharsha98 wants to merge 1 commit into
Conway-Research:mainfrom
hharsha98:fix/test-source-paths-with-spaces

Conversation

@hharsha98

Copy link
Copy Markdown

Problem

17 specs fail with ENOENT when the repo is checked out to a path containing a space, because the source-safety assertions locate files via new URL(rel, import.meta.url).pathname, and URL.pathname percent-encodes the path (space → %20). fs.readFileSync then can't find the file. CI never sees this because the runner path has no special characters. See #350.

Fix

Resolve the paths with fileURLToPath(new URL(rel, import.meta.url)) instead. It decodes percent-encoding, is cross-platform, and lets the fragile .replace("/src/__tests__/../", "/src/") string surgery be removed.

Test-only changes:

  • src/__tests__/command-injection.test.ts (5 sites)
  • src/__tests__/skills-hardening.test.ts (12 sites)

Verification

  • pnpm vitest run src/__tests__/command-injection.test.ts src/__tests__/skills-hardening.test.ts132 passed (132) (was 17 failing)
  • pnpm typecheck → clean

The assertions themselves are unchanged; no source or behavior changes.

Fixes #350

…paths with spaces

The source-safety assertions in command-injection.test.ts and
skills-hardening.test.ts located files via
`new URL(rel, import.meta.url).pathname`. URL.pathname percent-encodes
the path, so a repo checked out to a directory containing a space (or
other URL-special characters) yields e.g. `/foo%20bar/src/...`, and
readFileSync throws ENOENT — 17 specs fail purely because of the
checkout path.

Use fileURLToPath(new URL(rel, import.meta.url)) instead: it decodes
percent-encoding and is cross-platform, and it removes the fragile
'/src/__tests__/../' string replacement.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test suite fails with ENOENT when the repo path contains a space (URL.pathname percent-encoding in source-safety specs)

1 participant