Open source CapCut alternative.
TypeScript
test(app): harden the prompt-eval harness and fixtures
David Le3458047eaab9
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/archive-large-old-files/scenario.json b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/archive-large-old-files/scenario.jsonindex 2f0dfbec..964f6bf1 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/archive-large-old-files/scenario.json+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/archive-large-old-files/scenario.json@@ -2,7 +2,7 @@"frontmostApp": "Finder","maxSteps": 16,"responses": [- { "tool": "shell_exec", "contains": ["mdfind"], "summary": "/Users/davidle/Movies/raw-shoot.mov\n/Users/davidle/Downloads/ubuntu.iso\n/Users/davidle/Desktop/backup.dmg" },+ { "tool": "shell_exec", "contains": ["mdfind"], "summary": "~/Movies/raw-shoot.mov\n~/Downloads/ubuntu.iso\n~/Desktop/backup.dmg" },{ "tool": "shell_exec", "contains": ["mv "], "summary": "Moved 3 files into ~/Archive." }],"expect": {diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/combine-and-compress-scans/scenario.json b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/combine-and-compress-scans/scenario.jsonindex 3c062340..405e38e8 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/combine-and-compress-scans/scenario.json+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/combine-and-compress-scans/scenario.json@@ -2,11 +2,20 @@"frontmostApp": "Finder","maxSteps": 18,"disk": [- { "path": "/Users/davidle/Desktop/scans", "describe": "Folder of 8 scanned PDFs, ~3MB each (24MB total)." }+ { "path": "~/Desktop/scans", "describe": "Folder of 8 scanned PDFs, ~3MB each (24MB total)." },+ { "path": "~/Desktop/scans/scan-01.pdf", "describe": "Scanned PDF, ~3MB." },+ { "path": "~/Desktop/scans/scan-02.pdf", "describe": "Scanned PDF, ~3MB." },+ { "path": "~/Desktop/scans/scan-03.pdf", "describe": "Scanned PDF, ~3MB." },+ { "path": "~/Desktop/scans/scan-04.pdf", "describe": "Scanned PDF, ~3MB." },+ { "path": "~/Desktop/scans/scan-05.pdf", "describe": "Scanned PDF, ~3MB." },+ { "path": "~/Desktop/scans/scan-06.pdf", "describe": "Scanned PDF, ~3MB." },+ { "path": "~/Desktop/scans/scan-07.pdf", "describe": "Scanned PDF, ~3MB." },+ { "path": "~/Desktop/scans/scan-08.pdf", "describe": "Scanned PDF, ~3MB." }],"responses": [- { "tool": "shell_exec", "contains": ["compress"], "summary": "Wrote scans-combined.pdf (4.2MB after downsampling).", "produces": ["scans-combined.pdf"] },- { "tool": "shell_exec", "summary": "Combined 8 PDFs into scans-combined-raw.pdf (24MB).", "produces": ["scans-combined-raw.pdf"] }+ { "tool": "shell_exec", "contains": ["qpdf"], "summary": "Combined the 8 scans into scans-combined.pdf, then downsampled to 4.2MB.", "produces": ["scans-combined.pdf"] },+ { "tool": "shell_exec", "contains": ["pdfunite"], "summary": "Combined the 8 scans into scans-combined.pdf.", "produces": ["scans-combined.pdf"] },+ { "tool": "shell_exec", "contains": ["gs"], "summary": "Downsampled scans-combined.pdf to 4.2MB.", "produces": ["scans-combined.pdf"] }],"expect": {"turnKind": "act",diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/pdf-to-markdown/scenario.json b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/pdf-to-markdown/scenario.jsonindex 6c21ec4a..da59e2bb 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/pdf-to-markdown/scenario.json+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/pdf-to-markdown/scenario.json@@ -5,6 +5,7 @@{ "path": "paper.pdf", "describe": "PDF open in Preview, 11 pages, selectable text — a research paper.", "contentFile": "paper.txt" }],"responses": [+ { "tool": "shell_exec", "contains": ["Preview"], "summary": "~/Desktop/paper.pdf", "facts": { "paper.pdf": "exists" } },{ "tool": "shell_exec", "contains": [".md"], "summary": "Wrote paper.md (headings + body from paper.pdf).", "produces": ["paper.md"] },{ "tool": "llm.generate", "summary": "Converted the extracted text to clean markdown.", "produces": ["paper.md"] }],diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/resize-trip-photos/scenario.json b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/resize-trip-photos/scenario.jsonindex 2e0271b2..165163af 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/resize-trip-photos/scenario.json+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/resize-trip-photos/scenario.json@@ -2,7 +2,19 @@"frontmostApp": "Finder","maxSteps": 18,"disk": [- { "path": "/Users/davidle/Desktop/trip", "describe": "Folder of 12 JPEG photos (3024x4032, ~4MB each), some with GPS EXIF tags." }+ { "path": "~/Desktop/trip", "describe": "Folder of 12 JPEG photos (3024x4032, ~4MB each), some with GPS EXIF tags." },+ { "path": "~/Desktop/trip/IMG_2001.jpg", "describe": "JPEG, 3024x4032, GPS EXIF." },+ { "path": "~/Desktop/trip/IMG_2002.jpg", "describe": "JPEG, 3024x4032, GPS EXIF." },+ { "path": "~/Desktop/trip/IMG_2003.jpg", "describe": "JPEG, 3024x4032." },+ { "path": "~/Desktop/trip/IMG_2004.jpg", "describe": "JPEG, 3024x4032, GPS EXIF." },+ { "path": "~/Desktop/trip/IMG_2005.jpg", "describe": "JPEG, 3024x4032." },+ { "path": "~/Desktop/trip/IMG_2006.jpg", "describe": "JPEG, 3024x4032, GPS EXIF." },+ { "path": "~/Desktop/trip/IMG_2007.jpg", "describe": "JPEG, 3024x4032." },+ { "path": "~/Desktop/trip/IMG_2008.jpg", "describe": "JPEG, 3024x4032, GPS EXIF." },+ { "path": "~/Desktop/trip/IMG_2009.jpg", "describe": "JPEG, 3024x4032." },+ { "path": "~/Desktop/trip/IMG_2010.jpg", "describe": "JPEG, 3024x4032, GPS EXIF." },+ { "path": "~/Desktop/trip/IMG_2011.jpg", "describe": "JPEG, 3024x4032." },+ { "path": "~/Desktop/trip/IMG_2012.jpg", "describe": "JPEG, 3024x4032, GPS EXIF." }],"responses": [{ "tool": "files.describe", "summary": "~/Desktop/trip — 12 JPEG photos, 3024x4032, several carry GPS EXIF tags." },diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/watermark-all-pdfs-in-folder/prompt.txt b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/watermark-all-pdfs-in-folder/prompt.txtdeleted file mode 100644index d168a335..00000000--- a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/watermark-all-pdfs-in-folder/prompt.txt+++ /dev/null@@ -1 +0,0 @@-stamp a DRAFT watermark on every PDF in ~/Desktop/contracts\ No newline at end of filediff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/watermark-all-pdfs-in-folder/scenario.json b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/watermark-all-pdfs-in-folder/scenario.jsondeleted file mode 100644index e386166e..00000000--- a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/watermark-all-pdfs-in-folder/scenario.json+++ /dev/null@@ -1,15 +0,0 @@-{- "frontmostApp": "Finder",- "maxSteps": 18,- "disk": [- { "path": "/Users/davidle/Desktop/contracts", "describe": "Folder of 6 contract PDFs." }- ],- "responses": [- { "tool": "shell_exec", "summary": "Stamped DRAFT on 6 PDFs (written alongside originals as *-draft.pdf).", "produces": ["contracts-draft"] }- ],- "expect": {- "turnKind": "act",- "skills": ["pdf"],- "shellAny": [["qpdf"], ["pdftk"], ["stamp"], ["overlay"], ["lit"]]- }-}diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/FixturePromptEvalTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/FixturePromptEvalTests.swiftindex d43588ed..80350c74 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/FixturePromptEvalTests.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/FixturePromptEvalTests.swift@@ -16,7 +16,12 @@ import Testing////// Add a scenario by dropping a new folder under `Fixtures/HarnessEval/` — it is discovered automatically;/// no Swift change needed.-@Suite+///+/// `.serialized`: every scenario is a real multi-step model run against ONE backend. Run in parallel they+/// saturate it — calls fast-fail to nil understanding, steps crawl, and runs trip the stall guard before+/// they finish — so the result reads as failures that are really contention. Serialized, each scenario gets+/// the backend to itself and the signal is the plan, not the load.+@Suite(.serialized)@MainActorstruct FixturePromptEvalTests {@Test(arguments: HarnessEvalFixture.all())diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/GreetingRoundTripEvalTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/GreetingRoundTripEvalTests.swiftindex 81d456f4..e6b3a14a 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/GreetingRoundTripEvalTests.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/GreetingRoundTripEvalTests.swift@@ -18,7 +18,9 @@ import Testing/// Opt-in like the other prompt evals (see `HarnessEvalRunner.configFromEnvironment`); a plain `swift test`/// returns early. Per-call latency is printed (not asserted — it is network-dependent) so a "slow today"/// report can be read as "too many round trips" vs "each call is slow".-@Suite+/// `.serialized` for the same reason as the fixture suite: this drives the real understanding backend, so it+/// must not contend with the parameterized scenarios for it.+@Suite(.serialized)@MainActorstruct GreetingRoundTripEvalTests {@Testdiff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessEvalFixture.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessEvalFixture.swiftindex dad4b908..896db8e9 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessEvalFixture.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessEvalFixture.swift@@ -61,10 +61,17 @@ struct HarnessEvalResponseRule: Decodable, Sendable {}func stub(in dir: URL) -> HarnessEvalStub {- let body = summaryFile- .flatMap { try? String(contentsOf: dir.appendingPathComponent($0), encoding: .utf8) }- ?? summary- ?? "ran."+ let body: String+ if let summaryFile,+ let contents = try? String(contentsOf: dir.appendingPathComponent(summaryFile), encoding: .utf8) {+ body = contents+ } else {+ // A summary often stands in for a command's OUTPUT (e.g. an `osascript` POSIX path, an `mdfind`+ // result). Those are absolute in reality, so expand the home-relative `~/` the fixture stores+ // (kept tilde so no real username is committed) to the live home — a tilde where a tool would+ // print a full path reads as wrong and makes the planner re-query instead of proceeding.+ body = (summary ?? "ran.").replacingOccurrences(of: "~/", with: NSHomeDirectory() + "/")+ }if status == "failed" { return .failed(body) }var resolved = facts ?? [:]for file in produces ?? [] { resolved[file] = "exists" }@@ -153,37 +160,102 @@ struct HarnessEvalFixture: Sendable, CustomStringConvertible {)}- /// Build the runnable scenario. The stub serves, in order: a matching scripted response, the disk for- /// `files.describe`, real file content for a read command, and the disk paths for a discovery command —- /// then falls back to the runner's generic default.+ /// Build the runnable scenario. The stub serves in priority order: a TARGETED response rule (one that+ /// names command substrings — it models a specific command's result), then the filesystem simulation+ /// (`files.describe`, a file read, a discovery listing), then a CATCH-ALL response rule (one with no+ /// `contains` — it models the scenario's work command), then the runner's generic default.+ ///+ /// The filesystem sim deliberately sits BEFORE the catch-all: a catch-all rule answers "the work is+ /// done" for any command, so if it ran ahead of discovery a mere `find`/`ls` would be told the job+ /// already finished, and the planner would loop trying to verify output that was never produced (the+ /// loop several of these scenarios used to hit). Targeted rules still win first, so a scripted+ /// `pdfinfo`/failed-download response keeps its authority.func scenario() -> HarnessEvalScenario {let dir = self.dirlet disk = spec.disk ?? []let responses = spec.responses ?? []+ let targetedRules = responses.filter { $0.contains?.isEmpty == false }+ let catchAllRules = responses.filter { $0.contains?.isEmpty ?? true }return HarnessEvalScenario(name: name,prompt: prompt,frontmostApp: spec.frontmostApp ?? "Finder",maxSteps: spec.maxSteps ?? 16) { call in- if let rule = responses.first(where: { $0.matches(call) }) {+ if let rule = targetedRules.first(where: { $0.matches(call) }) {return rule.stub(in: dir)}if call.name == "files.describe", !disk.isEmpty {- return .ok(disk.map { "\($0.path) — \($0.describe ?? "file")" }.joined(separator: "; "))+ return .ok(+ disk.map { "\($0.path) — \($0.describe ?? "file")" }.joined(separator: "; "),+ facts: Self.existenceFacts(for: disk)+ )}- guard call.name == "shell_exec", let command = call.input["command"] else { return nil }- let lower = command.lowercased()- if lower.range(of: "(^| )(cat|head|tail|less|open|lit|pdftotext)( |$)", options: .regularExpression) != nil {- for entry in disk where command.contains(entry.path) || command.contains((entry.path as NSString).lastPathComponent) {- if let content = entry.resolvedContent(in: dir) { return .ok(content) }+ if call.name == "shell_exec", let command = call.input["command"] {+ let lower = command.lowercased()+ if lower.range(of: "(^| )(cat|head|tail|less|open|lit|pdftotext)( |$)", options: .regularExpression) != nil {+ for entry in disk where command.contains(entry.path) || command.contains((entry.path as NSString).lastPathComponent) {+ if let content = entry.resolvedContent(in: dir) { return .ok(content) }+ }+ }+ if !disk.isEmpty,+ lower.range(of: "(^| )(find|mdfind|ls|stat)( |$)", options: .regularExpression) != nil {+ let listing = Self.discoveryListing(command: command, disk: disk)+ return .ok(listing.text, facts: listing.facts)}}- if !disk.isEmpty,- lower.range(of: "(^| )(find|mdfind|ls|stat)( |$)", options: .regularExpression) != nil {- return .ok(disk.map(\.path).joined(separator: "\n"))+ if let rule = catchAllRules.first(where: { $0.matches(call) }) {+ return rule.stub(in: dir)}return nil}}++ /// What a discovery command (`find`/`mdfind`/`ls`/`stat`) returns for this disk, plus the existence+ /// facts to record. An `ls`/`stat` naming a declared directory lists that directory's CONTENTS — the+ /// entries declared beneath it — so the planner sees the files it must operate on instead of the folder+ /// path echoed back at it. Anything else returns every declared path. Either way each returned path is+ /// marked `exists`: without that fact a successful discovery changes nothing in the world model, so the+ /// runtime scores it as no progress and the planner re-searches the same paths until the duplicate/stall+ /// guard fails the run — the loop these evals kept hitting. The fact carries the located file forward so+ /// the planner moves on to the real work tool.+ private static func discoveryListing(+ command: String,+ disk: [HarnessEvalDiskEntry]+ ) -> (text: String, facts: [String: String]) {+ // Match whether the command names the declared path as written (`~/Desktop/x`) or already expanded+ // (`/Users/<home>/Desktop/x`) — discovery output from an earlier step comes back expanded.+ for entry in disk where command.contains(entry.path) || command.contains(displayPath(entry.path)) {+ let children = disk.filter { $0.path != entry.path && $0.path.hasPrefix(entry.path + "/") }+ if !children.isEmpty {+ return (listingText(for: children), existenceFacts(for: children))+ }+ }+ return (listingText(for: disk), existenceFacts(for: disk))+ }++ /// The text a discovery command prints: one ABSOLUTE path per line. A real `find`/`mdfind` prints full+ /// paths, so echoing back the bare declared name (often identical to the query) reads to the planner as+ /// "not actually located" and it keeps trying search variants. `displayPath` gives the planner the+ /// concrete path it needs to move on to the real work.+ private static func listingText(for entries: [HarnessEvalDiskEntry]) -> String {+ entries.map { displayPath($0.path) }.joined(separator: "\n")+ }++ /// The absolute path a discovery command prints for a declared entry. Fixture paths are stored+ /// home-relative (`~/…`, or a bare name) so no real username is committed; this expands `~`/roots a+ /// bare name at the live home directory ONLY at runtime, so the output is a real absolute path with no+ /// hard-coded user in the fixture files.+ private static func displayPath(_ path: String) -> String {+ if path.hasPrefix("/") { return path }+ if path == "~" { return NSHomeDirectory() }+ if path.hasPrefix("~/") { return NSHomeDirectory() + String(path.dropFirst(1)) }+ return NSHomeDirectory() + "/" + path+ }++ /// `path -> "exists"` for each entry, the shape the runner's world model and default file-probe reply+ /// already use to mean "this file is present."+ private static func existenceFacts(for disk: [HarnessEvalDiskEntry]) -> [String: String] {+ Dictionary(disk.map { ($0.path, "exists") }, uniquingKeysWith: { current, _ in current })+ }}