@@ -2743,8 +2743,20 @@ describe("ClaudeAdapterV2 background wake turns", () => { |
2743 | 2743 | yield* start("/unrestricted"); |
2744 | 2744 | assert.equal(harness.getOpenedOptions()?.permissionMode, "bypassPermissions"); |
2745 | 2745 | assert.equal(harness.getOpenedOptions()?.allowDangerouslySkipPermissions, true); |
2746 | | - // Forwarded asks (including ask rules and settings fallback) still need a decision |
2747 | | - // before queued init/status frames arrive. |
| 2746 | + // Fork: while the CLI runs in bypass, forwarded asks (safety checks, ask rules) are |
| 2747 | + // allowed without a person; once the CLI reports a downgrade they ask again. |
| 2748 | + const forwardBash = (phase: string) => |
| 2749 | + Effect.promise(() => |
| 2750 | + harness.getOpenedOptions()!.canUseTool!( |
| 2751 | + "Bash", |
| 2752 | + { command: "git status" }, |
| 2753 | + { |
| 2754 | + signal: new AbortController().signal, |
| 2755 | + toolUseID: `forwarded-${phase}`, |
| 2756 | + requestId: `request-forwarded-${phase}`, |
| 2757 | + }, |
| 2758 | + ), |
| 2759 | + ).pipe(Effect.forkScoped); |
2748 | 2760 | for (const { phase, frame } of [ |
2749 | 2761 | { |
2750 | 2762 | phase: "init", |
@@ -2768,39 +2780,35 @@ describe("ClaudeAdapterV2 background wake turns", () => { |
2768 | 2780 | }), |
2769 | 2781 | }, |
2770 | 2782 | ]) { |
2771 | | - const forwardedDecision = yield* Effect.promise(() => |
2772 | | - harness.getOpenedOptions()!.canUseTool!( |
2773 | | - "Bash", |
2774 | | - { command: "git status" }, |
2775 | | - { |
2776 | | - signal: new AbortController().signal, |
2777 | | - toolUseID: `forwarded-before-${phase}`, |
2778 | | - requestId: `request-forwarded-before-${phase}`, |
2779 | | - }, |
2780 | | - ), |
2781 | | - ).pipe(Effect.forkScoped); |
2782 | | - const forwardedFirst = yield* Effect.raceFirst( |
2783 | | - Queue.take(harness.runtimeRequestReceipts).pipe( |
2784 | | - Effect.map((event) => ({ type: "request", event }) as const), |
2785 | | - ), |
2786 | | - Fiber.join(forwardedDecision).pipe( |
2787 | | - Effect.map((result) => ({ type: "decision", result }) as const), |
2788 | | - ), |
2789 | | - ); |
| 2783 | + const allowed = yield* Fiber.join(yield* forwardBash(`before-${phase}`)); |
2790 | 2784 | assert.equal( |
2791 | | - forwardedFirst.type, |
2792 | | - "request", |
2793 | | - `CLI-forwarded Bash must ask before the queued ${phase} frame reaches the adapter`, |
| 2785 | + allowed?.behavior, |
| 2786 | + "allow", |
| 2787 | + `Full access must not ask while the CLI still runs in bypass (before ${phase})`, |
2794 | 2788 | ); |
2795 | | - if (forwardedFirst.type !== "request") return; |
2796 | | - assert.equal(forwardedFirst.event.runtimeRequest.kind, "command"); |
2797 | | - yield* harness.runtime.respondToRuntimeRequest({ |
2798 | | - requestId: forwardedFirst.event.runtimeRequest.id, |
2799 | | - decision: "decline", |
2800 | | - }); |
2801 | | - assert.equal((yield* Fiber.join(forwardedDecision))?.behavior, "deny"); |
2802 | 2789 | yield* harness.offerAndWait(frame); |
2803 | 2790 | } |
| 2791 | + const downgradedDecision = yield* forwardBash("after-downgrade"); |
| 2792 | + const downgradedFirst = yield* Effect.raceFirst( |
| 2793 | + Queue.take(harness.runtimeRequestReceipts).pipe( |
| 2794 | + Effect.map((event) => ({ type: "request", event }) as const), |
| 2795 | + ), |
| 2796 | + Fiber.join(downgradedDecision).pipe( |
| 2797 | + Effect.map((result) => ({ type: "decision", result }) as const), |
| 2798 | + ), |
| 2799 | + ); |
| 2800 | + assert.equal( |
| 2801 | + downgradedFirst.type, |
| 2802 | + "request", |
| 2803 | + "A Bash ask after the CLI reported a downgrade must reach the user", |
| 2804 | + ); |
| 2805 | + if (downgradedFirst.type !== "request") return; |
| 2806 | + assert.equal(downgradedFirst.event.runtimeRequest.kind, "command"); |
| 2807 | + yield* harness.runtime.respondToRuntimeRequest({ |
| 2808 | + requestId: downgradedFirst.event.runtimeRequest.id, |
| 2809 | + decision: "decline", |
| 2810 | + }); |
| 2811 | + assert.equal((yield* Fiber.join(downgradedDecision))?.behavior, "deny"); |
2804 | 2812 | yield* finish; |
2805 | 2813 | const unrestrictedOptions = harness.getOpenedOptions(); |
2806 | 2814 | yield* start("/unrestricted"); |
@@ -3249,7 +3257,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { |
3249 | 3257 | ); |
3250 | 3258 | const toolName = "mcp__weather__get_weather"; |
3251 | 3259 | const id = "weather-call"; |
3252 | | - const permission = yield* Effect.promise(() => |
| 3260 | + yield* Effect.promise(() => |
3253 | 3261 | harness.getOpenedOptions()!.canUseTool!( |
3254 | 3262 | toolName, |
3255 | 3263 | { city: "Berlin" }, |
@@ -3259,13 +3267,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { |
3259 | 3267 | requestId: "weather-request", |
3260 | 3268 | }, |
3261 | 3269 | ), |
3262 | | - ).pipe(Effect.forkScoped); |
3263 | | - const request = yield* Queue.take(harness.runtimeRequestReceipts); |
3264 | | - yield* harness.runtime.respondToRuntimeRequest({ |
3265 | | - requestId: request.runtimeRequest.id, |
3266 | | - decision: "accept", |
3267 | | - }); |
3268 | | - yield* Fiber.join(permission); |
| 3270 | + ); |
3269 | 3271 | yield* harness.offerAndWait( |
3270 | 3272 | claudeSdkFrame({ |
3271 | 3273 | type: "assistant", |
|