The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { assert } from "@effect/vitest"; |
| 2 | import type { ProviderReplayTranscript } from "@t3tools/contracts"; |
| 3 | |
| 4 | import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts"; |
| 5 | import { |
| 6 | assertBaseProjection, |
| 7 | assertSemanticProjectionIntegrity, |
| 8 | assertVisibleTurnItemsMirrorLocalTurnItems, |
| 9 | projectionFor, |
| 10 | } from "../shared.ts"; |
| 11 | import { MUSE_PERMISSION_APPROVED_FILE, MUSE_PERMISSION_DECLINED_FILE } from "./input.ts"; |
| 12 | |
| 13 | /** Decline uses Muse Reject (abort); the command never runs and the turn can settle. */ |
| 14 | export function assertMusePermissionOutput( |
| 15 | result: OrchestratorV2ScenarioResult, |
| 16 | transcript: ProviderReplayTranscript, |
| 17 | ) { |
| 18 | const projection = projectionFor(result, transcript.scenario); |
| 19 | assertSemanticProjectionIntegrity(projection); |
| 20 | assertVisibleTurnItemsMirrorLocalTurnItems(projection); |
| 21 | assert.lengthOf(projection.runs, 2); |
| 22 | assert.equal(projection.runs[0]?.status, "completed"); |
| 23 | assert.include(["completed", "interrupted"], projection.runs[1]?.status); |
| 24 | assertBaseProjection({ |
| 25 | result, |
| 26 | transcript, |
| 27 | runCount: 2, |
| 28 | runStatuses: projection.runs.map((run) => run.status), |
| 29 | }); |
| 30 | |
| 31 | const requests = projection.runtimeRequests.toSorted((left, right) => |
| 32 | left.createdAt < right.createdAt ? -1 : 1, |
| 33 | ); |
| 34 | assert.deepEqual( |
| 35 | requests.map((request) => [request.kind, request.status, request.decision]), |
| 36 | [ |
| 37 | ["command", "resolved", "accept"], |
| 38 | ["command", "resolved", "decline"], |
| 39 | ], |
| 40 | ); |
| 41 | const approval = projection.turnItems.find((item) => item.type === "approval_request"); |
| 42 | const options = approval?.type === "approval_request" ? (approval.options ?? []) : []; |
| 43 | assert.includeDeepMembers( |
| 44 | options.map((option) => option.decision), |
| 45 | ["accept", "decline"], |
| 46 | ); |
| 47 | assert.notInclude( |
| 48 | options.map((option) => option.decision), |
| 49 | "cancel", |
| 50 | ); |
| 51 | |
| 52 | const decisions = transcript.entries.flatMap((entry) => |
| 53 | entry.type === "expect_outbound" && |
| 54 | typeof entry.frame === "object" && |
| 55 | entry.frame !== null && |
| 56 | Reflect.get(entry.frame, "method") === "approval/decide" |
| 57 | ? [Reflect.get(Reflect.get(entry.frame, "params") as object, "choiceId")] |
| 58 | : [], |
| 59 | ); |
| 60 | assert.deepEqual(decisions, ["allow_once", "abort"]); |
| 61 | |
| 62 | const shells = projection.turnItems.filter((item) => item.type === "command_execution"); |
| 63 | assert.isTrue( |
| 64 | shells.some( |
| 65 | (item) => |
| 66 | item.type === "command_execution" && |
| 67 | item.input.includes(MUSE_PERMISSION_APPROVED_FILE) && |
| 68 | item.status === "completed", |
| 69 | ), |
| 70 | ); |
| 71 | assert.isFalse( |
| 72 | shells.some( |
| 73 | (item) => |
| 74 | item.type === "command_execution" && |
| 75 | item.input.includes(MUSE_PERMISSION_DECLINED_FILE) && |
| 76 | item.status === "completed", |
| 77 | ), |
| 78 | ); |
| 79 | } |