Watch: review fixes for action errors that vanished, feed refreshes dropped or overwritten around a change, a fresh thread screen per route, errors cleared on sign out, notification actions only while paired, cache writes off the main thread and capped at 30 threads, Ask before acting and Load earlier races, two-letter search, C# headings, and strictly encoded query values

This commit is contained in:
gib committed 2026-11-02 15:29:15 -05:00
1 parent 99b300855e
commit 25be69fa30
14 files changed
+591 -94

No files matched your search

+47
View File
@@ -474,8 +474,50 @@ private let feedItemJSON = """
#expect(fresh.messages(before: [m("5")]).map(\.id) == ["5"])
}
@Test func olderMessagesTakeTheNewerCopy() {
func m(_ id: String, _ text: String) -> Message { Message(id: id, role: .assistant, text: text, createdAt: .now) }
var history = MessageHistory()
// Load earlier goes out with 3 caught mid-stream. A refresh lands before the page does.
history.startKeeping([m("3", "Runn"), m("4", "Done")])
history.keep([m("3", "Running the suite"), m("4", "Done"), m("5", "Next")])
#expect(history.messages(before: [m("6", "Later")]).map(\.text) == ["Running the suite", "Done", "Next", "Later"])
// The page repeats 3 and its copy, fetched last, wins in place.
history.prepend(HistoryResponse(messages: [m("2", "Two"), m("3", "Running the suite, all 48")], earlierCursor: nil))
#expect(history.messages(before: [m("6", "Later")]).map(\.text)
== ["Two", "Running the suite, all 48", "Done", "Next", "Later"])
}
@Test func queryValuesAreEncodedStrictly() {
let url = GatewayClient.url(
URL(string: "https://gateway.test")!, ["v1", "threads", "h/1", "t"],
query: [URLQueryItem(name: "cursor", value: "habc+/d=&e f")])
#expect(url.absoluteString == "https://gateway.test/v1/threads/h%2F1/t?cursor=habc%2B%2Fd%3D%26e%20f")
#expect(URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems?.first?.value == "habc+/d=&e f")
}
@Test func threadCacheKeepsTheNewest() async throws {
let directory = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
defer { try? FileManager.default.removeItem(at: directory) }
var cache = FeedCache(directory: directory)
cache.threadLimit = 3
var detail = try decode(ThreadDetail.self, #"{ "item": \#(feedItemJSON), "messages": [], "canStop": false }"#)
for id in ["a", "b", "c", "d", "e"] {
detail.item.threadId = id
cache.save(detail)
try await Task.sleep(for: .milliseconds(20))
}
cache.save(Feed(needsYou: [], working: [], recent: [], hosts: []))
let kept = ["a", "b", "c", "d", "e"].filter { cache.thread(hostId: detail.item.hostId, threadId: $0) != nil }
#expect(kept == ["c", "d", "e"])
#expect(cache.feed() != nil)
}
@Test func markdownReadsCleanly() {
#expect(Markdown.block("## Done") == "**Done**")
#expect(Markdown.block("## Porting to C#") == "**Porting to C#**")
#expect(Markdown.block("## Done ##") == "**Done**")
#expect(Markdown.block("# Notes # ") == "**Notes**")
#expect(Markdown.block(" - item") == " • item")
#expect(Markdown.block("> quoted") == "quoted")
#expect(Markdown.block("**bold** stays") == "**bold** stays")
@@ -599,6 +641,9 @@ private let feedItemJSON = """
#expect(Route(url: route.url) == route)
}
#expect(Route(url: URL(string: "wristcode://thread/only-host")!) == nil)
// The gateway searches two characters or more.
#expect(Route(url: URL(string: "wristcode://search?q=a")!) == nil)
#expect(Route(url: URL(string: "wristcode://search?q=ab")!) == .search(query: "ab"))
#expect(Route(url: URL(string: "https://thread/h/t")!) == nil)
}
@@ -1008,6 +1053,8 @@ private let feedItemJSON = """
#expect(model.feedIsCached)
model.signOut()
// The clear runs off the main actor, after any write still queued.
await model.cacheWrite?.value
#expect(cache.feed() == nil)
#expect(model.feed == nil)
}