fix(agent-prompt-resolver): handle file:// URIs cross-platform#8
Conversation
PR Summary by QodoFix plugin override file:// URI resolution across platforms Description
Diagram
High-Level Assessment
Files changed (4)
|
Code Review by Qodo
1. POSIX join breaks tilde test
|
…L parser
The plugin_override resolver used string-based parsing for `file://`
URIs:
const fileUri = value.match(/^file:\/\/(.+)$/)
if (raw.startsWith('/')) ...
This breaks on Windows where a properly-formed URI is
`file:///C:/path` (three slashes, drive letter, forward slashes),
and where a Windows-style `file://C:\\path\\x.md` (two slashes,
backslashes) is malformed. The manual `startsWith` ladder then
mis-classifies the malformed input and the resolver silently drops
into the wrong target.
The fix uses WHATWG `URL` and `fileURLToPath` to do the parsing:
- Form A `file://./...` and `file://../...` — relative to the
config file's directory, detected by regex BEFORE `new URL()`
because `URL` would otherwise resolve `./` against the
process cwd.
- Form B `file://~/...` — tilde is a convention, not a URL
standard, expanded against `homedir()`.
- Form C `file:///abs/path` / `file:///C:/path` — parsed via
`new URL()` + `fileURLToPath`. Malformed URIs degrade to
the `config` target (the value is left verbatim in
`source.value`, no `file_uri` claim is made).
Tests updated to use `pathToFileURL(target).href` instead of
`\`file://\${target}\``, which on Windows produces a malformed
URI (only 2 slashes, backslashes) and is now caught as a malformed
URL on every platform. The new test "malformed `file://` URI
degrades to `config` target" exercises the catch path with a
deliberately malformed input (`file://[invalid`) that is rejected
on all platforms.
`tests/path-utils.test.ts` updated to use `path.posix.join` in
assertions where the test fixture uses forward slashes regardless
of platform; the implementation correctly uses the platform-native
separator.
Fixes the 7 Windows CI failures:
- resolveAgentPromptSource > `file:///abs/path` URI is resolved verbatim
- expandTilde > expands '~/...' against the supplied home
- candidateGlobalOpencodeDirs > starts with $XDG_CONFIG_HOME/opencode when set
- prompt source shape: file:// URI in a plugin override file >
resolver classifies a file:// URI as plugin_override target=file_uri
- prompt source shape: file:// URI in a plugin override file >
AgentPromptManager.read() returns the file body for a file:// URI source
- prompt source shape: file:// URI in a plugin override file >
AgentPromptManager.write() edits the file at the URI, leaves the
plugin config's `prompt_append` field unchanged
- prompt source shape: file:// URI in a plugin override file >
file:// URI with a ~/... path resolves to $HOME
1659fbd to
da8e03f
Compare
No description provided.