|
| 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 extensible predicates system. The CallGraphFrom query uses `extensible predicate sourceFunction(string name)` to receive the function name via data extensions, 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. |
0 commit comments