Skip to content

Add a DurableFileTests suite — the crash-safety primitive has no tests of its own #3

Description

@eliseorobles

Context

DurableFile is what makes SPEC §5 durability true. The job counter, the session record, the published-batch history and atomic batch publication all go through it — so a defect here is invariant #1, never lose an acknowledged page, failing quietly.

It has no tests. grep -rn 'DurableFile' Tests/ returns exactly one hit in the whole test tree (Tests/ScanDeckImagePipelineTests/BatchPublisherTests.swift:426), and that call uses flush as setup for a different assertion. Nothing exercises write or rename, and no test asserts any DurableFileError case.

It is pure filesystem code — no AppKit, no scanner, no ImageCaptureCore. This is the easiest high-value suite in the repository to write.

What to change

New file Tests/ScanDeckCoreTests/DurableFileTests.swift. Model the temp-directory harness on Tests/ScanDeckCoreTests/JobCounterStoreTests.swiftevery test must inject a temp directory; nothing may touch real user state.

The API is in Sources/ScanDeckCore/DurableFile.swift: flush(_:), rename(_:to:), write(_:to:).

Behaviours worth pinning:

  • write creates intermediate directories.
  • write leaves no .<uuid>.tmp sibling behind — on success or on failure.
  • Overwriting an existing file replaces it atomically.
  • flush on a missing path throws DurableFileError.cannotOpen.
  • rename to a path on another volume throws .cannotRename.

The sharpest untested edge is in rename itself: the destination directory is flushed after Darwin.rename has already succeeded, so a throw from that flush reports failure for a move that actually happened. Pin whichever behaviour is intended and say which in the PR — if you think it is wrong, open that as a separate issue rather than changing it inside a test PR.

Use Swift Testing (@Suite / @Test / #expect), not XCTest.

How to verify

swift test --filter DurableFileTests
swift test -c release

See CONTRIBUTING.md. No scanner needed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions