An open-source, self-hosted system for apps built with web technologies.
Release System 0.1.70
zohayrslilehfbd4501fdcdd
diff --git a/bun.lock b/bun.lockindex 4729bc5..e5d0004 100644--- a/bun.lock+++ b/bun.lock@@ -8,7 +8,7 @@"@fontsource/roboto": "^5.3.0","@hono/node-server": "^2.1.1","@phreshos/core": "^0.1.49",- "@phreshos/react-ui": "^0.1.22",+ "@phreshos/react-ui": "^0.1.23","@the-link/core": "^0.3.0","@the-link/http": "^0.1.1","@the-link/ipc": "^0.2.1",@@ -249,7 +249,7 @@"@phreshos/core": ["@phreshos/[email protected]", "", {}, "sha512-WRVvFag4L2c/ooflnbyrB3WmFROMF6yF6Cz3ABt0UeyEZ2UIccQHJR125OvM5imVJNv+buTZIryXA5yooMn21Q=="],- "@phreshos/react-ui": ["@phreshos/[email protected]", "", { "dependencies": { "@base-ui/react": "^1.7.0", "@phreshos/core": "^0.1.49", "colorjs.io": "^0.7.1", "motion": "^13.2.0", "react-aria-components": "^1.20.0" }, "peerDependencies": { "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-IeqFhcTWsUqBwHyRA4evuLHJG8EJrJoTihjFmo9DsD9C36fMA2iFxZc0qNy5St9JUFhwml4IVXQdqwSEeOcwww=="],+ "@phreshos/react-ui": ["@phreshos/[email protected]", "", { "dependencies": { "@base-ui/react": "^1.7.0", "@phreshos/core": "^0.1.49", "colorjs.io": "^0.7.1", "motion": "^13.2.0", "react-aria-components": "^1.20.0" }, "peerDependencies": { "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-ajmii1CiYVLRlWGy2XLAMwFWYXFbOvsEgN11B7AcTQpA05Y8CCT5ARRHckDkP5BIGZ+wA3mRppVcDlXJBugd2w=="],"@react-types/shared": ["@react-types/[email protected]", "", { "peerDependencies": { "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" } }, "sha512-AzsuD9OfxTOZMMvTRhlN3oHBwOmFN7tDh27LzqmHt4+uOgPhJT7ZM7/kVs/8/o0WxayMUIk3hBmCFRHv1FUoag=="],diff --git a/package.json b/package.jsonindex 676db9b..85413d8 100644--- a/package.json+++ b/package.json@@ -1,7 +1,7 @@{"name": "phreshos","displayName": "PhreshOS",- "version": "0.1.69",+ "version": "0.1.70","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","@phreshos/core": "^0.1.49",- "@phreshos/react-ui": "^0.1.22",+ "@phreshos/react-ui": "^0.1.23","@the-link/core": "^0.3.0","@the-link/http": "^0.1.1","@the-link/ipc": "^0.2.1",diff --git a/source/client/view/structure/authentication/credentials-form.tsx b/source/client/view/structure/authentication/credentials-form.tsxindex 24d4779..a3427b1 100644--- a/source/client/view/structure/authentication/credentials-form.tsx+++ b/source/client/view/structure/authentication/credentials-form.tsx@@ -36,7 +36,7 @@ export default function CredentialsForm({ title, description, submitLabel, passwtransition={surfacePresenceTransition(reducedMotion, transaction)}- className="relative m-auto w-[min(24rem,calc(100%-2rem))]"+ className="pointer-events-auto relative m-auto w-[min(24rem,calc(100%-2rem))]"aria-busy={pending}diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsxindex 757e5cb..07ce26e 100644--- a/source/client/view/structure/desktop/desktop.tsx+++ b/source/client/view/structure/desktop/desktop.tsx@@ -17,7 +17,7 @@ import useWindows from "../../components/window-manager/window-manager"import { ReadyWallpaper, WallpaperBackground } from "./wallpaper/wallpaper"import Loading from "../../components/loading"import { useRequirement } from "@libs/readiness"-import { useAppearance, useThemedValue, useTheme } from "@phreshos/react-ui"+import { useAppearance, usePreferences, useThemedValue } from "@phreshos/react-ui"export default function Workspace() {@@ -31,7 +31,7 @@ export default function Workspace() {const foreground = useThemedValue(appearance.colors).foreground- const theme = useTheme()+ const { theme } = usePreferences()const windows = useWindows(authManager)diff --git a/source/client/view/structure/desktop/wallpaper/wallpaper.tsx b/source/client/view/structure/desktop/wallpaper/wallpaper.tsxindex a5c15ac..4f41fe0 100644--- a/source/client/view/structure/desktop/wallpaper/wallpaper.tsx+++ b/source/client/view/structure/desktop/wallpaper/wallpaper.tsx@@ -4,43 +4,34 @@ import { ApplicationContext } from "@client/view/contexts"import { useEffect, useEffectEvent, useRef, useState, type ReactNode, type TransitionEvent } from "react"import Loading from "@client/view/components/loading"import { useReady } from "@libs/readiness"-import { useAppearance, useTheme } from "@phreshos/react-ui"+import { useAppearance, usePreferences } from "@phreshos/react-ui"import { useReducedMotion } from "@libs/react-motion"import { cssEasing } from "@client/view/appearance/motion"+import { wallpaperKind, type WallpaperKind } from "@shared/wallpaper"const bundledWallpapers = [darkWallpaper, lightWallpaper] as const-const wallpaperImages = new Map<string, HTMLImageElement>()--const wallpaperLoads = new Map<string, Promise<void>>()+type WallpaperSource = Readonly<{+ identity: string+ kind: WallpaperKind+ url: string+}>type WallpaperLayers = Readonly<{- displayed: string | null- incoming: string | null+ displayed: WallpaperSource | null+ incoming: WallpaperSource | nullswitching: boolean}>-/**- * Displays one completely loaded wallpaper source.- *- * A filename asks for a served image and `null` selects the effective Theme's- * bundled wallpaper. Both bundled sources remain preloaded so a Theme change- * only replaces the source of this one visual layer.- */+/** Displays one completely loaded wallpaper source. */export function WallpaperBackground({ file, onReady }: WallpaperBackgroundProps) {-const application = ApplicationContext.useValue()-- const theme = useTheme()+ const { theme } = usePreferences()const reducedMotion = useReducedMotion()-- const desired = file === null- ? theme === "dark" ? darkWallpaper : lightWallpaper- : `${application.doors.uploads}/${encodeURIComponent(file)}`-+ const desired = resolveWallpaper(file, theme, application.doors.uploads)const [layers, setLayers] = useState<WallpaperLayers>({displayed: null,- incoming: null,+ incoming: desired,switching: false})const current = useRef(layers)@@ -49,165 +40,190 @@ export function WallpaperBackground({ file, onReady }: WallpaperBackgroundProps)current.current = layersconst ready = useEffectEvent(() => onReady?.())- const display = useEffectEvent((source: string) => {++ useEffect(() => {+ for (const wallpaper of bundledWallpapers) {+ const image = new Image()+ image.src = wallpaper+ }+ }, [])++ useEffect(() => {+ cancelSwitch(frame)+ setLayers(value => {+ if (value.displayed?.identity === desired.identity) {+ return value.incoming ? { displayed: value.displayed, incoming: null, switching: false } : value+ }++ if (value.incoming?.identity === desired.identity) return value++ return { displayed: value.displayed, incoming: desired, switching: false }+ })+ }, [desired.identity])++ useEffect(() => () => cancelSwitch(frame), [])++ function loaded(source: WallpaperSource) {const shown = current.current+ if (shown.incoming?.identity !== source.identity) return++ ready()+if (!shown.displayed || reducedMotion) {setLayers({ displayed: source, incoming: null, switching: false })return}- if (shown.displayed === source && !shown.incoming) return-- if (frame.current !== null) cancelAnimationFrame(frame.current)- setLayers({ displayed: shown.incoming ?? shown.displayed, incoming: source, switching: false })+ cancelSwitch(frame)frame.current = requestAnimationFrame(() => {frame.current = requestAnimationFrame(() => {frame.current = null- setLayers(value => value.incoming === source ? { ...value, switching: true } : value)+ setLayers(value => value.incoming?.identity === source.identity+ ? { ...value, switching: true }+ : value)})})- })-- useEffect(() => () => {- if (frame.current !== null) cancelAnimationFrame(frame.current)- }, [])+ }- useEffect(() => {- let active = true- const desiredLoad = loadWallpaper(desired)- const bundledLoads = bundledWallpapers.map(loadWallpaper)- const loading = file === null- ? Promise.allSettled(bundledLoads).then(() => desiredLoad)- : desiredLoad-- for (const preload of bundledLoads) void preload.catch(() => undefined)-- loading.then(() => {- if (!active) return- display(desired)- ready()- }, () => {- if (active) ready()- })+ function failed(source: WallpaperSource) {+ if (current.current.incoming?.identity !== source.identity) return- return () => { active = false }- }, [desired, file])+ setLayers(value => value.incoming?.identity === source.identity+ ? { ...value, incoming: null, switching: false }+ : value)+ ready()+ }- function transitionEnded(event: TransitionEvent<HTMLDivElement>, source: string) {- if (event.propertyName !== "opacity" || layers.incoming !== source || !layers.switching) return+ function transitionEnded(event: TransitionEvent<HTMLDivElement>, source: WallpaperSource) {+ if (event.propertyName !== "opacity" || layers.incoming?.identity !== source.identity || !layers.switching) returnsetLayers({ displayed: source, incoming: null, switching: false })}const incoming = layers.incomingreturn <>-{layers.displayed && <WallpaperLayer- key={layers.displayed}+ key={layers.displayed.identity}source={layers.displayed}visible/>}{incoming && <WallpaperLayer- key={incoming}+ key={incoming.identity}source={incoming}visible={layers.switching}+ onLoad={() => loaded(incoming)}+ onError={() => failed(incoming)}onTransitionEnd={event => transitionEnded(event, incoming)}/>}-</>}-function WallpaperLayer({ source, visible, onTransitionEnd }: {- source: string+function WallpaperLayer({ source, visible, onLoad, onError, onTransitionEnd }: Readonly<{+ source: WallpaperSourcevisible: boolean+ onLoad?: () => void+ onError?: () => voidonTransitionEnd?: (event: TransitionEvent<HTMLDivElement>) => void-}) {+}>) {const transaction = useAppearance().transactionconst reducedMotion = useReducedMotion()+ const interactive = source.kind === "html" && visiblereturn <div- aria-hidden="true"- className={`pointer-events-none absolute inset-0 bg-cover bg-center bg-no-repeat ${visible ? "opacity-100" : "opacity-0"}`}+ className={`absolute inset-0 ${interactive ? "pointer-events-auto" : "pointer-events-none"} ${visible ? "opacity-100" : "opacity-0"}`}style={{- backgroundImage: `url(${source})`,transitionDuration: reducedMotion ? "0ms" : String(transaction.duration) + "ms",transitionTimingFunction: cssEasing(transaction.easing),transitionProperty: "opacity"}}onTransitionEnd={onTransitionEnd}- />+ >+ {source.kind === "image" && <img+ aria-hidden="true"+ alt=""+ className="h-full w-full object-cover"+ draggable={false}+ src={source.url}+ onLoad={event => void event.currentTarget.decode().then(onLoad, onError)}+ onError={onError}+ />}++ {source.kind === "video" && <video+ aria-hidden="true"+ className="h-full w-full object-cover"+ src={source.url}+ autoPlay+ loop+ muted+ playsInline+ preload="auto"+ onCanPlay={onLoad}+ onError={onError}+ />}++ {source.kind === "html" && <iframe+ className="h-full w-full border-0"+ src={source.url}+ title="Wallpaper"+ sandbox="allow-scripts"+ referrerPolicy="no-referrer"+ onLoad={onLoad}+ onError={onError}+ />}+ </div>}-function loadWallpaper(source: string) {- const existing = wallpaperLoads.get(source)+function resolveWallpaper(file: string | null, theme: "light" | "dark", uploads: string): WallpaperSource {+ if (file === null) {+ const url = theme === "dark" ? darkWallpaper : lightWallpaper- if (existing) return existing+ return { identity: `bundled:${theme}`, kind: "image", url }+ }- const image = new Image()- const loading = new Promise<void>((resolve, reject) => {- const failed = () => {- wallpaperImages.delete(source)- wallpaperLoads.delete(source)- reject(new Error(`The wallpaper could not be loaded: ${source}`))- }+ const kind = wallpaperKind(file) ?? "image"+ const path = kind === "html" ? `${uploads}/wallpaper/${encodeURIComponent(file)}` : `${uploads}/${encodeURIComponent(file)}`- image.onload = () => void image.decode().then(resolve, failed)- image.onerror = failed- })+ return { identity: `${kind}:${file}`, kind, url: path }+}- wallpaperImages.set(source, image)- wallpaperLoads.set(source, loading)- image.src = source+function cancelSwitch(frame: { current: number | null }) {+ if (frame.current === null) return- return loading+ cancelAnimationFrame(frame.current)+ frame.current = null}/** A complete surface whose content sits above one file-backed wallpaper. */export function WallpaperStage({ file, children }: WallpaperStageProps) {-const [readyFile, setReadyFile] = useState<string | null>()-const ready = readyFile === filereturn <div className="relative isolate grid min-h-0">+ <WallpaperBackground file={file} onReady={() => setReadyFile(file)} />- <WallpaperBackground file={file} onReady={() => {-- setReadyFile(file)- }} />-- <div className="relative z-1 grid min-h-0">-+ <div className="pointer-events-none relative z-1 grid min-h-0">{children}-</div>{!ready && <Loading />}-{ready && <ReadyWallpaper />}-</div>}export function ReadyWallpaper() {-useReady("wallpaper")return null}interface WallpaperStageProps {-file: string | null-children: ReactNode}interface WallpaperBackgroundProps {-file: string | null-onReady?: () => void}diff --git a/source/client/view/structure/structure.tsx b/source/client/view/structure/structure.tsxindex 164807b..f981717 100644--- a/source/client/view/structure/structure.tsx+++ b/source/client/view/structure/structure.tsx@@ -121,7 +121,7 @@ function ConnectedDesktop({ linkManager }: { linkManager: LinkManager }) {return <LinkManagerContext.Provider value={linkManager}>- <AppearanceProvider appearance={appearance} theme={preferences.theme}>+ <AppearanceProvider appearance={appearance} preferences={preferences}><ConnectedAppearance>diff --git a/source/server/core/appearance-manager.ts b/source/server/core/appearance-manager.tsindex dbec79a..633b446 100644--- a/source/server/core/appearance-manager.ts+++ b/source/server/core/appearance-manager.ts@@ -1,11 +1,10 @@import Keyv from "keyv"-import { extname } from "node:path"import { defaultAppearance, parseAppearance, type Appearance } from "@phreshos/core"import UploadManager from "./upload-manager"+import { wallpaperKind, wallpaperSizeLimit } from "@shared/wallpaper"const storageKey = "appearance"const servedFile = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.[a-z0-9]+$/-const wallpaperExtensions = new Set(["avif", "bmp", "gif", "jpeg", "jpg", "png", "svg", "webp"])/** Durable, complete Appearance state owned by Server Core. */export default class AppearanceManager {@@ -43,7 +42,11 @@ export default class AppearanceManager {private validateWallpaper(file: string | null) {if (file === null) returnif (!servedFile.test(file)) throw new Error("A wallpaper must be a system upload")- if (!wallpaperExtensions.has(extname(file).slice(1))) throw new Error("A wallpaper must be an image file")- if (!this.uploads.stat(file)) throw new Error("The wallpaper upload does not exist")++ const upload = this.uploads.stat(file)++ if (!upload) throw new Error("The wallpaper upload does not exist")+ if (!wallpaperKind(file)) throw new Error("A wallpaper must be an image, video, or HTML file")+ if (upload.size > wallpaperSizeLimit) throw new Error("A wallpaper cannot exceed 50 MiB")}}diff --git a/source/server/view/http/uploads.ts b/source/server/view/http/uploads.tsindex 9625e66..5426c86 100644--- a/source/server/view/http/uploads.ts+++ b/source/server/view/http/uploads.ts@@ -4,6 +4,24 @@ import Application from "@server/core/application"import doors from "./doors"import { Hono } from "hono"import { isUploadFile } from "@phreshos/core"+import { readFile } from "node:fs/promises"+import { wallpaperKind, wallpaperSizeLimit } from "@shared/wallpaper"++const wallpaperPolicy = [+ "default-src 'none'",+ "script-src 'unsafe-inline' data: blob:",+ "style-src 'unsafe-inline' data: blob:",+ "img-src data: blob:",+ "media-src data: blob:",+ "font-src data:",+ "connect-src 'none'",+ "worker-src data: blob:",+ "object-src 'none'",+ "frame-src data: blob:",+ "base-uri 'none'",+ "form-action 'none'",+ "sandbox allow-scripts"+].join("; ")/*** The door bytes come through, and the one they go back out of.@@ -82,6 +100,30 @@ export default function (application: Application) {}})+ uploads.get("/wallpaper/:file", async function (context) {+ const file = context.req.param("file")++ if (!isUploadFile(file)) return context.text("That is not an upload file", 400)+ if (wallpaperKind(file) !== "html") return context.text("That upload is not an HTML wallpaper", 400)++ try {+ const upload = application.uploads.stat(file)++ if (!upload) return context.body(null, 404)+ if (upload.size > wallpaperSizeLimit) return context.text("A wallpaper cannot exceed 50 MiB", 413)++ context.header("Content-Security-Policy", wallpaperPolicy)+ context.header("Content-Type", "text/html; charset=utf-8")+ context.header("X-Content-Type-Options", "nosniff")++ return context.body(Uint8Array.from(await readFile(application.uploads.path(file))))+ }++ catch (error) {+ return context.text(error instanceof Error ? error.message : "Invalid wallpaper", 400)+ }+ })+uploads.use("/:file", async function (context, next) {const file = context.req.param("file")diff --git a/source/shared/wallpaper.ts b/source/shared/wallpaper.tsnew file mode 100644index 0000000..12d360d--- /dev/null+++ b/source/shared/wallpaper.ts@@ -0,0 +1,27 @@+/** Wallpaper sources accepted by the System-owned Appearance boundary. */+export type WallpaperKind = "image" | "video" | "html"++/** Applying a wallpaper is deliberately stricter than storing an upload. */+export const wallpaperSizeLimit = 50 * 1024 * 1024++const wallpaperKinds: Readonly<Record<string, WallpaperKind>> = {+ avif: "image",+ bmp: "image",+ gif: "image",+ jpeg: "image",+ jpg: "image",+ png: "image",+ svg: "image",+ webp: "image",+ mp4: "video",+ ogg: "video",+ ogv: "video",+ webm: "video",+ html: "html"+}++export function wallpaperKind(file: string): WallpaperKind | null {+ const extension = file.match(/\.([a-z0-9]+)$/i)?.[1]?.toLowerCase()++ return extension ? wallpaperKinds[extension] ?? null : null+}diff --git a/tests/appearance.test.ts b/tests/appearance.test.tsindex 5014dd2..837a64f 100644--- a/tests/appearance.test.ts+++ b/tests/appearance.test.ts@@ -4,10 +4,12 @@ import { defaultAppearance, parseAppearance } from "@phreshos/core"import AppearanceManager from "@server/core/appearance-manager"import FileManager from "@libs/file-manager"import UploadManager from "@server/core/upload-manager"-import { mkdtemp, rm } from "node:fs/promises"+import { mkdtemp, rm, truncate, writeFile } from "node:fs/promises"import { tmpdir } from "node:os"import { join } from "node:path"import { test } from "vitest"+import { randomUUID } from "node:crypto"+import { wallpaperSizeLimit } from "@shared/wallpaper"test("appearance contract", async () => {assert.deepEqual(parseAppearance(defaultAppearance), defaultAppearance)@@ -92,5 +94,30 @@ test("appearance contract", async () => {assert.equal(await store.get("appearance:colors"), undefined)assert.equal(await store.get("appearance:theme"), undefined)+ const wallpaperFiles = await Promise.all(["png", "webm", "html"].map(extension =>+ uploads.write(extension, new Blob(["wallpaper"]).stream())))++ for (const file of wallpaperFiles) {+ await manager.update({+ ...manager.value,+ desktopWallpaper: { ...manager.value.desktopWallpaper, light: file }+ })+ assert.equal(manager.value.desktopWallpaper.light, file)+ }++ const unsupported = await uploads.write("txt", new Blob(["wallpaper"]).stream())+ await assert.rejects(manager.update({+ ...manager.value,+ desktopWallpaper: { ...manager.value.desktopWallpaper, light: unsupported }+ }), /image, video, or HTML/)++ const oversized = `${randomUUID()}.html`+ await writeFile(uploads.path(oversized), "")+ await truncate(uploads.path(oversized), wallpaperSizeLimit + 1)+ await assert.rejects(manager.update({+ ...manager.value,+ desktopWallpaper: { ...manager.value.desktopWallpaper, light: oversized }+ }), /50 MiB/)+await rm(directory, { recursive: true, force: true })}, 120_000)diff --git a/tests/desktop-wallpaper.test.tsx b/tests/desktop-wallpaper.test.tsxindex f589bb6..b7ca252 100644--- a/tests/desktop-wallpaper.test.tsx+++ b/tests/desktop-wallpaper.test.tsx@@ -30,7 +30,7 @@ vi.mock("@client/view/structure/desktop/windows/process-window", () => ({}))test("Desktop replaces its default wallpaper with the running Client and restores the fallback after stop", () => {- const render = () => renderToStaticMarkup(<AppearanceProvider theme="light"><Workspace /></AppearanceProvider>)+ const render = () => renderToStaticMarkup(<AppearanceProvider preferences={{ theme: "light", animations: true }}><Workspace /></AppearanceProvider>)fixture.processes.clear()fixture.pane.mockClear()fixture.fallback.mockClear()diff --git a/tests/panel.test.tsx b/tests/panel.test.tsxindex 6d17d09..f416ee3 100644--- a/tests/panel.test.tsx+++ b/tests/panel.test.tsx@@ -23,7 +23,7 @@ test("panel contract", async () => {function markup(children: ReactNode) {return renderToStaticMarkup(<ApplicationContext.Provider value={application}>- <AppearanceProvider appearance={defaultAppearance} theme="light">{children}</AppearanceProvider>+ <AppearanceProvider appearance={defaultAppearance} preferences={{ theme: "light", animations: true }}>{children}</AppearanceProvider></ApplicationContext.Provider>)}diff --git a/tests/start-menu-search.test.tsx b/tests/start-menu-search.test.tsxindex f7944a1..4666591 100644--- a/tests/start-menu-search.test.tsx+++ b/tests/start-menu-search.test.tsx@@ -38,7 +38,7 @@ test("start menu search contract", async () => {assert(!matchesProcess(null, undefined, searchTerms("notes")))assert(!matchesProcess("daily draft", program, searchTerms("missing")))- const footer = renderToStaticMarkup(<AppearanceProvider appearance={defaultAppearance} theme="light"><SearchBar query="notes" onChange={() => {}} /></AppearanceProvider>)+ const footer = renderToStaticMarkup(<AppearanceProvider appearance={defaultAppearance} preferences={{ theme: "light", animations: true }}><SearchBar query="notes" onChange={() => {}} /></AppearanceProvider>)assert.match(footer, /<div class="react-aria-TextField"/)assert.match(footer, /<input\b/)diff --git a/tests/uploads.test.ts b/tests/uploads.test.tsindex 5d53e29..a7ee6fb 100644--- a/tests/uploads.test.ts+++ b/tests/uploads.test.ts@@ -66,6 +66,18 @@ test("uploads contract", async () => {assert.equal(downloaded.status, 200)assert.deepEqual(await described.json(), { size: created.size, modifiedAt: created.modifiedAt })assert.deepEqual(JSON.parse(await downloaded.text()), { ready: true })++ const htmlSource = "<!doctype html><script>document.body.textContent = 'offline wallpaper'</script>"+ const htmlFile = await uploads.write("html", new Blob([htmlSource]).stream())+ const wallpaper = await view.request(`http://system/uploads/wallpaper/${htmlFile}`)++ assert.equal(wallpaper.status, 200)+ assert.equal(wallpaper.headers.get("content-type"), "text/html; charset=utf-8")+ assert.match(wallpaper.headers.get("content-security-policy") ?? "", /connect-src 'none'/)+ assert.match(wallpaper.headers.get("content-security-policy") ?? "", /script-src 'unsafe-inline' data: blob:/)+ assert.match(wallpaper.headers.get("content-security-policy") ?? "", /sandbox allow-scripts/)+ assert.equal(await wallpaper.text(), htmlSource)+ assert.equal((await view.request(`http://system/uploads/wallpaper/${created.file}`)).status, 400)assert.equal((await view.request("http://system/uploads/not-a-key")).status, 400)assert.equal((await view.request("http://system/uploads/00000000-0000-0000-0000-000000000000.txt")).status, 404)} finally {diff --git a/tests/wallpaper-source.test.tsx b/tests/wallpaper-source.test.tsxnew file mode 100644index 0000000..fb28a73--- /dev/null+++ b/tests/wallpaper-source.test.tsx@@ -0,0 +1,45 @@+import assert from "node:assert/strict"+import { renderToStaticMarkup } from "react-dom/server"+import { AppearanceProvider } from "@phreshos/react-ui"+import { defaultAppearance } from "@phreshos/core"+import { ApplicationContext } from "@client/view/contexts"+import Application from "@client/core/application"+import { WallpaperBackground } from "@client/view/structure/desktop/wallpaper/wallpaper"+import { test } from "vitest"++test("wallpaper source contract", () => {+ const application = new Application("phreshos", "PhreshOS", "1.0.0", {+ link: "/link",+ proxy: "/proxy",+ storage: "/storage",+ uploads: "/uploads",+ program: "/program"+ })++ function render(file: string) {+ return renderToStaticMarkup(<ApplicationContext.Provider value={application}>+ <AppearanceProvider appearance={defaultAppearance} preferences={{ theme: "dark", animations: true }}>+ <WallpaperBackground file={file} />+ </AppearanceProvider>+ </ApplicationContext.Provider>)+ }++ const image = render("00000000-0000-0000-0000-000000000000.png")+ assert.match(image, /<img/)+ assert.match(image, /src="\/uploads\/00000000-0000-0000-0000-000000000000\.png"/)+ assert.match(image, /object-cover/)++ const video = render("00000000-0000-0000-0000-000000000000.webm")+ assert.match(video, /<video/)+ assert.match(video, /autoPlay=""/)+ assert.match(video, /loop=""/)+ assert.match(video, /muted=""/)+ assert.match(video, /playsInline=""/)++ const html = render("00000000-0000-0000-0000-000000000000.html")+ assert.match(html, /<iframe/)+ assert.match(html, /src="\/uploads\/wallpaper\/00000000-0000-0000-0000-000000000000\.html"/)+ assert.match(html, /sandbox="allow-scripts"/)+ assert.match(html, /referrerPolicy="no-referrer"/)+ assert.doesNotMatch(html, /allow-same-origin/)+})diff --git a/tsconfig.json b/tsconfig.jsonindex 5b51de4..e928b90 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -25,6 +25,9 @@],"@client/*": ["./source/client/*"+ ],+ "@shared/*": [+ "./source/shared/*"]}}