Skip to content

Commit f627599

Browse files
committed
test(migrations): unit-cover PublicVersion to satisfy 100% patch gate
The package-external test in router_test exercises PublicVersion but diff-cover attributes coverage by package, so the migrations/state.go PublicVersion body landed at 0% for diff-cover. Add a package-internal test (state_public_version_test.go) iterating the same 7 cases so the patch-coverage gate sees migrations/state.go at 100%. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 04c9fbb commit f627599

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package migrations_test
2+
3+
// state_public_version_test.go — BUG-API-090/217 regression. Lives in
4+
// the migrations package (not router_test) so go test's coverage tool
5+
// attributes the hits against migrations/state.go for the 100%-patch
6+
// gate.
7+
8+
import (
9+
"testing"
10+
11+
"github.com/stretchr/testify/require"
12+
13+
"instant.dev/internal/migrations"
14+
)
15+
16+
func TestPublicVersion_StripsFilenameSuffix(t *testing.T) {
17+
cases := []struct {
18+
filename string
19+
want string
20+
}{
21+
// The case that motivated the bug: BUG-API-090/217 — anyone
22+
// hitting /healthz saw the embedded table/feature name.
23+
{"063_forwarder_sent_audit_link.sql", "063"},
24+
{"022_schema_migrations.sql", "022"},
25+
{"001_init.sql", "001"},
26+
{"100_team_deletion_purge.sql", "100"},
27+
// No underscore — return stem only (strips .sql).
28+
{"baseline.sql", "baseline"},
29+
// No extension — return up to first underscore.
30+
{"063_anything", "063"},
31+
// Empty (DB unreachable / pre-migration).
32+
{"", ""},
33+
}
34+
for _, tc := range cases {
35+
s := migrations.State{Filename: tc.filename}
36+
got := s.PublicVersion()
37+
require.Equal(t, tc.want, got,
38+
"BUG-API-090: PublicVersion(%q) must strip to numeric prefix; got %q",
39+
tc.filename, got)
40+
// Sanity rail: no '_' or '.sql' escapes the helper, regardless of input.
41+
require.NotContains(t, got, "_",
42+
"BUG-API-090: PublicVersion must never contain '_' (would leak table/feature name)")
43+
require.NotContains(t, got, ".sql",
44+
"BUG-API-090: PublicVersion must never contain '.sql' (would leak filename)")
45+
}
46+
}

0 commit comments

Comments
 (0)