Skip to content

fix(portal): playground region accessors fall back to sessionStorage [W-22945464]#145

Open
spezzirriemiliano wants to merge 3 commits into
masterfrom
fix/W-22945464-playground-endpoint-ignores-region
Open

fix(portal): playground region accessors fall back to sessionStorage [W-22945464]#145
spezzirriemiliano wants to merge 3 commits into
masterfrom
fix/W-22945464-playground-endpoint-ignores-region

Conversation

@spezzirriemiliano

Copy link
Copy Markdown
Contributor

Summary

  • Fix playground steps always hitting anypoint.mulesoft.com (US) regardless of the region the user selected before logging in.
  • Make getSelectedServerType() and getSelectedRegion() in portal.js fall back to sessionStorage (anypoint_server_type / anypoint_region) when the DOM is at its default or the relevant element is missing, eliminating the DOMContentLoaded race that left .step-url-bar rendered against the wrong control plane.
  • DOM still wins whenever it holds a non-default value, so live region changes continue to take precedence and US-after-EU "change back" flows are not regressed.

Acceptance criteria

  • AC1 — EU + eu1 in sessionStorage on a ?playground=true page → getSelectedBaseUrl() resolves through the fixed accessors to eu1.anypoint.mulesoft.com. Evidence: jest returns sessionStorage value when DOM is at default us and storage has eu (bug repro) + getSelectedBaseUrl existing block continues green (240/240).
  • AC2 — Canada (platform/ca1) and Japan (platform/jp1) resolve to the correct host via the same path. Evidence: jest returns sessionStorage region when DOM has platform but no regionPreset for ca1 and ... for jp1.
  • AC3 — User-driven region changes after load still win (no regression). Evidence: jest prefers DOM region over sessionStorage when both are set + prefers DOM value when DOM is non-default, even if storage says otherwise.
  • AC4 — getSelectedServerType() returns the persisted value when #serverSelect is missing or at default 'us' while sessionStorage holds a different value. Evidence: _safeSessionGet('anypoint_server_type') branch in portal.js + new tests.
  • AC5 — getSelectedRegion() returns the persisted region when #regionPreset / #regionCustomInput are missing or empty. Evidence: new fallback branch + tests for eu/ca1/jp1.
  • AC6 — Empty DOM + empty sessionStorage falls back to today's behavior ('us' / null). Evidence: tests returns us when both DOM and sessionStorage are empty and returns null when neither DOM nor sessionStorage has a region.
  • AC7 — All existing jest tests in scripts/tests/portal.test.js continue to pass. Evidence: 240/240 green.
  • AC8 — New tests cover DOM-only, sessionStorage-only, both-present (DOM wins), and the "DOM has default but sessionStorage has non-default" bug repro. Evidence: 13 new test cases added across the getSelectedServerType and getSelectedRegion describe blocks.

Test plan

  • cd scripts && npx jest portal.test.js → 240 passed (includes 13 new tests for the W-22945464 fallback paths).
  • make test-portal (pytest + jest) — pytest deps not installed in this worktree (PEP 668 externally managed env); diff is JS-only so jest is the authoritative gate locally. CI runs both.
  • make pre-commit-hook — gracefully degraded locally (Python validators absent); CI is authoritative.

Related

  • Spec: docs/superpowers/specs/2026-06-24-w-22945464-playground-region-fix-design.md
  • Plan: docs/superpowers/plans/2026-06-24-w-22945464-playground-region-fix-plan.md
  • WI: W-22945464
  • Follow-up cleanup story: W-22930154

Notes

  • Wrapped sessionStorage.getItem in a _safeSessionGet helper that returns null when storage access throws (private mode / disabled storage), matching the edge case called out in the spec.
  • Scope is strictly the two accessors; no template, generator, or CSS changes (diff: 2 files, +183 / -7).

spezzirriemiliano and others added 3 commits June 24, 2026 17:37
Add comprehensive test coverage for getSelectedServerType and getSelectedRegion
to verify sessionStorage fallback behavior when DOM has default values.

Tests verify:
- sessionStorage fallback when DOM is at default 'us' but sessionStorage has non-default
- DOM preference when DOM value is non-default
- sessionStorage fallback when DOM elements are missing
- null/default fallback when both DOM and sessionStorage are empty
- custom region handling
- region behavior for US (always null regardless of sessionStorage)

All new tests currently fail — implementation follows.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add comprehensive test coverage for getSelectedRegion to verify sessionStorage
fallback behavior when regionPreset DOM element is missing.

Tests verify:
- sessionStorage fallback when serverSelect exists but regionPreset is missing
- Fallback for all platform regions (ca1, jp1)
- DOM region preference over sessionStorage when both are set
- null return when serverSelect is us (regardless of sessionStorage)
- null return when neither DOM nor sessionStorage has a region
- custom region handling via regionCustomInput
- null return when serverSelect is missing

All new tests currently fail — implementation follows.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@spezzirriemiliano spezzirriemiliano requested review from a team as code owners June 24, 2026 20:44
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