Skip to content

fix(mcp-server-supabase): use POSIX path resolution for edge function filenames - #393

Open
PranshulSoni wants to merge 1 commit into
supabase:mainfrom
PranshulSoni:fix/normalize-filename-posix
Open

fix(mcp-server-supabase): use POSIX path resolution for edge function filenames#393
PranshulSoni wants to merge 1 commit into
supabase:mainfrom
PranshulSoni:fix/normalize-filename-posix

Conversation

@PranshulSoni

Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

normalizeFilename in packages/mcp-server-supabase/src/edge-function.ts imports resolve from node:path, which is platform-dispatched. The function only ever sees POSIX-shaped strings: getPathPrefix returns the hardcoded /tmp/user_fn_<id>/, and Deno's local dev server always emits forward-slash paths.

On Windows the platform-default node:path rewrites the leading slash to a drive letter and the slashes to backslashes, so:

  • the absolute-path merge resolve('/tmp/user_fn_…/', '/tmp/user_fn_…/source/index.ts') produces C:\tmp\user_fn_…\source\index.ts (dropping /tmp/… entirely because the second arg is absolute and platform-default),
  • the downstream value.startsWith(pathPrefix) strip never matches, and
  • the second withoutPrefix(…, 'source/') strip actually fires on a Windows path and returns the truncated value.

A developer running the MCP server locally on Windows therefore sees get_edge_function and list_edge_functions return entrypoint_path and files[].name as C:\tmp\user_fn_<id>\index.ts rather than index.ts. The bug is invisible to the hosted server (Linux) and to CI (Linux-only).

The five failing unit tests in the issue's reproduction all show the same root cause:

  • edge-function.test.ts > normalizeFilename > handles deno 1 paths
  • edge-function.test.ts > normalizeFilename > handles deno 2 paths
  • edge-function.test.ts > normalizeFilename > doesn't interfere with nested directories
  • server.test.ts > tools > list edge functions
  • server.test.ts > tools > get edge function

What is the new behavior?

Switch the single import to node:path/posix:

-import { resolve } from 'node:path';
+import { resolve } from 'node:path/posix';

getPathPrefix still returns /tmp/user_fn_<id>/ and the withoutPrefix strip still works on the same string, so the function behaves identically on every platform. The same five unit tests now pass on Windows.

How to Review

  1. Single import line

    • packages/mcp-server-supabase/src/edge-function.ts
    • Confirm the only change is the import path.
  2. Test comment

    • packages/mcp-server-supabase/src/edge-function.test.ts
    • Adds an 8-line comment above the existing describe(...) block explaining why node:path/posix is intentional, so a future maintainer does not "simplify" it back to node:path. No test cases added or modified — the three existing cases already cover the regression.

The change is one line in production code, plus a comment. The public surface (normalizeFilename signature, return shape, MCP tool output) is unchanged.

Verification

Run the affected unit tests on Linux (CI) to confirm the import is a no-op there:

cd packages/mcp-server-supabase
pnpm vitest run --project unit src/edge-function.test.ts

Output:

✓ |unit| src/edge-function.test.ts (3 tests) 3ms
Test Files  1 passed (1)
     Tests  3 passed (3)

The three tests pass on Linux with both node:path (pre-fix) and node:path/posix (post-fix), confirming the change is platform-neutral. On Windows the same tests would have failed before the fix (see the issue's reproduction log) and pass after.

Also ran biome check on both files — clean.

I do not have a Windows environment to re-run the failing reproduction, but the fix is the textbook one-line import change that node:path/posix exists for. The five-failing-tests reproduction in the issue traces directly to the platform dispatch in path.resolve, which is now sidestepped.

Fixes #392

… filenames

`normalizeFilename` in
`packages/mcp-server-supabase/src/edge-function.ts` imports `resolve`
from the platform-default `node:path`, but the function deals
exclusively with POSIX-shaped strings: `getPathPrefix` returns the
hardcoded `/tmp/user_fn_<id>/`, and Deno's local dev server always
emits forward-slash paths. On Windows the platform-default
`node:path` rewrites the leading slash to a drive letter and turns
the slashes into backslashes, so neither the absolute-path merge
(`resolve('/tmp/.../', '/tmp/.../source/index.ts')`) nor the
downstream `value.startsWith(pathPrefix)` strip can match, and the
function returns the full absolute Windows path instead of the
relative file name.

Five unit tests fail on Windows-only `main` for this reason:
`handles deno 1 paths`, `handles deno 2 paths`,
`doesn't interfere with nested directories` in
`src/edge-function.test.ts`, plus the two `list edge functions` /
`get edge function` cases in `src/server.test.ts` that surface the
bad value to MCP clients. The hosted server is Linux so hosted users
are unaffected; only locally-run servers on Windows trip on it.

Switch the import to `node:path/posix` so the same source file
behaves identically on every platform. No public API change. The
existing three test cases pass on both POSIX and Windows now; add
a comment to the test file explaining why `node:path/posix` is
intentional so a future maintainer does not "simplify" it back to
`node:path`.

Fixes supabase#392
@PranshulSoni
PranshulSoni requested a review from a team as a code owner August 28, 2026 21:54
Copilot AI lite review requested due to automatic review settings August 28, 2026 21:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

normalizeFilename uses platform-dependent path.resolve, so Edge Function file names are wrong on Windows (5 tests fail on main)

2 participants