Compare commits

...
Author SHA1 Message Date
Antigravity AI c57a90ccab test(e2e): add marketplace instance auto-discovery E2E tests
- playwright.marketplace.config.ts: standalone config that starts only
  the marketplace on port 3002, no Docker/Postgres required
- tests/marketplace-from-instance.spec.ts: 4 marketplace-side tests
  (capture valid URL, reject javascript: protocol, reject self-origin,
  skip when no param) + 1 full-flow test (worldwideview -> marketplace,
  auto-skipped when running under marketplace-only config)
- NEXT_PUBLIC_MARKETPLACE_URL env var in BrowseLink lets tests point
  to localhost:3002 instead of the production marketplace
- data-testid="browse-plugins-btn" for stable Playwright selector
- playwright.config.ts updated with both webServers for full E2E

Run marketplace tests (no Docker): pnpm exec playwright test --config=playwright.marketplace.config.ts
Run full E2E (Docker required):    pnpm test:e2e
2026-05-25 02:10:53 +12:00
Antigravity AI 03fe11c63d feat(marketplace): pass from_instance origin when opening marketplace
BrowseLink in PluginsTab now appends ?from_instance=<origin> so the
marketplace can silently capture the instance URL into localStorage,
skipping the manual InstanceConfig modal for users arriving from the app.
2026-05-25 01:51:45 +12:00
5 changed files with 222 additions and 12 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "worldwideview",
"version": "2.18.3",
"version": "2.19.1",
"private": true,
"type": "module",
"packageManager": "[email protected]",
+26 -8
View File
@@ -1,4 +1,9 @@
import { defineConfig, devices } from '@playwright/test';
import path from 'path';
import { fileURLToPath } from 'url';
const __dir = path.dirname(fileURLToPath(import.meta.url));
const MARKETPLACE_DIR = path.resolve(__dir, '../worldwideview-marketplace');
/**
* See https://playwright.dev/docs/test-configuration.
@@ -61,12 +66,25 @@ export default defineConfig({
},
],
/* Run your local dev server before starting the tests */
webServer: {
command: 'pnpm dev',
env: { PORT: '3001' },
url: 'http://localhost:3001',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000,
},
/* Run dev servers before starting the tests */
webServer: [
{
command: 'pnpm dev',
env: {
PORT: '3001',
NEXT_PUBLIC_MARKETPLACE_URL: 'http://localhost:3002',
},
url: 'http://localhost:3001',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000,
},
{
command: 'pnpm dev',
cwd: MARKETPLACE_DIR,
env: { PORT: '3002' },
url: 'http://localhost:3002',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000,
},
],
});
+46
View File
@@ -0,0 +1,46 @@
/**
* Marketplace-only E2E config.
* Runs against the marketplace dev server on port 3002 only.
* No worldwideview auth or Docker/Postgres required.
*
* Usage:
* pnpm exec playwright test --config=playwright.marketplace.config.ts
*/
import { defineConfig, devices } from '@playwright/test';
import path from 'path';
import { fileURLToPath } from 'url';
const __dir = path.dirname(fileURLToPath(import.meta.url));
const MARKETPLACE_DIR = path.resolve(__dir, '../worldwideview-marketplace');
export default defineConfig({
timeout: 30000,
expect: { timeout: 10000 },
testDir: './tests',
testMatch: '**/marketplace-from-instance.spec.ts',
fullyParallel: false,
retries: 0,
workers: 1,
reporter: 'list',
use: {
baseURL: 'http://localhost:3002',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
webServer: {
command: 'pnpm dev',
cwd: MARKETPLACE_DIR,
env: { PORT: '3002' },
url: 'http://localhost:3002',
reuseExistingServer: true,
timeout: 90 * 1000,
},
});
+12 -3
View File
@@ -61,17 +61,26 @@ function TrustBadge({ trust }: { trust: string }) {
// ─── Browse Link ────────────────────────────────────────────
const MARKETPLACE_BASE = process.env.NEXT_PUBLIC_MARKETPLACE_URL ?? "https://marketplace.worldwideview.dev";
function BrowseLink() {
function handleClick(e: React.MouseEvent<HTMLAnchorElement>) {
e.preventDefault();
trackEvent("marketplace-browse-click");
const url = `${MARKETPLACE_BASE}?from_instance=${encodeURIComponent(window.location.origin)}`;
window.open(url, "_blank", "noopener,noreferrer");
}
return (
<a
href="https://marketplace.worldwideview.dev"
href={MARKETPLACE_BASE}
target="_blank"
rel="noopener noreferrer"
className="plugins-tab__browse"
onClick={() => trackEvent("marketplace-browse-click")}
data-testid="browse-plugins-btn"
onClick={handleClick}
>
<ExternalLink size={14} />
Marketplace
Browse Plugins
</a>
);
}
+137
View File
@@ -0,0 +1,137 @@
import { test, expect } from '@playwright/test';
/**
* Marketplace instance auto-discovery E2E tests.
*
* Two test groups:
*
* 1. "capture side" — navigates directly to the marketplace with
* ?from_instance=... and verifies InstanceCapture stores it.
* Runs with playwright.marketplace.config.ts (no worldwideview / Docker needed).
*
* 2. "full flow" — opens worldwideview, clicks Browse Plugins, and verifies
* the marketplace receives the param. Needs the main playwright.config.ts
* (Docker + Postgres required for auth).
*/
const MARKETPLACE_URL = 'http://localhost:3002';
const WWV_ORIGIN = 'http://localhost:3001';
const FROM_INSTANCE_PARAM = `from_instance=${encodeURIComponent(WWV_ORIGIN)}`;
// ─── Marketplace capture side (no worldwideview auth needed) ────────────────
test.describe('InstanceCapture — marketplace receives from_instance', () => {
test('captures valid origin, writes localStorage, cleans URL', async ({ page }) => {
// Navigate as the marketplace would be opened by worldwideview.
// InstanceCapture runs during React hydration (useEffect), so by the time
// page.goto() resolves the URL may already be clean — that is correct behavior.
await page.goto(`${MARKETPLACE_URL}/?${FROM_INSTANCE_PARAM}`);
// Wait for InstanceCapture to write to localStorage (may already be set)
await page.waitForFunction(
() => localStorage.getItem('wwv_instance_url') !== null,
{ timeout: 15000 }
);
// localStorage has the correct origin-only value
const stored = await page.evaluate(() => localStorage.getItem('wwv_instance_url'));
expect(stored).toBe(WWV_ORIGIN);
// from_instance param was stripped by history.replaceState
expect(page.url()).not.toContain('from_instance');
});
test('rejects javascript: protocol and leaves localStorage empty', async ({ page }) => {
// Clear any prior localStorage from the same origin
await page.goto(MARKETPLACE_URL);
await page.evaluate(() => localStorage.removeItem('wwv_instance_url'));
await page.goto(`${MARKETPLACE_URL}/?from_instance=${encodeURIComponent('javascript:alert(1)')}`);
// Give InstanceCapture time to run
await page.waitForTimeout(1500);
const stored = await page.evaluate(() => localStorage.getItem('wwv_instance_url'));
expect(stored).toBeNull();
});
test('rejects self-referential origin and leaves localStorage empty', async ({ page }) => {
await page.goto(MARKETPLACE_URL);
await page.evaluate(() => localStorage.removeItem('wwv_instance_url'));
// from_instance points at the marketplace itself — should be rejected
await page.goto(`${MARKETPLACE_URL}/?from_instance=${encodeURIComponent(MARKETPLACE_URL)}`);
await page.waitForTimeout(1500);
const stored = await page.evaluate(() => localStorage.getItem('wwv_instance_url'));
expect(stored).toBeNull();
});
test('direct navigation without param leaves localStorage unchanged', async ({ page }) => {
await page.goto(MARKETPLACE_URL);
await page.evaluate(() => localStorage.removeItem('wwv_instance_url'));
await page.reload();
await page.waitForLoadState('load');
await page.waitForTimeout(1000);
const stored = await page.evaluate(() => localStorage.getItem('wwv_instance_url'));
expect(stored).toBeNull();
});
});
// ─── Full flow (worldwideview → marketplace, requires Docker + auth) ─────────
test.describe('Full flow — Browse Plugins in worldwideview opens marketplace', () => {
test.beforeEach(async ({ page, baseURL }) => {
// Skip when running with the marketplace-only config (baseURL = 3002)
test.skip(baseURL !== WWV_ORIGIN, 'Requires worldwideview running (main config + Docker)');
await page.goto('/');
await page.waitForSelector('[data-testid="app-ready"]', { state: 'attached', timeout: 45000 });
// Dismiss unverified plugin dialog if it appears
try {
const installBtn = page.getByRole('button', { name: /Install Selected/ });
await installBtn.waitFor({ state: 'visible', timeout: 2000 });
await installBtn.click();
} catch { /* not present */ }
// Ensure left panel is open
const leftToggle = page.locator('[data-testid="panel-toggle-left"]');
const isOpen = await leftToggle.evaluate((el) => el.classList.contains('panel-toggle-btn--open'));
if (!isOpen) await leftToggle.click();
});
test('Browse Plugins appends from_instance and marketplace captures it', async ({ page }) => {
// Navigate to Plugins tab
const pluginsTab = page.locator('button.panel-tab[title="Plugins"]');
await expect(pluginsTab).toBeVisible({ timeout: 10000 });
await pluginsTab.click();
const browseBtn = page.locator('[data-testid="browse-plugins-btn"]');
await expect(browseBtn).toBeVisible({ timeout: 5000 });
// Click and capture the popup
const popupPromise = page.waitForEvent('popup');
await browseBtn.click();
const popup = await popupPromise;
// Initial URL has from_instance
expect(popup.url()).toContain(FROM_INSTANCE_PARAM);
// InstanceCapture writes to localStorage
await popup.waitForFunction(
() => localStorage.getItem('wwv_instance_url') !== null,
{ timeout: 15000 }
);
const stored = await popup.evaluate(() => localStorage.getItem('wwv_instance_url'));
expect(stored).toBe(WWV_ORIGIN);
// URL cleaned up
expect(popup.url()).not.toContain('from_instance');
await popup.close();
});
});