read text aloud

This commit is contained in:
2026-10-23 09:40:20 +02:00
parent 281f5465a6
commit 92b90c0e13
20 changed files with 471 additions and 18 deletions
@@ -625,7 +625,7 @@ import Testing
Issue.record("no context menu")
return
}
#expect(menuLabels(menu) == ["Copy", "Paste"])
#expect(menuLabels(menu) == ["Copy", "Paste", "Wait what?"])
#expect(menu.header.isEmpty)
#expect(menu.anchor == CGPoint(x: 900, y: 300))
}
@@ -637,6 +637,14 @@ import Testing
#expect(harness.system.copied == ["npm test"])
}
@Test func waitWhatInsertsTheSelectionAsAWaitWhatCommand() async {
let harness = WorkspaceHarness()
harness.agent.selectedText = " the reviewer was unsure\n"
await harness.perform(.context(.waitWhat(.agent)))
#expect(harness.agent.sent == [BracketedPaste.wrap("/wait-what `the reviewer was unsure`", composerHasText: false)])
#expect(harness.toastTitles == ["Passed to agent"])
}
@Test func pasteSendsThePasteboardToThatTerminal() async {
let harness = WorkspaceHarness()
let shell = FakeTerminal()
@@ -662,3 +670,78 @@ import Testing
}
}
@MainActor
@Suite struct ReadAloudModelTests {
@Test func aMarkdownFileIsReadAsPlainText() async {
let harness = WorkspaceHarness(contents: ["README.md": "# Hello\n\nSome **bold** [link](https://x.com)\n\n```\ncode\n```"])
await harness.start()
await harness.perform(.context(.readAloudFile("README.md")))
#expect(harness.speech.spoken == ["Hello.\nSome bold link."])
#expect(harness.model.readAloud.isReading)
}
@Test func theOpenFileIsReadWithItsUnsavedEdits() async {
let harness = WorkspaceHarness(contents: ["README.md": "On disk"])
await harness.start()
harness.model.open("README.md")
await harness.model.settle()
harness.model.editor?.edit("Typed")
await harness.perform(.context(.readAloudFile("README.md")))
#expect(harness.speech.spoken == ["Typed."])
}
@Test func aFileWithoutProseReadsNothingAndSaysSo() async {
let harness = WorkspaceHarness(contents: ["README.md": "```\nonly code\n```"])
await harness.start()
await harness.perform(.context(.readAloudFile("README.md")))
#expect(harness.speech.spoken.isEmpty)
#expect(!harness.model.readAloud.isReading)
#expect(harness.toastTitles == ["Nothing to read"])
}
@Test func aSelectionIsReadAsItIs() async {
let harness = WorkspaceHarness()
await harness.start()
await harness.perform(.context(.readAloudText("let a = 1")))
#expect(harness.speech.spoken == ["let a = 1"])
}
@Test func aDollarSignIsReadAsDollar() async {
let harness = WorkspaceHarness()
await harness.start()
await harness.perform(.context(.readAloudText("echo $HOME costs $5")))
#expect(harness.speech.spoken == ["echo dollar HOME costs $5"])
}
@Test func stopEndsTheReading() async {
let harness = WorkspaceHarness()
await harness.start()
await harness.perform(.context(.readAloudText("words")))
await harness.perform(.stopReading)
#expect(harness.speech.stops == 1)
#expect(!harness.model.readAloud.isReading)
}
@Test func readingToTheEndClearsTheState() async {
let harness = WorkspaceHarness()
await harness.start()
await harness.perform(.context(.readAloudText("words")))
harness.speech.finish()
#expect(!harness.model.readAloud.isReading)
}
@Test func aProjectSwitchStopsTheReading() async {
let harness = WorkspaceHarness()
await harness.start()
await harness.perform(.context(.readAloudText("words")))
await harness.model.openProject(URL(fileURLWithPath: "/fake/other"))
#expect(!harness.model.readAloud.isReading)
#expect(harness.speech.stops == 1)
}
@Test func readAloudUsesTheSpeakerIcon() {
#expect(ContextMenuOverlay.symbol(for: .readAloudFile("README.md")) == "speaker.wave.2")
#expect(ContextMenuOverlay.tint(for: .readAloudText("x")) == .plain)
}
}