GeezerVison is showing github.com — test(evals): shell grading keeps unknown list status, joins continuat… · pingdotgg/t3code@d64222b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: evals/mcp-tool-use/device-grading.ts +28-5Lines changed: 28 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -150,6 +150,8 @@ const managedUi = | 150 | 150 | /^(?:snapshot|screenshot|record|open|close|tap|click|type|fill|press|swipe|scroll|settings|back|home)$/; | 151 | 151 | const interpreter = /^(?:python\d*(?:\.\d+)?|node|ruby|perl|osascript)$/; | 152 | 152 | const shells = new Set(["bash", "sh", "zsh"]); | | 153 | +/** How agent-device reports a failed command, e.g. `Error (COMMAND_FAILED): …`. */ | | 154 | +const AGENT_DEVICE_ERROR = /\bError \([A-Z_]+\):/; | 153 | 155 |
| 154 | 156 | export type ShellInvocation = { | 155 | 157 | readonly words: ReadonlyArray<string>; | @@ -160,14 +162,18 @@ export type ShellInvocation = { | 160 | 162 | readonly executed: boolean; | 161 | 163 | /** An aggregate success cannot establish success of an action masked by ||. */ | 162 | 164 | readonly unmasked: boolean; | | 165 | + /** A later `;` or `&` command owns the call's exit status. */ | | 166 | + readonly sequenced: boolean; | 163 | 167 | }; | 164 | 168 |
| 165 | 169 | // A deliberately bounded shell grammar, not a shell executor. Keep quotes until expansion so | 166 | 170 | // literal command examples, comments and quoted heredocs never become invocations. | 167 | 171 | const tokens = (source: string) => | 168 | | - source.match( | 169 | | - /`(?:\\.|[^`])*`|[<>]\((?:[^()]|\([^()]*\))*\)|\$\((?:[^()'"\\]|\\.|'[^']*'|"(?:\\.|[^"\\])*"|\([^()]*\))*\)|(?:"(?:\\.|[^"\\])*"|'[^']*'|\\.|\$\{\w+\}|[^\s;&|(){}<>"'\\])+|&&|\|\||[;\n&|(){}]|\d*(?:>>?|<)(?:&\d+)?/g, | 170 | | - ) ?? []; | | 172 | + source | | 173 | + .replace(/'[^']*'|\\\n/g, (part) => (part.startsWith("'") ? part : "")) | | 174 | + .match( | | 175 | + /`(?:\\.|[^`])*`|[<>]\((?:[^()]|\([^()]*\))*\)|\$\((?:[^()'"\\]|\\.|'[^']*'|"(?:\\.|[^"\\])*"|\([^()]*\))*\)|(?:"(?:\\.|[^"\\])*"|'[^']*'|\\.|\$\{\w+\}|[^\s;&|(){}<>"'\\])+|&&|\|\||[;\n&|(){}]|\d*(?:>>?|<)(?:&\d+)?/g, | | 176 | + ) ?? []; | 171 | 177 | const unquote = (word: string, variables: Map<string, string>) => | 172 | 178 | word.replace( | 173 | 179 | /'([^']*)'|"((?:\\.|[^"\\])*)"|\\(.)|([^'"\\]+)/g, | @@ -346,12 +352,14 @@ export function shellInvocations( | 346 | 352 | let certain = true; | 347 | 353 | let currentCertain = true; | 348 | 354 | let currentUnmasked = true; | | 355 | + let currentSequenced = false; | 349 | 356 | const append = (nested: ShellInvocation[]) => | 350 | 357 | actions.push( | 351 | 358 | ...nested.map((action) => ({ | 352 | 359 | ...action, | 353 | 360 | executed: action.executed && currentCertain, | 354 | 361 | unmasked: action.unmasked && currentUnmasked, | | 362 | + sequenced: action.sequenced || currentSequenced, | 355 | 363 | })), | 356 | 364 | ); | 357 | 365 | const truth = (words: string[]): boolean | undefined => { | @@ -456,14 +464,26 @@ export function shellInvocations( | 456 | 464 | if (!active || !words.length || reachable === false) return; | 457 | 465 | const list = listTokens(); | 458 | 466 | currentUnmasked = !list.includes("||") && words[0] !== "!"; | | 467 | + // The call's exit status is the last command's; an action followed by `;` or `&` doesn't own it. | | 468 | + currentSequenced = commandTokens.slice(tokenIndex).some((t) => /^[;\n&]$/.test(t)); | 459 | 469 | const finalAndSuccess = | 460 | 470 | succeeded && | 461 | 471 | gate === "&&" && | 462 | 472 | currentUnmasked && | 463 | 473 | !commandTokens.some((t) => /^(?:if|for|while|until|then|else|fi|do|done)$/.test(t)) && | 464 | 474 | !commandTokens.slice(tokenIndex).some((t) => /^[;\n&]$/.test(t)); | 465 | 475 | currentCertain = certain && (reachable === true || finalAndSuccess); | 466 | | - status = truth(words); | | 476 | + // A list's status is known only when this command certainly ran, or when its own result | | 477 | + // decides the list either way (`x && false`, `x || true`). | | 478 | + const value = truth(words); | | 479 | + status = | | 480 | + reachable === true | | 481 | + ? value | | 482 | + : gate === "&&" && value === false | | 483 | + ? false | | 484 | + : gate === "||" && value === true | | 485 | + ? true | | 486 | + : undefined; | 467 | 487 | for (const word of [...rawWords, ...redirects]) if (!bodies.has(word)) substitutions(word); | 468 | 488 | if (loopList) return; | 469 | 489 | const body = words.map((word) => bodies.get(word)).find((value) => value !== undefined); | @@ -567,6 +587,7 @@ export function shellInvocations( | 567 | 587 | remote, | 568 | 588 | executed: currentCertain, | 569 | 589 | unmasked: currentUnmasked, | | 590 | + sequenced: currentSequenced, | 570 | 591 | raw: | 571 | 592 | uiCommand.test([cli, ...normalized.slice(1)].join(" ")) || | 572 | 593 | (agent && (remote || cli === "mac_agent_device")), | @@ -735,12 +756,14 @@ export function gradeDevice(expect: typeof DeviceExpect.Type | undefined, run: D | 735 | 756 | if (expect.recording !== undefined) { | 736 | 757 | const steps = shell | 737 | 758 | .filter(({ call }) => call.failed === false) | 738 | | - .flatMap(({ actions }) => | | 759 | + .flatMap(({ call, actions }) => | 739 | 760 | actions | 740 | 761 | .filter( | 741 | 762 | (action) => | 742 | 763 | action.executed && | 743 | 764 | action.unmasked && | | 765 | + // Before a later `;` command, only an error-free output shows the action succeeded. | | 766 | + (!action.sequenced || !AGENT_DEVICE_ERROR.test(call.output ?? "")) && | 744 | 767 | !action.remote && | 745 | 768 | (run.launchers ?? []).includes(action.words[0] ?? ""), | 746 | 769 | ) | |
Collapse file Copy file name to clipboardExpand all lines: evals/mcp-tool-use/run.test.ts +42Lines changed: 42 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -547,6 +547,10 @@ it.each([ | 547 | 547 | "! xcrun simctl io PRIVATE screenshot /tmp/proof.png", | 548 | 548 | "if false; then :; elif true; then xcrun simctl openurl PRIVATE acme://settings; fi", | 549 | 549 | "for f in $(xcrun simctl io PRIVATE screenshot /tmp/p.png); do echo $f; done", | | 550 | + // Review feedback on #25850: an uncertain short-circuit, and line continuations. | | 551 | + "test -f /tmp/flag && true || xcrun simctl io PRIVATE screenshot /tmp/a.png", | | 552 | + "ssh build-mac xcrun simctl io PRIVATE \\\n screenshot /tmp/a.png", | | 553 | + 'ssh build-mac "xcrun simctl io PRIVATE \\\n screenshot /tmp/a.png"', | 550 | 554 | ])("rejects simulator UI shell mutations: %s", (command) => { | 551 | 555 | const calls = [{ step: 0, tool: "Bash", input: { command } }]; | 552 | 556 | assert.isTrue(gradeDevice({ noRawUi: true }, { calls }).some((c) => !c.pass)); | @@ -1255,6 +1259,44 @@ it.each([ | 1255 | 1259 | ); | 1256 | 1260 | }); | 1257 | 1261 |
| | 1262 | +it.each([ | | 1263 | + [ | | 1264 | + "a later `;` command hides an agent-device error", | | 1265 | + "record start /tmp/demo/voice.mp4; echo done", | | 1266 | + "Error (COMMAND_FAILED): Remote daemon is unavailable\ndone", | | 1267 | + false, | | 1268 | + ], | | 1269 | + [ | | 1270 | + "a later `;` command with clean output", | | 1271 | + "record start /tmp/demo/voice.mp4; echo done", | | 1272 | + "Recording started\ndone", | | 1273 | + true, | | 1274 | + ], | | 1275 | + [ | | 1276 | + "`&&` makes the start part of the call's success", | | 1277 | + "record start /tmp/demo/voice.mp4 && echo done", | | 1278 | + "Error (COMMAND_FAILED): x", | | 1279 | + true, | | 1280 | + ], | | 1281 | +] as const)( | | 1282 | + "credits a recording start only when the call's status covers it: %s", | | 1283 | + (_, start, output, pass) => { | | 1284 | + const launcher = "/home/user/.t3/userdata/device/bin/agent-device"; | | 1285 | + const calls = [ | | 1286 | + { step: 0, tool: "Bash", failed: false, output, input: { command: `${launcher} ${start}` } }, | | 1287 | + { step: 1, tool: "Bash", failed: false, input: { command: `${launcher} record stop` } }, | | 1288 | + ]; | | 1289 | + const run = { | | 1290 | + calls, | | 1291 | + launchers: [launcher], | | 1292 | + text: "Saved /tmp/demo/voice.mp4", | | 1293 | + stopReason: "end_turn", | | 1294 | + }; | | 1295 | + const checks = gradeSample({ device: { recording: "/tmp/demo/voice.mp4" } }, run); | | 1296 | + assert.equal(checks.find((check) => check.check.startsWith("device recording"))?.pass, pass); | | 1297 | + }, | | 1298 | +); | | 1299 | + | 1258 | 1300 | it("leaves errored samples out of pass rates and lists them in the summary", () => { | 1259 | 1301 | const usage = { input: 10, output: 0, cacheWrite: 0, cacheRead: 0 }; | 1260 | 1302 | const row = (id: string, pass: boolean, error?: string) => ({ | |
|