Skip to content

fix(test): strip inline tests from remote presets on load#227

Merged
fohte merged 5 commits intomainfrom
fohte/fix-test-scope
Mar 17, 2026
Merged

fix(test): strip inline tests from remote presets on load#227
fohte merged 5 commits intomainfrom
fohte/fix-test-scope

Conversation

@fohte
Copy link
Copy Markdown
Owner

@fohte fohte commented Mar 17, 2026

Why

  • runok test evaluates inline tests from remote presets under local overrides, causing them to fail against the preset author's intent
    • e.g., a preset's ask: 'gh api * --paginate *' inline test fails with "expected ask, got deny" due to a local deny override
    • Remote preset inline tests should be validated by the preset itself, not by downstream consumers

What

  • Strip inline tests (RuleEntry.tests) from remote presets on load, excluding them from runok test test case collection
    • Local preset inline tests remain unaffected

Open with Devin

fohte added 3 commits March 18, 2026 01:17
Preset inline tests were evaluated against the full merged config,
causing them to fail when local rules overrode the same patterns with
stricter actions (e.g., preset `ask` overridden by local `deny`).
Inline tests should verify that their rule matches the given command,
not how the entire config evaluates it after downstream overrides.

Resolve extends twice: once without local rules to capture the
preset-only config, once normally for the merged config. Inline tests
whose rule_index falls within the preset range receive the preset
config as their evaluation scope via a new `scope_config` field on
`TestCase`. Local inline tests and top-level tests continue to use
the full merged config.
Remote preset inline tests are authored for the preset's own rules
and should not be evaluated by downstream consumers. Local overrides
can change the evaluation result (e.g., preset `ask` overridden by
local `deny`), causing preset tests to fail with "expected ask, got
deny".

Strip `RuleEntry.tests` from remote presets in `load_preset_with`
so they are never collected by `parse_test_cases`. Local preset
inline tests remain unaffected.
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

The runok test command was incorrectly evaluating inline tests from remote presets, leading to failures when local overrides conflicted with the preset author's intent. This change resolves the issue by stripping these inline tests from remote presets upon loading, ensuring that only the preset itself validates its own inline tests, while preserving inline tests for local presets.

Highlights

  • Remote Preset Inline Tests: Inline tests defined within remote presets are now stripped during loading. This prevents them from being evaluated by downstream consumers, which could lead to failures due to local overrides.
  • Local Preset Inline Tests: Inline tests for local presets remain unaffected and will continue to be evaluated as before.
Changelog
  • src/config/preset.rs
    • Implemented logic to iterate through rules in a remote preset and set rule.tests to None.
    • Added new test cases to verify that remote preset inline tests are stripped and local preset inline tests are preserved.
    • Imported CacheMetadata, MockGitClient, SystemTime, and UNIX_EPOCH for the new tests.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly implements the stripping of inline tests from remote presets to prevent them from running in consumer environments. The logic is sound and is added to load_preset_with to handle remote presets. New tests have been added to verify that tests are stripped for remote presets but preserved for local ones. I have one suggestion to improve the assertions in the new test for better maintainability, which is included in the comments.

Comment thread src/config/preset.rs
devin-ai-integration[bot]

This comment was marked as resolved.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.14%. Comparing base (6886648) to head (6f8f603).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/config/preset.rs 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #227      +/-   ##
==========================================
+ Coverage   90.09%   90.14%   +0.05%     
==========================================
  Files          50       50              
  Lines       10230    10243      +13     
==========================================
+ Hits         9217     9234      +17     
+ Misses       1013     1009       -4     
Flag Coverage Δ
Linux 90.04% <92.30%> (+0.07%) ⬆️
macOS 91.35% <92.30%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The previous commit strips inline tests from remote presets on load,
but the docs did not reflect this behavior change.
The previous commit only stripped inline tests (RuleEntry.tests) but
missed the top-level config.tests section. A remote preset with a
top-level tests block would have its test cases leak into the merged
config via Config::merge, and tests.extends paths would resolve
against the consumer's base_dir instead of the preset's cache dir.
@fohte fohte merged commit 725cf6e into main Mar 17, 2026
10 checks passed
@fohte fohte deleted the fohte/fix-test-scope branch March 17, 2026 17:19
@fohte-bot fohte-bot Bot mentioned this pull request Mar 17, 2026
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.

1 participant