Skip to content

Chore/expose requestid for cross tests#8862

Open
cyaiox wants to merge 5 commits into
devfrom
chore/expose-requestid-for-cross-tests
Open

Chore/expose requestid for cross tests#8862
cyaiox wants to merge 5 commits into
devfrom
chore/expose-requestid-for-cross-tests

Conversation

@cyaiox
Copy link
Copy Markdown
Member

@cyaiox cyaiox commented May 22, 2026

Pull Request Description

What does this PR change?

Adds a small, compile-time-gated test affordance to UnityAppWebBrowser.OpenUrl(string) so cross-stack Playwright tests in explorer-automation can intercept the auth-funnel URL the client would otherwise hand off to the system browser.

Problem

Cross-stack tests for the device-pairing / auth flow need the URL the client opens in the system browser to drive the web side. Today:

  • The URL is never logged, never surfaced in the Unity scene, and only readable from the system browser via osascript (CI-hostile, mac-only, fragile).
  • Letting Application.OpenURL fire under test also pops a stale tab the Playwright runner ignores, confusing anyone watching the run.

Solution

Under #if ALTTESTER only:

  • Write the escaped URL to Path.Combine(Application.persistentDataPath, "auth-url.txt") — Playwright polls and reads it.
  • Suppress Application.OpenURL entirely.

Production builds are untouched — the entire block is stripped at compile time when ALTTESTER isn't defined.

Implementation notes

  • Gated with the same #if ALTTESTER pattern used in SceneFacade.cs, AlttesterSceneReadinessProbe.cs, and MainSceneLoader.cs.
  • Output path uses Application.persistentDataPath so the affordance works on macOS, Windows, and Linux without a hardcoded per-OS path. Matches the convention used by DCLPlayerPrefs, ChatHistoryStorage, and ThirdWebLoginService.
  • I/O failures are reported via ReportHub.LogException(e, ReportCategory.AUTHENTICATION) so they participate in the project's diagnostics / Sentry pipeline (per CLAUDE.mdReportHub over Debug.Log*).
  • Zero new dependencies, no DI / plugin / asmdef wiring changes.

Coordination required

The Playwright consumer (explorer-automation/web/tests/auth/specs/client-to-web-handoff.spec.ts) must read from Unity's persistentDataPath, which is platform-specific:

  • macOS: ~/Library/Application Support/Decentraland/Decentraland Unity Explorer/auth-url.txt
  • Windows: %USERPROFILE%\AppData\LocalLow\Decentraland\Decentraland Unity Explorer\auth-url.txt
  • Linux: ~/.config/unity3d/Decentraland/Decentraland Unity Explorer/auth-url.txt

Exact folder names come from companyName / productName in ProjectSettings.asset.

Files changed

  • Explorer/Assets/DCL/NetworkDefinitions/Browser/UnityAppWebBrowser.cs (+21 / -1)

Test Instructions

Prerequisites

  • An ALTTESTER build of Unity Explorer (Scripting Define Symbol ALTTESTER).
  • The companion explorer-automation checkout updated to read auth-url.txt from Application.persistentDataPath (see Coordination required above).

Test Steps

Smoke — production build (no ALTTESTER)

  1. Build the project without the ALTTESTER define.
  2. Trigger an auth-funnel link (e.g. open the sign-in screen and click "Sign in").
  3. Expected: the system browser opens at the auth URL exactly as before. No file is created on disk.

ALTTESTER build (cross-stack test path)

  1. Build with ALTTESTER defined.
  2. Trigger an auth-funnel link.
  3. Expected:
    • The system browser does not open.
    • auth-url.txt is written under Application.persistentDataPath containing the escaped URL.
  4. Run the Playwright suite: client-to-web-handoff.spec.ts should pick up the URL and complete the handoff.

Failure-path smoke

  1. With ALTTESTER defined, point Application.persistentDataPath at a read-only location (or temporarily mark the file read-only after creation).
  2. Trigger the auth flow.
  3. Expected: a ReportCategory.AUTHENTICATION exception is logged via ReportHub; auth flow continues without throwing.

Additional Testing Notes

  • Verify the entire #if ALTTESTER block (including using System.IO; and using DCL.Diagnostics;) is stripped from a non-ALTTESTER build — quick check via ilspy / dotPeek on the produced assembly.
  • The branch name (chore/expose-requestid-for-cross-tests) is from an earlier scope; this PR does not expose a request ID. Worth renaming the PR title to match: "chore(browser): expose auth URL to disk for cross-stack tests (ALTTESTER)".

Quality Checklist

  • Changes have been tested locally
  • Documentation has been updated (if required) — N/A, no public API change
  • Performance impact has been considered — runs once per auth flow, only in instrumented builds
  • For SDK features: Test scene is included — N/A

Code Review Reference

Please review our Branch & PR Standards before submitting. It explains the automated review flow, QA/DEV approval requirements, and what each label does — especially useful for first-time contributors.

cyaiox added 3 commits May 22, 2026 12:01
Cross-stack tests in explorer-automation need the auth URL the client opens
in the system browser to drive the Playwright side of the device-pairing
flow. The URL is otherwise never logged, never surfaced in the Unity scene,
and only readable from the system browser via osascript (CI-hostile).

This patch writes the opened URL to a known file at the same moment
Application.OpenURL is called, so the Playwright orchestrator can detect
the auth flow has begun and navigate its own browser to the same URL.

Compile-time gated to #if ALTTESTER so shipping builds have ZERO
information-leak surface. Same pattern as data-testid annotations in
DCL dapp tests: an explicit test affordance owned by production code,
only active in instrumented builds.
Cross-stack Playwright tests navigate to the auth URL themselves (they read
auth-url.txt and drive their own Chromium). Letting Application.OpenURL also
fire just pops a stale system-browser tab the test ignores — and confuses
anyone watching the test run.

ALTTESTER builds now only write the URL to disk; production builds retain
the full system-browser open path. Compile-time gated, zero behaviour change
in shipped binaries.
…l write

- switch hardcoded mac-only Library/Application Support path to Application.persistentDataPath
- route I/O failures through ReportHub.LogException(ReportCategory.AUTHENTICATION) instead of Debug.LogWarning
- trim verbose comment block
@cyaiox cyaiox requested review from a team as code owners May 22, 2026 15:03
@github-actions github-actions Bot requested a review from anicalbano May 22, 2026 15:03
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

@cyaiox
Copy link
Copy Markdown
Member Author

cyaiox commented May 22, 2026

@claude review

@claude

This comment has been minimized.

Comment on lines +26 to +27
// so cross-stack Playwright tests can drive their own browser to the same target.
try
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Per CLAUDE.md: "Never write multi-line comment blocks — one short line max." This 2-line comment should be compressed to one line.

Suggested change
// so cross-stack Playwright tests can drive their own browser to the same target.
try
// ALTTESTER builds write auth URL to disk and suppress the system browser so Playwright tests can drive their own browser to it.

@cyaiox
Copy link
Copy Markdown
Member Author

cyaiox commented May 22, 2026

@claude review

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 22, 2026

Claude finished @cyaiox's task in 1m 12s —— View job


Code Review

  • Gather context
  • Read changed file and diff
  • Analyze for issues
  • Post review findings

Root-Cause Assessment

Problem: Cross-stack Playwright tests need the auth URL that Unity sends to the system browser to drive their own Chromium instance. Without this, the URL is unreachable from CI without fragile OS-level browser scraping.

Fix: Adds a #if ALTTESTER-gated block that writes the URL to auth-url.txt at Application.persistentDataPath and suppresses Application.OpenURL so only the test-controlled browser navigates. Production builds retain the original behavior, the entire block is stripped at compile time. This fixes the actual cause, not a symptom.


Previous Blocking Issue — Resolved ✅

The multi-line comment flagged in the prior review was collapsed to a single line in commit eb79cc65. The current state at line 25 is compliant with CLAUDE.md ("one short line max").


Blocking Issues

None. No new issues found.


Notes

  • var escaped is correctly extracted before the #if block and reused in both branches — no redundant computation.
  • Application.persistentDataPath is guaranteed by Unity to exist at runtime — no Directory.CreateDirectory needed.
  • ReportHub.LogException(e, ReportCategory.AUTHENTICATION) is correct per CLAUDE.md ("Use ReportHub instead of Debug.Log for all logging").
  • Catch-and-log without rethrow is intentional and appropriate here: auth flow must not break in test builds due to a transient I/O failure writing the intercept file.

REVIEW_RESULT: PASS ✅
COMPLEXITY: SIMPLE
COMPLEXITY_REASON: Touches a single utility class (UnityAppWebBrowser) with a compile-time gated file write; no ECS, async, plugin, or rendering systems involved.
QA_REQUIRED: YES

@m3taphysics
Copy link
Copy Markdown
Collaborator

PR #8862, run #26298583791

Builds: Windows change, Windows baseline, macOS change, macOS baseline

Framework 13 i7

Metric Change Baseline Delta Improvement
Samples 2701 2700
CPU average 33.3 ms 33.3 ms -0.0 ms 0.0%
CPU 1% worst 33.5 ms 33.9 ms -0.3 ms 1.0%
CPU 0.1% worst 35.2 ms 38.2 ms -3.0 ms 7.9% 🟢
GPU average 7.7 ms 7.6 ms 0.1 ms -0.9%
GPU 1% worst 19.3 ms 18.4 ms 0.8 ms -4.4% 🔴
GPU 0.1% worst 25.0 ms 23.0 ms 2.0 ms -8.7% 🔴

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