feat: add structural metadata to search JSON for evidence filtering#556
feat: add structural metadata to search JSON for evidence filtering#556
Conversation
…ut (#555) Adds structural metadata fields to JSON search output so downstream tools can reliably distinguish test evidence from docs, fenced examples, and implementation declarations without custom heuristics: - scope: "test" | "function" | "declaration" | "module" | "doc" | "example" - is_doc: true for markdown/docs/help files (omitted when false) - is_example: true for fenced code blocks in docs (omitted when false) - owner_symbol: owning function/class/method name extracted from code - Fix is_test: no longer set true for fenced code examples in docs Consumers can now filter `scope === "test"` for evidence-only results. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PR Overview: Add Structural Metadata to Search JSON for Evidence FilteringSummaryThis PR adds structural metadata fields to JSON search output, enabling downstream tools (ReqProof, traceability tools, test-mapping tools) to reliably filter requirement evidence without custom heuristics. The change fixes issue #555 where fenced code blocks in markdown documentation were incorrectly flagged as test code. Files Changed
Key Technical Changes1. New JSON Output Fields
2. Bug Fix: Fenced Code No Longer Flagged as TestBefore: A fenced code block in markdown containing After: Documentation files are excluded from test detection logic: let doc = is_doc_file(file_path);
let fenced_example = doc && is_fenced_example(&r.node_type);
let file_is_test = !doc && is_test_file(file_path);
let code_is_test = !doc && !file_is_test && is_test_code_block(&r.code, &r.node_type);3. Documentation File DetectionThe
4. Scope Classification LogicThe
5. Owner Symbol ExtractionThe
Architecture & ImpactComponent Relationshipsgraph TD
A[Search Results] --> B[format_and_print_json_results]
B --> C[is_doc_file]
B --> D[is_fenced_example]
B --> E[is_test_file / is_test_code_block]
B --> F[classify_scope]
B --> G[extract_owner_symbol]
C --> H[JsonResult with metadata]
D --> H
E --> H
F --> H
G --> H
H --> I[JSON Output]
J[Downstream Tools] --> I
K[ReqProof] --> I
L[Traceability Tools] --> I
M[Test-Mapping Tools] --> I
Data FlowsequenceDiagram
participant CLI as probe search
participant Output as search_output.rs
participant JSON as JsonResult
participant Consumer as Downstream Tool
CLI->>Output: SearchResults with file, node_type, code
Output->>Output: is_doc_file(path)
Output->>Output: is_fenced_example(node_type)
Output->>Output: is_test_file(path) & is_test_code_block()
Output->>Output: classify_scope(node_type, code, ...)
Output->>Output: extract_owner_symbol(code, node_type)
Output->>JSON: Populate all fields
Output->>Consumer: JSON with scope, is_doc, is_example, owner_symbol
Consumer->>Consumer: Filter by scope === "test"
Scope Discovery & ContextAffected System Components
Integration Points
Test Coverage24 New Unit Tests:
3 Integration Tests:
Existing Tests: All 361 unit tests, 11 integration tests, 21 CLI tests pass Example UsageBefore (Incorrect){
"file": "docs/help/checks/code_mcdc_coverage.md",
"node_type": "fenced_code_block",
"code": "```go
func TestShared(t *testing.T) {}
```",
"is_test": true
}After (Correct){
"file": "docs/help/checks/code_mcdc_coverage.md",
"node_type": "fenced_code_block",
"code": "```go
func TestShared(t *testing.T) {}
```",
"scope": "example",
"is_doc": true,
"is_example": true,
"owner_symbol": "TestShared"
}Filtering for Evidence# Get only test evidence (exclude docs and implementation)
probe search --allow-tests --format json "SYS-REQ-985" | \
jq '.results[] | select(.scope == "test")'
# Get owner symbols for test mapping
probe search --format json "requirement" | \
jq '.results[] | {file: .file, owner: .owner_symbol, scope: .scope}'ReferencesModified Files:
Related Files (Context):
Metadata
Powered by Visor from Probelabs Last updated: 2026-04-06T09:46:29.180Z | Triggered by: pr_opened | Commit: 2a3eeba 💡 TIP: You can chat with Visor using |
Architecture Issues (1)
Performance Issues (1)
Architecture Issues (1)
Powered by Visor from Probelabs Last updated: 2026-04-06T09:42:59.363Z | Triggered by: pr_opened | Commit: 2a3eeba 💡 TIP: You can chat with Visor using |
Summary
Fixes #555 — adds structural metadata fields to JSON search output so downstream tools (ReqProof, traceability tools, test-mapping tools) can reliably filter requirement evidence without custom heuristics.
New JSON fields
scope"test"|"function"|"declaration"|"module"|"doc"|"example"is_doctruefor markdown/docs/help files (omitted when false)is_exampletruefor fenced code blocks in docs (omitted when false)owner_symbolFixes
is_testno longer set true for fenced code examples in docs — afenced_code_blockin a markdown file that containsfunc TestFoo()was incorrectly flaggedis_test: truescopeclassifies blocks structurally — consumers can filterscope === "test"for evidence-only resultsExample output
For
probe search --allow-tests --exact --no-merge -o json SYS-REQ-985:Test plan
is_doc_file,is_fenced_example,classify_scope,extract_owner_symbol, and 3 integration-level testsis_test: true🤖 Generated with Claude Code