Skip to content

fix(testing): eliminate Playwright agents modal test flake (#3333)#3370

Merged
crivetimihai merged 1 commit intoIBM:mainfrom
omorros:fix/playwright-agents-modal-test-flake-3333
Mar 11, 2026
Merged

fix(testing): eliminate Playwright agents modal test flake (#3333)#3370
crivetimihai merged 1 commit intoIBM:mainfrom
omorros:fix/playwright-agents-modal-test-flake-3333

Conversation

@omorros
Copy link
Copy Markdown
Contributor

@omorros omorros commented Mar 2, 2026

🔗 Related Issue

Closes #3333


📝 Summary

Fixes intermittent timeout in test_view_modal_different_agents_show_different_data caused by a selector
race between the HTMX-loaded agents table and a hidden legacy table in admin.html. Removes the dead
legacy table (159 lines), targets the HTMX table by its specific #agents-table / #agents-table-body
IDs, and adds a wait for the HTMX partial to be attached before interacting with agent rows.


🏷️ Type of Change

  • Bug fix
  • Feature / Enhancement
  • Documentation
  • Refactor
  • Chore (deps, CI, tooling)
  • Other (describe below)

🧪 Verification

Check Command Status
Lint suite make lint
Unit tests make test
Coverage ≥ 80% make coverage N/A (test-only + template change)

Target test ran 5/5 times with no flakes against a live gateway.


✅ Checklist

  • Code formatted (make black isort pre-commit)
  • Tests added/updated for changes
  • Documentation updated (if applicable)
  • No secrets or credentials committed

📓 Notes (optional)

Root cause: agents_table used self.agents_panel.locator("table") which matched both the HTMX table
and a hidden legacy table (style="display: none"). When HTMX hadn't finished loading, Playwright resolved
against the hidden table first, finding View buttons that existed but were not actionable.

Changes:

  • Removed the <!-- Old table for reference (hidden) --> block from admin.html (lines 6916-7073) — dead
    code causing selector ambiguity
  • Changed agents_table / agents_table_body selectors to target #agents-table and #agents-table-body
    directly
  • Added wait_for_selector("#agents-table-body", state="attached") in wait_for_agents_panel_loaded() to
    ensure the HTMX partial has loaded before tests proceed (using attached instead of visible because an
    empty tbody has zero height)

@crivetimihai crivetimihai changed the title fix: eliminate Playwright agents modal test flake (#3333) fix(testing): eliminate Playwright agents modal test flake (#3333) Mar 2, 2026
@crivetimihai crivetimihai added bug Something isn't working SHOULD P2: Important but not vital; high-value items that are not crucial for the immediate release testing Testing (unit, e2e, manual, automated, etc) ui User Interface labels Mar 2, 2026
@crivetimihai crivetimihai added this to the Release 1.0.0-RC2 milestone Mar 2, 2026
@crivetimihai
Copy link
Copy Markdown
Member

Thanks @omorros. Excellent root cause analysis — the hidden legacy table creating selector ambiguity is a subtle one. The fix is clean: removes dead code and targets by specific IDs. The attached vs visible note for empty tbody is a nice detail. Looks good.

@marekdano
Copy link
Copy Markdown
Collaborator

@omorros - thank you for your contribution! Can you please resolve the conflict before a review?

@omorros
Copy link
Copy Markdown
Contributor Author

omorros commented Mar 10, 2026

Should be solved now! Let me know if there's anything else needed ;) @marekdano

marekdano
marekdano previously approved these changes Mar 11, 2026
Copy link
Copy Markdown
Collaborator

@marekdano marekdano left a comment

Choose a reason for hiding this comment

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

Summary
This PR resolves flaky Playwright tests for the A2A Agents modal by removing a legacy hidden table and using more precise HTMX selectors.

Changes Analysis

  1. mcpgateway/templates/admin.html (-165 lines)
    What Changed:
    - Removed entire legacy agents table that was hidden with style="display: none;"
    - This table was a duplicate of the HTMX-loaded active table

Why This Fixes the Flake:
- Eliminates selector ambiguity - Playwright could accidentally target the hidden table
- Removes race conditions between two similar DOM structures
- Reduces technical debt

Assessment: ✅ Excellent cleanup - removes dead code that was causing test instability

  1. tests/playwright/pages/agents_page.py (+3 lines, -1 line)
    What Changed:
    1 # Before:
    2 def agents_table_body(self) -> Locator:
    3 return self.agents_table.locator("tbody")
    4
    5 # After:
    6 def agents_table_body(self) -> Locator:
    7 return self.page.locator("#agents-table-body")

Why This Fixes the Flake:
- Uses direct ID selector instead of chaining through parent
- More precise targeting of the HTMX-loaded table body
- Added explicit wait for #agents-table-body to be attached before proceeding

Assessment: ✅ Proper fix - follows best practices for HTMX content waiting

Test Coverage
The test file test_agents_extended.py shows comprehensive coverage:
- ✅ 60+ test cases for agent modals (view/edit/test)
- ✅ Proper helper functions with API response interception
- ✅ Explicit waits for modal visibility
- ✅ Tests for all OAuth grant types and auth methods

Recommendations

✅ Approve with Confidence
1. Root cause properly addressed: Removes selector ambiguity
2. No breaking changes: Only removes hidden/unused HTML
3. Follows HTMX best practices: Direct ID selectors + explicit waits
4. Well-tested: Comprehensive test coverage already exists

LGTM 🚀

@marekdano marekdano added the release-fix Critical bugfix required for the release label Mar 11, 2026
… to eliminate Playwright modal test flake

Signed-off-by: Oriol Morros Vilaseca <OM368@student.aru.ac.uk>
@crivetimihai crivetimihai force-pushed the fix/playwright-agents-modal-test-flake-3333 branch from b139068 to 79b2bff Compare March 11, 2026 21:35
Copy link
Copy Markdown
Member

@crivetimihai crivetimihai left a comment

Choose a reason for hiding this comment

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

Rebased onto main and resolved one conflict in tests/playwright/pages/agents_page.py (chose self.page.locator("#agents-table") to match the consistent pattern used by all other page objects).

Review findings:

  • Root cause is correct: the hidden legacy <table> in the agents panel caused Playwright selector ambiguity when HTMX hadn't finished loading — this is confirmed dead HTML with no JS references, no feature flags, and no code paths to unhide it.
  • Fix is sound: removing the 159-line dead table eliminates the ambiguity, and the new wait_for_selector("#agents-table-body", state="attached") ensures the HTMX partial has loaded before tests interact with rows. Using attached over visible is correct since an empty <tbody> has zero height.
  • Consistency: all three selector changes (agents_table, agents_table_body, wait_for_agents_panel_loaded) now match the pattern used across all other page objects (tools, servers, gateways, prompts, resources).
  • No security or performance concerns — dead code removal + test infrastructure fix only.
  • Manual Playwright verification passed: View/Edit/Test modals, search, clear, tab navigation, HTMX table reload all work correctly.
  • Automated test: the originally flaky test_view_modal_different_agents_show_different_data passed 5/5 consecutive runs.

@crivetimihai crivetimihai merged commit 8eb687c into IBM:main Mar 11, 2026
48 of 89 checks passed
MohanLaksh pushed a commit that referenced this pull request Mar 12, 2026
… to eliminate Playwright modal test flake (#3370)

Signed-off-by: Oriol Morros Vilaseca <OM368@student.aru.ac.uk>
Yosiefeyob pushed a commit that referenced this pull request Mar 13, 2026
… to eliminate Playwright modal test flake (#3370)

Signed-off-by: Oriol Morros Vilaseca <OM368@student.aru.ac.uk>
Signed-off-by: Yosief Eyob <yosiefogbazion@gmail.com>
calculus-ask pushed a commit to calculus-ask/mcp-context-forge that referenced this pull request Mar 18, 2026
… to eliminate Playwright modal test flake (IBM#3370)

Signed-off-by: Oriol Morros Vilaseca <OM368@student.aru.ac.uk>
Signed-off-by: KRISHNAN, SANTHANA <sk8069@exo.att.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working release-fix Critical bugfix required for the release SHOULD P2: Important but not vital; high-value items that are not crucial for the immediate release testing Testing (unit, e2e, manual, automated, etc) ui User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][TESTING]: Playwright agents modal test flakes due to selector race with hidden legacy table

3 participants