+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
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]>
231 lines
6.6 KiB
TypeScript
231 lines
6.6 KiB
TypeScript
import { describe, expect, it } from "vite-plus/test";
|
|
import * as Schema from "effect/Schema";
|
|
|
|
import { ProviderRuntimeEvent } from "./providerRuntime.ts";
|
|
|
|
const decodeRuntimeEvent = Schema.decodeUnknownSync(ProviderRuntimeEvent);
|
|
|
|
describe("ProviderRuntimeEvent", () => {
|
|
it("requires input and output totals for complete turn usage", () => {
|
|
const completeEvent = {
|
|
type: "turn.completed",
|
|
eventId: "event-complete-usage",
|
|
provider: "codex",
|
|
createdAt: "2026-02-28T00:00:00.000Z",
|
|
threadId: "thread-1",
|
|
turnId: "turn-1",
|
|
payload: {
|
|
state: "completed",
|
|
tokenUsage: {
|
|
usageStatus: "complete",
|
|
usageScope: "main_agent",
|
|
hasSubagents: false,
|
|
},
|
|
},
|
|
};
|
|
|
|
expect(() => decodeRuntimeEvent(completeEvent)).toThrow();
|
|
expect(
|
|
decodeRuntimeEvent({
|
|
...completeEvent,
|
|
payload: {
|
|
...completeEvent.payload,
|
|
tokenUsage: {
|
|
...completeEvent.payload.tokenUsage,
|
|
inputTokens: 10,
|
|
outputTokens: 2,
|
|
},
|
|
},
|
|
}).type,
|
|
).toBe("turn.completed");
|
|
expect(
|
|
decodeRuntimeEvent({
|
|
...completeEvent,
|
|
payload: {
|
|
...completeEvent.payload,
|
|
tokenUsage: {
|
|
...completeEvent.payload.tokenUsage,
|
|
usageStatus: "partial",
|
|
},
|
|
},
|
|
}).type,
|
|
).toBe("turn.completed");
|
|
});
|
|
|
|
it("accepts fork-provided driver kinds as branded slugs", () => {
|
|
const parsed = decodeRuntimeEvent({
|
|
type: "session.started",
|
|
eventId: "event-ollama-session",
|
|
provider: "ollama",
|
|
providerInstanceId: "ollama_local",
|
|
createdAt: "2026-02-28T00:00:00.000Z",
|
|
threadId: "thread-1",
|
|
payload: {
|
|
message: "started",
|
|
},
|
|
});
|
|
|
|
expect(parsed.provider).toBe("ollama");
|
|
expect(parsed.providerInstanceId).toBe("ollama_local");
|
|
});
|
|
|
|
it("decodes turn.plan.updated for plan rendering", () => {
|
|
const parsed = decodeRuntimeEvent({
|
|
type: "turn.plan.updated",
|
|
eventId: "event-1",
|
|
provider: "claudeAgent",
|
|
sessionId: "runtime-session-1",
|
|
createdAt: "2026-02-28T00:00:00.000Z",
|
|
threadId: "thread-1",
|
|
turnId: "turn-1",
|
|
payload: {
|
|
explanation: "Implement schema updates",
|
|
plan: [
|
|
{ step: "Define event union", status: "completed" },
|
|
{ step: "Wire adapter mapping", status: "inProgress" },
|
|
],
|
|
},
|
|
});
|
|
|
|
expect(parsed.type).toBe("turn.plan.updated");
|
|
if (parsed.type !== "turn.plan.updated") {
|
|
throw new Error("expected turn.plan.updated");
|
|
}
|
|
expect(parsed.payload.plan).toHaveLength(2);
|
|
expect(parsed.payload.plan[1]?.status).toBe("inProgress");
|
|
});
|
|
|
|
it("decodes proposed-plan completion events", () => {
|
|
const parsed = decodeRuntimeEvent({
|
|
type: "turn.proposed.completed",
|
|
eventId: "event-proposed-plan-1",
|
|
provider: "codex",
|
|
createdAt: "2026-02-28T00:00:00.000Z",
|
|
threadId: "thread-1",
|
|
turnId: "turn-1",
|
|
payload: {
|
|
planMarkdown: "# Ship it",
|
|
},
|
|
});
|
|
|
|
expect(parsed.type).toBe("turn.proposed.completed");
|
|
if (parsed.type !== "turn.proposed.completed") {
|
|
throw new Error("expected turn.proposed.completed");
|
|
}
|
|
expect(parsed.payload.planMarkdown).toBe("# Ship it");
|
|
});
|
|
|
|
it("decodes user-input.requested with structured questions", () => {
|
|
const parsed = decodeRuntimeEvent({
|
|
type: "user-input.requested",
|
|
eventId: "event-2",
|
|
provider: "claudeAgent",
|
|
sessionId: "runtime-session-2",
|
|
createdAt: "2026-02-28T00:00:01.000Z",
|
|
threadId: "thread-2",
|
|
requestId: "request-1",
|
|
payload: {
|
|
questions: [
|
|
{
|
|
id: "sandbox_mode",
|
|
header: "Sandbox",
|
|
question: "Which mode should be used?",
|
|
options: [
|
|
{
|
|
label: "workspace-write",
|
|
description: "Allow edits in workspace only",
|
|
},
|
|
{
|
|
label: "danger-full-access",
|
|
description: "Allow unrestricted access",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
expect(parsed.type).toBe("user-input.requested");
|
|
if (parsed.type !== "user-input.requested") {
|
|
throw new Error("expected user-input.requested");
|
|
}
|
|
expect(parsed.payload.questions[0]?.id).toBe("sandbox_mode");
|
|
expect(parsed.payload.questions[0]?.options).toHaveLength(2);
|
|
});
|
|
|
|
it("decodes user-input.resolved with answer map", () => {
|
|
const parsed = decodeRuntimeEvent({
|
|
type: "user-input.resolved",
|
|
eventId: "event-3",
|
|
provider: "claudeAgent",
|
|
sessionId: "runtime-session-2",
|
|
createdAt: "2026-02-28T00:00:02.000Z",
|
|
threadId: "thread-2",
|
|
requestId: "request-1",
|
|
payload: {
|
|
answers: {
|
|
sandbox_mode: "workspace-write",
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(parsed.type).toBe("user-input.resolved");
|
|
if (parsed.type !== "user-input.resolved") {
|
|
throw new Error("expected user-input.resolved");
|
|
}
|
|
expect(parsed.payload.answers.sandbox_mode).toBe("workspace-write");
|
|
});
|
|
|
|
it("rejects legacy message.delta type", () => {
|
|
expect(() =>
|
|
decodeRuntimeEvent({
|
|
type: "message.delta",
|
|
eventId: "event-4",
|
|
provider: "codex",
|
|
sessionId: "runtime-session-3",
|
|
createdAt: "2026-02-28T00:00:03.000Z",
|
|
payload: { delta: "legacy" },
|
|
}),
|
|
).toThrow();
|
|
});
|
|
|
|
it("rejects empty branded canonical ids", () => {
|
|
expect(() =>
|
|
decodeRuntimeEvent({
|
|
type: "runtime.error",
|
|
eventId: "event-5",
|
|
provider: "codex",
|
|
sessionId: "runtime-session-3",
|
|
createdAt: "2026-02-28T00:00:03.000Z",
|
|
threadId: " ",
|
|
payload: { message: "boom" },
|
|
}),
|
|
).toThrow();
|
|
});
|
|
|
|
it("decodes normalized thread token usage snapshots", () => {
|
|
const parsed = decodeRuntimeEvent({
|
|
type: "thread.token-usage.updated",
|
|
eventId: "event-token-usage-1",
|
|
provider: "claudeAgent",
|
|
createdAt: "2026-02-28T00:00:04.000Z",
|
|
threadId: "thread-1",
|
|
payload: {
|
|
usage: {
|
|
usedTokens: 31251,
|
|
maxTokens: 200000,
|
|
toolUses: 25,
|
|
durationMs: 43567,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(parsed.type).toBe("thread.token-usage.updated");
|
|
if (parsed.type !== "thread.token-usage.updated") {
|
|
throw new Error("expected thread.token-usage.updated");
|
|
}
|
|
expect(parsed.payload.usage.maxTokens).toBe(200000);
|
|
expect(parsed.payload.usage.usedTokens).toBe(31251);
|
|
});
|
|
});
|