adds Clean Copy Support

This commit is contained in:
2026-10-12 09:43:57 +02:00
parent 188e078055
commit 281f5465a6
28 changed files with 579 additions and 120 deletions
@@ -35,6 +35,15 @@ import Testing
#expect(TerminalLaunch.environment(from: ["LC_ALL": "nl_NL.UTF-8"])["LANG"] == nil)
}
@Test func bothPanesTellTheChildItRunsInHelder() {
let base = ["TERM_PROGRAM": "Apple_Terminal", "TERM_PROGRAM_VERSION": "455"]
for kind in TerminalKind.allCases {
let env = TerminalLaunch.make(kind: kind, config: .defaults, projectRoot: "/p", environment: base).environment
#expect(env["TERM_PROGRAM"] == "Helder")
#expect(env["TERM_PROGRAM_VERSION"] == nil)
}
}
@Test func agentRunsTheCommandThroughAnInteractiveShell() {
let launch = TerminalLaunch.make(kind: .agent, config: .defaults, projectRoot: "/p", environment: ["SHELL": "/bin/bash"])
#expect(launch.executable == "/bin/bash")
@@ -43,6 +43,18 @@ private final class EventLog: @unchecked Sendable {
#expect(log.count(.git) == 0)
}
@Test func theCleanCopyFileFiresItsOwnEventNextToTheProjectEvent() async throws {
let dir = try TempDirectory()
let (watcher, log) = await watch(dir.root)
defer { watcher.stop() }
try dir.write("notes/.clean-copy", "elsewhere")
await settle()
#expect(log.count(.cleanCopy) == 0)
try dir.write(CleanCopy.fileName, "copy me")
#expect(await eventually { log.count(.cleanCopy) >= 1 })
#expect(await eventually { log.count(.project) >= 1 })
}
@Test func changesInsideIgnoredFoldersAreDropped() async throws {
let dir = try TempDirectory()
try dir.mkdir("node_modules/pkg")
@@ -0,0 +1,112 @@
import Foundation
import HelderCore
import HelderServices
@testable import HelderUI
import Testing
@MainActor
@Suite struct CleanCopyTests {
private let file = CleanCopy.fileName
private func started(_ text: String? = nil) async -> WorkspaceHarness {
let harness = WorkspaceHarness(contents: text.map { [CleanCopy.fileName: $0] } ?? [:])
await harness.start()
return harness
}
private func agentWrites(_ text: String, _ harness: WorkspaceHarness) async {
harness.files.set(file, text)
await harness.model.handle(.cleanCopy)
await harness.model.settle()
}
@Test func theTextFoundOnProjectOpenIsTheBaselineAndNeverPops() async {
let harness = await started("left over from yesterday")
#expect(harness.model.overlay.current == .none)
await harness.model.handle(.cleanCopy)
#expect(harness.model.overlay.current == .none)
}
@Test func aChangedFileOpensThePopupWithItsText() async {
let harness = await started("old")
await agentWrites("git commit -m \"fix\"", harness)
#expect(harness.model.overlay.current == .cleanCopy)
#expect(harness.model.cleanCopy?.text == "git commit -m \"fix\"")
}
@Test func aFileThatAppearsAfterOpenPops() async {
let harness = await started()
await agentWrites("first", harness)
#expect(harness.model.overlay.current == .cleanCopy)
}
@Test func theSameTextAgainDoesNotPop() async {
let harness = await started()
await agentWrites("once", harness)
await harness.perform(.dismissOverlay)
await agentWrites("once", harness)
#expect(harness.model.overlay.current == .none)
}
@Test func anEmptyOrBlankFileDoesNotPop() async {
let harness = await started("old")
await agentWrites("", harness)
await agentWrites(" \n\t", harness)
#expect(harness.model.overlay.current == .none)
}
@Test func copyPutsTheEditedTextOnThePasteboardClosesAndToasts() async {
let harness = await started()
await agentWrites("draft", harness)
harness.model.cleanCopy?.text = "draft, edited"
await harness.perform(.copyCleanCopy)
#expect(harness.system.copied == ["draft, edited"])
#expect(harness.model.overlay.current == .none)
#expect(harness.toastTitles == ["Copied"])
}
@Test func escClosesWithoutCopying() async {
let harness = await started()
await agentWrites("draft", harness)
await harness.perform(.dismissOverlay)
#expect(harness.system.copied.isEmpty)
#expect(harness.model.overlay.current == .none)
}
@Test func newTextReplacesAnUneditedPopup() async {
let harness = await started()
await agentWrites("one", harness)
await agentWrites("two", harness)
#expect(harness.model.overlay.current == .cleanCopy)
#expect(harness.model.cleanCopy?.text == "two")
}
@Test func newTextLeavesAnEditedPopupAlone() async {
let harness = await started()
await agentWrites("one", harness)
harness.model.cleanCopy?.text = "one, mine"
await agentWrites("two", harness)
#expect(harness.model.cleanCopy?.text == "one, mine")
#expect(harness.model.cleanCopy?.pending == nil)
}
@Test func textWaitsForAnotherOverlayAndOnlyTheLatestShows() async {
let harness = await started()
await harness.perform(.showNote)
await agentWrites("one", harness)
await agentWrites("two", harness)
#expect(harness.model.overlay.current == .note)
await harness.perform(.dismissOverlay)
#expect(await eventually { harness.model.overlay.current == .cleanCopy })
#expect(harness.model.cleanCopy?.text == "two")
}
@Test func theFileIsNeverWrittenOrDeleted() async {
let harness = await started()
await agentWrites("keep", harness)
await harness.perform(.copyCleanCopy)
#expect(harness.files.current(file) == "keep")
#expect(harness.files.deleted.isEmpty)
#expect(harness.files.writes.isEmpty)
}
}