Skip to content

Commit ae9b80a

Browse files
committed
test(webview): cover the remaining skill diagnostics patch lines
Closes the codecov/patch/webview-patch gap (4 not-fully-covered lines): - ExtensionStateContext.spec.tsx: dispatch real "skills" messages through the provider and assert skills/skillDiagnostics update, including the empty-array default when the message omits skillDiagnostics. - SkillsSettings.spec.tsx: render without skillDiagnostics in state (the exact shape that used to crash) and render diagnostics with and without line/column locations so every branch of the location formatting is exercised. Local: both specs 45/45 passing; lcov confirms all patch lines and branches in both files are taken.
1 parent 65a0ff3 commit ae9b80a

2 files changed

Lines changed: 109 additions & 0 deletions

File tree

‎webview-ui/src/components/settings/__tests__/SkillsSettings.spec.tsx‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,42 @@ describe("SkillsSettings", () => {
217217
expect(screen.getByText("global-skill")).toBeInTheDocument()
218218
})
219219

220+
it("does not show the malformed-skill warning when skillDiagnostics is absent from state", () => {
221+
mockExtensionState = {
222+
skills: mockSkills,
223+
cwd: "/workspace",
224+
customModes: [],
225+
}
226+
227+
renderWithExtensionState(<SkillsSettings />)
228+
229+
expect(screen.queryByRole("alert")).not.toBeInTheDocument()
230+
expect(screen.getByText("settings:sections.skills")).toBeInTheDocument()
231+
expect(screen.getByText("project-skill")).toBeInTheDocument()
232+
})
233+
234+
it("renders diagnostics with and without line/column locations", () => {
235+
renderSkillsSettings(mockSkills, undefined, [
236+
{
237+
path: "/workspace/.roo/skills/broken-2/SKILL.md",
238+
source: "project",
239+
message: "unexpected end of the stream",
240+
},
241+
{
242+
path: "/workspace/.roo/skills/broken-3/SKILL.md",
243+
source: "project",
244+
message: "bad indentation of a mapping entry",
245+
line: 7,
246+
},
247+
])
248+
249+
const warning = screen.getByRole("alert")
250+
expect(warning).toHaveTextContent("/workspace/.roo/skills/broken-2/SKILL.md")
251+
expect(warning).toHaveTextContent("unexpected end of the stream")
252+
expect(warning).toHaveTextContent("/workspace/.roo/skills/broken-3/SKILL.md:7")
253+
expect(warning).toHaveTextContent("bad indentation of a mapping entry")
254+
})
255+
220256
it("displays project skills section when in a workspace", () => {
221257
renderSkillsSettings()
222258

‎webview-ui/src/context/__tests__/ExtensionStateContext.spec.tsx‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ const RulesTestComponent = () => {
4040
return <div data-testid="rules">{JSON.stringify(rules)}</div>
4141
}
4242

43+
const SkillsTestComponent = () => {
44+
const { skills, skillDiagnostics } = useExtensionState()
45+
46+
return (
47+
<div>
48+
<div data-testid="skills">{JSON.stringify(skills)}</div>
49+
<div data-testid="skill-diagnostics">{JSON.stringify(skillDiagnostics)}</div>
50+
</div>
51+
)
52+
}
53+
4354
const ChatFontSizeTestComponent = () => {
4455
const { chatFontSize, setChatFontSize } = useExtensionState()
4556

@@ -192,6 +203,68 @@ describe("ExtensionStateContext", () => {
192203
expect(JSON.parse(screen.getByTestId("rules").textContent!)).toEqual([])
193204
})
194205

206+
it("updates skills and skill diagnostics from incoming skills message", () => {
207+
render(
208+
<ExtensionStateContextProvider>
209+
<SkillsTestComponent />
210+
</ExtensionStateContextProvider>,
211+
)
212+
213+
act(() => {
214+
window.dispatchEvent(
215+
new MessageEvent("message", {
216+
data: {
217+
type: "skills",
218+
skills: [
219+
{
220+
name: "good-skill",
221+
description: "A healthy skill",
222+
path: "/workspace/.roo/skills/good-skill/SKILL.md",
223+
source: "project",
224+
},
225+
],
226+
skillDiagnostics: [
227+
{
228+
path: "/workspace/.roo/skills/bad-skill/SKILL.md",
229+
source: "project",
230+
message: "bad indentation of a mapping entry",
231+
line: 3,
232+
},
233+
],
234+
},
235+
}),
236+
)
237+
})
238+
239+
expect(JSON.parse(screen.getByTestId("skills").textContent!)).toEqual([
240+
expect.objectContaining({ name: "good-skill" }),
241+
])
242+
expect(JSON.parse(screen.getByTestId("skill-diagnostics").textContent!)).toEqual([
243+
expect.objectContaining({ path: "/workspace/.roo/skills/bad-skill/SKILL.md", line: 3 }),
244+
])
245+
})
246+
247+
it("defaults skill diagnostics to an empty array when the skills message omits them", () => {
248+
render(
249+
<ExtensionStateContextProvider>
250+
<SkillsTestComponent />
251+
</ExtensionStateContextProvider>,
252+
)
253+
254+
act(() => {
255+
window.dispatchEvent(
256+
new MessageEvent("message", {
257+
data: {
258+
type: "skills",
259+
skills: [],
260+
},
261+
}),
262+
)
263+
})
264+
265+
expect(JSON.parse(screen.getByTestId("skill-diagnostics").textContent!)).toEqual([])
266+
})
267+
195268
it("initializes with soundEnabled set to false", () => {
196269
render(
197270
<ExtensionStateContextProvider>

0 commit comments

Comments
 (0)