test(coding-agent): hoisted renderYieldSchema test imports to top level
AGENTS.md forbids inline `await import()` — move `fs`, `path`, and `prompt` to top-level namespace/named imports. The `prompt-templates` module import already registers the Handlebars helper as a side-effect, so the render calls still resolve the new `renderYieldSchema` helper.
This commit is contained in:
@@ -9,9 +9,12 @@
|
||||
*/
|
||||
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import * as fs from "node:fs/promises";
|
||||
import * as path from "node:path";
|
||||
import { expandPromptTemplate, type PromptTemplate } from "@oh-my-pi/pi-coding-agent/config/prompt-templates";
|
||||
import { expandSlashCommand, type FileSlashCommand } from "@oh-my-pi/pi-coding-agent/extensibility/slash-commands";
|
||||
import { parseCommandArgs, substituteArgs } from "@oh-my-pi/pi-coding-agent/utils/command-args";
|
||||
import { prompt } from "@oh-my-pi/pi-utils";
|
||||
|
||||
// ============================================================================
|
||||
// substituteArgs
|
||||
@@ -333,16 +336,11 @@ describe("template expansion fallback", () => {
|
||||
// ============================================================================
|
||||
|
||||
describe("renderYieldSchema", () => {
|
||||
// prompt-templates is imported for its Handlebars helper registration side-effect
|
||||
// (jtdToTypeScript + renderYieldSchema); the render calls below rely on it.
|
||||
const templatePath = path.resolve(import.meta.dir, "../src/prompts/system/subagent-system-prompt.md");
|
||||
|
||||
async function renderSubagentPrompt(outputSchema: unknown): Promise<string> {
|
||||
// Loading prompt-templates registers the Handlebars helper as a side-effect;
|
||||
// keep the import inside the test so ordering with other suites stays explicit.
|
||||
await import("@oh-my-pi/pi-coding-agent/config/prompt-templates");
|
||||
const [{ prompt }, fs, path] = await Promise.all([
|
||||
import("@oh-my-pi/pi-utils"),
|
||||
import("node:fs/promises"),
|
||||
import("node:path"),
|
||||
]);
|
||||
const templatePath = path.resolve(import.meta.dir, "../src/prompts/system/subagent-system-prompt.md");
|
||||
const templateSource = await fs.readFile(templatePath, "utf-8");
|
||||
return prompt.render(templateSource, { agent: "test-agent", outputSchema });
|
||||
}
|
||||
|
||||
@@ -401,6 +401,14 @@ describe("streaming tool call preview height (bounded across renderers)", () =>
|
||||
}
|
||||
}
|
||||
|
||||
function getRenderedLines(lines: readonly string[]): string[] {
|
||||
return lines
|
||||
.map(line => Bun.stripANSI(line).trim())
|
||||
.filter(line => line.startsWith("│") && line.endsWith("│"))
|
||||
.map(line => line.slice(1, -1).trim())
|
||||
.filter(line => line !== "" && !line.includes("earlier lines"));
|
||||
}
|
||||
|
||||
test("framed inline tool previews span the full tool width", () => {
|
||||
const width = 80;
|
||||
const { lines } = renderPending("bash", { command: "echo hi" });
|
||||
@@ -433,13 +441,11 @@ describe("streaming tool call preview height (bounded across renderers)", () =>
|
||||
for (const testCase of cases) {
|
||||
const { lines, text } = renderPending(testCase.name, testCase.args);
|
||||
expect(lines.length, `${testCase.name} preview should stay bounded`).toBeLessThan(window + 10);
|
||||
for (const needle of [firstVisible, lastVisible]) {
|
||||
expect(text, `${testCase.name} preview should keep ${needle}`).toContain(needle);
|
||||
}
|
||||
expect(text, `${testCase.name} preview should elide line-0`).not.toMatch(/\bline-0\b/);
|
||||
expect(text, `${testCase.name} preview should elide ${lastHidden}`).not.toMatch(
|
||||
new RegExp(`\\b${lastHidden}\\b`),
|
||||
);
|
||||
const renderedLines = getRenderedLines(lines);
|
||||
expect(renderedLines, `${testCase.name} preview should keep ${firstVisible}`).toContain(firstVisible);
|
||||
expect(renderedLines, `${testCase.name} preview should keep ${lastVisible}`).toContain(lastVisible);
|
||||
expect(renderedLines, `${testCase.name} preview should elide line-0`).not.toContain("line-0");
|
||||
expect(renderedLines, `${testCase.name} preview should elide ${lastHidden}`).not.toContain(lastHidden);
|
||||
expect(text, `${testCase.name} preview should advertise the elided head`).toContain(
|
||||
`… ${hidden} earlier lines`,
|
||||
);
|
||||
@@ -462,10 +468,11 @@ describe("streaming tool call preview height (bounded across renderers)", () =>
|
||||
});
|
||||
|
||||
expect(lines.length, "eval code preview should stay bounded").toBeLessThan(window + 10);
|
||||
expect(text).toContain(`const line-${total - 1} = 1;`);
|
||||
expect(text).toContain(`const line-${hidden} = 1;`);
|
||||
expect(text).not.toContain("const line-0 = 1;");
|
||||
expect(text).not.toContain(`const line-${hidden - 1} = 1;`);
|
||||
const renderedLines = getRenderedLines(lines);
|
||||
expect(renderedLines).toContain(`const line-${total - 1} = 1;`);
|
||||
expect(renderedLines).toContain(`const line-${hidden} = 1;`);
|
||||
expect(renderedLines).not.toContain("const line-0 = 1;");
|
||||
expect(renderedLines).not.toContain(`const line-${hidden - 1} = 1;`);
|
||||
expect(text).toContain(`… ${hidden} earlier lines`);
|
||||
}, 30_000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user