Skip to content

fix(testutil): derive a per-workspace database for non-.test binaries - #983

Open
AmirF194 wants to merge 2 commits into
tokencanopy:mainfrom
AmirF194:fix/827-contract-server-shared-testdb-collision
Open

fix(testutil): derive a per-workspace database for non-.test binaries#983
AmirF194 wants to merge 2 commits into
tokencanopy:mainfrom
AmirF194:fix/827-contract-server-shared-testdb-collision

Conversation

@AmirF194

@AmirF194 AmirF194 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

derivedDBSuffix() (internal/testutil/db.go) only derived the per-workspace,
per-package test database name when os.Args[0] ended in .test. The one
non-test binary sharing this harness, cmd/e2a-contract-server, fell back to
the base URL verbatim, so two instances started from different checkouts (two
agents, two worktrees) landed on the same e2a_test database and truncated
each other's rows on Close, exactly as #827 describes.

The suffix is now keyed on the running binary's own name regardless of a
.test suffix, so cmd/e2a-contract-server derives its own per-workspace
database the same way a go test binary already does. testutil is imported
by exactly one other non-test file, cmd/e2a-contract-server/main.go; every
other consumer is a go test binary and derives the same suffix it did
before.

This PR doesn't touch the API or any client surface, so I've dropped the
client surface checklist.

Test plan

  • New regression test TestTestDBURLDerivesForNonTestBinaries: fails on
    main (derived name is the bare base, e2a_test) and passes on this
    branch (*_ws<hash>_pkg_e2a_contract_server), both run against a real
    Postgres 16 container.
  • Built the real cmd/e2a-contract-server binary and ran two instances from
    two different checkout paths against the same Postgres server: they landed
    on two distinct e2a_test_ws*_pkg_e2a_contract_server databases.
  • Full internal/testutil suite green against Postgres 16
    (go test ./internal/testutil/... -v).
  • Repo-wide go test ./..., gofmt/make fmt-check, and go vet all clean.

derivedDBSuffix() only derived the per-workspace, per-package database
suffix when os.Args[0] ended in ".test", so cmd/e2a-contract-server, the
one non-test binary sharing this harness, fell back to the base URL
verbatim. Two contract-server instances from different checkouts (two
agents, two worktrees) landed on the same e2a_test database and
truncated each other's rows on Close.

The suffix is now keyed on the running binary's own name regardless of
a ".test" suffix, so a compiled binary derives one too. testutil is
imported by exactly one other non-test file, cmd/e2a-contract-server;
every other consumer is already a `go test` binary and derives the
same suffix it did before.

Fixes tokencanopy#827
@AmirF194
AmirF194 requested a review from jiashuoz as a code owner September 1, 2026 14:22
Signed-off-by: Amir Fathi <amirfathi.me@gmail.com>
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.

1 participant