Skip to content

fix(tests): isolate locale and device identity from host environment - #715

Merged
shanselman merged 1 commit into
openclaw:mainfrom
AlexAlves87:fix/test-isolation-locale-and-identity
Jun 8, 2026
Merged

shanselman merged 1 commit into
openclaw:mainfrom
AlexAlves87:fix/test-isolation-locale-and-identity

Conversation

@AlexAlves87

Copy link
Copy Markdown
Contributor

What

Fixes two test isolation bugs that caused failures on machines with non-English locale or with the app installed and paired.

ChatAttachment.FormatBytes — locale-sensitive decimal separator

$"{val:F1}" respects the host thread culture. On systems with a non-English decimal separator (e.g., Spanish locale uses comma), the output was "1,5 KB" instead of "1.5 KB". Fixed by using ToString("F1", CultureInfo.InvariantCulture).

OpenClawGatewayClient signature tests — device identity leaking from host

OperatorConnect_FreshBootstrapDevice_StartsWithV2Signature and OperatorConnect_SharedTokenDevice_StartsWithV3Signature passed null as identityPath, so the client read the real device identity from %APPDATA%\OpenClawTray. On machines where the app is installed and paired, _deviceIdentity.DeviceToken is non-null during construction, which sets _useV2Signature to false before SetDeviceTokenForTest(null) is ever called. Fixed by passing a fresh temp directory so the tests start with no device state on disk.

Testing

Both fixes verified locally. All 3 previously failing tests now pass. Full shared test suite: 2080/2080 passed.

Co-Authored-By: Claude Sonnet 4.6 [email protected]

FormatBytes used locale-sensitive interpolation ($"{val:F1}") which
produced commas instead of dots on systems with a non-English decimal
separator. Use ToString("F1", CultureInfo.InvariantCulture) so the
output is always dot-separated regardless of host locale.

OperatorConnect_FreshBootstrapDevice_StartsWithV2Signature and
OperatorConnect_SharedTokenDevice_StartsWithV3Signature passed null as
identityPath, causing the client to read the real device identity from
%APPDATA%\OpenClawTray on machines where the app is installed and
paired. On those machines _useV2Signature was computed from a live
device token, making the bootstrap assertion fail. Pass a fresh temp
directory so the tests start with no device state.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@clawsweeper

clawsweeper Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed June 7, 2026, 8:27 PM ET / 00:27 UTC.

Summary
The PR makes ChatAttachment size formatting culture-invariant and passes isolated temporary identity directories to two OpenClawGatewayClient signature tests.

Reproducibility: yes. from source inspection: ambient non-English CurrentCulture can change the F1 decimal separator, and a paired appdata identity is read during OpenClawGatewayClient construction before the tests clear the token. I did not execute the failing environments because this review was read-only.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Ensure CI or a maintainer run covers AGENTS.md validation: ./build.ps1, shared tests, and tray tests.

Risk before merge

  • [P1] This read-only review did not run AGENTS.md validation; the PR body reports the shared test suite, but maintainers should still rely on CI or run the required build, shared tests, and tray tests before merge.

Maintainer options:

  1. Decide the mitigation before merge
    Land the narrow isolation fix after normal repository validation, keeping gateway credential precedence and device-token behavior unchanged.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] No repair lane is needed; the PR is already a narrow implementation and needs ordinary review plus repository validation.

Security
Cleared: The diff only changes deterministic formatting and test identity setup; it does not add dependencies, downloads, permissions, secret handling, or broader auth behavior.

Review details

Best possible solution:

Land the narrow isolation fix after normal repository validation, keeping gateway credential precedence and device-token behavior unchanged.

Do we have a high-confidence way to reproduce the issue?

Yes from source inspection: ambient non-English CurrentCulture can change the F1 decimal separator, and a paired appdata identity is read during OpenClawGatewayClient construction before the tests clear the token. I did not execute the failing environments because this review was read-only.

Is this the best way to solve the issue?

Yes: using invariant formatting matches existing dot-decimal assertions and local invariant-format precedent, and isolating identityPath before construction fixes constructor-time host state leakage. Reusing the existing CreateTempIdentityPath helper would be minor cleanup, not a correctness blocker.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 25c11dd07f09.

Label changes

Label changes:

  • add P3: This is a low-risk test reliability and formatting isolation fix with limited blast radius.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports after-fix local verification, including all 3 previously failing tests and the shared test suite passing 2080/2080.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body reports after-fix local verification, including all 3 previously failing tests and the shared test suite passing 2080/2080.

Label justifications:

  • P3: This is a low-risk test reliability and formatting isolation fix with limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body reports after-fix local verification, including all 3 previously failing tests and the shared test suite passing 2080/2080.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports after-fix local verification, including all 3 previously failing tests and the shared test suite passing 2080/2080.
Evidence reviewed

What I checked:

  • Repository policy read: AGENTS.md was read fully; its validation and gateway identity/test-isolation guidance was applied as review context for this test isolation PR. (AGENTS.md:1, 25c11dd07f09)
  • Current main still formats file sizes with ambient culture: ChatAttachment.FormatBytes uses interpolated F1 formatting for KB/MB, so decimal separators follow CurrentCulture on current master. (src/OpenClaw.Shared/ChatAttachment.cs:129, 25c11dd07f09)
  • Current tests still pass null identityPath: The two signature tests currently construct GatewayClientTestHelper without an isolated identityPath and then clear the token after construction. (tests/OpenClaw.Shared.Tests/OpenClawGatewayClientTests.cs:464, 25c11dd07f09)
  • Constructor reads default appdata identity before test mutation: OpenClawGatewayClient defaults null identityPath to the OpenClawTray appdata directory, initializes DeviceIdentity, and derives _useV2Signature from the stored DeviceToken in the constructor. (src/OpenClaw.Shared/OpenClawGatewayClient.cs:240, 25c11dd07f09)
  • Identity path is a directory containing device-key-ed25519.json: DeviceIdentity combines the provided dataPath with device-key-ed25519.json and loads or generates the key during Initialize, matching the PR's host-state leak explanation. (src/OpenClaw.Shared/DeviceIdentity.cs:160, 25c11dd07f09)
  • PR diff directly addresses both isolation bugs: The provided PR diff changes FormatBytes to ToString("F1", CultureInfo.InvariantCulture) and passes fresh temp identity directories to both signature tests. (src/OpenClaw.Shared/ChatAttachment.cs:127, f46e3bfb2ef7)

Likely related people:

  • Christine Yan: git blame and file history show the current ChatAttachment formatting, OpenClawGatewayClient constructor, and affected signature tests date to commit 85445c7. (role: introduced behavior; confidence: high; commits: 85445c78066b; files: src/OpenClaw.Shared/ChatAttachment.cs, src/OpenClaw.Shared/OpenClawGatewayClient.cs, tests/OpenClaw.Shared.Tests/OpenClawGatewayClientTests.cs)
  • github-actions[bot]: Recent commit 7564208 touched OpenClawGatewayClient and its tests, but not the exact signature-test constructor lines. (role: recent adjacent contributor; confidence: low; commits: 7564208d9686; files: src/OpenClaw.Shared/OpenClawGatewayClient.cs, tests/OpenClaw.Shared.Tests/OpenClawGatewayClientTests.cs)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. labels Jun 8, 2026
@shanselman
shanselman merged commit 8bcd0f3 into openclaw:main Jun 8, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants