Luigit
repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by admin

extensions/ultra/__tests__/agent-prompt.test.ts

Raw
import { describe, expect, it } from "vitest";
import {
	assignmentPrompt,
	quoteAgentOutput,
	resumePrompt,
} from "../agent-prompt.ts";

describe("agent prompt envelopes", () => {
	it("identifies fresh assignments", () => {
		expect(
			assignmentPrompt(
				{ workflow: "research", phase: "synthesis", index: 2 },
				"Synthesize evidence.",
			),
		).toBe(`<agent id="synthesis#2" workflow="research" phase="synthesis" index="2">
  <message from="orchestrator" kind="assignment">
Synthesize evidence.
  </message>
</agent>`);
	});

	it("quotes producer identity and task without exposing interpolation syntax", () => {
		const quoted = quoteAgentOutput('{"finding":"a < b"}', [
			{ agentId: "gather#0", task: 'Inspect "parser" & docs' },
		]);
		expect(quoted).toContain(
			'<source agent="gather#0" task="Inspect &quot;parser&quot; &amp; docs"/>',
		);
		expect(quoted).toContain(
			'<content><![CDATA[{"finding":"a < b"}]]></content>',
		);
		expect(quoted).not.toContain("results[]");
	});

	it("marks continuation without exposing checkpoint internals", () => {
		const prompt = resumePrompt("synthesis#2", "synthesis", "Continue.");
		expect(prompt).toContain('from="ultra" kind="resume"');
		expect(prompt).not.toContain("checkpoint");
	});
});