-
-
Notifications
You must be signed in to change notification settings - Fork 3
witness gate: requiring the :: payload silently drops de-marked markers that have no payload, and the changelog claims otherwise #353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ### Fixed | ||
| - Tightened the witness-gate near-miss detector so ordinary prose that merely | ||
| mentions WITNESS (without the ``::`` payload) is no longer flagged, while | ||
| de-marked (zero-width) and malformed markers still are. | ||
| - Replaced the file-level de-marked-marker exemption in the gate with a | ||
| line-level one, so a genuine de-marked marker appended to | ||
| ``scripts/check_witness_token.py`` is reported while its three documented | ||
| docstring examples are not. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ### Fixed | ||
| - Tightened the witness-gate near-miss detector so ordinary prose that merely | ||
| mentions WITNESS (without the ``::`` payload) is no longer flagged, while | ||
| de-marked (zero-width) markers that retain a colon after the broken separator | ||
| and other malformed markers containing a colon still are. | ||
| - Replaced the file-level de-marked-marker exemption in the gate with a | ||
| line-level one, so a genuine de-marked marker appended to | ||
| ``scripts/check_witness_token.py`` is reported while its three documented | ||
| docstring examples are not. | ||
| - Corrected the near-miss detector to catch de-marked markers whose payload | ||
| is missing, fixing a silent regression introduced when the detector was | ||
| tightened to require the ``::`` payload. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,9 @@ | |
| test file itself survives. This gate cannot be fooled by that -- it resolves the | ||
| TOKEN, not the path. The gate is non-vacuous in both directions: it fails when a | ||
| declared token is removed (file stays importable), and it does NOT fire on a bare | ||
| test-filename mention in ordinary prose. | ||
| test-filename mention in ordinary prose. A comment that quotes the marker | ||
| syntax (e.g. ``path::token``) without forming a live marker will still be | ||
| flagged by the near-miss detector. | ||
|
|
||
| Marker contract (the only thing that triggers the check): | ||
|
|
||
|
|
@@ -63,11 +65,20 @@ | |
| _REPO_ROOT = Path(__file__).resolve().parent.parent | ||
| REPO_ROOT = Path(os.environ.get("WITNESS_GATE_ROOT") or _REPO_ROOT) | ||
| WITNESS_RE = re.compile(r"#\s*WITNESS:\s*(.+)$") | ||
| _NEAR_MISS_RE = re.compile(r"#\s*WITNESS[^:]") | ||
| # Files whose docstrings contain de-marked illustrative examples. Greppable name. | ||
| _DEMARKED_MARKER_EXEMPTION = frozenset({ | ||
| "scripts/check_witness_token.py", | ||
| }) | ||
| # A near-miss resembles a WITNESS marker whose separator is broken -- a | ||
| # zero-width character (e.g. U+200B) lodged between WITNESS and the colon, | ||
| # or the colon replaced. Requiring a colon after the broken separator keeps | ||
| # ordinary prose mentioning WITNESS from being mistaken for a malformed | ||
| # marker, while still catching de-marked markers that omit the ``::`` | ||
| # payload. Prose that quotes the marker syntax (e.g. ``path::token``) still | ||
| # trips the near-miss detector; that is a known residual. | ||
| _NEAR_MISS_RE = re.compile(r"#\s*WITNESS[^:](?=[^:]*:)") | ||
| # Documented examples of a de-marked marker in this file's own docstring. | ||
| # They are intentionally de-marked and must not be reported; every other line | ||
| # in the same file (e.g. an appended genuine marker) still is. Greppable name. | ||
| _DEMARKED_MARKER_EXEMPTION = { | ||
| "scripts/check_witness_token.py": frozenset({4, 21, 38}), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: Hardcoded line numbers in The frozenset Reply with |
||
| } | ||
|
|
||
|
|
||
| @dataclass | ||
|
|
@@ -120,14 +131,15 @@ def _extract_claims(file_path: Path, repo_root: Path) -> list[WitnessClaim]: | |
|
|
||
| def _check_near_misses(file_path: Path, repo_root: Path) -> list[Violation]: | ||
| rel = _relative_source(file_path, repo_root) | ||
| if rel in _DEMARKED_MARKER_EXEMPTION: | ||
| return [] | ||
| exempt_lines = _DEMARKED_MARKER_EXEMPTION.get(rel, frozenset()) | ||
| try: | ||
| source = file_path.read_text(encoding="utf-8") | ||
| except (OSError, UnicodeDecodeError): | ||
| return [] | ||
| violations: list[Violation] = [] | ||
| for lineno, line in enumerate(source.splitlines(), start=1): | ||
| if lineno in exempt_lines: | ||
| continue | ||
| if _NEAR_MISS_RE.search(line): | ||
| claim = WitnessClaim( | ||
| source_file=rel, line_number=lineno, raw=line.strip() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SUGGESTION: Changelog claims old regex required
::payloadThe changelog states the old regex required the
::payload, but the diff shows the previous regex wasr"#\\s*WITNESS[^:]", which does not require::. Consider revising the changelog to accurately describe the prior regex behavior.Reply with
@kilocode-bot fix itto have Kilo Code address this issue.