Skip to content

Commit 7c5adb3

Browse files
samuelcoleclaude
andauthored
Check the demo pages with Harbor actually loaded, and delete Playwright fixtures that never loaded it (#165)
Playwright can't load Harbor into a Firefox it drives, so the Harbor-dependent Playwright fixtures never had Harbor in the page, and the 19 tests built on them were always skipped. This deletes those fixtures and tests (demo-pages.spec.ts, harbor-flow.spec.ts, permissions.spec.ts, webext-firefox.ts, and the skipped cases in extension-load.spec.ts and native-bridge.spec.ts), and reduces fixtures/extension.ts to the plain browserContext fixture. The demo-page check moves to a new tests/e2e/test-demo-pages.mjs, run with `npm run test:demo-pages` (also part of `test:all`). It launches Firefox with the built extension, serves demo/ on a free loopback port, and checks that Getting Started, Summarizer, Time Agent and Bring Your Chatbot each get window.agent and LanguageModel. On the chatbot page it waits for the page's own script to reveal the chat button, which it does only after finding Harbor's API. global-setup now checks extension/dist-firefox/manifest.json, which is what the build produces, and run-browser-tests.mjs drops its extension/dist fallback. tests/README.md and demo/README.md describe what the Playwright specs can and can't check, list the remaining fixtures, and no longer name a CI workflow that doesn't exist. Fixes HBR-122 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 45fc7e9 commit 7c5adb3

15 files changed

Lines changed: 218 additions & 639 deletions

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
160160
- When Harbor refuses a page's `agent.chat.open()`, the page now gets the policy engine's code (`ERR_BLOCKED_BY_POLICY`, `ERR_PERMISSION_DENIED`, `ERR_QUARANTINED`) instead of `ERR_CHAT_OPEN`, so it can tell a refusal from a failure. `agent.mcp.register()` and `unregister()` report their refusal of another origin's server as `ERR_PERMISSION_DENIED` instead of `ERR_MCP_REGISTER` / `ERR_MCP_UNREGISTER`. Other failures keep their codes.
161161
- `window.ai.providers.getActive()` now needs the site's `model:list` grant, as the spec says, like the other `window.ai.providers` calls. Before, any page could read which model the person uses. All four `window.ai.providers` calls now go through Harbor's policy engine: they appear in the Activity panel, and a policy rule can deny them.
162162
- A page's prompt to an LM Studio or llamafile model, or to a provider instance the person named (such as `my-ollama:llama3`), is now checked and audited as a local prompt, since it runs on this machine. Before, Harbor judged by the model's name and logged these as remote, so rules written for local models didn't match them. The native bridge decides, through a new `llm.model_locality` request; with an older bridge, Harbor still judges by the name.
163+
- **The demo-page checks now show Harbor actually reaching each page.** `tests/e2e/specs/demos/demo-pages.spec.ts` ran in a Playwright Firefox with no extension, so it only confirmed that each page's body was visible. `npm run test:demo-pages` (`tests/e2e/test-demo-pages.mjs`) now launches Firefox with the built extension and checks that `window.agent` and `LanguageModel` reach Getting Started, the Summarizer, Time Agent and Bring Your Own Chatbot. Playwright can't load Harbor into a Firefox it drives, so the Playwright fixtures that claimed to (`extensionContext`, `extensionId`, `sidebarPage` and `fixtures/webext-firefox.ts`) are deleted, along with the 19 always-skipped tests that used them.
164+
- `tests/e2e`'s Playwright `globalSetup` checked for the extension at `extension/dist/manifest.json`, which `npm run build` never writes (it writes `extension/dist-firefox/`), so every Playwright run believed the extension was missing and rebuilt it, recompiling the native bridge from scratch too.
163165

164166
### Removed
165167

‎demo/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ cd tests/e2e
6464
npx playwright install firefox
6565
npx playwright test specs/demos/demo-layout.spec.ts specs/demos/demo-behavior.spec.ts
6666
npm run test:browser
67+
npm run test:demo-pages
6768
```
6869

69-
The layout suite checks all 11 pages at 360px and 1280px in both system themes. Behavior tests use page-boundary API fakes to cover consent, tool names, wizard transitions, research streams, cleanup and failure states; they do not replace testing with Harbor, the bridge and a real model. Keep `playwright` and `@playwright/test` at the same version and install the matching Firefox build after updating them.
70+
The layout suite checks all 11 pages at 360px and 1280px in both system themes. Behavior tests use page-boundary API fakes to cover consent, tool names, wizard transitions, research streams, cleanup and failure states; they do not replace testing with Harbor, the bridge and a real model. Keep `playwright` and `@playwright/test` at the same version and install the matching Firefox build after updating them. `test:demo-pages` (`test-demo-pages.mjs`) is not a Playwright test: Playwright can't load Harbor into a Firefox tab it drives, so it launches a real Firefox with the built extension itself and checks that `window.agent`/`LanguageModel` actually reach Getting Started, the Summarizer, Time Agent and Bring Your Own Chatbot — a page merely loading proves nothing.
7071

7172
For real interactions, use a temporary Firefox profile and enable **Browser Interaction** for Basic Actions and Multi-step Form, and **Browser Control** for Research Agent. Reload after changing flags. Getting Started and Time Agent ask for the specific built-in time tool as well as its scope; listing a tool does not grant permission to call it. The wizard waits for its own DOM transitions locally—there is no `agent.browser.activeTab.waitForSelector()` API.
7273

‎tests/README.md‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ It needs the network and a live third-party site, so it is run by hand and is no
5959
```
6060
tests/
6161
├── e2e/ # End-to-end browser tests (Playwright)
62-
│ ├── fixtures/ # Test fixtures (extension loading, native bridge, etc.)
62+
│ ├── fixtures/ # Playwright fixtures (plain Firefox, native bridge, demo server)
6363
│ ├── specs/ # Test specifications
6464
│ │ ├── extension-load.spec.ts
6565
│ │ ├── native-bridge.spec.ts
@@ -89,7 +89,7 @@ npm run test:setup
8989
```
9090

9191
This will:
92-
- Build the extension (`extension/dist/`)
92+
- Build the extension (`extension/dist-firefox/`)
9393
- Build the native bridge (`bridge-rs/target/release/harbor-bridge`)
9494
- Install the native messaging manifest
9595

@@ -121,7 +121,7 @@ cargo test --manifest-path bridge-rs/Cargo.toml
121121

122122
### E2E Tests
123123

124-
E2E tests use Playwright to automate Firefox with the extension installed.
124+
The Playwright specs drive a plain Firefox with no extension: Playwright can't load Harbor into a Firefox it drives. They cover the demo pages against page-boundary API fakes, and the native bridge install. Tests that need Harbor itself launch Firefox with the built extension and drive it over the remote debugging protocol: `npm run test:browser`, `npm run test:demo-pages` and the other `test-*.mjs` scripts in `tests/e2e`.
125125

126126
```bash
127127
# Run all e2e tests
@@ -137,7 +137,7 @@ npm run test:e2e:debug
137137
cd tests/e2e && npx playwright test specs/extension-load.spec.ts
138138

139139
# Run tests matching a pattern
140-
cd tests/e2e && npx playwright test -g "extension loads"
140+
cd tests/e2e && npx playwright test -g "native bridge"
141141
```
142142

143143
### Viewing Test Reports
@@ -171,8 +171,8 @@ describe('myFunction', () => {
171171
import { test, expect } from '../fixtures/index.js';
172172

173173
test.describe('My Feature', () => {
174-
test('should work correctly', async ({ extensionContext, demoServer }) => {
175-
const page = await extensionContext.newPage();
174+
test('should work correctly', async ({ browserContext, demoServer }) => {
175+
const page = await browserContext.newPage();
176176
await page.goto(`${demoServer.url}/web-agents/my-demo/`);
177177

178178
// Test assertions
@@ -183,22 +183,21 @@ test.describe('My Feature', () => {
183183

184184
### Available Fixtures
185185

186-
- `extensionContext` - Browser context with Harbor loaded
187-
- `extensionId` - Harbor extension UUID
188-
- `sidebarPage` - Harbor sidebar page (already open)
186+
- `browserContext` - Plain Firefox browser context, without Harbor
187+
- `bridgeInstalled` - Whether the native bridge binary and manifest are installed
189188
- `nativeBridge` - Running native bridge process
190189
- `demoServer` - Local HTTP server serving demo files
191190

192191
## CI/CD
193192

194-
Tests run automatically on GitHub Actions. See `.github/workflows/test.yml`.
193+
No CI workflow runs these tests; the only GitHub Actions workflow deploys the Pages site.
195194

196195
## Troubleshooting
197196

198197
### Extension not loading
199198

200199
1. Make sure the extension is built: `npm run build`
201-
2. Check that `extension/dist/manifest.json` exists
200+
2. Check that `extension/dist-firefox/manifest.json` exists
202201

203202
### Native bridge errors
204203

@@ -214,6 +213,5 @@ Tests run automatically on GitHub Actions. See `.github/workflows/test.yml`.
214213

215214
### Firefox profile issues
216215

217-
- Each test run creates a fresh Firefox profile
218-
- Profiles are cleaned up automatically
219-
- If issues persist, manually clear `/tmp/harbor-test-*` directories
216+
- Each run creates a fresh temporary Firefox profile and removes it afterwards
217+
- After a run that was killed, check for a leftover test Firefox and stop only that process, not your own Firefox

‎tests/e2e/fixtures/extension.ts‎

Lines changed: 11 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,32 @@
11
/**
2-
* Playwright fixture for loading the Harbor extension in Firefox.
3-
*
4-
* Firefox extension loading is complex. This fixture provides:
5-
* 1. A basic browser context (no extensions) for simple page tests
6-
* 2. Extension-aware context using web-ext for full integration tests
2+
* Playwright fixture for a plain Firefox browser context.
3+
*
4+
* This context has no extensions. Playwright can't load Harbor into a Firefox
5+
* it drives, so tests that need Harbor itself use the launch-and-RDP scripts
6+
* in tests/e2e (`npm run test:browser`, `npm run test:demo-pages` and the
7+
* other `test-*.mjs`).
78
*/
89

9-
import { test as base, firefox, type BrowserContext, type Page } from '@playwright/test';
10-
import path from 'path';
11-
import fs from 'fs/promises';
12-
import os from 'os';
13-
import { fileURLToPath } from 'url';
14-
import { spawn, type ChildProcess, execSync } from 'child_process';
15-
16-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
17-
18-
// Path relative to the test fixtures directory
19-
const EXTENSION_PATH = path.resolve(__dirname, '../../../extension/dist');
10+
import { test as base, firefox, type BrowserContext } from '@playwright/test';
2011

2112
export type ExtensionFixtures = {
2213
/** Basic browser context without extensions - for simple page tests */
2314
browserContext: BrowserContext;
24-
/** Browser context with the extension loaded via web-ext */
25-
extensionContext: BrowserContext;
26-
extensionId: string;
27-
sidebarPage: Page;
2815
};
2916

30-
/**
31-
* Check if web-ext is available
32-
*/
33-
function hasWebExt(): boolean {
34-
try {
35-
execSync('npx web-ext --version', { stdio: 'ignore' });
36-
return true;
37-
} catch {
38-
return false;
39-
}
40-
}
41-
4217
export const test = base.extend<ExtensionFixtures>({
43-
/**
44-
* Basic browser context without extensions.
45-
* Use this for tests that just need to load web pages.
46-
*/
4718
browserContext: async ({}, use) => {
48-
const context = await firefox.launch({
19+
const browser = await firefox.launch({
4920
headless: false,
5021
firefoxUserPrefs: {
5122
'devtools.chrome.enabled': true,
5223
},
5324
});
54-
55-
const browserContext = await context.newContext();
25+
26+
const browserContext = await browser.newContext();
5627
await use(browserContext);
5728
await browserContext.close();
58-
await context.close();
59-
},
60-
61-
/**
62-
* Browser context with extensions.
63-
*
64-
* This uses a persistent context with extensions installed via profile.
65-
* For full extension testing, web-ext is recommended but adds complexity.
66-
*/
67-
extensionContext: async ({}, use) => {
68-
// Create a temporary profile directory
69-
const profileDir = await fs.mkdtemp(path.join(os.tmpdir(), 'harbor-test-'));
70-
71-
// Write Firefox preferences to enable extension loading
72-
const prefsContent = [
73-
'user_pref("xpinstall.signatures.required", false);',
74-
'user_pref("extensions.autoDisableScopes", 0);',
75-
'user_pref("extensions.enabledScopes", 15);',
76-
'user_pref("devtools.chrome.enabled", true);',
77-
'user_pref("app.update.enabled", false);',
78-
'user_pref("browser.shell.checkDefaultBrowser", false);',
79-
'user_pref("datareporting.policy.dataSubmissionEnabled", false);',
80-
'user_pref("toolkit.telemetry.reportingpolicy.firstRun", false);',
81-
].join('\n');
82-
83-
await fs.writeFile(path.join(profileDir, 'user.js'), prefsContent);
84-
85-
// Launch Firefox with the profile
86-
const context = await firefox.launchPersistentContext(profileDir, {
87-
headless: false,
88-
firefoxUserPrefs: {
89-
'xpinstall.signatures.required': false,
90-
'extensions.autoDisableScopes': 0,
91-
'extensions.enabledScopes': 15,
92-
},
93-
});
94-
95-
await use(context);
96-
97-
// Cleanup
98-
await context.close();
99-
try {
100-
await fs.rm(profileDir, { recursive: true, force: true });
101-
} catch {
102-
// Ignore cleanup errors
103-
}
104-
},
105-
106-
/**
107-
* Harbor extension UUID - placeholder for now
108-
*/
109-
extensionId: async ({}, use) => {
110-
// Extension UUID is assigned dynamically by Firefox
111-
// For tests that need this, they should load via about:debugging
112-
await use('extension-not-loaded');
113-
},
114-
115-
/**
116-
* Harbor sidebar page - requires extension to be loaded
117-
*/
118-
sidebarPage: async ({ extensionContext }, use) => {
119-
const page = await extensionContext.newPage();
120-
// Can't navigate to extension page without UUID
121-
// Tests using this will need to handle the case
122-
await use(page);
29+
await browser.close();
12330
},
12431
});
12532

‎tests/e2e/fixtures/global-setup.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export default async function globalSetup() {
2828
console.log('\n🚀 Harbor E2E Test Setup\n');
2929

3030
// 1. Check extension build
31-
const extensionDist = path.join(ROOT, 'extension/dist/manifest.json');
31+
// `npm run build` (the default, Firefox target) writes extension/dist-firefox/,
32+
// never extension/dist/. Checking the wrong path made this rebuild, and
33+
// recompile the Rust bridge below, on every single run.
34+
const extensionDist = path.join(ROOT, 'extension/dist-firefox/manifest.json');
3235
if (!(await fileExists(extensionDist))) {
3336
console.log('📦 Extension not built. Building...');
3437
try {

‎tests/e2e/fixtures/index.ts‎

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
/**
2-
* Combined test fixtures for Harbor E2E tests.
3-
*
4-
* We have two fixture approaches:
5-
*
6-
* 1. Basic fixtures (this file) - For tests that don't need extensions
7-
* - browserContext: Basic Firefox browser
8-
* - bridgeInstalled: Verifies native bridge is installed
9-
* - demoServer: Local server for demo files
10-
*
11-
* 2. WebExt fixtures (webext-firefox.ts) - For tests that need Harbor extension
12-
* - harborBrowser: Firefox with Harbor extension loaded via about:debugging
13-
* - sidebarPage: Harbor sidebar page ready to use
14-
*
15-
* Usage:
16-
* // For basic tests:
17-
* import { test, expect } from '../fixtures/index.js';
18-
*
19-
* // For extension tests:
20-
* import { test, expect } from '../fixtures/webext-firefox.js';
2+
* Combined Playwright fixtures for Harbor E2E tests. None of them load the
3+
* Harbor extension; Playwright can't load it into a Firefox it drives. Tests
4+
* that need Harbor use the launch-and-RDP scripts in tests/e2e instead
5+
* (`npm run test:browser`, `npm run test:demo-pages` and the other `test-*.mjs`).
6+
*
7+
* - browserContext: basic Firefox browser, no extensions
8+
* - bridgeInstalled / nativeBridge: the native bridge is installed and spawns
9+
* - demoServer: local server for the demo files
2110
*/
2211

2312
import { mergeTests } from '@playwright/test';
@@ -34,6 +23,3 @@ export { expect } from '@playwright/test';
3423
export type { ExtensionFixtures } from './extension.js';
3524
export type { NativeBridgeFixtures } from './native-bridge.js';
3625
export type { DemoServerFixtures } from './demo-server.js';
37-
38-
// Re-export webext fixtures for convenience
39-
export { test as harborTest, expect as harborExpect, type WebExtFixtures } from './webext-firefox.js';

0 commit comments

Comments
 (0)