From c6deb8687f329461284d4c6cd50883e858434195 Mon Sep 17 00:00:00 2001 From: 7ttp <117663341+7ttp@users.noreply.github.com> Date: Sat, 6 Dec 2025 18:28:21 +0530 Subject: [PATCH] fix(db test): resolve absolute paths before computing relative path 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 #3194 --- internal/db/test/test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/db/test/test.go b/internal/db/test/test.go index 428fc61a9..b3d3bcbbf 100644 --- a/internal/db/test/test.go +++ b/internal/db/test/test.go @@ -27,8 +27,16 @@ const ( func Run(ctx context.Context, testFiles []string, config pgconn.Config, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error { // Build test command cmd := []string{"pg_prove", "--ext", ".pg", "--ext", ".sql", "-r"} + absTestsDir, err := filepath.Abs(utils.DbTestsDir) + if err != nil { + return errors.Errorf("failed to resolve absolute path: %w", err) + } for _, fp := range testFiles { - relPath, err := filepath.Rel(utils.DbTestsDir, fp) + absPath, err := filepath.Abs(fp) + if err != nil { + return errors.Errorf("failed to resolve absolute path: %w", err) + } + relPath, err := filepath.Rel(absTestsDir, absPath) if err != nil { return errors.Errorf("failed to resolve relative path: %w", err) } @@ -38,10 +46,7 @@ func Run(ctx context.Context, testFiles []string, config pgconn.Config, fsys afe cmd = append(cmd, "--verbose") } // Mount tests directory into container as working directory - srcPath, err := filepath.Abs(utils.DbTestsDir) - if err != nil { - return errors.Errorf("failed to resolve absolute path: %w", err) - } + srcPath := absTestsDir dstPath := "/tmp" binds := []string{fmt.Sprintf("%s:%s:ro", srcPath, dstPath)} // Enable pgTAP if not already exists