resolver: implement bare-namespace cross-source search (Python -> 10/10 conformance)#10
Merged
Merged
Conversation
Phase 2.5(d). Closes the last conformance failure — Python Server-API now passes 10/10 fixtures, matching the canonical SecID-Service Worker. When a query like `secid:advisory/CVE-2021-44228` has no DNS-rooted namespace match (the input is an ID, not a domain), the resolver now walks all namespaces of the type looking for child patterns that match the input. Aggregates results sorted by weight descending. Implementation in resolver.py: - _slug_from_pattern(pat) — extracts canonical source slug from a source-level regex like '(?i)^cve$' -> 'cve'. Returns None for complex patterns where a clean slug isn't extractable. - _all_namespaces_of_type(store, secid_type, registry_dirs) — enumerates known namespaces from both the store and filesystem. Filesystem-discovered namespaces are eagerly loaded into the store so subsequent queries don't re-read them. Uses the 'namespace' field inside each JSON file as canonical, avoiding the reverse-DNS path-to-namespace ambiguity (e.g., 'uk/gov/legislation.json' is unambiguously 'legislation.gov.uk' once we read the file). - _cross_source_search(store, secid_type, search_term, registry_dirs) — for each namespace, walks one level of children looking for pattern matches. Builds a full-namespace SecID for each match, substitutes URL templates (reusing the helper from Phase 2.5a), sorts by weight descending. Hook in resolve(): when `_match_namespace()` returns no match, fall back to cross-source. If cross-source finds results, return them with status=found. Otherwise return not_found as before. Behavior: Worker (canonical): 21 results for secid:advisory/CVE-2021-44228 Python (this PR): 18 results The 3-result gap likely reflects (a) Python walking one level of children only (no grandchildren), (b) some namespaces having patterns the Worker indexes differently. The fixture's `min_results >= 5` intentionally allows this tolerance — cross-source agreement on "many namespaces match" is the contract, not exact result count. Tests: - 5 new unit tests for slug extraction and cross-source edge cases - 28/28 tests pass locally Conformance progression: Initial: 3 / 10 against Python After Phase 2.5(a): 7 / 10 After Phase 2.5(c): 9 / 10 After this PR: 10 / 10 Python now serves as the reference for TS/Go ports. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2.5(d). Closes the last conformance failure — Python Server-API now passes 10/10 fixtures, matching the canonical SecID-Service Worker. Python is now ready to serve as the reference for the TypeScript and Go Server-API ports.
What's added
A new resolution mode: cross-source search. When a query like `secid:advisory/CVE-2021-44228` has no DNS-rooted namespace match (the input is an ID, not a domain), the resolver walks all namespaces of the type, checks each for child-pattern matches against the input, and aggregates results sorted by weight.
Three new helpers in `resolver.py`
Hook in `resolve()`
When `_match_namespace()` returns no match, fall back to cross-source. If results found, status=found. Otherwise not_found as before.
Result counts
The 3-result gap likely reflects (a) Python walks only one level of children (no grandchildren), (b) some namespaces have patterns the Worker indexes differently. The fixture's `min_results >= 5` intentionally allows this tolerance — cross-source agreement on "many namespaces match" is the behavioral contract, not exact-count parity.
Conformance progression
Tests
5 new unit tests for slug extraction and cross-source edge cases. 28/28 pass locally.
What this unblocks
Python Server-API is now at conformance parity with SecID-Service. This unblocks:
🤖 Generated with Claude Code