Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

handoff.test.ts

65 lines2.1 KB

1import { ProviderInstanceId, RunId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3import { resolveHandoffEndpoints, type HandoffTimelineRun } from "./handoff.ts";
4​
5const from = ProviderInstanceId.make("codex_personal");
6const to = ProviderInstanceId.make("claudeAgent");
7const item = {
8 runId: RunId.make("target"),
9 fromProviderInstanceIds: [from],
10 toProviderInstanceId: to,
11};
12const run = (
13 id: string,
14 ordinal: number,
15 instanceId: ProviderInstanceId,
16 model: string,
17): HandoffTimelineRun => ({
18 id: RunId.make(id),
19 ordinal,
20 providerInstanceId: instanceId,
21 modelSelection: { instanceId, model },
22});
23​
24describe("handoff endpoints shared by web and mobile", () => {
25 it("preserves stamped models including several models from the same provider", () => {
26 const fromModelSelections = [
27 { instanceId: from, model: "source-a" },
28 { instanceId: from, model: "source-b" },
29 ];
30 expect(
31 resolveHandoffEndpoints({ ...item, fromModelSelections, toModel: "destination" }, [
32 run("target", 2, to, "later-model"),
33 ]),
34 ).toEqual({
35 from: fromModelSelections,
36 to: { instanceId: to, model: "destination" },
37 });
38 });
39​
40 it("recovers legacy models from the handoff run and latest earlier source run", () => {
41 const runs = [
42 run("later", 4, from, "wrong-later-model"),
43 run("old", 1, from, "old-model"),
44 run("target", 3, to, "destination"),
45 run("source", 2, from, "source-model"),
46 ];
47 expect(resolveHandoffEndpoints(item, runs)).toEqual({
48 from: [{ instanceId: from, model: "source-model" }],
49 to: { instanceId: to, model: "destination" },
50 });
51 });
52​
53 it("retains provider identities when historical runs are not loaded", () => {
54 expect(resolveHandoffEndpoints(item, [])).toEqual({
55 from: [{ instanceId: from, model: undefined }],
56 to: { instanceId: to, model: undefined },
57 });
58 });
59​
60 it("does not borrow a target model from another provider", () => {
61 expect(
62 resolveHandoffEndpoints(item, [run("target", 2, from, "wrong-model")]).to.model,
63 ).toBeUndefined();
64 });
65});