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 () => {