From f70e4f1570872dc973a3f70f02dd8961969abe57 Mon Sep 17 00:00:00 2001 From: roboomp Date: Wed, 1 Jul 2026 03:26:13 +0000 Subject: [PATCH] test(coding-agent): hoisted renderYieldSchema test imports to top level MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../test/prompt-templates.test.ts | 16 +++++----- .../test/streaming-preview-height.test.ts | 29 ++++++++++++------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/coding-agent/test/prompt-templates.test.ts b/packages/coding-agent/test/prompt-templates.test.ts index 0d13ad77e..d800c8530 100644 --- a/packages/coding-agent/test/prompt-templates.test.ts +++ b/packages/coding-agent/test/prompt-templates.test.ts @@ -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 { - // 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 }); } diff --git a/packages/coding-agent/test/streaming-preview-height.test.ts b/packages/coding-agent/test/streaming-preview-height.test.ts index 97c015142..8dacce85f 100644 --- a/packages/coding-agent/test/streaming-preview-height.test.ts +++ b/packages/coding-agent/test/streaming-preview-height.test.ts @@ -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); });