Skip to content

fix(db): support arbitrary test directories#4590

Merged
sweatybridge merged 4 commits into
supabase:developfrom
7ttp:bug2
Jan 8, 2026
Merged

fix(db): support arbitrary test directories#4590
sweatybridge merged 4 commits into
supabase:developfrom
7ttp:bug2

Conversation

@7ttp

@7ttp 7ttp commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

when running supabase db test from a docker-outside-of-docker environment, test file paths may be absolute host paths while utils.DbTestsDir is relative. filepath.Rel fails when the base path is relative and the target is absolute, producing the error: Rel: can't make /path/to/supabase/tests relative to supabase/tests. this change converts both paths to absolute before computing the relative path, which handles all path combinations correctly.

cc @sweatybridge

closes #4523

when running supabase db test from a docker-outside-of-docker environment,
test file paths may be absolute host paths while utils.DbTestsDir is relative.
filepath.Rel fails when the base path is relative and the target is absolute.

this change converts both paths to absolute before computing the relative path,
which handles all path combinations correctly: relative+relative, absolute+absolute,
and mixed scenarios like docker-outside-of-docker.

closes supabase#3194
@7ttp 7ttp requested a review from a team as a code owner December 6, 2025 13:00
@sweatybridge sweatybridge changed the title fix(db test): resolve absolute paths before computing relative path fix(db): support arbitrary test directories Jan 8, 2026
@sweatybridge

Copy link
Copy Markdown
Contributor

Improved the command to support arbitrary test directories passed in via command line args.

@sweatybridge sweatybridge merged commit 0a02076 into supabase:develop Jan 8, 2026
16 of 17 checks passed
@7ttp 7ttp deleted the bug2 branch January 9, 2026 18:49
@franck-ada

Copy link
Copy Markdown

@7ttp @sweatybridge - We have a use case where we execute the test on 1 files but need some extra files imported via \i . with this fixed introduce we cannot use the \i anymore as the file is not imported.

@lightstrike

Copy link
Copy Markdown
Contributor

@franck-ada and all: we just hit this issue in a project as well. The patch in our case was to go from:

\i _utils/mocks/payload.sql.mock

to:

\ir ../../_utils/mocks/payload.sql.mock

Ideally WorkingDir could be set via config.toml to support arbitrary test directions, defaulting to supabase/tests to prevent regressions like the one mentioned above.

@franck-ada

Copy link
Copy Markdown

@lightstrike - thanks a lot for your comment this fix seems to work when you give a full directory (and your file is in it).
But if you run an exact file it seems to have the same issue. (cf #4734)

Comment thread internal/db/test/test.go
"PGDATABASE=" + config.Database,
},
Cmd: cmd,
WorkingDir: dstPath,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I feel the issue is coming from removing this part

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you are right. We need to set working dir supabase/tests for \i to work consistently inside and outside of docker.

@lightstrike

Copy link
Copy Markdown
Contributor

@franck-ada Did you try this as a workaround? Changing:

\i init-function.sql

to:

\ir ./init-function.sql

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.

Unable to run supabase test db when using docker-outside-of-docker

4 participants