Skip to content

Commit a4d617c

Browse files
fix(mobile): drain tests mock thread details; settings picker ignores streamed text
The acknowledged-message prune reads environmentThreadDetails, which the outbox drain test mocks of ./threads did not provide. The thread settings picker reads the quiet thread structure, so streamed deltas no longer re-render it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 322d43a commit a4d617c

5 files changed

Lines changed: 33 additions & 9 deletions

File tree

‎apps/mobile/src/features/threads/ThreadSettingsSheet.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ import {
8686
useComposerDraft,
8787
useComposerDraftSettings,
8888
} from "../../state/use-composer-drafts";
89-
import { useSelectedThreadProjection } from "../../state/use-thread-detail";
89+
import { useQuietThreadStructure } from "../../state/use-thread-detail";
9090
import { updateThreadDraftModelSelection } from "../../state/use-thread-composer-state";
9191
import { useThreadSelection } from "../../state/use-thread-selection";
9292
import { threadAllowsProviderSwitch } from "../../state/thread-provider-switching";
@@ -1496,7 +1496,8 @@ export function ExistingThreadSettingsRouteScreen({
14961496
// Reads the same environmentId/threadId params as the Thread route beneath it.
14971497
const { selectedThread, selectedThreadDetailRef, selectedEnvironmentRuntime } =
14981498
useThreadSelection();
1499-
const projection = useSelectedThreadProjection();
1499+
// Streamed text would otherwise re-render the whole model picker on every delta.
1500+
const structure = useQuietThreadStructure(selectedThreadDetailRef);
15001501
const reportedModelSelection = useThreadReportedModelSelection(selectedThreadDetailRef);
15011502
const threadKey = scopedThreadKey(route.params.environmentId, route.params.threadId);
15021503
const draftSettings = useComposerDraftSettings(threadKey);
@@ -1510,7 +1511,7 @@ export function ExistingThreadSettingsRouteScreen({
15101511
const modelSelection = draftSettings.modelSelection ?? selectedThread.modelSelection;
15111512
const lockedProviderInstanceId = threadAllowsProviderSwitch({
15121513
thread: selectedThread,
1513-
projection: projection?.projection,
1514+
projection: structure?.projection,
15141515
})
15151516
? undefined
15161517
: modelSelection.instanceId;

‎apps/mobile/src/state/thread-provider-switching.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
22
import { threadSupportsProviderHandoff } from "@t3tools/client-runtime/state/thread-workflows";
3-
import type { OrchestrationV2ThreadProjection } from "@t3tools/contracts";
3+
import type { ThreadStructure } from "@t3tools/client-runtime/state/models";
44

55
type ThreadStartMarkers = Pick<
66
EnvironmentThreadShell,
@@ -16,7 +16,7 @@ function threadShellHasStarted(thread: ThreadStartMarkers | null | undefined): b
1616

1717
export function threadAllowsProviderSwitch(input: {
1818
readonly thread: ThreadStartMarkers | null | undefined;
19-
readonly projection: OrchestrationV2ThreadProjection | null | undefined;
19+
readonly projection: ThreadStructure | null | undefined;
2020
}): boolean {
2121
return input.projection != null
2222
? threadSupportsProviderHandoff(input.projection)

‎apps/mobile/src/state/use-thread-detail.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { useAtomValue } from "@effect/atom-react";
22
import type { PendingThreadRequests } from "@t3tools/client-runtime/state/thread-requests";
3+
import type { EnvironmentThreadStructure } from "@t3tools/client-runtime/state/models";
34
import type { EnvironmentThread } from "@t3tools/client-runtime/state/shell";
4-
import type { EnvironmentId, OrchestrationV2ThreadProjection, ThreadId } from "@t3tools/contracts";
5+
import type {
6+
EnvironmentId,
7+
OrchestrationV2ThreadProjection,
8+
ScopedThreadRef,
9+
ThreadId,
10+
} from "@t3tools/contracts";
511
import { Atom } from "effect/reactivity";
612

713
import { environmentThreadDetails, useEnvironmentThread } from "./threads";
@@ -10,6 +16,9 @@ import { useThreadSelection } from "./use-thread-selection";
1016
const EMPTY_THREAD_PROJECTION_ATOM = Atom.make<EnvironmentThread | null>(null).pipe(
1117
Atom.withLabel("mobile-thread-projection:empty"),
1218
);
19+
const EMPTY_THREAD_STRUCTURE_ATOM = Atom.make<EnvironmentThreadStructure | null>(null).pipe(
20+
Atom.withLabel("mobile-thread-structure:empty"),
21+
);
1322
const EMPTY_VISIBLE_TURN_ITEMS_ATOM = Atom.make<
1423
OrchestrationV2ThreadProjection["visibleTurnItems"]
1524
>(Object.freeze([])).pipe(Atom.withLabel("mobile-thread-visible-turn-items:empty"));
@@ -42,6 +51,15 @@ export function useThreadProjection(target: ThreadDetailTarget): EnvironmentThre
4251
);
4352
}
4453

54+
/** Keeps its value through streamed text; runs, sessions, and item status still update. */
55+
export function useQuietThreadStructure(
56+
ref: ScopedThreadRef | null,
57+
): EnvironmentThreadStructure | null {
58+
return useAtomValue(
59+
ref === null ? EMPTY_THREAD_STRUCTURE_ATOM : environmentThreadDetails.quietThreadAtom(ref),
60+
);
61+
}
62+
4563
export function useSelectedThreadProjection(): EnvironmentThread | null {
4664
const { selectedThreadDetailRef } = useThreadSelection();
4765
return useThreadProjection({

‎apps/mobile/src/state/use-thread-outbox-drain.permissions.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ vi.mock("./threads", async () => {
7878
setInteractionMode: state.interaction,
7979
},
8080
environmentThreadShells: { threadShellsAtom: Atom.make([state.thread]) },
81+
environmentThreadDetails: { threadAtom: Atom.family((_key: unknown) => Atom.make(null)) },
8182
};
8283
});
8384
vi.mock("./use-atom-command", () => ({ useAtomCommand: <A>(command: A) => command }));

‎apps/mobile/src/state/use-thread-outbox-drain.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,13 @@ vi.mock("./server", async () => {
8989

9090
vi.mock("./git", () => ({ gitEnvironment: {} }));
9191

92-
vi.mock("./threads", () => ({
93-
threadEnvironment: {},
94-
}));
92+
vi.mock("./threads", async () => {
93+
const { Atom } = await import("effect/reactivity");
94+
return {
95+
threadEnvironment: {},
96+
environmentThreadDetails: { threadAtom: Atom.family((_key: unknown) => Atom.make(null)) },
97+
};
98+
});
9599

96100
vi.mock("./use-atom-command", () => ({
97101
useAtomCommand: () => async () => undefined,

0 commit comments

Comments
 (0)