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 1/4] 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 From 5f6c3068201897808022ada47829deec1bd77bc6 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Fri, 9 Jan 2026 01:09:35 +0800 Subject: [PATCH 2/4] fix: support arbitrary test directories --- internal/db/test/test.go | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/internal/db/test/test.go b/internal/db/test/test.go index b3d3bcbbf..3b8d9cf16 100644 --- a/internal/db/test/test.go +++ b/internal/db/test/test.go @@ -26,29 +26,22 @@ const ( func Run(ctx context.Context, testFiles []string, config pgconn.Config, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error { // Build test command + binds := []string{} 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) + if len(testFiles) == 0 { + testFiles = append(testFiles, utils.DbTestsDir) } for _, fp := range testFiles { - 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) + if !filepath.IsAbs(fp) { + fp = filepath.Join(utils.CurrentDirAbs, fp) } - cmd = append(cmd, relPath) + dockerPath := utils.ToDockerPath(fp) + cmd = append(cmd, dockerPath) + binds = append(binds, fmt.Sprintf("%s:%s:ro", fp, dockerPath)) } if viper.GetBool("DEBUG") { cmd = append(cmd, "--verbose") } - // Mount tests directory into container as working directory - srcPath := absTestsDir - dstPath := "/tmp" - binds := []string{fmt.Sprintf("%s:%s:ro", srcPath, dstPath)} // Enable pgTAP if not already exists alreadyExists := false options = append(options, func(cc *pgx.ConnConfig) { @@ -93,7 +86,7 @@ func Run(ctx context.Context, testFiles []string, config pgconn.Config, fsys afe "PGDATABASE=" + config.Database, }, Cmd: cmd, - WorkingDir: dstPath, + WorkingDir: utils.CurrentDirAbs, }, hostConfig, network.NetworkingConfig{}, From 7189e9b3c7a34973c7c8e8c7ba7661332afe453d Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Fri, 9 Jan 2026 01:12:12 +0800 Subject: [PATCH 3/4] chore: unset container working dir --- internal/db/test/test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/db/test/test.go b/internal/db/test/test.go index 3b8d9cf16..86f51dea8 100644 --- a/internal/db/test/test.go +++ b/internal/db/test/test.go @@ -85,8 +85,7 @@ func Run(ctx context.Context, testFiles []string, config pgconn.Config, fsys afe "PGPASSWORD=" + config.Password, "PGDATABASE=" + config.Database, }, - Cmd: cmd, - WorkingDir: utils.CurrentDirAbs, + Cmd: cmd, }, hostConfig, network.NetworkingConfig{}, From 83f6d28b66824f5d52c2a1a3607bb4b1eb79be6f Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Fri, 9 Jan 2026 01:14:12 +0800 Subject: [PATCH 4/4] chore: refactor bind mount --- internal/db/test/test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/db/test/test.go b/internal/db/test/test.go index 86f51dea8..3f9aff8e6 100644 --- a/internal/db/test/test.go +++ b/internal/db/test/test.go @@ -26,18 +26,18 @@ const ( func Run(ctx context.Context, testFiles []string, config pgconn.Config, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error { // Build test command - binds := []string{} - cmd := []string{"pg_prove", "--ext", ".pg", "--ext", ".sql", "-r"} if len(testFiles) == 0 { testFiles = append(testFiles, utils.DbTestsDir) } - for _, fp := range testFiles { + binds := make([]string, len(testFiles)) + cmd := []string{"pg_prove", "--ext", ".pg", "--ext", ".sql", "-r"} + for i, fp := range testFiles { if !filepath.IsAbs(fp) { fp = filepath.Join(utils.CurrentDirAbs, fp) } dockerPath := utils.ToDockerPath(fp) cmd = append(cmd, dockerPath) - binds = append(binds, fmt.Sprintf("%s:%s:ro", fp, dockerPath)) + binds[i] = fmt.Sprintf("%s:%s:ro", fp, dockerPath) } if viper.GetBool("DEBUG") { cmd = append(cmd, "--verbose")