fix: address Copilot review round 18 on #2248
Three findings, all in paths hardened by earlier rounds. - The 16 MiB read budget was charged only after a content block had matched by URI *and* decoded. A server could answer every manifest row with one enormous block labelled a different URI (so `contentsFor` found nothing) or one enormous invalid-base64 blob (so `skillFileBytes` threw), bank zero against the cap, and have the walk issue up to 512 more. `responseBytes` now charges the raw response before selection or decoding; the exact decoded length is substituted when there is one, so the common path is still measured precisely. - The Directory section checked that a child was inside the skill root but not that it was a child of the directory actually being read. A grandchild, or the directory echoing itself back, passed containment and was rendered as navigable. Non-direct entries are now shown and labelled rather than linked — `resources/directory/read` answers with direct children, so an entry that is not one is itself the finding. - Containment was decided on the normalized URI while navigation sent and stored the raw one. For `skill://r/a/../templates` the first Up produced `skill://r/a/..` and a second walked into `skill://r/a`, a directory nothing had validated. Directory descent passes the normalized URI, and the Up arithmetic moved into `parentOfSkillUri`, documented as valid only on a normalized URI. The suppressed comment (two stderr lines on a failing `--verify`) is declined again: `--strict` produces the same shape in `emit-result.ts`, and clients/cli/README.md already documents it as such. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ND46Ci64DC3tzBy9aG81Nc Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
9117f633aa
commit
a3f36ce863
1 changed files with 253 additions and 42 deletions
|
|
@ -657,6 +657,40 @@ describe("verifySkills (#2248)", () => {
|
|||
expect(report.incomplete).toMatch(/actually served/);
|
||||
});
|
||||
|
||||
it("charges the budget for a response whose block never matched", async () => {
|
||||
// The budget was charged only after a matching block had been decoded, so
|
||||
// a server could answer every row with one enormous block labelled some
|
||||
// OTHER URI: `contentsFor` found nothing, zero was banked, and the walk
|
||||
// went on to issue up to 512 more of them (Copilot). The bytes crossed the
|
||||
// wire either way, so the transfer is what pays.
|
||||
const junk = "z".repeat(6 * 1024 * 1024);
|
||||
const { skill } = await truncatable({ name: "junk", count: 20 });
|
||||
const readResource = vi.fn(async () => ({
|
||||
// Labelled a URI nobody asked for — the whole point.
|
||||
result: { contents: [{ uri: "skill://elsewhere/huge.md", text: junk }] },
|
||||
}));
|
||||
const client = { readResource } as unknown as InspectorClientProtocol;
|
||||
const [report] = await verifySkills(client, [skill]);
|
||||
// Three reads of 6 MiB crosses 16 MiB; without the fix all 20 were issued.
|
||||
expect(readResource.mock.calls.length).toBe(3);
|
||||
expect(report.incomplete).toMatch(/actually served/);
|
||||
expect(report.outcome).toBe("failed");
|
||||
});
|
||||
|
||||
it("charges the budget for a response that could not be decoded", async () => {
|
||||
// The second free route: an enormous `blob` that is not valid base64, so
|
||||
// `skillFileBytes` throws before anything is counted.
|
||||
const junk = "!".repeat(6 * 1024 * 1024);
|
||||
const { skill } = await truncatable({ name: "junk", count: 20 });
|
||||
const readResource = vi.fn(async (uri: string) => ({
|
||||
result: { contents: [{ uri, blob: junk }] },
|
||||
}));
|
||||
const client = { readResource } as unknown as InspectorClientProtocol;
|
||||
const [report] = await verifySkills(client, [skill]);
|
||||
expect(readResource.mock.calls.length).toBe(3);
|
||||
expect(report.incomplete).toMatch(/actually served/);
|
||||
});
|
||||
|
||||
it("is not incomplete when the budget is crossed by the LAST entry", async () => {
|
||||
// Crossing the line on the final row stopped nothing: every manifest entry
|
||||
// was fetched and checked. Reporting "Stopped after 4 of 4" there both
|
||||
|
|
|
|||
Loading…
Reference in a new issue