Skip to content

Author Semgrep rules as validated YAML fragments#19

Merged
haasonsaas merged 1 commit into
mainfrom
feat/semgrep-rule-fragments
Jul 18, 2026
Merged

Author Semgrep rules as validated YAML fragments#19
haasonsaas merged 1 commit into
mainfrom
feat/semgrep-rule-fragments

Conversation

@haasonsaas

Copy link
Copy Markdown
Collaborator

Summary

  • Split the room.yml godfile into one-rule-per-file fragments under analyzers/semgrep/rules/, bundled by a deterministic Go generator (cmd/semgrep-rule-bundler + internal/semgrepbundle) via go generate ./analyzers/semgrep.
  • The bundler validates every fragment: exactly one rule, known room_signal, integer room_confidence_basis_points in 1..10000, and no ambiguous YAML (anchors, aliases, merge keys, duplicate or non-string mapping keys). Output is canonically sorted, carries a DO-NOT-EDIT header, and is written atomically — a symlinked room.yml is replaced, never followed.
  • CI regenerates the bundle and fails on drift, so the checked-in room.yml (and its config_sha256 receipt binding) always matches the authored fragments. Contributor workflow documented in docs/analyzer.md.

Test plan

  • go test ./... — unit tests for deterministic ordering, invalid fragments (duplicate ids/keys, anchors, aliases, merge keys, float/exponent/quoted confidence), symlink rejection, and atomic write semantics
  • go generate ./analyzers/semgrep reproduces checked-in room.yml byte-for-byte (sha256 2a4073e1…)
  • semgrep --validate --strict — 8 rules, 0 errors
  • ROOM_SEMGREP_CORE=… go test -tags=semgrep_integration ./cmd/room-semgrep — real semgrep-core 1.139.0 suite passes
  • actionlint .github/workflows/ci.yml, go vet ./..., gofmt, git diff --check all clean

Adding a rule now means dropping one fragment under
analyzers/semgrep/rules/ and running go generate, instead of editing
the room.yml godfile. The bundler validates signal metadata, rejects
duplicate ids and ambiguous YAML (anchors, aliases, merge keys,
duplicate keys, non-integer confidence), sorts canonically, and
rewrites room.yml atomically so the checked-in bundle stays a
regular file. CI regenerates and fails on drift, keeping the
config_sha256 receipt binding intact.
@haasonsaas
haasonsaas merged commit 90aa8ed into main Jul 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant