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.
This commit is contained in:
can1357
2026-06-20 22:15:52 +02:00
parent 9722505a2b
commit c47b57a199
@@ -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 () => {