ci: add pre-commit hook and CI validation for generated skill rules#148
ci: add pre-commit hook and CI validation for generated skill rules#148avivsinai merged 4 commits intoavivsinai:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
avivsinai
left a comment
There was a problem hiding this comment.
Correct staleness check — rulesDir derivation matches, SKILL.md copied into $TMPDIR before regen (matches generator contract at internal/docgen/generate.go:80), trap-based cleanup is solid.
One thing worth fixing: scripts/check-generated-skill.sh:19 — drop the 2>/dev/null on go run ./cmd/docgen. It suppresses the real generator failure. With set -e, if docgen can't build or errors at runtime, the script aborts opaquely with no useful output — reproduced by running the script with go missing from PATH: exit 127, nothing on stderr, nothing telling the dev what actually broke. Drop the redirect or capture stderr to a log that's dumped on failure.
Nits (take or leave):
diff -rqruns twice in the failure path (script:22,37) — single invocation into a var.❌emoji in error output — project CLAUDE.md discourages; plainERROR:is more portable across CI log viewers..pre-commit-config.yaml:22— consider addingMakefile+ the script itself to thefiles:pattern so gen-plumbing edits also trigger re-verification..github/workflows/ci.yml:24— newsetup-gostep has no module cache; existingbuildjob should share it.
Happy to approve once the 2>/dev/null is dropped.
Add staleness detection so generated skill rules stay in sync with the Cobra command tree: - scripts/check-generated-skill.sh: regenerates rules into a temp dir and diffs against committed files; also validates the SKILL.md References section - Makefile: add check-generated-skill target - .pre-commit-config.yaml: local hook triggers on changes to pkg/cmd/, cmd/docgen/, internal/docgen/, or skills/bkt/ - .github/workflows/ci.yml: check-skills job now also runs check-generated-skill with Go toolchain This is PR 4 of 4 in the auto-generate skill series: 1. Add detailed docstrings to all commands (merged) 2. Generator core + make generate-skill (merged) 3. Generated rules, SKILL.md rewrite (merged) 4. (this) Pre-commit hook + CI validation for staleness detection
bf10a9a to
1884fcc
Compare
- Drop 2>/dev/null on docgen invocation to surface real failures - Deduplicate diff -rq into a single variable - Replace emoji with ERROR: prefix for CI log portability - Ignore manually authored rule files (e.g. headless.md) in staleness check - Normalize trailing whitespace for end-of-file-fixer compatibility - Add Makefile and script to pre-commit trigger pattern - Regenerate skill rules
|
Addressed all points:
Additional fixes in the same commit:
|
avivsinai
left a comment
There was a problem hiding this comment.
Blocking issue in scripts/check-generated-skill.sh:23-31.
The new staleness check only iterates over $TMPDIR/rules/*.md, so it catches missing/generated mismatches for files docgen currently emits, but it never notices extra committed auto-generated files that docgen would remove.
Why this matters:
docgen.GenerateAllexplicitly deletes stale generated markdown files before regenerating (internal/docgen/generate.go:149-173).- There is already a dedicated regression test asserting that behavior (
internal/docgen/generate_test.go:481-514). - The current shell loop does not model that contract. If
skills/bkt/rules/old-command.mdis a stale auto-generated file and docgen now only emitspr.md, the script still passes because it only walks the generated side.
I reproduced the loop with:
- committed:
old-command.md+pr.md - generated:
pr.md
and STALE remained empty.
For a pristine OSS gate, this needs to fail on orphaned generated files too, while still ignoring hand-maintained files like headless.md. The simplest fix is to compare both sides, but only treat committed .md files with the docgen auto-generated header as candidates for orphan detection.
|
Added a reverse loop ( |
avivsinai
left a comment
There was a problem hiding this comment.
One issue still left here for a pristine OSS repo.
The new generated-skill check path ignores the repo's existing GO override contract. Makefile defines GO ?= go, and generate-skill uses $(GO), but scripts/check-generated-skill.sh:18 hardcodes go run ./cmd/docgen .... That means make generate-skill GO=... and make check-generated-skill GO=... can run under different Go binaries / wrappers, which is inconsistent for contributors and CI setups that pin GO.
Please thread the same GO override through the check path as well, so generation and verification use the same toolchain contract.
|
Done — script now reads |
avivsinai
left a comment
There was a problem hiding this comment.
Re-reviewed the latest head after the GO override fix. check-generated-skill now honors the same GO contract as generate-skill, both through the Makefile and direct script invocation. LGTM.
Summary
Full Plan (4 PRs) - Complete
cmd/docgen/+internal/docgen/) +make generate-skillrules/*.md, rewriteSKILL.mdChanges
scripts/check-generated-skill.sh— regenerates into temp dir and diffs against committed rules + SKILL.md References sectionMakefile—check-generated-skilltarget.pre-commit-config.yaml— local hook triggers on changes topkg/cmd/,cmd/docgen/,internal/docgen/, orskills/bkt/.github/workflows/ci.yml—check-skillsjob now runscheck-generated-skillwith Go toolchainTest plan
make check-generated-skillpasses on clean treemake check-generated-skillto fail with clear errormake generate-skill && make check-generated-skillrecovers from stale statego test ./...passescheck-skillsandcheck-generated-skill