Fix NumSecrets() always returning 0 (closes #4) #9

Merged
sneak merged 2 commits from clawbot/secret:fix/issue-4 into main 2026-02-09 02:39:30 +01:00
Contributor

NumSecrets() now checks for the current file instead of looking for non-existent direct file children. Includes test.

This also fixes the safety check in UnlockersRemove that was always allowing removal of the last unlocker.

NumSecrets() now checks for the `current` file instead of looking for non-existent direct file children. Includes test. This also fixes the safety check in `UnlockersRemove` that was always allowing removal of the last unlocker.
sneak was assigned by clawbot 2026-02-08 21:06:00 +01:00
clawbot added 1 commit 2026-02-08 21:06:00 +01:00
NumSecrets() previously looked for non-directory, non-'current' files
directly under each secret directory, but the only children are
'current' (file, excluded) and 'versions' (directory, excluded),
so it always returned 0.

Now checks for the existence of the 'current' file, which is the
canonical indicator that a secret exists and has an active version.

This fixes the safety check in UnlockersRemove that was always
allowing removal of the last unlocker.
Author
Contributor

Test Results

Tests with ONLY test changes (no fix applied): FAIL

=== RUN   TestVaultOperations
=== RUN   TestVaultOperations/CreateVault
=== RUN   TestVaultOperations/ListVaults
=== RUN   TestVaultOperations/SelectVault
=== RUN   TestVaultOperations/SecretOperations
=== RUN   TestVaultOperations/NumSecrets
    vault_test.go:179: Expected 1 secret, got 0
=== RUN   TestVaultOperations/UnlockerOperations
--- FAIL: TestVaultOperations (0.36s)
    --- PASS: TestVaultOperations/CreateVault (0.02s)
    --- PASS: TestVaultOperations/ListVaults (0.00s)
    --- PASS: TestVaultOperations/SelectVault (0.00s)
    --- PASS: TestVaultOperations/SecretOperations (0.00s)
    --- FAIL: TestVaultOperations/NumSecrets (0.00s)
    --- PASS: TestVaultOperations/UnlockerOperations (0.34s)
FAIL

The new NumSecrets test correctly detects the bug: Expected 1 secret, got 0.

Tests with fix applied: PASS

ok  git.eeqj.de/sneak/secret/internal/vault  0.655s

Code quality

  • gofmt -l .: No formatting issues
  • go vet ./...: No issues
## Test Results ### Tests with ONLY test changes (no fix applied): FAIL ``` === RUN TestVaultOperations === RUN TestVaultOperations/CreateVault === RUN TestVaultOperations/ListVaults === RUN TestVaultOperations/SelectVault === RUN TestVaultOperations/SecretOperations === RUN TestVaultOperations/NumSecrets vault_test.go:179: Expected 1 secret, got 0 === RUN TestVaultOperations/UnlockerOperations --- FAIL: TestVaultOperations (0.36s) --- PASS: TestVaultOperations/CreateVault (0.02s) --- PASS: TestVaultOperations/ListVaults (0.00s) --- PASS: TestVaultOperations/SelectVault (0.00s) --- PASS: TestVaultOperations/SecretOperations (0.00s) --- FAIL: TestVaultOperations/NumSecrets (0.00s) --- PASS: TestVaultOperations/UnlockerOperations (0.34s) FAIL ``` The new NumSecrets test correctly detects the bug: Expected 1 secret, got 0. ### Tests with fix applied: PASS ``` ok git.eeqj.de/sneak/secret/internal/vault 0.655s ``` ### Code quality - gofmt -l .: No formatting issues - go vet ./...: No issues
Owner

@clawbot remember in all repos to always use the checks specified in the makefile, not random invented “go vet”. we have standards in almost all repos that must be followed.

@clawbot remember in all repos to always use the checks specified in the makefile, not random invented “go vet”. we have standards in almost all repos that must be followed.
sneak added 1 commit 2026-02-09 02:26:22 +01:00
Author
Contributor

Understood — will use make test (which runs lintvetgo test) and make check (build + test) from the Makefile going forward, not ad-hoc commands. Will apply this to all repos.

Understood — will use `make test` (which runs `lint` → `vet` → `go test`) and `make check` (build + test) from the Makefile going forward, not ad-hoc commands. Will apply this to all repos.
sneak merged commit b06d7fa3f4 into main 2026-02-09 02:39:30 +01:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sneak/secret#9
No description provided.