diff --git a/tests/features/chat/domain/runtime/state.test.ts b/tests/features/chat/domain/runtime/state.test.ts index 7db1205e..4d72eb1b 100644 --- a/tests/features/chat/domain/runtime/state.test.ts +++ b/tests/features/chat/domain/runtime/state.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from "vitest"; +import { setRuntimeIntentValue } from "../../../../../src/features/chat/domain/runtime/intent"; import { clearRequestedApprovalsReviewerRuntimeState, clearRequestedFastModeRuntimeState, @@ -52,6 +53,61 @@ describe("chat runtime state", () => { }); }); + it.each([ + { applied: "never" as const, expectedPolicy: "never" as const, expectedKnown: true }, + { applied: null, expectedPolicy: null, expectedKnown: false }, + ])("applies approval policy $applied with the correct known state", ({ applied, expectedPolicy, expectedKnown }) => { + const state = { + ...initialChatRuntimeState(), + active: { + ...initialChatRuntimeState().active, + approvalPolicy: "on-request" as const, + approvalPolicyKnown: true, + }, + }; + + const next = commitAppliedRuntimeSettingsPatchState(state, { approvalPolicy: applied }); + + expect(next.active.approvalPolicy).toBe(expectedPolicy); + expect(next.active.approvalPolicyKnown).toBe(expectedKnown); + }); + + it("clears only the applied approval policy intent and preserves unrelated state", () => { + const initial = initialChatRuntimeState(); + const state = { + ...initial, + active: { + ...initial.active, + model: "gpt-5.1", + reasoningEffort: "high" as const, + serviceTier: "flex" as const, + serviceTierKnown: true, + approvalsReviewer: "user" as const, + }, + pending: { + ...initial.pending, + model: setRuntimeIntentValue("gpt-5.1"), + reasoningEffort: setRuntimeIntentValue("high" as const), + permissionProfile: setRuntimeIntentValue(":workspace"), + approvalPolicy: setRuntimeIntentValue("never" as const), + approvalsReviewer: setRuntimeIntentValue("auto_review" as const), + fastMode: setRuntimeIntentValue("enabled" as const), + }, + }; + + const next = commitAppliedRuntimeSettingsPatchState(state, { approvalPolicy: "never" }); + + expect(next.active).toMatchObject({ + ...state.active, + approvalPolicy: "never", + approvalPolicyKnown: true, + }); + expect(next.pending).toMatchObject({ + ...state.pending, + approvalPolicy: { kind: "unchanged" }, + }); + }); + it("preserves unknown service tier state when committing unrelated settings", () => { const state = requestModelRuntimeState(initialChatRuntimeState(), "gpt-5.1"); const next = commitAppliedRuntimeSettingsPatchState(state, { model: "gpt-5.1" });