refactor(test): dedupe agent and discord test fixtures

This commit is contained in:
Peter Steinberger
2026-02-22 20:01:43 +00:00
parent 5547a2275c
commit 3c75bc0e41
26 changed files with 632 additions and 737 deletions

View File

@@ -9,23 +9,19 @@ import {
makeModelSnapshotEntry,
makeReasoningAssistantMessages,
makeSimpleUserMessages,
makeSnapshotChangedOpenAIReasoningScenario,
sanitizeSnapshotChangedOpenAIReasoning,
type SanitizeSessionHistoryFn,
sanitizeWithOpenAIResponses,
TEST_SESSION_ID,
} from "./pi-embedded-runner.sanitize-session-history.test-harness.js";
let sanitizeSessionHistory: SanitizeSessionHistoryFn;
vi.mock("./pi-embedded-helpers.js", async () => ({
...(await vi.importActual("./pi-embedded-helpers.js")),
isGoogleModelApi: vi.fn(),
sanitizeSessionMessagesImages: vi.fn(async (msgs) => msgs),
}));
// Mock dependencies
vi.mock("./pi-embedded-helpers.js", async () => {
const actual = await vi.importActual("./pi-embedded-helpers.js");
return {
...actual,
isGoogleModelApi: vi.fn(),
sanitizeSessionMessagesImages: vi.fn().mockImplementation(async (msgs) => msgs),
};
});
let sanitizeSessionHistory: SanitizeSessionHistoryFn;
// We don't mock session-transcript-repair.js as it is a pure function and complicates mocking.
// We rely on the real implementation which should pass through our simple messages.
@@ -59,6 +55,24 @@ describe("sanitizeSessionHistory", () => {
const getAssistantContentTypes = (messages: AgentMessage[]) =>
getAssistantMessage(messages).content.map((block: { type: string }) => block.type);
const makeThinkingAndTextAssistantMessages = (
thinkingSignature: string = "some_sig",
): AgentMessage[] =>
[
{ role: "user", content: "hello" },
{
role: "assistant",
content: [
{
type: "thinking",
thinking: "internal",
thinkingSignature,
},
{ type: "text", text: "hi" },
],
},
] as unknown as AgentMessage[];
beforeEach(async () => {
sanitizeSessionHistory = await loadSanitizeSessionHistoryWithCleanMocks();
});
@@ -394,13 +408,8 @@ describe("sanitizeSessionHistory", () => {
});
it("downgrades orphaned openai reasoning when the model changes too", async () => {
const { sessionManager, messages, modelId } = makeSnapshotChangedOpenAIReasoningScenario();
const result = await sanitizeWithOpenAIResponses({
const result = await sanitizeSnapshotChangedOpenAIReasoning({
sanitizeSessionHistory,
messages,
modelId,
sessionManager,
});
expect(result).toEqual([]);
@@ -457,20 +466,7 @@ describe("sanitizeSessionHistory", () => {
it("drops assistant thinking blocks for github-copilot models", async () => {
setNonGoogleModelApi();
const messages = [
{ role: "user", content: "hello" },
{
role: "assistant",
content: [
{
type: "thinking",
thinking: "internal",
thinkingSignature: "reasoning_text",
},
{ type: "text", text: "hi" },
],
},
] as unknown as AgentMessage[];
const messages = makeThinkingAndTextAssistantMessages("reasoning_text");
const result = await sanitizeGithubCopilotHistory({ messages });
const assistant = getAssistantMessage(result);
@@ -532,20 +528,7 @@ describe("sanitizeSessionHistory", () => {
it("does not drop thinking blocks for non-copilot providers", async () => {
setNonGoogleModelApi();
const messages = [
{ role: "user", content: "hello" },
{
role: "assistant",
content: [
{
type: "thinking",
thinking: "internal",
thinkingSignature: "some_sig",
},
{ type: "text", text: "hi" },
],
},
] as unknown as AgentMessage[];
const messages = makeThinkingAndTextAssistantMessages();
const result = await sanitizeSessionHistory({
messages,
@@ -563,20 +546,7 @@ describe("sanitizeSessionHistory", () => {
it("does not drop thinking blocks for non-claude copilot models", async () => {
setNonGoogleModelApi();
const messages = [
{ role: "user", content: "hello" },
{
role: "assistant",
content: [
{
type: "thinking",
thinking: "internal",
thinkingSignature: "some_sig",
},
{ type: "text", text: "hi" },
],
},
] as unknown as AgentMessage[];
const messages = makeThinkingAndTextAssistantMessages();
const result = await sanitizeGithubCopilotHistory({ messages, modelId: "gpt-5.2" });
const types = getAssistantContentTypes(result);