Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions apps/mobile/src/state/entities.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { RegistryContext } from "@effect/atom-react";
import { act } from "react";
import { createRoot } from "react-dom/client";
import { expect, it, vi } from "vite-plus/test";
import { Atom, AtomRegistry } from "effect/reactivity";
import { EnvironmentId, ThreadId } from "@t3tools/contracts";

vi.mock("./atom-registry", () => ({ appAtomRegistry: AtomRegistry.make() }));
vi.mock("./projects", () => ({ environmentProjects: {} }));
vi.mock("./server", () => ({
environmentServerConfigsAtom: Atom.make(new Map()),
serverEnvironment: {},
}));
vi.mock("./assets", () => ({ projectFaviconUrlAtom: vi.fn() }));
vi.mock("../native/ProjectChipIconImages", () => ({
projectGlyphImageAtom: vi.fn(),
projectGlyphKey: vi.fn(),
}));
vi.mock("./threads", () => {
const shell = Atom.make<{ title: string } | null>(null);
return {
environmentThreadDetails: {},
environmentThreadShells: { threadShellAtom: () => shell },
threadFamilies: {
mount: (registry: AtomRegistry.AtomRegistry) => {
registry.set(shell, { title: "Child result" });
return () => registry.set(shell, null);
},
},
};
});

import { appAtomRegistry } from "./atom-registry";
import { useLiveThreadLinkLabels } from "./entities";
import { environmentThreadShells } from "./threads";

it("keeps a linked child title mounted until the message stops citing it", async () => {
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
const container = document.createElement("div");
const root = createRoot(container);
let renders = 0;
function Probe({ text }: { text: string }) {
if (++renders > 20) throw new Error("Thread title subscription loop");
return useLiveThreadLinkLabels(text, EnvironmentId.make("local"));
}
try {
await act(async () =>
root.render(
<RegistryContext.Provider value={appAtomRegistry}>
<Probe text="[Child](t3-thread://v2/local/child)" />
</RegistryContext.Provider>,
),
);
expect(container.textContent).toBe("[Child result](t3-thread://v2/local/child)");
expect(renders).toBeLessThan(20);
await act(async () =>
root.render(
<RegistryContext.Provider value={appAtomRegistry}>
<Probe text="No link" />
</RegistryContext.Provider>,
),
);
expect(container.textContent).toBe("No link");
expect(
appAtomRegistry.get(
environmentThreadShells.threadShellAtom({
environmentId: EnvironmentId.make("local"),
threadId: ThreadId.make("child"),
}),
),
).toBeNull();
} finally {
await act(async () => root.unmount());
}
});
10 changes: 4 additions & 6 deletions apps/mobile/src/state/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,17 @@ export function useLiveThreadLinkLabels(markdown: string, environmentId: Environ
);
// Shells leave out idle subagent children and older settled threads, so a cited thread the
// shell lacks is read with its family until it lands; only a settled empty read proves it gone.
const missingKey = JSON.stringify(
refs.filter((ref) => !titles.has(threadKey(ref))).map(threadKey),
);
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- mounts family reads for cited threads the shell omits while this message shows them
const refsKey = JSON.stringify(refs.map(threadKey));
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- keeps cited families mounted until the links change; releasing on title arrival removes that title again
useEffect(() => {
const releases = (JSON.parse(missingKey) as ReadonlyArray<string>).map((key) => {
const releases = (JSON.parse(refsKey) as ReadonlyArray<string>).map((key) => {
const ref = scopeThreadRef(...decodeThreadKey(JSON.parse(key)));
return threadFamilies.mount(appAtomRegistry, ref.environmentId, ref.threadId);
});
return () => {
for (const release of releases) release();
};
}, [missingKey]);
}, [refsKey]);
return relabelThreadLinks(markdown, environmentId, (ref) => titles.get(threadKey(ref)));
}

Expand Down
1 change: 1 addition & 0 deletions apps/mobile/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineConfig, normalizePath } from "vite-plus";
import "vite-plus/test/config";

const reactTests = [
"src/state/entities.test.tsx",
"src/features/external-history/ExternalHistoryRouteScreen.test.tsx",
"src/features/conversation-summaries/ConversationSummariesRouteScreen.test.tsx",
"src/components/ProjectKnowledgeEntry.test.tsx",
Expand Down
Loading