test(workspace): stop create-then-rebind flaking on stray lookups, and opening a browser

Merged
SA
1mo ago
+40-2

Issue for this PR

No GitHub issue. This is a flaky test that is failing CI on main and on #1374.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fixes two problems in test/altimate/workspace/create-then-rebind.test.ts. The PR changes only that test file.

1. It failed at random on CI. bun test runs every file in one process. A background skill or memory sync that is still running from an earlier file can send its binding lookup (GET /datamate-project-bindings/by-path) through this file's fetch stub. The endpoint-sequence filter kept that request, so unlinked project uses the atomic create-and-bind saw an extra entry and failed:

+   "GET /datamate-project-bindings/by-path",
    "POST /datamate-project-bindings/",

The same failure shows up on main CI (e.g. runs 35986778047, 35895965016). Every request these tests assert on is a write, so the filter now ignores lookups (GETs). A new test sends that stray lookup deliberately; removing the filter reproduces CI's exact failure.

2. It opened a real browser tab. A create opens the new workspace's manage URL with open, and the test never stubbed it, so a local run opened https://x.test/w/7. open is now stubbed before the modules under test load, using the same mock.module("open", …) pattern as oauth-browser.test.ts. The stub records each URL, so the test still asserts that the open happens.

How did you verify your code works?

  • The file passes 8/8, including the new stray-lookup test.
  • Removing the GET filter fails the new test with CI's exact diff.
  • The open stub is process-wide in Bun, so I ran this file together with oauth-browser.test.ts in both orders. All 11 tests pass either way.
  • Workspace, CLI, plugin and server suites: 2104 pass. One test fails, flushPendingSyncs … would abandon (a 5s timeout); it fails the same way on main.
  • Typecheck clean.

Screenshots / recordings

N/A. Test-only change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

šŸ¤– Generated with Claude Code


Summary by cubic

Stops the create-then-rebind workspace test from failing at random on CI and from opening a real browser tab on local runs.

Bug Fixes

  • The endpoint sequence filter now ignores GET requests, so a background sync left in flight by an earlier test file can no longer break the sequence assertion; a new test replays that stray lookup to lock in the fix.
  • The open call that launches a created workspace's manage URL is now stubbed before modules load, so local runs don't open real browser tabs; the stub records URLs so the test still asserts the open happens. Because mock.module is process-wide, the stub returns a subprocess-like emitter so the oauth-browser tests (which mock the same module) keep working.

Summary by CodeRabbit

  • Tests
    • Expanded coverage for workspace creation and CLI behavior. Checks now verify that a background lookup before workspace creation does not affect the sequence of write requests, and that the management page opens after creating an unlinked workspace. These checks help confirm that the creation flow and its resulting page behave as expected.