@botiverse/porthole 0.3.1 → 0.3.3
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.
- package/dist/bridge/bridge.d.ts +2 -5
- package/dist/bridge/types.d.ts +11 -4
- package/dist/check/check.d.ts +2 -2
- package/dist/check/check.js +4 -19
- package/dist/check/page-source.js +1 -1
- package/dist/conformance/harness-source.d.ts +2 -0
- package/dist/conformance/harness-source.js +2 -0
- package/dist/conformance/host-kit.d.ts +2 -2
- package/dist/conformance/host-kit.js +4 -27
- package/dist/host/create-host.js +5 -1
- package/dist/index.d.ts +1 -1
- package/dist/node/index.d.ts +4 -1
- package/dist/node/index.js +3 -1
- package/dist/react/frame.js +8 -1
- package/dist/server/host.d.ts +4 -1
- package/dist/server/host.js +6 -0
- package/docs/ADOPTING.md +16 -5
- package/docs/DECISIONS.md +53 -0
- package/docs/DESIGN.md +6 -3
- package/package.json +5 -3
- package/src/bridge/bridge.ts +2 -1
- package/src/bridge/types.ts +12 -1
- package/src/check/check.ts +6 -17
- package/src/check/page-source.ts +4 -3
- package/src/conformance/harness-source.ts +23 -0
- package/src/conformance/host-kit.ts +4 -27
- package/src/host/create-host.ts +5 -1
- package/src/index.ts +1 -0
- package/src/node/index.ts +7 -2
- package/src/react/frame.tsx +8 -1
- package/src/server/host.ts +10 -1
- package/dist/conformance/harness.js +0 -1662
package/docs/ADOPTING.md
CHANGED
|
@@ -65,7 +65,9 @@ reads the page's), `handlers`, `openLink` (default: a new tab), `notify` (your o
|
|
|
65
65
|
a copy button copied), and `renderConfirm` (your own dialog, given `accept`, `decline` and
|
|
66
66
|
`redirect`: Porthole keeps the queue, runs `accept` inside its click, and counts declines toward
|
|
67
67
|
muting the display; `redirect`, for "edit it first", answers the call `"redirected"` and neither
|
|
68
|
-
counts nor resets the count).
|
|
68
|
+
counts nor resets the count). The request names the display (`request.display`: its `id`,
|
|
69
|
+
`title`, and the `instance` a served frame shows), so the dialog can say what it is from your own
|
|
70
|
+
records. `useRunAgain()` gives a "run again" button.
|
|
69
71
|
|
|
70
72
|
## 4. Served pages: the host kit
|
|
71
73
|
|
|
@@ -132,7 +134,10 @@ nodeServer({ content, app: async (request) => (await routes(request)) ?? app(req
|
|
|
132
134
|
every other request to `app` (fetch-style: Hono's `app.fetch`) or `request` (a Node listener:
|
|
133
135
|
Express), the health gate started on listen and stopped on close. Behind a TLS edge, add
|
|
134
136
|
`scheme: "https"`. A host that needs the port first (`listen(0)`) can come later: `content:
|
|
135
|
-
() => host` (null until made); requests go to the app until it gives one.
|
|
137
|
+
() => host` (null until made); requests go to the app until it gives one. `nodeServer` starts
|
|
138
|
+
the host it is given: a host made in a `listen` callback starts right after it, and one made
|
|
139
|
+
later at the next request. `start()` runs once (a started host ignores it), so starting it
|
|
140
|
+
yourself as soon as you make it is fine too.
|
|
136
141
|
- **`nodeHost(content, { request })`** is for an app that keeps its own `node:http` server (or a
|
|
137
142
|
framework that owns one): put its `request` and `upgrade` listeners on your server, call
|
|
138
143
|
`content.start()` once it listens and `content.close()` when it stops.
|
|
@@ -338,13 +343,19 @@ opaque frame, so the agent reads only "Script error.", and names no line in a se
|
|
|
338
343
|
```js
|
|
339
344
|
import puppeteer from "@cloudflare/puppeteer";
|
|
340
345
|
import { cdpDriver, checkPage } from "@botiverse/porthole/check";
|
|
341
|
-
import page from "@botiverse/porthole/check/page"; // the check page's script, bundled
|
|
342
346
|
const browser = await puppeteer.launch(env.BROWSER);
|
|
343
347
|
const tab = await browser.newPage();
|
|
344
|
-
const report = await checkPage({ config, content,
|
|
348
|
+
const report = await checkPage({ config, content, driver: cdpDriver(() => tab.createCDPSession()) }); // no cast
|
|
345
349
|
await browser.close();
|
|
346
350
|
```
|
|
347
351
|
|
|
352
|
+
**Bundling:** every entry point bundles whole (a Worker, a single executable): `/check` imports
|
|
353
|
+
its check page's script as a module, and `/conformance` its harness, so nothing is looked up
|
|
354
|
+
beside a module at run time. Each release is bundled with rolldown and esbuild and checked for
|
|
355
|
+
that before it is published (`test:bundle`). `/conformance`, which runs under Playwright, still
|
|
356
|
+
looks for the optional MCP Apps App SDK where it runs; without it, the App SDK probes say so and
|
|
357
|
+
don't run.
|
|
358
|
+
|
|
348
359
|
## 7. Conformance: prove your integration
|
|
349
360
|
|
|
350
361
|
`@botiverse/porthole/conformance` runs Porthole's suite (egress and escape probes, the served
|
|
@@ -432,7 +443,7 @@ prints each reason at the end; so does `--reporter=json`.
|
|
|
432
443
|
| `@botiverse/porthole/react` | `PortholeProvider`, `PortholeFrame`, `PortholeView`, `usePortholeLink`, `cssVariableTheme`, `useRunAgain` |
|
|
433
444
|
| `@botiverse/porthole/server` | `createContentHost` (`routes`, `forget`), `contentHostFor`, `prefixedName`, `memoryTicketStore`, `d1TicketStore`, `upstreamHeaders`, `statusPage`, `conformancePage`, the callbacks' types |
|
|
434
445
|
| `@botiverse/porthole/node` | `nodeServer`, `nodeHost`, `nodeProbe`, `toRequest`, `sendResponse` |
|
|
435
|
-
| `@botiverse/porthole/check` | `checkPage`, `playwrightDriver`, `cdpDriver` (`CHECK_ORIGIN`, `CHECK_CONTENT_DOMAIN`: the names a driver of your own answers); `/check/page`, the check page's script |
|
|
446
|
+
| `@botiverse/porthole/check` | `checkPage`, `playwrightDriver`, `cdpDriver` (`CHECK_ORIGIN`, `CHECK_CONTENT_DOMAIN`: the names a driver of your own answers); `/check/page`, the check page's script (`checkPage` has it already) |
|
|
436
447
|
| `@botiverse/porthole/mcp` | the MCP Apps adapter (views, the sandbox proxy) |
|
|
437
448
|
| `@botiverse/porthole/conformance` | `defineHostConformance`, `conformanceProjects`, `onDemand`, `conformancePage`; `/conformance/reporter`, skip reasons |
|
|
438
449
|
|
package/docs/DECISIONS.md
CHANGED
|
@@ -2089,3 +2089,56 @@ scheme and themeKey keep each frame element, its window and its page, opaque, se
|
|
|
2089
2089
|
(failing before item 18); the examples' unit tests and their conformance run on three engines.
|
|
2090
2090
|
**Revisit when** a driver that can't intercept requests needs served checks (it would need a
|
|
2091
2091
|
real content domain).
|
|
2092
|
+
|
|
2093
|
+
## P075 · 2026-10-12 · Every entry point bundles whole: no file looked up beside a module · Accepted
|
|
2094
|
+
|
|
2095
|
+
**Decision.** `/check` loaded its check page's script at run time from a path computed beside its
|
|
2096
|
+
module (`new URL("./page-source.js", import.meta.url)`, then `import()` of it), and `/conformance`
|
|
2097
|
+
read its harness the same way (`readFile(new URL("./harness.js", import.meta.url))`, falling back
|
|
2098
|
+
to `import("esbuild")`). A bundle has no files beside its modules: Ferry's CLI, one executable
|
|
2099
|
+
built by rolldown for Node SEA, refuses such loads at build time, and its 0.1.85 release failed
|
|
2100
|
+
on `/check`; a Worker's bundle would fail where the path runs. 0.3.2:
|
|
2101
|
+
1. **Both scripts are modules imported statically**: `check/page-source` and
|
|
2102
|
+
`conformance/harness-source`, which from the sources build the script with esbuild (Porthole's
|
|
2103
|
+
own development dependency), and which the build replaces with a module exporting the built
|
|
2104
|
+
script as a string and nothing else. `checkPage`'s `page` option stays, and is no longer
|
|
2105
|
+
needed anywhere.
|
|
2106
|
+
2. **`test:bundle`** bundles every published entry point from the build, with rolldown (for Node,
|
|
2107
|
+
one file, dynamic imports inlined) and with esbuild for Workers, lists every load left for run
|
|
2108
|
+
time as Ferry's build does (an `import()` of anything but a literal builtin, `require`,
|
|
2109
|
+
`createRequire`, the module's own location), and fails on any not reviewed in the script; then
|
|
2110
|
+
it imports each bundle from a directory with nothing else in it, and checks a page in Chromium
|
|
2111
|
+
from the `/check` bundle with no `page` given. CI and the release workflow run it after the
|
|
2112
|
+
build: a package that fails it is never published. Run on 0.3.1's build it fails, naming
|
|
2113
|
+
`/check`'s and `/conformance`'s loads.
|
|
2114
|
+
3. **The one reviewed load:** `/conformance`'s MCP probes look for the optional official App SDK
|
|
2115
|
+
where the suite runs (`createRequire(import.meta.url).resolve(...)`), inside a `try`: without it
|
|
2116
|
+
they say so and don't run. The runner runs under Playwright, from `node_modules`.
|
|
2117
|
+
4. The build empties `dist/` first, so no file of an earlier build ships.
|
|
2118
|
+
|
|
2119
|
+
**Cost.** Importing `/check` loads the check page's script (about 145 KB) with it; importing
|
|
2120
|
+
`/conformance` its harness (about 140 KB). Both were loaded on first use before.
|
|
2121
|
+
**Why.** An entry point that works only beside its own files isn't a library a bundler can take,
|
|
2122
|
+
and the failure shows only where the path runs.
|
|
2123
|
+
**Revisit when** a bundler needs code split into chunks of its own (none does yet).
|
|
2124
|
+
|
|
2125
|
+
## P076 · 2026-10-12 · A confirmation names the instance; a content host starts once · Accepted
|
|
2126
|
+
|
|
2127
|
+
**Decision.** From Ferry, #10. 0.3.3, additive:
|
|
2128
|
+
1. **`ConfirmRequest.display` carries the frame's `instance`** where the display is served
|
|
2129
|
+
(`ConfirmDisplay`: `id`, `title`, `instance?`), in the core's `confirm` and React's
|
|
2130
|
+
`renderConfirm`. A host words its dialog from its own records (Ferry: the transcript the
|
|
2131
|
+
instance belongs to) without keeping an index from display ids to them (28 lines in Ferry). The
|
|
2132
|
+
instance is the host's own, as it gave it to `mount`: nothing the content chose.
|
|
2133
|
+
2. **`ContentHost.start()` runs once**: a started host ignores it until `close`, so the app and
|
|
2134
|
+
`nodeServer` may both start it (before, each start ran a check, and the second came at the first
|
|
2135
|
+
request). **`nodeServer` asks a lazily given host right after the server's `listen` callbacks**
|
|
2136
|
+
(a host made in one, with the port it got, starts then), and again at each request until it
|
|
2137
|
+
gives one. ADOPTING says who starts it.
|
|
2138
|
+
|
|
2139
|
+
**Why.** Each was a workaround in Ferry: the side index, and starting the host itself while
|
|
2140
|
+
`nodeServer` started it again.
|
|
2141
|
+
**Measured.** `leak/react.spec.ts` (`renderConfirm` names the served frame's instance, and none
|
|
2142
|
+
for an opaque one); `test/kit03.test.ts` (a host made in the `listen` callback is checked without a
|
|
2143
|
+
request, once, however often it is started).
|
|
2144
|
+
|
package/docs/DESIGN.md
CHANGED
|
@@ -530,7 +530,8 @@ What both adopters still wrote after 0.2 moves into Porthole (ADOPTING.md is the
|
|
|
530
530
|
served, content source, frame sources, health) and `POST`/`DELETE handoff`.
|
|
531
531
|
`contentHostFor(build)` gives one host per Workers `env`, failing closed with a plain 503;
|
|
532
532
|
`nodeServer({ content, app })` is the whole Node server (`content` may be a function giving the
|
|
533
|
-
host once made, P074
|
|
533
|
+
host once made, P074; asked right after the `listen` callbacks and at each request until it
|
|
534
|
+
gives one, and `start` is idempotent, P076). A missing or short secret throws, naming `PORTHOLE_SECRET`.
|
|
534
535
|
- **The client:** `portholeClient({ displays, base, headers, credentials, handoff })` is the
|
|
535
536
|
locator and knows each kind's config from the meta (null until known), links, `openInTab`
|
|
536
537
|
(a tab opened in the click, then sent to the address), the handoff, and `entryTarget` (the
|
|
@@ -539,7 +540,8 @@ What both adopters still wrote after 0.2 moves into Porthole (ADOPTING.md is the
|
|
|
539
540
|
`denied`, `expired`, `failed`, `timeout`). React: `PortholeView` (a display by kind, served or
|
|
540
541
|
opaque, with its fallback), `usePortholeLink`, and the provider's shared `scheme`, `theme`
|
|
541
542
|
(`cssVariableTheme`), `nonce: "auto"`, `handlers`, `openLink`, `notify` and `renderConfirm`
|
|
542
|
-
(`accept`, `decline`, and `redirect`: `"redirected"`, which doesn't count toward muting, P074
|
|
543
|
+
(`accept`, `decline`, and `redirect`: `"redirected"`, which doesn't count toward muting, P074;
|
|
544
|
+
the request's `display` carries the served frame's `instance`, P076).
|
|
543
545
|
A flip of the provider's scheme or a new themeKey re-themes running frames in place: no effect
|
|
544
546
|
that makes a display depends on the context value those renew (#9, P074).
|
|
545
547
|
- **The viewer handoff** for a page that holds a token: `POST /porthole/handoff` with the app's
|
|
@@ -566,7 +568,8 @@ What both adopters still wrote after 0.2 moves into Porthole (ADOPTING.md is the
|
|
|
566
568
|
document taken as its body) and returns the warnings as a note.
|
|
567
569
|
- **`checkPage({ config, content, driver })`** (`/check`): the content in the real sandbox at each
|
|
568
570
|
width and scheme (defaults: the manual's phone and desktop widths, light and dark unless
|
|
569
|
-
unthemed). The check page (`src/check/page.ts`, bundled and shipped as `/check/page
|
|
571
|
+
unthemed). The check page (`src/check/page.ts`, bundled and shipped as `/check/page`, a module
|
|
572
|
+
`checkPage` imports, so a bundle carries it, P075) is served
|
|
570
573
|
by the driver at a fixed origin (`https://porthole-check.invalid`), mounts the content with a
|
|
571
574
|
small instrument first in it, and hears errors, rejections, CSP blocks, failed loads, the
|
|
572
575
|
console and the document's width by `postMessage`; heights come from the display's resize
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botiverse/porthole",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "A host-side sandbox for agent-made HTML: isolation, egress hardening, a themed shell, gated host functions, and the agent manual, from one config.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"bin": {
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"miniflare": "4.20260730.0",
|
|
67
67
|
"react": "19.3.0",
|
|
68
68
|
"react-dom": "19.3.0",
|
|
69
|
+
"rolldown": "1.2.11",
|
|
69
70
|
"typescript": "7.0.2"
|
|
70
71
|
},
|
|
71
72
|
"peerDependencies": {
|
|
@@ -80,7 +81,8 @@
|
|
|
80
81
|
"node": ">=24"
|
|
81
82
|
},
|
|
82
83
|
"scripts": {
|
|
83
|
-
"build": "tsc -p tsconfig.build.json && node scripts/build-harness.ts && node scripts/copy-docs.ts",
|
|
84
|
-
"test:leak": "playwright test -c leak/playwright.config.ts"
|
|
84
|
+
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json && node scripts/build-harness.ts && node scripts/copy-docs.ts",
|
|
85
|
+
"test:leak": "playwright test -c leak/playwright.config.ts",
|
|
86
|
+
"test:bundle": "node scripts/bundle-test.ts"
|
|
85
87
|
}
|
|
86
88
|
}
|
package/src/bridge/bridge.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
CapabilityHandlers,
|
|
16
16
|
Confirm,
|
|
17
17
|
ConfirmAnswer,
|
|
18
|
+
ConfirmDisplay,
|
|
18
19
|
ConfirmRequest,
|
|
19
20
|
HostFunctionBridge,
|
|
20
21
|
Refusal,
|
|
@@ -35,7 +36,7 @@ export type BridgeEvent =
|
|
|
35
36
|
|
|
36
37
|
export interface BridgeOptions {
|
|
37
38
|
readonly config: PortholeConfig;
|
|
38
|
-
readonly display:
|
|
39
|
+
readonly display: ConfirmDisplay;
|
|
39
40
|
readonly handlers: CapabilityHandlers;
|
|
40
41
|
readonly confirm?: Confirm;
|
|
41
42
|
/** Whether the embedding page has user activation now; undefined where it can't tell. */
|
package/src/bridge/types.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
CapabilityResults,
|
|
5
5
|
HandledCapability,
|
|
6
6
|
} from "../config/capabilities.ts";
|
|
7
|
+
import type { InstanceRef } from "../isolation/types.ts";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* The host-function bridge (ARCHITECTURE § Framework layer): carries a capability call from the
|
|
@@ -28,12 +29,22 @@ export type CapabilityHandler<N extends CapabilityName> = (
|
|
|
28
29
|
/** The host's handlers: one for each declared capability served by a handler. */
|
|
29
30
|
export type CapabilityHandlers = { readonly [N in HandledCapability]?: CapabilityHandler<N> };
|
|
30
31
|
|
|
32
|
+
/**
|
|
33
|
+
* The display a confirmation is for, as the host named it: its id and title, and the instance it
|
|
34
|
+
* shows where it is served (P076), so a host can word its dialog from its own records.
|
|
35
|
+
*/
|
|
36
|
+
export interface ConfirmDisplay {
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly title: string;
|
|
39
|
+
readonly instance?: InstanceRef;
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
/** What a person is asked to confirm: the call's whole effect, not a summary the content chose. */
|
|
32
43
|
export type ConfirmRequest = {
|
|
33
44
|
[N in CapabilityName]: {
|
|
34
45
|
readonly capability: N;
|
|
35
46
|
readonly args: CapabilityArgs[N];
|
|
36
|
-
readonly display:
|
|
47
|
+
readonly display: ConfirmDisplay;
|
|
37
48
|
};
|
|
38
49
|
}[CapabilityName];
|
|
39
50
|
|
package/src/check/check.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { presets } from "../presets/presets.ts";
|
|
|
4
4
|
import { createServer } from "../server/server.ts";
|
|
5
5
|
import { CHECK_CONTENT_DOMAIN, CHECK_ORIGIN } from "./drivers.ts";
|
|
6
6
|
import { lintContent, type Finding } from "./lint.ts";
|
|
7
|
+
// The check page's script, imported as a module so a bundler takes it in (P075): no file is
|
|
8
|
+
// looked up beside this one at run time.
|
|
9
|
+
import PAGE_SCRIPT from "./page-source.ts";
|
|
7
10
|
import {
|
|
8
11
|
instrumented,
|
|
9
12
|
namedScripts,
|
|
@@ -70,8 +73,8 @@ export interface CheckOptions {
|
|
|
70
73
|
/** The most distinct problems `text` names (default 8): the rest are counted. */
|
|
71
74
|
readonly maxProblems?: number;
|
|
72
75
|
/**
|
|
73
|
-
* The check page's script
|
|
74
|
-
*
|
|
76
|
+
* The check page's script. Default: Porthole's own (`@botiverse/porthole/check/page`), imported
|
|
77
|
+
* with this module, so a bundle (a Worker, a single executable) has it too (P075).
|
|
75
78
|
*/
|
|
76
79
|
readonly page?: string;
|
|
77
80
|
}
|
|
@@ -125,20 +128,6 @@ function checkedAs(config: PortholeConfig): PortholeConfig {
|
|
|
125
128
|
: opaque;
|
|
126
129
|
}
|
|
127
130
|
|
|
128
|
-
/** The check page's script: given, or (Node) the package's own. */
|
|
129
|
-
async function pageScript(given: string | undefined): Promise<string> {
|
|
130
|
-
if (given !== undefined) {
|
|
131
|
-
return given;
|
|
132
|
-
}
|
|
133
|
-
// Not a literal: a bundler for a Worker leaves it alone (a Worker passes `page`).
|
|
134
|
-
const where = new URL(
|
|
135
|
-
import.meta.url.endsWith(".ts") ? "./page-source.ts" : "./page-source.js",
|
|
136
|
-
import.meta.url,
|
|
137
|
-
).href;
|
|
138
|
-
const loaded = (await import(where)) as { default: string };
|
|
139
|
-
return loaded.default;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
131
|
const escapeScript = (code: string) => code.replace(/<\/script/giu, "<\\/script");
|
|
143
132
|
|
|
144
133
|
export async function checkPage(options: CheckOptions): Promise<CheckReport> {
|
|
@@ -157,7 +146,7 @@ export async function checkPage(options: CheckOptions): Promise<CheckReport> {
|
|
|
157
146
|
const schemes = options.schemes ?? (unthemed ? ["light"] : ["light", "dark"]);
|
|
158
147
|
const settle = options.settleMs ?? 1_500;
|
|
159
148
|
const fills = config.layout.kind === "fill";
|
|
160
|
-
const script =
|
|
149
|
+
const script = options.page ?? PAGE_SCRIPT;
|
|
161
150
|
const html = `<!doctype html><html><head><meta charset="utf-8"><title>Porthole check</title><style>body{margin:0;padding:8px}section{margin-bottom:16px}</style></head><body><script>${escapeScript(script)}</script></body></html>`;
|
|
162
151
|
// Its inline scripts named, so an error says the line in the content as written (P074).
|
|
163
152
|
const { content, scriptLines } = namedScripts(options.content);
|
package/src/check/page-source.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The check page's script as a module (`@botiverse/porthole/check/page`)
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* The check page's script as a module (`@botiverse/porthole/check/page`), which `checkPage`
|
|
3
|
+
* imports: from the sources, bundled now (Node, esbuild, Porthole's own development dependency);
|
|
4
|
+
* the package ships it built (`dist/check/page-source.js`, a string and nothing else), so a
|
|
5
|
+
* bundler takes it in like any module (P075).
|
|
5
6
|
*/
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
7
8
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The conformance harness as one browser script, as a module `defineHostConformance` imports: from
|
|
3
|
+
* the sources, bundled now (Node, esbuild, Porthole's own development dependency); the package
|
|
4
|
+
* ships it built (`dist/conformance/harness-source.js`, a string and nothing else), so a bundler
|
|
5
|
+
* takes it in like any module and nothing is looked up beside it at run time (P075).
|
|
6
|
+
*/
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const { build } = await import("esbuild");
|
|
10
|
+
const result = await build({
|
|
11
|
+
entryPoints: [fileURLToPath(new URL("./harness/page.ts", import.meta.url))],
|
|
12
|
+
bundle: true,
|
|
13
|
+
format: "iife",
|
|
14
|
+
platform: "browser",
|
|
15
|
+
target: "es2022",
|
|
16
|
+
write: false,
|
|
17
|
+
logLevel: "silent",
|
|
18
|
+
});
|
|
19
|
+
const source: string = result.outputFiles[0]?.text ?? "";
|
|
20
|
+
if (source === "") {
|
|
21
|
+
throw new Error("the conformance harness didn't build");
|
|
22
|
+
}
|
|
23
|
+
export default source;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
1
|
import { fileURLToPath } from "node:url";
|
|
3
2
|
import { runInThisContext } from "node:vm";
|
|
4
3
|
import { expect, type Frame, type Page, type TestInfo, type TestType } from "@playwright/test";
|
|
@@ -6,6 +5,7 @@ import type { PortholeConfig } from "../config/schema.ts";
|
|
|
6
5
|
import type { Displays } from "../displays/displays.ts";
|
|
7
6
|
import type { FrameLocation, InstanceRef } from "../isolation/types.ts";
|
|
8
7
|
import { entryTests, type EntryConformanceHost } from "./entry.ts";
|
|
8
|
+
import HARNESS from "./harness-source.ts";
|
|
9
9
|
export { conformancePage } from "./page.ts";
|
|
10
10
|
import type { ConformanceHarness } from "./harness/page.ts";
|
|
11
11
|
import type { FrameOutcome } from "../host/types.ts";
|
|
@@ -103,35 +103,12 @@ const FOREIGN = "http://porthole-foreign.example";
|
|
|
103
103
|
/** Where the harness loads from, on the app's own origin (routed by the test, never the app's). */
|
|
104
104
|
const HARNESS_PATH = "/__porthole/conformance/harness.js";
|
|
105
105
|
|
|
106
|
-
let built: Promise<string> | null = null;
|
|
107
|
-
|
|
108
106
|
/**
|
|
109
|
-
* The harness as one script
|
|
110
|
-
*
|
|
107
|
+
* The harness as one script, imported with this module (`harness-source`), so a bundle has it too
|
|
108
|
+
* (P075).
|
|
111
109
|
*/
|
|
112
110
|
export function harnessScript(): Promise<string> {
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
return await readFile(new URL("./harness.js", import.meta.url), "utf8");
|
|
116
|
-
} catch {
|
|
117
|
-
const { build } = await import("esbuild");
|
|
118
|
-
const result = await build({
|
|
119
|
-
entryPoints: [fileURLToPath(new URL("./harness/page.ts", import.meta.url))],
|
|
120
|
-
bundle: true,
|
|
121
|
-
format: "iife",
|
|
122
|
-
platform: "browser",
|
|
123
|
-
target: "es2022",
|
|
124
|
-
write: false,
|
|
125
|
-
logLevel: "silent",
|
|
126
|
-
});
|
|
127
|
-
const text = result.outputFiles[0]?.text;
|
|
128
|
-
if (text === undefined) {
|
|
129
|
-
throw new Error("the conformance harness didn't build");
|
|
130
|
-
}
|
|
131
|
-
return text;
|
|
132
|
-
}
|
|
133
|
-
})();
|
|
134
|
-
return built;
|
|
111
|
+
return Promise.resolve(HARNESS);
|
|
135
112
|
}
|
|
136
113
|
|
|
137
114
|
type Harness = Record<string, ((...args: unknown[]) => unknown) | undefined>;
|
package/src/host/create-host.ts
CHANGED
|
@@ -353,7 +353,11 @@ export function createHost<C extends AdapterConnection = ShellConnection>(
|
|
|
353
353
|
}
|
|
354
354
|
const bridge = createBridge({
|
|
355
355
|
config,
|
|
356
|
-
display: {
|
|
356
|
+
display: {
|
|
357
|
+
id: mount.displayId,
|
|
358
|
+
title: mount.title,
|
|
359
|
+
...(mount.instance === undefined ? {} : { instance: mount.instance }),
|
|
360
|
+
},
|
|
357
361
|
handlers,
|
|
358
362
|
...(options.confirm === undefined ? {} : { confirm: options.confirm }),
|
|
359
363
|
userActivation: () => created.userActivation(),
|
package/src/index.ts
CHANGED
package/src/node/index.ts
CHANGED
|
@@ -295,7 +295,10 @@ export interface NodeServerOptions {
|
|
|
295
295
|
/**
|
|
296
296
|
* The content host, or a function giving it when it exists: a host made after the server listens
|
|
297
297
|
* (its content domain names the port `listen(0)` chose, P074). Until it gives one, every request
|
|
298
|
-
* is the app's
|
|
298
|
+
* is the app's. `nodeServer` starts the host's health gate when it listens, asking the function
|
|
299
|
+
* once the server's `listen` callbacks have run (a host made in one starts then), and again at
|
|
300
|
+
* each request until it gives one; `start` is idempotent, so an app may start the host itself
|
|
301
|
+
* as soon as it makes it (P076).
|
|
299
302
|
*/
|
|
300
303
|
readonly content: ContentHost<unknown> | (() => ContentHost<unknown> | null);
|
|
301
304
|
/**
|
|
@@ -384,9 +387,11 @@ export function nodeServer(options: NodeServerOptions): Server {
|
|
|
384
387
|
});
|
|
385
388
|
server.on("listening", () => {
|
|
386
389
|
listening = true;
|
|
387
|
-
|
|
390
|
+
// After the listen callbacks: a host made in one (with the port it got) starts now.
|
|
391
|
+
setImmediate(current);
|
|
388
392
|
});
|
|
389
393
|
server.on("close", () => {
|
|
394
|
+
listening = false;
|
|
390
395
|
const host = typeof given === "function" ? given() : given;
|
|
391
396
|
host?.close();
|
|
392
397
|
});
|
package/src/react/frame.tsx
CHANGED
|
@@ -715,7 +715,14 @@ function Mount({ frame, page, initialHeightPx, placeholder, run }: MountProps):
|
|
|
715
715
|
? {
|
|
716
716
|
confirm: (request: ConfirmRequest, proceed: Proceed) =>
|
|
717
717
|
(latest().confirm ?? pageConfirm ?? (() => Promise.resolve(false)))(
|
|
718
|
-
{
|
|
718
|
+
{
|
|
719
|
+
...request,
|
|
720
|
+
display: {
|
|
721
|
+
...request.display,
|
|
722
|
+
id: latest().displayId,
|
|
723
|
+
title: latest().title,
|
|
724
|
+
},
|
|
725
|
+
},
|
|
719
726
|
proceed,
|
|
720
727
|
),
|
|
721
728
|
}
|
package/src/server/host.ts
CHANGED
|
@@ -311,7 +311,10 @@ export interface ContentHost<V> {
|
|
|
311
311
|
): (request: Request) => Promise<Response>;
|
|
312
312
|
/** A url-mode app's access for a WebSocket upgrade (`server.access`), or null. */
|
|
313
313
|
access(request: Request): Promise<Access | null>;
|
|
314
|
-
/**
|
|
314
|
+
/**
|
|
315
|
+
* Starts the health gate (after the app listens). Once: starting a started host does nothing,
|
|
316
|
+
* so the app and `nodeServer` may both start it (P076). After `close`, it starts again.
|
|
317
|
+
*/
|
|
315
318
|
start(): void;
|
|
316
319
|
/** Runs one health check now. */
|
|
317
320
|
check(): Promise<ContentHealthView>;
|
|
@@ -533,6 +536,7 @@ export function createContentHost<V>(options: ContentHostOptions<V>): ContentHos
|
|
|
533
536
|
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
534
537
|
let running: Promise<ContentHealthView> | null = null;
|
|
535
538
|
let closed = false;
|
|
539
|
+
let started = false;
|
|
536
540
|
const schedule = () => {
|
|
537
541
|
if (closed || gate === undefined || view.misconfigured === true || domain === null) {
|
|
538
542
|
return;
|
|
@@ -1114,12 +1118,17 @@ export function createContentHost<V>(options: ContentHostOptions<V>): ContentHos
|
|
|
1114
1118
|
access: async (request) => (server === null ? null : server.access(request)),
|
|
1115
1119
|
|
|
1116
1120
|
start() {
|
|
1121
|
+
if (started) {
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
started = true;
|
|
1117
1125
|
closed = false;
|
|
1118
1126
|
void check();
|
|
1119
1127
|
},
|
|
1120
1128
|
check,
|
|
1121
1129
|
close() {
|
|
1122
1130
|
closed = true;
|
|
1131
|
+
started = false;
|
|
1123
1132
|
if (timer !== null) {
|
|
1124
1133
|
clearTimeout(timer);
|
|
1125
1134
|
timer = null;
|