Skip to content

One detector dialect, read alike by every runtime - #46

Merged
jithinAB merged 6 commits into
masterfrom
pact-kernel/detector-dialect
Nov 17, 2026
Merged

jithinAB merged 6 commits into
masterfrom
pact-kernel/detector-dialect

Conversation

@jithinAB

Copy link
Copy Markdown
Contributor

What

One detector dialect, read alike by every runtime.

  • crates/pact-loader/src/dialect.rs: the detector dialect as a reader. outside(pattern) says why a pattern is outside it, and where. pact check holds every detectors.<name>.looks-like: line to it, each line on its own and then the lines joined as every runtime joins them, and refuses the rest with loader/looks-like-outside-the-dialect.
  • adapters/typescript/src/detectors.ts: the TypeScript port. translateDetectorPattern translates exactly the patterns in the dialect to JavaScript that finds what Python's re finds, and refuses the rest with the checker's reasons. compileDetectors compiles a workspace's detectors: and holds each to its examples:, and the module carries the five built-in recognisers.
  • tests/conformance/detectors.json: 87 patterns over 68 texts. Each case is in or outside the dialect, with its reason, and lists every match re.finditer yields for the ones in it. It is read by crates/pact-loader/tests/detector_dialect_cases.rs (the checker's reasons) and by adapters/python/tests/test_every_port_reads_one_detector_dialect.py (the reference's matches through detectors.declared_in, the TypeScript port's refusals and matches through read-detectors.mts, and pact check refusing a tree).
  • spec/schema.yaml (detector.looks-like) describes the dialect, and the CHANGELOG and headline counts are updated.

Why

looks-like: took any regular expression Python's re compiled. A runtime in another language reads the patterns with its own engine. Engines disagree on lookaround, back-references, (?<name>...) (refused by Python's re, a named group to others), flags for the whole pattern, {,m}, nested classes, \b beside non-ASCII letters, $ before a final newline, and where the next search starts after an empty match. So one tree could hide a card number on one runtime and let it through on another. The dialect is the part both Python's re and the Rust regex crate read, with Python's meaning. The TypeScript port translates \b, \w, \d, \s, $ and (?i:...) to Python's meaning rather than JavaScript's. A pattern that can match an empty value is outside the dialect: it finds something in every text, and Python and JavaScript step past an empty match differently, which was the one disagreement the shared cases found.

The TypeScript module is the detector port Bud Meta Harness has run since its PK-3 card, with 10 000 canary values compared against Python's re. Upstream holds one copy, and BMH re-pins to it instead of keeping its own (plan §3.14).

Evidence

On this branch's head (upstream master a52dcdd merged in), the steps of scripts/test-all.sh:

  • cargo build -p pact-cli, the pact-fill-wasm release build, cargo test --no-fail-fast (1727 passed, 0 failed, including detector_dialect_cases), cargo clippy --all-targets -D warnings and the wasm clippy: exit 0.
  • TypeScript adapter tsc --noEmit: exit 0.
  • Python adapter: the full suite on the head before the master merge, 3583 passed, 30 skipped; on the merged head test_every_port_reads_one_detector_dialect.py (4 passed) and test_the_headline_test_count_is_the_count.py.
  • scripts/sync-counts.sh: rust=1727 adapter=3618, no document changed.

Purpose checklist (§0.2)

  1. P1 Declared: what a detector finds is what the document writes, on every runtime.
  2. P2 No hidden divergence: the checker refuses what runtimes would read differently, and the shared cases hold three ports to one answer.
  3. P3 Honest gaps: examples: are held by the Python and TypeScript ports at compile time. The checker holds syntax, since it carries no regular-expression engine.
  4. P4 Host choices recorded: none.
  5. P5 Model-visible ⟺ logged: not applicable.
  6. P6 Cross-runtime evidence: tests/conformance/detectors.json, read by Rust, Python and TypeScript.
  7. P7 Versioned and checked: a tree with a pattern outside the dialect is refused by pact check, so it is never versioned.
  8. P8 Reusable: any runtime can take detectors.ts or read the cases.
  9. P9 Platform rules: the module imports nothing and keeps nothing between calls.
  10. P10 Justified: portability of hiding rules is the point of PACT's detectors (law 7 hides values before a model sees them).
  11. P11 Lane hygiene: CHANGELOG, schema help and counts in the PR.

jithinAB and others added 6 commits November 17, 2026 09:36
pact check holds every looks-like line to the detector dialect
(loader/looks-like-outside-the-dialect); the TypeScript port and shared
conformance cases hold Rust, Python and TypeScript to one answer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r-dialect

# Conflicts:
#	CHANGELOG.md
#	README.md
#	docs/90-REVIEW.md
#	site-docs/index.md
#	site-docs/status/verified.md
…r-dialect

# Conflicts:
#	CHANGELOG.md
#	README.md
#	docs/90-REVIEW.md
#	site-docs/index.md
#	site-docs/status/verified.md
…r-dialect

# Conflicts:
#	README.md
#	docs/90-REVIEW.md
#	site-docs/index.md
#	site-docs/status/verified.md
@jithinAB
jithinAB marked this pull request as ready for review November 17, 2026 09:30
@jithinAB
jithinAB merged commit 535a28e into master Nov 17, 2026
4 of 5 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