Files
t3code/apps/mobile/src/lib/threadActivityInspector.test.ts
T
+36 de34391427 feat(orchestrator): introduce new orchestrator (#2829)
Co-authored-by: maria-rcks <[email protected]>
Co-authored-by: Bilal Bakr <[email protected]>
Co-authored-by: shivam <[email protected]>
Co-authored-by: Vitalii Yehorov <[email protected]>
Co-authored-by: Jake Leventhal <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Alex Southwell <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicholas Wasmiller <[email protected]>
Co-authored-by: PB <[email protected]>
Co-authored-by: Exotic <[email protected]>
Co-authored-by: Yash Singh <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Theo Browne <[email protected]>
Co-authored-by: Gabriel De Andrade <[email protected]>
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: scratchyone <[email protected]>
Co-authored-by: Dominic Roy <[email protected]>
Co-authored-by: chukfinley <[email protected]>
Co-authored-by: Primož Ajdišek <[email protected]>
Co-authored-by: benthecarman <[email protected]>
Co-authored-by: NaveDanan <[email protected]>
Co-authored-by: aaditagrawal <[email protected]>
Co-authored-by: Aditya Garud <[email protected]>
Co-authored-by: Nick Anisimov <[email protected]>
Co-authored-by: MacKinley Smith <[email protected]>
Co-authored-by: Yordis Prieto <[email protected]>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: AKolenda <[email protected]>
Co-authored-by: Guillermo Casanova <[email protected]>
Co-authored-by: Otavio Salvador <[email protected]>
Co-authored-by: Shirish Pothi <[email protected]>
Co-authored-by: Ishaan Kothari <[email protected]>
Co-authored-by: Bob Fowler <[email protected]>
Co-authored-by: Anton Bezdenezhnykh <[email protected]>
Co-authored-by: ValeraZSD <[email protected]>
Co-authored-by: Ephraim <[email protected]>
Co-authored-by: Ryan Ilano <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: maco <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Tristan Knight <[email protected]>
Co-authored-by: PR Batch Tester <[email protected]>
Co-authored-by: oliver <[email protected]>
Co-authored-by: kamkm <[email protected]>
Signed-off-by: Yordis Prieto <[email protected]>
2026-10-02 12:22:22 -07:00

275 lines
8.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { EMPTY_V2_ITEM_SUPPORT } from "@t3tools/client-runtime/state/item-support";
import {
CheckpointId,
CheckpointScopeId,
NodeId,
ProviderDriverKind,
ProviderInstanceId,
RunId,
ThreadId,
TurnItemId,
type OrchestrationV2ProjectedTurnItem,
type OrchestrationV2TurnItem,
} from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import { describe, expect, it } from "vite-plus/test";
import type { ThreadFeedActivity } from "./threadActivity";
import { buildThreadActivityInspector } from "./threadActivityInspector";
const threadId = ThreadId.make("thread-1");
const sourceThreadId = ThreadId.make("thread-source");
const runId = RunId.make("run-1");
const nodeId = NodeId.make("node-1");
const startedAt = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
const completedAt = DateTime.makeUnsafe("2026-06-20T00:00:02.000Z");
function itemBase(id: string) {
return {
id: TurnItemId.make(id),
threadId,
runId,
nodeId,
providerThreadId: null,
providerTurnId: null,
nativeItemRef: null,
parentItemId: null,
ordinal: 0,
status: "completed" as const,
title: null,
startedAt,
completedAt,
updatedAt: completedAt,
};
}
function activityFor(item: OrchestrationV2TurnItem): Pick<ThreadFeedActivity, "projectedItem"> {
const row: OrchestrationV2ProjectedTurnItem = {
position: 0,
visibility: "inherited",
sourceThreadId,
sourceItemId: item.id,
item,
};
return { projectedItem: row };
}
describe("buildThreadActivityInspector", () => {
it("presents command lifecycle and exit state without cached raw output", () => {
const item: OrchestrationV2TurnItem = {
...itemBase("command"),
type: "command_execution",
input: "vp check",
output: "all checks passed",
exitCode: 0,
};
const support = {
...EMPTY_V2_ITEM_SUPPORT,
item,
run: { status: "completed" } as never,
attempts: [
{
id: "attempt-1",
attemptOrdinal: 1,
status: "superseded",
reason: "initial",
},
{
id: "attempt-2",
attemptOrdinal: 2,
status: "completed",
reason: "steering_restart",
},
] as never,
node: { kind: "tool_call", status: "completed" } as never,
providerSession: {
status: "ready",
model: "gpt-5.4",
cwd: "/workspace/project",
} as never,
};
const model = buildThreadActivityInspector(activityFor(item), support, sourceThreadId);
expect(model.fields).toEqual(
expect.arrayContaining([
{ label: "Duration", value: "2.0s" },
{ label: "Run", value: "completed" },
{ label: "Working directory", value: "/workspace/project" },
{ label: "Visibility", value: "inherited" },
]),
);
expect(model.blocks).toEqual(
expect.arrayContaining([
expect.objectContaining({ label: "Command", value: "vp check" }),
expect.objectContaining({ label: "Exit", value: "Process exited with code 0" }),
expect.objectContaining({ label: "Attempt history" }),
]),
);
expect(model.blocks.some((block) => block.label === "Output")).toBe(false);
expect(model.structuredDetails).not.toContain("all checks passed");
});
it("exposes file and web result provenance plus dynamic structured data", () => {
const fileSearch: OrchestrationV2TurnItem = {
...itemBase("file-search"),
type: "file_search",
pattern: "resolveSession",
results: [{ fileName: "src/session.ts", line: 42, preview: "function resolveSession()" }],
};
const fileModel = buildThreadActivityInspector(
activityFor(fileSearch),
EMPTY_V2_ITEM_SUPPORT,
sourceThreadId,
);
expect(fileModel.fileLinks).toEqual([
{
label: "src/session.ts — function resolveSession()",
path: "src/session.ts",
line: 42,
},
]);
const webSearch: OrchestrationV2TurnItem = {
...itemBase("web-search"),
type: "web_search",
patterns: ["Effect Schema docs"],
results: [
{ title: "Schema", url: "https://effect.website/docs/schema", snippet: "Typed schemas" },
],
};
const webModel = buildThreadActivityInspector(
activityFor(webSearch),
EMPTY_V2_ITEM_SUPPORT,
sourceThreadId,
);
expect(webModel.webLinks).toEqual([
{ label: "Schema", url: "https://effect.website/docs/schema" },
]);
expect(webModel.blocks).toEqual(
expect.arrayContaining([
expect.objectContaining({ label: "Schema", value: "Typed schemas" }),
]),
);
const dynamicTool: OrchestrationV2TurnItem = {
...itemBase("dynamic"),
type: "dynamic_tool",
toolName: "custom",
input: { nested: { value: 1 } },
output: { ok: true },
};
const dynamicModel = buildThreadActivityInspector(
activityFor(dynamicTool),
EMPTY_V2_ITEM_SUPPORT,
sourceThreadId,
);
expect(dynamicModel.blocks).toEqual(
expect.arrayContaining([
expect.objectContaining({ label: "Input", value: expect.stringContaining('"nested"') }),
]),
);
expect(dynamicModel.structuredDetails).toContain('"type": "dynamic_tool"');
expect(dynamicModel.blocks.some((block) => block.label === "Output")).toBe(false);
expect(dynamicModel.structuredDetails).not.toContain('"output"');
});
it("keeps file links and change counts without cached patch bodies", () => {
const item: OrchestrationV2TurnItem = {
...itemBase("file"),
type: "file_change",
fileName: "src/example.ts",
additions: 2,
deletions: 1,
diffStr: "RAW_PATCH",
oldStr: "RAW_BEFORE",
newStr: "RAW_AFTER",
};
const model = buildThreadActivityInspector(activityFor(item), EMPTY_V2_ITEM_SUPPORT, threadId);
expect(model.fileLinks).toEqual([{ label: `modify ${item.fileName}`, path: item.fileName }]);
expect(model.fields).toContainEqual({ label: "Changes", value: "+2 −1" });
expect(model.blocks).toEqual([]);
expect(model.structuredDetails).not.toContain("RAW_");
expect(model.structuredDetails).toContain(item.fileName);
});
it("enables rollback only for the matching ready checkpoint", () => {
const checkpointId = CheckpointId.make("checkpoint-1");
const scopeId = CheckpointScopeId.make("scope-1");
const item: OrchestrationV2TurnItem = {
...itemBase("checkpoint"),
type: "checkpoint",
checkpointId,
scopeId,
files: [{ path: "src/main.ts", kind: "modified", additions: 2, deletions: 1 }],
};
const checkpoint = { id: checkpointId, scopeId, status: "ready" } as never;
const model = buildThreadActivityInspector(
activityFor(item),
{
...EMPTY_V2_ITEM_SUPPORT,
item,
checkpoint,
},
sourceThreadId,
);
expect(model.canRollback).toBe(true);
expect(model.rollbackTarget).toEqual({
threadId: sourceThreadId,
checkpointId,
scopeId,
});
const inheritedModel = buildThreadActivityInspector(
activityFor(item),
{
...EMPTY_V2_ITEM_SUPPORT,
item,
checkpoint,
},
ThreadId.make("child-thread"),
);
expect(inheritedModel.canRollback).toBe(false);
expect(inheritedModel.rollbackTarget).toBeNull();
});
it("prefers live subagent progress from supporting state", () => {
const item: OrchestrationV2TurnItem = {
...itemBase("subagent"),
type: "subagent",
subagentId: nodeId,
origin: "provider_native",
driver: ProviderDriverKind.make("claude"),
providerInstanceId: ProviderInstanceId.make("claude"),
childThreadId: null,
prompt: "Audit the reducer",
progress: "Starting",
result: null,
};
const model = buildThreadActivityInspector(
activityFor(item),
{
...EMPTY_V2_ITEM_SUPPORT,
item,
subagent: {
origin: "provider_native",
status: "running",
progress: "Reading projection tests",
result: null,
} as never,
},
sourceThreadId,
);
expect(model.fields).toContainEqual({
label: "Delegated task",
value: "provider native · running",
});
expect(model.blocks).toContainEqual({
label: "Progress",
value: "Reading projection tests",
monospaced: false,
});
});
});