























@@ -109,13 +109,6 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
109109return value;
110110}
111111112-function requireArray(value: unknown, label: string): unknown[] {
113-if (!Array.isArray(value)) {
114-throw new Error(`expected ${label} to be an array`);
115-}
116-return value;
117-}
118-119112function expectRecordFields(value: unknown, label: string, expected: Record<string, unknown>) {
120113const record = requireRecord(value, label);
121114for (const [key, expectedValue] of Object.entries(expected)) {
@@ -135,6 +128,15 @@ function requireNestedRecord(value: unknown, label: string, path: string[]) {
135128return requireRecord(current, label);
136129}
137130131+function expectInteractiveApprovalButtons(
132+result: Record<string, unknown>,
133+expectedButtons: readonly Record<string, unknown>[],
134+) {
135+expect(requireNestedRecord(result, "interactive payload", ["interactive"])).toEqual({
136+blocks: [{ type: "buttons", buttons: expectedButtons }],
137+});
138+}
139+138140function requireSingleMessagingTarget(ctx: ToolHandlerContext) {
139141const targets = ctx.state.messagingToolSentTargets;
140142expect(targets).toHaveLength(1);
@@ -568,12 +570,23 @@ describe("handleToolExecutionEnd exec approval prompts", () => {
568570allowedDecisions: ["allow-once", "allow-always", "deny"],
569571},
570572);
571-expect(
572-requireArray(
573-requireNestedRecord(result, "interactive payload", ["interactive"]).blocks,
574-"interactive blocks",
575-).length,
576-).toBeGreaterThan(0);
573+expectInteractiveApprovalButtons(result, [
574+{
575+label: "Allow Once",
576+value: "/approve 12345678-1234-1234-1234-123456789012 allow-once",
577+style: "success",
578+},
579+{
580+label: "Allow Always",
581+value: "/approve 12345678-1234-1234-1234-123456789012 allow-always",
582+style: "primary",
583+},
584+{
585+label: "Deny",
586+value: "/approve 12345678-1234-1234-1234-123456789012 deny",
587+style: "danger",
588+},
589+]);
577590expect(ctx.state.deterministicApprovalPromptSent).toBe(true);
578591});
579592@@ -615,12 +628,18 @@ describe("handleToolExecutionEnd exec approval prompts", () => {
615628allowedDecisions: ["allow-once", "deny"],
616629},
617630);
618-expect(
619-requireArray(
620-requireNestedRecord(result, "interactive payload", ["interactive"]).blocks,
621-"interactive blocks",
622-).length,
623-).toBeGreaterThan(0);
631+expectInteractiveApprovalButtons(result, [
632+{
633+label: "Allow Once",
634+value: "/approve 12345678-1234-1234-1234-123456789012 allow-once",
635+style: "success",
636+},
637+{
638+label: "Deny",
639+value: "/approve 12345678-1234-1234-1234-123456789012 deny",
640+style: "danger",
641+},
642+]);
624643});
625644626645it("emits a deterministic unavailable payload when the initiating surface cannot approve", async () => {
@@ -1356,7 +1375,7 @@ describe("control UI credential redaction (issue #72283)", () => {
13561375const commandOutputCalls = onAgentEvent.mock.calls
13571376.map((call) => call[0])
13581377.filter((arg: unknown) => (arg as { stream?: string })?.stream === "command_output");
1359-expect(commandOutputCalls.length).toBeGreaterThan(0);
1378+expect(commandOutputCalls).toHaveLength(1);
13601379const lastOutput = commandOutputCalls.at(-1) as { data?: { output?: string } } | undefined;
13611380const output = requireString(lastOutput?.data?.output, "command output");
13621381expect(output).not.toContain("sk-or-v1-abcdef0123456789");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。