Skip to content

Document and test sarif_list_rules per-rule resultCount field#219

Merged
data-douser merged 6 commits intomainfrom
copilot/add-result-count-field-to-sarif-list-rules
Apr 6, 2026
Merged

Document and test sarif_list_rules per-rule resultCount field#219
data-douser merged 6 commits intomainfrom
copilot/add-result-count-field-to-sarif-list-rules

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

📝 Update Information

Primitive Details

  • Type: Tool
  • Name: sarif_list_rules
  • Update Category: Feature Enhancement, Documentation

⚠️ CRITICAL: PR SCOPE VALIDATION

ALLOWED FILES:

  • Server implementation files (server/src/**/*.ts)
  • Updated test files (server/test/**/*.ts)
  • Documentation updates (server/src/resources/server-tools.md)

🚫 FORBIDDEN FILES:

  • None included

🛑 MANDATORY PR VALIDATION CHECKLIST

  • ONLY server implementation files are included
  • NO temporary or output files are included
  • NO unrelated configuration files are included
  • ALL existing tests continue to pass
  • NEW functionality is properly tested

  • Impact Scope: Localized (resource documentation + test file)

Update Metadata

  • Breaking Changes: No
  • API Compatibility: Maintained
  • Performance Impact: Neutral

🎯 Changes Description

Current Behavior

The resultCount field is implemented in SarifRuleSummary, listSarifRules(), and the sarif_list_rules tool response. However, the per-rule resultCount field and complete response schema were not documented in the server-tools.md MCP resource served to LLMs at runtime. Additionally, the tool-level test only asserted resultCount on the first rule, used a fixture where every rule had exactly 1 result (making off-by-one bugs invisible), and had no test for zero-result rules.

Updated Behavior

The server/src/resources/server-tools.md resource now includes a sarif_list_rules Response Format section documenting the per-rule resultCount field, complete JSON response example, top-level summary fields (totalRules, totalResults), and per-rule field reference table with types and required/optional markers. Test fixture now has varying result counts per rule (2 vs 1). Assertions cover resultCount on every rule. A dedicated test validates resultCount: 0 for defined-but-untriggered rules.

Motivation

The per-rule resultCount field and response schema were undocumented in the MCP resource served to LLMs, making it harder for AI assistants to understand the tool's output format. The existing tool-level test could not distinguish a correct implementation from one that always returns 1. These changes close both gaps.

🔄 Before vs. After Comparison

Documentation Changes

<!-- BEFORE: server-tools.md only had a one-line description -->
| `sarif_list_rules` | List all rules in a SARIF file with result counts, severity, precision, and tags |

<!-- AFTER: server-tools.md includes full response format documentation -->
### `sarif_list_rules` Response Format

Returns a JSON object with per-rule result counts and metadata:
{
  "totalRules": 3,
  "totalResults": 15,
  "rules": [
    {
      "ruleId": "js/sql-injection",
      "resultCount": 8,
      ...
    }
  ]
}

| Field         | Type   | Required | Description                                                                  |
| ------------- | ------ | -------- | ---------------------------------------------------------------------------- |
| `resultCount` | number | yes      | Number of results (findings) for this rule; `0` if defined but not triggered |
...

Test Fixture Changes

// BEFORE: 1 result per rule — can't detect constant-1 bugs
results: [
  { ruleId: 'js/sql-injection', ... },  // 1 result
  { ruleId: 'js/xss', ... },            // 1 result
]

// AFTER: Varying counts (2 vs 1) — actually tests counting logic
results: [
  { ruleId: 'js/sql-injection', ... },  // result 1
  { ruleId: 'js/sql-injection', ... },  // result 2
  { ruleId: 'js/xss', ... },            // 1 result
]

New Test Case

it('should return resultCount 0 for rules with no results', async () => {
  // Rule defined in driver.rules but zero matching results
  expect(parsed.rules[0].resultCount).toBe(0);
  expect(parsed.totalResults).toBe(0);
});

🧪 Testing & Validation

Test Coverage Updates

  • Existing Tests: All 1250 server tests pass
  • New Test Cases: Zero-result rule scenario added
  • Regression Tests: Updated dependent assertions (sarif_extract_rule, sarif_diff_runs) for enriched fixture
  • Edge Case Tests: Zero results, varying counts per rule

Test Results

  • Unit Tests: All pass (1250/1250)
  • Lint: Clean
  • CodeQL Security Scan: No alerts

📋 Implementation Details

Files Modified

  • Documentation: server/src/resources/server-tools.md — Added sarif_list_rules Response Format section with JSON example, field tables, and per-rule resultCount documentation
  • Tests: server/test/src/tools/sarif-tools.test.ts — Enhanced test coverage for per-rule resultCount

Code Changes Summary

  • Added sarif_list_rules Response Format section to server-tools.md with JSON example, top-level field descriptions, and per-rule field reference table
  • Added second js/sql-injection result to createTestSarif() fixture for varying counts
  • Extracted createZeroResultsSarif() helper (consistent with existing fixture pattern)
  • Asserted resultCount for all rules in sarif_list_rules test
  • Added 'should return resultCount 0 for rules with no results' test
  • Updated sarif_extract_rule expected count from 1→2
  • Changed sarif_diff_runs result filtering to filter() instead of index-based splice

Dependencies

  • No New Dependencies

🔗 References

Related Issues/PRs

🚀 Compatibility & Migration

Backward Compatibility

  • Fully Compatible: Documentation and test-only changes, no behavioral changes

API Evolution

  • No API changes — documents existing response format

👥 Review Guidelines

For Reviewers

  • ⚠️ SCOPE COMPLIANCE: Resource documentation file and test file changed
  • ⚠️ NO UNRELATED FILES: Confirmed
  • ⚠️ BACKWARD COMPATIBILITY: No production behavior changes

Testing Instructions

# Run SARIF tool tests
cd server && npx vitest run test/src/tools/sarif-tools.test.ts --reporter=verbose

# Verify formatting
npm run format:check
npm run lint

Copilot AI requested review from Copilot and removed request for Copilot April 6, 2026 15:05
Copilot AI linked an issue Apr 6, 2026 that may be closed by this pull request
1 task
- Add second sql-injection result to test fixture for varied counts
- Verify resultCount for all rules (not just the first)
- Add test for rules with zero results (resultCount: 0)
- Update related test assertions for the enriched fixture

Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/7ea1caeb-de6d-40cd-b045-3dd634602403

Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 6, 2026 15:27
Address code review feedback: extract inline SARIF object into
createZeroResultsSarif() helper for consistency with existing patterns.

Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/7ea1caeb-de6d-40cd-b045-3dd634602403

Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 6, 2026 15:29
Copilot AI changed the title [WIP] Add per-rule resultCount field to sarif_list_rules Enhance sarif_list_rules test coverage for per-rule resultCount Apr 6, 2026
Copilot AI requested a review from data-douser April 6, 2026 15:31
Copy link
Copy Markdown
Collaborator

@data-douser data-douser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This PR should not be a test-only PR. The original issue #214 requires the per-rule resultCount field in the standard response data structure of the sarif_list_rules MCP tool.

Document the per-rule resultCount field and complete response schema
in the MCP resource file served to LLMs at runtime. Includes JSON
example, top-level field descriptions, and per-rule field reference
with types and required/optional markers.

Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/c1d03a5c-2041-41bb-a120-365ddf420c5b

Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 6, 2026 15:54
Copilot AI requested review from Copilot and removed request for Copilot April 6, 2026 15:55
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 6, 2026

@copilot This PR should not be a test-only PR. The original issue #214 requires the per-rule resultCount field in the standard response data structure of the sarif_list_rules MCP tool.

Added production changes in d21f47a: server/src/resources/server-tools.md now includes a sarif_list_rules Response Format section documenting the per-rule resultCount field, complete response schema with JSON example, top-level summary fields, and per-rule field reference table with types and required/optional markers. This resource file is served to LLMs at runtime via the MCP server.

Note: the resultCount field was already implemented in the SarifRuleSummary interface, listSarifRules() function, and sarif_list_rules tool response on main — the resource documentation was the missing production artifact.

Copilot AI changed the title Enhance sarif_list_rules test coverage for per-rule resultCount Document and test sarif_list_rules per-rule resultCount field Apr 6, 2026
Copilot AI requested a review from data-douser April 6, 2026 15:57
Copilot AI review requested due to automatic review settings April 6, 2026 16:31
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA cedcddc.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

  • package-lock.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the usability of the sarif_list_rules MCP tool by documenting the full response schema (including per-rule resultCount) in the runtime-served tools resource, and by strengthening tests to validate varying and zero-result scenarios.

Changes:

  • Expanded server-tools.md with a detailed sarif_list_rules response format section (example JSON + field tables).
  • Updated SARIF test fixtures and assertions to validate per-rule resultCount across multiple rules and a zero-results rule.
  • Regenerated the bundled server output to include the updated resource content.
Show a summary per file
File Description
server/test/src/tools/sarif-tools.test.ts Enhances SARIF tool tests to catch constant/incorrect counting and validate zero-result rules.
server/src/resources/server-tools.md Documents sarif_list_rules output schema for LLM consumers (per-rule and summary fields).
server/dist/codeql-development-mcp-server.js Updates bundled artifact to include the latest server-tools.md content.
package-lock.json Lockfile change included in PR scope (appears unrelated to the stated “no dependencies” change).

Copilot's findings

  • Files reviewed: 2/5 changed files
  • Comments generated: 0

@data-douser data-douser marked this pull request as ready for review April 6, 2026 16:55
@data-douser data-douser requested review from a team and enyil as code owners April 6, 2026 16:55
@data-douser data-douser merged commit 2cf8b49 into main Apr 6, 2026
24 checks passed
@data-douser data-douser deleted the copilot/add-result-count-field-to-sarif-list-rules branch April 6, 2026 16:57
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.

sarif_list_rules: add per-rule resultCount field

3 participants