fix: address Copilot review round 7 on #2251

- skills.ts: stop sorting `resources` arrays recursively. Only the entry's
  OWN manifest is a set; `frontmatter` is verbatim arbitrary JSON, so a
  custom `frontmatter.metadata.resources` array was being sorted too and
  two genuinely different frontmatters compared equal. The manifest sort is
  now done once, at the top level, and every other array keeps its order.
- SkillsScreen: invalidate on the whole selected entry, not just its
  manifest. The `skills/get` comparison covers `frontmatter`, so a refresh
  that changed only a description left a stale "matches skills/list"
  verdict on screen — computed against an entry that no longer existed.
  Re-verifying after a metadata-only refresh is the cheap direction to be
  wrong in; showing a match against a different entry is not.
- SkillsScreen: give each "Verify all" invocation a token, so a finalizer
  can only ever clear its own batch rather than any batch with a matching
  manifest key.
- SkillsScreen.stories: supply `onGetSkill`. Every story rendered the
  "Fetch with skills/get" button, and clicking it threw.

On the batch token: the A → B → A sequence the review describes is not
actually reachable, because the button is disabled whenever the in-flight
batch's key matches the selection — returning to A finds it disabled, not
clickable. The token is defence in depth for the same property, and the
test asserts what is really guaranteed rather than the unreachable path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018kfrH3uRNUM4JAk1reKtyY
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-09-04 23:36:35 -04:00
commit 1f33ba93be

View file

@ -615,6 +615,74 @@ describe("SkillsScreen", () => {
).toBeInTheDocument();
});
it("drops the skills/get verdict when a refresh changes only metadata", async () => {
// The manifest is untouched, so a manifest-only invalidation key would
// leave "matches" on screen even though it was computed against the
// previous entry — and that comparison covers `frontmatter` too.
const user = userEvent.setup();
const onGetSkill = vi.fn().mockResolvedValue(CLEAN_SKILL);
const { rerender } = renderWithMantine(
<SkillsScreen
{...baseProps}
skills={[CLEAN_SKILL]}
onGetSkill={onGetSkill}
ui={{ ...EMPTY_SKILLS_UI, selectedSkillUri: CLEAN_SKILL.uri }}
/>,
);
await user.click(
screen.getByRole("button", { name: /Fetch with skills\/get/ }),
);
expect(
await screen.findByText("skills/get matches skills/list"),
).toBeInTheDocument();
rerender(
<SkillsScreen
{...baseProps}
skills={[
{
...CLEAN_SKILL,
frontmatter: {
...CLEAN_SKILL.frontmatter,
description: "reworded since the fetch",
},
},
]}
onGetSkill={onGetSkill}
ui={{ ...EMPTY_SKILLS_UI, selectedSkillUri: CLEAN_SKILL.uri }}
/>,
);
expect(screen.queryByTestId("skills-get-result")).not.toBeInTheDocument();
});
it("keeps Verify all disabled on returning to a skill whose batch is still running", async () => {
// This is what actually blocks a second batch for one manifest: the button
// is disabled whenever the in-flight batch's key matches the selection, so
// A → B → A comes back to a disabled button rather than a second pool.
// (`batch` also carries a per-invocation token, so a finalizer can only
// ever clear its own batch — belt and braces for the same property.)
const user = userEvent.setup();
const onReadSkillFile = vi.fn(
() => new Promise<{ text: string }>(() => {}),
);
renderWithMantine(
<ControlledSkillsScreen onReadSkillFile={onReadSkillFile} />,
);
await user.click(screen.getByText("data-analysis"));
await user.click(screen.getByRole("button", { name: /Verify all/ }));
expect(screen.getByRole("button", { name: /Verify all/ })).toBeDisabled();
// B is free to run its own batch...
await user.click(screen.getByText("tampered"));
expect(
screen.getByRole("button", { name: /Verify all/ }),
).not.toBeDisabled();
// ...and returning to A finds its batch still in flight.
await user.click(screen.getByText("data-analysis"));
expect(screen.getByRole("button", { name: /Verify all/ })).toBeDisabled();
});
it("shows the SKILL.md preview on demand", async () => {
const user = userEvent.setup();
renderWithMantine(<ControlledSkillsScreen />);