@botiverse/porthole 0.3.1 → 0.3.2

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/docs/DESIGN.md CHANGED
@@ -566,7 +566,8 @@ What both adopters still wrote after 0.2 moves into Porthole (ADOPTING.md is the
566
566
  document taken as its body) and returns the warnings as a note.
567
567
  - **`checkPage({ config, content, driver })`** (`/check`): the content in the real sandbox at each
568
568
  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`) is served
569
+ unthemed). The check page (`src/check/page.ts`, bundled and shipped as `/check/page`, a module
570
+ `checkPage` imports, so a bundle carries it, P075) is served
570
571
  by the driver at a fixed origin (`https://porthole-check.invalid`), mounts the content with a
571
572
  small instrument first in it, and hears errors, rejections, CSP blocks, failed loads, the
572
573
  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.1",
3
+ "version": "0.3.2",
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
  }
@@ -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 (`import page from "@botiverse/porthole/check/page"`). Node finds it
74
- * itself; a bundled runtime (a Worker) passes it.
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 = await pageScript(options.page);
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);
@@ -1,7 +1,8 @@
1
1
  /**
2
- * The check page's script as a module (`@botiverse/porthole/check/page`): from the sources, bundled
3
- * now (Node, esbuild); the package ships it built (`dist/check/page-source.js`), for a Worker to
4
- * import and pass to `checkPage` as `page`.
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: from the package (`dist/conformance/harness.js`), or, run from the
110
- * sources, bundled now (esbuild, a development dependency of Porthole's).
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
- built ??= (async () => {
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>;