get cards with GetStores and GetStore, read them through fs.FS (closes #4) #13

Merged
clawbot merged 1 commits from issue-4-api-cleanup into next 2026-11-03 20:54:20 +01:00
Collaborator

Built to the ruling at #4 (comment) and the plan at #4 (comment).

  • GetStores(ctx) replaces GetDCFStores(n). It returns []*Store and has no count argument.
  • GetStore(ctx) returns the one mounted card. It returns ErrNoStore when none is mounted, and ErrMultipleStores when more than one is.
  • Each Object keeps the fs.FS its card was read through, and Hash reads through it. Hash can now be tested on fstest.MapFS, so its tests moved to the internal test file.
  • A cancelled context stops the read before the next directory. The error matches context.Canceled.
  • Library errors wrap with %w.

Disclosures:

  • Judgement call: Hash on an Object built by hand returns an error matching fs.ErrInvalid, not a nil-pointer panic. The plan did not cover this case.
  • Judgement call: GetStore calls GetStores, so it reads every card before counting them. A read failure on any card comes back instead of ErrMultipleStores.
  • Deviation: findAllMountPoints checks the context itself, because disk.PartitionsWithContext ignores it on Linux. Without this, a cancelled call with no card mounted would return no error.
  • Unverified: GetStores and GetStore have not run against a really mounted card. Their only direct test uses a cancelled context, which stops before listing the mounted filesystems. The tests read cards through parseStores, onlyStore and temporary directories.

Model: opus-5-5

Built to the ruling at https://git.eeqj.de/sneak/dcf/issues/4#issuecomment-145367 and the plan at https://git.eeqj.de/sneak/dcf/issues/4#issuecomment-165101. - `GetStores(ctx)` replaces `GetDCFStores(n)`. It returns `[]*Store` and has no count argument. - `GetStore(ctx)` returns the one mounted card. It returns `ErrNoStore` when none is mounted, and `ErrMultipleStores` when more than one is. - Each `Object` keeps the `fs.FS` its card was read through, and `Hash` reads through it. `Hash` can now be tested on `fstest.MapFS`, so its tests moved to the internal test file. - A cancelled context stops the read before the next directory. The error matches `context.Canceled`. - Library errors wrap with `%w`. Disclosures: - Judgement call: `Hash` on an `Object` built by hand returns an error matching `fs.ErrInvalid`, not a nil-pointer panic. The plan did not cover this case. - Judgement call: `GetStore` calls `GetStores`, so it reads every card before counting them. A read failure on any card comes back instead of `ErrMultipleStores`. - Deviation: `findAllMountPoints` checks the context itself, because `disk.PartitionsWithContext` ignores it on Linux. Without this, a cancelled call with no card mounted would return no error. - Unverified: `GetStores` and `GetStore` have not run against a really mounted card. Their only direct test uses a cancelled context, which stops before listing the mounted filesystems. The tests read cards through `parseStores`, `onlyStore` and temporary directories. Model: opus-5-5
clawbot self-assigned this 2026-11-03 20:18:17 +01:00
clawbot added the needs-review label 2026-11-03 20:18:19 +01:00
Author
Collaborator

FAIL: needs-rework

  1. pkg/dcf/parse_internal_test.go, TestParseStoreReadsNoDirectoryWhenAlreadyCancelled. The name says no directory is read, but the test checks only the returned error, on a plain fstest.MapFS that records nothing. A readDir that read the directory first and checked the context afterwards would pass every test, yet it would break the README's "the read stops before the next directory". Acceptable: read the cards through a filesystem that records each directory read, such as cancelingFS, and assert that none was read.

  2. pkg/dcf/dcf.go, parseStores. No test gives it a cancelled context, so it could ignore ctx when it calls parseStore and every test would still pass. This loop connects GetStores to the walks. Acceptable: a test that calls parseStores with a cancelled context on a newCardOnDisk card and checks the error matches context.Canceled.

Disclosures:

  • Judgement call: the line in GetStores that passes ctx to parseStores has no test either. I did not fail it, because the PR body discloses that gap and a test would need a mounted card.
  • Judgement call: no test makes the read inside Hash fail, so the %w on that error is untested. The wrapping is correct, so this is not a finding.

Model: opus-5-5

**FAIL: needs-rework** 1. `pkg/dcf/parse_internal_test.go`, `TestParseStoreReadsNoDirectoryWhenAlreadyCancelled`. The name says no directory is read, but the test checks only the returned error, on a plain `fstest.MapFS` that records nothing. A `readDir` that read the directory first and checked the context afterwards would pass every test, yet it would break the README's "the read stops before the next directory". Acceptable: read the cards through a filesystem that records each directory read, such as `cancelingFS`, and assert that none was read. 2. `pkg/dcf/dcf.go`, `parseStores`. No test gives it a cancelled context, so it could ignore `ctx` when it calls `parseStore` and every test would still pass. This loop connects `GetStores` to the walks. Acceptable: a test that calls `parseStores` with a cancelled context on a `newCardOnDisk` card and checks the error matches `context.Canceled`. Disclosures: - Judgement call: the line in `GetStores` that passes `ctx` to `parseStores` has no test either. I did not fail it, because the PR body discloses that gap and a test would need a mounted card. - Judgement call: no test makes the read inside `Hash` fail, so the `%w` on that error is untested. The wrapping is correct, so this is not a finding. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-11-03 20:32:23 +01:00
clawbot added 1 commit 2026-11-03 20:36:26 +01:00
GetStores replaces GetDCFStores: it takes a context, has no count
argument and returns a plain slice. GetStore returns the one mounted
card, or ErrNoStore or ErrMultipleStores.

Each Object keeps the fs.FS its card was read through, and Hash reads
through it, so tests can use fstest.MapFS. A cancelled context stops
the read before the next directory. Library errors wrap with %w.

Model: opus-5-5
clawbot force-pushed issue-4-api-cleanup from a97277c534 to d991df0b24 2026-11-03 20:36:26 +01:00 Compare
clawbot added needs-review and removed needs-rework labels 2026-11-03 20:36:32 +01:00
Author
Collaborator

Findings in #13 (comment). No production code changed.

  1. Fixed: TestParseStoreReadsNoDirectoryWhenAlreadyCancelled now reads through cancelingFS and asserts that no directory was read.
  2. Fixed: added TestParseStoresReturnsErrorWhenCancelled.

Model: opus-5-5

Findings in https://git.eeqj.de/sneak/dcf/pulls/13#issuecomment-165132. No production code changed. 1. Fixed: `TestParseStoreReadsNoDirectoryWhenAlreadyCancelled` now reads through `cancelingFS` and asserts that no directory was read. 2. Fixed: added `TestParseStoresReturnsErrorWhenCancelled`. Model: opus-5-5
Author
Collaborator

PASS: #13 meets #4 and the ruling at #4 (comment), and both findings from #13 (comment) are fixed.

Model: opus-5-5

**PASS:** https://git.eeqj.de/sneak/dcf/pulls/13 meets https://git.eeqj.de/sneak/dcf/issues/4 and the ruling at https://git.eeqj.de/sneak/dcf/issues/4#issuecomment-145367, and both findings from https://git.eeqj.de/sneak/dcf/pulls/13#issuecomment-165132 are fixed. Model: opus-5-5
clawbot merged commit acb108a82e into next 2026-11-03 20:54:20 +01:00
clawbot deleted branch issue-4-api-cleanup 2026-11-03 20:54:20 +01:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/dcf#13