fix: address Copilot review round 16 on #2248

**A hole my own round-13 change opened.** The byte budget added a `break`,
and `manifestListsSelf` described the bounded slice rather than the rows the
walk reached — so breaking before a later self-entry left the flag true,
suppressed the fallback, and skipped the mandatory frontmatter check
entirely. It is `selfAttempted` now, set inside the loop, and marked before
the read: a row the walk reached but could not read has still been attempted,
and its failure belongs to the loop rather than to a second fetch.

**A preview could overwrite a verification's own bytes.** The digest verdict
on screen was computed from the verification's fetch; replacing only the text
let the frontmatter findings describe different bytes, recreating the
mixed-fetch verdict that state exists to prevent. `entryTextVerified` marks
which read produced it, and a preview no longer wins over a verification.

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:
cliffhall 2026-09-07 22:58:19 -04:00
commit 5a1f0efb5a

View file

@ -718,6 +718,51 @@ describe("verifySkills (#2248)", () => {
);
});
it("runs the fallback when the byte budget broke the loop before the self row", async () => {
// `manifestListsSelf` described the bounded SLICE, not the rows reached —
// so a break on the byte budget left it true, suppressed the fallback, and
// skipped the mandatory frontmatter check entirely (Copilot).
const md = "---\nname: late\ndescription: Served\n---\n\n# late\n";
const big = "z".repeat(9 * 1024 * 1024);
const enc = new TextEncoder();
const skill: SkillEntry = {
uri: "skill://late/SKILL.md",
frontmatter: { name: "late", description: "Listed" },
resources: [
// Two oversized files cross the budget before the self row is reached.
{
uri: "skill://late/a.md",
digest: await sha256Digest(enc.encode(big)),
size: 1,
},
{
uri: "skill://late/b.md",
digest: await sha256Digest(enc.encode(big)),
size: 1,
},
{
uri: "skill://late/SKILL.md",
digest: await sha256Digest(enc.encode(md)),
size: enc.encode(md).byteLength,
},
],
};
const readResource = vi.fn(async (uri: string) => ({
result: {
contents: [{ uri, text: uri.endsWith("/SKILL.md") ? md : big }],
},
}));
const client = { readResource } as unknown as InspectorClientProtocol;
const [report] = await verifySkills(client, [skill]);
// The self file was still fetched, and its frontmatter still compared.
expect(readResource).toHaveBeenCalledWith(
"skill://late/SKILL.md",
undefined,
);
expect(report.frontmatter).toHaveLength(1);
expect(report.frontmatter[0].code).toBe("frontmatter-mismatch");
});
it("does not truncate a conforming manifest", async () => {
// A conforming skill totals at most 16 MiB by definition, so the bound
// must never shorten one — otherwise it would trade a hostile-server