Skip to content

[UPDATE PRIMITIVE] Refresh rust PrintAST/PrintCFG .expected to match macro-expanded output#270

Merged
enyil merged 1 commit intocodeql/upgrade-to-v2.25.3from
copilot/fix-query-unit-tests
May 4, 2026
Merged

[UPDATE PRIMITIVE] Refresh rust PrintAST/PrintCFG .expected to match macro-expanded output#270
enyil merged 1 commit intocodeql/upgrade-to-v2.25.3from
copilot/fix-query-unit-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

The Query Unit Tests - rust job was failing because server/ql/rust/tools/test/PrintAST/PrintAST.expected and PrintCFG/PrintCFG.expected did not include the getMacroCallExpansion() subtrees that the rust extractor emits when a Rust toolchain is available (as in CI via install-language-runtimes: true). A previous refresh attempt captured only a partial expansion.

📝 Update Information

Primitive Details

  • Type: Tool (test fixtures)
  • Name: rust PrintAST / PrintCFG queries
  • Update Category: Bug Fix (test fixture refresh)

⚠️ CRITICAL: PR SCOPE VALIDATION

✅ Only .expected test fixtures under server/ql/rust/tools/test/ are touched.


🛑 MANDATORY PR VALIDATION CHECKLIST

  • NO temporary or output files included
  • NO unrelated configuration files included
  • ALL existing tests continue to pass (5/5 rust query unit tests)

  • Impact Scope: Localized (test fixtures only)

Update Metadata

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

🎯 Changes Description

Current Behavior

CI runs the rust query unit tests with the Rust toolchain present, so MacroCall.getMacroCallExpansion() resolves to expanded AST/CFG nodes (e.g. vec!, println!, format_args_nl!). The committed .expected files only contained the unexpanded variant, so PrintAST and PrintCFG failed with FAILED(RESULT).

Updated Behavior

.expected files now contain the fully macro-expanded AST/CFG output produced by the same query + extractor combination CI uses.

Motivation

Unblock CI on the v2.25.3 upgrade branch.

🔄 Before vs. After Comparison

Functionality Changes

No query, schema, or output-format changes. Only .expected fixtures regenerated via:

codeql test run --learn \
  --additional-packs=server/ql/rust/tools \
  -- server/ql/rust/tools/test/PrintAST \
     server/ql/rust/tools/test/PrintCFG

Output Format Changes

Expected fixtures now include getMacroCallExpansion() subtrees, e.g.:

#   24|               getTokenTree(): [TokenTree] TokenTree
+#   24|               getMacroCallExpansion(): [CallExpr] ...::into_vec(...)
+#   24|                 getArgList(): [ArgList] ArgList
...

and CFG edges are corrected from ...::format_args_nl!... placeholders to the expanded FormatArgsExpr / template-string targets.

🧪 Testing & Validation

Test Results

  • codeql test run for server/ql/rust/tools/test: 5/5 passed locally with rustc available, matching CI's environment.

📋 Implementation Details

Files Modified

  • server/ql/rust/tools/test/PrintAST/PrintAST.expected (+105)
  • server/ql/rust/tools/test/PrintCFG/PrintCFG.expected (+34/-4)

Code Changes Summary

  • Test fixture refresh to match macro-expanded extractor output

Dependencies

  • No New Dependencies

🔍 Quality Improvements

Bug Fixes

  • Issue: Query Unit Tests - rust job failed on PrintAST.qlref and PrintCFG.qlref.
  • Root Cause: Prior .expected regeneration was performed against an extractor run without macro expansion, so the fixtures lacked getMacroCallExpansion() subtrees that CI consistently produces.
  • Solution: Re-ran codeql test run --learn with the Rust toolchain installed locally, capturing the canonical expanded output.
  • Prevention: Future .expected regenerations for rust must be performed with rustc/cargo on PATH, equivalent to install-language-runtimes: true in CI.

🚀 Compatibility & Migration

Backward Compatibility

  • Fully Compatible

👥 Review Guidelines

Testing Instructions

./server/scripts/run-query-unit-tests.sh --language rust

Requires rustc/cargo on PATH to reproduce CI's macro expansion behavior.

📊 Impact Assessment

Test fixtures only — no runtime, server, or AI-assistant impact.

🔄 Deployment Strategy

  • Safe Deployment: fixture-only change

Update Methodology:

  1. ✅ Reproduced CI failure locally
  2. ✅ Regenerated fixtures via codeql test run --learn against the same extractor configuration as CI
  3. ✅ Verified all 5 rust query unit tests pass

@enyil enyil marked this pull request as ready for review May 4, 2026 18:49
@enyil enyil requested review from a team, data-douser and enyil as code owners May 4, 2026 18:49
@enyil enyil merged commit f5fa9f1 into codeql/upgrade-to-v2.25.3 May 4, 2026
@enyil enyil deleted the copilot/fix-query-unit-tests branch May 4, 2026 18:49
data-douser added a commit that referenced this pull request May 4, 2026
* Upgrade CodeQL CLI dependency to v2.25.3

* Fix upgrade-packs.sh to actually refresh pack lock files

Previously, codeql pack upgrade was a no-op for packs with pinned
codeql/<lang>-all dependencies because the existing pin already
satisfied the constraint. This left codeql-pack.lock.yml files
unchanged across CLI bumps, even though newer compatible library
pack versions were available.

The fix temporarily rewrites the pinned dependency to a wildcard
before running codeql pack upgrade, then restores the manifest and
pins it to the version resolved into the lock file.

Also regenerates all pack lock files and re-pins manifests against
CodeQL CLI v2.25.3, and refreshes ruby/rust/swift PrintAST/PrintCFG
.expected files for benign output ordering and library behavior
changes introduced by the upgraded codeql/*-all packs.

* Skip update-codeql cron run when upgrade branch already exists

Adds a 'check-existing-branch' job that runs after detect-update and
gates the create-pr job. On scheduled (cron) runs, if the target
'codeql/upgrade-to-vX.Y.Z' branch already exists on origin, the rest
of the pipeline is skipped so peter-evans/create-pull-request does
not force-push over reviewer commits or follow-up fixes (such as
manually-applied lock-file refreshes).

The check is bypassed on workflow_dispatch so a maintainer can
always force a refresh by re-running the workflow manually.

* Refresh rust PrintAST/PrintCFG expected with rust toolchain installed

CI runs query unit tests with install-language-runtimes: true, which
makes rustc/cargo available to the rust extractor and causes println!
and similar macros to be expanded to their stdlib internals
was performed without rust installed locally, so the expected files
captured the collapsed output and did not match CI.

Re-learned with rustc 1.95.0 installed via rustup, matching the CI
runner environment.

* Refresh rust PrintAST/PrintCFG expected to match macro expansion output (#270)

Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/beb1ad8c-da44-4beb-8483-c2b6d9e1f2b7

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: enyil <87337678+enyil@users.noreply.github.com>

---------

Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Co-authored-by: Nathan Randall <data-douser@github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: enyil <87337678+enyil@users.noreply.github.com>
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.

2 participants