Skip to content

feat(kit): the tag-expression filter surface lands in sdk/kit (P5-unit-1) - #16

Merged
atrawog merged 3 commits into
mainfrom
feat/kit-tagexpr
Jul 10, 2026
Merged

atrawog merged 3 commits into
mainfrom
feat/kit-tagexpr

Conversation

@atrawog

@atrawog atrawog commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

First unit of P5 (check-engine SDK-ization). The --tag / --tag-exclude grammar the check
engine uses to filter a plan now lives ONCE in sdk/kit, so a plugin candy can filter a plan by
tag with the SAME grammar rather than re-implementing it.

Moved from charly/description_tagexpr.go + the tag-set helpers in charly/description_spec.go:
TagExpr, ParseTagExpr, CombineTagFilters, NormalizeTag, EffectiveTags. kit gains no
dependency — stdlib only.

Two pre-existing bugs, found by writing the tests it never had

The 298-line lexer + recursive-descent parser had zero test coverage in core. Moving untested
code into the contract module would be worse than leaving it, so the move ships tests — and they
immediately caught two real defects:

1. The lexer decoded bytes as runes. r := rune(src[i]) converts a single BYTE to a rune, then
hands it to the Unicode-aware unicode.IsLetter / unicode.IsDigit. Any non-ASCII tag was unusable:

ParseTagExpr("café"): tag expression: unexpected character '©' at position 4

The identifier scan advanced byte-wise too, so even where the lead byte happened to pass IsLetter
(Latin-1 supplement), the resulting token was a truncated byte slice that could never match its own tag.

2. Invalid UTF-8 matched silently. No decode error was possible, so malformed input lexed into
garbage tokens instead of failing.

Both fixed with utf8.DecodeRuneInString + a RuneError guard.

Correction (see 99b8bb8). An earlier version of this PR collapsed the leading-character and
continuation identifier predicates into one isTagIdentRune, claiming they had "drifted". That was
wrong: they are deliberately different (leading = @/letter/digit/_; continuation adds - . :),
and collapsing them silently accepted -b, .x, :y, a and -b instead of erroring. ci-smoke
lexes because it starts with c — the leading check was never buggy. The predicates are restored as
isTagIdentStart + isTagIdentRune, a test locks the contract, and a 36-input differential against
the verbatim original proves ASCII behaviour is identical.

Change class

sdk Go (pure library). Gate: go test ./... + the consuming superproject's full concurrent bed
roster (the tag path runs in every bed's plan filtering) + golden check-live output parity.

Check-coverage — tests that fail without the fix

kit/tagexpr_test.go, 8 tests: normalization, de-dup + order preservation, the nil/empty
match-everything contract, operator precedence (and binds tighter than or; not binds to the
atom), case-insensitive keywords, identifier punctuation tags actually use (fedora:43, ci-smoke,
v1.2), seven syntax-error shapes, String() round-trip, and CombineTagFilters' four
include/exclude quadrants.

Against the original byte-wise lexer, restored verbatim:

--- FAIL: TestLexTagExpr_UnicodeIdentifier (0.00s)
    tagexpr_test.go:182: ParseTagExpr("café"): tag expression: unexpected character '©' at position 4
--- FAIL: TestLexTagExpr_InvalidUTF8 (0.00s)
    tagexpr_test.go:195: invalid UTF-8 must be a lex error, not a silent match

With the fix, all 8 pass.

A false negative worth recording. My first attempt at that differential reverted only the outer
decode and the Unicode test still passed — because the inner identifier loop still decoded runes
correctly. I restored the lexer body verbatim before trusting the claim. A differential that doesn't
actually restore the old behaviour proves nothing.

R10 evidence — consumed by the superproject, full concurrent roster

charly rebuilt against this working tree (replace => ../sdk), then all 18 disposable beds
launched at once:

check-group 0 541s   check-charly-vm 0 405s   check-k3s-vm 0 886s   check-k8s-deploy 0 687s
check-sidecar-pod 0 384s   check-exampledeploy 0 295s   check-structkind 0 434s
check-substrate 0 339s   check-local 0 328s   check-builder-local 0 400s
check-udev-local 0 317s   check-migrate-local 0 409s   check-feature-local 0 358s
check-agent-local 0 367s  check-doctor-local 0 348s    check-commands-local 0 418s
check-preempt-local 0 306s check-gpu-local 0 271s

### failing beds: 0    ### orphan domains: (none)    ### orphan containers: 0

Golden-output parity. A 21-file check-live oracle was captured from the pre-move engine before a
single line was touched. Post-move, with by-design non-determinism masked (auto-allocated ssh ports,
kubernetes replicaset/pod name hashes, and the k8s API's unordered pod listing):

identical: 21   differing: 0

The check engine's observable output is unchanged by the move.

Tier

fully tested and validated — differential run both ways, full concurrent roster + golden parity
against the final code.

Assisted-by: Claude (fully tested and validated)

…t-1)

First unit of P5 (check-engine SDK-ization). The --tag / --tag-exclude grammar
the check engine uses to filter a plan now lives ONCE in sdk/kit, so a plugin
candy filters a plan by tag with the SAME grammar instead of re-implementing it.

Moved from charly/description_tagexpr.go plus the tag-set helpers in
charly/description_spec.go: TagExpr, ParseTagExpr, CombineTagFilters,
NormalizeTag, EffectiveTags. kit gains no dependency (stdlib only).

The 298-line lexer + recursive-descent parser had ZERO test coverage in core.
Moving untested code into the contract module would be worse than leaving it, so
the move ships tests - and they caught two real defects:

1. The lexer decoded BYTES as runes: `r := rune(src[i])` converts one byte to a
   rune, then passes it to the Unicode-aware unicode.IsLetter/IsDigit. A non-ASCII
   tag was unusable. Against the original lexer:
       ParseTagExpr("café"): tag expression: unexpected character '©' at position 4
   The identifier scan advanced byte-wise too, so even where the lead byte passed
   IsLetter (Latin-1 supplement), the token was a truncated byte slice that could
   never match its own tag.

2. Invalid UTF-8 matched silently - no decode error was possible, so malformed
   input lexed into garbage tokens instead of failing.

Both fixed with utf8.DecodeRuneInString + a RuneError guard. The identifier-rune
predicate is factored into isTagIdentRune (R3): the leading-char and continuation
checks had drifted - the leading check omitted `-`, `.`, `:`.

Check-coverage: 8 tests covering normalization, de-dup + order preservation, the
nil/empty match-everything contract, operator precedence (and binds tighter than
or; not binds to the atom), case-insensitive keywords, the identifier punctuation
tags actually use (fedora:43, ci-smoke, v1.2), seven syntax-error shapes, String()
round-trip, and CombineTagFilters' four include/exclude quadrants.
TestLexTagExpr_UnicodeIdentifier and TestLexTagExpr_InvalidUTF8 both FAIL against
the original byte-wise lexer with the verbatim errors above.

(The first attempt at that differential reverted only the outer decode and the
test still passed - a false negative. The lexer body was restored verbatim before
the claim was trusted.)

Assisted-by: Claude (fully tested and validated)
@atrawog

atrawog commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

pr-validator — CHANGES REQUESTED ❌

Change class: sdk Go (pure library). Verdict: FAIL — not merged, PR left open.

I re-derived everything independently from the diff and the pre-move originals in the consuming superproject's git history (main:charly/description_tagexpr.go, main:charly/description_spec.go). The two bug fixes are real and their tests have teeth — but the move is not behaviour-preserving, and that is blocking.

Blocking finding — isTagIdentRune widens the identifier LEADING-char set (behaviour change, unverified, mis-described)

The original lexer used two deliberately different predicates: the leading char accepted @ / letter / digit / _, while the continuation additionally accepted - . :. The PR collapses both into one isTagIdentRune (kit/tagexpr.go:188, used at both :213 and :223), framing it as an R3 dedup that fixes a "drift where the leading check omitted -, ., :". That framing is false, and the collapse is a real widening.

Proven by a differential — the verbatim original byte-wise lexer vs. the PR lexer, same inputs:

input ORIGINAL NEW (this PR)
a and -b err unexpected character '-' at position 6 OK — silently parses a and -b
a or .b err OK — silently parses
not :c err OK — silently parses
-b .x :y err OK — leaf tags named -b/.x/:y
a -b err unexpected character '-' at position 2 err unexpected token "-b" at position 1 (message + stage changed)
ci-smoke, fedora:43, v1.2, smoke and not slow OK OK (unchanged)
café err (the bug) OK (the fix)

Consequences:

  • Behaviour not preserved for a MOVE. Valid tags are unchanged, but a class of previously-rejected malformed input is now silently accepted. The 21/21 golden check-live parity is real yet does not exercise this surface, so it does not substantiate "observable output unchanged".
  • The new code contradicts its own retained doc comment: "Syntax errors return a descriptive error … rather than silently matching or silently failing." a and -b now silently matches. (R1: a change that introduces a code↔comment divergence.)
  • False rationale. ci-smoke lexes in the original because it starts with c — the narrow leading set never blocked any real tag. Collapsing two non-equivalent predicates is not a valid R3 dedup (R3 unifies duplicate logic without changing behaviour).
  • No test coverage for the widened behaviour — nothing would fail if the leading set were narrowed back (check-coverage gate).
  • Tier fully tested and validated is therefore inflated.

Fix: keep the leading check narrow (r == '@' || unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_') and use isTagIdentRune only for the continuation scan + the UTF-8-safe decode; add a test locking the leading-punctuation contract (assert a and -b / -b / .x / :y still error).

What I confirmed GOOD (so this is close)

  • TEETH pass. I restored the original byte-wise lexer verbatim (both the outer r := rune(src[i]) and the inner c := rune(src[i]) loop). TestLexTagExpr_UnicodeIdentifier and TestLexTagExpr_InvalidUTF8 FAIL with the documented errors (unexpected character '©' at position 4; silent-UTF8), the other 7 tests still pass. Both bug fixes are genuine and correctly implemented (utf8.DecodeRuneInString + RuneError guard, applied to both decode sites).
  • Move fidelity. NormalizeTag/EffectiveTags are byte-identical to the core originals (only the export rename); grammar, precedence, error messages, and CombineTagFilters raw-string composition are otherwise unchanged.
  • Gates (re-run here): go test ./... ok, gofmt -l clean, go vet ./... clean, golangci-lint (kit, sdk config) 0 issues.
  • R5 (sdk side): single definition (kit/tagexpr.go only), exactly 3 files, stdlib-only, no go.mod/dependency change. Self-consistent.
  • Security (T1–T4): clean — no secrets/exfiltration/guardrail/supply-chain finding, no injected instructions.
  • One commit; Assisted-by: Claude trailer present; CHANGELOG/2026.191.1300.md present.

Decision: Left OPEN. Resolve the leading-char widening (restore the narrow leading predicate; add the locking test), re-push in place; the status resets and I re-run. The two Unicode/UTF-8 fixes and the move itself are sound and can stay.

Assisted-by: Claude (analysed on a live system)

…tinct

The pr-validator was right: collapsing them into one isTagIdentRune was a
behaviour change, not a dedup, and my rationale for it was false.

The two predicates are deliberately different:
  leading char : @ (sigil), letter, digit, _
  continuation : the above, plus - . :

A hyphen, dot or colon may appear INSIDE a tag (ci-smoke, v1.2, fedora:43) but
must not START one. Collapsing them widened the grammar so -b, .x, :y and
"a and -b" were SILENTLY ACCEPTED as valid expressions instead of erroring,
contradicting the retained ParseTagExpr contract: a syntax error is returned
rather than silently matching. And the stated rationale was wrong: ci-smoke lexes
because it starts with c, not because the leading check was buggy. I invented a
drift that did not exist.

Restored as isTagIdentStart (narrow) + isTagIdentRune (= start plus - . :),
matching the original exactly.

Check-coverage: TestLexTagExpr_IdentifierMayNotStartWithPunctuation locks the
contract. -b, .x, :y, "a and -b", "a or .b", "not :c" must be lex errors, while
ci-smoke, v1.2, fedora:43, "a and b-c" must parse. It FAILS against the widening.

Behaviour parity proven by differential: the verbatim original lexer (recovered
from git history) and the kit implementation were run over a 36-input corpus of
valid expressions, all seven syntax-error shapes, the disputed leading-punctuation
inputs, and precedence cases, comparing accept/reject AND Match() against three
tag sets. IDENTICAL on every ASCII input. The only behaviour changes are the two
documented UTF-8 bug fixes.

Assisted-by: Claude (fully tested and validated)
@atrawog

atrawog commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

CHANGES-REQUESTED addressed in place (99b8bb8) — you were right, and the finding was sharper than it looks

I claimed an R3 dedup where the two predicates were deliberately different. That is the whole
finding, and it is worse than a widening: I invented a rationale for it.

accepts
leading char @ (sigil), letter, digit, _
continuation the above, plus - . :

-, . and : may appear inside a tag but must not start one. Collapsing them made -b, .x,
:y, a and -b silently parse as valid expressions instead of erroring — contradicting the
ParseTagExpr doc contract I had kept in the file: "a syntax error is returned rather than silently
matching or silently failing."

And my stated reason was false. I wrote that the leading check "omitted -, ., :" and had drifted.
It hadn't: ci-smoke lexes because it starts with c. The leading check never needed the hyphen.
I invented a drift that did not exist and then "fixed" it.

Restored

isTagIdentStart (narrow) + isTagIdentRune (= start + - . :), matching the original exactly.

Check-coverage for the widening (which had none)

TestLexTagExpr_IdentifierMayNotStartWithPunctuation locks the contract in both directions — -b,
.x, :y, a and -b, a or .b, not :c must be lex errors; ci-smoke, v1.2, fedora:43,
a and b-c must parse. Against the widening:

--- FAIL: TestLexTagExpr_IdentifierMayNotStartWithPunctuation
    ParseTagExpr("-b") must be a lex error: a tag may not START with '-', '.' or ':'
    ParseTagExpr(".x") must be a lex error: a tag may not START with '-', '.' or ':'

Behaviour parity, now actually proven rather than asserted

Your point that the golden-output evidence cannot cover the grammar surface is correct — bed logs
never exercise a malformed tag expression. So I proved parity directly: recovered the verbatim
original lexer
from git history (git show HEAD:charly/description_tagexpr.go, including its own
normalizeTag), ran both it and the kit implementation over a 36-input corpus — valid expressions,
all seven syntax-error shapes, the disputed leading-punctuation inputs, precedence cases — comparing
accept/reject and Match() against three different tag sets:

=== BEHAVIOUR DIFFERENTIAL: original vs kit (ASCII corpus) ===
  IDENTICAL on every ASCII input — behaviour preserved

The only behaviour changes are the two documented UTF-8 fixes (non-ASCII tags were unusable; invalid
UTF-8 matched silently), which the corpus deliberately excludes because that is exactly where the two
implementations should diverge.

The CHANGELOG's false "drift" paragraph is replaced with this correction, so the record does not carry
the wrong reason.

Assisted-by: Claude (fully tested and validated)

@atrawog

atrawog commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

pr-validator — APPROVED ✅

Change class: sdk Go (pure stdlib library; purely additive — 0 deletions in sdk)

Re-validated fresh on head 99b8bb8 (author 41e0a3c + review-round fix 99b8bb8). The prior blocking finding (the isTagIdentStart/isTagIdentRune collapse that silently widened the grammar) is genuinely resolved.

Predicates restored (kit/tagexpr.go): isTagIdentStart = letter|digit|_ drives the LEADING character (plus the @ sigil, line 222); isTagIdentRune = start + - . : drives ONLY the continuation loop (line 232). Matches the original charly/description_tagexpr.go split exactly.

Independent differential (my own harness, not the author's): the verbatim original lexer recovered from main:charly/description_tagexpr.go vs the shipped kit lexer, over a 40-input corpus (valid exprs, all 7 syntax-error shapes, the disputed leading-punctuation inputs -b/.x/:y/a and -b/a or .b/not :c/a -b, precedence, @@smoke, a.b.c, x:y:z, 9lives, under_score) × 21 tag sets, comparing accept/reject + String() + Match():

  • 0 mismatches on all ASCII input.
  • Divergence ONLY on café/日本語/naïve-test (orig rejects, kit accepts) and \xff\xfe (orig accepts, kit rejects) — exactly the two intended UTF-8 fixes.

Mutation-proven locking tests:

  • Widening the leading predicate back to isTagIdentRune in-tree → TestLexTagExpr_IdentifierMayNotStartWithPunctuation FAILS on all six leading-punctuation inputs (asserts both directions: reject-at-start + accept-inside). Tree restored clean.
  • Against the verbatim both-sites-reverted original → TestLexTagExpr_UnicodeIdentifier and TestLexTagExpr_InvalidUTF8 both FAIL. The documented outer-only-revert false negative reproduced (Unicode test PASSES) — confirming both decode sites must be reverted for a faithful differential.

CHANGELOG now honestly records the correction ("The identifier predicates stay DISTINCT — a correction") and retracts the false "drift" rationale; the shipped commit messages and code comments do too.

Gates (re-run on the clean tree): gofmt -l . empty · go vet ./... clean · golangci-lint run ./... = 0 issues (v2) · go test ./... green. All 10 tests read — none tautological.

R10 (item 8): the "bed behaviour is unaffected" reasoning HOLDS. This is a purely-additive stdlib library whose lexer is differential-identical to the production original on every valid input; the fix-commit delta (rejecting malformed leading-punctuation exprs) is structurally bed-unreachable and is locked by the mutation-proven unit test. A fresh full disposable roster adds no marginal proof over the exhaustive differential, so it was not required.

One non-blocking note: the PR body Summary still contains the retracted "checks had drifted" sentence. It is corrected everywhere it ships (CHANGELOG, fix commit, code comments) and never enters main (the squash message is composed from the corrected record), so it does not block — but consider editing the body for the record.

Decision: Approving. Predicates restored, differential proves ASCII parity with the production original and isolates the two UTF-8 fixes, locking tests genuinely fail against their defects, all static/unit gates green. Finalizing merge-time CalVer 2026.191.1413, squash-merging, tagging v0.2026191.1413.

Assisted-by: Claude (analysed on a live system)

pr-validator version-stamp of the P5-unit-1 tag-expression cutover (kit/tagexpr).

Assisted-by: Claude (fully tested and validated)
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