From b3d691de04f15b67df97a93e4892a9afe3721a85 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?=
<16311043+immakermatty@users.noreply.github.com>
Date: Thu, 5 Nov 2026 23:55:14 +0000
Subject: [PATCH] fix(web): keep a view's tab id in upper case, as F50 and the
server do
LazurioPlatform F50 point 2 (`targetIdOf` in `src/browser/contract/pure.ts`)
takes a tab id in either case and keeps it in upper case, and the server's
`exactView` announces it so. The web's `environmentBrowserTab` kept the id
as written, so `https://browser..lazurio.io/t/` was a
panel surface of its own, apart from the one the server announces for the
same remote tab. It now upper-cases the id and builds the view from it.
F50 point 2's table of view addresses, which ran on the server's host
only, moves to `viewAddressCases.ts`, which apps/server and apps/web hold
as the same file. The web's tests run every row through
`environmentBrowserLink` and `foreignEnvironmentBrowserTab`, and the
release contract test keeps the two copies equal. Against the old web
parser seven tests fail: the four lower- and mixed-case rows and the tab,
link and new-tab expectations.
`AgentContextBudget.test.ts` fails on main as it does here (#167).
Co-Authored-By: Claude Opus 5.5
---
.../src/lazurio/environmentBrowser.test.ts | 154 +----------------
apps/server/src/lazurio/viewAddressCases.ts | 161 ++++++++++++++++++
...LazurioEnvironmentBrowser.browser.test.tsx | 4 +-
.../src/lazurio/environmentBrowser.test.ts | 43 ++++-
apps/web/src/lazurio/environmentBrowser.ts | 12 +-
.../src/lazurio/threadTabs.browser.test.ts | 10 +-
apps/web/src/lazurio/viewAddressCases.ts | 161 ++++++++++++++++++
scripts/lazurio-release-contract.test.mjs | 5 +
8 files changed, 377 insertions(+), 173 deletions(-)
create mode 100644 apps/server/src/lazurio/viewAddressCases.ts
create mode 100644 apps/web/src/lazurio/viewAddressCases.ts
diff --git a/apps/server/src/lazurio/environmentBrowser.test.ts b/apps/server/src/lazurio/environmentBrowser.test.ts
index 4e157f64f28a2..7280940ea742e 100644
--- a/apps/server/src/lazurio/environmentBrowser.test.ts
+++ b/apps/server/src/lazurio/environmentBrowser.test.ts
@@ -35,6 +35,7 @@ import * as ProcessRunner from "../processRunner.ts";
import { agentBrowserSessionName } from "./agentBrowserSession.ts";
import * as EnvironmentBrowser from "./environmentBrowser.ts";
import * as ThreadTabs from "./threadTabs.ts";
+import { contractCases, foreignId, foreignView, ownHost, personTab } from "./viewAddressCases.ts";
import type {
EnvironmentBrowserConnection,
EnvironmentBrowserTab,
@@ -48,7 +49,6 @@ const home = "/home/environment";
const lazurio = `${home}/.local/bin/lazurio`;
// DevTools target ids: 32 hex digits.
const threadWindow = "A1A1A1A1A1A1A1A1A1A1A1A1A1A1A1A1";
-const personTab = "B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2";
const scopeOf = (
thread: ThreadId,
@@ -726,8 +726,6 @@ it.effect("adopts a tab handed over by its id, and refuses an id that names no t
// Another Environment's people's view of one of its tabs: an agent here works over SSH in that
// Environment, whose browser this host cannot drive.
-const foreignId = "0123456789ABCDEF0123456789ABCDEF";
-const foreignView = `https://browser.vm-02.acme.lazurio.io/t/${foreignId}`;
it.effect("answers preview_open of another Environment's view without this browser", () =>
Effect.scoped(
@@ -965,156 +963,6 @@ it.effect("takes a view's tab id in either case and hands on its upper-case form
),
);
-// LazurioPlatform F50 point 2 (`viewAddressOf`, `isViewHost`), case by case: a view address is
-// taken only as written, its own bare origin a new tab, `/t/` its tab or another Environment's.
-// Any other address on a view host is refused, as written or as `normalizePreviewUrl` makes it,
-// before this browser loads it; an address on any other host loads.
-const ownHost = "browser.vm-01.acme.lazurio.io";
-const foreignHost = "browser.vm-02.acme.lazurio.io";
-type Takes =
- | "new tab"
- | "own tab"
- | { readonly foreign: string }
- | { readonly refused: string }
- /** `normalizePreviewUrl` reads no URL in it, so nothing is opened or loaded. */
- | "invalid"
- /** What this browser loads. */
- | { readonly loads: string };
-
-/** Each address on the view host `host` that F50 point 2 does not take, around the tab `id`. */
-const offContract = (host: string, id: string): ReadonlyArray => [
- // The host as written: its trailing dot, upper case, or a scheme in upper case.
- `https://${host}./t/${id}`,
- `https://${host}../t/${id}`,
- `https://${host}%2e/t/${id}`,
- `https://${host}\u3002/t/${id}`,
- `https://${host.toUpperCase()}/t/${id}`,
- `https://${host.replace("browser", "BROWSER")}/t/${id}`,
- `HTTPS://${host}/t/${id}`,
- // A port, even the default one, or another scheme.
- `https://${host}:443/t/${id}`,
- `https://${host}:8443/t/${id}`,
- `https://${host}:/t/${id}`,
- `http://${host}/t/${id}`,
- // What only `new URL` or `normalizePreviewUrl` makes a view address of.
- `https:/${host}/t/${id}`,
- `//${host}/t/${id}`,
- `${host}/t/${id}`,
- ` https://${host}/t/${id} `,
- `https://${host}/t/${id}\n`,
- `https://${host}\\t\\${id}`,
- `https:\\\\${host}\\t\\${id}`,
- `ht\ttps://${host}/t/${id}`,
- `\u00a0https://${host}/t/${id}`,
- // Another path.
- `https://${host}/x/../t/${id}`,
- `https://${host}/t/./${id}`,
- `https://${host}//t/${id}`,
- `https://${host}/t/${id}/`,
- `https://${host}/t/${id}/live`,
- `https://${host}/t/`,
- `https://${host}/t`,
- `https://${host}/x`,
- `https://${host}/T/${id}`,
- `https://${host}/%74/${id}`,
- // A query, a fragment or credentials, even empty ones.
- `https://${host}/t/${id}?source=agent`,
- `https://${host}/t/${id}?`,
- `https://${host}/t/${id}#view`,
- `https://${host}/t/${id}#`,
- `https://user@${host}/t/${id}`,
- `https://user:pw@${host}/t/${id}`,
- `https://@${host}/t/${id}`,
- // No target id: 31 or 33 digits, not hexadecimal, or percent-encoded.
- `https://${host}/t/${id.slice(1)}`,
- `https://${host}/t/${id}0`,
- `https://${host}/t/${"G".repeat(32)}`,
- `https://${host}/t/%41${id.slice(1)}`,
- // The bare origin in any form but the two.
- `https://${host}/?`,
- `https://${host}/?source=agent`,
- `https://${host}#`,
- `https://${host}/#`,
- `https://${host}:443`,
- `https://${host}:443/`,
- `https://${host}:/`,
- `https://:@${host}/`,
- `\ufeffhttps://${host}/`,
- `https://${host}./`,
- `https://${host}/./`,
- `https://${host}//`,
- `https://${host.toUpperCase()}/`,
- `https://${host.replace("browser", "BROWSER")}/`,
- ` https://${host}/`,
- host,
-];
-const mixedCase = (id: string) =>
- [...id].map((digit, index) => (index % 2 === 0 ? digit.toLowerCase() : digit)).join("");
-const personalHost = "browser.example-person.lazurio.io";
-const personalView = `https://${personalHost}/t/${foreignId}`;
-const longLabel = "a".repeat(63);
-const contractCases: ReadonlyArray<{ readonly address: string; readonly takes: Takes }> = [
- { address: `https://${ownHost}`, takes: "new tab" },
- { address: `https://${ownHost}/`, takes: "new tab" },
- { address: `https://${ownHost}/t/${personTab}`, takes: "own tab" },
- { address: `https://${ownHost}/t/${personTab.toLowerCase()}`, takes: "own tab" },
- { address: `https://${ownHost}/t/${mixedCase(personTab)}`, takes: "own tab" },
- { address: foreignView, takes: { foreign: foreignView } },
- {
- address: `https://${foreignHost}/t/${foreignId.toLowerCase()}`,
- takes: { foreign: foreignView },
- },
- { address: `https://${foreignHost}/t/${mixedCase(foreignId)}`, takes: { foreign: foreignView } },
- { address: personalView, takes: { foreign: personalView } },
- {
- address: `https://browser.${longLabel}.a-1.lazurio.io/t/${foreignId}`,
- takes: { foreign: `https://browser.${longLabel}.a-1.lazurio.io/t/${foreignId}` },
- },
- ...offContract(ownHost, personTab).map((address) => ({ address, takes: { refused: ownHost } })),
- ...offContract(foreignHost, foreignId).map((address) => ({
- address,
- takes: { refused: foreignHost },
- })),
- ...offContract(personalHost, foreignId).map((address) => ({
- address,
- takes: { refused: personalHost },
- })),
- // Another Environment's bare origin is a new tab of its browser, which this host does not open.
- { address: `https://${foreignHost}`, takes: { refused: foreignHost } },
- { address: `https://${foreignHost}/`, takes: { refused: foreignHost } },
- // A base that is no Environment id: three labels, none, or a label that is no DNS label.
- ...[
- "browser.a.vm-02.acme.lazurio.io",
- "browser.lazurio.io",
- "browser.-vm-02.acme.lazurio.io",
- "browser.vm-02-.acme.lazurio.io",
- `browser.${"a".repeat(64)}.acme.lazurio.io`,
- "browser.vm_02.acme.lazurio.io",
- ].map((host) => ({ address: `https://${host}/t/${foreignId}`, takes: { refused: host } })),
- // A label is written as the host is: an internationalized name only in its ASCII form.
- {
- address: `https://browser.vm-02.xn--cme-dla.lazurio.io/t/${foreignId}`,
- takes: { foreign: `https://browser.vm-02.xn--cme-dla.lazurio.io/t/${foreignId}` },
- },
- {
- address: `https://browser.vm-02.ácme.lazurio.io/t/${foreignId}`,
- takes: { refused: "browser.vm-02.xn--cme-dla.lazurio.io" },
- },
- { address: `https:${ownHost}/t/${personTab}`, takes: "invalid" },
- ...[`wss://${ownHost}/t/${personTab}`, `view-source:https://${ownHost}/t/${personTab}`].map(
- (address) => ({ address, takes: "invalid" as const }),
- ),
- // Any other host loads, a Lazurio app or a look-alike of a view host.
- ...[
- "https://xbrowser.vm-01.acme.lazurio.io/",
- `https://t3code.vm-01.acme.lazurio.io/t/${personTab}`,
- `https://browser.vm-01.acme.lazurio.io.example.test/t/${personTab}`,
- "https://browser.example.test/",
- `https://${ownHost}@example.test/`,
- ].map((address) => ({ address, takes: { loads: address } })),
- { address: "example.test/t/x", takes: { loads: "https://example.test/t/x" } },
-];
-
it.effect.each(contractCases)("takes $address as F50 point 2 does", ({ address, takes }) =>
Effect.scoped(
Effect.gen(function* () {
diff --git a/apps/server/src/lazurio/viewAddressCases.ts b/apps/server/src/lazurio/viewAddressCases.ts
new file mode 100644
index 0000000000000..1410cddadfbea
--- /dev/null
+++ b/apps/server/src/lazurio/viewAddressCases.ts
@@ -0,0 +1,161 @@
+/**
+ * Lazurio overlay: LazurioPlatform F50 point 2 (`viewAddressOf`, `isViewHost`) as a table of
+ * addresses and what each is, for the tests of the server's Environment browser host and of the
+ * web's panel. apps/server and apps/web hold this same file; the release contract test keeps it so.
+ */
+
+/** A remote tab of this Environment's browser, written as Chromium writes it. */
+export const personTab = "B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2";
+/** A remote tab of another Environment's browser. */
+export const foreignId = "0123456789ABCDEF0123456789ABCDEF";
+export const foreignView = `https://browser.vm-02.acme.lazurio.io/t/${foreignId}`;
+
+// LazurioPlatform F50 point 2 (`viewAddressOf`, `isViewHost`), case by case: a view address is
+// taken only as written, its own bare origin a new tab, `/t/` its tab or another Environment's.
+// Any other address on a view host is refused, as written or as `normalizePreviewUrl` makes it,
+// before this browser loads it; an address on any other host loads.
+export const ownHost = "browser.vm-01.acme.lazurio.io";
+const foreignHost = "browser.vm-02.acme.lazurio.io";
+export type Takes =
+ | "new tab"
+ | "own tab"
+ | { readonly foreign: string }
+ | { readonly refused: string }
+ /** `normalizePreviewUrl` reads no URL in it, so nothing is opened or loaded. */
+ | "invalid"
+ /** What this browser loads. */
+ | { readonly loads: string };
+
+/** Each address on the view host `host` that F50 point 2 does not take, around the tab `id`. */
+const offContract = (host: string, id: string): ReadonlyArray => [
+ // The host as written: its trailing dot, upper case, or a scheme in upper case.
+ `https://${host}./t/${id}`,
+ `https://${host}../t/${id}`,
+ `https://${host}%2e/t/${id}`,
+ `https://${host}\u3002/t/${id}`,
+ `https://${host.toUpperCase()}/t/${id}`,
+ `https://${host.replace("browser", "BROWSER")}/t/${id}`,
+ `HTTPS://${host}/t/${id}`,
+ // A port, even the default one, or another scheme.
+ `https://${host}:443/t/${id}`,
+ `https://${host}:8443/t/${id}`,
+ `https://${host}:/t/${id}`,
+ `http://${host}/t/${id}`,
+ // What only `new URL` or `normalizePreviewUrl` makes a view address of.
+ `https:/${host}/t/${id}`,
+ `//${host}/t/${id}`,
+ `${host}/t/${id}`,
+ ` https://${host}/t/${id} `,
+ `https://${host}/t/${id}\n`,
+ `https://${host}\\t\\${id}`,
+ `https:\\\\${host}\\t\\${id}`,
+ `ht\ttps://${host}/t/${id}`,
+ `\u00a0https://${host}/t/${id}`,
+ // Another path.
+ `https://${host}/x/../t/${id}`,
+ `https://${host}/t/./${id}`,
+ `https://${host}//t/${id}`,
+ `https://${host}/t/${id}/`,
+ `https://${host}/t/${id}/live`,
+ `https://${host}/t/`,
+ `https://${host}/t`,
+ `https://${host}/x`,
+ `https://${host}/T/${id}`,
+ `https://${host}/%74/${id}`,
+ // A query, a fragment or credentials, even empty ones.
+ `https://${host}/t/${id}?source=agent`,
+ `https://${host}/t/${id}?`,
+ `https://${host}/t/${id}#view`,
+ `https://${host}/t/${id}#`,
+ `https://user@${host}/t/${id}`,
+ `https://user:pw@${host}/t/${id}`,
+ `https://@${host}/t/${id}`,
+ // No target id: 31 or 33 digits, not hexadecimal, or percent-encoded.
+ `https://${host}/t/${id.slice(1)}`,
+ `https://${host}/t/${id}0`,
+ `https://${host}/t/${"G".repeat(32)}`,
+ `https://${host}/t/%41${id.slice(1)}`,
+ // The bare origin in any form but the two.
+ `https://${host}/?`,
+ `https://${host}/?source=agent`,
+ `https://${host}#`,
+ `https://${host}/#`,
+ `https://${host}:443`,
+ `https://${host}:443/`,
+ `https://${host}:/`,
+ `https://:@${host}/`,
+ `\ufeffhttps://${host}/`,
+ `https://${host}./`,
+ `https://${host}/./`,
+ `https://${host}//`,
+ `https://${host.toUpperCase()}/`,
+ `https://${host.replace("browser", "BROWSER")}/`,
+ ` https://${host}/`,
+ host,
+];
+const mixedCase = (id: string) =>
+ [...id].map((digit, index) => (index % 2 === 0 ? digit.toLowerCase() : digit)).join("");
+const personalHost = "browser.example-person.lazurio.io";
+const personalView = `https://${personalHost}/t/${foreignId}`;
+const longLabel = "a".repeat(63);
+export const contractCases: ReadonlyArray<{ readonly address: string; readonly takes: Takes }> = [
+ { address: `https://${ownHost}`, takes: "new tab" },
+ { address: `https://${ownHost}/`, takes: "new tab" },
+ { address: `https://${ownHost}/t/${personTab}`, takes: "own tab" },
+ { address: `https://${ownHost}/t/${personTab.toLowerCase()}`, takes: "own tab" },
+ { address: `https://${ownHost}/t/${mixedCase(personTab)}`, takes: "own tab" },
+ { address: foreignView, takes: { foreign: foreignView } },
+ {
+ address: `https://${foreignHost}/t/${foreignId.toLowerCase()}`,
+ takes: { foreign: foreignView },
+ },
+ { address: `https://${foreignHost}/t/${mixedCase(foreignId)}`, takes: { foreign: foreignView } },
+ { address: personalView, takes: { foreign: personalView } },
+ {
+ address: `https://browser.${longLabel}.a-1.lazurio.io/t/${foreignId}`,
+ takes: { foreign: `https://browser.${longLabel}.a-1.lazurio.io/t/${foreignId}` },
+ },
+ ...offContract(ownHost, personTab).map((address) => ({ address, takes: { refused: ownHost } })),
+ ...offContract(foreignHost, foreignId).map((address) => ({
+ address,
+ takes: { refused: foreignHost },
+ })),
+ ...offContract(personalHost, foreignId).map((address) => ({
+ address,
+ takes: { refused: personalHost },
+ })),
+ // Another Environment's bare origin is a new tab of its browser, which this host does not open.
+ { address: `https://${foreignHost}`, takes: { refused: foreignHost } },
+ { address: `https://${foreignHost}/`, takes: { refused: foreignHost } },
+ // A base that is no Environment id: three labels, none, or a label that is no DNS label.
+ ...[
+ "browser.a.vm-02.acme.lazurio.io",
+ "browser.lazurio.io",
+ "browser.-vm-02.acme.lazurio.io",
+ "browser.vm-02-.acme.lazurio.io",
+ `browser.${"a".repeat(64)}.acme.lazurio.io`,
+ "browser.vm_02.acme.lazurio.io",
+ ].map((host) => ({ address: `https://${host}/t/${foreignId}`, takes: { refused: host } })),
+ // A label is written as the host is: an internationalized name only in its ASCII form.
+ {
+ address: `https://browser.vm-02.xn--cme-dla.lazurio.io/t/${foreignId}`,
+ takes: { foreign: `https://browser.vm-02.xn--cme-dla.lazurio.io/t/${foreignId}` },
+ },
+ {
+ address: `https://browser.vm-02.ácme.lazurio.io/t/${foreignId}`,
+ takes: { refused: "browser.vm-02.xn--cme-dla.lazurio.io" },
+ },
+ { address: `https:${ownHost}/t/${personTab}`, takes: "invalid" },
+ ...[`wss://${ownHost}/t/${personTab}`, `view-source:https://${ownHost}/t/${personTab}`].map(
+ (address) => ({ address, takes: "invalid" as const }),
+ ),
+ // Any other host loads, a Lazurio app or a look-alike of a view host.
+ ...[
+ "https://xbrowser.vm-01.acme.lazurio.io/",
+ `https://t3code.vm-01.acme.lazurio.io/t/${personTab}`,
+ `https://browser.vm-01.acme.lazurio.io.example.test/t/${personTab}`,
+ "https://browser.example.test/",
+ `https://${ownHost}@example.test/`,
+ ].map((address) => ({ address, takes: { loads: address } })),
+ { address: "example.test/t/x", takes: { loads: "https://example.test/t/x" } },
+];
diff --git a/apps/web/src/lazurio/LazurioEnvironmentBrowser.browser.test.tsx b/apps/web/src/lazurio/LazurioEnvironmentBrowser.browser.test.tsx
index 075d91bf736b6..b8e3aec6be98c 100644
--- a/apps/web/src/lazurio/LazurioEnvironmentBrowser.browser.test.tsx
+++ b/apps/web/src/lazurio/LazurioEnvironmentBrowser.browser.test.tsx
@@ -64,7 +64,7 @@ const files = { id: "files", kind: "files" } as const;
const threadA = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-A"));
const threadB = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-B"));
// Another Environment's people's view of one of its tabs, where an agent works over SSH.
-const foreignId = "fedcba9876543210".repeat(2);
+const foreignId = "FEDCBA9876543210".repeat(2);
const foreignOrigin = "https://browser.vm-02.acme.lazurio.io";
const foreignView = `${foreignOrigin}/t/${foreignId}`;
const foreignTab = {
@@ -785,7 +785,7 @@ describe("the chat's hook", () => {
using page = setup();
await using _screen = await renderUi(chatOn(threadA));
await page.stream().emit("snapshot", snapshot([]));
- await page.stream().emit("foreign", { tabId: foreignId.toUpperCase(), view: foreignView });
+ await page.stream().emit("foreign", { tabId: foreignId, view: foreignView });
expect(panel()).toMatchObject({ isOpen: false, surfaces: [foreignTab] });
await page
.stream()
diff --git a/apps/web/src/lazurio/environmentBrowser.test.ts b/apps/web/src/lazurio/environmentBrowser.test.ts
index 0b41bfa5ca64c..ae67eb1bd243b 100644
--- a/apps/web/src/lazurio/environmentBrowser.test.ts
+++ b/apps/web/src/lazurio/environmentBrowser.test.ts
@@ -8,6 +8,7 @@ import {
readEnvironmentBrowserMessage,
viewEnvironmentId,
} from "./environmentBrowser";
+import { contractCases, foreignId, foreignView, ownHost, personTab } from "./viewAddressCases";
const origin = "https://t3code.vm-01.example.lazurio.io";
const viewOrigin = "https://browser.vm-01.example.lazurio.io";
@@ -18,10 +19,10 @@ const targetId = "0123456789abcdef".repeat(2);
const tabView = `${viewOrigin}/t/${targetId}`;
describe("a tab of the panel", () => {
- it("is the view of exactly one remote tab, named by its target id", () => {
+ it("is the view of exactly one remote tab, named by its target id in upper case", () => {
expect(environmentBrowserTab(tabView)).toEqual({
- id: `environment-browser:${targetId}`,
- view: tabView,
+ id: `environment-browser:${targetId.toUpperCase()}`,
+ view: `${viewOrigin}/t/${targetId.toUpperCase()}`,
});
expect(environmentBrowserTab(view, origin)).toEqual({
id: "environment-browser:8A3F0C2D4E5B6A7980C1D2E3F4A5B6C7",
@@ -71,8 +72,8 @@ describe("a tab of the panel", () => {
describe("a link in the chat", () => {
it("opens in the panel when it is one remote tab of the view the Environment named", () => {
expect(environmentBrowserLink(tabView, origin, viewOrigin)).toEqual({
- id: `environment-browser:${targetId}`,
- view: tabView,
+ id: `environment-browser:${targetId.toUpperCase()}`,
+ view: `${viewOrigin}/t/${targetId.toUpperCase()}`,
});
});
@@ -119,8 +120,7 @@ describe("a link in the chat", () => {
describe("another Lazurio Environment's tab", () => {
// This page is the T3 of `vm-01.example.lazurio.io`; its own view is `browser.` beside it.
- const foreignId = "fedcba9876543210".repeat(2);
- const organization = `https://browser.vm-02.acme.lazurio.io/t/${foreignId}`;
+ const organization = foreignView;
const personal = `https://browser.example-person.lazurio.io/t/${foreignId}`;
const tabOf = (address: string, named: string | null = viewOrigin) =>
foreignEnvironmentBrowserTab(address, origin, named);
@@ -197,6 +197,30 @@ describe("another Lazurio Environment's tab", () => {
});
});
+// LazurioPlatform F50 point 2's table, which the server's host runs through its tools: the panel
+// opens this Environment's tab or another's only for a view address as written, and keeps the
+// tab's id in upper case, as the server announces it. Any other address is left to the browser.
+describe("F50 point 2's view addresses", () => {
+ const page = "https://t3code.vm-01.acme.lazurio.io";
+ const named = `https://${ownHost}`;
+ it.each(contractCases)("takes $address as F50 point 2 does", ({ address, takes }) => {
+ const own =
+ takes === "own tab"
+ ? { id: `environment-browser:${personTab}`, view: `${named}/t/${personTab}` }
+ : null;
+ const foreign =
+ typeof takes === "object" && "foreign" in takes
+ ? {
+ id: `environment-browser:${takes.foreign.slice(-32)}`,
+ view: takes.foreign,
+ environment: expect.objectContaining({ view: takes.foreign }),
+ }
+ : null;
+ expect(environmentBrowserLink(address, page, named)).toEqual(own);
+ expect(foreignEnvironmentBrowserTab(address, page, named)).toEqual(foreign);
+ });
+});
+
describe("a message of the framed view", () => {
const frame = {};
const newTab = { type: "lazurio-browser:new-tab", view: tabView, url: "https://example.com/" };
@@ -234,7 +258,10 @@ describe("a message of the framed view", () => {
it("opens a page's new tab on the view's own origin", () => {
expect(readEnvironmentBrowserMessage(message(newTab), frame, view)).toEqual({
type: "new-tab",
- tab: { id: `environment-browser:${targetId}`, view: tabView },
+ tab: {
+ id: `environment-browser:${targetId.toUpperCase()}`,
+ view: `${viewOrigin}/t/${targetId.toUpperCase()}`,
+ },
});
// A tab that a page opened tells of its own new tabs as well.
expect(readEnvironmentBrowserMessage(message(newTab), frame, tabView)).toMatchObject({
diff --git a/apps/web/src/lazurio/environmentBrowser.ts b/apps/web/src/lazurio/environmentBrowser.ts
index a5bdde7fd3c27..65427e3efc581 100644
--- a/apps/web/src/lazurio/environmentBrowser.ts
+++ b/apps/web/src/lazurio/environmentBrowser.ts
@@ -20,9 +20,9 @@ const TAB_VIEW_PATH = /^\/t\/([0-9A-Fa-f]{32})$/;
/**
* Null unless exactly `https:///t/<32 hex digits>` as written (LazurioPlatform F50 point 2),
- * with no credentials, query or fragment, so a kept address names one remote tab and carries
- * nothing else. With `pageOrigin`, the page's own origin is refused too: the view is never framed
- * on the page's origin.
+ * with no credentials, query or fragment. The id is kept in upper case, as the server announces it
+ * (F50 `targetIdOf`), so one remote tab is one surface. With `pageOrigin`, the page's own origin
+ * is refused too: the view is never framed on the page's origin.
*/
export function environmentBrowserTab(
view: unknown,
@@ -43,8 +43,10 @@ export function environmentBrowserTab(
return null;
}
if (url.origin === pageOrigin) return null;
- const target = TAB_VIEW_PATH.exec(url.pathname)?.[1];
- return target === undefined ? null : { id: `environment-browser:${target}`, view: url.href };
+ const target = TAB_VIEW_PATH.exec(url.pathname)?.[1]?.toUpperCase();
+ return target === undefined
+ ? null
+ : { id: `environment-browser:${target}`, view: `${url.origin}/t/${target}` };
}
/**
diff --git a/apps/web/src/lazurio/threadTabs.browser.test.ts b/apps/web/src/lazurio/threadTabs.browser.test.ts
index 8b82aa5439295..b9c142b859bf6 100644
--- a/apps/web/src/lazurio/threadTabs.browser.test.ts
+++ b/apps/web/src/lazurio/threadTabs.browser.test.ts
@@ -40,9 +40,9 @@ const viewOrigin = "https://browser.vm-01.example.lazurio.io";
const id = (n: number) => n.toString(16).toUpperCase().padStart(32, "0");
const tab = (n: number) => ({ id: tabSurfaceId(id(n)), kind: "environment-browser" }) as const;
const foreign = {
- id: `environment-browser:${"ab".repeat(16)}`,
+ id: `environment-browser:${"AB".repeat(16)}`,
kind: "environment-browser",
- view: `https://browser.vm-02.acme.lazurio.io/t/${"ab".repeat(16)}`,
+ view: `https://browser.vm-02.acme.lazurio.io/t/${"AB".repeat(16)}`,
} as const;
const files = { id: "files", kind: "files" } as const;
const threadA = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-A"));
@@ -128,7 +128,7 @@ describe("the strip from the server's list", () => {
using _server = setup();
setPanel({ isOpen: true, activeSurfaceId: null, surfaces: [] });
receiveSnapshot(threadA, snapshot([]));
- receiveForeign(threadA, { tabId: "ab".repeat(16), view: foreign.view });
+ receiveForeign(threadA, { tabId: "AB".repeat(16), view: foreign.view });
expect(panel()).toEqual({ isOpen: true, activeSurfaceId: foreign.id, surfaces: [foreign] });
});
@@ -176,10 +176,10 @@ describe("reveals", () => {
surfaces: [tab(1), files],
});
// Another Environment's tab the server reveals again, while the strip still has it.
- receiveForeign(threadA, { tabId: "ab".repeat(16), view: foreign.view });
+ receiveForeign(threadA, { tabId: "AB".repeat(16), view: foreign.view });
expect(panel().activeSurfaceId).toBe(tab(1).id);
receiveForeign(threadA, {
- tabId: "ab".repeat(16),
+ tabId: "AB".repeat(16),
view: foreign.view,
revealRequest: { id: "e:1" },
});
diff --git a/apps/web/src/lazurio/viewAddressCases.ts b/apps/web/src/lazurio/viewAddressCases.ts
new file mode 100644
index 0000000000000..1410cddadfbea
--- /dev/null
+++ b/apps/web/src/lazurio/viewAddressCases.ts
@@ -0,0 +1,161 @@
+/**
+ * Lazurio overlay: LazurioPlatform F50 point 2 (`viewAddressOf`, `isViewHost`) as a table of
+ * addresses and what each is, for the tests of the server's Environment browser host and of the
+ * web's panel. apps/server and apps/web hold this same file; the release contract test keeps it so.
+ */
+
+/** A remote tab of this Environment's browser, written as Chromium writes it. */
+export const personTab = "B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2";
+/** A remote tab of another Environment's browser. */
+export const foreignId = "0123456789ABCDEF0123456789ABCDEF";
+export const foreignView = `https://browser.vm-02.acme.lazurio.io/t/${foreignId}`;
+
+// LazurioPlatform F50 point 2 (`viewAddressOf`, `isViewHost`), case by case: a view address is
+// taken only as written, its own bare origin a new tab, `/t/` its tab or another Environment's.
+// Any other address on a view host is refused, as written or as `normalizePreviewUrl` makes it,
+// before this browser loads it; an address on any other host loads.
+export const ownHost = "browser.vm-01.acme.lazurio.io";
+const foreignHost = "browser.vm-02.acme.lazurio.io";
+export type Takes =
+ | "new tab"
+ | "own tab"
+ | { readonly foreign: string }
+ | { readonly refused: string }
+ /** `normalizePreviewUrl` reads no URL in it, so nothing is opened or loaded. */
+ | "invalid"
+ /** What this browser loads. */
+ | { readonly loads: string };
+
+/** Each address on the view host `host` that F50 point 2 does not take, around the tab `id`. */
+const offContract = (host: string, id: string): ReadonlyArray => [
+ // The host as written: its trailing dot, upper case, or a scheme in upper case.
+ `https://${host}./t/${id}`,
+ `https://${host}../t/${id}`,
+ `https://${host}%2e/t/${id}`,
+ `https://${host}\u3002/t/${id}`,
+ `https://${host.toUpperCase()}/t/${id}`,
+ `https://${host.replace("browser", "BROWSER")}/t/${id}`,
+ `HTTPS://${host}/t/${id}`,
+ // A port, even the default one, or another scheme.
+ `https://${host}:443/t/${id}`,
+ `https://${host}:8443/t/${id}`,
+ `https://${host}:/t/${id}`,
+ `http://${host}/t/${id}`,
+ // What only `new URL` or `normalizePreviewUrl` makes a view address of.
+ `https:/${host}/t/${id}`,
+ `//${host}/t/${id}`,
+ `${host}/t/${id}`,
+ ` https://${host}/t/${id} `,
+ `https://${host}/t/${id}\n`,
+ `https://${host}\\t\\${id}`,
+ `https:\\\\${host}\\t\\${id}`,
+ `ht\ttps://${host}/t/${id}`,
+ `\u00a0https://${host}/t/${id}`,
+ // Another path.
+ `https://${host}/x/../t/${id}`,
+ `https://${host}/t/./${id}`,
+ `https://${host}//t/${id}`,
+ `https://${host}/t/${id}/`,
+ `https://${host}/t/${id}/live`,
+ `https://${host}/t/`,
+ `https://${host}/t`,
+ `https://${host}/x`,
+ `https://${host}/T/${id}`,
+ `https://${host}/%74/${id}`,
+ // A query, a fragment or credentials, even empty ones.
+ `https://${host}/t/${id}?source=agent`,
+ `https://${host}/t/${id}?`,
+ `https://${host}/t/${id}#view`,
+ `https://${host}/t/${id}#`,
+ `https://user@${host}/t/${id}`,
+ `https://user:pw@${host}/t/${id}`,
+ `https://@${host}/t/${id}`,
+ // No target id: 31 or 33 digits, not hexadecimal, or percent-encoded.
+ `https://${host}/t/${id.slice(1)}`,
+ `https://${host}/t/${id}0`,
+ `https://${host}/t/${"G".repeat(32)}`,
+ `https://${host}/t/%41${id.slice(1)}`,
+ // The bare origin in any form but the two.
+ `https://${host}/?`,
+ `https://${host}/?source=agent`,
+ `https://${host}#`,
+ `https://${host}/#`,
+ `https://${host}:443`,
+ `https://${host}:443/`,
+ `https://${host}:/`,
+ `https://:@${host}/`,
+ `\ufeffhttps://${host}/`,
+ `https://${host}./`,
+ `https://${host}/./`,
+ `https://${host}//`,
+ `https://${host.toUpperCase()}/`,
+ `https://${host.replace("browser", "BROWSER")}/`,
+ ` https://${host}/`,
+ host,
+];
+const mixedCase = (id: string) =>
+ [...id].map((digit, index) => (index % 2 === 0 ? digit.toLowerCase() : digit)).join("");
+const personalHost = "browser.example-person.lazurio.io";
+const personalView = `https://${personalHost}/t/${foreignId}`;
+const longLabel = "a".repeat(63);
+export const contractCases: ReadonlyArray<{ readonly address: string; readonly takes: Takes }> = [
+ { address: `https://${ownHost}`, takes: "new tab" },
+ { address: `https://${ownHost}/`, takes: "new tab" },
+ { address: `https://${ownHost}/t/${personTab}`, takes: "own tab" },
+ { address: `https://${ownHost}/t/${personTab.toLowerCase()}`, takes: "own tab" },
+ { address: `https://${ownHost}/t/${mixedCase(personTab)}`, takes: "own tab" },
+ { address: foreignView, takes: { foreign: foreignView } },
+ {
+ address: `https://${foreignHost}/t/${foreignId.toLowerCase()}`,
+ takes: { foreign: foreignView },
+ },
+ { address: `https://${foreignHost}/t/${mixedCase(foreignId)}`, takes: { foreign: foreignView } },
+ { address: personalView, takes: { foreign: personalView } },
+ {
+ address: `https://browser.${longLabel}.a-1.lazurio.io/t/${foreignId}`,
+ takes: { foreign: `https://browser.${longLabel}.a-1.lazurio.io/t/${foreignId}` },
+ },
+ ...offContract(ownHost, personTab).map((address) => ({ address, takes: { refused: ownHost } })),
+ ...offContract(foreignHost, foreignId).map((address) => ({
+ address,
+ takes: { refused: foreignHost },
+ })),
+ ...offContract(personalHost, foreignId).map((address) => ({
+ address,
+ takes: { refused: personalHost },
+ })),
+ // Another Environment's bare origin is a new tab of its browser, which this host does not open.
+ { address: `https://${foreignHost}`, takes: { refused: foreignHost } },
+ { address: `https://${foreignHost}/`, takes: { refused: foreignHost } },
+ // A base that is no Environment id: three labels, none, or a label that is no DNS label.
+ ...[
+ "browser.a.vm-02.acme.lazurio.io",
+ "browser.lazurio.io",
+ "browser.-vm-02.acme.lazurio.io",
+ "browser.vm-02-.acme.lazurio.io",
+ `browser.${"a".repeat(64)}.acme.lazurio.io`,
+ "browser.vm_02.acme.lazurio.io",
+ ].map((host) => ({ address: `https://${host}/t/${foreignId}`, takes: { refused: host } })),
+ // A label is written as the host is: an internationalized name only in its ASCII form.
+ {
+ address: `https://browser.vm-02.xn--cme-dla.lazurio.io/t/${foreignId}`,
+ takes: { foreign: `https://browser.vm-02.xn--cme-dla.lazurio.io/t/${foreignId}` },
+ },
+ {
+ address: `https://browser.vm-02.ácme.lazurio.io/t/${foreignId}`,
+ takes: { refused: "browser.vm-02.xn--cme-dla.lazurio.io" },
+ },
+ { address: `https:${ownHost}/t/${personTab}`, takes: "invalid" },
+ ...[`wss://${ownHost}/t/${personTab}`, `view-source:https://${ownHost}/t/${personTab}`].map(
+ (address) => ({ address, takes: "invalid" as const }),
+ ),
+ // Any other host loads, a Lazurio app or a look-alike of a view host.
+ ...[
+ "https://xbrowser.vm-01.acme.lazurio.io/",
+ `https://t3code.vm-01.acme.lazurio.io/t/${personTab}`,
+ `https://browser.vm-01.acme.lazurio.io.example.test/t/${personTab}`,
+ "https://browser.example.test/",
+ `https://${ownHost}@example.test/`,
+ ].map((address) => ({ address, takes: { loads: address } })),
+ { address: "example.test/t/x", takes: { loads: "https://example.test/t/x" } },
+];
diff --git a/scripts/lazurio-release-contract.test.mjs b/scripts/lazurio-release-contract.test.mjs
index bf27365f446cf..c897b42fdd5da 100644
--- a/scripts/lazurio-release-contract.test.mjs
+++ b/scripts/lazurio-release-contract.test.mjs
@@ -2150,6 +2150,11 @@ NodeTest.test("the server and the web read a Lazurio browser view's address alik
import("../apps/web/src/lazurio/browserView.ts"),
]);
NodeAssert.equal(web.lazurioBrowserView.toString(), server.lazurioBrowserView.toString());
+ // Both run F50 point 2's one table of view addresses: the server's host and the web's panel.
+ NodeAssert.equal(
+ await read("apps/web/src/lazurio/viewAddressCases.ts"),
+ await read("apps/server/src/lazurio/viewAddressCases.ts"),
+ );
const targetId = "0123456789abcdef".repeat(2);
NodeAssert.deepEqual(
server.lazurioBrowserView(`https://browser.vm-01.acme.lazurio.io/t/${targetId}`),