Open source CapCut alternative.
TypeScript
test(app): extend eval runner expectations and add scenarios
David Lee0c48cb3b0ad
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 964f6bf1..1cf072c7 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@@ -7,6 +7,7 @@],"expect": {"turnKind": "act",+ "actionSurface": "appless","skillsAny": ["finder", "system-tools"],"shellAny": [["mdfind"], ["find "]]}diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/excalidraw-delete-red-note/prompt.txt b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/excalidraw-delete-red-note/prompt.txtnew file mode 100644index 00000000..77f205a6--- /dev/null+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/excalidraw-delete-red-note/prompt.txt@@ -0,0 +1 @@+in the Excalidraw board that's open, delete the red sticky note\ No newline at end of filediff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/excalidraw-delete-red-note/scenario.json b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/excalidraw-delete-red-note/scenario.jsonnew file mode 100644index 00000000..ec9e7327--- /dev/null+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/excalidraw-delete-red-note/scenario.json@@ -0,0 +1,31 @@+{+ "frontmostApp": "Excalidraw",+ "maxSteps": 14,+ "responses": [+ {+ "tool": "ax.observe",+ "summary": "Excalidraw is frontmost. Accessibility exposes the top toolbar (Selection, Rectangle, Diamond, Ellipse, Arrow, Text tools) and the hamburger menu — all buttons. The drawing surface itself is a single AXGroup \"canvas\" with NO child elements: the shapes on the board are drawn pixels with no Accessibility roles, so none of them can be selected with ax.click. To act on a shape you must see it with vision.capture."+ },+ {+ "tool": "vision.capture",+ "summary": "Detected elements (scope=window):\n toolbar-selection — button \"Selection tool\"\n toolbar-rectangle — button \"Rectangle tool\"\n note-yellow — yellow sticky note reading \"Ship Friday\", clickable\n note-red — red sticky note reading \"BLOCKED: needs review\", clickable\n note-green — green sticky note reading \"Done\", clickable\n arrow-1 — connector arrow between two notes, clickable"+ },+ {+ "tool": "vision.click",+ "summary": "Clicked note-red. The red sticky note is now selected (resize handles shown).",+ "facts": { "canvas.selection": "note-red" }+ },+ {+ "tool": "keyboard.press",+ "summary": "Pressed Delete. The selected element was removed from the board.",+ "facts": { "canvas.note-red": "deleted" }+ }+ ],+ "expect": {+ "turnKind": "act",+ "used": ["vision.capture", "vision.click"],+ "toolInput": [+ { "tool": "vision.click", "contains": ["note-red"] }+ ]+ }+}diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/fifa-standings-image/prompt.txt b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/fifa-standings-image/prompt.txtnew file mode 100644index 00000000..159bc979--- /dev/null+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/fifa-standings-image/prompt.txt@@ -0,0 +1 @@+show the current fifa standings in a nice imagediff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/fifa-standings-image/scenario.json b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/fifa-standings-image/scenario.jsonnew file mode 100644index 00000000..e741c6f2--- /dev/null+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/fifa-standings-image/scenario.json@@ -0,0 +1,15 @@+{+ "frontmostApp": "Finder",+ "maxSteps": 16,+ "responses": [+ { "tool": "web.search", "summary": "FIFA Men's World Ranking (latest): 1 Argentina, 2 France, 3 Spain, 4 England, 5 Brazil, 6 Netherlands, 7 Portugal, 8 Belgium, 9 Italy, 10 Germany." },+ { "tool": "web.fetch", "summary": "FIFA/Coca-Cola Men's World Ranking. 1 Argentina 1862.71; 2 France 1859.78; 3 Spain 1853.07; 4 England 1819.20; 5 Brazil 1776.03; 6 Netherlands 1754.17." },+ { "tool": "image.generate", "summary": "Generated ~/Downloads/fifa-standings.png (1200x900).", "produces": ["~/Downloads/fifa-standings.png"] },+ { "contains": ["png"], "summary": "Wrote ~/Downloads/fifa-standings.png.", "produces": ["~/Downloads/fifa-standings.png"] }+ ],+ "expect": {+ "turnKind": "act",+ "actionSurface": "appless",+ "notUsed": ["ax.click", "vision.click", "automation.applescript.execute"]+ }+}diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/keynote-bold-titles/scenario.json b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/keynote-bold-titles/scenario.jsonindex b0469395..99310de7 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/keynote-bold-titles/scenario.json+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/keynote-bold-titles/scenario.json@@ -5,6 +5,7 @@{ "tool": "ax.observe", "summary": "Keynote frontmost: 8 slides in the navigator, slide 1 title text selected." }],"expect": {- "turnKind": "act"+ "turnKind": "act",+ "actionSurface": "guiApp"}}diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/korean-clip-overlay/scenario.json b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/korean-clip-overlay/scenario.jsonindex 5d70a532..023732df 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/korean-clip-overlay/scenario.json+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/korean-clip-overlay/scenario.json@@ -2,12 +2,11 @@"frontmostApp": "Safari","maxSteps": 16,"responses": [- { "tool": "shell_exec", "contains": ["yt-dlp"], "summary": "[download] 100% of 12.50MiB\n~/Downloads/clip.mp4", "produces": ["~/Downloads/clip.mp4"] },- { "tool": "shell_exec", "contains": ["ffprobe"], "summary": "duration=60.000000\nformat_name=mov,mp4,m4a,3gp,3g2,mj2" },+ { "tool": "shell_exec", "contains": ["yt-dlp"], "summary": "[download] 100% of 12.50MiB\n~/Downloads/clip.webm", "produces": ["~/Downloads/clip.webm"] },+ { "tool": "shell_exec", "contains": ["ffprobe"], "summary": "duration=60.000000\nformat_name=matroska,webm" },{ "tool": "llm.generate", "summary": "Transcribed and translated to Korean → ~/Downloads/subs.srt", "produces": ["~/Downloads/subs.srt"] },{ "tool": "files.write", "summary": "Wrote ~/Downloads/subs.srt", "produces": ["~/Downloads/subs.srt"] },- { "tool": "shell_exec", "contains": ["ffmpeg", "subtitles"], "summary": "Burned Korean subtitles → ~/Downloads/out.mp4", "produces": ["~/Downloads/out.mp4"] },- { "tool": "shell_exec", "contains": ["ffmpeg"], "summary": "ffmpeg: wrote output." }+ { "tool": "shell_exec", "contains": ["ffmpeg", "subtitles"], "summary": "Burned Korean subtitles → ~/Downloads/out.mp4", "produces": ["~/Downloads/out.mp4"] }],"expect": {"turnKind": "act",diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/summarize-long-pdf/report.txt b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/summarize-long-pdf/report.txtindex b73f37c8..dc7ef8e3 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/summarize-long-pdf/report.txt+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/summarize-long-pdf/report.txt@@ -1,13 +1,65 @@Q3 PLATFORM RELIABILITY REVIEW+Prepared by the Reliability Engineering team — internal distribution only-Executive summary: availability was 99.92%, below the 99.95% target, driven by two-incidents in the payments path. Mean time to recovery improved 18% quarter over quarter.+EXECUTIVE SUMMARY-Section 1 — Incidents. INC-204 (payments timeout, 47 min) and INC-219 (cache stampede,-31 min) accounted for 78 of 83 minutes of downtime. Both traced to missing backpressure.+Overall availability for the quarter was 99.92%, below our 99.95% target. The miss was+driven almost entirely by two incidents in the payments path; outside those windows the+platform held above 99.98%. Mean time to recovery improved 18% quarter over quarter, from+44 minutes in Q2 to 36 minutes in Q3, reflecting better runbooks and faster paging. Error+budget for the quarter was exhausted on the payments service but remained healthy for every+other tier. No data loss occurred in any incident, and no customer-facing data integrity+issues were reported.-Section 2 — Capacity. Peak traffic grew 22%. Database CPU headroom fell to 15% at peak;-read-replica rollout is recommended before Q4 promotions.+SECTION 1 — INCIDENTS-Section 3 — Action items. Add backpressure to the payments queue, ship read replicas,-and add a cache-stampede guard. Owners assigned; target dates in Q4.+We recorded two SEV-1 incidents and eleven SEV-3 incidents this quarter. The two SEV-1s+account for nearly all of the downtime.++INC-204 (payments timeout, 47 minutes). A deploy to the payments gateway shipped a default+connection-pool size that was too small for peak load. Under traffic the pool saturated,+requests queued, and upstream callers timed out. The incident was detected by synthetic+checks two minutes after the regression reached 50% of hosts. Rollback resolved it. Root+cause: missing backpressure between the gateway and the downstream ledger service, so a slow+dependency turned into a full queue rather than shedding load.++INC-219 (cache stampede, 31 minutes). A cache node was cycled during routine maintenance.+On cold start, every front-end replica missed simultaneously and stampeded the primary+database, driving CPU to saturation and slowing all reads. Recovery required manually+warming the cache and shedding traffic. Root cause: no request coalescing on cache miss and+no jitter on the refill path, so a single eviction event became a thundering herd.++Together these two incidents accounted for 78 of the 83 total minutes of downtime. Both+trace to the same underlying gap: the platform lacks backpressure and load-shedding at its+busiest tiers, so a localized slowdown escalates into a site-wide event.++SECTION 2 — CAPACITY++Peak traffic grew 22% quarter over quarter, ahead of the 15% we forecast. Growth was+concentrated in the evening window and skewed toward read-heavy endpoints. Database CPU+headroom at peak fell from 31% in Q2 to 15% in Q3. At the current trajectory we will cross+the 10% headroom line — our action threshold — midway through Q4, before the holiday+promotion traffic lands.++The read-replica rollout that was scoped in Q2 has not yet shipped. It remains the single+highest-leverage capacity investment: modeling suggests it would restore headroom to roughly+35% at projected Q4 peak and would also have blunted INC-219, since replicas absorb the read+stampede that saturated the primary. We recommend shipping it before Q4 promotions rather+than after.++Storage and network headroom are comfortable and not a concern this quarter.++SECTION 3 — ACTION ITEMS++1. Add backpressure and load-shedding to the payments queue. Owner: Payments. Target: early+ Q4. This is the direct fix for INC-204 and the highest-priority item.+2. Ship read replicas for the primary database. Owner: Data Platform. Target: before Q4+ promotions. Addresses both the capacity trend and the INC-219 stampede class.+3. Add request coalescing and refill jitter on the cache path. Owner: Edge. Target: mid Q4.+4. Raise the payments connection-pool default and add a load test that exercises it at 1.5x+ peak. Owner: Payments. Target: early Q4.+5. Review paging thresholds for the read tier; current alerts fired late during INC-219.+ Owner: Reliability. Target: Q4.++All owners are assigned and dates are tracked in the reliability planning board. The team+will review progress at the mid-quarter checkpoint.diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/summarize-long-pdf/scenario.json b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/summarize-long-pdf/scenario.jsonindex 14d03156..1496bf4e 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/summarize-long-pdf/scenario.json+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/Fixtures/HarnessEval/summarize-long-pdf/scenario.json@@ -2,7 +2,7 @@"frontmostApp": "Finder","maxSteps": 16,"disk": [- { "path": "report.pdf", "describe": "PDF, 42 pages, selectable text — a quarterly reliability review.", "contentFile": "report.txt" }+ { "path": "report.pdf", "describe": "PDF, selectable text — a quarterly reliability review with three sections and an action-item list.", "contentFile": "report.txt" }],"responses": [{ "tool": "llm.generate", "summary": "Wrote a one-page brief of report.pdf.", "produces": ["report-brief.md"] },diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/FixturePromptEvalTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/FixturePromptEvalTests.swiftindex 80350c74..d0edaa08 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/FixturePromptEvalTests.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/FixturePromptEvalTests.swift@@ -8,9 +8,10 @@ import Testing/// a `prompt.txt`, a `scenario.json`, and any realistic input data the task operates on (CSVs, form data, a/// captured web page). The runner is the same as the hand-written category suites; only the scenario source/// differs. Real model, stubbed system + UI; opt-in exactly like the others — a plain `swift test` returns-/// early. Run with:+/// early. The only required flag is `DONKEY_PROMPT_EVAL=1`; the backend defaults to `http://localhost:3000`+/// (set `DONKEY_WEB_BASE_URL` only to point elsewhere). Run with:///-/// env DONKEY_PROMPT_EVAL=1 DONKEY_WEB_BASE_URL=http://localhost:3000 DONKEY_DEV_AUTH_BYPASS=1 \+/// env DONKEY_PROMPT_EVAL=1 DONKEY_DEV_AUTH_BYPASS=1 \/// DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer \/// swift test --filter PromptEval///@@ -50,6 +51,12 @@ struct FixturePromptEvalTests {"[\(name)] turnKind expected \(turnKind), got \(String(describing: run.understanding?.turnKind))")}+ if let surface = expect.actionSurface {+ #expect(+ run.understanding?.actionSurface.rawValue == surface,+ "[\(name)] actionSurface expected \(surface), got \(String(describing: run.understanding?.actionSurface))"+ )+ }for id in expect.skills ?? [] {#expect(skills.contains(id), "[\(name)] expected skill \(id); got \(skills)")}@@ -62,6 +69,12 @@ struct FixturePromptEvalTests {if let groups = expect.shellAny, !groups.isEmpty {#expect(groups.contains { shellMatches(run, $0) }, "[\(name)] expected a shell command matching any of \(groups); shells: \(run.shellCommands)")}+ for group in expect.toolInput ?? [] {+ #expect(+ toolInputMatches(run, tool: group.tool, needles: group.contains),+ "[\(name)] expected a \(group.tool) call whose input contains all of \(group.contains); \(group.tool) inputs: \(run.inputs(for: group.tool))"+ )+ }for tool in expect.used ?? [] {#expect(run.used(tool), "[\(name)] expected tool \(tool) used; tools: \(run.toolNames)")}@@ -73,6 +86,16 @@ struct FixturePromptEvalTests {}}+ /// True if some call to `tool` carried an input value containing every substring in `needles`+ /// (case-insensitive) — the grounding check, matched over the call's input the way `shellMatches`+ /// matches a shell command, so a vision/AX action can be asserted to have hit the intended target.+ private func toolInputMatches(_ run: HarnessEvalRun, tool: String, needles: [String]) -> Bool {+ run.inputs(for: tool).contains { input in+ let haystack = input.values.joined(separator: " ")+ return needles.allSatisfy { haystack.range(of: $0, options: .caseInsensitive) != nil }+ }+ }+/// True if some `shell_exec` command contains every substring in `needles` (case-insensitive) — the/// array form of `HarnessEvalRun.anyShellMatches`, for `shellAll` / `shellAny` groups.private func shellMatches(_ run: HarnessEvalRun, _ needles: [String]) -> Bool {diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessEvalConfigTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessEvalConfigTests.swiftnew file mode 100644index 00000000..97aa752d--- /dev/null+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessEvalConfigTests.swift@@ -0,0 +1,33 @@+import Foundation+import Testing++/// Pure config-resolution checks for the prompt-eval runner — no network, so they run in a plain+/// `swift test` (unlike the scenario suites). They lock the two rules that matter: the eval still requires+/// the `DONKEY_PROMPT_EVAL=1` opt-in, and the backend URL no longer has to be passed by hand.+@Suite+struct HarnessEvalConfigTests {+ @Test+ func optInIsStillRequired() {+ // Without the opt-in flag the eval must skip, even if a URL is present — these tests hit the real+ // model and must never run by accident in a plain `swift test`.+ #expect(HarnessEvalRunner.configFromEnvironment([:]) == nil)+ #expect(HarnessEvalRunner.configFromEnvironment(["DONKEY_WEB_BASE_URL": "http://x.test"]) == nil)+ }++ @Test+ func backendURLDefaultsWhenUnset() {+ // The whole point of this change: opting in is enough; the URL defaults to the dev backend instead+ // of forcing the developer to export DONKEY_WEB_BASE_URL.+ let config = HarnessEvalRunner.configFromEnvironment(["DONKEY_PROMPT_EVAL": "1"])+ #expect(config?.baseURL == HarnessEvalRunner.defaultBaseURL)+ }++ @Test+ func explicitEnvURLStillWins() {+ let config = HarnessEvalRunner.configFromEnvironment([+ "DONKEY_PROMPT_EVAL": "1",+ "DONKEY_WEB_BASE_URL": "http://example.test:9999"+ ])+ #expect(config?.baseURL == URL(string: "http://example.test:9999"))+ }+}diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessEvalFixture.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessEvalFixture.swiftindex 896db8e9..e9c62c20 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessEvalFixture.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessEvalFixture.swift@@ -85,6 +85,10 @@ struct HarnessEvalResponseRule: Decodable, Sendable {struct HarnessEvalExpect: Decodable, Sendable {/// "act" | "converse" | "clarify".var turnKind: String?+ /// "guiApp" | "appless" — whether the turn drives an app or is produced app-less. Locks that an+ /// artifact/system task (make an image, change a setting) is typed `appless`, so it is never pinned to+ /// a window or blocked on a missing frontmost app.+ var actionSurface: String?/// Skill IDs that must all be surfaced.var skills: [String]?/// Skill IDs of which at least one must be surfaced.@@ -93,11 +97,22 @@ struct HarnessEvalExpect: Decodable, Sendable {var shellAll: [[String]]?/// At least one inner group must be satisfied by some shell command.var shellAny: [[String]]?+ /// Grounding: some call to `tool` must carry an input value containing all of `contains` — the GUI+ /// analogue of `shellAll`. A vision/AX action's target lives in the call input (the `elementID` a+ /// `vision.click` aims at), not in a shell string, so this asserts the click LANDED on the intended+ /// element (e.g. the red note among several), not merely that the tool ran.+ var toolInput: [HarnessEvalToolInput]?var used: [String]?var notUsed: [String]?var completed: Bool?}+/// One grounding assertion: a tool name and the substrings that some call to it must carry in its input.+struct HarnessEvalToolInput: Decodable, Sendable {+ var tool: String+ var contains: [String]+}+/// The decoded `scenario.json`. Every field is optional with a sensible default so a folder needs nothing/// beyond `prompt.txt` to run.struct HarnessEvalScenarioSpec: Decodable, Sendable {@@ -181,7 +196,7 @@ struct HarnessEvalFixture: Sendable, CustomStringConvertible {prompt: prompt,frontmostApp: spec.frontmostApp ?? "Finder",maxSteps: spec.maxSteps ?? 16- ) { call in+ ) { call, knownFiles inif let rule = targetedRules.first(where: { $0.matches(call) }) {return rule.stub(in: dir)}@@ -200,7 +215,11 @@ struct HarnessEvalFixture: Sendable, CustomStringConvertible {}if !disk.isEmpty,lower.range(of: "(^| )(find|mdfind|ls|stat)( |$)", options: .regularExpression) != nil {- let listing = Self.discoveryListing(command: command, disk: disk)+ // Discover over the LIVE filesystem: the declared disk plus whatever earlier steps+ // produced (tracked as `exists` facts in `knownFiles`). Without the produced files an+ // `ls output.mp3` of a file the run just made comes back empty, and the planner loops+ // probing for an output it can't see — a false stall the real app never hits.+ let listing = Self.discoveryListing(command: command, disk: Self.liveFilesystem(disk: disk, knownFiles: knownFiles))return .ok(listing.text, facts: listing.facts)}}@@ -211,6 +230,18 @@ struct HarnessEvalFixture: Sendable, CustomStringConvertible {}}+ /// The disk a discovery command sees: the declared inputs plus a synthetic entry for every file an+ /// earlier step produced (`knownFiles` are the world model's `exists` facts). A produced path already+ /// covered by a declared entry is not duplicated. This is what lets a verify of a just-created output+ /// resolve, so the plan proceeds to the next real action instead of re-probing for a hidden file.+ private static func liveFilesystem(disk: [HarnessEvalDiskEntry], knownFiles: [String]) -> [HarnessEvalDiskEntry] {+ let declared = Set(disk.map(\.path))+ let produced = knownFiles+ .filter { !declared.contains($0) }+ .map { HarnessEvalDiskEntry(path: $0, describe: nil, contentFile: nil, content: nil) }+ return disk + produced+ }+/// 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 folderdiff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessPromptEvalRunner.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessPromptEvalRunner.swiftindex ca61ae9e..bd755c22 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessPromptEvalRunner.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessPromptEval/HarnessPromptEvalRunner.swift@@ -15,10 +15,11 @@ import Foundation/// gate). What is stubbed: the executors. No command runs, no file is touched, no app is driven — each/// tool hands the planner a scripted observation instead, so the loop keeps moving and we record the plan.///-/// These tests hit the network and cost model tokens, so they are opt-in exactly like the live smoke-/// tests. Run with:+/// These tests hit the network and cost model tokens, so they are opt-in via `DONKEY_PROMPT_EVAL=1` (a+/// plain `swift test` skips them). The backend defaults to `http://localhost:3000`; set+/// `DONKEY_WEB_BASE_URL` only to point elsewhere. Run with:///-/// env DONKEY_PROMPT_EVAL=1 DONKEY_WEB_BASE_URL=http://localhost:3000 DONKEY_DEV_AUTH_BYPASS=1 \+/// env DONKEY_PROMPT_EVAL=1 DONKEY_DEV_AUTH_BYPASS=1 \/// DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer \/// swift test --filter PromptEval///@@ -58,14 +59,17 @@ struct HarnessEvalScenario: Sendable {/// Runaway backstop. Each step is a real model call, so keep it modest; the loop normally ends when/// the planner calls `run.complete`.var maxSteps: Int- var respond: @Sendable (HarnessToolCall) -> HarnessEvalStub?+ /// Scripted reply for a tool call. The second argument is the files the agent already knows exist —+ /// the static disk plus everything earlier steps produced — so a discovery/probe stub can surface an+ /// output a prior step created, not just the fixture's declared inputs.+ var respond: @Sendable (HarnessToolCall, [String]) -> HarnessEvalStub?init(name: String,prompt: String,frontmostApp: String = "Finder",maxSteps: Int = 16,- respond: @escaping @Sendable (HarnessToolCall) -> HarnessEvalStub? = { _ in nil }+ respond: @escaping @Sendable (HarnessToolCall, [String]) -> HarnessEvalStub? = { _, _ in nil }) {self.name = nameself.prompt = prompt@@ -89,6 +93,12 @@ struct HarnessEvalRun {func used(_ tool: String) -> Bool { toolNames.contains(tool) }+ /// The inputs of every call to a given tool — so a GUI/vision scenario can assert WHERE an action+ /// landed (e.g. the `elementID` a `vision.click` targeted), not merely that the tool was used.+ func inputs(for tool: String) -> [[String: String]] {+ calls.filter { $0.name == tool }.map(\.input)+ }+/// True if some `shell_exec` command contains all of the given substrings (case-insensitive) — the/// usual shape of a plan assertion (e.g. a yt-dlp call that also passes `--download-sections`).func anyShellMatches(_ needles: String...) -> Bool {@@ -119,18 +129,24 @@ enum HarnessEvalRunner {var devAuthBypass: Bool}+ /// The dev backend the eval drives when nothing else is configured — the same value the dev build's+ /// Info.plist and `run-donkey-dev.sh` use, so a developer with the local site up can run the eval+ /// without exporting `DONKEY_WEB_BASE_URL`.+ static let defaultBaseURL = URL(string: "http://localhost:3000")!+/// Returns the live config, or nil when the eval is not opted into. A nil result means the caller- /// should return early (skip) — these tests reach the real model and must never run by accident in a- /// plain `swift test`.+ /// should return early (skip): the single opt-in is `DONKEY_PROMPT_EVAL=1`, because these tests reach+ /// the real model and must never run by accident in a plain `swift test`. The backend URL is resolved+ /// the way the app does — env `DONKEY_WEB_BASE_URL`, then the baked Info.plist `DonkeyWebBaseURL` — and+ /// falls back to the dev default, so it no longer has to be passed by hand.static func configFromEnvironment(_ environment: [String: String] = ProcessInfo.processInfo.environment) -> Config? {guard environment["DONKEY_PROMPT_EVAL"] == "1" else { return nil }- guard let raw = environment["DONKEY_WEB_BASE_URL"], !raw.isEmpty, let url = URL(string: raw) else {- return nil- }+ let baseURL = (try? DonkeyBackendInferenceConfiguration.fromEnvironment(environment))?.baseURL+ ?? defaultBaseURLreturn Config(- baseURL: url,+ baseURL: baseURL,clientID: environment["DONKEY_CLIENT_ID"] ?? "prompt-eval",devAuthBypass: environment["DONKEY_DEV_AUTH_BYPASS"] == "1")@@ -167,18 +183,21 @@ enum HarnessEvalRunner {.compactMap { BuiltInLocalAppSkillPacks.skillGuidance(forID: $0) }// Real tool surface; stub executors so the planner sees the true descriptors but nothing executes.- let descriptors = BuiltInHarnessToolCatalog.descriptors+ let descriptors = plannerToolDescriptors()let respond = scenario.respondlet tools = descriptors.map { descriptor inHarnessTool(descriptor: descriptor) { context inlet knownFiles = context.worldModel.facts.compactMap { $0.value == "exists" ? $0.key : nil }.sorted()- let reply = respond(context.call) ?? defaultReply(for: context.call, knownFiles: knownFiles)+ let reply = respond(context.call, knownFiles) ?? defaultReply(for: context.call, knownFiles: knownFiles)return HarnessToolResult(callID: context.call.id,toolName: context.call.name,status: reply.status,summary: reply.summary,- observations: HarnessObservationDelta(visibleText: reply.visibleText, facts: reply.facts),+ observations: HarnessObservationDelta(+ visibleText: reply.visibleText,+ facts: shellStampedFacts(reply, call: context.call)+ ),metadata: ["evalStub": "true"])}@@ -213,6 +232,27 @@ enum HarnessEvalRunner {)}+ /// The tool surface the planner SEES, assembled the way production does in `UserQueryCommandHandler`:+ /// the built-in catalog with the placeholder see/act tools removed, plus the real AX, vision, and+ /// pointer see/act DESCRIPTORS (and the native music tools). Execution is stubbed either way, but the+ /// planner must read the SAME tool NAMES the app gives it — `ax.observe` / `ax.click` / `vision.capture`+ /// / `vision.click` — or a GUI/vision scenario would exercise a screen surface the model never gets and+ /// every grounding assertion would be meaningless. Deduped by name (first wins, so a non-replaced+ /// built-in keeps its place) in case two providers ever advertise the same tool.+ @MainActor+ static func plannerToolDescriptors() -> [HarnessToolDescriptor] {+ // The placeholders the providers below supersede — same set production strips before registering+ // the real see/act tools, so the planner is never offered both a placeholder and its replacement.+ let replaced: Set<String> = ["screen.observe", "elements.get", "element.perform", "text.enter", "keyboard.press"]+ let base = BuiltInHarnessToolCatalog.descriptors.filter { !replaced.contains($0.name) }+ let seeAct = AXComputerUseToolProvider.descriptors+ + VisionComputerUseToolProvider.descriptors+ + PointerComputerUseToolProvider.descriptors+ + MusicPlaybackToolProvider.descriptors+ var seen = Set<String>()+ return (base + seeAct).filter { seen.insert($0.name).inserted }+ }+/// Default stubbed reply when a scenario does not script the call. Skill lookups get the REAL built-in/// `SKILL.md` (so the eval exercises the same guidance the planner reads in production), and everything/// else gets a generic success carrying a fact so the step counts as progress and the loop advances.@@ -257,6 +297,19 @@ enum HarnessEvalRunner {}}+ /// The observation facts a stubbed reply carries, with the same `lastShellExitCode` the REAL shell+ /// executor stamps on every successful `shell_exec` (DonkeyCommandBackends). Production attaches it+ /// unconditionally, which is what makes a read-only shell command (a `lit parse`, a `cat`) count as+ /// progress in the runtime's stall accounting; a stub that returned content with no fact scored as+ /// no-progress and tripped the stall guard mid-task — a false failure the real app never hits. Mirror+ /// production so the eval measures the plan, not a missing fact.+ private static func shellStampedFacts(_ reply: HarnessEvalStub, call: HarnessToolCall) -> [String: String] {+ guard call.name == "shell_exec", reply.status == .succeeded else { return reply.facts }+ var facts = reply.facts+ facts["lastShellExitCode"] = facts["lastShellExitCode"] ?? "0"+ return facts+ }+/// True for a read-only command whose job is to look at the filesystem — so the stub answers with the/// known files rather than a content-free success.private static func isFileProbe(_ command: String) -> Bool {