Repository navigation
fix(skills): report YAML frontmatter parse errors and serialize SKILL.md safely #1321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e9eed2e
55d95f5
d4f2ca3
872179d
6c2e44e
928f3bf
987fa9a
65a0ff3
ae9b80a
5153db6
3c652b2
a5cb89e
e91e586
a3f0dd9
ce9297e
b19eeb3
6e683f9
4dcc369
6615cc4
b4c059b
ea343e7
40de142
7e12ca4
7521958
c26661b
bf9d91f
ab15ab2
870efed
8ba903a
691d79f
7163cfd
304c647
3f0010f
2901935
30e0e01
08b2447
1100ade
ca68406
741a280
38844c7
f3fff45
7301b4d
bc96d5b
0ee05df
fe5498b
f166724
3b2d872
2a25a2b
46bc5d2
9e287f6
8cf3030
9714d1f
17b2689
9b6dc1a
6b59564
5046115
0637006
7449df1
e25910c
6f29d73
b5bbd12
c0a445b
bbf3917
098d789
a0639af
b8271cb
4c6aa03
f373d54
168162c
ee761d3
83cdf67
da3e16e
58e6705
bbe8d03
259003f
3bd350f
bd1c590
3bb84b0
e232bf7
24558e7
0501ad1
5be4bb2
ffe19c1
a4d588e
5eb6bbe
d0f837c
ee3062f
05297f0
4b77cd2
4f5faf4
515ac40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import * as assert from "assert" | ||
| import * as fs from "fs/promises" | ||
| import * as path from "path" | ||
|
|
||
| import * as vscode from "vscode" | ||
|
|
||
| import { setDefaultSuiteTimeout } from "./test-utils" | ||
| import { waitFor } from "./utils" | ||
|
|
||
| const GOOD_SKILL = "e2e-skill-good" | ||
| const BAD_SKILL = "e2e-skill-bad" | ||
|
|
||
| // Issue #859 reproduction content: the description is a double-quoted YAML | ||
| // scalar whose inner double quotes are left unescaped, which makes the | ||
| // frontmatter unparseable. | ||
| const MALFORMED_SKILL_MD = `--- | ||
| name: ${BAD_SKILL} | ||
| description: "Use when implementing features. Triggers on: "TDD", "test-driven development" | ||
| --- | ||
|
|
||
| # E2E Skill Bad | ||
|
|
||
| Instructions here. | ||
| ` | ||
|
|
||
| const FIXED_SKILL_MD = `--- | ||
| name: ${BAD_SKILL} | ||
| description: 'Use when implementing features. Triggers on: "TDD", "test-driven development"' | ||
| --- | ||
|
|
||
| # E2E Skill Bad | ||
|
|
||
| Instructions here. | ||
| ` | ||
|
|
||
| const GOOD_SKILL_MD = `--- | ||
| name: ${GOOD_SKILL} | ||
| description: A healthy skill used by the skill diagnostics e2e smoke test. | ||
| --- | ||
|
|
||
| # E2E Skill Good | ||
|
|
||
| Instructions here. | ||
| ` | ||
|
|
||
| // Write a skill file atomically (write to a sidecar, then rename over the | ||
| // target) so the extension host's file watcher only ever observes complete | ||
| // content. An in-place fs.writeFile is visible mid-write, the watcher can | ||
| // fire for that moment, and - because discovery scans are serialized - a | ||
| // mid-write event could be the last one, leaving a stale scan result. | ||
| const writeSkillFileAtomic = async (finalPath: string, content: string): Promise<void> => { | ||
| const tmpPath = `${finalPath}.tmp` | ||
| await fs.writeFile(tmpPath, content, "utf8") | ||
| await fs.rename(tmpPath, finalPath) | ||
| } | ||
|
|
||
| suite("Roo Code Skill Diagnostics", function () { | ||
| setDefaultSuiteTimeout(this) | ||
|
|
||
| let skillsRoot: string | ||
|
|
||
| setup(async function () { | ||
| const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath | ||
| assert.ok(workspaceRoot, "e2e workspace folder must be open") | ||
| skillsRoot = path.join(workspaceRoot, ".roo", "skills") | ||
| }) | ||
|
|
||
| teardown(async function () { | ||
| // Remove only the skill directories this suite created so pre-existing | ||
| // or other suites' fixtures under .roo/skills are left intact. | ||
| await Promise.all( | ||
| [GOOD_SKILL, BAD_SKILL].map((name) => fs.rm(path.join(skillsRoot, name), { recursive: true, force: true })), | ||
| ) | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| test("should surface a malformed SKILL.md as a diagnostic without hiding healthy skills", async function () { | ||
| this.timeout(180_000) | ||
|
|
||
| // Arrange: one healthy skill and one malformed skill on real disk in the | ||
| // workspace's .roo/skills directory, written atomically so the watcher | ||
| // only observes complete files. | ||
| await fs.mkdir(path.join(skillsRoot, GOOD_SKILL), { recursive: true }) | ||
| await writeSkillFileAtomic(path.join(skillsRoot, GOOD_SKILL, "SKILL.md"), GOOD_SKILL_MD) | ||
| await fs.mkdir(path.join(skillsRoot, BAD_SKILL), { recursive: true }) | ||
| const badSkillMd = path.join(skillsRoot, BAD_SKILL, "SKILL.md") | ||
| await writeSkillFileAtomic(badSkillMd, MALFORMED_SKILL_MD) | ||
|
|
||
| // Act: the extension host's file watcher re-discovers skills; wait until | ||
| // the real SkillsManager reports the healthy skill and a diagnostic for | ||
| // the malformed one. | ||
| await waitFor( | ||
| async () => { | ||
| const state = globalThis.api.getSkillsState() | ||
| const goodVisible = state.skills.some((skill) => skill.name === GOOD_SKILL) | ||
| const badDiagnosed = state.skillDiagnostics.some((diagnostic) => diagnostic.path.includes(BAD_SKILL)) | ||
| return goodVisible && badDiagnosed | ||
| }, | ||
| { timeout: 60_000, interval: 500 }, | ||
| ) | ||
|
|
||
| // Assert: the malformed skill is skipped with a diagnostic pointing at it, | ||
| // while the healthy skill is unaffected. | ||
| const state = globalThis.api.getSkillsState() | ||
| const diagnostic = state.skillDiagnostics.find((d) => d.path.includes(BAD_SKILL)) | ||
| assert.ok(diagnostic, "malformed SKILL.md should produce a diagnostic") | ||
| assert.strictEqual(diagnostic.source, "project") | ||
| assert.ok(diagnostic.message.length > 0, "diagnostic should carry the parse error message") | ||
| assert.ok( | ||
| state.skills.some((skill) => skill.name === GOOD_SKILL), | ||
| "healthy skill should still be discovered", | ||
| ) | ||
| assert.ok( | ||
| !state.skills.some((skill) => skill.name === BAD_SKILL), | ||
| "malformed skill should be omitted from skills", | ||
| ) | ||
|
|
||
| // Act: repair the frontmatter in place (atomically); the watcher | ||
| // re-discovers and the diagnostic clears. | ||
| await writeSkillFileAtomic(badSkillMd, FIXED_SKILL_MD) | ||
|
|
||
| await waitFor( | ||
| async () => { | ||
| const next = globalThis.api.getSkillsState() | ||
| const cleared = !next.skillDiagnostics.some((d) => d.path.includes(BAD_SKILL)) | ||
| const loaded = next.skills.some((skill) => skill.name === BAD_SKILL) | ||
| return cleared && loaded | ||
| }, | ||
| { timeout: 60_000, interval: 500 }, | ||
| ) | ||
|
|
||
| const fixed = globalThis.api.getSkillsState() | ||
| assert.ok( | ||
| fixed.skills.some((skill) => skill.name === BAD_SKILL), | ||
| "fixed skill should load after repair", | ||
| ) | ||
| assert.ok(fixed.skills.find((skill) => skill.name === BAD_SKILL)?.description.includes("TDD") === true) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| SPECIFICATION Spec | ||
| CONSTANTS | ||
| KeyDomain = {"description", "de*s", "(a)+"} | ||
| LineDomain = {"description: x", "description : y", "de*s: w", "(a)+: v", "name: n"} | ||
| Mode = "Unescaped" | ||
| INVARIANT NoBroadening | ||
| INVARIANT RawKeyBroadensMatch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| SPECIFICATION Spec | ||
| CONSTANTS | ||
| KeyDomain = {"description", "de*s", "(a)+"} | ||
| LineDomain = {"description: x", "description : y", "de*s: w", "(a)+: v", "name: n"} | ||
| Mode = "Escaped" | ||
| INVARIANT NoBroadening | ||
| INVARIANT RawKeyBroadensMatch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| ---- MODULE FrontmatterKeyMatch ---- | ||
| \* Loop-2 of PR #1321 (review thread PRRT_kwDOSK-bwM7ACALw, CWE-1333). The key | ||
| \* argument of getFrontmatterLine (src/services/skills/SkillsManager.ts) is | ||
| \* interpolated into the RegExp that picks the frontmatter line the diagnostic | ||
| \* quotes. Source: the key argument. Sink: the per-line pattern test. | ||
| \* | ||
| \* Failure the change must prevent (one sentence): a key carrying regex | ||
| \* metacharacters, interpolated unescaped, matches frontmatter lines the caller | ||
| \* did not name - and with a nested-quantifier key can backtrack catastrophically. | ||
| \* | ||
| \* Step 1 search: Frontmatter.tla models the sibling sink (the parseFrontmatter | ||
| \* engine guard in src/utils/safeFrontmatter.ts); its source and sink differ | ||
| \* (header language vs line selection), so this is a new module, not an extension. | ||
| \* UrlRedaction.tla is the same shape (regex construction, Variant constant) and | ||
| \* supplies the oracle idiom: an unconstrained variable, not a set-union operator. | ||
| \* | ||
| \* Invariants: NoBroadening (the matcher in use agrees with the literal-prefix | ||
| \* contract: literal key, optional whitespace, colon) and RawKeyBroadensMatch | ||
| \* (the unescaped interpolation admits a decoy line). Mode selects the matcher: | ||
| \* "Escaped" = the fixed construction, "Unescaped" = the pre-fix construction | ||
| \* (the sabotage run). Spelled "Unescaped", not "Raw": TLC 2.19 rejects the cfg | ||
| \* string value "Raw" with a misleading "did not specify the initial state | ||
| \* predicate" error (probed: RAW/raw/RawX fine, "Raw" not). | ||
| \* | ||
| \* Expect BEFORE the run: NoBroadening holds for Mode="Escaped" (the matcher is | ||
| \* the literal-prefix contract by construction); the UnescapedMode variant fails | ||
| \* NoBroadening when the oracle raw agrees with a decoy line; RawKeyBroadensMatch | ||
| \* holds for "Unescaped" and is vacuous for "Escaped" (recorded, not hidden). The | ||
| \* backtracking half of the finding is not TLC-able (no time model); the escape | ||
| \* rule removes both halves at pattern construction. | ||
| \* Result AFTER: base config passes in 32,768 states (2^15 oracle assignments); | ||
| \* the UnescapedMode variant fails NoBroadening - counterexample: raw agrees TRUE | ||
| \* with a decoy pair (e.g. ("de*s", "description: x")), a line whose literal | ||
| \* prefix is not the key; RawKeyBroadensMatch holds by domain in both configs. | ||
| \* | ||
| \* Review ratchet: covered = NoBroadening (PR 1321 thread PRRT_kwDOSK-bwM7ACALw); | ||
| \* added = RawKeyBroadensMatch; gap = 0 expressible gaps; the backtracking half | ||
| \* is a named gap (not expressible without a time model), covered by the escape | ||
| \* rule itself and the mutation gate on the same lines. | ||
| \* | ||
| \* Property test: SkillsManager.spec.ts row "whitespace before the colon" keeps | ||
| \* the quote hint - the literal-prefix contract on the real code path. | ||
| \* Not modeled: the YAML parser, the file reader, i18n rendering. | ||
| \* Cost: TLC runs in under 1 second per config. Agent time is not measured. | ||
| EXTENDS Sequences, Integers | ||
|
|
||
| CONSTANTS KeyDomain, LineDomain, Mode | ||
|
|
||
| ASSUME ModeAssumption == | ||
| Mode \in {"Unescaped", "Escaped"} | ||
|
|
||
| VARIABLES raw | ||
|
|
||
| \* Literal key, optional whitespace, colon: the sink contract the escape fixes. | ||
| WS == {"", " ", " "} | ||
| LiteralPrefix(k, l) == | ||
| \E ws \in WS : | ||
| Len(l) >= Len(k) + Len(ws) + 1 | ||
| /\ SubSeq(l, 1, Len(k)) = k | ||
| /\ SubSeq(l, Len(k) + 1, Len(k) + Len(ws)) = ws | ||
| /\ SubSeq(l, Len(k) + Len(ws) + 1, Len(k) + Len(ws) + 1) = ":" | ||
|
|
||
| \* The oracle: the unescaped interpolation agrees per line with any result | ||
| \* (unconstrained variable, the UrlRedaction idiom). TLC tries every result. | ||
| MatchUsed(k, l) == IF Mode = "Unescaped" THEN raw[k, l] ELSE LiteralPrefix(k, l) | ||
|
|
||
| Init == raw \in [KeyDomain \X LineDomain -> BOOLEAN] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Record a replayable sabotage counterexample.
Thus, the variant fails even though its input domain contains no real broadening example. Add a replayable line, such as As per coding guidelines, “Replay each counterexample on the real code. Keep the counterexamples that leak. Record the false alarms.”
|
||
| Next == UNCHANGED raw | ||
| vars == <<raw>> | ||
| Spec == Init /\ [][Next]_vars | ||
|
|
||
| \* Safety: the matcher in use never agrees beyond the literal-prefix contract. | ||
| NoBroadening == | ||
| \A k \in KeyDomain, l \in LineDomain : MatchUsed(k, l) => LiteralPrefix(k, l) | ||
|
|
||
| \* Ratchet: the broadening the review finding names is realizable in the domain: | ||
| \* some (key, line) pair is a decoy, so the unescaped pattern can agree with it. | ||
| \* Holds by domain in both modes; its teeth show in the UnescapedMode variant, | ||
| \* where NoBroadening fails on the same pair. | ||
| RawKeyBroadensMatch == | ||
| \E k \in KeyDomain, l \in LineDomain : ~LiteralPrefix(k, l) | ||
|
Comment on lines
+80
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate domain coverage from matcher broadening. When every This predicate checks only that the domain contains a non-prefix pair. It does not check the matcher behavior stated in the header. Rename it to describe domain coverage and correct the header. If matcher broadening needs a separate check, require an accepted non-prefix witness.
|
||
| ==== | ||
Uh oh!
There was an error while loading. Please reload this page.