fix(test): de-flake mass transfer NIfTI conversion acceptance test#345
fix(test): de-flake mass transfer NIfTI conversion acceptance test#345samuelvkwong merged 3 commits intomainfrom
Conversation
… race The mass transfer form's "Convert to NIfTI" checkbox is reactively disabled by Alpine.js until isDestinationFolder updates. The previous click(force=True) bypassed Playwright's enabled-check but the browser silently drops clicks on disabled checkboxes, and disabled fields are also stripped from POST data. This caused test_mass_transfer_to_folder_with_nifti_conversion[chromium-c-move] to flake: the job was created with convert_to_nifti=False, ran the non-NIfTI export path, reported success, and then failed the "No NIfTI files were generated" assertion. Set disabled=false and checked=true via page.evaluate so submission always carries the value, regardless of Alpine.js scheduling. Verified with 100/100 stress runs of the failing case and the full 12-test acceptance matrix (4 tests x 3 protocols). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe acceptance test helper ChangesMass Transfer Form Submission Test
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request modifies the mass transfer acceptance tests to handle a race condition where Alpine.js might disable the 'Convert to NIfTI' checkbox during form submission. The current implementation uses page.evaluate to force-enable the field via JavaScript. Feedback suggests replacing this with Playwright's idiomatic .set_checked(True) method, which is less brittle and automatically waits for the element to become enabled, ensuring the test remains stable without bypassing the application's reactive logic.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
adit/mass_transfer/tests/acceptance/test_mass_transfer.py (1)
41-45: ⚡ Quick winConsider applying the same
page.evaluatepattern to thepseudonymizecheckbox.The
pseudonymize_checkbox.click(force=True)calls use the same approach that was identified as the root cause of the NIfTI flakiness. If thePseudonymizecheckbox ever gains a reactivedisabledbinding in Alpine.js (e.g., tied to destination type or permissions), it will exhibit the same silent-drop behaviour. Replacing it now would keep the two checkbox interactions consistent and preempt a future flake.♻️ Proposed refactor
- pseudonymize_checkbox = page.get_by_label("Pseudonymize") - if pseudonymize and not pseudonymize_checkbox.is_checked(): - pseudonymize_checkbox.click(force=True) - elif not pseudonymize and pseudonymize_checkbox.is_checked(): - pseudonymize_checkbox.click(force=True) + page.evaluate( + """(checked) => { + const cb = document.getElementById('id_pseudonymize'); + if (cb) { cb.disabled = false; cb.checked = checked; } + }""", + pseudonymize, + )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@adit/mass_transfer/tests/acceptance/test_mass_transfer.py` around lines 41 - 45, The pseudonymize checkbox click currently uses pseudonymize_checkbox.click(force=True) which can silently fail if the element becomes disabled; replace that interaction with the same page.evaluate pattern used elsewhere: locate the element (pseudonymize_checkbox) and run page.evaluate in the page context to set its checked state to the desired boolean (pseudonymize) and dispatch appropriate input/change events so Alpine/reactive bindings update (e.g., element.checked = ...; element.dispatchEvent(new Event('input', { bubbles: true })); element.dispatchEvent(new Event('change', { bubbles: true }))); keep the conditional logic using the pseudonymize variable to avoid unnecessary DOM ops.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@adit/mass_transfer/tests/acceptance/test_mass_transfer.py`:
- Around line 41-45: The pseudonymize checkbox click currently uses
pseudonymize_checkbox.click(force=True) which can silently fail if the element
becomes disabled; replace that interaction with the same page.evaluate pattern
used elsewhere: locate the element (pseudonymize_checkbox) and run page.evaluate
in the page context to set its checked state to the desired boolean
(pseudonymize) and dispatch appropriate input/change events so Alpine/reactive
bindings update (e.g., element.checked = ...; element.dispatchEvent(new
Event('input', { bubbles: true })); element.dispatchEvent(new Event('change', {
bubbles: true }))); keep the conditional logic using the pseudonymize variable
to avoid unnecessary DOM ops.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7bebf201-ef49-419c-9235-a53226d2a66b
📒 Files selected for processing (1)
adit/mass_transfer/tests/acceptance/test_mass_transfer.py
Per Gemini review: the JS-evaluate bypass uses a hardcoded element ID and skips the application's reactive logic, which could mask real bugs. set_checked(True) — without force=True — auto-waits for Playwright's actionability checks (including enabled), so it tolerates Alpine.js's brief reactive disabling during destination changes without bypassing it. Verified 100/100 stress runs pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
test_mass_transfer_to_folder_with_nifti_conversion[chromium-c-move]was flaking ~5–10% of runs withAssertionError: No NIfTI files were generated.Convert to NIfTIcheckbox is reactivelydisabledby Alpine.js (x-effect) untilisDestinationFolderupdates after the destination select changes. The originalclick(force=True)bypassed Playwright's actionability checks, but the browser silently drops clicks on disabled checkboxes — and disabled fields are stripped from the POST. So the job was submitted withconvert_to_nifti=False, the processor ran the non-NIfTI export path, reported success, and the file-existence assertion failed.disabled=false; checked=trueon the input viapage.evaluateright before form submission.Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit