Skip to content

Commit 07516b0

Browse files
fix(web): keep cited child threads available on desktop and web (#86)
* fix(web): keep cited child threads available in chat * fix(chat): fetch cited families only when absent from shell
1 parent ea2f052 commit 07516b0

2 files changed

Lines changed: 69 additions & 7 deletions

File tree

‎apps/mobile/src/state/entities.test.tsx‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { act } from "react";
33
import { createRoot } from "react-dom/client";
44
import { expect, it, vi } from "vite-plus/test";
55
import { Atom, AtomRegistry } from "effect/reactivity";
6-
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
6+
import { EnvironmentId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
77

88
vi.mock("./atom-registry", () => ({ appAtomRegistry: AtomRegistry.make() }));
99
vi.mock("./projects", () => ({ environmentProjects: {} }));
@@ -18,11 +18,15 @@ vi.mock("../native/ProjectChipIconImages", () => ({
1818
}));
1919
vi.mock("./threads", () => {
2020
const shell = Atom.make<{ title: string } | null>(null);
21+
const absent = Atom.make(null);
2122
return {
2223
environmentThreadDetails: {},
23-
environmentThreadShells: { threadShellAtom: () => shell },
24+
environmentThreadShells: {
25+
threadShellAtom: (ref: ScopedThreadRef) => (ref.threadId === childId ? shell : absent),
26+
},
2427
threadFamilies: {
25-
mount: (registry: AtomRegistry.AtomRegistry) => {
28+
mount: (registry: AtomRegistry.AtomRegistry, _env: EnvironmentId, id: ThreadId) => {
29+
if (id !== childId) return () => {};
2630
registry.set(shell, { title: "Child result" });
2731
return () => registry.set(shell, null);
2832
},
@@ -31,9 +35,11 @@ vi.mock("./threads", () => {
3135
});
3236

3337
import { appAtomRegistry } from "./atom-registry";
34-
import { useLiveThreadLinkLabels } from "./entities";
38+
import { resolveThreadLink, useLiveThreadLinkLabels } from "./entities";
3539
import { environmentThreadShells } from "./threads";
3640

41+
const childId = ThreadId.make("thread:delegated-task:command%3Amcp%3Achild");
42+
3743
it("keeps a linked child title mounted until the message stops citing it", async () => {
3844
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
3945
const container = document.createElement("div");
@@ -47,11 +53,15 @@ it("keeps a linked child title mounted until the message stops citing it", async
4753
await act(async () =>
4854
root.render(
4955
<RegistryContext.Provider value={appAtomRegistry}>
50-
<Probe text="[Child](t3-thread://v2/local/child)" />
56+
<Probe text={`<t3-thread://v2/local/${childId}>`} />
5157
</RegistryContext.Provider>,
5258
),
5359
);
54-
expect(container.textContent).toBe("[Child result](t3-thread://v2/local/child)");
60+
expect(container.textContent).toBe(`[Child result](t3-thread://v2/local/${childId})`);
61+
const target = { environmentId: EnvironmentId.make("local"), threadId: childId };
62+
expect(
63+
resolveThreadLink((atom) => appAtomRegistry.get(atom), target, target.environmentId),
64+
).toEqual(target);
5565
expect(renders).toBeLessThan(20);
5666
await act(async () =>
5767
root.render(
@@ -65,7 +75,7 @@ it("keeps a linked child title mounted until the message stops citing it", async
6575
appAtomRegistry.get(
6676
environmentThreadShells.threadShellAtom({
6777
environmentId: EnvironmentId.make("local"),
68-
threadId: ThreadId.make("child"),
78+
threadId: childId,
6979
}),
7080
),
7181
).toBeNull();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { RegistryContext, useAtomValue } from "@effect/atom-react";
2+
import { EnvironmentId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
3+
import { Atom } from "effect/reactivity";
4+
import { expect, it, vi } from "vite-plus/test";
5+
6+
import { render } from "../../../test/render";
7+
import { appAtomRegistry } from "../../rpc/atomRegistry";
8+
import { threadFamilies } from "../../state/threads";
9+
import { MarkdownThreadLink } from "./MarkdownThreadLink";
10+
import "../../index.css";
11+
12+
const environmentId = EnvironmentId.make("local");
13+
const threadId = ThreadId.make("thread:delegated-task:command%3Amcp%3Achild");
14+
const child = { environmentId, id: threadId, title: "Code store foundation" };
15+
const familyLoaded = Atom.make(false);
16+
17+
vi.mock("../../state/entities", async (original) => ({
18+
...(await original<typeof import("../../state/entities")>()),
19+
useThreadShell: (ref: ScopedThreadRef | null) => {
20+
const loaded = useAtomValue(familyLoaded);
21+
return loaded && ref?.environmentId === environmentId && ref.threadId === threadId
22+
? child
23+
: null;
24+
},
25+
useThreadRefs: () => [],
26+
useProject: () => null,
27+
}));
28+
29+
it("opens a cited idle child's literal ID and keeps its title until the citation unmounts", async () => {
30+
using _family = vi.spyOn(threadFamilies, "mount").mockImplementation((registry, env, id) => {
31+
if (env !== environmentId || id !== threadId) return () => {};
32+
registry.set(familyLoaded, true);
33+
return () => registry.set(familyLoaded, false);
34+
});
35+
await using screen = await render(
36+
<RegistryContext value={appAtomRegistry}>
37+
<p>
38+
The repairs are verified in{" "}
39+
<MarkdownThreadLink
40+
environmentId={environmentId}
41+
link={{ environmentId, threadId }}
42+
label={null}
43+
/>
44+
.
45+
</p>
46+
</RegistryContext>,
47+
);
48+
const link = screen.getByRole("link", { name: "Thread, Code store foundation" });
49+
await expect.element(link).toHaveAttribute("href", `/local/${encodeURIComponent(threadId)}`);
50+
await screen.unmount();
51+
expect(appAtomRegistry.get(familyLoaded)).toBe(false);
52+
});

0 commit comments

Comments
 (0)