// Send: one local write, and the chips written down beside it.//// The optimistic-cache cases (put a `temp-` row in on send, swap it on success,// filter it out on error) have no subject here: this app has no query cache, a// write answers with `tables` and the screens re-read (design P5). What is left// is the pair of facts that matter, and the two this file had to prove for itself.importFoundationimport XCTest@testable importCottonKitfinalclassCaptureServiceTests: XCTestCase {privatelet key = "@cotton:pendingLinks:v1:u1:ws-1"privatestructKit {let core: ScriptedCorelet store: MemoryLinkStorelet service: CaptureService }privatefunc makeKit(answer: ScriptedCore.Reply = .ok(#"{"id":"i1"}"#)) -> Kit {let core = ScriptedCore([CottonMethod.captureCreate: answer])let store = MemoryLinkStore()let links = PendingLinks( userId: "u1", workspaceId: "ws-1", store: store, source: ScriptedLinkSource(), writer: RecordingLinkWriter(), now: { Date(timeIntervalSince1970: 1_785_542_400) }, report: { _ in } )returnKit(core: core, store: store, service: CaptureService(core: core, links: links)) }func testRemembersBothKindsOfChipAgainstTheRowThatLanded() asyncthrows {let kit = makeKit() _ = tryawait kit.service.capture(CaptureRequest(text: "lunch with Meera", projectIds: ["pr-1"]), personIds: ["per-1", "per-2"] )let stored = kit.store.intents(key) XCTAssertEqual(stored.count, 1) XCTAssertEqual(stored.first?.inboxItemId, "i1") XCTAssertEqual(stored.first?.projectIds, ["pr-1"]) XCTAssertEqual(stored.first?.personIds, ["per-1", "per-2"]) }func testARefusalIsThrownAndRemembersNothing() async {// The previous app rolled its optimistic row back on error; the host// does that by keeping its draft when this throws. What matters here is the// half that IS this layer's: a capture that did not land has no id to hang// an intent on, and inventing one would leave a chip waiting a week for a// record that was never going to exist.let kit = makeKit(answer: .refuse(code: "bad_request", message: "no"))do { _ = tryawait kit.service.capture(CaptureRequest(text: "x", projectIds: ["pr-1"]), personIds: ["per-1"] ) XCTFail("a refused capture must throw") } catch { XCTAssertEqual((error as? CottonCallError)?.code, "bad_request") } XCTAssertFalse(kit.store.has(key)) }// ── The pictures on a capture (store schema 36) ─────────────────────}