Conversation
e93f0fe to
5f07689
Compare
Auto-repair Started
Task prompt (3027 tokens)PR Repair Task: PR #139Before making changes, read Repair the existing PR branch in place. Do not create a new branch or PR. Context
Required OutcomeFix the currently failing checks shown below. Required Local VerificationThe workflow will rerun these commands before pushing. Your changes should make them pass: python3 scripts/dispatch-cops.py changed --base origin/main --head HEAD > "$REPAIR_CHANGED_COPS_FILE"
failed=0
while IFS= read -r cop; do
[ -z "$cop" ] && continue
echo "=============================="
echo "Checking: $cop (re-running against corpus)"
echo "=============================="
if ! python3 scripts/check-cop.py "$cop" --verbose --rerun --quick --clone; then
echo "FAIL: $cop regression detected"
failed=$((failed + 1))
fi
done < "$REPAIR_CHANGED_COPS_FILE"
test "$failed" -eq 0
Current PR Diff StatCurrent PR Diff Excerptdiff --git a/src/cop/style/mixin_usage.rs b/src/cop/style/mixin_usage.rs
index f297299bd..ccb94c2a3 100644
--- a/src/cop/style/mixin_usage.rs
+++ b/src/cop/style/mixin_usage.rs
@@ -29,6 +29,12 @@ use crate::parse::source::SourceFile;
/// matches exactly ONE `const` argument. Multi-argument mixin calls like `include A, B, C`
/// don't match the pattern and are not flagged. nitrocop was incorrectly accepting any number
/// of const arguments. Fixed by requiring exactly one argument in the const check.
+///
+/// Corpus investigation (round 5): 3 FPs from `include UtilityFunctions` inside `BEGIN { ... }`
+/// blocks in linguistics experiments. Root cause: Prism models `BEGIN` as `PreExecutionNode`,
+/// which we did not mark as opaque, so top-level state leaked into its body. RuboCop's
+/// `in_top_level_scope?` does not treat `preexe` as transparent. Fixed by marking
+/// `visit_pre_execution_node` as opaque scope.
pub struct MixinUsage;
const MIXIN_METHODS: &[&[u8]] = &[b"include", b"extend", b"prepend"];
@@ -141,6 +147,13 @@ impl<'pr> Visit<'pr> for MixinUsageVisitor<'_> {
// === Opaque scopes (mixin calls inside these are NOT top-level) ===
+ fn visit_pre_execution_node(&mut self, node: &ruby_prism::PreExecutionNode<'pr>) {
+ let prev = self.in_opaque_scope;
+ self.in_opaque_scope = true;
+ ruby_prism::visit_pre_execution_node(self, node);
+ self.in_opaque_scope = prev;
+ }
+
fn visit_class_node(&mut self, node: &ruby_prism::ClassNode<'pr>) {
let prev = self.in_opaque_scope;
self.in_opaque_scope = true;
diff --git a/tests/fixtures/cops/style/mixin_usage/no_offense.rb b/tests/fixtures/cops/style/mixin_usage/no_offense.rb
index 173609fe3..798d73459 100644
--- a/tests/fixtures/cops/style/mixin_usage/no_offense.rb
+++ b/tests/fixtures/cops/style/mixin_usage/no_offense.rb
@@ -49,6 +49,10 @@ module N
ensure
cleanup
end
+# `BEGIN` (PreExecutionNode) is opaque for Style/MixinUsage
+BEGIN {
+ include UtilityFunctions
+}
# Multiple constant arguments: RuboCop's pattern matches only a single const
include GravatarHelper, GravatarHelper::PublicMethods, ERB::Util
extend A, BLocal Corpus ContextThese corpus oracle artifacts are already downloaded locally by the workflow.
Use these files directly with the repo scripts when you need corpus context. python3 scripts/investigate-cop.py Department/CopName --input /home/runner/work/_temp/agent-pr-repair/repair/corpus-standard.json --context
python3 scripts/check-cop.py Department/CopName --input /home/runner/work/_temp/agent-pr-repair/repair/corpus-standard.json --verbose --rerun --quick --cloneFailed Checks Packetcop-check
Constraints
Available Local Helper ScriptsThese helper scripts are available in this CI checkout. Prefer the stable top-level CLI paths shown below over ad hoc commands when they directly help with diagnosis or validation.
Typical usage when present: python3 scripts/check-cop.py Department/CopName --verbose --rerun --quick --clone
python3 scripts/dispatch-cops.py changed --base origin/main --head HEAD
python3 scripts/investigate-cop.py Department/CopName --context
python3 scripts/verify-cop-locations.py Department/CopName
python3 scripts/corpus-smoke-test.py --binary target/release/nitrocopLocal Cop-Check DiagnosisThe workflow already reran the changed-cop corpus check locally before agent execution. Changed cops:
Style/MixinUsageStart here:
Oracle context from CI corpus artifact:
/usr/bin/python3 scripts/check-cop.py Style/MixinUsage --verbose --rerun --quick --cloneExit status: |
Auto-repair Failed Verification
Auto-repair failed local verification with backend Reason: cop-check: Check cops against corpus baseline Verification tail |
Auto-repair Skipped
|
Automated fix fix for
Style/MixinUsagecorpus conformance.Details
Style/MixinUsageResult
Changes
Agent conversation excerpt
I’m going to follow your workflow exactly: first I’ll read
docs/agent-ci.md, then verify RuboCop behavior for the reported FP case and a top-level baseline before I touch fixtures or Rust code.I’m going to follow your workflow exactly: first I’ll read
docs/agent-ci.md, then verify RuboCop behavior for the reported FP case and a top-level baseline before I touch fixtures or Rust code.I’ve read
docs/agent-ci.md. Next I’ll run the required RuboCop checks for the specificBEGIN { include ... }case and then the general top-levelincludepattern to keep the fix narrow.I’ve read
docs/agent-ci.md. Next I’ll run the required RuboCop checks for the specificBEGIN { include ... }case and then the general top-levelincludepattern to keep the fix narrow.echo '---'
cat > /tmp/test.rb <<'RUBY'
include M
RUBY
rubocop --o`
RuboCop confirmed the behavior:
includeinsideBEGIN { ... }is accepted, while top-levelinclude Mis still an offense. I’ll now add theBEGINFP case tono_offense.rbbefore touching Rust logic.RuboCop confirmed the behavior:
includeinsideBEGIN { ... }is accepted, while top-levelinclude Mis still an offense. I’ll now add theBEGINFP case tono_offense.rbbefore touching Rust logic.I’ve added the fixture for
BEGIN { include UtilityFunctions }. Next I’m running the targeted cop test to confirm it fails before the code change.I’ve added the fixture for
BEGIN { include UtilityFunctions }. Next I’m running the targeted cop test to confirm it fails before the code change.The targeted test is still running; once it completes I’ll patch
mixin_usage.rsto makeBEGINblocks opaque, then re-run the same test.The targeted test is still running; once it completes I’ll patch
mixin_usage.rsto makeBEGINblocks opaque, then re-run the same test.I confirmed the new fixture fails as expected. I’m now checking Prism visitor method names for
BEGIN/ENDnodes so the scope change is implemented with the correct node hooks.I confirmed the new fixture fails as expected. I’m now checking Prism visitor method names for
BEGIN/ENDnodes so the scope change is implemented with the correct node hooks.I’m applying a narrow cop fix now: treat Prism
PreExecutionNode(BEGIN { ... }) as an opaque scope so top-level checks don’t fire inside it, and I’ll document this as a new corpus round in the cop doc comment.I’m applying a narrow cop fix now: treat Prism
PreExecutionNode(BEGIN { ... }) as an opaque scope so top-level checks don’t fire inside it, and I’ll document this as a new corpus round in the cop doc comment.The code change is in place and the targeted test run is still in progress; I’ll confirm pass/fail and then do a file-scoped format plus commit of only the two cop files.
The code change is in place and the targeted test run is still in progress; I’ll confirm pass/fail and then do a file-scoped format plus commit of only the two cop files.
The targeted test now passes with the scope change. I’m running
cargo fmton the touched Rust file (done) and re-running the same test once more to verify post-format stability before committing.The targeted test now passes with the scope change. I’m running
cargo fmton the touched Rust file (done) and re-running the same test once more to verify post-format stability before committing.I’m at the final step now: only the two allowed cop files are changed, tests are green, and I’ll commit just these files.
I’m at the final step now: only the two allowed cop files are changed, tests are green, and I’ll commit just these files.
Implemented and committed a narrow FP fix for
Style/MixinUsageinBEGIN { ... }context.docs/agent-ci.mdfirst, as requested.BEGIN { include UtilityFunctions }=> no offenseinclude M=> offenseExpected no offenses but got 1for that newBEGINcase).PreExecutionNodeas opaque scope and documented findings in///comments:cargo fmt -- src/cop/style/mixin_usage.rscargo test --lib -- cop::style::mixin_usageand it passed (2 passed, 0 failed).e93f0fe2with message:Fix Style/MixinUsage in BEGIN blocks.Task prompt (5798 tokens)
Fix Style/MixinUsage — 3 FP, 0 FN
Instructions
You are fixing ONE cop in nitrocop, a Rust Ruby linter that uses Prism for parsing.
Current state: 2,834 matches, 3 false positives, 0 false negatives.
Focus on: FP (nitrocop flags code RuboCop does not).
Workflow
behavior on BOTH the specific FP case AND the general pattern:
tests/fixtures/cops/style/mixin_usage/offense.rbwith^annotationtests/fixtures/cops/style/mixin_usage/no_offense.rbcargo test --lib -- cop::style::mixin_usagesrc/cop/style/mixin_usage.rscargo test --lib -- cop::style::mixin_usage///doc comment on the cop struct documenting what you found and fixedFixture Format
Mark offenses with
^markers on the line AFTER the offending source line:The
^characters must align with the offending columns. The message format isStyle/MixinUsage: <message text>.If your test passes immediately
If you add a test case and it passes without code changes, the corpus mismatch is
caused by config/context differences, not a detection bug.
Do NOT loop trying to make the test fail. Instead:
src/config/or the cop's config handling, not detection logica
///comment on the cop struct and commitCRITICAL: Avoid regressions in the opposite direction
When fixing FPs, your change MUST NOT suppress legitimate detections. When fixing FNs,
your change MUST NOT flag code that RuboCop accepts. A fix that eliminates a few issues
in one direction but introduces hundreds in the other is a catastrophic regression.
Before exempting a category of patterns, verify with RuboCop that the general case
is still an offense:
If RuboCop flags the general pattern but not your specific case, the difference is in
a narrow context (e.g., enclosing structure, receiver type, argument count) — your fix
must target that specific context, not the broad category.
Rule of thumb: if your fix adds an early
returnorcontinuethat skips a wholenode type, operator class, or naming pattern, it's probably too broad. Prefer adding a
condition that matches the SPECIFIC differentiating context.
Rules
src/cop/style/mixin_usage.rsandtests/fixtures/cops/style/mixin_usage/cargo test --lib -- cop::style::mixin_usageto verify your fix (do NOT run the full test suite)git stashPrism Notes
Foo) and ConstantPathNode (qualifiedFoo::Bar). If you handle one, check if you need the other.Start Here
Use the existing corpus data to focus on the most concentrated regressions first.
Helpful local commands:
python3 scripts/investigate-cop.py Style/MixinUsage --repos-onlypython3 scripts/investigate-cop.py Style/MixinUsage --contextpython3 scripts/verify-cop-locations.py Style/MixinUsageTop FP repos:
ged__linguistics__b0b119c(3 FP) — exampleexperiments/conjunct-with-block.rb:13Representative FP examples:
ged__linguistics__b0b119c: experiments/conjunct-with-block.rb:13—includeis used at the top level. Use insideclassormodule.ged__linguistics__b0b119c: experiments/lafcadio_plural.rb:13—includeis used at the top level. Use insideclassormodule.ged__linguistics__b0b119c: experiments/lprintf.rb:17—includeis used at the top level. Use insideclassormodule.Pre-diagnostic Results
Diagnosis Summary
Each example was tested by running nitrocop on the extracted source in isolation
with
--force-default-configto determine if the issue is a code bug or config issue.Note: source context is truncated and may not parse perfectly. If a diagnosis
seems wrong (e.g., your test passes immediately for a 'CODE BUG'), treat it as
a config/context issue instead.
FP #1:
ged__linguistics__b0b119c: experiments/conjunct-with-block.rb:13CONFIRMED false positive — CODE BUG
nitrocop incorrectly flags this pattern in isolation.
Fix the detection logic to not flag this.
Enclosing structure: BEGIN {} block (Prism: PreExecutionNode) (line:
BEGIN {)The offense is inside this structure — this is likely WHY
RuboCop does not flag it. Your fix should detect this context.
Full source context (add relevant parts to no_offense.rb):
Message: ``include
is used at the top level. Use insideclass` or `module`.`FP #2:
ged__linguistics__b0b119c: experiments/lafcadio_plural.rb:13CONFIRMED false positive — CODE BUG
nitrocop incorrectly flags this pattern in isolation.
Fix the detection logic to not flag this.
Enclosing structure: BEGIN {} block (Prism: PreExecutionNode) (line:
BEGIN {)The offense is inside this structure — this is likely WHY
RuboCop does not flag it. Your fix should detect this context.
Full source context (add relevant parts to no_offense.rb):
Message: ``include
is used at the top level. Use insideclass` or `module`.`FP #3:
ged__linguistics__b0b119c: experiments/lprintf.rb:17CONFIRMED false positive — CODE BUG
nitrocop incorrectly flags this pattern in isolation.
Fix the detection logic to not flag this.
Enclosing structure: BEGIN {} block (Prism: PreExecutionNode) (line:
BEGIN {)The offense is inside this structure — this is likely WHY
RuboCop does not flag it. Your fix should detect this context.
Full source context (add relevant parts to no_offense.rb):
Message: ``include
is used at the top level. Use insideclass` or `module`.`Current Rust Implementation
src/cop/style/mixin_usage.rsRuboCop Ruby Implementation (ground truth)
vendor/rubocop/lib/rubocop/cop/style/mixin_usage.rbRuboCop Test Excerpts
vendor/rubocop/spec/rubocop/cop/style/mixin_usage_spec.rbCurrent Fixture: offense.rb
tests/fixtures/cops/style/mixin_usage/offense.rbCurrent Fixture: no_offense.rb
tests/fixtures/cops/style/mixin_usage/no_offense.rb