fix: address Codex round 2 on BasePath trailing slash and benchmark DB cleanup

- profilerHandler: trim all trailing slashes (TrimRight), not just a bare "/", so
  a BaseURL like "/music/" strips correctly instead of 404ing. Cover it in the test.
- BenchmarkScan: keep and defer db.Init's closer so the DB is closed before
  b.TempDir cleanup, which otherwise cannot delete the open SQLite/WAL files on Windows.
This commit is contained in:
Deluan 2026-08-30 17:33:10 -04:00
parent b5089d380c
commit e982b837de
3 changed files with 5 additions and 5 deletions

View File

@ -151,10 +151,8 @@ func startServer(ctx context.Context) func() error {
// profilerHandler returns the pprof handler. net/http/pprof resolves the profile
// name from the raw request path, so the BasePath has to come off first.
func profilerHandler() http.Handler {
basePath := conf.Server.BasePath
if basePath == "/" { // StripPrefix("/") would drop the leading slash chi needs
basePath = ""
}
// A trailing or root slash would make StripPrefix drop the leading slash chi needs.
basePath := strings.TrimRight(conf.Server.BasePath, "/")
return http.StripPrefix(basePath, middleware.Profiler())
}

View File

@ -41,5 +41,6 @@ var _ = Describe("profilerHandler", func() {
Entry("without a BasePath", ""),
Entry("with a BasePath", "/music"),
Entry("with a root BasePath", "/"),
Entry("with a trailing-slash BasePath", "/music/"),
)
})

View File

@ -50,7 +50,8 @@ func BenchmarkScan(b *testing.B) {
// TestScanner may run first and close the shared DB singleton; drop it so db.Init
// opens a fresh one whether or not the test suite ran before this benchmark.
singleton.DeleteInstance[*sql.DB]()
db.Init(context.Background())
// Close before b.TempDir cleanup runs, or Windows cannot delete the open DB/WAL files.
defer db.Init(context.Background())()
ds := persistence.New(db.Db())
conf.Server.DevExternalScanner = false