package recruiting import ( "os" "path/filepath" "strings" "testing" ) // TestNoMustParseInRequestPaths guards the fix for the panicking id round trips. Every create in this // module used to return its new id as text and parse it back with uuid.MustParse, which CLAUDE.md forbids // in a request path: the parse has no legitimate failure mode, so the only thing it could ever do is // panic on a caller who did nothing wrong. Two of them ran AFTER the transaction committed, where a panic // destroys the response for work the database has already accepted and cannot be safely retried. The ids // are scanned as uuid.UUID now, so there is nothing left to parse. // // The guard is a source scan because the defect is the presence of a call, not a value any test could // observe: the panic is unreachable through the API without corrupting Postgres itself. func TestNoMustParseInRequestPaths(t *testing.T) { files, err := filepath.Glob("*.go") if err != nil { t.Fatal(err) } for _, f := range files { if strings.HasSuffix(f, "_test.go") { continue } src, err := os.ReadFile(f) if err != nil { t.Fatal(err) } for i, line := range strings.Split(string(src), "\n") { // Comments may name the call while explaining why it is gone. if strings.HasPrefix(strings.TrimSpace(line), "//") { continue } if strings.Contains(line, "uuid.MustParse") { t.Errorf("%s:%d: uuid.MustParse panics in a request path; scan the id as a uuid.UUID or return an error instead: %s", f, i+1, strings.TrimSpace(line)) } } } }