stably 4.12.16 → 4.12.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // ../../app/node_modules/.pnpm/@stablyai-internal+playwright-cli@0.4.30/node_modules/@stablyai-internal/playwright-cli/playwright-cli.js
3
+ // ../../app/node_modules/.pnpm/@stablyai-internal+playwright-cli@0.4.32/node_modules/@stablyai-internal/playwright-cli/playwright-cli.js
4
4
  var fs = require("fs");
5
5
  var path = require("path");
6
6
  if (process.platform === "darwin" && !process.env.PLAYWRIGHT_DAEMON_SOCKETS_DIR) {
@@ -261,7 +261,10 @@ function createReconnectableBrowserProxy(playwright) {
261
261
  } catch (error) {
262
262
  if (!isRecoverableCdpError(error)) throw error;
263
263
  const freshBrowser = await reconnectBrowser(playwright);
264
- return freshBrowser.newContext(...args);
264
+ // Prefer the default context (from connectOverCDP) over creating a new one.
265
+ // Creating a new context isolates cookies/localStorage from the default
266
+ // context where the auth login session lives, causing auth failures.
267
+ return freshBrowser.contexts()[0] || freshBrowser.newContext(...args);
265
268
  }
266
269
  };
267
270
  }
@@ -369,7 +372,12 @@ const test = realPw.test.extend({
369
372
  }
370
373
 
371
374
  // Apply storageState from the fixture chain (custom fixture or project config).
372
- // This covers both: use: { storageState: 'path' } AND custom fixture overrides.
375
+ // Store the path so the page fixture can re-apply localStorage on new pages.
376
+ if (storageState && typeof storageState === 'string') {
377
+ const path = require('path');
378
+ process.env.__STABLY_STORAGE_STATE_PATH__ = path.isAbsolute(storageState)
379
+ ? storageState : path.resolve(process.cwd(), storageState);
380
+ }
373
381
  if (storageState) {
374
382
  try {
375
383
  // Try Playwright's native setStorageState first (newer versions)
@@ -405,39 +413,31 @@ const test = realPw.test.extend({
405
413
  // No close \u2014 preserve state for post-test inspection
406
414
  },
407
415
 
408
- // Test-scoped: create a fresh page for each test to avoid stale CDP frame references.
409
- // The previous test's page is closed to free resources. The new page gets a fresh
410
- // CDP frame, avoiding the "second test always fails" issue where the reused page's
411
- // internal frame reference becomes invalid between fixture teardown/setup cycles.
416
+ // Test-scoped: reuse the existing page for each test.
417
+ // Between tests, Playwright's frame tree can go stale \u2014 execution contexts are
418
+ // destroyed but not recreated. Navigating to about:blank triggers
419
+ // Runtime.executionContextDestroyed + Created, giving fresh contexts.
420
+ // Reusing the page (instead of creating new ones) ensures the daemon's MCP
421
+ // _currentTab always points to the actual test page with full state after run-test.
412
422
  page: async ({ context, browser, playwright, baseURL, extraHTTPHeaders, httpCredentials, geolocation, permissions, offline }, use, testInfo) => {
413
- // Get or create a page. We reuse the existing page (don't close it \u2014 closing
414
- // the last page on a CDP default context can terminate the browser process).
415
- // Instead, navigate to about:blank to reset frame state.
416
- let page = context.pages()[0];
417
- if (!page) {
418
- try {
419
- page = await context.newPage();
420
- } catch (error) {
421
- if (!isRecoverableCdpError(error)) throw error;
422
- const freshBrowser = await reconnectBrowser(playwright);
423
- const ctx = freshBrowser.contexts()[0] || await freshBrowser.newContext();
424
- page = ctx.pages()[0] || await ctx.newPage();
425
- }
426
- }
427
- // Navigate to about:blank to get a fresh frame/document, avoiding stale
428
- // frame references from the previous test. This is cheaper than closing
429
- // and recreating the page (which can kill the CDP browser).
423
+ // Reuse the existing page instead of creating new pages.
424
+ // This ensures the daemon's MCP _currentTab always points to the actual
425
+ // test page with full state (DOM, cookies, localStorage, etc.).
426
+ // Navigate to about:blank between tests to refresh Playwright's frame tree
427
+ // (triggers Runtime.executionContextDestroyed + Created, fixing stale frames).
428
+ let page;
430
429
  try {
431
- await page.goto('about:blank', { timeout: 5000 });
432
- } catch {
433
- // If navigation fails, the page might be stale \u2014 create a new one
434
- try {
435
- page = await context.newPage();
436
- } catch (error) {
437
- if (!isRecoverableCdpError(error)) throw error;
430
+ page = context.pages()[0];
431
+ if (!page) page = await context.newPage();
432
+ await page.goto('about:blank');
433
+ } catch (error) {
434
+ if (isRecoverableCdpError(error)) {
438
435
  const freshBrowser = await reconnectBrowser(playwright);
439
436
  const ctx = freshBrowser.contexts()[0] || await freshBrowser.newContext();
440
437
  page = ctx.pages()[0] || await ctx.newPage();
438
+ await page.goto('about:blank').catch(() => {});
439
+ } else {
440
+ throw error;
441
441
  }
442
442
  }
443
443
 
@@ -502,7 +502,7 @@ const test = realPw.test.extend({
502
502
  }
503
503
  }
504
504
  await use(page);
505
- // No close \u2014 page must survive for snapshot
505
+ // No close \u2014 page must survive for daemon interaction after run-test.
506
506
  },
507
507
  });
508
508
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stably",
3
- "version": "4.12.16",
3
+ "version": "4.12.17",
4
4
  "packageManager": "pnpm@10.24.0",
5
5
  "description": "AI-powered E2E Playwright testing CLI. Stably can understand your codebase, edit/run tests, and handle complex test scenarios for you.",
6
6
  "main": "dist/index.mjs",
@@ -87,7 +87,7 @@
87
87
  "playwright": "1.59.0-alpha-1771104257000",
88
88
  "@stablyai/codegen-agent-constants": "workspace:*",
89
89
  "@stablyai-internal/api-client": "workspace:*",
90
- "@stablyai-internal/playwright-cli": "0.4.30",
90
+ "@stablyai-internal/playwright-cli": "0.4.32",
91
91
  "@stablyai-internal/pwtrace": "0.3.1",
92
92
  "@stablyai/agent-hooks": "workspace:*",
93
93
  "@stablyai/agent-schemas": "workspace:*",