uttrflow / uttrflow/uttrflow-swift
Test that ClipboardStore reports couldNotWrite when the disk refuses a copied picture or a list write
- Dominant language
- Swift
- Stars
- 4
- Forks
- 17
- Avg merge
- 4h 27m
- Merged PRs (30d)
- 286
Description
## What happens
`Sources/UttrflowClipboard/ClipboardStore.swift` has two `catch { throw .couldNotWrite }` blocks that have never run:
- line 206, in `keep(_:forClip:width:height:sha:)`: writing a copied picture into `Images/` fails;
- line 486, in `persist(_:to:)`: creating the folder or atomically writing a list fails.
The existing test `writeFailure` ("reports a disk that refuses the write") passes through the `unreplaceable` guard on line 477 instead, so neither `catch` is reached.
Measured on origin/main `26d7bc1` with `swift test --enable-code-coverage` (5,384 tests, all passing) and `xcrun llvm-cov export` over the test binary. The regions named below have an execution count of 0: no test runs them, so a change that breaks them passes `make verify`.
## Why it matters
The comment on `keep` says "a missing file is forever". A picture must be on disk before a clip points at it, and the pinned list must not be replaced by a half-written one. If either `catch` stops throwing, the store records a clip whose picture never landed, or says a pin was saved when it wasn't.
## How to reproduce
Run `swift test --enable-code-coverage`, then `xcrun llvm-cov show -instr-profile .build/debug/codecov/default.profdata .build/debug/UttrflowPackageTests.xctest/Contents/MacOS/UttrflowPackageTests Sources/UttrflowClipboard/ClipboardStore.swift` and look for the `0` counts on the lines named above.
## Acceptance criteria
- A test records a `NoticedClip` with a picture into a store whose `Images` path is blocked by a regular file. It expects `ClipboardStoreError.couldNotWrite`, and `clips(keeping:)` must not contain a clip pointing at the missing picture.
- A test makes the history file's folder exist but unwritable (or blocks the file path with a directory), records a text clip, and expects `.couldNotWrite` from `persist`, with the earlier list still readable.
- Each new test fails when the branch it covers is broken. Check this by hand before opening the PR: temporarily change the branch (flip the condition or return the other value), see the test fail, then restore it.
## Where to start
- `Tests/UttrflowClipboardTests/ClipboardStoreTests.swift`. Copy `writeFailure` and its `TemporaryFile(named:)` "blocker" trick, but block `imagesFolder` or the list file instead of the parent folder.
- `Tests/UttrflowClipboardTests/ClipImageTests.swift` builds `NoticedClip` values with pictures.
Read `CONTRIBUTING.md` first. Iterate with `swift test --filter `, then run `make verify` before pushing. Only tests change; no product code needs to.
**Size:** S.
Contributor guide
Research direction
Read CONTRIBUTING.md, then inspect Tests/UttrflowClipboardTests/ClipboardStoreTests.swift, especially writeFailure and TemporaryFile(named:); use ClipImageTests.swift for NoticedClip values with pictures. Run the focused Swift tests while blocking imagesFolder and the history path as described. Done means both error paths return .couldNotWrite, preserve the earlier list, and fail under a temporary mutation before make verify passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100