Skip to content

Commit 7327a9a

Browse files
Copilotdata-douser
andcommitted
Add client integration tests for codeql_query_run with Rust language
- rust_tools_print_ast: Tests PrintAST query with graphtext format interpretation, including expected graphtext output for AST visualization - rust_call_graph_from_example1: Tests CallGraphFrom query with SARIF format interpretation and external predicates for source function selection Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/ee9dfe2b-a152-4a44-88b9-6e9c2b7bc831 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
1 parent b488914 commit 7327a9a

File tree

7 files changed

+685
-0
lines changed

7 files changed

+685
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Integration Test: codeql_query_run/rust_call_graph_from_example1
2+
3+
## Purpose
4+
5+
Tests the `codeql_query_run` tool with the CallGraphFrom query for Rust language, demonstrating external predicates for source function selection and SARIF format interpretation for call graph visualization.
6+
7+
## Test Scenario
8+
9+
This test validates that the `codeql_query_run` tool can:
10+
11+
1. Accept `queryName` ("CallGraphFrom") and `queryLanguage` ("rust") parameters
12+
2. Accept `sourceFunction` parameter to specify which function's outbound calls to analyze
13+
3. Resolve the query path using `codeql resolve queries` to find the CallGraphFrom.ql query
14+
4. Automatically provide external predicates for the sourceFunction
15+
5. Execute the resolved query against a Rust test database with external predicate data
16+
6. Interpret the .bqrs results using native `codeql bqrs interpret --format=sarif-latest`
17+
7. Generate SARIF format output containing call graph results
18+
8. Return enhanced results confirming the interpretation succeeded
19+
20+
## Required Inputs
21+
22+
The test requires the following inputs in `before/monitoring-state.json`:
23+
24+
- `queryName`: "CallGraphFrom" - Name of the query to resolve and execute
25+
- `queryLanguage`: "rust" - Programming language for query resolution
26+
- `database`: "server/ql/rust/tools/test/CallGraphFrom/CallGraphFrom.testproj" - Path to CodeQL test database
27+
- `sourceFunction`: "source_func" - Source function name to analyze (used as external predicate)
28+
- `output`: "query-results.bqrs" - Output file for binary query results
29+
- `format`: "sarif-latest" - SARIF format for interpreting @kind problem query results
30+
- `interpretedOutput`: "query-results.sarif" - Output file for SARIF format results
31+
- `timeout`: 300000 - Timeout in milliseconds (5 minutes)
32+
33+
The test database is created by running `codeql test extract server/ql/rust/tools/test/CallGraphFrom`.
34+
35+
## Expected Outputs
36+
37+
The test expects the following behavior:
38+
39+
- `monitoring-state.json`: Test execution state showing success
40+
- The tool generates `query-results.bqrs` (binary query results, not committed to repo)
41+
- The tool interprets results using `codeql bqrs interpret --format=sarif-latest`
42+
- The SARIF output contains call graph entries showing calls from `source_func` to `unrelated1` and `unrelated2`
43+
- The monitoring state confirms successful execution and interpretation
44+
45+
## Expected Behavior
46+
47+
The tool should:
48+
49+
1. Resolve "CallGraphFrom" to the absolute path of `server/ql/rust/tools/src/CallGraphFrom/CallGraphFrom.ql`
50+
2. Automatically add external predicate: `sourceFunction=source_func`
51+
3. Execute the query against the provided database with the external predicate data
52+
4. Generate query results in BQRS format
53+
5. Call `codeql bqrs interpret` with format=sarif-latest
54+
6. Generate SARIF output showing calls from the source function
55+
7. Return enhanced output confirming the interpretation succeeded
56+
57+
## External Predicates Integration
58+
59+
This test demonstrates the integration between the MCP server's sourceFunction parameter and CodeQL's external predicates system. The CallGraphFrom query uses `external string sourceFunction()` to receive the function name, making it work with any Rust code database.
60+
61+
## Format Parameter
62+
63+
This test uses the `format` parameter which leverages native CodeQL tooling (`codeql bqrs interpret`) to produce SARIF output based on query metadata.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"toolName": "codeql_query_run",
3+
"parameters": {
4+
"queryName": "CallGraphFrom",
5+
"queryLanguage": "rust",
6+
"database": "server/ql/rust/tools/test/CallGraphFrom/CallGraphFrom.testproj",
7+
"sourceFunction": "source_func",
8+
"output": "query-results.bqrs",
9+
"format": "sarif-latest",
10+
"interpretedOutput": "query-results.sarif",
11+
"timeout": 300000
12+
},
13+
"success": true,
14+
"description": "Successfully executed CallGraphFrom (@kind problem) query using query name resolution with external predicates and SARIF format interpretation for Rust language"
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"toolName": "codeql_query_run",
3+
"parameters": {
4+
"queryName": "CallGraphFrom",
5+
"queryLanguage": "rust",
6+
"database": "server/ql/rust/tools/test/CallGraphFrom/CallGraphFrom.testproj",
7+
"sourceFunction": "source_func",
8+
"output": "query-results.bqrs",
9+
"format": "sarif-latest",
10+
"interpretedOutput": "query-results.sarif",
11+
"timeout": 300000
12+
},
13+
"expectedSuccess": true,
14+
"description": "Test codeql_query_run with queryName resolution for CallGraphFrom (@kind problem) query using external predicates and SARIF format interpretation for Rust language"
15+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Integration Test: codeql_query_run/rust_tools_print_ast
2+
3+
## Purpose
4+
5+
Tests the `codeql_query_run` tool with the PrintAST query for Rust language, demonstrating external predicates for source file selection and graphtext format interpretation for AST visualization.
6+
7+
## Test Scenario
8+
9+
This test validates that the `codeql_query_run` tool can:
10+
11+
1. Accept `queryName` ("PrintAST") and `queryLanguage` ("rust") parameters
12+
2. Accept `sourceFiles` parameter to specify which source files to analyze
13+
3. Resolve the query path using `codeql resolve queries` to find the PrintAST.ql query
14+
4. Automatically provide external predicates for the selectedSourceFiles
15+
5. Execute the resolved query against a Rust test database with external predicate data
16+
6. Interpret the .bqrs results using native `codeql bqrs interpret -t kind=graph -t id=rust/tools/print-ast --format=graphtext`
17+
7. Generate graphtext format output representing the AST graph structure
18+
8. Return enhanced results confirming the interpretation succeeded
19+
20+
## Required Inputs
21+
22+
The test requires the following inputs in `before/monitoring-state.json`:
23+
24+
- `queryName`: "PrintAST" - Name of the query to resolve and execute
25+
- `queryLanguage`: "rust" - Programming language for query resolution
26+
- `database`: "server/ql/rust/tools/test/PrintAST/PrintAST.testproj" - Path to CodeQL test database
27+
- `sourceFiles`: "server/ql/rust/tools/test/PrintAST/Example1.rs" - Source file(s) to analyze (used as external predicate)
28+
- `output`: "query-results.bqrs" - Output file for binary query results
29+
- `format`: "graphtext" - Native CodeQL format for interpreting @kind graph query results
30+
- `interpretedOutput`: "query-results" - Output directory for graphtext format results
31+
32+
The test database should be pre-created at `server/ql/rust/tools/test/PrintAST/PrintAST.testproj` by running `codeql test extract server/ql/rust/tools/test/PrintAST`.
33+
34+
## Expected Outputs
35+
36+
The test expects the following behavior:
37+
38+
- `monitoring-state.json`: Test execution state showing success
39+
- The tool generates `query-results.bqrs` (binary query results, not committed to repo)
40+
- The tool interprets results using `codeql bqrs interpret -t kind=graph -t id=rust/tools/print-ast --format=graphtext`
41+
- The interpreted output is written to a directory structure at `query-results/`
42+
- The monitoring state confirms successful execution and interpretation
43+
44+
## Expected Behavior
45+
46+
The tool should:
47+
48+
1. Resolve "PrintAST" to the absolute path of `server/ql/rust/tools/src/PrintAST/PrintAST.ql`
49+
2. Automatically add external predicate: `selectedSourceFiles=Example1.rs`
50+
3. Execute the query against the provided database with the external predicate data
51+
4. Generate query results in BQRS format
52+
5. Call `codeql bqrs interpret` with format=graphtext and appropriate metadata (-t kind=graph -t id=rust/tools/print-ast)
53+
6. Generate graphtext format output showing the AST structure for the selected Rust source file
54+
7. Return enhanced output confirming the interpretation succeeded
55+
56+
## External Predicates Integration
57+
58+
This test demonstrates the integration between the MCP server's sourceFiles parameter and CodeQL's external predicates system. The PrintAST query uses `external string selectedSourceFiles()` to receive file paths, making it work with any Rust code database rather than being limited to test directories.
59+
60+
## Format Parameter
61+
62+
This test uses the `format` parameter which leverages native CodeQL tooling (`codeql bqrs interpret`) to produce properly formatted output based on query metadata, rather than custom post-processing.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"toolName": "codeql_query_run",
3+
"parameters": {
4+
"queryName": "PrintAST",
5+
"queryLanguage": "rust",
6+
"database": "server/ql/rust/tools/test/PrintAST/PrintAST.testproj",
7+
"sourceFiles": "server/ql/rust/tools/test/PrintAST/Example1.rs",
8+
"output": "query-results.bqrs",
9+
"format": "graphtext",
10+
"interpretedOutput": "query-results"
11+
},
12+
"success": true,
13+
"description": "Successfully executed PrintAST query using query name resolution with external predicates and graphtext format interpretation for Rust language"
14+
}

0 commit comments

Comments
 (0)