Files
gbrain/test/check-resolvable.test.ts
T
32f8be96c2 v0.41.14.0 fix(#1451): close RESOLVER.md drift bug class structurally (#1458)
* feat(core): loadSkillTriggerIndex shared primitive (closes #1451 drift class)

Single loader that unions per-skill SKILL.md frontmatter triggers: with
curated RESOLVER.md / AGENTS.md rows. UNION semantics — explicit
RESOLVER.md rows ADD to frontmatter triggers for the same skill (don't
replace). Dedup keyed on (skillPath, normalized trigger string) so case
or whitespace drift between the two surfaces collapses to one entry.

This is the structural foundation for #1451: pre-fix, gbrain skills
declared triggers in two places (per-skill frontmatter and a curated
RESOLVER.md table) that could silently drift. Three consumers
(checkResolvable, routing-eval CLI, mounts-cache.composeResolvers) each
built their own resolver index from RESOLVER.md only, so fixing
frontmatter would have closed doctor's warning without closing the
other two surfaces. This primitive becomes the single join point for
all three; consumers are wired in the next commit.

Tests: 18 hermetic cases pinning frontmatter auto-registration,
RESOLVER.md/AGENTS.md merge, case-insensitive dedupe, OpenClaw
workspace-root layout (../AGENTS.md), graceful skip of conventions /
deprecated skills / non-directory entries / missing skillsDir, plus
synthesis round-trip and findPrimaryResolverPath.

Plan: ~/.claude/plans/system-instruction-you-are-working-tidy-storm.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor: wire 3 consumers through loadSkillTriggerIndex (#1451)

Replace the three independent resolver-content loaders with calls to
the v0.41.11 shared primitive so frontmatter triggers propagate to
every dispatch surface, not just doctor.

Before: checkResolvable, runRoutingEvalCli, and mounts-cache each
walked RESOLVER.md / AGENTS.md files separately. Adding frontmatter
triggers to one consumer (e.g. checkResolvable) wouldn't have reached
the routing-eval CLI or cross-brain composed dispatchers — the same
drift bug class as #1451 in cross-consumer form. Codex caught this in
plan-eng-review.

After: all three consumers fold through loadSkillTriggerIndex. UNION
semantics across both surfaces means new skills with frontmatter
triggers are reachable everywhere without editing RESOLVER.md.

Also updates:
- check-resolvable action text on routing_miss to point at the
  canonical surface (SKILL.md frontmatter triggers) first, with
  RESOLVER.md row as secondary.
- test/resolver-merge.test.ts to test BOTH the legacy
  RESOLVER.md-only authority path (skills with no frontmatter
  triggers) AND the new auto-registration path (skills reachable via
  frontmatter alone, no RESOLVER.md needed).
- 3 routing-eval.jsonl fixtures (voice-note-ingest, brain-taxonomist,
  strategic-reading) gain `ambiguous_with` declarations for skill
  overlaps that auto-registration newly exposes. These overlaps are
  legitimate (voice-note vs idea-ingest on audio notes,
  brain-taxonomist vs repo-architecture on filing, strategic-reading
  vs idea-ingest on reading-through-a-lens) — the agent picks based
  on context.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(#1451): broaden skillpack-harvest triggers + negative fixtures + tighten gate

Closes the 7 residual routing_miss warnings on skillpack-harvest that
gbrain doctor reported on every fresh install (resolver_health: WARN,
~5 health-score points).

Three changes:

1. Broaden skills/skillpack-harvest/SKILL.md frontmatter triggers from
   5 narrow to 10 realistic phrasings. Each new trigger is a
   contiguous substring of one of the 7 shipped routing-eval.jsonl
   intents (per kylma-code's design in PR #1331; moved from
   RESOLVER.md to frontmatter under the v0.41.11 frontmatter-
   authoritative contract). Existing RESOLVER.md row stays for
   human-readability of the dispatcher map.

2. Add 4 negative-fixture cases to skills/skillpack-harvest/
   routing-eval.jsonl with expected_skill=null to defend against
   false positives the broader triggers might introduce
   ("publish this report to the team", "promote my role on
   LinkedIn", "bundle these screenshots into a deck", "lift weights
   at the gym"). Two candidate negatives ("save this report as PDF",
   "share this article with the channel") were excluded — they trip
   idea-ingest's existing "save this"/"share" triggers, a real
   overlap but a separate v0.42+ concern.

3. Tighten test/check-resolvable.test.ts's "repo skills/ pass cleanly"
   assertion: the v0.25.1 carve-out that allowed routing_miss as
   informational is removed. The contract is back to zero errors AND
   zero warnings — the CI gate (next commit) enforces this for PRs
   so future drift fails the build instead of degrading user-install
   resolver_health silently.

Co-Authored-By: kylma-code <noreply@github.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(cli): register reindex in CLI_ONLY so --help works (closes part of #1354)

Pre-fix: src/cli.ts had a `case 'reindex':` handler at line 1334 that
dispatched to reindex-multimodal or reindex.ts based on flags, but
'reindex' was missing from the CLI_ONLY Set at line 38. The dispatcher
rejected the command with "Unknown command: reindex" before the handler
ever ran.

Post-fix: 'reindex' is in CLI_ONLY (recognized as a registered command).
NOT added to CLI_ONLY_SELF_HELP — the handler doesn't have its own
--help branch, so the dispatcher's generic printCliOnlyHelp() shows
"gbrain reindex - run gbrain --help for the full command list."
Polishing this to per-flag help text (--multimodal, --markdown, --code)
is a follow-up TODO.

Regression test in test/cli.test.ts asserts `'reindex'` is in the
CLI_ONLY Set source string. Mirrors the existing pattern for
'reinit-pglite' in test/v0_37_fix_wave.serial.test.ts:284 and
'book-mirror' in test/book-mirror.test.ts:73.

Cherry-picked from lost9999's PR #1354 (which bundled this fix with
their fixture-rewrite approach to #1451 — the routing-eval half of
that PR was superseded by kylma-code's trigger-broadening direction
in #1331, which we took structurally in the previous commits).

Co-Authored-By: lost9999 <noreply@github.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(ci): wire check:resolver into bun run verify

Adds `bun run check:resolver` (= `bun src/cli.ts check-resolvable
--strict --skills-dir skills/`) to package.json scripts and registers
it in scripts/run-verify-parallel.sh's CHECKS array.

This gates PR CI on resolver health: any future drift between a
skill's frontmatter triggers and its routing-eval.jsonl fixtures
fails the build, instead of silently degrading the resolver_health
score on user installs after merge. The --strict flag exits non-zero
on warnings (not just errors), so routing_miss / routing_ambiguous /
routing_false_positive all block.

Closes the CI half of #1451's structural fix: doctor catches drift
at runtime, this gate catches drift at PR time.

Local pre-flight: `bun run check:resolver`.

Codex finding #9 from plan review: scripts/run-verify-parallel.sh
invokes entries as `bun run <script-name>`, not raw shell. The
package.json script name + CHECKS-array entry is the correct shape.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(test): update CLI unreachable test for v0.41.11 contract change

The prior fixture used `triggers: ['alpha']` + `inResolver: false` to
simulate an unreachable skill. Under v0.41.11's structural fix,
frontmatter triggers auto-register the skill independently of
RESOLVER.md, so this skill is reachable now — the assertion
`errors.length > 0` failed.

Drop the `triggers:` array from the fixture so the skill is genuinely
unreachable (neither frontmatter nor RESOLVER.md row), preserving the
test's regression-guard intent: doctor/check-resolvable still exits 1
when a manifest skill is truly unreachable.

Caught by the full unit test suite after the merge.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs: CLAUDE.md Key Files note for skill-trigger-index + regen llms.txt

Document the v0.41.11 shared primitive (loadSkillTriggerIndex) in
the Key Files section so future contributors find it before they
reach for parseResolverEntries directly. Notes the 3 consumers
(checkResolvable, runRoutingEvalCli, mounts-cache.composeResolvers),
the UNION semantics, skip rules, parseSkillFrontmatter dependency,
test coverage, and the CI gate wiring.

Regenerated llms.txt + llms-full.txt per the CLAUDE.md edit rule.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* v0.41.14.0 fix(#1451): close RESOLVER.md drift bug class structurally

Frontmatter triggers + RESOLVER.md / AGENTS.md rows now union into one
unified index via the new loadSkillTriggerIndex primitive, consumed by
all three dispatch surfaces (checkResolvable, routing-eval CLI,
mounts-cache.composeResolvers). Closes the 7 residual routing_miss
warnings #1451 reported on every fresh install, and the drift bug class
that produced them.

Highlights:
- New shared primitive src/core/skill-trigger-index.ts (252 lines + 361
  lines of tests across 18 cases). UNION semantics, case-insensitive
  dedupe keyed on (skillPath, normalized trigger).
- Three consumers wired through the primitive — fixing frontmatter
  triggers for doctor now also fixes routing-eval CLI and
  cross-brain mounted dispatch (codex outside-voice catch).
- skillpack-harvest frontmatter broadened from 5 to 10 triggers per
  kylma-code's design in #1331, plus 4 negative-fixture cases for
  false-positive defense.
- reindex CLI added to CLI_ONLY set so `gbrain reindex --help` works
  instead of "Unknown command: reindex" (lost9999's #1354 hunk).
- check:resolver wired into bun run verify CI gate so future drift
  fails PR CI instead of silently degrading user-install
  resolver_health.
- check-resolvable's repo skills/ test tightened from "warn-tolerant"
  to "zero errors AND zero warnings" — the carve-out was a stop-gap
  pre-structural-fix.

Plan + 5 decisions + codex outside-voice recalibration captured at
~/.claude/plans/system-instruction-you-are-working-tidy-storm.md.

Co-Authored-By: kylma-code <noreply@github.com>
Co-Authored-By: lost9999 <noreply@github.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs: update project documentation for v0.41.14.0

- CLAUDE.md: tag skill-trigger-index entry with correct shipped version
  (v0.41.14.0, closes #1451) instead of the stale v0.41.11 draft tag.
- CONTRIBUTING.md: list the new `check:resolver` gate in the `bun run
  verify` chain so contributors know to expect resolver-drift failures
  in PR CI.
- llms-full.txt: regenerated from updated CLAUDE.md (mandatory per
  CLAUDE.md's auto-derived files rule; CI shard 1 fails the build
  otherwise).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: kylma-code <noreply@github.com>
2026-05-25 20:00:03 -07:00

420 lines
17 KiB
TypeScript

import { describe, test, expect } from "bun:test";
import { join } from "path";
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "fs";
import { tmpdir } from "os";
import {
checkResolvable,
parseResolverEntries,
extractDelegationTargets,
} from "../src/core/check-resolvable.ts";
const SKILLS_DIR = join(import.meta.dir, "..", "skills");
describe("parseResolverEntries", () => {
test("extracts skill paths from markdown table rows", () => {
const content = `## Brain operations
| Trigger | Skill |
|---------|-------|
| "What do we know about" | \`skills/query/SKILL.md\` |
| Creating a person page | \`skills/enrich/SKILL.md\` |`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(2);
expect(entries[0].skillPath).toBe("skills/query/SKILL.md");
expect(entries[0].section).toBe("Brain operations");
expect(entries[1].skillPath).toBe("skills/enrich/SKILL.md");
});
test("handles GStack entries (external skills)", () => {
const content = `## Thinking skills
| Trigger | Skill |
|---------|-------|
| "Brainstorm" | GStack: office-hours |`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(1);
expect(entries[0].isGStack).toBe(true);
});
test("handles identity/access rows (non-skill references)", () => {
const content = `## Identity
| Trigger | Skill |
|---------|-------|
| Non-owner sends a message | Check \`ACCESS_POLICY.md\` before responding |`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(1);
expect(entries[0].isGStack).toBe(true);
});
test("skips separator and header rows", () => {
const content = `| Trigger | Skill |
|---------|-------|
| "query" | \`skills/query/SKILL.md\` |`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(1);
});
test("tracks section headings", () => {
const content = `## Always-on
| Trigger | Skill |
|---------|-------|
| Every message | \`skills/signal-detector/SKILL.md\` |
## Brain operations
| Trigger | Skill |
|---------|-------|
| "What do we know" | \`skills/query/SKILL.md\` |`;
const entries = parseResolverEntries(content);
expect(entries[0].section).toBe("Always-on");
expect(entries[1].section).toBe("Brain operations");
});
// ──────────────────────────────────────────────────────────────────────
// v0.41.7.0 — Compact list-format support (OpenClaw-native shape)
//
// The list branch was added so `gbrain doctor` no longer reports every
// skill as unreachable on agents that write the compact `- **name**: t1 | t2`
// shape instead of the markdown table. The OpenClaw 306-skill regression
// was 238 FAIL errors → 0 errors after this fix.
// ──────────────────────────────────────────────────────────────────────
test("[list] bold-name single trigger", () => {
const content = `## Personal
- **gift-advisor**: gift idea`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(1);
expect(entries[0].trigger).toBe("gift idea");
expect(entries[0].skillPath).toBe("skills/gift-advisor/SKILL.md");
expect(entries[0].isGStack).toBe(false);
expect(entries[0].section).toBe("Personal");
});
test("[list] bold-name multi-trigger fan-out", () => {
const content = `- **flight-tracker**: track my flight | flight status | when does my flight land`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(3);
expect(entries.map(e => e.trigger)).toEqual([
"track my flight",
"flight status",
"when does my flight land",
]);
expect(entries.every(e => e.skillPath === "skills/flight-tracker/SKILL.md")).toBe(true);
});
test("[list] plain-name fallback (no bold markers)", () => {
const content = `- gift-advisor: gift idea | birthday gift`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(2);
expect(entries[0].skillPath).toBe("skills/gift-advisor/SKILL.md");
expect(entries[1].trigger).toBe("birthday gift");
});
test("[list] D3: path suffix with Unicode → is stripped, not captured", () => {
// D3 walkback: downstream consumers (routing-eval.ts skillSlugFromPath
// and check-resolvable.ts:367 manifest derivation) assume the
// skills/<name>/SKILL.md shape. Capturing the explicit path would
// produce silent orphan_trigger warnings + routing-eval coverage
// gaps for that skill. So the suffix is stripped and the path is
// always derived from the name.
const content = "- **quality**: lint the page → `skills/conventions/quality.md`";
const entries = parseResolverEntries(content);
expect(entries.length).toBe(1);
expect(entries[0].trigger).toBe("lint the page");
expect(entries[0].skillPath).toBe("skills/quality/SKILL.md"); // derived, NOT the captured path
});
test("[list] F4: path suffix with ASCII -> is also stripped", () => {
const content = "- **quality**: lint the page -> `skills/conventions/quality.md`";
const entries = parseResolverEntries(content);
expect(entries.length).toBe(1);
expect(entries[0].trigger).toBe("lint the page");
expect(entries[0].skillPath).toBe("skills/quality/SKILL.md");
});
test("[list] ellipsis placeholder is dropped", () => {
const content = `- **foo-skill**: bar | ... | baz`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(2);
expect(entries.map(e => e.trigger)).toEqual(["bar", "baz"]);
});
test("[list] empty pipe segments are dropped", () => {
const content = `- **foo-skill**: bar | | baz`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(2);
expect(entries.map(e => e.trigger)).toEqual(["bar", "baz"]);
});
test("[mixed] table and list rows in the same file", () => {
const content = `## Always-on
| Trigger | Skill |
|---------|-------|
| Every message | \`skills/signal-detector/SKILL.md\` |
## Personal
- **gift-advisor**: gift idea | what should I bring`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(3);
expect(entries[0].skillPath).toBe("skills/signal-detector/SKILL.md");
expect(entries[0].section).toBe("Always-on");
expect(entries[1].skillPath).toBe("skills/gift-advisor/SKILL.md");
expect(entries[1].section).toBe("Personal");
expect(entries[2].section).toBe("Personal");
});
test("[list] section tracking across list entries", () => {
const content = `## Personal
- **gift-advisor**: gift idea
## Travel
- **flight-tracker**: track my flight`;
const entries = parseResolverEntries(content);
expect(entries[0].section).toBe("Personal");
expect(entries[1].section).toBe("Travel");
});
test("[list] D4 REGRESSION: prose bullets do not match as skill rows", () => {
// The kebab-lowercase name regex deliberately rejects bold names
// starting with an uppercase letter. This kills the noise class where
// real AGENTS.md files have prose bullets like `- **Note**: …` that
// would otherwise be parsed as fake skill rows pointing at
// `skills/Note/SKILL.md`. Codex F2; D4 decision.
const content = `- **Note**: this is a prose bullet
- **Convention**: see [some convention link]
- **TODO**: fix this later
- **Important**: read this carefully`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(0);
});
test("[list] D4 negative: convention-violating uppercase names are silently skipped", () => {
// Documents the trade: a real skill named `MyTool` would not parse.
// The user would notice on the first `gbrain doctor` run and lowercase it.
const content = `- **MyTool**: this trigger silently disappears
- **camelCase**: also silently dropped`;
const entries = parseResolverEntries(content);
expect(entries.length).toBe(0);
});
});
describe("checkResolvable — real skills directory", () => {
const report = checkResolvable(SKILLS_DIR);
test("produces a report with summary", () => {
expect(report.summary.total_skills).toBeGreaterThan(0);
expect(typeof report.ok).toBe("boolean");
expect(Array.isArray(report.issues)).toBe(true);
});
test("all manifest skills are reachable from RESOLVER.md", () => {
const unreachableIssues = report.issues.filter(i => i.type === "unreachable");
if (unreachableIssues.length > 0) {
const names = unreachableIssues.map(i => i.skill).join(", ");
console.warn(`Unreachable skills: ${names}`);
}
// Currently expect all 24 skills to be reachable
expect(report.summary.unreachable).toBe(0);
});
test("no missing files referenced by RESOLVER.md", () => {
const missingFiles = report.issues.filter(i => i.type === "missing_file");
expect(missingFiles.length).toBe(0);
});
test("no orphan triggers (in resolver but not manifest)", () => {
const orphans = report.issues.filter(i => i.type === "orphan_trigger");
expect(orphans.length).toBe(0);
});
test("action strings are specific (contain file paths)", () => {
for (const issue of report.issues) {
expect(issue.action.length).toBeGreaterThan(10);
// Action should mention a file or a specific fix
expect(
issue.action.includes("RESOLVER.md") ||
issue.action.includes("SKILL.md") ||
issue.action.includes("manifest") ||
issue.action.includes("conventions/")
).toBe(true);
}
});
test("unreachable issues have structured fix objects", () => {
const unreachable = report.issues.filter(i => i.type === "unreachable");
for (const issue of unreachable) {
expect(issue.fix).toBeDefined();
expect(issue.fix!.type).toBe("add_trigger");
expect(issue.fix!.file).toContain("RESOLVER.md");
}
});
test("whitelisted skills (ingest, signal-detector, brain-ops) don't trigger MECE overlap", () => {
const overlaps = report.issues.filter(i => i.type === "mece_overlap");
for (const issue of overlaps) {
// The skill field lists the overlapping skills
expect(issue.skill).not.toContain("signal-detector");
expect(issue.skill).not.toContain("brain-ops");
}
});
test("summary counts are consistent", () => {
expect(report.summary.reachable + report.summary.unreachable).toBe(report.summary.total_skills);
});
});
// ---------------------------------------------------------------------------
// DRY detection — proximity-based suppression
// ---------------------------------------------------------------------------
function makeSkillsFixture(files: Record<string, string>): string {
const dir = mkdtempSync(join(tmpdir(), "gbrain-dry-"));
// Minimal RESOLVER.md and manifest.json so checkResolvable doesn't bail.
const skillNames = Object.keys(files);
const resolverRows = skillNames.map(n => `| "${n}" | \`skills/${n}/SKILL.md\` |`).join("\n");
writeFileSync(join(dir, "RESOLVER.md"), `## Test\n| Trigger | Skill |\n|-----|-----|\n${resolverRows}\n`);
writeFileSync(
join(dir, "manifest.json"),
JSON.stringify({ skills: skillNames.map(n => ({ name: n, path: `${n}/SKILL.md` })) }, null, 2)
);
for (const [name, body] of Object.entries(files)) {
mkdirSync(join(dir, name), { recursive: true });
// Skill conformance tests (elsewhere) check for frontmatter + triggers;
// checkResolvable itself only needs the body.
const frontmatter = `---\nname: ${name}\ndescription: test\ntriggers:\n - "${name}"\n---\n`;
writeFileSync(join(dir, name, "SKILL.md"), frontmatter + body);
}
return dir;
}
describe("extractDelegationTargets", () => {
test("parses > **Convention:** callouts", () => {
const refs = extractDelegationTargets(
"> **Convention:** See `skills/conventions/quality.md` for citation rules.\n"
);
expect(refs).toEqual([{ convention: "conventions/quality.md", line: 1 }]);
});
test("parses > **Filing rule:** callouts", () => {
const refs = extractDelegationTargets(
"> **Filing rule:** Read `skills/_brain-filing-rules.md` before any new page.\n"
);
expect(refs).toEqual([{ convention: "_brain-filing-rules.md", line: 1 }]);
});
test("parses inline backtick references", () => {
const refs = extractDelegationTargets(
"some prose.\nSee `skills/conventions/quality.md` for details.\n"
);
expect(refs).toEqual([{ convention: "conventions/quality.md", line: 2 }]);
});
test("ignores backticks pointing outside known delegation targets", () => {
const refs = extractDelegationTargets(
"See `skills/random/README.md` for unrelated notes.\n"
);
expect(refs).toHaveLength(0);
});
test("handles frontmatter-only skill (no body matches)", () => {
const refs = extractDelegationTargets("---\nname: foo\n---\n");
expect(refs).toHaveLength(0);
});
});
describe("DRY detection — checkResolvable", () => {
let dir: string;
afterEachCleanup(() => dir && rmSync(dir, { recursive: true, force: true }));
test("flags inlined notability rule with no reference", () => {
dir = makeSkillsFixture({
bad: "# BadSkill\n\nCheck the notability gate every time.\n",
});
const report = checkResolvable(dir);
const dry = report.issues.filter(i => i.type === "dry_violation");
expect(dry).toHaveLength(1);
expect(dry[0].skill).toBe("bad");
});
test("suppresses DRY when > **Convention:** callout points at quality.md (notability)", () => {
dir = makeSkillsFixture({
good: `# GoodSkill\n\n> **Convention:** See \`skills/conventions/quality.md\` for rules.\n\nCheck the notability gate.\n`,
});
const report = checkResolvable(dir);
const dry = report.issues.filter(i => i.type === "dry_violation");
expect(dry).toHaveLength(0);
});
test("suppresses DRY when _brain-filing-rules.md is referenced for notability", () => {
dir = makeSkillsFixture({
good: `# GoodSkill\n\n> **Filing rule:** Read \`skills/_brain-filing-rules.md\`.\n\nCheck the notability gate.\n`,
});
const report = checkResolvable(dir);
const dry = report.issues.filter(i => i.type === "dry_violation");
expect(dry).toHaveLength(0);
});
test("does NOT suppress when reference is >40 lines from the match", () => {
const filler = Array(50).fill("padding paragraph with no match.").join("\n");
dir = makeSkillsFixture({
distant: `> **Convention:** See \`skills/conventions/quality.md\`.\n\n${filler}\n\nCheck the notability gate now.\n`,
});
const report = checkResolvable(dir);
const dry = report.issues.filter(i => i.type === "dry_violation");
expect(dry).toHaveLength(1);
});
test("DOES suppress when reference is ~30 lines from the match", () => {
const filler = Array(20).fill("padding paragraph with no match.").join("\n");
dir = makeSkillsFixture({
near: `> **Convention:** See \`skills/conventions/quality.md\`.\n\n${filler}\n\nCheck the notability gate now.\n`,
});
const report = checkResolvable(dir);
const dry = report.issues.filter(i => i.type === "dry_violation");
expect(dry).toHaveLength(0);
});
test("iron-law pattern does NOT accept _brain-filing-rules.md as delegation", () => {
// iron-law's only accepted target is conventions/quality.md
dir = makeSkillsFixture({
filing: `> **Filing rule:** Read \`skills/_brain-filing-rules.md\`.\n\n## Iron Law: Back-Linking (MANDATORY)\n`,
});
const report = checkResolvable(dir);
const dry = report.issues.filter(i => i.type === "dry_violation");
expect(dry.length).toBeGreaterThanOrEqual(1);
});
});
describe("v0.22.4 regression — actual repo skills/ has 0 errors", () => {
test("repo skills/ pass check-resolvable cleanly (zero errors AND zero warnings)", () => {
// The v0.22.4 (Part A) contract was zero warnings AND zero errors.
// The v0.25.1 update relaxed it to allow `routing_miss` warnings as
// informational — a stop-gap because the structural matcher
// required substring-match against narrow triggers in RESOLVER.md
// and natural paraphrases legitimately missed.
//
// v0.41.11 #1451 closes the drift bug class structurally:
// frontmatter triggers + RESOLVER.md rows merge with UNION
// semantics via `loadSkillTriggerIndex`. The 7 residual
// `routing_miss` warnings on skillpack-harvest (and any future
// drift on other skills) MUST be addressed at write time, not
// tolerated at test time. The CI gate `bun run check:resolver`
// (--strict, exit-1 on any warning) enforces this for PRs.
//
// The test now asserts the FULL contract: zero errors, zero
// warnings. If a routing_miss reappears, the fix is to broaden
// the skill's frontmatter `triggers:` so the realistic fixture
// intent contains a trigger substring.
const report = checkResolvable(SKILLS_DIR);
const errors = report.issues.filter(i => i.severity === "error");
const warnings = report.issues.filter(i => i.severity === "warning");
expect(errors).toEqual([]);
expect(warnings).toEqual([]);
});
});
// bun:test has no beforeEach/afterEach at module scope cleanly interacting
// with closures; a small helper keeps cleanup readable and per-test.
function afterEachCleanup(fn: () => void) {
const { afterEach } = require("bun:test");
afterEach(fn);
}