test(editor): pin the external watch's false 67 conflict
CI / ci (push) Canceled after 0s

The external guest's watch (PostsModelImports.startExternalWatch)
reads disk raw while the session's text/lastFlushedText came through
readDocument's normalizing external branch (BOM strip + CRLF->LF), so
diskTextChanged raised conflictAlert on unchanged BOM/CRLF files —
re-arming after every sibling directory event and after either alert
answer, blocking departures and quit (brief-32, argus cycle-6).

Three RED pins over the real watch closure
(externalWatcher.onEvent): no conflict on an unchanged BOM/CRLF
guest, no re-arm after yes-reload or keep-local, and the load-bearing
negative — a real foreign write still raises. Targeted rail at base:
11 executed / 8 passed / 3 failed (all three new pins), 164
SwiftCompile lines.
This commit is contained in:
AlexKucera committed 2026-11-30 22:15:58 +01:00
1 parent 5341c4ee53
commit b69ddd3963
1 file changed
+86
+86
View File
@@ -25,6 +25,16 @@ private func writeExternal(_ name: String, _ body: String) throws -> URL {
return url return url
} }
/// brief-32: the guest-watch pins' own temp dir — `startExternalWatch`
/// observes the file's CONTAINING folder, so their guest must live where
/// no sibling test ever writes.
private func watchedDir() throws -> URL {
let dir = FileManager.default.temporaryDirectory
.appendingPathComponent("museion-watch-\(UUID().uuidString)", isDirectory: true)
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
return dir
}
@Suite(.serialized) @Suite(.serialized)
@MainActor @MainActor
struct ImportExternalTests { struct ImportExternalTests {
@@ -190,4 +200,80 @@ struct ImportExternalTests {
#expect(!session.conflictAlert) #expect(!session.conflictAlert)
#expect(session.text == "# C\n\nForeign edit.") #expect(session.text == "# C\n\nForeign edit.")
} }
// MARK: - The guest watch (brief-32: the #67 compare's disk read)
@Test func `external watch raises no 67 conflict on an unchanged BOM and CRLF file`() throws {
let model = PostsModel()
let dir = try watchedDir()
let ext = dir.appendingPathComponent("watched.md")
// Windows-authored file: BOM + CRLF. The open read normalizes
// (readDocument's external branch); the watch must read in the
// SAME representation or every directory event reads as #67.
try "\u{FEFF}# Title\r\n\r\nBody line.\r\n".write(to: ext, atomically: true, encoding: .utf8)
defer { try? FileManager.default.removeItem(at: dir) }
model.openExternal(ext)
let session = try #require(model.externalSession)
#expect(session.text == "# Title\n\nBody line.\n")
// Sibling directory events re-fire the compare (the watch observes
// the containing folder): representation alone must never raise.
model.externalWatcher.onEvent?()
#expect(!session.conflictAlert)
model.externalWatcher.onEvent?()
#expect(!session.conflictAlert)
}
@Test func `external watch still conflicts on a real write and never re-arms after yes-reload`() throws {
let model = PostsModel()
let dir = try watchedDir()
let ext = dir.appendingPathComponent("foreign.md")
try "\u{FEFF}# Title\r\n\r\nBody line.\r\n".write(to: ext, atomically: true, encoding: .utf8)
defer { try? FileManager.default.removeItem(at: dir) }
model.openExternal(ext)
let session = try #require(model.externalSession)
// A REAL external modification (different content, same BOM/CRLF
// representation): the departure gate must still see it.
try "\u{FEFF}# Title\r\n\r\nRewritten underneath.\r\n".write(to: ext, atomically: true, encoding: .utf8)
model.externalWatcher.onEvent?()
#expect(session.conflictAlert)
// Yes-reload takes the foreign content, normalized:
session.reloadFromDisk()
#expect(!session.conflictAlert)
#expect(session.text == "# Title\n\nRewritten underneath.\n")
// The next directory event reads the same unchanged bytes — the
// false conflict must not re-arm.
model.externalWatcher.onEvent?()
#expect(!session.conflictAlert)
}
@Test func `external watch never re-arms after keep-local on a BOM and CRLF file`() throws {
let model = PostsModel()
let dir = try watchedDir()
let ext = dir.appendingPathComponent("kept.md")
try "\u{FEFF}# Title\r\n\r\nBody line.\r\n".write(to: ext, atomically: true, encoding: .utf8)
defer { try? FileManager.default.removeItem(at: dir) }
model.openExternal(ext)
let session = try #require(model.externalSession)
try "\u{FEFF}# Title\r\n\r\nForeign body.\r\n".write(to: ext, atomically: true, encoding: .utf8)
model.externalWatcher.onEvent?()
#expect(session.conflictAlert)
// No: keep local — the disk state is seen, the local buffer stays
// and stays pending.
session.keepLocal()
#expect(!session.conflictAlert)
#expect(session.text == "# Title\n\nBody line.\n")
#expect(session.saveState == .changed)
model.externalWatcher.onEvent?()
#expect(!session.conflictAlert)
}
} }