Skip to content

An open-source, self-hosted system for apps built with web technologies.

Release System 0.1.84

zohayrslilehb302142cff37
diff --git a/bun.lock b/bun.lock
index 10b0dab..54695b3 100644
--- a/bun.lock
+++ b/bun.lock
@@ -8,7 +8,7 @@
"@fontsource/roboto": "^5.3.0",
"@hono/node-server": "^2.1.1",
"@jitl/quickjs-ng-wasmfile-release-sync": "^0.32.0",
- "@phreshos/core": "^0.1.56",
+ "@phreshos/core": "^0.1.57",
"@phreshos/react-ui": "^0.1.32",
"@the-link/core": "^0.3.1",
"@the-link/http": "^0.1.1",
@@ -199,7 +199,7 @@
"@oxc-project/types": ["@oxc-project/[email protected]", "", {}, "sha512-rDS5/31E9HfPl/CIzGrn0DOlvBbXFseQ5URJ9sYMfstbKLD/c6Gm9vmRzRGDdAXyOIL4zmO37lc9RIwYqVruZw=="],
- "@phreshos/core": ["@phreshos/[email protected]", "", { "dependencies": { "zod": "^4.6.5" } }, "sha512-X5JphvijFBfhzo7JplkrIra/61dXVQFQ2Y1tzpGFHycvHA3L7g6D9FriiBZcmDFk5RzohivYzJGpXq1tPeXDQQ=="],
+ "@phreshos/core": ["@phreshos/[email protected]", "", { "dependencies": { "zod": "^4.6.5" } }, "sha512-q7oJQAu9FE7CJmtM9J6xOYOK5ZjCYbJMq0FY4u1TlW+u8eHN4lwLhAXq1njotph0Fcp7VLKoxFyVzhitCk6KCQ=="],
"@phreshos/react-ui": ["@phreshos/[email protected]", "", { "dependencies": { "@base-ui/react": "^1.7.0", "@internationalized/date": "^3.12.3", "@phreshos/core": "^0.1.56", "colorjs.io": "^0.7.1", "motion": "^13.2.0", "react-aria": "^3.51.0", "react-aria-components": "^1.20.0" }, "peerDependencies": { "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-QmmpNTrM4lRaQPcAhmIwfMnf+g0lG83Z/jW3CG2HSEN5TQmlN86gzNFKED52xLY/XRfQ7VU+Ptj6MHgL0hX8zg=="],
@@ -527,6 +527,8 @@
"zod": ["[email protected]", "", {}, "sha512-v5l/aFXZQeai4awLbOpSoHecE9UiMrnfx75tEXLjNonXVARxQ5mOeipTjROUchszUNCqnE+hqAMujRsRHsut2Q=="],
+ "@phreshos/react-ui/@phreshos/core": ["@phreshos/[email protected]", "", { "dependencies": { "zod": "^4.6.5" } }, "sha512-X5JphvijFBfhzo7JplkrIra/61dXVQFQ2Y1tzpGFHycvHA3L7g6D9FriiBZcmDFk5RzohivYzJGpXq1tPeXDQQ=="],
+
"@tailwindcss/node/lightningcss": ["[email protected]", "", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.32.0", "lightningcss-darwin-arm64": "1.32.0", "lightningcss-darwin-x64": "1.32.0", "lightningcss-freebsd-x64": "1.32.0", "lightningcss-linux-arm-gnueabihf": "1.32.0", "lightningcss-linux-arm64-gnu": "1.32.0", "lightningcss-linux-arm64-musl": "1.32.0", "lightningcss-linux-x64-gnu": "1.32.0", "lightningcss-linux-x64-musl": "1.32.0", "lightningcss-win32-arm64-msvc": "1.32.0", "lightningcss-win32-x64-msvc": "1.32.0" } }, "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ=="],
"@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/[email protected]", "", { "dependencies": { "@emnapi/wasi-threads": "1.2.3", "tslib": "^2.4.0" }, "bundled": true }, "sha512-zLpS5asjEb7lq8jYLq37N6XKaE41DIexlY1rF/z4/tIl3wo13Sqm28fRyfIsKZD+NZ8mM5RoKkpW/rBcuoSZSg=="],
diff --git a/package.json b/package.json
index 30392f9..f7ba93b 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "phreshos",
"displayName": "PhreshOS",
- "version": "0.1.83",
+ "version": "0.1.84",
"description": "The PhreshOS server, desktop, and authoritative system runtime.",
"type": "module",
"private": true,
@@ -37,7 +37,7 @@
"@fontsource/roboto": "^5.3.0",
"@hono/node-server": "^2.1.1",
"@jitl/quickjs-ng-wasmfile-release-sync": "^0.32.0",
- "@phreshos/core": "^0.1.56",
+ "@phreshos/core": "^0.1.57",
"@phreshos/react-ui": "^0.1.32",
"@the-link/core": "^0.3.1",
"@the-link/http": "^0.1.1",
diff --git a/source/client/core/link-manager/auth-manager/process-manager/client-state.ts b/source/client/core/link-manager/auth-manager/process-manager/client-state.ts
index a94586d..2d84bce 100644
--- a/source/client/core/link-manager/auth-manager/process-manager/client-state.ts
+++ b/source/client/core/link-manager/auth-manager/process-manager/client-state.ts
@@ -6,7 +6,7 @@ export default class ClientState {
public readonly window: Window
- public sameOrigin: boolean
+ public readonly sandbox: boolean
public readonly service: NonNullable<ProcessSnapshot["client"]>["service"]
@@ -14,7 +14,7 @@ export default class ClientState {
this.window = window
- this.sameOrigin = payload.sameOrigin
+ this.sandbox = payload.sandbox
this.service = payload.service
}
diff --git a/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts
index 23e9426..daf100f 100644
--- a/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts
+++ b/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts
@@ -302,17 +302,6 @@ export default class ProcessManager extends TheLink {
return this.list()
}
- @Subscribe("/client-access")
- @Publish("/processes", "inbound")
- protected async clientAccessHandle(identity: string | null, payload: ProcessSnapshot | null) {
-
- if (!identity || !payload) return
-
- this.processes.get(identity)?.clientAccessChanged(payload)
-
- return this.list()
- }
-
@Subscribe("/exited")
@Publish("/processes", "inbound")
protected async exitedHandle(payload: ProcessSnapshot | null) {
diff --git a/source/client/core/link-manager/auth-manager/process-manager/process.ts b/source/client/core/link-manager/auth-manager/process-manager/process.ts
index 0a8dc02..bd685a1 100644
--- a/source/client/core/link-manager/auth-manager/process-manager/process.ts
+++ b/source/client/core/link-manager/auth-manager/process-manager/process.ts
@@ -101,12 +101,7 @@ export default class Process {
// live at birth. Its following lifecycle announcement describes that
// same Client; it must update the existing projection rather than
// inventing a second local incarnation for the Window Manager.
- if (this.client) {
-
- this.client.sameOrigin = payload.client.sameOrigin
-
- return
- }
+ if (this.client) return
this.client = new ClientState(this.clientEndpoint.window, payload.client)
}
@@ -116,10 +111,6 @@ export default class Process {
this.client = null
}
- public clientAccessChanged(payload: ProcessSnapshot) {
-
- if (this.client && payload.client) this.client.sameOrigin = payload.client.sameOrigin
- }
}
/** Retained identity needed only to reconstruct a departed parent handle. */
diff --git a/source/client/view/components/alert.tsx b/source/client/view/components/alert.tsx
index 0e1198b..997ff97 100644
--- a/source/client/view/components/alert.tsx
+++ b/source/client/view/components/alert.tsx
@@ -1,6 +1,15 @@
+import { useAppearance, useThemedValue } from "@phreshos/react-ui"
import { ComponentProps } from "react"
-export default function ({ className, ...props }: ComponentProps<"div">) {
+export default function ({ style, ...props }: ComponentProps<"div">) {
- return <div role="alert" className={`rounded border px-3 py-2 ${className ?? ""}`} {...props} />
+ const color = useThemedValue(useAppearance().colors).danger
+
+ // Form-wide failures cannot belong to one FieldError, but should retain
+ // the same compact visual language rather than introducing another surface.
+ return <div
+ {...props}
+ role="alert"
+ style={{ fontSize: "0.92em", color, ...style }}
+ />
}
diff --git a/source/client/view/components/program-frame.tsx b/source/client/view/components/program-frame.tsx
index 773850a..9483584 100644
--- a/source/client/view/components/program-frame.tsx
+++ b/source/client/view/components/program-frame.tsx
@@ -34,7 +34,9 @@ export default function ProgramFrame({ record, assetId, client, title, door, acc
title={title}
- sandbox={`allow-scripts allow-forms${client.sameOrigin ? " allow-same-origin" : ""}`}
+ // Browser containment is fixed by the Client definition; permission
+ // changes must never weaken or reload this execution boundary.
+ sandbox={client.sandbox ? "allow-scripts allow-forms" : undefined}
className={className}
diff --git a/source/client/view/components/window-manager/layer-policy.ts b/source/client/view/components/window-manager/layer-policy.ts
index eae05cb..ff31462 100644
--- a/source/client/view/components/window-manager/layer-policy.ts
+++ b/source/client/view/components/window-manager/layer-policy.ts
@@ -1,7 +1,7 @@
import type { WindowPresentationState } from "../desktop-host/window-presentation"
-import { requireWindowPresentationApplication, supportsWindowPresentationApplication, type WindowPresentationProperty } from "@shared/window-layers"
+import { requireWindowPresentationMutation, supportsWindowPresentationApplication, type WindowPresentationProperty } from "@shared/window-layers"
-export const requirePresentationApplication = requireWindowPresentationApplication
+export const requirePresentationMutation = requireWindowPresentationMutation
/** A target contributes only properties allowed by the receiving role. */
export function followedState(current: WindowPresentationState, target: WindowPresentationState, previous?: WindowPresentationState) {
diff --git a/source/client/view/components/window-manager/window-geometry.ts b/source/client/view/components/window-manager/window-geometry.ts
index 9c2b1ab..1146fe7 100644
--- a/source/client/view/components/window-manager/window-geometry.ts
+++ b/source/client/view/components/window-manager/window-geometry.ts
@@ -56,6 +56,19 @@ export function resolveWindowGeometry(position: Position, size: Size, surface: W
}
}
+/**
+ * Applies a presentation-owned minimum without rewriting authoritative values.
+ * A smaller workspace is the only case where the Desktop cannot provide it.
+ */
+export function constrainWindowGeometry(region: WindowRegion, surface: WindowSurfaceSize, minimum: WindowSurfaceSize): WindowRegion {
+
+ return {
+ ...region,
+ width: Math.max(region.width, Math.min(minimum.width, surface.width)),
+ height: Math.max(region.height, Math.min(minimum.height, surface.height))
+ }
+}
+
/**
* The window's box is its geometry; an ordinary painted frame is inset only
* on edges that do not touch that box's containing surface. Snap previews use
diff --git a/source/client/view/components/window-manager/window-manager.ts b/source/client/view/components/window-manager/window-manager.ts
index 123ea73..974732e 100644
--- a/source/client/view/components/window-manager/window-manager.ts
+++ b/source/client/view/components/window-manager/window-manager.ts
@@ -177,8 +177,8 @@ export default function useWindows(authManager: AuthManager) {
}
// Presentation and authoritative mutation are two explicit acts.
- // The presentation act already rendered the result; only the server echo may
- // project the authoritative act back onto an ordinary Window.
+ // Standard Window control always crosses the authoritative handle. Pointer
+ // motion may already show the gesture, but the server echo owns its result.
const commit = useCallback(function (request: Promise<void>) {
request.catch(() => undefined)
@@ -219,8 +219,6 @@ export default function useWindows(authManager: AuthManager) {
const highest = summit(window.layer)
- presentation.raise(process.identity)
-
if (window.depth === highest) return
commit(window.raise())
@@ -233,8 +231,6 @@ export default function useWindows(authManager: AuthManager) {
if (!window || window.layer !== "window") return
- void presentation.minimize(process.identity, minimized)
-
commit(window.minimize(minimized))
}, [commit])
@@ -257,8 +253,6 @@ export default function useWindows(authManager: AuthManager) {
if (!window || window.layer !== "window") return
- void presentation.move(process.identity, { x, y })
-
commit(window.move({ x, y }))
}, [commit])
@@ -270,9 +264,6 @@ export default function useWindows(authManager: AuthManager) {
if (!window || window.layer !== "window") return
if (!position) {
-
- void presentation.resize(process.identity, { width, height })
-
commit(window.resize({ width, height }))
return
@@ -280,8 +271,6 @@ export default function useWindows(authManager: AuthManager) {
const geometry = { ...position, width, height }
- void presentation.setGeometry(process.identity, geometry)
-
commit(window.setGeometry(geometry))
}, [commit])
@@ -294,8 +283,6 @@ export default function useWindows(authManager: AuthManager) {
const geometry = { ...position, ...size }
- void presentation.setGeometry(process.identity, geometry)
-
commit(window.setGeometry(geometry))
}, [commit])
@@ -304,7 +291,6 @@ export default function useWindows(authManager: AuthManager) {
const window = process.client?.window
if (!window || window.layer !== "window") return
const maximized = !presentation.projection(process.identity).maximized
- void presentation.maximize(process.identity, maximized)
commit(window.maximize(maximized))
}, [commit])
@@ -401,13 +387,10 @@ export default function useWindows(authManager: AuthManager) {
if (!window || window.layer !== "window") continue
const geometry = { ...region }
-
- void presentation.setGeometry(identity, geometry)
-
commit(window.setGeometry(geometry))
}
- }, [commit, presentation, peer])
+ }, [commit, peer])
return {
diff --git a/source/client/view/components/window-manager/window-presentations.ts b/source/client/view/components/window-manager/window-presentations.ts
index fbdd931..06d8a92 100644
--- a/source/client/view/components/window-manager/window-presentations.ts
+++ b/source/client/view/components/window-manager/window-presentations.ts
@@ -1,4 +1,4 @@
-import { followedState, requirePresentationApplication } from "./layer-policy"
+import { followedState, requirePresentationMutation } from "./layer-policy"
import ClientState from "@client/core/link-manager/auth-manager/process-manager/client-state"
import {
type WindowFrame,
@@ -7,7 +7,7 @@ import {
} from "@phreshos/core"
import { type PresentationTransactionRequest, type WindowPresentationHost, type WindowPresentationState } from "../desktop-host/window-presentation"
import { type WindowRegion } from "./window-geometry"
-import { isFixedWindowPresentationLayer, requireWindowPresentationRead, supportsWindowPresentationApplication } from "@shared/window-layers"
+import { isFixedWindowPresentationLayer, requireWindowPresentationRead, supportsWindowPresentationApplication, windowPresentationFollowing } from "@shared/window-layers"
export interface WindowPresentationEntry {
identity: string
@@ -75,7 +75,7 @@ export default class WindowPresentations implements WindowPresentationHost {
const state = next.get(identity)!
const target = this.authoritative.get(identity)!
const previous = relation.snapshot
- const changes = { transaction: target.transaction, ...followedState(state, target, previous) }
+ const changes = { transaction: target.transaction, depth: target.depth, ...followedState(state, target, previous) }
const maximized = changes.maximized ?? state.maximized
const minimized = changes.minimized ?? state.minimized
const geometryChanged = ("position" in changes && JSON.stringify(state.position) !== JSON.stringify(changes.position))
@@ -203,34 +203,34 @@ export default class WindowPresentations implements WindowPresentationHost {
public move(process: string, position: WindowState["position"], transaction?: PresentationTransactionRequest) {
const { identity, state } = this.existing(process)
- requirePresentationApplication(state.layer, "position")
+ requirePresentationMutation(state.layer, "position")
return this.changeGeometry(identity, { ...position, ...state.size }, transaction)
}
public resize(process: string, size: WindowState["size"], transaction?: PresentationTransactionRequest) {
const { identity, state } = this.existing(process)
- requirePresentationApplication(state.layer, "size")
+ requirePresentationMutation(state.layer, "size")
return this.changeGeometry(identity, { ...state.position, ...size }, transaction)
}
public setGeometry(process: string, value: WindowGeometry, transaction?: PresentationTransactionRequest) {
const { identity, state } = this.existing(process)
- requirePresentationApplication(state.layer, "position")
+ requirePresentationMutation(state.layer, "position")
return this.changeGeometry(identity, value, transaction)
}
public minimize(process: string, minimized: boolean, transaction?: PresentationTransactionRequest) {
const { identity, state } = this.existing(process)
- requirePresentationApplication(state.layer, "minimized")
+ requirePresentationMutation(state.layer, "minimized")
return this.changeMinimized(identity, minimized, transaction)
}
public maximize(process: string, maximized: boolean, transaction?: PresentationTransactionRequest) {
const { identity, state } = this.existing(process)
- requirePresentationApplication(state.layer, "maximized")
+ requirePresentationMutation(state.layer, "maximized")
if (state.maximized === maximized) return Promise.resolve()
this.cancel(identity, "geometry")
const animation = !state.minimized ? presentationAnimation(++this.revision, defaultPresentationTransaction(state), transaction) : null
@@ -239,7 +239,10 @@ export default class WindowPresentations implements WindowPresentationHost {
}
public follow(process: string, transaction?: PresentationTransactionRequest) {
- const { identity } = this.existing(process)
+ const { identity, state } = this.existing(process)
+ const relationship = windowPresentationFollowing(state.layer)
+ if (relationship === "required") return Promise.resolve()
+ if (relationship === "forbidden") throw new Error(`The ${state.layer} layer cannot follow an authoritative Window`)
const snapshot = this.authoritative.get(identity)!
this.following.set(identity, { snapshot })
const current = this.windows.get(identity)!
@@ -263,7 +266,10 @@ export default class WindowPresentations implements WindowPresentationHost {
}
public unfollow(process: string) {
- const { identity } = this.existing(process)
+ const { identity, state } = this.existing(process)
+ const relationship = windowPresentationFollowing(state.layer)
+ if (relationship === "required") throw new Error(`The ${state.layer} layer cannot unfollow its authoritative Window`)
+ if (relationship === "forbidden") return Promise.resolve()
this.following.delete(identity)
return Promise.resolve()
}
@@ -271,14 +277,14 @@ export default class WindowPresentations implements WindowPresentationHost {
public setTitle(process: string, title: string) {
const { identity, state } = this.existing(process)
- requirePresentationApplication(state.layer, "title")
+ requirePresentationMutation(state.layer, "title")
this.replace(identity, { ...state, title })
}
public setHeader(process: string, header: boolean) {
const { identity, state } = this.existing(process)
- requirePresentationApplication(state.layer, "header")
+ requirePresentationMutation(state.layer, "header")
if (state.header === header) return
this.replace(identity, { ...state, header })
}
@@ -286,7 +292,7 @@ export default class WindowPresentations implements WindowPresentationHost {
public raise(process: string) {
const { identity, state } = this.existing(process)
- requirePresentationApplication(state.layer, "front")
+ requirePresentationMutation(state.layer, "front")
if (frontmost(this.windows, state.layer) === identity) return
const depth = [...this.windows.values()].reduce((highest, other) => other.layer === state.layer ? Math.max(highest, other.depth) : highest, 0)
this.replace(identity, { ...state, depth: depth + 1 })
@@ -311,7 +317,7 @@ export default class WindowPresentations implements WindowPresentationHost {
public setFrame(process: string, frame: WindowFrame, transaction?: PresentationTransactionRequest) {
const { identity, state } = this.existing(process)
- requirePresentationApplication(state.layer, "frame")
+ requirePresentationMutation(state.layer, "frame")
if (JSON.stringify(state.frame) === JSON.stringify(frame)) return Promise.resolve()
this.cancel(identity, "frame")
diff --git a/source/client/view/structure/authentication/credentials-form.tsx b/source/client/view/structure/authentication/credentials-form.tsx
index 3906c04..94eef66 100644
--- a/source/client/view/structure/authentication/credentials-form.tsx
+++ b/source/client/view/structure/authentication/credentials-form.tsx
@@ -4,16 +4,18 @@ import { useReducedMotion } from "@libs/react-motion"
import { motion } from "motion/react"
import { Button, Input, Panel, useAppearance } from "@phreshos/react-ui"
import Alert from "../../components/alert"
-import { type SyntheticEvent } from "react"
+import { useState, type SyntheticEvent } from "react"
import { ApplicationContext } from "../../contexts"
import SystemHeader from "../../components/system-header"
/** The common username-and-password surface for sign-up and sign-in. */
-export default function CredentialsForm({ title, description, submitLabel, passwordAutocomplete, requirements, error, pending, onSubmit }: CredentialsFormProps) {
+export default function CredentialsForm({ title, description, submitLabel, passwordAutocomplete, requirements, error, pending, onEdit, onSubmit }: CredentialsFormProps) {
const reducedMotion = useReducedMotion()
const transaction = useAppearance().transaction
const application = ApplicationContext.useValue()
+ const [password, setPassword] = useState("")
+ const passwordReady = requirements === undefined || [...password].length >= requirements.password.minimumLength
function submit(event: SyntheticEvent<HTMLFormElement, SubmitEvent>) {
@@ -40,6 +42,10 @@ export default function CredentialsForm({ title, description, submitLabel, passw
aria-busy={pending}
+ // Authentication owns normalized credential validation. Native
+ // interception would prevent its field-specific result reaching this form.
+ noValidate
+
onSubmit={submit}
>
@@ -60,6 +66,7 @@ export default function CredentialsForm({ title, description, submitLabel, passw
<div className="grid gap-4">
+ {/* A submitted failure belongs to the exact credential values that produced it. */}
<Input
aria-label="Username"
placeholder="Username"
@@ -71,6 +78,9 @@ export default function CredentialsForm({ title, description, submitLabel, passw
maxLength={requirements?.username.maximumLength}
required
disabled={pending}
+ invalid={error?.target === "username" || error?.target === "credentials"}
+ errorMessage={error?.target === "username" ? error.message : undefined}
+ onChange={() => onEdit?.()}
autoFocus
/>
@@ -85,18 +95,27 @@ export default function CredentialsForm({ title, description, submitLabel, passw
maxLength={requirements?.password.maximumLength}
required
disabled={pending}
+ invalid={error?.target === "password" || error?.target === "credentials"}
+ errorMessage={error?.target === "password" ? error.message : undefined}
+ onChange={value => {
+
+ // This controls registration readiness only; Authentication
+ // remains the authority for accepting the submitted value.
+ setPassword(value)
+ onEdit?.()
+ }}
description={requirements ? `Use at least ${requirements.password.minimumLength} characters.` : undefined}
/>
</div>
- {error && <Alert className="text-sm">{error}</Alert>}
+ {(error?.target === "credentials" || error?.target === "form") && <Alert className="text-sm">{error.message}</Alert>}
<Button
type="submit"
- disabled={pending}
+ disabled={!passwordReady}
pending={pending}
@@ -129,9 +148,18 @@ interface CredentialsFormProps {
requirements?: AuthenticationState["requirements"]
- error?: string | null
+ error?: CredentialsError | null
pending: boolean
+ onEdit?: () => void
+
onSubmit: (username: string, password: string) => void
}
+
+export interface CredentialsError {
+
+ target: "username" | "password" | "credentials" | "form"
+
+ message: string
+}
diff --git a/source/client/view/structure/authentication/sign-in.tsx b/source/client/view/structure/authentication/sign-in.tsx
index 6dfdd13..38f4ac0 100644
--- a/source/client/view/structure/authentication/sign-in.tsx
+++ b/source/client/view/structure/authentication/sign-in.tsx
@@ -1,4 +1,4 @@
-import CredentialsForm from "./credentials-form"
+import CredentialsForm, { type CredentialsError } from "./credentials-form"
import { LinkManagerContext } from "../../contexts"
import usePromise from "@libs/react-promise"
@@ -21,11 +21,32 @@ export default function () {
passwordAutocomplete="current-password"
- error={signIn.exception ? String(signIn.exception.current) : signIn.solve && !signIn.solve.current ? "The username or password is incorrect." : null}
+ error={resolveError(signIn.exception?.current, signIn.solve?.current)}
pending={signIn.isPending}
+ onEdit={signIn.reset}
+
onSubmit={signIn.safeExecute}
/>
}
+
+function resolveError(exception: unknown, signedIn: boolean | undefined): CredentialsError | null {
+
+ if (exception !== undefined) return {
+
+ target: "form",
+
+ message: exception instanceof Error ? exception.message : String(exception)
+ }
+
+ if (signedIn === false) return {
+
+ target: "credentials",
+
+ message: "The username or password is incorrect."
+ }
+
+ return null
+}
diff --git a/source/client/view/structure/authentication/sign-up.tsx b/source/client/view/structure/authentication/sign-up.tsx
index 305b81d..c77b851 100644
--- a/source/client/view/structure/authentication/sign-up.tsx
+++ b/source/client/view/structure/authentication/sign-up.tsx
@@ -1,5 +1,5 @@
import { type AuthenticationState, type SignUpError } from "@server/core/authentication/authentication"
-import CredentialsForm from "./credentials-form"
+import CredentialsForm, { type CredentialsError } from "./credentials-form"
import { LinkManagerContext } from "../../contexts"
import usePromise from "@libs/react-promise"
@@ -13,7 +13,7 @@ export default function SignUp({ state, onClosed }: SignUpProps) {
if ("error" in response && response.error === "signed-up") onClosed()
- return "error" in response ? message(response.error, state) : null
+ return "error" in response ? resolveError(response.error, state) : null
})
return <CredentialsForm
@@ -28,30 +28,38 @@ export default function SignUp({ state, onClosed }: SignUpProps) {
requirements={state.requirements}
- error={signUp.exception ? String(signUp.exception.current) : signUp.solve?.current}
+ error={signUp.exception ? {
+
+ target: "form",
+
+ message: signUp.exception.current instanceof Error ? signUp.exception.current.message : String(signUp.exception.current)
+
+ } : signUp.solve?.current}
pending={signUp.isPending}
+ onEdit={signUp.reset}
+
onSubmit={signUp.safeExecute}
/>
}
-function message(error: SignUpError, state: AuthenticationState) {
+function resolveError(error: SignUpError, state: AuthenticationState): CredentialsError {
switch (error) {
- case "signed-up": return "Sign-up is already complete."
+ case "signed-up": return { target: "form", message: "Sign-up is already complete." }
- case "username-required": return "Enter a username."
+ case "username-required": return { target: "username", message: "Enter a username." }
- case "username-invalid": return `Use a username of at most ${state.requirements.username.maximumLength} characters without control characters.`
+ case "username-invalid": return { target: "username", message: `Use a username of at most ${state.requirements.username.maximumLength} characters without control characters.` }
- case "password-too-short": return `Use at least ${state.requirements.password.minimumLength} characters.`
+ case "password-too-short": return { target: "password", message: `Use at least ${state.requirements.password.minimumLength} characters.` }
- case "password-too-long": return `Use at most ${state.requirements.password.maximumLength} characters.`
+ case "password-too-long": return { target: "password", message: `Use at most ${state.requirements.password.maximumLength} characters.` }
- case "password-matches-username": return "The password must not be the username."
+ case "password-matches-username": return { target: "password", message: "The password must not be the username." }
}
}
diff --git a/source/client/view/structure/desktop/taskbar/programs/window-taskbar-item.tsx b/source/client/view/structure/desktop/taskbar/programs/window-taskbar-item.tsx
index 82bf61b..57289f9 100644
--- a/source/client/view/structure/desktop/taskbar/programs/window-taskbar-item.tsx
+++ b/source/client/view/structure/desktop/taskbar/programs/window-taskbar-item.tsx
@@ -42,7 +42,7 @@ export default memo(function ({ record, title, icon, active, minimized, maximize
<ContextMenu.Content UNSTABLE_portalContainer={scaleContainer ?? undefined}>
- <Menu aria-label={`${title} window actions`}>
+ <Menu aria-label={`${title} window actions`} size="small">
<Menu.Item onAction={changeVisibility}>{minimized ? "Show" : "Minimize"}</Menu.Item>
diff --git a/source/client/view/structure/desktop/windows/snap-preview.tsx b/source/client/view/structure/desktop/windows/snap-preview.tsx
index d8b07d2..bf71d1b 100644
--- a/source/client/view/structure/desktop/windows/snap-preview.tsx
+++ b/source/client/view/structure/desktop/windows/snap-preview.tsx
@@ -8,7 +8,7 @@ import { motionTransition } from "@client/view/appearance/motion"
import useWindowGeometryMotion from "./window-geometry-motion"
/** Preview of the placement currently offered by a drag. */
-export default function SnapPreview({ shown, visible, bare, paintSurfaceSize, reducedMotion, zIndex }: SnapPreviewProps) {
+export default function SnapPreview({ shown, visible, bare, minimumSize, paintSurfaceSize, reducedMotion, zIndex }: SnapPreviewProps) {
const transaction = useAppearance().transaction
@@ -17,7 +17,8 @@ export default function SnapPreview({ shown, visible, bare, paintSurfaceSize, re
size: shown.size,
animation: null,
transaction: true,
- immediate: reducedMotion
+ immediate: reducedMotion,
+ minimumSize
})
return <motion.div
@@ -52,6 +53,7 @@ interface SnapPreviewProps {
shown: SnapTarget
visible: boolean
bare: boolean
+ minimumSize?: WindowSurfaceSize
paintSurfaceSize: WindowSurfaceSize
reducedMotion: boolean
zIndex: CSSProperties["zIndex"]
diff --git a/source/client/view/structure/desktop/windows/window-geometry-motion.ts b/source/client/view/structure/desktop/windows/window-geometry-motion.ts
index fdfb1c7..78e8155 100644
--- a/source/client/view/structure/desktop/windows/window-geometry-motion.ts
+++ b/source/client/view/structure/desktop/windows/window-geometry-motion.ts
@@ -1,4 +1,4 @@
-import { resolveWindowGeometry, type WindowRegion } from "@client/view/components/window-manager/window-geometry"
+import { constrainWindowGeometry, resolveWindowGeometry, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
import { type PresentationAnimation } from "@client/view/components/desktop-host/window-presentation"
import { resolveWindowTransaction } from "@client/view/appearance/motion"
import { type AppearanceTransaction, type Position, type Size, type WindowTransaction } from "@phreshos/core"
@@ -13,6 +13,7 @@ interface WindowGeometryMotionOptions {
animation?: PresentationAnimation | null
transaction?: WindowTransaction | null
immediate: boolean
+ minimumSize?: WindowSurfaceSize
onComplete?: (revision: number) => void
}
@@ -23,7 +24,7 @@ interface WindowGeometryMotionOptions {
* visible pixels, including during a pointer gesture, so releasing a drag
* cannot hand the transform to another renderer before snapping begins.
*/
-export default function useWindowGeometryMotion({ position, size, animation, transaction, immediate, onComplete }: WindowGeometryMotionOptions) {
+export default function useWindowGeometryMotion({ position, size, animation, transaction, immediate, minimumSize, onComplete }: WindowGeometryMotionOptions) {
const appearanceTransaction = useAppearance().transaction
const frame = useRef<HTMLDivElement>(null)
@@ -41,9 +42,9 @@ export default function useWindowGeometryMotion({ position, size, animation, tra
const gesturing = useRef(false)
const restoringGesture = useRef(false)
const initialized = useRef(false)
- const values = useRef({ position, size, animation, transaction, immediate, onComplete })
+ const values = useRef({ position, size, animation, transaction, immediate, minimumSize, onComplete })
- values.current = { position, size, animation, transaction, immediate, onComplete }
+ values.current = { position, size, animation, transaction, immediate, minimumSize, onComplete }
function read(): WindowRegion {
@@ -113,7 +114,11 @@ export default function useWindowGeometryMotion({ position, size, animation, tra
const parent = frame.current?.parentElement
- return parent ? resolveWindowGeometry(values.current.position, values.current.size, logicalSize(parent)) : null
+ if (!parent) return null
+
+ const surface = logicalSize(parent)
+ const region = resolveWindowGeometry(values.current.position, values.current.size, surface)
+ return values.current.minimumSize ? constrainWindowGeometry(region, surface, values.current.minimumSize) : region
}
useLayoutEffect(function () {
@@ -148,7 +153,7 @@ export default function useWindowGeometryMotion({ position, size, animation, tra
transition(region, selected, revision === undefined ? undefined : () => onComplete?.(revision))
- }, [position.x, position.y, size.width, size.height, animation?.revision, transaction, immediate])
+ }, [position.x, position.y, size.width, size.height, animation?.revision, transaction, immediate, minimumSize?.width, minimumSize?.height])
useLayoutEffect(function () {
diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsx
index 001d27e..193cf49 100644
--- a/source/client/view/structure/desktop/windows/window.tsx
+++ b/source/client/view/structure/desktop/windows/window.tsx
@@ -2,7 +2,7 @@ import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useEffect
import { useReducedMotion } from "@libs/react-motion"
import { surfaceLifecyclePose, surfacePresencePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"
import WindowPanel from "./window-panel"
-import { absoluteWindowGeometry, minimumWindowSize, resolveWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
+import { absoluteWindowGeometry, constrainWindowGeometry, minimumWindowSize, resolveWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
import { type Position, type Size, type WindowFrame as WindowFrameDefinition, type WindowLayer, type WindowTransaction } from "@phreshos/core"
import WindowHeader from "./window-header"
import WindowFrame from "./window-frame"
@@ -56,6 +56,14 @@ export default function ({ title, header = true, frame: frameDefinition = false,
const appearanceTransaction = useAppearance().transaction
const desktopScale = useDesktopScale()
const standard = layer === "window"
+ const presentationMinimum = standard ? { width: minWidth, height: minHeight } : undefined
+
+ function resolvePresentedGeometry(selectedPosition: Position, selectedSize: Size, surface: WindowSurfaceSize) {
+
+ const region = resolveWindowGeometry(selectedPosition, selectedSize, surface)
+
+ return presentationMinimum ? constrainWindowGeometry(region, surface, presentationMinimum) : region
+ }
// Hidden windows retain their last presentation while lower-priority state changes.
const presented = useRef({ position, size })
@@ -68,6 +76,7 @@ export default function ({ title, header = true, frame: frameDefinition = false,
size: presented.current.size,
animation: geometryAnimation,
immediate: reducedMotion,
+ minimumSize: presentationMinimum,
onComplete: revision => onPresentationAnimationComplete?.("geometry", revision)
})
@@ -305,7 +314,7 @@ export default function ({ title, header = true, frame: frameDefinition = false,
const restoringMaximized = maximized
if (restoringMaximized) {
- const stored = resolveWindowGeometry(position, size, bounds)
+ const stored = resolvePresentedGeometry(position, size, bounds)
origin = { ...origin, width: stored.width, height: stored.height }
onMaximize?.()
}
@@ -393,7 +402,7 @@ export default function ({ title, header = true, frame: frameDefinition = false,
// frame never shows a stale in-between.
if (term) {
- geometryMotion.finishGesture(resolveWindowGeometry(term.position, term.size, bounds))
+ geometryMotion.finishGesture(resolvePresentedGeometry(term.position, term.size, bounds))
onSnap?.(term.position, term.size)
}
@@ -438,6 +447,7 @@ export default function ({ title, header = true, frame: frameDefinition = false,
shown={gesture.shown}
visible={gesture.zone !== null}
bare={!standard}
+ minimumSize={presentationMinimum}
paintSurfaceSize={paintSurfaceSize}
reducedMotion={reducedMotion}
zIndex={style?.zIndex}
diff --git a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
index 83f95f3..9647dc7 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
@@ -36,7 +36,6 @@ import {
} from "@phreshos/core"
import { isDesktopReplacementLayer, type DesktopReplacementLayer } from "@shared/window-layers"
import type { ServerRuntime, ServerRuntimeFactory } from "@server/core/server-runtime"
-import { permissionCatalog } from "@server/core/permissions"
import SystemAccess from "./system-access"
import { WebSocket } from "ws"
@@ -1017,8 +1016,6 @@ export default class ProcessManager extends TheLink {
this.hostTraffic,
- permissionCatalog.granted(this.authManager.programManager.permission(program, "all")),
-
window
)
@@ -1734,21 +1731,6 @@ export default class ProcessManager extends TheLink {
return this.authManager.programManager.requestPermission(program, request, name, input, process)
}
- /** Keeps each live Client's iframe access policy aligned with its Program. */
- public async updateClientAccess(program: Program) {
-
- const sameOrigin = permissionCatalog.granted(this.authManager.programManager.permission(program, "all"))
-
- for (const process of this.processes.values()) {
-
- if (process.program !== program || !process.client) continue
-
- if (!process.setClientSameOrigin(sameOrigin)) continue
-
- await this.$outbound.publish("/client-access", process.identity, process.hosted())
- }
- }
-
public cancelPermission(identity: string, request: string) {
const process = this.processes.get(identity)
diff --git a/source/server/core/link-manager/auth-manager/process-manager/process.ts b/source/server/core/link-manager/auth-manager/process-manager/process.ts
index 04e16cb..35607b8 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/process.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/process.ts
@@ -74,8 +74,6 @@ export default class Process {
private readonly hostTraffic: HostTraffic
- private clientSameOrigin: boolean
-
private readonly serverStarts: ((server: ServerProcessBoundary) => void)[] = []
private readonly serverStops: ((code: number | null, signal: NodeJS.Signals | null) => void)[] = []
@@ -95,7 +93,7 @@ export default class Process {
private exitProcess: (() => Promise<unknown>) | null = null
- public constructor(identity: string, name: string | null, program: Program, options: Options, launch: ProcessLaunch, parent: Process | null, hostTraffic: HostTraffic, clientSameOrigin: boolean, window: Window | null = null) {
+ public constructor(identity: string, name: string | null, program: Program, options: Options, launch: ProcessLaunch, parent: Process | null, hostTraffic: HostTraffic, window: Window | null = null) {
this.identity = identity
@@ -111,20 +109,9 @@ export default class Process {
this.hostTraffic = hostTraffic
- this.clientSameOrigin = clientSameOrigin
-
this.clientEndpoint = window ? Object.freeze({ window }) : null
}
- public setClientSameOrigin(sameOrigin: boolean) {
-
- if (this.clientSameOrigin === sameOrigin) return false
-
- this.clientSameOrigin = sameOrigin
-
- return true
- }
-
public startServer(runtime: ServerRuntime, service: boolean, ended: (boundary: ServerProcessBoundary, code: number | null, signal: NodeJS.Signals | null) => Promise<void> | void, unanswered: (values: unknown[], reason: string) => void, appearance: Tunnel, hostVisible: HostVisibility) {
if (this.server) return this.server
@@ -341,7 +328,7 @@ export default class Process {
? { window: this.clientEndpoint.window.toJSON() }
: null,
- client: this.client ? { ...this.client, sameOrigin: this.clientSameOrigin } : null
+ client: this.client ? { ...this.client, sandbox: this.program.client?.sandbox ?? true } : null
}
}
diff --git a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
index 46cb8e0..7d5b1fa 100644
--- a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
+++ b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
@@ -236,13 +236,7 @@ export default class ProgramManager extends TheLink {
const permission = permissionCatalog.resolve(name, value)
if (permission === null) throw new Error("A stored Program permission cannot be null")
if (before === undefined || permissionCatalog.changed(before, permission)) {
-
- const previousAll = this.permission(program, "all")
state.setPermission(name, permission)
-
- if (name === "all" && permissionCatalog.changed(previousAll, this.permission(program, "all"))) {
- await this.authManager.processManager.updateClientAccess(program)
- }
}
}
diff --git a/source/server/core/link-manager/auth-manager/program-manager/program.ts b/source/server/core/link-manager/auth-manager/program-manager/program.ts
index a545a42..61578ab 100644
--- a/source/server/core/link-manager/auth-manager/program-manager/program.ts
+++ b/source/server/core/link-manager/auth-manager/program-manager/program.ts
@@ -99,10 +99,11 @@ export default class Program {
} : null
}
- public get client(): Resolved<ClientConfig> | null {
+ public get client(): ResolvedClient | null {
return this.config.client ? {
...this.config.client,
+ sandbox: this.config.client.sandbox ?? true,
start: this.config.client.start ?? true,
service: this.config.client.service ?? false,
} : null
@@ -221,6 +222,8 @@ export default class Program {
client: client && {
+ sandbox: client.sandbox,
+
start: client.start,
service: client.service,
@@ -407,6 +410,8 @@ function coherent(config: ProgramConfig) {
if (config.client?.title !== undefined && typeof config.client.title !== "string") throw new Error("A client half's title must be text")
+ if (config.client?.sandbox !== undefined && typeof config.client.sandbox !== "boolean") throw new Error("A client half's sandbox mode must be true or false")
+
if (config.client?.frame !== undefined) parseWindowFrame(config.client.frame)
if (config.client?.transaction !== undefined) parseWindowTransaction(config.client.transaction)
@@ -437,6 +442,8 @@ type Resolved<Half extends { start?: boolean, service?: boolean }> = Half extend
? Omit<Half, "start" | "service"> & { start: boolean, service: boolean }
: never
+type ResolvedClient = Omit<Resolved<ClientConfig>, "sandbox"> & { sandbox: boolean }
+
function execution(server: { command?: unknown, worker?: unknown, sandbox?: unknown }) {
const selected = [server.command, server.worker, server.sandbox].filter(value => value !== undefined)
diff --git a/source/shared/window-layers.ts b/source/shared/window-layers.ts
index c6c5611..12580bb 100644
--- a/source/shared/window-layers.ts
+++ b/source/shared/window-layers.ts
@@ -22,8 +22,12 @@ type WindowLayerPresentation = Readonly<{
/** Facts this presentation role can report. */
readable: readonly WindowPresentationProperty[]
- /** Facts this presentation role can apply, follow, mutate, and emit. */
+ /** Facts the Desktop can apply from authoritative state and emit. */
applicable: readonly WindowPresentationProperty[]
+ /** Whether a Program may directly mutate this Desktop presentation. */
+ mutable: boolean
+ /** Whether projection from the authoritative Window is optional, required, or forbidden. */
+ following: "optional" | "required" | "forbidden"
defaults: Readonly<{
frame: boolean
header: boolean
@@ -38,6 +42,8 @@ export const windowLayerModel: Readonly<Record<WindowLayer, WindowLayerPresentat
window: Object.freeze({
readable: Object.freeze(["title", "header", "frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),
applicable: Object.freeze(["title", "header", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),
+ mutable: false,
+ following: "required",
defaults: Object.freeze({ frame: true, header: true, transaction: false }),
fixed: false,
exclusive: false,
@@ -46,6 +52,8 @@ export const windowLayerModel: Readonly<Record<WindowLayer, WindowLayerPresentat
under: Object.freeze({
readable: Object.freeze(["frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),
applicable: Object.freeze(["frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),
+ mutable: true,
+ following: "optional",
defaults: Object.freeze({ frame: false, header: false, transaction: false }),
fixed: false,
exclusive: false,
@@ -54,6 +62,8 @@ export const windowLayerModel: Readonly<Record<WindowLayer, WindowLayerPresentat
over: Object.freeze({
readable: Object.freeze(["frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),
applicable: Object.freeze(["frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),
+ mutable: true,
+ following: "optional",
defaults: Object.freeze({ frame: false, header: false, transaction: false }),
fixed: false,
exclusive: false,
@@ -62,6 +72,8 @@ export const windowLayerModel: Readonly<Record<WindowLayer, WindowLayerPresentat
wallpaper: Object.freeze({
readable: Object.freeze(["layer"] satisfies WindowPresentationProperty[]),
applicable: Object.freeze(["layer"] satisfies WindowPresentationProperty[]),
+ mutable: false,
+ following: "forbidden",
defaults: Object.freeze({ frame: false, header: false, transaction: false }),
fixed: true,
exclusive: true,
@@ -70,6 +82,8 @@ export const windowLayerModel: Readonly<Record<WindowLayer, WindowLayerPresentat
"start-menu": Object.freeze({
readable: Object.freeze(["layer"] satisfies WindowPresentationProperty[]),
applicable: Object.freeze(["layer"] satisfies WindowPresentationProperty[]),
+ mutable: false,
+ following: "forbidden",
defaults: Object.freeze({ frame: false, header: false, transaction: false }),
fixed: true,
exclusive: true,
@@ -105,6 +119,18 @@ export function requireWindowPresentationApplication(layer: WindowLayer, propert
}
}
+/** Rejects public local control while preserving application for following and Desktop ownership. */
+export function requireWindowPresentationMutation(layer: WindowLayer, property: WindowPresentationProperty) {
+ if (!windowLayerModel[layer].mutable) {
+ throw new Error(`The ${layer} layer does not allow direct presentation changes`)
+ }
+ requireWindowPresentationApplication(layer, property)
+}
+
+export function windowPresentationFollowing(layer: WindowLayer) {
+ return windowLayerModel[layer].following
+}
+
export function supportsWindowPresentationTransactions(layer: WindowLayer) {
return windowLayerModel[layer].transactions
}
diff --git a/tests/client-layer-permissions.test.ts b/tests/client-layer-permissions.test.ts
index ffbe786..1394a93 100644
--- a/tests/client-layer-permissions.test.ts
+++ b/tests/client-layer-permissions.test.ts
@@ -11,7 +11,7 @@ function fixture() {
const program: ProgramSnapshot = {
identity: "owner", reference: "program-reference", assetId: "assets", name: "Owner",
version: "0.0.0", description: null, hasAgent: false, server: null,
- client: { start: true, service: false, title: null, header: null, frame: null, transaction: null, size: null, position: null, layer: "over", minimize: null, maximize: null }
+ client: { sandbox: true, start: true, service: false, title: null, header: null, frame: null, transaction: null, size: null, position: null, layer: "over", minimize: null, maximize: null }
}
const process = { identity: "caller", reference: "process-reference", program: program.identity, name: null, startedAt: 0, options: {}, server: null, client: null }
const createProcess = vi.fn(async () => process.identity)
diff --git a/tests/client-sandbox.test.ts b/tests/client-sandbox.test.ts
index 27ec8ed..b48ba3f 100644
--- a/tests/client-sandbox.test.ts
+++ b/tests/client-sandbox.test.ts
@@ -1,18 +1,18 @@
import assert from "node:assert/strict"
import Process from "@server/core/link-manager/auth-manager/process-manager/process"
import Window from "@server/core/link-manager/auth-manager/process-manager/window"
-import type Program from "@server/core/link-manager/auth-manager/program-manager/program"
+import Program from "@server/core/link-manager/auth-manager/program-manager/program"
import type HostTraffic from "@server/core/link-manager/auth-manager/process-manager/host-traffic"
import { test } from "vitest"
test("client sandbox contract", async () => {
- const process = new Process(
+ const sandboxed = new Process(
"process",
null,
- { identity: "program" } as Program,
+ new Program({ identity: "sandboxed", storage: ".", client: { location: "." } }),
{},
@@ -22,8 +22,6 @@ test("client sandbox contract", async () => {
{} as HostTraffic,
- false,
-
new Window(
{ title: "Client", header: true, frame: true, transaction: false, layer: "window" },
@@ -38,12 +36,27 @@ test("client sandbox contract", async () => {
)
)
- process.startClient(false)
+ sandboxed.startClient(false)
- assert.equal(process.hosted().client?.sameOrigin, false)
+ assert.equal(sandboxed.hosted().client?.sandbox, true)
- assert.equal(process.setClientSameOrigin(true), true)
- assert.equal(process.setClientSameOrigin(true), false)
+ const trusted = new Process(
+ "trusted-process",
+ null,
+ new Program({ identity: "trusted", storage: ".", client: { location: ".", sandbox: false } }),
+ {},
+ { server: null, client: null, options: {} },
+ null,
+ {} as HostTraffic,
+ new Window(
+ { title: "Client", header: true, frame: true, transaction: false, layer: "window" },
+ { x: 0, y: 0 },
+ { width: 640, height: 480 },
+ 1,
+ false
+ )
+ )
+ trusted.startClient(false)
- assert.equal(process.hosted().client?.sameOrigin, true)
+ assert.equal(trusted.hosted().client?.sandbox, false)
}, 120_000)
diff --git a/tests/panel.test.tsx b/tests/panel.test.tsx
index f01165d..5ee62e7 100644
--- a/tests/panel.test.tsx
+++ b/tests/panel.test.tsx
@@ -55,17 +55,30 @@ test("panel contract", async () => {
const authentication = markup(<CredentialsForm title="Sign in" description="Welcome" submitLabel="Continue" passwordAutocomplete="current-password" pending={false} onSubmit={() => {}} />)
panel(authentication, 5)
assert.equal(authentication.match(/<form\b/g)?.length, 1)
+ assert.match(authentication, /<form[^>]*noValidate=""/)
assert.match(authentication, /name="username"/)
assert.match(authentication, /name="password"/)
assert.match(authentication, /placeholder="Username"/)
assert.match(authentication, /placeholder="Password"/)
- assert.equal(authentication.match(/height:42px/g)?.length, 3)
assert.doesNotMatch(authentication, /<label\b/)
+ assert.equal(authentication.match(/height:42px/g)?.length, 3)
assert.match(authentication, /type="submit"/)
assert.match(authentication, /<h2[^>]*>Example System<\/h2>/)
assert.match(authentication, /System version 1.2.3/)
assert.doesNotMatch(authentication, /backdrop-blur/)
+ const authenticationError = markup(<CredentialsForm title="Sign up" description="Welcome" submitLabel="Continue" passwordAutocomplete="new-password" pending={false}
+ requirements={{ username: { minimumLength: 1, maximumLength: 64 }, password: { minimumLength: 8, maximumLength: 1024 } }}
+ error={{ target: "password", message: "Use a stronger password." }} onSubmit={() => {}} />)
+ assert.match(authenticationError, /<input(?=[^>]*name="password")(?=[^>]*aria-invalid="true")/)
+ assert.match(authenticationError, /Use a stronger password\./)
+ assert.match(authenticationError, /<button(?=[^>]*disabled="")(?=[^>]*type="submit")/)
+
+ const authenticationFailure = markup(<CredentialsForm title="Sign in" description="Welcome" submitLabel="Continue" passwordAutocomplete="current-password" pending={false}
+ error={{ target: "form", message: "The request failed." }} onSubmit={() => {}} />)
+ assert.match(authenticationFailure, /role="alert"/)
+ assert.match(authenticationFailure, /The request failed\./)
+
const launcher = markup(<Launcher label="Example System" trigger="Open">{(_close, labelId) => <StartMenuPanel labelId={labelId} name="Example System" version="1.2.3" left={<button>Programs</button>} right={<p>Processes</p>} footer={<input type="search" aria-label="Search Programs and Processes" />} />}</Launcher>)
assert.equal(launcher.match(/data-material=""/g)?.length, 4)
assert.match(launcher, /grid-cols-2/)
diff --git a/tests/permission-requests.test.ts b/tests/permission-requests.test.ts
index d04212d..e353857 100644
--- a/tests/permission-requests.test.ts
+++ b/tests/permission-requests.test.ts
@@ -20,10 +20,9 @@ test("permission requests contract", async () => {
let dialogs = 0
let choice: boolean | null = null
let whilePending: (() => void) | undefined
- let accessUpdates = 0
let dialogProgram: Program | null = null
- const process = new Process("process", null, program, {}, { server: null, client: null, options: {} }, null, {} as HostTraffic, false,
+ const process = new Process("process", null, program, {}, { server: null, client: null, options: {} }, null, {} as HostTraffic,
new Window({ title: "Client", header: true, frame: true, transaction: false, layer: "window" }, { x: 0, y: 0 }, { width: 640, height: 480 }, 1, false))
process.startClient(false)
@@ -40,11 +39,7 @@ test("permission requests contract", async () => {
const programManager = Object.assign(Object.create(ProgramManager.prototype), { authManager }) as ProgramManager
const processManager = Object.assign(Object.create(ProcessManager.prototype), {
authManager,
- processes: new Map([["process", process]]),
- $outbound: { async publish(event: string) {
- assert.equal(event, "/client-access")
- accessUpdates++
- } }
+ processes: new Map([["process", process]])
}) as ProcessManager
Object.assign(authManager, { programManager, processManager })
@@ -99,16 +94,11 @@ test("permission requests contract", async () => {
assert(!programManager.grantsPermission(declared, "services", ["browser"]))
assert(programManager.grantsPermission(declared, "services", ["editor"]))
- // The iframe policy is synchronized independently of permission request results.
assign("all", false)
assert.deepEqual(await request("all"), [])
- assert.equal(process.hosted().client?.sameOrigin, true)
- assert.equal(accessUpdates, 1)
await programManager.setPermission(program, "all", [])
- assert.equal(accessUpdates, 1)
await programManager.setPermission(program, "all", false)
- assert.equal(process.hosted().client?.sameOrigin, false)
- assert.equal(accessUpdates, 2)
+ assert.equal(programManager.permission(program, "all"), false)
}
finally {
rmSync(temporary, { recursive: true, force: true })
diff --git a/tests/program-creation.test.ts b/tests/program-creation.test.ts
index 5aeca52..28c69bb 100644
--- a/tests/program-creation.test.ts
+++ b/tests/program-creation.test.ts
@@ -19,7 +19,7 @@ function fixture(context: TestContext) {
const announceHost = vi.fn()
const auth = Object.assign(new TheLink(), {
linkManager: { application: { storage: new FileManager(directory, "system"), defaultProgramIcon: "" } },
- processManager: { processes: new Map(), exitAll: vi.fn(), announceHost, announceSubject: vi.fn(), updateClientAccess: vi.fn() }
+ processManager: { processes: new Map(), exitAll: vi.fn(), announceHost, announceSubject: vi.fn() }
}) as unknown as AuthManager
const manager = new ProgramManager(auth)
function definition(permissions?: ProgramPermissionDeclarations) {
diff --git a/tests/program-frame.test.tsx b/tests/program-frame.test.tsx
index d37dd5f..969db3e 100644
--- a/tests/program-frame.test.tsx
+++ b/tests/program-frame.test.tsx
@@ -7,7 +7,7 @@ import { test } from "vitest"
test("program frame contract", async () => {
const record = { identity: "process", program: "program" } as Process
- const client = { sameOrigin: false, window: {} } as ClientState
+ const client = { sandbox: true, window: {} } as ClientState
const common = {
record,
assetId: "00000000-0000-4000-8000-000000000000",
@@ -22,13 +22,11 @@ test("program frame contract", async () => {
const dark = renderToStaticMarkup(<ProgramFrame {...common} theme="dark" />)
const light = renderToStaticMarkup(<ProgramFrame {...common} theme="light" />)
- client.sameOrigin = true
-
- const fullAccess = renderToStaticMarkup(<ProgramFrame {...common} theme="light" />)
+ const trusted = renderToStaticMarkup(<ProgramFrame {...common} client={{ ...client, sandbox: false } as ClientState} theme="light" />)
assert.match(dark, /style="color-scheme:dark"/)
assert.match(light, /style="color-scheme:light"/)
assert.match(dark, /sandbox="allow-scripts allow-forms"/)
- assert.match(fullAccess, /sandbox="allow-scripts allow-forms allow-same-origin"/)
- assert.match(fullAccess, /src="\/program\/00000000-0000-4000-8000-000000000000\/assets\/"/)
+ assert.doesNotMatch(trusted, /sandbox=/)
+ assert.match(trusted, /src="\/program\/00000000-0000-4000-8000-000000000000\/assets\/"/)
}, 120_000)
diff --git a/tests/window-geometry.test.ts b/tests/window-geometry.test.ts
index 8973998..6de20a6 100644
--- a/tests/window-geometry.test.ts
+++ b/tests/window-geometry.test.ts
@@ -3,9 +3,23 @@ import ClientWindow from "@client/core/link-manager/auth-manager/process-manager
import ClientProcessManager from "@client/core/link-manager/auth-manager/process-manager/process-manager"
import ProcessManager from "@server/core/link-manager/auth-manager/process-manager/process-manager"
import ServerWindow from "@server/core/link-manager/auth-manager/process-manager/window"
+import { constrainWindowGeometry, minimumWindowSize, resolveWindowGeometry } from "@client/view/components/window-manager/window-geometry"
import { TheLink } from "@the-link/core"
import { test } from "vitest"
+test("a standard presentation enforces its minimum after resolving authoritative geometry", () => {
+ const surface = { width: 1200, height: 800 }
+ const authoritative = resolveWindowGeometry({ x: 0, y: 0 }, { width: "1/2", height: 1 }, surface)
+
+ assert.deepEqual(authoritative, { x: 0, y: 0, width: 600, height: 1 })
+ assert.deepEqual(constrainWindowGeometry(authoritative, surface, minimumWindowSize), {
+ x: 0, y: 0, width: 600, height: 160
+ })
+ assert.deepEqual(constrainWindowGeometry({ x: 0, y: 0, width: 1, height: 1 }, { width: 120, height: 80 }, minimumWindowSize), {
+ x: 0, y: 0, width: 120, height: 80
+ })
+})
+
test("window geometry contract", async () => {
const initial = {
position: { x: 10, y: 20 },
diff --git a/tests/window-presentation-layers.test.ts b/tests/window-presentation-layers.test.ts
index 4b4a2ed..171f997 100644
--- a/tests/window-presentation-layers.test.ts
+++ b/tests/window-presentation-layers.test.ts
@@ -42,7 +42,7 @@ test.each(["wallpaper", "start-menu"] as const)("%s exposes only concepts unders
() => presentations.setFrame("own", true),
() => presentations.raise("own")
]
- for (const operation of unsupported) expect(operation).toThrow(new RegExp(`${layer} layer cannot apply`))
+ for (const operation of unsupported) expect(operation).toThrow(new RegExp(`${layer} layer does not allow direct`))
own.window.position = { x: 500, y: 600 }
own.window.title = "Changed"
@@ -50,7 +50,7 @@ test.each(["wallpaper", "start-menu"] as const)("%s exposes only concepts unders
expect(presentations.projection("own").position).toEqual({ x: 0, y: 0 })
expect(presentations.projection("own").title).toBe("Original")
- await presentations.follow("own")
+ expect(() => presentations.follow("own")).toThrow(new RegExp(`${layer} layer cannot follow`))
expect(presentations.projection("own").title).toBe("Original")
expect(presentations.projection("own").position).toEqual({ x: 0, y: 0 })
})
@@ -79,11 +79,24 @@ test.each(["under", "over"] as const)("%s presents geometry and frame without a
expect(presentations.projection("own").position).toEqual({ x: 100, y: 200 })
})
-test("a standard presentation reports its permanent frame without allowing frame changes", async () => {
+test("a standard presentation is observed locally and controlled through its authoritative Window", async () => {
const { presentations } = fixture("window")
expect(presentations.read("own", "frame")).toBe(true)
- expect(() => presentations.setFrame("own", false)).toThrow(/window layer cannot apply frame/)
+ const mutations = [
+ () => presentations.move("own", { x: 1, y: 2 }),
+ () => presentations.resize("own", { width: 300, height: 200 }),
+ () => presentations.setGeometry("own", { x: 1, y: 2, width: 300, height: 200 }),
+ () => presentations.minimize("own", true),
+ () => presentations.maximize("own", true),
+ () => presentations.setTitle("own", "Changed"),
+ () => presentations.setHeader("own", false),
+ () => presentations.setFrame("own", false),
+ () => presentations.raise("own")
+ ]
+ for (const mutation of mutations) expect(mutation).toThrow(/window layer does not allow direct/)
+ await expect(presentations.follow("own")).resolves.toBeUndefined()
+ expect(() => presentations.unfollow("own")).toThrow(/window layer cannot unfollow/)
})
test("unsupported presentation events remain silent", () => {
@@ -93,7 +106,7 @@ test("unsupported presentation events remain silent", () => {
own.window.position = { x: 500, y: 600 }
own.window.title = "Changed"
- presentations.follow("own")
+ expect(() => presentations.follow("own")).toThrow(/wallpaper layer cannot follow/)
presentations.reconcile(entries)
expect(received).toEqual([])
diff --git a/tests/window-presentation.test.ts b/tests/window-presentation.test.ts
index 6a7b30b..5f2dd97 100644
--- a/tests/window-presentation.test.ts
+++ b/tests/window-presentation.test.ts
@@ -32,10 +32,10 @@ test("each Desktop owns an independent Window presentation", async () => {
const first = new WindowPresentations(entries, identity => byProcess.get(identity) as never ?? null)
const second = new WindowPresentations(entries, identity => byProcess.get(identity) as never ?? null)
- await first.move("ordinary", { x: 40, y: 50 })
+ assert.throws(() => first.move("ordinary", { x: 40, y: 50 }), /does not allow direct/)
await first.move("overlay", { x: 60, y: 70 })
- assert.deepEqual(first.state("ordinary").position, { x: 40, y: 50 })
+ assert.deepEqual(first.state("ordinary").position, { x: 0, y: 0 })
assert.deepEqual(first.state("overlay").position, { x: 60, y: 70 })
assert.deepEqual(second.state("ordinary").position, { x: 0, y: 0 })
assert.deepEqual(ordinary.window.position, { x: 0, y: 0 })
@@ -112,19 +112,13 @@ test("transaction-capable presentations use the authoritative Window transaction
await inherited
})
-test("standard Window geometry uses the Desktop Appearance transaction by default", async () => {
+test("authoritative standard Window geometry uses the Desktop Appearance transaction", async () => {
const ordinary = client("window")
const entries = new Map([
["ordinary", { identity: "ordinary:0", client: ordinary }]
]) as unknown as ReadonlyMap<string, WindowPresentationEntry>
const presentations = new WindowPresentations(entries, () => ordinary as never)
- await presentations.move("ordinary", { x: 20, y: 30 })
- assert.equal(presentations.projection("ordinary").geometryAnimation?.transaction, true)
-
- await presentations.resize("ordinary", { width: 500, height: 400 })
- assert.equal(presentations.projection("ordinary").geometryAnimation?.transaction, true)
-
ordinary.window.position = { x: 80, y: 90 }
presentations.reconcile(entries)
assert.equal(presentations.projection("ordinary").geometryAnimation?.transaction, true)