+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
297 lines
8.6 KiB
TypeScript
297 lines
8.6 KiB
TypeScript
import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
|
|
import { describe, expect, it } from "vite-plus/test";
|
|
import { deriveProviderInstanceEntries } from "../../providerInstances";
|
|
import {
|
|
formatContextWindowCompactionMessage,
|
|
hasAvailableCompactionProvider,
|
|
hasDismissedResumeCompaction,
|
|
formatContextWindowCost,
|
|
resolveContextWindowModelDisplayName,
|
|
shouldOfferResumeCompaction,
|
|
shouldReserveContextWindowMeter,
|
|
} from "./ContextWindowMeter.logic";
|
|
|
|
function claudeProvider(input: {
|
|
instanceId: string;
|
|
continuationGroupKey: string;
|
|
enabled?: boolean;
|
|
}): ServerProvider {
|
|
return {
|
|
instanceId: ProviderInstanceId.make(input.instanceId),
|
|
driver: ProviderDriverKind.make("claudeAgent"),
|
|
continuation: { groupKey: input.continuationGroupKey },
|
|
enabled: input.enabled ?? true,
|
|
installed: true,
|
|
version: null,
|
|
status: "ready",
|
|
auth: { status: "authenticated" },
|
|
checkedAt: "2026-08-24T12:00:00.000Z",
|
|
models: [],
|
|
slashCommands: [{ name: "compact", description: "" }],
|
|
skills: [],
|
|
};
|
|
}
|
|
|
|
describe("hasAvailableCompactionProvider", () => {
|
|
const originalInstanceId = ProviderInstanceId.make("claude_original");
|
|
|
|
it("rejects a fallback in a different locked continuation group", () => {
|
|
const providers = deriveProviderInstanceEntries([
|
|
claudeProvider({
|
|
instanceId: originalInstanceId,
|
|
continuationGroupKey: "claude:home:/original",
|
|
enabled: false,
|
|
}),
|
|
claudeProvider({
|
|
instanceId: "claude_other",
|
|
continuationGroupKey: "claude:home:/other",
|
|
}),
|
|
]);
|
|
|
|
expect(
|
|
hasAvailableCompactionProvider({
|
|
providers,
|
|
driverKind: ProviderDriverKind.make("claudeAgent"),
|
|
instanceId: originalInstanceId,
|
|
lockedInstanceId: originalInstanceId,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("accepts an enabled fallback in the locked continuation group", () => {
|
|
const providers = deriveProviderInstanceEntries([
|
|
claudeProvider({
|
|
instanceId: originalInstanceId,
|
|
continuationGroupKey: "claude:home:/original",
|
|
enabled: false,
|
|
}),
|
|
claudeProvider({
|
|
instanceId: "claude_fallback",
|
|
continuationGroupKey: "claude:home:/original",
|
|
}),
|
|
]);
|
|
|
|
expect(
|
|
hasAvailableCompactionProvider({
|
|
providers,
|
|
driverKind: ProviderDriverKind.make("claudeAgent"),
|
|
instanceId: originalInstanceId,
|
|
lockedInstanceId: originalInstanceId,
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("resolveContextWindowModelDisplayName", () => {
|
|
it("uses the selected model from the exact provider instance", () => {
|
|
const primaryInstanceId = ProviderInstanceId.make("codex");
|
|
const selectedInstanceId = ProviderInstanceId.make("codex-work");
|
|
const modelOptionsByInstance = new Map([
|
|
[
|
|
primaryInstanceId,
|
|
[{ slug: "gpt-5.6-sol", name: "Primary profile model", shortName: "Primary" }],
|
|
],
|
|
[selectedInstanceId, [{ slug: "gpt-5.6-sol", name: "GPT-5.6 Sol", shortName: "5.6 Sol" }]],
|
|
]);
|
|
|
|
expect(
|
|
resolveContextWindowModelDisplayName(
|
|
{
|
|
instanceId: selectedInstanceId,
|
|
model: "gpt-5.6-sol",
|
|
},
|
|
modelOptionsByInstance,
|
|
),
|
|
).toBe("5.6 Sol");
|
|
});
|
|
|
|
it("falls back to the selected model slug when model metadata is unavailable", () => {
|
|
const selectedInstanceId = ProviderInstanceId.make("codex-work");
|
|
|
|
expect(
|
|
resolveContextWindowModelDisplayName(
|
|
{
|
|
instanceId: selectedInstanceId,
|
|
model: "custom-model",
|
|
},
|
|
new Map(),
|
|
),
|
|
).toBe("custom-model");
|
|
});
|
|
});
|
|
|
|
describe("formatContextWindowCompactionMessage", () => {
|
|
it("describes compaction in terms of the selected model", () => {
|
|
expect(formatContextWindowCompactionMessage("GPT-5.6 Sol")).toBe(
|
|
"Context for GPT-5.6 Sol compacts automatically when needed.",
|
|
);
|
|
});
|
|
|
|
it("uses neutral copy when the model is unavailable", () => {
|
|
expect(formatContextWindowCompactionMessage(null)).toBe(
|
|
"Context compacts automatically when needed.",
|
|
);
|
|
});
|
|
|
|
it("shows the configured auto-compaction threshold", () => {
|
|
expect(formatContextWindowCompactionMessage("Claude Sonnet 5", 300_000)).toBe(
|
|
"Compacts automatically at 300,000 tokens.",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("shouldOfferResumeCompaction", () => {
|
|
const now = "2026-08-24T12:00:00.000Z";
|
|
|
|
it("matches Claude's old-session age and context thresholds", () => {
|
|
expect(
|
|
shouldOfferResumeCompaction({
|
|
provider: "claudeAgent",
|
|
usedTokens: 100_000,
|
|
updatedAt: "2026-08-24T10:50:00.000Z",
|
|
now,
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("does not prompt for recent or smaller sessions", () => {
|
|
expect(
|
|
shouldOfferResumeCompaction({
|
|
provider: "claudeAgent",
|
|
usedTokens: 99_999,
|
|
updatedAt: "2026-08-24T10:00:00.000Z",
|
|
now,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldOfferResumeCompaction({
|
|
provider: "claudeAgent",
|
|
usedTokens: 200_000,
|
|
updatedAt: "2026-08-24T10:51:00.000Z",
|
|
now,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("does not show Claude's resume prompt for another provider", () => {
|
|
expect(
|
|
shouldOfferResumeCompaction({
|
|
provider: "codex",
|
|
usedTokens: 300_000,
|
|
updatedAt: "2026-08-24T09:00:00.000Z",
|
|
now,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("hasDismissedResumeCompaction", () => {
|
|
it("recognizes the native resume dialog's permanent dismissal", () => {
|
|
expect(
|
|
hasDismissedResumeCompaction([
|
|
{
|
|
kind: "user-input.resolved",
|
|
payload: {
|
|
answers: {
|
|
"This session is 2h 0m old and uses 250,000 tokens. Compact it before continuing?":
|
|
"Don't ask again",
|
|
},
|
|
},
|
|
},
|
|
]),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("ignores the same answer on an unrelated question", () => {
|
|
expect(
|
|
hasDismissedResumeCompaction([
|
|
{
|
|
kind: "user-input.resolved",
|
|
payload: { answers: { "Show this setup reminder?": "Don't ask again" } },
|
|
},
|
|
]),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("ignores unrelated questions that end with Claude's compaction prompt", () => {
|
|
expect(
|
|
hasDismissedResumeCompaction([
|
|
{
|
|
kind: "user-input.resolved",
|
|
payload: {
|
|
answers: {
|
|
"The build cache is large. Compact it before continuing?": "Don't ask again",
|
|
},
|
|
},
|
|
},
|
|
]),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("ignores pending questions and malformed resolved payloads", () => {
|
|
expect(
|
|
hasDismissedResumeCompaction([
|
|
{ kind: "user-input.requested", payload: { answers: { question: "Don't ask again" } } },
|
|
{ kind: "user-input.resolved", payload: null },
|
|
{ kind: "user-input.resolved", payload: { answers: ["Don't ask again"] } },
|
|
]),
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("shouldReserveContextWindowMeter", () => {
|
|
const loadingStartedThread = {
|
|
meterEnabled: true,
|
|
detailLoading: true,
|
|
threadStarted: true,
|
|
providerReportsContextWindow: true,
|
|
};
|
|
|
|
it("holds the meter's slot while a started thread's detail loads", () => {
|
|
expect(shouldReserveContextWindowMeter(loadingStartedThread)).toBe(true);
|
|
});
|
|
|
|
it("reserves nothing once the detail is in", () => {
|
|
expect(shouldReserveContextWindowMeter({ ...loadingStartedThread, detailLoading: false })).toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
it("reserves nothing for a thread that never ran a turn", () => {
|
|
expect(shouldReserveContextWindowMeter({ ...loadingStartedThread, threadStarted: false })).toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
it("reserves while the thread's provider is not in the catalog yet", () => {
|
|
expect(
|
|
shouldReserveContextWindowMeter({
|
|
...loadingStartedThread,
|
|
providerReportsContextWindow: null,
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("reserves nothing for a provider that does not stream usage", () => {
|
|
expect(
|
|
shouldReserveContextWindowMeter({
|
|
...loadingStartedThread,
|
|
providerReportsContextWindow: false,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("reserves nothing while the meter is switched off", () => {
|
|
expect(shouldReserveContextWindowMeter({ ...loadingStartedThread, meterEnabled: false })).toBe(
|
|
false,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("formatContextWindowCost", () => {
|
|
it("keeps ordinary and sub-cent ACP costs readable", () => {
|
|
expect(formatContextWindowCost({ amount: 0.42, currency: "USD" })).toBe("USD 0.42");
|
|
expect(formatContextWindowCost({ amount: 0.0042, currency: "USD" })).toBe("USD 0.0042");
|
|
});
|
|
});
|