Add full-coverage tests for rules-guard#1
Merged
Conversation
Expand the `rules-guard` suite to positive, negative, adversarial, and fuzzy cases, reaching 100% function and line coverage. Enforce it with `coverageThreshold = 1.0` in `bunfig.toml` so any regression fails `bun test`. New coverage: - Positive and negative cases for every export: `compileGlob`, `bashMatcher`, `parseRule`, `candidateAbsPaths`, `pathTokens`, `redactText`, `loadPolicyEntries`, and the `rulesGuard` wiring hooks (registration, session_start, tool_call, tool_result). - Adversarial bypass vectors: path traversal that resolves into a denied directory, denied commands hidden after shell separators, and a read-class deny binding write, edit, and unknown tools. - Seeded (mulberry32) fuzz invariants: `decide` never throws, `compileGlob` output stays anchored, `redactText` is idempotent, and any leaf under a denied directory is blocked. Also add an embedded deny rule covering RSA private key files, and exclude the test suite from the `detect_private_key` pre-commit hook since it embeds a synthetic PEM fixture to exercise secret redaction. Glory to the Omnissiah
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Brings the
rules-guardextension test suite to 100% function and line coverage across positive, negative, adversarial, and fuzzy cases, and enforces it withcoverageThreshold = 1.0inbunfig.tomlso any regression failsbun test.Test count: 20 → 55, all passing.
What changed
extensions/rules-guard/index.test.ts— new suites:compileGlob,bashMatcher,parseRule,candidateAbsPaths,pathTokens,redactText,loadPolicyEntries, plus therulesGuardwiring hooks (registration,session_start,tool_call,tool_result) via a minimalExtensionAPImock...) that resolves into a denied directory, denied commands hidden after shell separators (;,&&,||,|, newline), and a read-class deny bindingwrite/edit/unknown tools.mulberry32for determinism under the coverage gate:decidenever throws,compileGloboutput stays anchored,redactTextis idempotent, and any leaf under a denied directory is always blocked.bunfig.toml—coverageThreshold = 1.0.extensions/rules-guard/index.ts— embedded deny rule for RSA private key files (Read(**/*.id_rsa)).hk.pkl— exclude the test suite from thedetect_private_keypre-commit hook; the suite embeds a synthetic PEM fixture purely to exercise secret redaction, which otherwise trips the scanner.Verification
bun test— 55 pass, 0 fail, 100.00% funcs / 100.00% lines, exit 0.bun typecheck— clean.bunx biome check— clean.hkhooks pass (includingdetect_private_keywith the scoped exclusion).