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
59 changes: 59 additions & 0 deletions apps/web/src/components/ManagedRunEvidence.browser.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { EnvironmentId } from "@t3tools/contracts";
import { expect, it, vi } from "vite-plus/test";

import { render } from "../../test/render";
import type { ManagedRun } from "~/lib/managedRunDelivery";
import { ManagedRunEvidence } from "./ManagedRunEvidence";

vi.mock(import("~/state/environments"), async (original) => ({
...(await original()),
usePrimaryEnvironmentId: () => EnvironmentId.make("windows-fixture"),
}));
vi.mock(import("~/state/entities"), async (original) => ({
...(await original()),
useQuietThreadShell: (ref) =>
ref?.threadId === "mcp:launch:known" ? ({ threadId: ref.threadId } as never) : null,
}));

it("links an operator wait to the locally known worker and preserves unknown evidence", async () => {
const run: ManagedRun = {
version: 1,
runId: "00000000-0000-0000-0000-000000000000",
ticket: "fixture",
revision: "a".repeat(64),
status: "approved",
brief: {
workspaceId: "fixture",
repository: "lab/fixture",
baseSha: "b".repeat(40),
scope: "Fixture",
tokens: 100,
},
budget: { reserved: 100, used: null, remaining: null },
stages: [
{
stageId: "known",
role: "implementation",
status: "waiting_for_operator",
threadId: "mcp:launch:known",
providerInstanceId: "codex",
toolCalls: 0,
},
{
stageId: "unknown",
role: "qa",
status: "queued",
threadId: "mcp:launch:unknown",
providerInstanceId: null,
},
],
};
await using screen = await render(<ManagedRunEvidence run={run} />);
await expect.element(screen.getByText("implementation · Waiting for operator")).toBeVisible();
await expect
.element(screen.getByRole("link", { name: "Open worker thread" }))
.toHaveAttribute("href", "/windows-fixture/mcp%3Alaunch%3Aknown");
await expect.element(screen.getByText("Thread mcp:launch:unknown")).toBeVisible();
await expect.element(screen.getByText("Tool calls 0")).toBeVisible();
await expect.element(screen.getByText("Tool calls Unknown")).toBeVisible();
});
24 changes: 23 additions & 1 deletion apps/web/src/components/ManagedRunEvidence.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
import { ThreadId } from "@t3tools/contracts";
import { Link } from "@tanstack/react-router";

import type { ManagedRun } from "~/lib/managedRunDelivery";
import { useQuietThreadShell } from "~/state/entities";
import { usePrimaryEnvironmentId } from "~/state/environments";

function WorkerThread({ id }: { id: string | null }) {
const environmentId = usePrimaryEnvironmentId();
const ref = environmentId && id ? { environmentId, threadId: ThreadId.make(id) } : null;
const thread = useQuietThreadShell(ref);
return (
<p>
Thread {id ?? "Unknown"}
{ref && thread && (
<>
{" · "}
<Link className="underline" to="/$environmentId/$threadId" params={ref}>
Open worker thread
</Link>
</>
)}
</p>
);
}

function formatCount(value: number | null): string {
return value === null ? "Unknown" : value.toLocaleString();
Expand Down Expand Up @@ -49,7 +71,7 @@ export function ManagedRunEvidence({ run }: { run: ManagedRun }) {
</p>
<p>Stage ID {stage.stageId}</p>
<p>Provider instance {stage.providerInstanceId ?? "Unknown"}</p>
<p>Thread {stage.threadId ?? "Unknown"}</p>
<WorkerThread id={stage.threadId} />
<p>Tool calls {formatCount(stage.toolCalls ?? null)}</p>
{stage.status === "waiting_for_operator" && (
<p className="mt-1 text-muted-foreground">
Expand Down
Loading