Skip to content

Commit 68d614d

Browse files
praffiiiclaude
andcommitted
test(mobile): compaction notice case crosses the time boundary
The case that sends after the thread became due now does so through the eligibility time, with the model unchanged, so it fails for the reason the notice gate exists: the notice's minute clock trailing the exact deadline. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 72fb96d commit 68d614d

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

‎apps/mobile/src/state/thread-task-permissions.test.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const state = vi.hoisted(() => ({
3939
enqueue: vi.fn(async () => undefined),
4040
freshPending: false,
4141
compactModel: null as string | null,
42+
compactDueAt: "",
4243
setFreshPending: vi.fn(),
4344
clearDraft: vi.fn(),
4445
approve: vi.fn(),
@@ -79,8 +80,10 @@ vi.mock("react", () => ({
7980
vi.mock("expo-crypto", () => ({ randomUUID: () => "uuid" }));
8081
vi.mock("@t3tools/client-runtime/state/context-window", async (importOriginal) => ({
8182
...(await importOriginal<typeof import("@t3tools/client-runtime/state/context-window")>()),
82-
compactBeforeSendTokens: (input: { readonly selection: ModelSelection }) =>
83-
input.selection.model === state.compactModel ? 248_000 : null,
83+
compactBeforeSendTokens: (input: { readonly selection: ModelSelection; readonly now: string }) =>
84+
input.selection.model === state.compactModel && input.now >= state.compactDueAt
85+
? 248_000
86+
: null,
8487
}));
8588
vi.mock("../lib/clock", () => ({ useNowMinuteMs: () => 0 }));
8689
vi.mock("../lib/attachmentUpload", () => ({ prepareTurnAttachments: vi.fn() }));
@@ -206,6 +209,7 @@ beforeEach(() => {
206209
};
207210
state.freshPending = false;
208211
state.compactModel = null;
212+
state.compactDueAt = "";
209213
state.thread.latestRun = null;
210214
state.projection = null;
211215
state.serverConfig = {
@@ -316,29 +320,32 @@ describe("mobile task permissions", () => {
316320
visibleTurnItems: [],
317321
updatedAt: DateTime.makeUnsafe(0),
318322
} as unknown as OrchestrationV2ThreadProjection;
319-
const due: ModelSelection = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.5" };
320-
state.compactModel = due.model;
323+
state.compactModel = "gpt-5.4";
324+
// The notice's minute clock (the epoch here) trails a deadline the send's exact time has passed.
325+
state.compactDueAt = "2026-01-01T00:00:00.000Z";
321326
const unannounced = useThreadComposerState(NO_SIDE_CHATS);
322327
expect(unannounced.compactBeforeSend).toBeNull();
323-
// Due at send time but not at the last render, as when the minute clock trails the deadline.
324-
state.draft = { ...state.draft, modelSelection: due };
325328
await unannounced.onSendMessage();
326329
expect(state.enqueue).toHaveBeenLastCalledWith(
327330
expect.not.objectContaining({ compactBeforeSend: true }),
328331
);
332+
state.compactDueAt = "";
329333
const composer = useThreadComposerState(NO_SIDE_CHATS);
330334
expect(composer.compactBeforeSend?.tokens).toBe(248_000);
331335
await composer.onSendMessage();
332336
expect(state.enqueue).toHaveBeenLastCalledWith(
333337
expect.objectContaining({ compactBeforeSend: true }),
334338
);
335339
// A model picked after the last render still decides the send.
336-
state.draft = { ...state.draft, modelSelection: undefined };
340+
state.draft = {
341+
...state.draft,
342+
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.5" },
343+
};
337344
await composer.onSendMessage();
338345
expect(state.enqueue).toHaveBeenLastCalledWith(
339346
expect.not.objectContaining({ compactBeforeSend: true }),
340347
);
341-
state.draft = { ...state.draft, modelSelection: due };
348+
state.draft = { ...state.draft, modelSelection: undefined };
342349
composer.compactBeforeSend?.keepFullHistory();
343350
const kept = useThreadComposerState(NO_SIDE_CHATS);
344351
expect(kept.compactBeforeSend).toBeNull();

0 commit comments

Comments
 (0)