Orphaned .backgrounds/ files get tidied — a repoint trims the one it leaves behind, and every open sweeps what got away

Follow-up to d0c5461's .backgrounds/ folder: generating, pasting, or
choosing solid now trims the app's own prior file in .backgrounds/ as
part of the same write when it repoints or unsets background.image
away from it — silent, best-effort, never blocking the gesture that
triggered it. A scheduled heal at every board open sweeps whatever
that trim declined or missed: any .backgrounds/ file the board's
current background.image no longer names, announced with a loss-row
notice in the loose-file relocation's own voice. Legacy root-level
references are untouched by both paths — the tidy scopes to
.backgrounds/ only, since that is the one folder the app can prove it
wrote into.

Removal is via FileManager.trashItem, matching the attachment-removal
precedent (recoverable, never a hard delete).

Supersedes applySolidBackground's earlier "facets.png survives on
disk" contract for the settled case: the ruling reads "unsets" as one
more shape of "repoints away from a .backgrounds/ file", so a settled
solid choice now trims the generated picture it displaces, same as
switching producers does. The superseded test and doc comment are
updated to the new behavior; the echo-window (no-reload-yet) case is
unaffected and still leaves the file in place.

Claude-Session: https://claude.ai/code/session_014PtZdPwqZuqEDLc6wZMtEy
This commit is contained in:
2026-08-09 09:44:30 -04:00
parent d905e73960
commit ca0328be2e
9 changed files with 858 additions and 26 deletions
+20
View File
@@ -748,6 +748,26 @@ struct PasteBoardBackgroundTests {
#expect(try background(harness.fixture).backgroundImage.value == ".backgrounds/Pasted Background.png")
}
/// `theTwoProducersStayApart`'s settled counterpart the orphan tidy's replace-in-place trim
/// (ruled 2026-08-09): once the generate has *settled* (a reload landed and `snapshot` caught up
/// with it), a paste that repoints away from it trims the generated file, on the same terms
/// `GeneratedBackgroundTests.BackgroundReplaceInPlaceTrimTests` pins for the reverse direction.
@Test("A paste after a settled generated background trims it")
func aSettledPasteTrimsTheGeneratedFile() async throws {
let harness = try makeClipboardHarness()
defer { harness.tearDown() }
let generated = encodedImage(.png, side: 4)
#expect(harness.store.applyGeneratedBackground(png: generated, colorHex: "#445566"))
await settle(harness.store)
harness.pasteboard.seed([(UTType.png.identifier, encodedImage(.png, side: 8))])
#expect(harness.clipboard.pasteBoardBackground(into: harness.store))
#expect(!harness.fixture.exists(".backgrounds/\(FacetsGenerator.fileName)"), "trimmed by the settled paste")
#expect(try background(harness.fixture).backgroundImage.value == ".backgrounds/Pasted Background.png")
#expect(harness.store.banners.losses.isEmpty, "the in-flow trim is silent")
}
@Test("⌘Z puts the image subkey back and leaves the colour alone")
func undoRestoresTheSubkey() throws {
let fixture = try makeClipboardBoard()