diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 54298be..b0ea7a7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -40,4 +40,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v8 with: - version: v2.10 + version: v2.14 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ae7d0b1..295ee3d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,9 +29,9 @@ jobs: if: matrix.os == 'windows-latest' run: go test -v ./... - - name: Run tests with coverage + - name: Run tests with race detector and coverage if: matrix.os != 'windows-latest' - run: go test -v -coverprofile=coverage.out ./... + run: go test -v -race -coverprofile=coverage.out ./... - name: Upload coverage if: matrix.os == 'ubuntu-latest' diff --git a/.golangci.yml b/.golangci.yml index b830ee0..12bab05 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -59,8 +59,9 @@ linters: - gocognit - nestif - # Note: copyloopvar, intrange, modernize, perfsprint require Go 1.22+ + # Note: copyloopvar, intrange, modernize require Go 1.22+ # They will be enabled when Go version constraint is lifted. + # perfsprint has no Go version floor; it stays off for now, as its findings are mechanical errors.New swaps. settings: depguard: @@ -194,9 +195,6 @@ linters: - text: "SELECT" linters: - gosec - - path: "cmd/hack-browser-data/main.go" - linters: - - lll - path: "masterkey/gcoredump_darwin.go" linters: - gocognit @@ -210,7 +208,8 @@ formatters: - goimports settings: gofumpt: - extra-rules: true + extra: + group-params: true goimports: local-prefixes: - github.com/moond4rk/hackbrowserdata diff --git a/CLAUDE.md b/CLAUDE.md index 0f9200a..e385a74 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -61,7 +61,7 @@ make payload-clean # rm internal/abe/payload/*.bin - **Logging**: `log.Debugf` for record-level diagnostics, `log.Infof` for user-facing progress/status, `log.Warnf` for unexpected conditions. Extract methods should return errors, not log them. - **Naming**: follow Go conventions and the settled names in `rfcs/004-naming-decisions.md` — `Def` not `BrowserConfig`, `Extract` not `BrowsingData` - **Comment width**: wrap comments at 140 columns (matches `.golangci.yml` `lll.line-length`) -- **Tests**: `internal/browser/browsertest` builds real fixture files (SQLite, JSON, LevelDB, plist) into a `t.TempDir()` — never a live browser, never a database mock; goldens live in each package's `testdata/` and `go test ./... -update` regenerates them +- **Tests**: `internal/browser/browsertest` builds real fixture files (SQLite, JSON, LevelDB, plist) into a `t.TempDir()` — never a live browser, never a database mock; goldens live in each package's `testdata/` and `HBD_UPDATE_GOLDEN=1 go test ./...` regenerates them - **Architecture**: see `rfcs/README.md` — design RFCs 000–011, format and technique RFCs 013–021 ## Key Constraints diff --git a/internal/golden/golden.go b/internal/golden/golden.go index 89cfb45..56f2c63 100644 --- a/internal/golden/golden.go +++ b/internal/golden/golden.go @@ -1,9 +1,8 @@ -// Package golden compares test output against files in the calling package's testdata/, which -update rewrites. +// Package golden compares test output against files in the calling package's testdata/, which HBD_UPDATE_GOLDEN=1 rewrites. package golden import ( "archive/zip" - "flag" "fmt" "os" "path/filepath" @@ -15,21 +14,23 @@ import ( "github.com/stretchr/testify/require" ) -var update = flag.Bool("update", false, "rewrite the golden files from the current code") +// updateEnv is an environment variable, not a test flag: go test ./... passes a flag to packages that do not define it, +// and reading the variable at test time keys go test's cache on it. +const updateEnv = "HBD_UPDATE_GOLDEN" const dir = "testdata" -// Assert compares got with testdata/, rewriting it first when -update is set. +// Assert compares got with testdata/, rewriting it first when HBD_UPDATE_GOLDEN=1. func Assert(t testing.TB, name, got string) { t.Helper() path := filepath.Join(dir, name) - if *update { + if os.Getenv(updateEnv) == "1" { require.NoError(t, os.MkdirAll(dir, 0o755)) require.NoError(t, os.WriteFile(path, []byte(got), 0o644)) } want, err := os.ReadFile(path) require.NoError(t, err) - assert.Equal(t, string(want), got, "regenerate with: go test ./... -run '%s' -update", t.Name()) + assert.Equal(t, string(want), got, "regenerate with: %s=1 go test ./... -run '%s'", updateEnv, t.Name()) } // Read returns testdata/. diff --git a/rfcs/011-testing-and-quality.md b/rfcs/011-testing-and-quality.md index e9bfcd5..a868654 100644 --- a/rfcs/011-testing-and-quality.md +++ b/rfcs/011-testing-and-quality.md @@ -29,7 +29,7 @@ These guard the contract; a failure means something a user can see has changed. ## Golden files -Export and extractor tests compare against checked-in golden outputs. Deterministic ordering is what makes goldens stable — without it, goldens would flap. A `-update` flag regenerates them on intentional changes. Goldens double as documentation of the exact output shape, useful for the README and for talks. +Export and extractor tests compare against checked-in golden outputs. Deterministic ordering is what makes goldens stable — without it, goldens would flap. Setting `HBD_UPDATE_GOLDEN=1` regenerates them on intentional changes. Goldens double as documentation of the exact output shape, useful for the README and for talks. Each golden lives beside the package whose output it pins: the export goldens in `export`, `keys.json` in `masterkey`, and the `extract`, `archive`, and `restore` goldens — all of which run the pipeline — in `app`; the flag-surface and `list` goldens stay in `cmd/hack-browser-data`. Shared fixture builders are in `internal/browser/browsertest`, the comparison helpers in `internal/golden`. A golden holds what no other golden already implies: the Cookie-Editor golden holds only `cookie.json`, because every other category is asserted to match the json output byte for byte, and `restore` is asserted to match the extract output except for its `browser` stamp.