RotNot / src /lib /debate /__tests__ /few-shot-examples.test.ts
deploy
Deploy RotNot
9580dce
Raw History Blame Contribute Delete
52 kB
import { describe, it, expect } from "vitest"; import { type FewShotExample, loadFewShotExamples, getExamplesForDimension, getOverallExamples, groupByScoreLevel, formatExample, buildFewShotBlock, buildInlineDimensionExamples, } from "../few-shot-examples"; // --------------------------------------------------------------------------- // Fixtures // --------------------------------------------------------------------------- function makeExample(overrides: Partial<FewShotExample> = {}): FewShotExample { return { id: "ex-test", scoreLevel: 7, dimensionId: "argument-structure", argument: "This is a test argument about governance.", rationale: "Scores 7 because the structure is clear and logical.", topic: "Governments should regulate social media", ...overrides, }; } const SAMPLE_EXAMPLES: FewShotExample[] = [ makeExample({ id: "ex-01", scoreLevel: 2, dimensionId: "flaw-detection" }), makeExample({ id: "ex-02", scoreLevel: 5, dimensionId: "argument-structure" }), makeExample({ id: "ex-03", scoreLevel: 8, dimensionId: "argument-structure" }), makeExample({ id: "ex-04", scoreLevel: 3, dimensionId: "overall" }), makeExample({ id: "ex-05", scoreLevel: 9, dimensionId: "persuasiveness" }), makeExample({ id: "ex-06", scoreLevel: 6, dimensionId: "flaw-detection" }), ]; // --------------------------------------------------------------------------- // loadFewShotExamples β€” disk loading (real file) // --------------------------------------------------------------------------- describe("loadFewShotExamples", () => { it("returns an array", () => { const result = loadFewShotExamples(); expect(Array.isArray(result)).toBe(true); }); it("returns at least 50 examples from the real calibration dataset", () => { const result = loadFewShotExamples(); // The repo ships 82 manually graded calibration examples expect(result.length).toBeGreaterThanOrEqual(50); const first = result[0]; expect(first.id).toBe("ex-01"); expect(typeof first.argument).toBe("string"); expect(typeof first.rationale).toBe("string"); expect(typeof first.topic).toBe("string"); expect(typeof first.scoreLevel).toBe("number"); expect(typeof first.dimensionId).toBe("string"); }); it("all loaded entries have required fields", () => { const result = loadFewShotExamples(); for (const ex of result) { expect(typeof ex.id).toBe("string"); expect(typeof ex.scoreLevel).toBe("number"); expect(typeof ex.dimensionId).toBe("string"); expect(typeof ex.argument).toBe("string"); expect(typeof ex.rationale).toBe("string"); expect(typeof ex.topic).toBe("string"); } }); }); // --------------------------------------------------------------------------- // getExamplesForDimension // --------------------------------------------------------------------------- describe("getExamplesForDimension", () => { it("returns only examples matching the given dimensionId", () => { const result = getExamplesForDimension(SAMPLE_EXAMPLES, "argument-structure"); expect(result).toHaveLength(2); expect(result.every((ex) => ex.dimensionId === "argument-structure")).toBe(true); }); it("returns empty array when no examples match", () => { const result = getExamplesForDimension(SAMPLE_EXAMPLES, "nonexistent-dim"); expect(result).toHaveLength(0); }); it("returns all matching examples (multiple dimensions)", () => { const result = getExamplesForDimension(SAMPLE_EXAMPLES, "flaw-detection"); expect(result).toHaveLength(2); }); it("returns empty array on empty input", () => { expect(getExamplesForDimension([], "argument-structure")).toHaveLength(0); }); }); // --------------------------------------------------------------------------- // getOverallExamples // --------------------------------------------------------------------------- describe("getOverallExamples", () => { it("returns only examples with dimensionId === 'overall'", () => { const result = getOverallExamples(SAMPLE_EXAMPLES); expect(result).toHaveLength(1); expect(result[0].id).toBe("ex-04"); }); it("returns empty array when no overall examples exist", () => { const noOverall = SAMPLE_EXAMPLES.filter((ex) => ex.dimensionId !== "overall"); expect(getOverallExamples(noOverall)).toHaveLength(0); }); }); // --------------------------------------------------------------------------- // groupByScoreLevel // --------------------------------------------------------------------------- describe("groupByScoreLevel", () => { it("places scores 0–3 in low", () => { const { low } = groupByScoreLevel(SAMPLE_EXAMPLES); expect(low.map((e) => e.id)).toEqual(expect.arrayContaining(["ex-01", "ex-04"])); expect(low.every((e) => e.scoreLevel <= 3)).toBe(true); }); it("places scores 4–6 in medium", () => { const { medium } = groupByScoreLevel(SAMPLE_EXAMPLES); expect(medium.map((e) => e.id)).toEqual( expect.arrayContaining(["ex-02", "ex-06"]), ); expect(medium.every((e) => e.scoreLevel >= 4 && e.scoreLevel <= 6)).toBe(true); }); it("places scores 7–10 in high", () => { const { high } = groupByScoreLevel(SAMPLE_EXAMPLES); expect(high.map((e) => e.id)).toEqual( expect.arrayContaining(["ex-03", "ex-05"]), ); expect(high.every((e) => e.scoreLevel >= 7)).toBe(true); }); it("handles empty input", () => { const { low, medium, high } = groupByScoreLevel([]); expect(low).toHaveLength(0); expect(medium).toHaveLength(0); expect(high).toHaveLength(0); }); it("score 3 is in low, score 4 is in medium, score 6 is in medium, score 7 is in high", () => { const boundary = [ makeExample({ id: "b1", scoreLevel: 3 }), makeExample({ id: "b2", scoreLevel: 4 }), makeExample({ id: "b3", scoreLevel: 6 }), makeExample({ id: "b4", scoreLevel: 7 }), ]; const { low, medium, high } = groupByScoreLevel(boundary); expect(low.map((e) => e.id)).toContain("b1"); expect(medium.map((e) => e.id)).toContain("b2"); expect(medium.map((e) => e.id)).toContain("b3"); expect(high.map((e) => e.id)).toContain("b4"); }); }); // --------------------------------------------------------------------------- // formatExample // --------------------------------------------------------------------------- describe("formatExample", () => { it("includes the score level", () => { const ex = makeExample({ scoreLevel: 7 }); expect(formatExample(ex)).toContain("Score: 7/10"); }); it("includes a humanised dimension name for kebab-case ids", () => { const ex = makeExample({ dimensionId: "argument-structure" }); expect(formatExample(ex)).toContain("Argument Structure"); }); it("shows 'Overall Quality' for dimensionId === 'overall'", () => { const ex = makeExample({ dimensionId: "overall" }); expect(formatExample(ex)).toContain("Overall Quality"); }); it("includes the topic", () => { const ex = makeExample({ topic: "AI should be banned" }); expect(formatExample(ex)).toContain("AI should be banned"); }); it("includes the argument text", () => { const ex = makeExample({ argument: "Here is my argument." }); expect(formatExample(ex)).toContain("Here is my argument."); }); it("includes the rationale", () => { const ex = makeExample({ rationale: "Because logic says so." }); expect(formatExample(ex)).toContain("Because logic says so."); }); it("includes side note when side is provided", () => { const ex = makeExample({ side: "pro" }); expect(formatExample(ex)).toContain("arguing pro"); }); it("omits side note when side is not provided", () => { const ex = makeExample(); delete (ex as Partial<FewShotExample>).side; expect(formatExample(ex)).not.toContain("arguing"); }); }); // --------------------------------------------------------------------------- // buildFewShotBlock // --------------------------------------------------------------------------- describe("buildFewShotBlock", () => { it("returns empty string when no examples are provided", () => { expect(buildFewShotBlock([])).toBe(""); }); it("returns non-empty string when examples are provided", () => { const result = buildFewShotBlock(SAMPLE_EXAMPLES); expect(result.length).toBeGreaterThan(0); }); it("includes the calibration header", () => { const result = buildFewShotBlock(SAMPLE_EXAMPLES); expect(result).toContain("Calibration Examples"); }); it("distributes examples across score levels", () => { const result = buildFewShotBlock(SAMPLE_EXAMPLES); // Should include examples from low, medium, and high tiers expect(result).toContain("Score: 2/10"); // low expect(result).toContain("Score: 5/10"); // medium expect(result).toContain("Score: 8/10"); // high }); it("respects maxExamples limit", () => { // 6 examples, limit to 2 const result = buildFewShotBlock(SAMPLE_EXAMPLES, 2); // Count occurrences of "Score:" β€” each example adds one const count = (result.match(/Score:/g) ?? []).length; expect(count).toBeLessThanOrEqual(2); }); it("works with a single example", () => { const single = [makeExample({ id: "only", scoreLevel: 7 })]; const result = buildFewShotBlock(single); expect(result).toContain("Calibration Examples"); expect(result).toContain("Score: 7/10"); }); }); // --------------------------------------------------------------------------- // buildInlineDimensionExamples // --------------------------------------------------------------------------- describe("buildInlineDimensionExamples", () => { it("returns empty string when no examples for the dimension", () => { const result = buildInlineDimensionExamples(SAMPLE_EXAMPLES, "rebuttal-quality"); expect(result).toBe(""); }); it("returns a non-empty hint when examples exist", () => { const result = buildInlineDimensionExamples(SAMPLE_EXAMPLES, "argument-structure"); expect(result.length).toBeGreaterThan(0); expect(result).toContain("e.g."); }); it("includes score reference in the hint", () => { const result = buildInlineDimensionExamples(SAMPLE_EXAMPLES, "argument-structure"); expect(result).toMatch(/score \d+/); }); it("respects maxExamples (default 2)", () => { // argument-structure has 2 examples, both should appear const result = buildInlineDimensionExamples(SAMPLE_EXAMPLES, "argument-structure"); const scoreMatches = result.match(/score \d+/g) ?? []; expect(scoreMatches.length).toBeLessThanOrEqual(2); }); it("truncates long arguments to 80 chars with ellipsis", () => { const longEx = [ makeExample({ dimensionId: "persuasiveness", argument: "A".repeat(200), }), ]; const result = buildInlineDimensionExamples(longEx, "persuasiveness"); expect(result).toContain("..."); // The total result should not contain all 200 A's expect(result.match(/A{200}/)).toBeNull(); }); it("does not add ellipsis for short arguments", () => { const shortEx = [ makeExample({ dimensionId: "persuasiveness", argument: "Short argument.", }), ]; const result = buildInlineDimensionExamples(shortEx, "persuasiveness"); expect(result).not.toContain("..."); }); }); // --------------------------------------------------------------------------- // Integration: buildJudgeSystemPrompt with examples // --------------------------------------------------------------------------- describe("buildJudgeSystemPrompt β€” few-shot integration", () => { // Import the function here to avoid circular imports in tests // We test via the few-shot block indirectly it("buildFewShotBlock output is suitable for prompt injection", () => { const block = buildFewShotBlock(SAMPLE_EXAMPLES); // Should start with newlines (for clean separation in prompt) expect(block.startsWith("\n")).toBe(true); // Should not contain raw JSON or code fences expect(block).not.toContain("```"); }); }); // --------------------------------------------------------------------------- // Data integrity: real 20-example calibration dataset // --------------------------------------------------------------------------- describe("few-shot calibration data integrity (real 82-example dataset)", () => { // Load once for the whole suite const REAL_EXAMPLES = loadFewShotExamples(); const VALID_DIMENSION_IDS = new Set([ "flaw-detection", "steelman-awareness", "devils-advocate-depth", "argument-structure", "persuasiveness", "evidence-accuracy", "rebuttal-quality", "intellectual-honesty", "overall", ]); it("has at least 104 examples", () => { expect(REAL_EXAMPLES.length).toBeGreaterThanOrEqual(104); }); it("all IDs are unique", () => { const ids = REAL_EXAMPLES.map((ex) => ex.id); const uniqueIds = new Set(ids); expect(uniqueIds.size).toBe(ids.length); }); it("all IDs follow the ex-NN format", () => { for (const ex of REAL_EXAMPLES) { expect(ex.id).toMatch(/^ex-\d{2,}$/); } }); it("all scoreLevel values are integers in range [0, 10]", () => { for (const ex of REAL_EXAMPLES) { expect(Number.isInteger(ex.scoreLevel)).toBe(true); expect(ex.scoreLevel).toBeGreaterThanOrEqual(0); expect(ex.scoreLevel).toBeLessThanOrEqual(10); } }); it("all dimensionId values are valid scoring dimension IDs or 'overall'", () => { for (const ex of REAL_EXAMPLES) { expect(VALID_DIMENSION_IDS).toContain(ex.dimensionId); } }); it("all 8 debate scoring dimensions are represented at least once", () => { const presentDimensions = new Set(REAL_EXAMPLES.map((ex) => ex.dimensionId)); const debateDimensions = [ "flaw-detection", "steelman-awareness", "devils-advocate-depth", "argument-structure", "persuasiveness", "evidence-accuracy", "rebuttal-quality", "intellectual-honesty", ]; for (const dim of debateDimensions) { expect(presentDimensions, `dimension "${dim}" must have at least one example`).toContain(dim); } }); it("argument text is non-empty and meaningful (> 20 characters) for all examples", () => { for (const ex of REAL_EXAMPLES) { expect(typeof ex.argument).toBe("string"); expect(ex.argument.trim().length).toBeGreaterThan(20); } }); it("rationale text is non-empty and meaningful (> 20 characters) for all examples", () => { for (const ex of REAL_EXAMPLES) { expect(typeof ex.rationale).toBe("string"); expect(ex.rationale.trim().length).toBeGreaterThan(20); } }); it("topic text is non-empty for all examples", () => { for (const ex of REAL_EXAMPLES) { expect(typeof ex.topic).toBe("string"); expect(ex.topic.trim().length).toBeGreaterThan(0); } }); it("side field, when present, is 'pro' or 'con'", () => { const withSide = REAL_EXAMPLES.filter((ex) => ex.side !== undefined); for (const ex of withSide) { expect(["pro", "con"]).toContain(ex.side); } }); it("all examples have the side field set", () => { // All real calibration examples include a debate side for context const withSide = REAL_EXAMPLES.filter((ex) => ex.side !== undefined); expect(withSide).toHaveLength(REAL_EXAMPLES.length); }); it("includes a score level 10 anchor example", () => { const level10 = REAL_EXAMPLES.filter((ex) => ex.scoreLevel === 10); expect(level10.length).toBeGreaterThanOrEqual(1); }); it("covers all score levels 1-9", () => { const levels = new Set(REAL_EXAMPLES.map((ex) => ex.scoreLevel)); for (let i = 1; i <= 9; i++) { expect(levels, `score level ${i} should have at least one example`).toContain(i); } }); it("covers all three calibration tiers: low (0–3), medium (4–6), high (7–10)", () => { const { low, medium, high } = groupByScoreLevel(REAL_EXAMPLES); expect(low.length).toBeGreaterThan(0); expect(medium.length).toBeGreaterThan(0); expect(high.length).toBeGreaterThan(0); }); it("has at least 3 distinct score levels for broad scale coverage", () => { const levels = new Set(REAL_EXAMPLES.map((ex) => ex.scoreLevel)); expect(levels.size).toBeGreaterThanOrEqual(3); }); it("no argument text is identical across examples (no copy-paste duplicates)", () => { const args = REAL_EXAMPLES.map((ex) => ex.argument.trim()); const uniqueArgs = new Set(args); expect(uniqueArgs.size).toBe(args.length); }); it("no topic text is identical across all examples (diverse topics)", () => { const topics = REAL_EXAMPLES.map((ex) => ex.topic.trim()); const uniqueTopics = new Set(topics); // May share topics across dimensions β€” but should have meaningful variety expect(uniqueTopics.size).toBeGreaterThanOrEqual(10); }); it("each score level 1-10 has at least 2 examples for broad calibration coverage", () => { const levelCounts = new Map<number, number>(); for (const ex of REAL_EXAMPLES) { levelCounts.set(ex.scoreLevel, (levelCounts.get(ex.scoreLevel) ?? 0) + 1); } for (let i = 1; i <= 10; i++) { expect( levelCounts.get(i) ?? 0, `score level ${i} should have at least 2 calibration examples`, ).toBeGreaterThanOrEqual(2); } }); it("'overall' dimension has at least 2 examples for cross-dimension calibration", () => { const overall = REAL_EXAMPLES.filter((ex) => ex.dimensionId === "overall"); expect(overall.length).toBeGreaterThanOrEqual(2); }); it("rationale references the scoreLevel (explains why the score was given)", () => { // Each rationale should explain the scoring β€” at minimum contain a digit // referencing the level, or words like 'score', 'because', 'lack', 'strong' const explanatoryPattern = /\d|score|because|lack|strong|weak|clear|poor|good|excellent/i; for (const ex of REAL_EXAMPLES) { expect(ex.rationale, `example ${ex.id} rationale should explain the score`).toMatch( explanatoryPattern, ); } }); it("buildFewShotBlock with real data includes examples from all three tiers", () => { const block = buildFewShotBlock(REAL_EXAMPLES); expect(block).toContain("Calibration Examples"); // Block should reference low scores (1-3) and high scores (7-10) expect(block).toMatch(/Score: [1-3]\/10/); expect(block).toMatch(/Score: [7-9]\/10|Score: 10\/10/); }); it("getExamplesForDimension returns examples for every dimension in the real dataset", () => { for (const dimId of VALID_DIMENSION_IDS) { const dimExamples = getExamplesForDimension(REAL_EXAMPLES, dimId); expect( dimExamples.length, `dimension "${dimId}" should have at least 1 real example`, ).toBeGreaterThan(0); } }); it("getOverallExamples returns the 'overall' examples from the real dataset", () => { const overall = getOverallExamples(REAL_EXAMPLES); expect(overall.length).toBeGreaterThan(0); expect(overall.every((ex) => ex.dimensionId === "overall")).toBe(true); }); it("each of the 8 scoring dimensions has at least 4 examples for inline calibration", () => { // Ensures no dimension is too thin to produce useful inline score anchors. // Dimensions with β‰₯4 examples can anchor multiple score levels in prompts. const scoringDimensions = [ "argument-structure", "persuasiveness", "evidence-accuracy", "rebuttal-quality", "intellectual-honesty", "flaw-detection", "steelman-awareness", "devils-advocate-depth", ]; for (const dimId of scoringDimensions) { const count = REAL_EXAMPLES.filter((ex) => ex.dimensionId === dimId).length; expect( count, `dimension "${dimId}" should have at least 4 calibration examples`, ).toBeGreaterThanOrEqual(4); } }); it("newly added examples ex-39 to ex-44 cover the intended gap dimensions", () => { const newIds = ["ex-39", "ex-40", "ex-41", "ex-42", "ex-43", "ex-44"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); expect(newExamples).toHaveLength(6); const coveredDimensions = new Set(newExamples.map((ex) => ex.dimensionId)); expect(coveredDimensions).toContain("evidence-accuracy"); expect(coveredDimensions).toContain("intellectual-honesty"); expect(coveredDimensions).toContain("rebuttal-quality"); }); it("newly added examples ex-45 to ex-50 fill mid-range gaps in flaw-detection and persuasiveness", () => { const newIds = ["ex-45", "ex-46", "ex-47", "ex-48", "ex-49", "ex-50"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); expect(newExamples).toHaveLength(6); const coveredDimensions = new Set(newExamples.map((ex) => ex.dimensionId)); expect(coveredDimensions).toContain("flaw-detection"); expect(coveredDimensions).toContain("persuasiveness"); // All three mid-range score levels should be represented const newScoreLevels = new Set(newExamples.map((ex) => ex.scoreLevel)); expect(newScoreLevels).toContain(4); expect(newScoreLevels).toContain(5); expect(newScoreLevels).toContain(6); }); it("every scoring dimension has both a floor (score 1) and ceiling (score 10) anchor", () => { const scoringDimensions = [ "argument-structure", "persuasiveness", "evidence-accuracy", "rebuttal-quality", "intellectual-honesty", "flaw-detection", "steelman-awareness", "devils-advocate-depth", ]; for (const dimId of scoringDimensions) { const dimExamples = REAL_EXAMPLES.filter((ex) => ex.dimensionId === dimId); const levels = new Set(dimExamples.map((ex) => ex.scoreLevel)); expect( levels, `dimension "${dimId}" must have a floor anchor (score 1)`, ).toContain(1); expect( levels, `dimension "${dimId}" must have a ceiling anchor (score 10)`, ).toContain(10); } }); it("newly added examples ex-51 to ex-65 add floor and ceiling anchors for under-covered dimensions", () => { const newIds = [ "ex-51", "ex-52", "ex-53", "ex-54", "ex-55", "ex-56", "ex-57", "ex-58", "ex-59", "ex-60", "ex-61", "ex-62", "ex-63", "ex-64", "ex-65", ]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); expect(newExamples).toHaveLength(15); const coveredDimensions = new Set(newExamples.map((ex) => ex.dimensionId)); // Floor anchors added for rebuttal-quality, steelman-awareness, intellectual-honesty, // overall, argument-structure, devils-advocate-depth; ceilings for evidence-accuracy, // intellectual-honesty, overall, rebuttal-quality, steelman-awareness expect(coveredDimensions).toContain("rebuttal-quality"); expect(coveredDimensions).toContain("steelman-awareness"); expect(coveredDimensions).toContain("intellectual-honesty"); expect(coveredDimensions).toContain("overall"); expect(coveredDimensions).toContain("argument-structure"); expect(coveredDimensions).toContain("devils-advocate-depth"); expect(coveredDimensions).toContain("evidence-accuracy"); // The new batch includes both floor (1) and ceiling (10) score levels const newScoreLevels = new Set(newExamples.map((ex) => ex.scoreLevel)); expect(newScoreLevels).toContain(1); expect(newScoreLevels).toContain(10); }); }); // --------------------------------------------------------------------------- // Expansion batch: ex-66 to ex-73 β€” mid-range gaps for argument-structure // and evidence-accuracy // --------------------------------------------------------------------------- describe("few-shot calibration expansion batch ex-66 to ex-73", () => { const REAL_EXAMPLES = loadFewShotExamples(); it("has exactly 8 new examples in the ex-66 to ex-73 range", () => { const newIds = ["ex-66", "ex-67", "ex-68", "ex-69", "ex-70", "ex-71", "ex-72", "ex-73"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); expect(newExamples).toHaveLength(8); }); it("argument-structure now covers score levels 4, 6, 7, 9 via new examples", () => { const argExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "argument-structure", ); const scores = new Set(argExamples.map((ex) => ex.scoreLevel)); expect(scores).toContain(4); expect(scores).toContain(6); expect(scores).toContain(7); expect(scores).toContain(9); }); it("evidence-accuracy now covers score levels 2, 4, 5, 7 via new examples", () => { const evidExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "evidence-accuracy", ); const scores = new Set(evidExamples.map((ex) => ex.scoreLevel)); expect(scores).toContain(2); expect(scores).toContain(4); expect(scores).toContain(5); expect(scores).toContain(7); }); it("all new examples have non-empty argument, rationale, and topic fields", () => { const newIds = ["ex-66", "ex-67", "ex-68", "ex-69", "ex-70", "ex-71", "ex-72", "ex-73"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.argument.trim().length).toBeGreaterThan(50); expect(ex.rationale.trim().length).toBeGreaterThan(50); expect(ex.topic.trim().length).toBeGreaterThan(5); } }); it("all new examples have valid dimensionId values", () => { const validDimensions = new Set([ "argument-structure", "evidence-accuracy", "flaw-detection", "steelman-awareness", "devils-advocate-depth", "persuasiveness", "rebuttal-quality", "intellectual-honesty", "overall", ]); const newIds = ["ex-66", "ex-67", "ex-68", "ex-69", "ex-70", "ex-71", "ex-72", "ex-73"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(validDimensions).toContain(ex.dimensionId); } }); }); // --------------------------------------------------------------------------- // Expansion batch: ex-74 to ex-82 β€” gap-fill for flaw-detection (3,7,9), // rebuttal-quality (3,6,8), devils-advocate-depth (5,7), and overall (8) // --------------------------------------------------------------------------- describe("few-shot calibration expansion batch ex-74 to ex-82", () => { const REAL_EXAMPLES = loadFewShotExamples(); it("has exactly 9 new examples in the ex-74 to ex-82 range", () => { const newIds = ["ex-74", "ex-75", "ex-76", "ex-77", "ex-78", "ex-79", "ex-80", "ex-81", "ex-82"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); expect(newExamples).toHaveLength(9); }); it("flaw-detection now covers all score levels 1–10 (filled gaps 3, 7, 9)", () => { const examples = REAL_EXAMPLES.filter((ex) => ex.dimensionId === "flaw-detection"); const scores = new Set(examples.map((ex) => ex.scoreLevel)); for (let i = 1; i <= 10; i++) { expect(scores).toContain(i); } }); it("rebuttal-quality now covers all score levels 1–10 (filled gaps 3, 6, 8)", () => { const examples = REAL_EXAMPLES.filter((ex) => ex.dimensionId === "rebuttal-quality"); const scores = new Set(examples.map((ex) => ex.scoreLevel)); for (let i = 1; i <= 10; i++) { expect(scores).toContain(i); } }); it("overall now covers all score levels 1–10 (filled gap 8)", () => { const examples = REAL_EXAMPLES.filter((ex) => ex.dimensionId === "overall"); const scores = new Set(examples.map((ex) => ex.scoreLevel)); for (let i = 1; i <= 10; i++) { expect(scores).toContain(i); } }); it("devils-advocate-depth now covers score levels 5 and 7", () => { const examples = REAL_EXAMPLES.filter((ex) => ex.dimensionId === "devils-advocate-depth"); const scores = new Set(examples.map((ex) => ex.scoreLevel)); expect(scores).toContain(5); expect(scores).toContain(7); }); it("all new examples have non-empty argument, rationale, and topic fields", () => { const newIds = ["ex-74", "ex-75", "ex-76", "ex-77", "ex-78", "ex-79", "ex-80", "ex-81", "ex-82"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.argument.trim().length).toBeGreaterThan(50); expect(ex.rationale.trim().length).toBeGreaterThan(50); expect(ex.topic.trim().length).toBeGreaterThan(5); } }); it("all new examples have valid dimensionId values", () => { const validDimensions = new Set([ "argument-structure", "evidence-accuracy", "flaw-detection", "steelman-awareness", "devils-advocate-depth", "persuasiveness", "rebuttal-quality", "intellectual-honesty", "overall", ]); const newIds = ["ex-74", "ex-75", "ex-76", "ex-77", "ex-78", "ex-79", "ex-80", "ex-81", "ex-82"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(validDimensions).toContain(ex.dimensionId); } }); }); // --------------------------------------------------------------------------- // Expansion batch: ex-83 to ex-90 β€” full 1–10 coverage for all 9 dimensions // fills: devils-advocate-depth (9), intellectual-honesty (4,6), // persuasiveness (2,7,9), steelman-awareness (3,8) // --------------------------------------------------------------------------- describe("few-shot calibration expansion batch ex-83 to ex-90", () => { const REAL_EXAMPLES = loadFewShotExamples(); it("has exactly 8 new examples in the ex-83 to ex-90 range", () => { const newIds = ["ex-83", "ex-84", "ex-85", "ex-86", "ex-87", "ex-88", "ex-89", "ex-90"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); expect(newExamples).toHaveLength(8); }); it("every scoring dimension now covers all 10 score levels (1–10)", () => { const scoringDimensions = [ "argument-structure", "persuasiveness", "evidence-accuracy", "rebuttal-quality", "intellectual-honesty", "flaw-detection", "steelman-awareness", "devils-advocate-depth", ]; for (const dimId of scoringDimensions) { const dimExamples = REAL_EXAMPLES.filter((ex) => ex.dimensionId === dimId); const scores = new Set(dimExamples.map((ex) => ex.scoreLevel)); for (let i = 1; i <= 10; i++) { expect( scores, `dimension "${dimId}" must have a score-${i} example after full coverage expansion`, ).toContain(i); } } }); it("devils-advocate-depth now covers score level 9", () => { const examples = REAL_EXAMPLES.filter((ex) => ex.dimensionId === "devils-advocate-depth"); const scores = new Set(examples.map((ex) => ex.scoreLevel)); expect(scores).toContain(9); }); it("intellectual-honesty now covers score levels 4 and 6", () => { const examples = REAL_EXAMPLES.filter((ex) => ex.dimensionId === "intellectual-honesty"); const scores = new Set(examples.map((ex) => ex.scoreLevel)); expect(scores).toContain(4); expect(scores).toContain(6); }); it("persuasiveness now covers score levels 2, 7, and 9", () => { const examples = REAL_EXAMPLES.filter((ex) => ex.dimensionId === "persuasiveness"); const scores = new Set(examples.map((ex) => ex.scoreLevel)); expect(scores).toContain(2); expect(scores).toContain(7); expect(scores).toContain(9); }); it("steelman-awareness now covers score levels 3 and 8", () => { const examples = REAL_EXAMPLES.filter((ex) => ex.dimensionId === "steelman-awareness"); const scores = new Set(examples.map((ex) => ex.scoreLevel)); expect(scores).toContain(3); expect(scores).toContain(8); }); it("all new examples have non-empty argument, rationale, and topic fields", () => { const newIds = ["ex-83", "ex-84", "ex-85", "ex-86", "ex-87", "ex-88", "ex-89", "ex-90"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.argument.trim().length).toBeGreaterThan(50); expect(ex.rationale.trim().length).toBeGreaterThan(50); expect(ex.topic.trim().length).toBeGreaterThan(5); } }); it("all new examples have valid dimensionId values", () => { const validDimensions = new Set([ "argument-structure", "evidence-accuracy", "flaw-detection", "steelman-awareness", "devils-advocate-depth", "persuasiveness", "rebuttal-quality", "intellectual-honesty", "overall", ]); const newIds = ["ex-83", "ex-84", "ex-85", "ex-86", "ex-87", "ex-88", "ex-89", "ex-90"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(validDimensions).toContain(ex.dimensionId); } }); }); // --------------------------------------------------------------------------- // Expansion batch: ex-91 to ex-96 β€” con-side balance pass // All prior examples were heavily pro-side (73% pro); this batch adds // con-side examples to the 5 dimensions that were 90-100% pro: // intellectual-honesty (was 100% pro) β†’ ex-91 (score=7), ex-92 (score=3) // argument-structure (was 90% pro) β†’ ex-93 (score=8) // overall (was 90% pro) β†’ ex-94 (score=5) // evidence-accuracy (was 90% pro) β†’ ex-95 (score=4) // persuasiveness (was 90% pro) β†’ ex-96 (score=6) // --------------------------------------------------------------------------- describe("few-shot calibration expansion batch ex-91 to ex-96 β€” con-side balance", () => { const REAL_EXAMPLES = loadFewShotExamples(); it("has exactly 6 new examples in the ex-91 to ex-96 range", () => { const newIds = ["ex-91", "ex-92", "ex-93", "ex-94", "ex-95", "ex-96"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); expect(newExamples).toHaveLength(6); }); it("all 6 new examples are con-side arguments", () => { const newIds = ["ex-91", "ex-92", "ex-93", "ex-94", "ex-95", "ex-96"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.side).toBe("con"); } }); it("intellectual-honesty now has at least 2 con-side examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "intellectual-honesty" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(2); }); it("argument-structure now has at least 2 con-side examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "argument-structure" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(2); }); it("overall dimension now has at least 2 con-side examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "overall" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(2); }); it("evidence-accuracy now has at least 2 con-side examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "evidence-accuracy" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(2); }); it("persuasiveness now has at least 2 con-side examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "persuasiveness" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(2); }); it("total dataset now has at least 96 examples", () => { expect(REAL_EXAMPLES.length).toBeGreaterThanOrEqual(96); }); it("all new examples have non-empty argument, rationale, and topic fields", () => { const newIds = ["ex-91", "ex-92", "ex-93", "ex-94", "ex-95", "ex-96"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.argument.trim().length).toBeGreaterThan(50); expect(ex.rationale.trim().length).toBeGreaterThan(50); expect(ex.topic.trim().length).toBeGreaterThan(5); } }); it("all new examples have valid dimensionId values", () => { const validDimensions = new Set([ "argument-structure", "evidence-accuracy", "flaw-detection", "steelman-awareness", "devils-advocate-depth", "persuasiveness", "rebuttal-quality", "intellectual-honesty", "overall", ]); const newIds = ["ex-91", "ex-92", "ex-93", "ex-94", "ex-95", "ex-96"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(validDimensions).toContain(ex.dimensionId); } }); }); describe("few-shot calibration expansion batch ex-97 to ex-102 β€” devils-advocate-depth con-side + structural gaps", () => { const REAL_EXAMPLES = loadFewShotExamples(); it("has exactly 6 new examples in the ex-97 to ex-102 range", () => { const newExamples = REAL_EXAMPLES.filter((ex) => ["ex-97", "ex-98", "ex-99", "ex-100", "ex-101", "ex-102"].includes(ex.id), ); expect(newExamples).toHaveLength(6); }); it("total dataset now has at least 102 examples", () => { expect(REAL_EXAMPLES.length).toBeGreaterThanOrEqual(102); }); it("devils-advocate-depth now has at least 4 con-side examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "devils-advocate-depth" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(4); }); it("devils-advocate-depth con-side now covers score levels 2, 6, and 9", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "devils-advocate-depth" && ex.side === "con", ); const levels = conExamples.map((ex) => ex.scoreLevel); expect(levels).toContain(2); expect(levels).toContain(6); expect(levels).toContain(9); }); it("argument-structure con-side now covers score level 3", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "argument-structure" && ex.side === "con", ); const levels = conExamples.map((ex) => ex.scoreLevel); expect(levels).toContain(3); }); it("intellectual-honesty con-side now covers score level 5", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "intellectual-honesty" && ex.side === "con", ); const levels = conExamples.map((ex) => ex.scoreLevel); expect(levels).toContain(5); }); it("overall con-side now covers score level 3", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "overall" && ex.side === "con", ); const levels = conExamples.map((ex) => ex.scoreLevel); expect(levels).toContain(3); }); it("all new examples are con-side arguments", () => { const newIds = ["ex-97", "ex-98", "ex-99", "ex-100", "ex-101", "ex-102"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.side).toBe("con"); } }); it("all new examples have non-empty argument, rationale, and topic fields", () => { const newIds = ["ex-97", "ex-98", "ex-99", "ex-100", "ex-101", "ex-102"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.argument.trim().length).toBeGreaterThan(50); expect(ex.rationale.trim().length).toBeGreaterThan(50); expect(ex.topic.trim().length).toBeGreaterThan(5); } }); it("all new examples have valid dimensionId values", () => { const validDimensions = new Set([ "argument-structure", "evidence-accuracy", "flaw-detection", "steelman-awareness", "devils-advocate-depth", "persuasiveness", "rebuttal-quality", "intellectual-honesty", "overall", ]); const newIds = ["ex-97", "ex-98", "ex-99", "ex-100", "ex-101", "ex-102"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(validDimensions).toContain(ex.dimensionId); } }); }); // --------------------------------------------------------------------------- // Expansion batch: ex-103 to ex-104 β€” evidence-accuracy & persuasiveness con-side balance // // Remaining con-side gaps after ex-102: // evidence-accuracy (only 2 con examples) β†’ ex-103 (score=7, single-use plastics ban) // persuasiveness (only 2 con examples) β†’ ex-104 (score=5, UBI vs targeted welfare) // Both dimensions now have β‰₯3 con-side examples. // --------------------------------------------------------------------------- describe("few-shot calibration expansion batch ex-103 to ex-104 β€” evidence-accuracy & persuasiveness con-side balance", () => { const REAL_EXAMPLES = loadFewShotExamples(); it("has exactly 2 new examples in the ex-103 to ex-104 range", () => { const newExamples = REAL_EXAMPLES.filter((ex) => ["ex-103", "ex-104"].includes(ex.id), ); expect(newExamples.length).toBe(2); }); it("total dataset now has at least 104 examples", () => { expect(REAL_EXAMPLES.length).toBeGreaterThanOrEqual(104); }); it("evidence-accuracy con-side now has at least 3 examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "evidence-accuracy" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(3); }); it("evidence-accuracy con-side covers score level 7", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "evidence-accuracy" && ex.side === "con", ); const levels = conExamples.map((ex) => ex.scoreLevel); expect(levels).toContain(7); }); it("persuasiveness con-side now has at least 3 examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "persuasiveness" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(3); }); it("persuasiveness con-side covers score level 5", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "persuasiveness" && ex.side === "con", ); const levels = conExamples.map((ex) => ex.scoreLevel); expect(levels).toContain(5); }); it("all new examples are con-side arguments", () => { const newIds = ["ex-103", "ex-104"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.side).toBe("con"); } }); it("all new examples have non-empty argument, rationale, and topic fields", () => { const newIds = ["ex-103", "ex-104"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.argument.trim().length).toBeGreaterThan(50); expect(ex.rationale.trim().length).toBeGreaterThan(50); expect(ex.topic.trim().length).toBeGreaterThan(5); } }); it("all new examples have valid dimensionId values", () => { const validDimensions = new Set([ "argument-structure", "evidence-accuracy", "flaw-detection", "steelman-awareness", "devils-advocate-depth", "persuasiveness", "rebuttal-quality", "intellectual-honesty", "overall", ]); const newIds = ["ex-103", "ex-104"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(validDimensions).toContain(ex.dimensionId); } }); }); // --------------------------------------------------------------------------- // Expansion batch: ex-105 to ex-110 β€” con-side balance pass for steelman-awareness, // flaw-detection, argument-structure, rebuttal-quality, intellectual-honesty, overall // --------------------------------------------------------------------------- describe("few-shot calibration expansion batch ex-105 to ex-110 β€” con-side coverage gaps", () => { const REAL_EXAMPLES = loadFewShotExamples(); it("has exactly 6 new examples in the ex-105 to ex-110 range", () => { const newExamples = REAL_EXAMPLES.filter((ex) => ["ex-105", "ex-106", "ex-107", "ex-108", "ex-109", "ex-110"].includes(ex.id), ); expect(newExamples.length).toBe(6); }); it("total dataset now has at least 110 examples", () => { expect(REAL_EXAMPLES.length).toBeGreaterThanOrEqual(110); }); it("steelman-awareness con-side now has at least 5 examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "steelman-awareness" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(5); }); it("flaw-detection con-side now has at least 4 examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "flaw-detection" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(4); }); it("argument-structure con-side now has at least 3 examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "argument-structure" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(3); }); it("rebuttal-quality con-side now has at least 3 examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "rebuttal-quality" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(3); }); it("intellectual-honesty con-side now has at least 4 examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "intellectual-honesty" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(4); }); it("overall con-side now has at least 4 examples", () => { const conExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "overall" && ex.side === "con", ); expect(conExamples.length).toBeGreaterThanOrEqual(4); }); it("all new examples have non-empty argument, rationale, and topic fields", () => { const newIds = ["ex-105", "ex-106", "ex-107", "ex-108", "ex-109", "ex-110"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.argument.trim().length).toBeGreaterThan(50); expect(ex.rationale.trim().length).toBeGreaterThan(50); expect(ex.topic.trim().length).toBeGreaterThan(5); } }); it("all new examples are con-side arguments", () => { const newIds = ["ex-105", "ex-106", "ex-107", "ex-108", "ex-109", "ex-110"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.side).toBe("con"); } }); it("all new examples have valid dimensionId values", () => { const validDimensions = new Set([ "argument-structure", "evidence-accuracy", "flaw-detection", "steelman-awareness", "devils-advocate-depth", "persuasiveness", "rebuttal-quality", "intellectual-honesty", "overall", ]); const newIds = ["ex-105", "ex-106", "ex-107", "ex-108", "ex-109", "ex-110"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(validDimensions).toContain(ex.dimensionId); } }); }); // --------------------------------------------------------------------------- // Expansion batch: ex-111 to ex-116 β€” pro-side balance pass // Recent batches (ex-91 to ex-110) focused heavily on con-side balance. // This batch adds pro-side examples to dimensions that received con-side // coverage, ensuring the judge sees both sides of debates. // persuasiveness (ex-111, score 8) β€” pro-side high-tier example // flaw-detection (ex-112, score 6) β€” pro-side mid-tier example // evidence-accuracy (ex-113, score 9) β€” pro-side near-exemplary example // steelman-awareness (ex-114, score 5) β€” con-side mid-tier (balance check) // rebuttal-quality (ex-115, score 4) β€” pro-side low-mid tier example // overall (ex-116, score 6) β€” pro-side mid-tier example // --------------------------------------------------------------------------- describe("few-shot calibration expansion batch ex-111 to ex-116 β€” pro-side balance", () => { const REAL_EXAMPLES = loadFewShotExamples(); it("has exactly 6 new examples in the ex-111 to ex-116 range", () => { const newExamples = REAL_EXAMPLES.filter((ex) => ["ex-111", "ex-112", "ex-113", "ex-114", "ex-115", "ex-116"].includes(ex.id), ); expect(newExamples.length).toBe(6); }); it("total dataset now has at least 116 examples", () => { expect(REAL_EXAMPLES.length).toBeGreaterThanOrEqual(116); }); it("persuasiveness pro-side now has at least 6 examples", () => { const proExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "persuasiveness" && ex.side === "pro", ); expect(proExamples.length).toBeGreaterThanOrEqual(6); }); it("flaw-detection pro-side now has at least 4 examples", () => { const proExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "flaw-detection" && ex.side === "pro", ); expect(proExamples.length).toBeGreaterThanOrEqual(4); }); it("evidence-accuracy pro-side now has at least 6 examples", () => { const proExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "evidence-accuracy" && ex.side === "pro", ); expect(proExamples.length).toBeGreaterThanOrEqual(6); }); it("rebuttal-quality pro-side now has at least 4 examples", () => { const proExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "rebuttal-quality" && ex.side === "pro", ); expect(proExamples.length).toBeGreaterThanOrEqual(4); }); it("overall pro-side now has at least 6 examples", () => { const proExamples = REAL_EXAMPLES.filter( (ex) => ex.dimensionId === "overall" && ex.side === "pro", ); expect(proExamples.length).toBeGreaterThanOrEqual(6); }); it("new examples cover score levels 4, 5, 6, 8, 9", () => { const newIds = ["ex-111", "ex-112", "ex-113", "ex-114", "ex-115", "ex-116"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); const levels = new Set(newExamples.map((ex) => ex.scoreLevel)); expect(levels).toContain(4); expect(levels).toContain(5); expect(levels).toContain(6); expect(levels).toContain(8); expect(levels).toContain(9); }); it("all new examples have non-empty argument, rationale, and topic fields", () => { const newIds = ["ex-111", "ex-112", "ex-113", "ex-114", "ex-115", "ex-116"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(ex.argument.trim().length).toBeGreaterThan(50); expect(ex.rationale.trim().length).toBeGreaterThan(50); expect(ex.topic.trim().length).toBeGreaterThan(5); } }); it("all new examples have valid dimensionId values", () => { const validDimensions = new Set([ "argument-structure", "evidence-accuracy", "flaw-detection", "steelman-awareness", "devils-advocate-depth", "persuasiveness", "rebuttal-quality", "intellectual-honesty", "overall", ]); const newIds = ["ex-111", "ex-112", "ex-113", "ex-114", "ex-115", "ex-116"]; const newExamples = REAL_EXAMPLES.filter((ex) => newIds.includes(ex.id)); for (const ex of newExamples) { expect(validDimensions).toContain(ex.dimensionId); } }); });
import { describe, it, expect } from "vitest";
import {
type FewShotExample,
loadFewShotExamples,
getExamplesForDimension,
getOverallExamples,
groupByScoreLevel,
formatExample,
buildFewShotBlock,
buildInlineDimensionExamples,
} from "../few-shot-examples";
// ---------------------------------------------------------------------------
// Fixtures
// ---------------------------------------------------------------------------
function makeExample(overrides: Partial<FewShotExample> = {}): FewShotExample {
return {
id: "ex-test",
scoreLevel: 7,
dimensionId: "argument-structure",
argument: "This is a test argument about governance.",
rationale: "Scores 7 because the structure is clear and logical.",
topic: "Governments should regulate social media",
...overrides,
};
}
const SAMPLE_EXAMPLES: FewShotExample[] = [
makeExample({ id: "ex-01", scoreLevel: 2, dimensionId: "flaw-detection" }),
makeExample({ id: "ex-02", scoreLevel: 5, dimensionId: "argument-structure" }),
makeExample({ id: "ex-03", scoreLevel: 8, dimensionId: "argument-structure" }),
makeExample({ id: "ex-04", scoreLevel: 3, dimensionId: "overall" }),
makeExample({ id: "ex-05", scoreLevel: 9, dimensionId: "persuasiveness" }),
makeExample({ id: "ex-06", scoreLevel: 6, dimensionId: "flaw-detection" }),
];
// ---------------------------------------------------------------------------
// loadFewShotExamples β€” disk loading (real file)
// ---------------------------------------------------------------------------
describe("loadFewShotExamples", () => {
it("returns an array", () => {
const result = loadFewShotExamples();
expect(Array.isArray(result)).toBe(true);
});
it("returns at least 50 examples from the real calibration dataset", () => {
const result = loadFewShotExamples();
// The repo ships 82 manually graded calibration examples
expect(result.length).toBeGreaterThanOrEqual(50);
const first = result[0];
expect(first.id).toBe("ex-01");
expect(typeof first.argument).toBe("string");
expect(typeof first.rationale).toBe("string");
expect(typeof first.topic).toBe("string");
expect(typeof first.scoreLevel).toBe("number");
expect(typeof first.dimensionId).toBe("string");
});
it("all loaded entries have required fields", () => {
const result = loadFewShotExamples();
for (const ex of result) {
expect(typeof ex.id).toBe("string");
expect(typeof ex.scoreLevel).toBe("number");
expect(typeof ex.dimensionId).toBe("string");
expect(typeof ex.argument).toBe("string");
expect(typeof ex.rationale).toBe("string");
expect(typeof ex.topic).toBe("string");
}
});
});
// ---------------------------------------------------------------------------
// getExamplesForDimension
// ---------------------------------------------------------------------------
describe("getExamplesForDimension", () => {
it("returns only examples matching the given dimensionId", () => {
const result = getExamplesForDimension(SAMPLE_EXAMPLES, "argument-structure");
expect(result).toHaveLength(2);
expect(result.every((ex) => ex.dimensionId === "argument-structure")).toBe(true);
});
it("returns empty array when no examples match", () => {
const result = getExamplesForDimension(SAMPLE_EXAMPLES, "nonexistent-dim");
expect(result).toHaveLength(0);
});
it("returns all matching examples (multiple dimensions)", () => {
const result = getExamplesForDimension(SAMPLE_EXAMPLES, "flaw-detection");
expect(result).toHaveLength(2);
});
it("returns empty array on empty input", () => {
expect(getExamplesForDimension([], "argument-structure")).toHaveLength(0);
});
});
// ---------------------------------------------------------------------------