Skip to content

Requirement annotation search needs evidence-only mode (exclude docs, fenced examples, top-level declarations) #555

@buger

Description

@buger

Problem

probe search --allow-tests --exact --no-merge -o json <REQ-ID> <root> is close to what ReqProof needs for live MC/DC witness discovery, but after upgrading to @probelabs/probe@0.6.0-rc314 it still does not provide a clean "real witness/test blocks only" mode.

rc314 added is_test to JSON output, which helps, but the search still returns mixed results that force downstream tools to maintain a large amount of filtering logic.

What we need

For requirement-annotation search, probe should support a mode that returns only source blocks that are valid requirement evidence candidates, especially test/witness blocks.

In practice we want all of the following:

  1. Include real test / witness code blocks.
  2. Exclude docs and help files.
  3. Exclude fenced code examples from docs.
  4. Exclude top-level implementation declarations that merely carry file-level requirement comments.
  5. Prefer the owning symbol/block over generic surrounding declaration noise.

This should work across languages. The requirement comments are not Go-specific.

Current command

probe search --allow-tests --exact --no-merge -o json SYS-REQ-985 .

Environment used:

  • package: @probelabs/probe@0.6.0-rc314
  • CLI: probe-code 0.6.0

Actual output problem

The results still include all of these categories together:

1. Good results we want

Actual test functions:

  • pkg/workflow/workflow_code_mcdc_test.go
    • TestFormatNestedCodeMCDCProgressSummarizesSharedTestCommandWhenNotVerbose
    • TestSharedCodeMCDCTestRunIsReusedByCoverageCheck

These now include is_test: true, which is useful.

2. Docs/help blocks we do not want

Examples from:

  • docs/help/checks/code_mcdc_coverage.md
  • docs/help/checks/slow_tests_clean.md
  • docs/help/commands/mcdc.md

This also includes fenced examples, for example a Markdown code fence containing:

// Verifies: SYS-REQ-985, SYS-REQ-986
// MCDC SYS-REQ-985: code_mcdc_audit_enabled=F, shared_test_evidence_run=F => TRUE
func TestSharedWorkflowBehavior(t *testing.T) {
    t.Parallel()
}

That block is returned with:

  • node_type: "fenced_code_block"
  • is_test: true

So is_test alone is not enough for consumers.

3. Top-level implementation declarations we do not want

These are still returned as requirement hits even though they are not test/witness blocks:

  • pkg/workflow/workflow.go
  • pkg/workflow/workflow_code_mcdc.go

Those hits come from file-level requirement comments and top-level declarations such as type ... struct{}.

Why this matters

ReqProof is using probe as the backend for live requirement witness discovery. We want source-derived evidence to be evaluated in real time instead of relying on stale regenerated caches.

Right now we still need downstream filtering logic roughly like this:

  • skip docs/, specs/, .proof/, vendor/, node_modules/
  • skip fenced_code_block
  • require either:
    • explicit witness comments, or
    • test-like file / symbol heuristics
  • ignore top-level declarations that only carry broad requirement comments

That works, but it means probe is still not giving us a first-class "requirement evidence blocks" query mode.

Desired solution

Any of the following would solve the problem well:

Option A: add a focused search flag

Something like one of these:

  • --evidence-only
  • --test-evidence-only
  • --requirement-blocks-only

Behavior:

  • include real source blocks that are plausible requirement evidence carriers
  • exclude markdown/docs/fenced code/help examples
  • exclude top-level/module-level declaration noise
  • keep multi-language support

Option B: add stronger structural metadata to JSON

If probe does not want a new filter mode yet, then JSON output should expose enough to let downstream tools do this reliably without brittle heuristics. For example:

  • scope: file | module | declaration | function | test | example
  • is_doc: bool
  • is_example: bool
  • is_fenced_example: bool
  • has_requirement_annotation: bool
  • stable owner/parent identity for the logical block

The new is_test field in rc314 is a good start, but it is not sufficient because fenced Markdown examples can also be marked is_test: true.

Option C: make test/evidence ownership explicit

When a requirement annotation is attached to a comment above a block, return the owning block in a way that lets consumers request only that owning block and not unrelated broader declaration/file context.

Concrete expected behavior for this repro

For:

probe search --allow-tests --exact --no-merge -o json SYS-REQ-985 .

an evidence-focused mode should ideally return only these two blocks from this repo:

  • pkg/workflow/workflow_code_mcdc_test.go:178
  • pkg/workflow/workflow_code_mcdc_test.go:200

and not return:

  • docs/help markdown
  • fenced code examples
  • pkg/workflow/workflow.go
  • pkg/workflow/workflow_code_mcdc.go

Relationship to issue #553

Issue #553 helped clarify duplicate/block-shape behavior. This issue is the next step: even with rc314 and is_test, we still need a first-class way to ask probe for the real requirement evidence blocks only.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions