From 0eeed3f8b490b88033a11df3ad388d071558fffc Mon Sep 17 00:00:00 2001 From: mattj Date: Fri, 4 Dec 2026 08:41:02 -0600 Subject: [PATCH] feat(declared-literal): --exempt-prefix DIR/ per rule, self-expiring (v1.96.0) A consumer is importing a whole repository into a subdirectory (edge-host stack/, the trade-infra fold). The imported tree carries 71 copies of a path the importing repo's rule forbids; they are real debt, repointed at a later flip, and the import must stay byte-identical to its source until then. Declaring each file would also excuse any NEW copy in it; there was no other way to scope. `--exempt-prefix DIR/` attaches to one rule (like --declared) and excuses that rule only, under that directory only. It is debt, so it is built to end: - the files under it are still read, and the summary names the excused line and file counts; - a prefix holding no tracked file (wrong path) or no live match any more (debt paid) is exit 2 until the flag is deleted; - a prefix that is not a repo-relative directory ending '/' is exit 2 (a bare `vendor` would also excuse vendored.sh). Selftest: 8 new cases both directions. Must-fire: dropping the prefix filter from findings_in, or the "excuses nothing any more" check, each turns the selftest red. Co-Authored-By: Claude Opus 5.5 --- ci_kit/declared_literal.py | 93 +++++++++++++++++++++++++++++++++++--- docs/gates/secrets.md | 4 ++ pyproject.toml | 2 +- uv.lock | 2 +- 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/ci_kit/declared_literal.py b/ci_kit/declared_literal.py index 458a59c..9e7207b 100644 --- a/ci_kit/declared_literal.py +++ b/ci_kit/declared_literal.py @@ -9,10 +9,16 @@ THE POLICY IS THE CALLER'S. The kit ships no pattern, no declared file and no message. A rule is opened by `--rule LABEL`; the `--pattern` (Python `re`, repeatable, OR'd), `--example TEXT` -(repeatable, REQUIRED), `--declared PATH` (repo-relative, repeatable) and `--message TEXT` flags -after it belong to it. Flags before any `--rule` belong to one implicit rule. `--exempt-suffix +(repeatable, REQUIRED), `--declared PATH` (repo-relative, repeatable), `--exempt-prefix DIR/` +(repeatable) and `--message TEXT` flags after it belong to it. Flags before any `--rule` belong to one implicit rule. `--exempt-suffix .EXT` (every rule) exempts a file kind from findings, e.g. `.md` when prose may name the value. +AN EXEMPT PREFIX EXPIRES ITSELF. `--exempt-prefix DIR/` (one rule, a directory ending `/`) excuses +that rule's matches under DIR -- a tree imported whole that will be repointed later, say. It is +debt, so it must be able to end: the files under it are still READ, every excused line is counted +and named in the summary, and a prefix that holds no tracked file (a wrong path) or no live match +any more (the debt is paid) is exit 2 until the flag is deleted. It never excuses another rule. + A RULE MUST PROVE IT CAN FIRE. A pattern that cannot match the value it guards (a stray trailing space, a doubled backslash) would scan the tree and report clean forever. So: every `--example` must be flagged as a live line by the rule, and every `--pattern` must match at least one example; @@ -83,7 +89,7 @@ POWERSHELL_SUFFIXES = frozenset({".ps1", ".psm1", ".psd1"}) DEFAULT_MESSAGE = "Read the value from the declared source instead; a comment line may keep it for history." VALUE_FLAGS = frozenset({"--root", "--rule", "--pattern", "--example", "--declared", "--message", - "--exempt-suffix", "--comment-prefix"}) + "--exempt-suffix", "--comment-prefix", "--exempt-prefix"}) #: The openers the predecessor honoured in EVERY file. Each family below is a subset of it. OLD_OPENERS = ("#", "//", "