From c47b57a1996a95a2f4618b505d2f9dac180c8c97 Mon Sep 17 00:00:00 2001 From: can1357 Date: Sat, 20 Jun 2026 22:15:52 +0200 Subject: [PATCH] test(coding-agent): make inventoryFrom robust to prompt.md reorder The prompt-inventory test sliced on the '# Inventory'/'ENV' markers from the PR's merge-base prompt.md. On current main (chore: prompt reorder) the heading is '# Tool Inventory' and the 'ENV' marker is gone, which is why the file was deleted there. Accept either layout so the resurrected tests (incl. the SDK 'render provided tools' contract) pass after the cherry-pick. --- .../test/system-prompt-inventory.test.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/coding-agent/test/system-prompt-inventory.test.ts b/packages/coding-agent/test/system-prompt-inventory.test.ts index bb8d4f743..c6d2dc1fb 100644 --- a/packages/coding-agent/test/system-prompt-inventory.test.ts +++ b/packages/coding-agent/test/system-prompt-inventory.test.ts @@ -79,11 +79,18 @@ describe("system prompt tool inventory", () => { } function inventoryFrom(text: string): string { - const inventoryStart = text.indexOf("# Inventory"); + // Tolerate either prompt layout: the merge-base "# Inventory" / "ENV" framing and the + // reordered "# Tool Inventory" / "TOOL POLICY" framing on current main. The slice just + // needs to isolate the rendered tool list from the rest of the prompt. + const inventoryStart = ["# Tool Inventory", "# Inventory"] + .map(header => text.indexOf(header)) + .find(index => index >= 0) ?? -1; expect(inventoryStart).toBeGreaterThan(-1); - const envStart = text.indexOf("ENV\n", inventoryStart); - expect(envStart).toBeGreaterThan(inventoryStart); - return text.slice(inventoryStart, envStart); + const sectionEnds = ["\nENV\n", "\nTOOL POLICY", "\n# "] + .map(marker => text.indexOf(marker, inventoryStart + 1)) + .filter(index => index > inventoryStart); + const inventoryEnd = sectionEnds.length > 0 ? Math.min(...sectionEnds) : text.length; + return text.slice(inventoryStart, inventoryEnd); } it("renders a compact name list only when native tools are active and descriptors stay in schemas", async () => {