Files
t3code/apps/server/src/orchestration/decider.workflowTaskStop.test.ts
T
Theo BrowneandClaude Fable 5 ad171b3f42 Add workflow run visibility: live agent tree, script view, transcripts
Surface Claude Agent SDK workflow runs (the Workflow orchestration tool)
end to end in the desktop app:

- Contracts: WorkflowProgressEntry schemas, run handles, workflow
  inspection RPCs, thread.task.stop command + task-stop-requested event
- ClaudeAdapter: normalize the SDK's undocumented workflow_progress
  snapshot (size-capped, tolerant), forward workflow identity on task
  events, emit task.workflowMeta from Workflow tool results, stopTask
- Ingestion: upsert workflow snapshots under a stable per-task activity
  id so projections and reconnect payloads stay one row per run
- WorkflowInspectionService: path-validated, size-capped reads of the
  run's script, journal, and per-agent transcripts (realpath containment
  under ~/.claude/projects)
- Web: WorkflowRunCard inline in the chat timeline, a workflow right-
  panel surface with Run/Script/Logs tabs, cursor-paged transcript
  polling, stop + resume affordances; remote runs link to their cloud
  session

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-02 03:26:48 -07:00

122 lines
3.8 KiB
TypeScript

import {
CommandId,
DEFAULT_PROVIDER_INTERACTION_MODE,
EventId,
ProjectId,
ThreadId,
ProviderInstanceId,
} from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { expect, it } from "@effect/vitest";
import { decideOrchestrationCommand } from "./decider.ts";
import { createEmptyReadModel, projectEvent } from "./projector.ts";
const asCommandId = (value: string): CommandId => CommandId.make(value);
const asEventId = (value: string): EventId => EventId.make(value);
const asProjectId = (value: string): ProjectId => ProjectId.make(value);
const asThreadId = (value: string): ThreadId => ThreadId.make(value);
const now = "2026-01-01T00:00:00.000Z";
const seedReadModel = Effect.gen(function* () {
const initial = createEmptyReadModel(now);
const withProject = yield* projectEvent(initial, {
sequence: 1,
eventId: asEventId("evt-project-create"),
aggregateKind: "project",
aggregateId: asProjectId("project-workflow"),
type: "project.created",
occurredAt: now,
commandId: asCommandId("cmd-project-create"),
causationEventId: null,
correlationId: asCommandId("cmd-project-create"),
metadata: {},
payload: {
projectId: asProjectId("project-workflow"),
title: "Project Workflow",
workspaceRoot: "/tmp/project-workflow",
defaultModelSelection: null,
scripts: [],
createdAt: now,
updatedAt: now,
},
});
return yield* projectEvent(withProject, {
sequence: 2,
eventId: asEventId("evt-thread-create"),
aggregateKind: "thread",
aggregateId: asThreadId("thread-workflow"),
type: "thread.created",
occurredAt: now,
commandId: asCommandId("cmd-thread-create"),
causationEventId: null,
correlationId: asCommandId("cmd-thread-create"),
metadata: {},
payload: {
threadId: asThreadId("thread-workflow"),
projectId: asProjectId("project-workflow"),
title: "Thread Workflow",
modelSelection: {
instanceId: ProviderInstanceId.make("codex"),
model: "gpt-5-codex",
},
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
runtimeMode: "approval-required",
branch: null,
worktreePath: null,
createdAt: now,
updatedAt: now,
},
});
});
it.layer(NodeServices.layer)("decider thread.task.stop", (it) => {
it.effect("emits a thread.task-stop-requested event carrying the task id", () =>
Effect.gen(function* () {
const readModel = yield* seedReadModel;
const result = yield* decideOrchestrationCommand({
command: {
type: "thread.task.stop",
commandId: asCommandId("cmd-task-stop"),
threadId: asThreadId("thread-workflow"),
taskId: "task-9",
createdAt: now,
},
readModel,
});
const events = Array.isArray(result) ? result : [result];
expect(events).toHaveLength(1);
const event = events[0]!;
expect(event.type).toBe("thread.task-stop-requested");
expect(event.payload).toMatchObject({
threadId: asThreadId("thread-workflow"),
taskId: "task-9",
createdAt: now,
});
}),
);
it.effect("rejects a task stop for a thread that does not exist", () =>
Effect.gen(function* () {
const readModel = yield* seedReadModel;
const error = yield* Effect.flip(
decideOrchestrationCommand({
command: {
type: "thread.task.stop",
commandId: asCommandId("cmd-task-stop-missing"),
threadId: asThreadId("thread-missing"),
taskId: "task-9",
createdAt: now,
},
readModel,
}),
);
expect(error.message).toContain("thread-missing");
expect(error.message).toContain("does not exist");
}),
);
});