From e982b837de0b7c48fbb7d2bb445f6c42f9a813d1 Mon Sep 17 00:00:00 2001 From: Deluan Date: Sun, 30 Aug 2026 17:33:10 -0400 Subject: [PATCH] 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. --- cmd/root.go | 6 ++---- cmd/root_test.go | 1 + scanner/scanner_benchmark_test.go | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 100a27f06..94f861f40 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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()) } diff --git a/cmd/root_test.go b/cmd/root_test.go index 1b46c285f..af8d44e7e 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -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/"), ) }) diff --git a/scanner/scanner_benchmark_test.go b/scanner/scanner_benchmark_test.go index 2b01f907c..65410d500 100644 --- a/scanner/scanner_benchmark_test.go +++ b/scanner/scanner_benchmark_test.go @@ -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