| import { describe, expect, it } from "vitest"; |
|
|
| import { |
| buildIterationMemoryPrompt, |
| createIterationMemory, |
| optimizeIterationMemory, |
| } from "../queue/iteration-memory.js"; |
|
|
| describe("iteration memory optimizer", () => { |
| it("accumulates repeated weak dimensions into a compact memory prompt", () => { |
| const first = optimizeIterationMemory( |
| createIterationMemory(), |
| { |
| total_score: 8, |
| max_score: 12, |
| verdict: "NEEDS_REVISION", |
| dimensions: { |
| task_realism: { score: 1, explanation: "The task reads like a procedural checklist." }, |
| trajectory_task_alignment: { score: 0, explanation: "The task asks for an action missing from the trajectory." }, |
| }, |
| }, |
| 1, |
| "first feedback", |
| ); |
| const second = optimizeIterationMemory( |
| first, |
| { |
| total_score: 9, |
| max_score: 12, |
| verdict: "NEEDS_REVISION", |
| dimensions: { |
| task_realism: { score: 2, explanation: "Now reads naturally." }, |
| trajectory_task_alignment: { score: 0, explanation: "Still contains the unsupported action." }, |
| }, |
| }, |
| 2, |
| "second feedback", |
| ); |
|
|
| expect(second.bestScore).toBe(9); |
| expect(second.resolvedDimensions).toContain("task_realism"); |
| expect(second.activeFindings).toHaveLength(1); |
| expect(second.activeFindings[0]).toMatchObject({ |
| dimension: "trajectory_task_alignment", |
| firstSeenIteration: 1, |
| lastSeenIteration: 2, |
| hits: 2, |
| }); |
|
|
| const prompt = buildIterationMemoryPrompt(second); |
| expect(prompt).toContain("ITERATION MEMORY"); |
| expect(prompt).toContain("trajectory_task_alignment"); |
| expect(prompt).toContain("repeated 2x"); |
| expect(prompt).toContain("RESOLVED DIMENSIONS: task_realism"); |
| expect(prompt).toContain("second feedback"); |
| }); |
|
|
| it("removes active findings once the dimension is fixed", () => { |
| const first = optimizeIterationMemory( |
| createIterationMemory(), |
| { |
| total_score: 7, |
| dimensions: { |
| rubric_quality: { score: 0, explanation: "Rubric is not observable." }, |
| }, |
| }, |
| 1, |
| "needs observable rubric", |
| ); |
| const fixed = optimizeIterationMemory( |
| first, |
| { |
| total_score: 11, |
| dimensions: { |
| rubric_quality: { score: 2, explanation: "Rubric is now observable." }, |
| }, |
| }, |
| 2, |
| "fixed", |
| ); |
|
|
| expect(fixed.activeFindings).toHaveLength(0); |
| expect(fixed.resolvedDimensions).toEqual(["rubric_quality"]); |
| expect(buildIterationMemoryPrompt(fixed)).toContain("No active weak dimensions remain"); |
| }); |
| }); |
|
|