Skip to content
TypeScript

test(web): linked-environment subagents keep opening in their own thread (#26492)

Sebastian Pugliesebf5485c2e9e6
diff --git a/apps/web/src/components/chat/useThreadLifecycle.browser.test.tsx b/apps/web/src/components/chat/useThreadLifecycle.browser.test.tsx
index 6c02319d25a..76f9434eedf 100644
--- a/apps/web/src/components/chat/useThreadLifecycle.browser.test.tsx
+++ b/apps/web/src/components/chat/useThreadLifecycle.browser.test.tsx
@@ -1,10 +1,12 @@
import * as Cause from "effect/Cause";
import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
+import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { expect, it, vi } from "vite-plus/test";
import { page } from "vite-plus/test/browser";
const state = vi.hoisted(() => ({
+ childThreadInputs: [] as EnvironmentThreadShell[],
switchRef: (async () => undefined) as (input: unknown) => Promise<unknown>,
}));
@@ -32,7 +34,7 @@ vi.mock(import("../../hooks/useThreadActions"), async (importOriginal) => ({
vi.mock(import("../../state/entities"), async (importOriginal) => ({
...(await importOriginal()),
- useChildThreadInputs: (() => []) as never,
+ useChildThreadInputs: (() => state.childThreadInputs) as never,
}));
import { render } from "../../../test/render";
@@ -41,6 +43,7 @@ import { useThreadLifecycle } from "./useThreadLifecycle";
const environmentId = EnvironmentId.make("environment:test");
function setup() {
+ state.childThreadInputs = [];
state.switchRef = async () => undefined;
}
@@ -60,6 +63,41 @@ function threadInput(threadId: string, branch: string) {
type ThreadInput = ReturnType<typeof threadInput>;
+it.each([
+ { remote: false, approval: false, link: "Open question" },
+ { remote: true, approval: false, link: "Open question" },
+ { remote: true, approval: false, link: "Child" },
+ { remote: true, approval: true, link: "Open approval" },
+])("opens the child in its environment ($remote, $link)", async ({ remote, approval, link }) => {
+ setup();
+ const parent = threadInput("parent", "main");
+ const childEnvironmentId = remote ? EnvironmentId.make("remote") : environmentId;
+ state.childThreadInputs = [
+ {
+ id: ThreadId.make("child"),
+ environmentId: childEnvironmentId,
+ title: "Child",
+ hasPendingApprovals: approval,
+ lineage: { sideChat: false },
+ } as EnvironmentThreadShell,
+ ];
+ await using screen = await render(
+ <RestoreBranchHarness
+ thread={parent}
+ currentRouteThreadKeyRef={{ current: parent.routeThreadKey }}
+ refreshGitStatus={() => undefined}
+ focusComposer={() => undefined}
+ />,
+ { router: "/environment:test/parent" },
+ );
+ await screen.getByRole("button", { name: link, exact: true }).click();
+ await vi.waitFor(() =>
+ expect(screen.router?.state.location.pathname).toBe(
+ `/${encodeURIComponent(childEnvironmentId)}/child`,
+ ),
+ );
+});
+
function RestoreBranchHarness(props: {
readonly thread: ThreadInput;
readonly currentRouteThreadKeyRef: { readonly current: string | null };
@@ -97,6 +135,8 @@ function RestoreBranchHarness(props: {
});
return (
<>
+ {lifecycle.childInputNow?.description}
+ {lifecycle.childInputNow?.actions}
{lifecycle.workNow?.actions}
<button
type="button"