mirror of
https://github.com/murashit/codex-panel.git
synced 2026-07-22 06:57:10 +00:00
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { forkCandidatesFromItems, isForkCandidateItem, turnsAfterTurnId } from "../../../src/features/chat/fork";
|
|
import type { DisplayItem } from "../../../src/features/chat/display/types";
|
|
|
|
describe("fork candidates", () => {
|
|
it("selects final assistant messages and counts later turns", () => {
|
|
const items: DisplayItem[] = [
|
|
{ id: "u1", kind: "message", messageKind: "user", role: "user", text: "first", turnId: "turn-1" },
|
|
{
|
|
id: "a1",
|
|
kind: "message",
|
|
role: "assistant",
|
|
text: "first answer",
|
|
turnId: "turn-1",
|
|
messageKind: "assistantResponse",
|
|
messageState: "completed",
|
|
},
|
|
{ id: "tool-1", kind: "tool", role: "tool", text: "work", turnId: "turn-2" },
|
|
{
|
|
id: "a2-delta",
|
|
kind: "message",
|
|
role: "assistant",
|
|
text: "draft",
|
|
turnId: "turn-2",
|
|
messageKind: "proposedPlan",
|
|
messageState: "streaming",
|
|
},
|
|
{
|
|
id: "a2",
|
|
kind: "message",
|
|
role: "assistant",
|
|
text: "second answer",
|
|
turnId: "turn-2",
|
|
messageKind: "assistantResponse",
|
|
messageState: "completed",
|
|
},
|
|
{ id: "u3", kind: "message", messageKind: "user", role: "user", text: "third", turnId: "turn-3" },
|
|
{
|
|
id: "a3",
|
|
kind: "message",
|
|
role: "assistant",
|
|
text: "third answer",
|
|
turnId: "turn-3",
|
|
messageKind: "assistantResponse",
|
|
messageState: "completed",
|
|
},
|
|
];
|
|
|
|
const candidates = forkCandidatesFromItems(items);
|
|
|
|
expect(candidates).toEqual([
|
|
{ itemId: "a1", turnId: "turn-1" },
|
|
{ itemId: "a2", turnId: "turn-2" },
|
|
{ itemId: "a3", turnId: "turn-3" },
|
|
]);
|
|
expect(isForkCandidateItem(expectPresent(items[4]), candidates)).toBe(true);
|
|
expect(isForkCandidateItem(expectPresent(items[3]), candidates)).toBe(false);
|
|
expect(turnsAfterTurnId(items, "turn-1")).toBe(2);
|
|
expect(turnsAfterTurnId(items, "turn-2")).toBe(1);
|
|
expect(turnsAfterTurnId(items, "turn-3")).toBe(0);
|
|
expect(turnsAfterTurnId(items, "missing")).toBeNull();
|
|
});
|
|
});
|
|
|
|
function expectPresent<T>(value: T | null | undefined): T {
|
|
if (value === null || value === undefined) throw new Error("Expected value to be present");
|
|
return value;
|
|
}
|