Files
t3code/packages/client-runtime/src/state/threadRequests.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

154 lines
4.6 KiB
TypeScript

import {
NodeId,
ProviderSessionId,
RuntimeRequestId,
TurnItemId,
type OrchestrationV2ThreadProjection,
} from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
import { v2Now, v2Projection } from "./orchestrationV2TestFixtures.ts";
import { createQuestionHistoryProjector, derivePendingThreadRequests } from "./threadRequests.ts";
const requestId = RuntimeRequestId.make("async-question");
const nodeId = NodeId.make("async-question-node");
const projection: OrchestrationV2ThreadProjection = {
...v2Projection,
runtimeRequests: [
{
id: requestId,
nodeId,
providerTurnId: null,
nativeRequestRef: null,
kind: "user_input",
status: "pending",
responseCapability: { type: "message" },
createdAt: v2Now,
resolvedAt: null,
},
],
turnItems: [
{
id: TurnItemId.make("async-question-item"),
threadId: v2Projection.thread.id,
runId: null,
nodeId,
providerThreadId: null,
providerTurnId: null,
nativeItemRef: null,
parentItemId: null,
ordinal: 0,
status: "completed",
title: null,
startedAt: v2Now,
completedAt: v2Now,
updatedAt: v2Now,
type: "user_input_request",
requestId,
responseMode: "message",
questions: [
{
id: "next",
header: "Next",
question: "What should happen next?",
required: true,
allowCustomAnswer: false,
options: [{ label: "Continue", value: " continue ", description: "Resume work" }],
},
],
},
],
};
describe("pending v2 questions", () => {
it("keeps message responses available after the originating runtime exits", () => {
expect(projection.providerSessions).toEqual([]);
expect(derivePendingThreadRequests(projection).userInputs).toEqual([
{
requestId,
createdAt: "2026-06-20T00:00:00.000Z",
responseCapability: "message",
responseMode: "message",
dismissible: true,
questions: [
{
id: "next",
header: "Next",
question: "What should happen next?",
required: true,
allowCustomAnswer: false,
multiSelect: false,
options: [{ label: "Continue", value: " continue ", description: "Resume work" }],
},
],
},
]);
});
it("only marks asynchronous questions as dismissible", () => {
const live = {
...projection,
runtimeRequests: projection.runtimeRequests.map((request) => ({
...request,
responseCapability: {
type: "live" as const,
providerSessionId: ProviderSessionId.make("live-session"),
},
})),
turnItems: projection.turnItems.map((item) =>
item.type === "user_input_request" ? { ...item, responseMode: undefined } : item,
),
};
expect(derivePendingThreadRequests(live).userInputs[0]?.dismissible).toBe(false);
});
it("removes answered requests from the composer while retaining their answers in projection data", () => {
const answered = {
...projection,
runtimeRequests: projection.runtimeRequests.map((request) => ({
...request,
status: "resolved" as const,
resolvedAt: v2Now,
answers: { next: " continue " },
})),
};
expect(derivePendingThreadRequests(answered).userInputs).toEqual([]);
expect(answered.runtimeRequests[0]?.answers).toEqual({ next: " continue " });
});
});
it("restores old text answers without mutating history or replacing unchanged rows", () => {
const project = createQuestionHistoryProjector();
const item = projection.turnItems[0]!;
const row = {
item,
position: 0,
sourceItemId: item.id,
sourceThreadId: item.threadId,
visibility: "local" as const,
};
const rows = [row];
const pending = { visibleTurnItems: rows, runtimeRequests: projection.runtimeRequests };
expect(project(pending)).toBe(rows);
const answered = {
...pending,
runtimeRequests: [
{
...projection.runtimeRequests[0]!,
status: "resolved" as const,
answers: { next: "Continue" },
},
],
};
const result = project(answered);
expect(result[0]?.item).toMatchObject({
questionAnswer: {
answers: { next: "Continue" },
attachmentsByQuestionId: {},
questionTextById: { next: "What should happen next?" },
},
});
expect(row.item).not.toHaveProperty("questionAnswer");
expect(project(answered)).toBe(result);
expect(project({ ...answered, visibleTurnItems: [...rows] })[0]).toBe(result[0]);
});