Skip to content

Add chaos rig + reject phone-number-shaped tokens as MACs - #13

Merged
StewAlexander-com merged 1 commit into
mainfrom
chaos-test-rig
May 27, 2026
Merged

StewAlexander-com merged 1 commit into
mainfrom
chaos-test-rig

Conversation

@StewAlexander-com

Copy link
Copy Markdown
Owner

Summary

  • New chaos rig (tests/chaos_rig.py + tests/chaos_corpus.py) throws 67 messy real-world inputs at maclookup.lookup_detailed and classifies each result as match / match_ocr / partial / none. Covers Windows ipconfig, Linux ip link / ifconfig, Cisco IOS show interfaces + bia, Juniper / Arista / iDRAC / iLO labels, JSON / HTML / email / ticket prose, every wrapper and trailing punctuation combo, locally-administered / broadcast / multicast / all-zero edges, longest-prefix correctness, partial prefixes from 4-10 hex chars, OCR typo correction, hex-word false-positive guards (deadbeefcafe, face:beef:cafe, cisco, 3com), Unicode-fancy punctuation (en-dashes, tabs, NBSP), multi-MAC inputs, and pathological empties / overlong runs.
  • The rig emits a Markdown report; the snapshot is committed at tests/fixtures/chaos_report.md so reviewers can read corpus + behavior side by side without running the rig.
  • Wired into unittest via tests/test_chaos_rig.py so the existing CI step picks it up — total Python tests goes from 34 → 37.
  • Defect surfaced & fixed: 1-800-555-1234 was being cleaned into the fake MAC 18005551234. Reason: the candidate scorer only required that the hex-only length sit in 6-12 chars; pure-digit phone shapes slipped through. Fix in maclookup.py:_has_macish_grouping (and mirrored in web/app.js:hasMacishGrouping): when a separator-bearing token has no hex letters (a–f), require every separator-delimited group to be uniformly 2 or 4 chars. Keeps 01:23:45:67:89:01 (2/2/2/2/2/2) and 0123.4567.8901 (4/4/4) working; rejects 1-800-555-1234 (1/3/3/4) and (415) 555-1212-shaped strings.
  • Takeaways doc at tests/fixtures/chaos_takeaways.md records the higher-level findings: en-dashes accidentally reassemble, OCR I/l correction can legitimately end up partial, hex blobs outside 6-12 chars are rejected outright, etc.

Running the rig

```
python3 tests/chaos_rig.py # plain-text summary
python3 tests/chaos_rig.py --md # Markdown report to stdout
python3 tests/chaos_rig.py --strict # exits 1 on any mismatch
python3 tests/chaos_rig.py --md --out tests/fixtures/chaos_report.md
```

Test plan

  • `python3 -m unittest discover -s tests` (37 tests, all pass)
  • `python3 tests/chaos_rig.py --strict` (67/67 cases match expectations)
  • `node tests/web/fresh_load.mjs`
  • `node tests/web/i18n_smoke.mjs`
  • `node tests/web/mac_formats.mjs` (now includes phone-number rejection assertions)
  • `node --check web/app.js && node --check web/sw.js && node --check web/i18n.js`

🤖 Generated by Computer

Adds tests/chaos_rig.py and tests/chaos_corpus.py: 67 messy real-world
inputs (Windows ipconfig, Linux ip-link, Cisco show interfaces, BIOS
labels, JSON/HTML/email pastes, wrappers, OCR typos, en-dashes,
multi-MAC inputs, hex-word false positives, length boundaries) with a
pinned expected outcome each. The rig classifies every result as match /
match_ocr / partial / none, emits a Markdown report, and is wired into
unittest via tests/test_chaos_rig.py so regressions fail CI.

Running the rig surfaced one real defect: 1-800-555-1234 was cleaned
into the fake MAC 18005551234 because the extractor only checked that
the hex-only length sat in 6-12. Fixed by requiring pure-digit
separator-bearing tokens to use a uniform group size of 2 or 4 chars
(real MAC formats), which keeps 01:23:45:67:89:01 and 0123.4567.8901
working while rejecting 1/3/3/4 phone shapes. Same guard applied to
web/app.js. The Python and JS smoke tests both pin the new behavior.

tests/fixtures/chaos_report.md is the committed snapshot of the rig's
output so reviewers can read the corpus and the behavior side by side.
tests/fixtures/chaos_takeaways.md summarizes the higher-level findings.
@StewAlexander-com
StewAlexander-com marked this pull request as ready for review May 27, 2026 21:50
@StewAlexander-com
StewAlexander-com merged commit ad3cbea into main May 27, 2026
1 check passed
@StewAlexander-com
StewAlexander-com deleted the chaos-test-rig branch May 27, 2026 21:50
StewAlexander-com added a commit that referenced this pull request May 27, 2026
…prefixes (#14)

PR #13 added a group-uniformity guard to the candidate scorer but
lookup_detailed / macLookupDetailed had a separate fast path that fed
normalize_mac(input) straight into the prefix matcher. Phone digits
like '1-800-555-1234' survived normalize_mac (which only strips
[-:.\s]) as 11 hex-valid chars, passed the 6-12 window, and surfaced
as 'No registry entry for prefix 180055512' in the live PWA.

This change adds _normalized_input_is_mac_shaped (Python) and
normalizedInputIsMacShaped (JS) which apply the same group rule to the
raw input before the fast path is allowed to set 'cleaned'. The rule
is also broadened to accept group sizes in {2, 4, 6} (canonical 6x2,
Cisco 3x4, half-and-half 6/6, truncated 4/2 like '0000.00'); tokens
with 4 or more groups must additionally be uniformly sized so a UK
phone like '+44-20-7946-0958' (2/2/4/4) still gets rejected.

Tests:
- chaos corpus picks up bare 1-800-555-1234, 555-1234,
  (415) 555-1212, +44-20-7946-0958, 192.168.1.1, 10.0.0.1 with
  expect=none, pinning cleaned=None so the live regression can't
  recur.
- test_no_phone_numbers_become_macs now also asserts
  lookup_detailed(...).cleaned is None for each phone -- catching
  the actual UI-facing failure, not just extract_mac_candidates.
- tests/web/mac_formats.mjs exports the new JS helpers and runs a
  simulated macLookupDetailed against phone and MAC inputs to assert
  the same outcome on the PWA side.
- Regenerated tests/fixtures/chaos_report.md (73/73 cases pass) and
  updated tests/fixtures/chaos_takeaways.md to document both defects.

Co-authored-by: Claude Code <claude-code@anthropic.com>
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.

2 participants