File size: 1,781 Bytes
6a2bc3b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | import { describe, expect, it } from "vitest";
import { getForkTurnIndex } from "../shared/fork-turn-index";
interface TestMessage {
readonly id: string;
readonly role: "user" | "assistant";
readonly content: string;
readonly timestamp: number;
readonly forkable?: boolean;
readonly steps?: readonly {
readonly n: number;
readonly items: readonly { readonly type: string; readonly content?: string }[];
}[];
}
function message(
role: TestMessage["role"],
options: Partial<TestMessage> = {},
): TestMessage {
return {
id: crypto.randomUUID(),
role,
content: "",
timestamp: 1,
...options,
};
}
describe("fork turn index", () => {
it("counts a steer embedded in the current assistant response", () => {
const messages = [
message("user"),
message("assistant", {
steps: [{ n: 1, items: [{ type: "steer", content: "also fix tests" }] }],
}),
];
expect(getForkTurnIndex(messages, 1)).toBe(1);
});
it("carries prior steer turns into later assistant responses", () => {
const messages = [
message("user"),
message("assistant", {
steps: [{ n: 1, items: [{ type: "steer", content: "also fix tests" }] }],
}),
message("user"),
message("assistant"),
];
expect(getForkTurnIndex(messages, 3)).toBe(2);
});
it("does not count or offer forks for host-only command output", () => {
const messages = [
message("user", { content: "/compact", forkable: false }),
message("assistant", { content: "The context has been compacted.", forkable: false }),
message("user"),
message("assistant"),
];
expect(getForkTurnIndex(messages, 1)).toBeUndefined();
expect(getForkTurnIndex(messages, 3)).toBe(0);
});
});
|