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 { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | import { deriveProviderInstanceEntries } from "../../providerInstances"; |
| 4 | import { hasDismissedResumeCompaction } from "@t3tools/client-runtime/state/context-window"; |
| 5 | import { hasAvailableCompactionProvider } from "./compaction.logic"; |
| 6 | |
| 7 | function claudeProvider(input: { |
| 8 | instanceId: string; |
| 9 | continuationGroupKey: string; |
| 10 | enabled?: boolean; |
| 11 | }): ServerProvider { |
| 12 | return { |
| 13 | instanceId: ProviderInstanceId.make(input.instanceId), |
| 14 | driver: ProviderDriverKind.make("claudeAgent"), |
| 15 | continuation: { groupKey: input.continuationGroupKey }, |
| 16 | enabled: input.enabled ?? true, |
| 17 | installed: true, |
| 18 | version: null, |
| 19 | status: "ready", |
| 20 | auth: { status: "authenticated" }, |
| 21 | checkedAt: "2026-08-24T12:00:00.000Z", |
| 22 | models: [], |
| 23 | slashCommands: [{ name: "compact", description: "" }], |
| 24 | skills: [], |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | describe("hasAvailableCompactionProvider", () => { |
| 29 | const originalInstanceId = ProviderInstanceId.make("claude_original"); |
| 30 | |
| 31 | it("rejects a fallback in a different locked continuation group", () => { |
| 32 | const providers = deriveProviderInstanceEntries([ |
| 33 | claudeProvider({ |
| 34 | instanceId: originalInstanceId, |
| 35 | continuationGroupKey: "claude:home:/original", |
| 36 | enabled: false, |
| 37 | }), |
| 38 | claudeProvider({ |
| 39 | instanceId: "claude_other", |
| 40 | continuationGroupKey: "claude:home:/other", |
| 41 | }), |
| 42 | ]); |
| 43 | |
| 44 | expect( |
| 45 | hasAvailableCompactionProvider({ |
| 46 | providers, |
| 47 | driverKind: ProviderDriverKind.make("claudeAgent"), |
| 48 | instanceId: originalInstanceId, |
| 49 | lockedInstanceId: originalInstanceId, |
| 50 | }), |
| 51 | ).toBe(false); |
| 52 | }); |
| 53 | |
| 54 | it("accepts an enabled fallback in the locked continuation group", () => { |
| 55 | const providers = deriveProviderInstanceEntries([ |
| 56 | claudeProvider({ |
| 57 | instanceId: originalInstanceId, |
| 58 | continuationGroupKey: "claude:home:/original", |
| 59 | enabled: false, |
| 60 | }), |
| 61 | claudeProvider({ |
| 62 | instanceId: "claude_fallback", |
| 63 | continuationGroupKey: "claude:home:/original", |
| 64 | }), |
| 65 | ]); |
| 66 | |
| 67 | expect( |
| 68 | hasAvailableCompactionProvider({ |
| 69 | providers, |
| 70 | driverKind: ProviderDriverKind.make("claudeAgent"), |
| 71 | instanceId: originalInstanceId, |
| 72 | lockedInstanceId: originalInstanceId, |
| 73 | }), |
| 74 | ).toBe(true); |
| 75 | }); |
| 76 | }); |
| 77 | |
| 78 | describe("hasDismissedResumeCompaction", () => { |
| 79 | it("recognizes the native resume dialog's permanent dismissal", () => { |
| 80 | expect( |
| 81 | hasDismissedResumeCompaction([ |
| 82 | { |
| 83 | kind: "user-input.resolved", |
| 84 | payload: { |
| 85 | answers: { |
| 86 | "This session is 2h 0m old and uses 250,000 tokens. Compact it before continuing?": |
| 87 | "Don't ask again", |
| 88 | }, |
| 89 | }, |
| 90 | }, |
| 91 | ]), |
| 92 | ).toBe(true); |
| 93 | }); |
| 94 | |
| 95 | it("ignores unrelated questions that end with Claude's compaction prompt", () => { |
| 96 | expect( |
| 97 | hasDismissedResumeCompaction([ |
| 98 | { |
| 99 | kind: "user-input.resolved", |
| 100 | payload: { |
| 101 | answers: { |
| 102 | "The build cache is large. Compact it before continuing?": "Don't ask again", |
| 103 | }, |
| 104 | }, |
| 105 | }, |
| 106 | ]), |
| 107 | ).toBe(false); |
| 108 | }); |
| 109 | }); |