From ea81733e84736648db69b687e46fd1b149b0b2fa Mon Sep 17 00:00:00 2001 From: 2witstudios <2witstudios@gmail.com> Date: Wed, 25 Nov 2026 22:00:04 -0600 Subject: [PATCH 01/34] fix(server): staging and the hourly sweep refuse an org's .viewswitcher/ or staging/ that is a link (ISSUE-29) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QyQdJ4G3VLsm4D1srj2oKF --- apps/server/src/library/contain.ts | 18 ++++++++ apps/server/src/packs.test.ts | 66 +++++++++++++++++++++++++++++- apps/server/src/packs.ts | 22 ++++++---- 3 files changed, 96 insertions(+), 10 deletions(-) diff --git a/apps/server/src/library/contain.ts b/apps/server/src/library/contain.ts index 80515b0..c1fc989 100644 --- a/apps/server/src/library/contain.ts +++ b/apps/server/src/library/contain.ts @@ -62,6 +62,24 @@ export async function resolveInLibrary(libraryRoot: string, clientPath: unknown, return abs; } +/** + * An org's staging folder (/.viewswitcher/staging), where template packs are unpacked before + * anyone says Install and which the hourly sweep clears, or a PathError. The org folder must really be + * in the library (it may be a link to another place in it), and neither .viewswitcher/ nor staging/ may + * be a link at all: a pack is written there and anything older than an hour deleted, so a link would + * aim both at wherever it points. Folders that aren't there yet are made by whoever writes. + */ +export async function stagingIn(libraryRoot: string, orgId: string): Promise { + let at = await resolveInLibrary(libraryRoot, orgId, { forWrite: true }); + for (const part of STAGING.split("/")) { + at = join(at, part); + const s = await lstat(at).catch(() => null); + // A link or a file where a folder should be: never followed, never replaced. + if (s && !s.isDirectory()) throw new PathError("The show's staging folder is a link or a file; packs are only unpacked into a plain folder in the library"); + } + return at; +} + /** * Where a library path really is (through links), as a library path, or the path itself when that * can't be told. Synchronous, for checks that must happen at one instant (the agents' on-air guard). diff --git a/apps/server/src/packs.test.ts b/apps/server/src/packs.test.ts index 5e8a2a9..52c396d 100644 --- a/apps/server/src/packs.test.ts +++ b/apps/server/src/packs.test.ts @@ -1,13 +1,13 @@ // Staging, installing and removing template packs on a real (temporary) // library, with the starter kit exported as a pack, and hostile packs that must leave nothing behind. import { afterEach, beforeEach, describe, expect, test } from "bun:test"; -import { cp, mkdir, mkdtemp, readdir, readFile, rename, rm, symlink, writeFile } from "node:fs/promises"; +import { cp, mkdir, mkdtemp, readdir, readFile, rename, rm, symlink, utimes, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join, resolve } from "node:path"; import { asDropped, buildBuiltins, readBuiltins } from "./builtin-packs"; import { addFromTemplate, createOrg, createProject } from "./library"; import { LibraryScanner } from "./library/scanner"; -import { cancelPack, installPack, PackError, removeSet, stagePack } from "./packs"; +import { cancelPack, installPack, PackError, removeSet, stagePack, sweepStaging } from "./packs"; import { SHOWS, SHOWS_DIR, showPacks, starterPack, writeZip, zipPack } from "@viewswitcher/packs"; const starter = resolve(import.meta.dir, "../starter"); @@ -313,3 +313,65 @@ describe("a templates/ folder linked outside the library", () => { } }); }); + +describe("an org's .viewswitcher/ or staging/ linked outside the library", () => { + const HOUR_AND_A_BIT = (Date.now() - 2 * 60 * 60 * 1000) / 1000; + /** A folder outside the library with an old file and an old folder in it, as a sweep would see them. */ + async function awayWithOldFiles() { + const away = await mkdtemp(join(tmpdir(), "vs-packs-away-")); + await mkdir(join(away, "staging/old-folder"), { recursive: true }); + await writeFile(join(away, "staging/old-file"), "keep me"); + await writeFile(join(away, "old-file"), "keep me"); + for (const p of ["staging/old-folder", "staging/old-file", "old-file", "staging"]) await utimes(join(away, p), HOUR_AND_A_BIT, HOUR_AND_A_BIT); + return away; + } + const outsideListing = (away: string) => listing(away); + + for (const [what, link] of [[".viewswitcher/", ".viewswitcher"], ["staging/", ".viewswitcher/staging"]] as const) { + test(`${what}: staging a pack is refused and writes nothing there; the sweep deletes nothing there`, async () => { + const away = await awayWithOldFiles(); + try { + const before = await outsideListing(away); + await rm(join(root, org, ".viewswitcher"), { recursive: true, force: true }); + await mkdir(join(root, org, ".viewswitcher"), { recursive: true }); + await rm(join(root, org, link), { recursive: true, force: true }); + await symlink(link === ".viewswitcher" ? away : join(away, "staging"), join(root, org, link)); + await expect(stagePack(root, org, { zip: starterZip }, await starterJs())).rejects.toThrow("link"); + await sweepStaging(root); + expect(await outsideListing(away)).toEqual(before); + expect(await readFile(join(away, "staging/old-file"), "utf8")).toBe("keep me"); + // Install and cancel with a token that would name a folder there touch nothing either. + const token = "a".repeat(24); + await mkdir(join(away, "staging", token), { recursive: true }); + await writeFile(join(away, "staging", token, "meta.json"), JSON.stringify({ org, set: "x", manifest: { id: "x" }, files: [], created: 0 })); + await expect(installPack(root, org, token)).rejects.toThrow("link"); + await cancelPack(root, org, token).catch(() => {}); + expect(await readFile(join(away, "staging", token, "meta.json"), "utf8")).toContain(org); + } finally { + await rm(away, { recursive: true, force: true }); + } + }); + } + + test("an org folder that is a link outside the library: the sweep leaves it alone", async () => { + const away = await awayWithOldFiles(); + try { + await mkdir(join(away, ".viewswitcher"), { recursive: true }); + await rename(join(away, "staging"), join(away, ".viewswitcher/staging")); + await symlink(away, join(root, "elsewhere")); + const before = await outsideListing(away); + await sweepStaging(root); + expect(await outsideListing(away)).toEqual(before); + } finally { + await rm(away, { recursive: true, force: true }); + } + }); + + test("a plain staging folder is still swept: a pack staged over an hour ago goes, a new one stays", async () => { + const old = await stagePack(root, org, { zip: starterZip }, await starterJs()); + const fresh = await stagePack(root, org, { zip: starterZip }, await starterJs()); + await utimes(join(root, org, ".viewswitcher/staging", old.token), HOUR_AND_A_BIT, HOUR_AND_A_BIT); + await sweepStaging(root); + expect(await readdir(join(root, org, ".viewswitcher/staging"))).toEqual([fresh.token]); + }); +}); diff --git a/apps/server/src/packs.ts b/apps/server/src/packs.ts index 4bc4797..80d5886 100644 --- a/apps/server/src/packs.ts +++ b/apps/server/src/packs.ts @@ -9,13 +9,13 @@ // 3. remove a set: delete its folder, unless scenes made from it still use its theme and pictures: // then only its views and pack.json go, so those scenes keep their look. import { createHash, randomBytes } from "node:crypto"; -import { mkdir, readdir, readFile, rename, rm, rmdir, stat, writeFile } from "node:fs/promises"; +import { lstat, mkdir, readdir, readFile, rename, rm, rmdir, writeFile } from "node:fs/promises"; import { dirname, join } from "node:path"; import { checkPack, fillPlaceholders, installedPath, isTextFile, libraryUrl, PACK_LIMITS, placeholderVars, planPack, readTitle } from "@viewswitcher/shared"; import type { PackEntry, PackFile, PackManifest, StagedPack } from "@viewswitcher/shared"; import { writeAtomic } from "./atomic"; import { exists, readOrg } from "./library"; -import { resolveInLibrary, STAGING, STAGING_TOKEN } from "./library/contain"; +import { resolveInLibrary, STAGING, STAGING_TOKEN, stagingIn } from "./library/contain"; import { limit } from "./limit"; import { inside, PathError, plainName } from "./paths"; import { listZip, readZipEntry, walkFiles, ZipError } from "@viewswitcher/packs"; @@ -31,7 +31,8 @@ export type PackSource = { zip: Uint8Array } | { files: { path: string; data: Bl type StageMeta = { org: string; set: string; manifest: PackManifest; files: string[]; created: number }; const tokenOk = (t: unknown): t is string => typeof t === "string" && STAGING_TOKEN.test(t); -const stageDir = (libraryRoot: string, orgId: string, token: string) => inside(libraryRoot, `${plainName(orgId)}/${STAGING}/${token}`); +/** A staged pack's folder: in the org's staging folder, which is never a link (contain.ts stagingIn). */ +const stageDir = async (libraryRoot: string, orgId: string, token: string) => inside(await stagingIn(libraryRoot, plainName(orgId)), token); /** A filesystem error, without the absolute path Node puts in its message (AGENTS.md: none in responses). */ function plainFsError(e: unknown, doing: string): Error { @@ -66,9 +67,12 @@ export async function sweepStaging(libraryRoot: string) { const now = Date.now(); for (const org of await readdir(libraryRoot).catch(() => [] as string[])) { if (org.startsWith(".")) continue; - const dir = join(libraryRoot, org, STAGING); + // An org (or its staging folder) that leads outside the library is left alone: nothing there is ours to delete. + const dir = await stagingIn(libraryRoot, org).catch(() => null); + if (!dir) continue; for (const name of await readdir(dir).catch(() => [] as string[])) { - const s = await stat(join(dir, name)).catch(() => null); + // lstat: a link in staging is judged (and removed) as the link, never followed. + const s = await lstat(join(dir, name)).catch(() => null); if (s && now - s.mtimeMs > STAGE_TTL_MS) await rm(join(dir, name), { recursive: true, force: true }); } } @@ -109,7 +113,9 @@ export async function stagePack(libraryRoot: string, orgId: string, source: Pack // 2. Unpack into staging (only the planned files, each checked to land inside it once more). const token = randomBytes(12).toString("hex"); - const dir = stageDir(libraryRoot, orgId, token); + const dir = await stageDir(libraryRoot, orgId, token).catch((e) => { + throw plainFsError(e, "Unpacking it"); + }); const raw = join(dir, "raw"); try { const texts: Record = {}; @@ -160,7 +166,7 @@ const hash = (s: string) => createHash("sha256").update(s.replace(/\r\n/g, "\n") /** Install a staged pack into its org as templates//. Returns the set's folder name. */ export async function installPack(libraryRoot: string, orgId: string, token: unknown): Promise<{ set: string }> { if (!tokenOk(token)) throw new PackError("That pack isn't ready to install any more. Drop it again."); - const dir = stageDir(libraryRoot, orgId, token); + const dir = await stageDir(libraryRoot, orgId, token); const meta = await readFile(join(dir, "meta.json"), "utf8").then((t) => JSON.parse(t) as StageMeta, () => null); if (!meta) throw new PackError("That pack isn't ready to install any more. Drop it again."); if (meta.org !== orgId) throw new PackError("That pack was checked for another show. Drop it again here."); @@ -196,7 +202,7 @@ export async function installPack(libraryRoot: string, orgId: string, token: unk } export async function cancelPack(libraryRoot: string, orgId: string, token: unknown) { - if (tokenOk(token)) await rm(stageDir(libraryRoot, orgId, token), { recursive: true, force: true }); + if (tokenOk(token)) await rm(await stageDir(libraryRoot, orgId, token), { recursive: true, force: true }); } /** Library-relative paths of the org's project scenes that link the set's files. */ From 3ac9accce9bb5ef52532c8b6e11608914b16ba68 Mon Sep 17 00:00:00 2001 From: 2witstudios <2witstudios@gmail.com> Date: Wed, 25 Nov 2026 22:01:44 -0600 Subject: [PATCH 02/34] fix(server): the library scan, org.json and a set's removal never read through a link out of the library (ISSUE-28) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QyQdJ4G3VLsm4D1srj2oKF --- apps/server/src/library-scan.test.ts | 59 +++++++++++++++++++++++++++ apps/server/src/library.ts | 6 ++- apps/server/src/library/scanner.ts | 60 +++++++++++++++++----------- apps/server/src/packs.test.ts | 14 +++++++ apps/server/src/packs.ts | 10 +++-- 5 files changed, 120 insertions(+), 29 deletions(-) diff --git a/apps/server/src/library-scan.test.ts b/apps/server/src/library-scan.test.ts index 3a5df1f..605781a 100644 --- a/apps/server/src/library-scan.test.ts +++ b/apps/server/src/library-scan.test.ts @@ -100,6 +100,65 @@ describe("LibraryScanner", () => { }); }); +describe("links out of the library are never read", () => { + let away: string; + beforeEach(async () => { + away = mkdtempSync(join(tmpdir(), "vs-scan-away-")); + roots.push(away); + await writeFile(join(away, "secret.html"), view("Outside secret")); + await writeFile(join(away, "secret.json"), JSON.stringify({ name: "Outside name", date: "2026-09-09", order: ["z"] })); + await writeFile(join(away, "secret.png"), "outside picture"); + await mkdir(join(away, "folder"), { recursive: true }); + await writeFile(join(away, "folder/inside.html"), view("Outside folder view")); + }); + const everything = async () => JSON.stringify(await scanner.scanOrg(ORG)); + + test("a view that is a link to a file outside is left out, and its title isn't read", async () => { + await symlink(join(away, "secret.html"), join(root, ORG, "projects/p/scenes/leak.html")); + await symlink(join(away, "secret.html"), join(root, ORG, "templates/leak.html")); + const l = await scanner.scanOrg(ORG); + expect(l.templates.map((t) => t.name)).toEqual(["title"]); + expect(l.projects[0]!.scenes.map((s) => s.name)).toEqual(["intro", "brb"]); + expect(await everything()).not.toContain("Outside"); + }); + + test("a view that is a link to another view in the library is listed with its title", async () => { + await symlink(join(root, ORG, "templates/title.html"), join(root, ORG, "projects/p/scenes/again.html")); + expect(await labels()).toContain("p/scenes/again.html=Title"); + }); + + test("folders, JSON files and pictures linked outside are left out too", async () => { + await symlink(join(away, "folder"), join(root, ORG, "projects/p/streams/a-linked")); + await rm(join(root, ORG, "projects/p/scenes"), { recursive: true }); + await symlink(join(away, "folder"), join(root, ORG, "projects/p/scenes")); + await rm(join(root, ORG, "projects/p/streams/b/stream.json")); + await symlink(join(away, "secret.json"), join(root, ORG, "projects/p/streams/b/stream.json")); + await put(`${ORG}/assets/logo.png`, "png"); + await symlink(join(away, "secret.png"), join(root, ORG, "assets/leak.png")); + await mkdir(join(root, ORG, "templates/neon"), { recursive: true }); + await symlink(join(away, "secret.json"), join(root, ORG, "templates/neon/pack.json")); + await rm(join(root, ORG, "org.json")); + await symlink(join(away, "secret.json"), join(root, ORG, "org.json")); + const l = await scanner.scanOrg(ORG); + expect(l.projects[0]!.scenes).toEqual([]); + expect(l.projects[0]!.streams.map((s) => `${s.id}=${s.name}`)).toEqual(["a=First", "b=b"]); + expect(l.assets.map((a) => a.name)).toEqual(["logo.png"]); + expect(l.sets).toEqual([]); + expect(l.org.name).toBe(ORG); + expect(await everything()).not.toContain("Outside"); + }); + + test("an org folder that is a link outside the library lists nothing from there", async () => { + await mkdir(join(away, "org/projects/p/scenes"), { recursive: true }); + await writeFile(join(away, "org/org.json"), JSON.stringify({ name: "Outside org" })); + await writeFile(join(away, "org/projects/p/scenes/x.html"), view("Outside view")); + await symlink(join(away, "org"), join(root, "linked")); + const l = await scanner.scanOrg("linked"); + expect(l.projects).toEqual([]); + expect(JSON.stringify(l)).not.toContain("Outside"); + }); +}); + describe("titledCopy (Duplicate)", () => { test("adds \" copy\" to the title, decoded and escaped again", () => { expect(titledCopy("R&B night")).toBe("R&B night copy"); diff --git a/apps/server/src/library.ts b/apps/server/src/library.ts index 729a0ba..b282e08 100644 --- a/apps/server/src/library.ts +++ b/apps/server/src/library.ts @@ -19,8 +19,10 @@ import { inside, PathError, plainName } from "./paths"; const ORG_DEFAULTS = { accent: "#8b7bff", ground: "#0e0f13" }; export async function readOrg(libraryRoot: string, id: string): Promise { - const dir = inside(libraryRoot, plainName(id)); - const meta = await readJson(join(dir, "org.json"), { name: id, ...ORG_DEFAULTS }); + const fallback = { name: id, ...ORG_DEFAULTS }; + // An org.json that is a link outside the library isn't read (contain.ts): the org reads as unnamed. + const file = await resolveInLibrary(libraryRoot, `${plainName(id)}/org.json`).catch(() => null); + const meta = file ? await readJson(file, fallback) : fallback; return { id, name: meta.name, accent: meta.accent, ground: meta.ground }; } diff --git a/apps/server/src/library/scanner.ts b/apps/server/src/library/scanner.ts index 7e73948..99da078 100644 --- a/apps/server/src/library/scanner.ts +++ b/apps/server/src/library/scanner.ts @@ -5,17 +5,24 @@ // and dropped for the paths the watcher reports (scene-titles.ts); folders are walked side by side. // File reads and stats go through one bounded queue, so a big library can't run out of open files. // +// Nothing outside the library is read, even through a link (contain.ts, the rule every read follows): +// a folder the scan reads, a JSON file, or a view or picture that is a link is checked first, and one +// that leads outside is left out. Plain files in a folder that's inside are inside, so most files cost +// no extra check. +// // The cache and the queue belong to one LibraryScanner, which main.ts makes and hands to the // switcher's routes and the MCP server, so both share them and their lifetime is the server's; a // test makes its own and shares nothing with another. +import type { Dirent } from "node:fs"; import { readdir, readFile, stat } from "node:fs/promises"; -import { extname, join } from "node:path"; +import { extname, join, relative, sep } from "node:path"; import { isViewFile, ORG_TRANSITION, readManifest, TRANSITION_FILE as TRANSITION } from "@viewswitcher/shared"; import type { Asset, AssetKind, OrgContent, Project, Scene, SceneOrigin, Stream, TemplateSet } from "@viewswitcher/shared"; import { exists, readOrg } from "../library"; import { limit } from "../limit"; import { inside, plainName } from "../paths"; import { createSceneTitles } from "../scene-titles"; +import { resolveInLibrary } from "./contain"; import { dirs as listDirs, type Io, readJson as readJsonFile } from "./read"; const KINDS: Record = { @@ -46,27 +53,33 @@ export class LibraryScanner { const prefix = `${orgId}/`; // readOrg's id is the one asked for, so nothing waits for org.json const [org, templates, sets, assets, projects, transition] = await Promise.all([ readOrg(this.libraryRoot, orgId), - this.readJson(join(orgDir, "templates/_shared/order.json"), { order: [] as string[] }).then((meta) => this.scenesIn(orgDir, "templates", "template", meta.order, prefix)), + this.readJson(orgDir, "templates/_shared/order.json", { order: [] as string[] }).then((meta) => this.scenesIn(orgDir, "templates", "template", meta.order, prefix)), this.listSets(orgDir, prefix), this.listAssets(orgDir, prefix), - this.dirs(join(orgDir, "projects")).then((ids) => Promise.all(ids.map((id) => this.scanProject(orgDir, prefix, id)))), - this.urlIfThere(join(orgDir, ORG_TRANSITION), `${prefix}${ORG_TRANSITION}`), + this.dirs(orgDir, "projects").then((ids) => Promise.all(ids.map((id) => this.scanProject(orgDir, prefix, id)))), + this.urlIfThere(orgDir, ORG_TRANSITION, `${prefix}${ORG_TRANSITION}`), ]); return { org, templates, sets, assets, projects, transition }; } - private dirs = (path: string) => listDirs(path, this.io); - private readJson = (path: string, fallback: T) => readJsonFile(path, fallback, this.io); - /** `url` when the file `abs` is there, else null (a transition, for the library listing). */ - private urlIfThere = (abs: string, url: string) => this.io(() => exists(abs)).then((t) => (t ? url : null)); + /** Whether `rel` in the org folder `orgDir` is really in the library, through any links (contain.ts). */ + private inLibrary = (orgDir: string, rel: string) => + this.io(() => resolveInLibrary(this.libraryRoot, `${relative(this.libraryRoot, orgDir).split(sep).join("/")}/${rel}`)).then(() => true, () => false); + /** The folders the library lists in `rel`, when `rel` itself is in the library (a listed folder is never a link: isDirectory). */ + private dirs = async (orgDir: string, rel: string) => ((await this.inLibrary(orgDir, rel)) ? listDirs(join(orgDir, rel), this.io) : []); + /** The entries of the folder `rel`, when it's in the library; none when it isn't or can't be read. */ + private entries = async (orgDir: string, rel: string): Promise => + (await this.inLibrary(orgDir, rel)) ? this.io(() => readdir(join(orgDir, rel), { withFileTypes: true })).catch(() => []) : []; + /** Entries of a folder that's inside the library: a plain file is inside too; a link is checked. */ + private kept = (orgDir: string, rel: string, e: Dirent) => (e.isSymbolicLink() ? this.inLibrary(orgDir, `${rel}/${e.name}`) : Promise.resolve(true)); + private readJson = async (orgDir: string, rel: string, fallback: T) => ((await this.inLibrary(orgDir, rel)) ? readJsonFile(join(orgDir, rel), fallback, this.io) : fallback); + /** `url` when the file `rel` is there, in the library, else null (a transition, for the library listing). */ + private urlIfThere = async (orgDir: string, rel: string, url: string) => + (await this.io(() => exists(join(orgDir, rel)))) && (await this.inLibrary(orgDir, rel)) ? url : null; private async scenesIn(orgDir: string, rel: string, origin: SceneOrigin, order: string[], prefix: string, set?: string): Promise { - let files: string[] = []; - try { - files = (await this.io(() => readdir(join(orgDir, rel)))).filter(isViewFile); - } catch { - return []; - } + const listed = (await this.entries(orgDir, rel)).filter((e) => isViewFile(e.name) && !e.isDirectory()); + const files = (await Promise.all(listed.map(async (e) => ((await this.kept(orgDir, rel, e)) ? e.name : null)))).filter((f): f is string => f !== null); const scenes = await Promise.all( files.map(async (f) => { const name = f.slice(0, -5); @@ -81,7 +94,8 @@ export class LibraryScanner { private async listAssets(orgDir: string, prefix: string): Promise { try { - const names = (await this.io(() => readdir(join(orgDir, "assets")))).filter((n) => !n.startsWith(".")); + const listed = (await this.entries(orgDir, "assets")).filter((e) => !e.name.startsWith(".")); + const names = (await Promise.all(listed.map(async (e) => ((await this.kept(orgDir, "assets", e)) ? e.name : null)))).filter((n): n is string => n !== null); const assets = await Promise.all( names.map(async (name) => { // One that's gone since the listing (a replace, a delete, a broken link) is left out, not the rest with it. @@ -96,20 +110,19 @@ export class LibraryScanner { } private async scanProject(orgDir: string, prefix: string, id: string): Promise { - const dir = join(orgDir, "projects", id); - const p = await this.readJson(join(dir, "project.json"), { name: id, order: [] as string[] }); + const p = await this.readJson(orgDir, `projects/${id}/project.json`, { name: id, order: [] as string[] }); const [scenes, streams, transition] = await Promise.all([ this.scenesIn(orgDir, `projects/${id}/scenes`, "project", p.order, prefix), - this.dirs(join(dir, "streams")).then((ids) => + this.dirs(orgDir, `projects/${id}/streams`).then((ids) => Promise.all( ids.map(async (sid): Promise => { const rel = `projects/${id}/streams/${sid}`; - const [s, scenes] = await Promise.all([this.readJson(join(orgDir, rel, "stream.json"), { name: sid, date: "" }), this.scenesIn(orgDir, rel, "stream", p.order, prefix)]); + const [s, scenes] = await Promise.all([this.readJson(orgDir, `${rel}/stream.json`, { name: sid, date: "" }), this.scenesIn(orgDir, rel, "stream", p.order, prefix)]); return { id: sid, name: s.name, date: s.date, scenes }; }), ), ), - this.urlIfThere(join(dir, TRANSITION), `${prefix}projects/${id}/${TRANSITION}`), + this.urlIfThere(orgDir, `projects/${id}/${TRANSITION}`, `${prefix}projects/${id}/${TRANSITION}`), ]); streams.sort((a, b) => (a.date || a.id).localeCompare(b.date || b.id)); return { id, name: p.name, scenes, streams, transition }; @@ -121,8 +134,9 @@ export class LibraryScanner { /** The org's template sets: folders in templates/ that have a pack.json. */ private async listSets(orgDir: string, prefix: string): Promise { const found = await Promise.all( - (await this.dirs(join(orgDir, "templates"))).map(async (id): Promise => { - const text = await this.io(() => readFile(join(orgDir, "templates", id, "pack.json"), "utf8")).catch(() => null); + (await this.dirs(orgDir, "templates")).map(async (id): Promise => { + const manifest = `templates/${id}/pack.json`; + const text = (await this.inLibrary(orgDir, manifest)) ? await this.io(() => readFile(join(orgDir, manifest), "utf8")).catch(() => null) : null; if (text === null) return null; const read = readManifest(text); // A pack.json someone edited by hand into something odd: still list the set, by its folder. @@ -130,7 +144,7 @@ export class LibraryScanner { const rel = `templates/${id}`; const [templates, transition] = await Promise.all([ this.scenesIn(orgDir, rel, "template", m.views, prefix, id), - this.urlIfThere(join(orgDir, rel, "_shared", TRANSITION), `${prefix}${rel}/_shared/${TRANSITION}`), + this.urlIfThere(orgDir, `${rel}/_shared/${TRANSITION}`, `${prefix}${rel}/_shared/${TRANSITION}`), ]); return { id, name: m.name, version: m.version, description: m.description, ...("author" in m && m.author ? { author: m.author } : {}), templates, transition }; }), diff --git a/apps/server/src/packs.test.ts b/apps/server/src/packs.test.ts index 52c396d..0cda089 100644 --- a/apps/server/src/packs.test.ts +++ b/apps/server/src/packs.test.ts @@ -222,6 +222,20 @@ describe("removing a set", () => { expect(await readFile(join(root, org, "templates/starter/_shared/theme.css"), "utf8")).toContain("--accent"); }); + test("a scene that is a link outside the library isn't read to count it", async () => { + await installPack(root, org, (await stagePack(root, org, { zip: starterZip }, null)).token); + const { projectId } = await createProject(join(root, org), "Show", ["starter/teaching"]); + const away = await mkdtemp(join(tmpdir(), "vs-packs-away-")); + try { + const real = join(root, org, "projects", projectId, "scenes/teaching.html"); + await rename(real, join(away, "teaching.html")); + await symlink(join(away, "teaching.html"), real); + expect(await removeSet(root, org, "starter")).toEqual({ kept: 0 }); + } finally { + await rm(away, { recursive: true, force: true }); + } + }); + test("refuses what isn't a set", async () => { await expect(removeSet(root, org, "_shared")).rejects.toThrow(); await expect(removeSet(root, org, "../projects")).rejects.toThrow(); diff --git a/apps/server/src/packs.ts b/apps/server/src/packs.ts index 80d5886..57f720f 100644 --- a/apps/server/src/packs.ts +++ b/apps/server/src/packs.ts @@ -206,15 +206,17 @@ export async function cancelPack(libraryRoot: string, orgId: string, token: unkn } /** Library-relative paths of the org's project scenes that link the set's files. */ -async function scenesUsing(orgDir: string, orgId: string, set: string): Promise { +async function scenesUsing(libraryRoot: string, orgDir: string, orgId: string, set: string): Promise { // As written by hand or by the switcher: plain, or with each segment encoded (libraryUrl). const needle = `/library/${orgId}/templates/${set}/`; const encoded = `${libraryUrl(`${orgId}/templates/${set}`)}/`; const projects = join(orgDir, "projects"); const read = limit(16); // scenes can be megabytes: read side by side, but not all at once - // Linked scenes too: a scene that is a link still uses the set through it. + // Linked scenes too: a scene that is a link still uses the set through it. One that leads outside the library isn't read (contain.ts). const scenes = (await walkFiles(projects, { links: true }).catch(() => [] as string[])).filter((rel) => rel.endsWith(".html")); - const uses = await Promise.all(scenes.map((rel) => read(() => readFile(join(projects, rel), "utf8").catch(() => "")).then((t) => t.includes(needle) || t.includes(encoded)))); + const textOf = (rel: string) => + resolveInLibrary(libraryRoot, `${plainName(orgId)}/projects/${rel}`).then((abs) => readFile(abs, "utf8")).catch(() => ""); + const uses = await Promise.all(scenes.map((rel) => read(() => textOf(rel)).then((t) => t.includes(needle) || t.includes(encoded)))); return uses.filter(Boolean).length; } @@ -228,7 +230,7 @@ export async function removeSet(libraryRoot: string, orgId: string, set: string) // What it deletes must really be in the library, not wherever a linked templates/ leads. await resolveInLibrary(libraryRoot, `${plainName(orgId)}/templates/${plainName(set)}`, { forWrite: true }); if (!(await exists(join(dir, "pack.json")))) throw new PathError("That isn't an installed template set"); - const kept = await scenesUsing(orgDir, orgId, set); + const kept = await scenesUsing(libraryRoot, orgDir, orgId, set); if (kept === 0) { await rm(dir, { recursive: true, force: true }); return { kept }; From 96957d55fe8f060f83ab2bd5247c76148d4e2132 Mon Sep 17 00:00:00 2001 From: 2witstudios <2witstudios@gmail.com> Date: Wed, 25 Nov 2026 22:03:01 -0600 Subject: [PATCH 03/34] =?UTF-8?q?fix(web,server):=20the=20Orgs=20show's=20?= =?UTF-8?q?library=20has=20its=20own=20cache=20key;=20the=20SIGTERM=20remo?= =?UTF-8?q?val=20test=20picks=20the=20device=20it=20paired=20(ISSUE-25=20?= =?UTF-8?q?=C2=B7=20ISSUE-23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QyQdJ4G3VLsm4D1srj2oKF --- apps/server/src/remote.test.ts | 12 +++++++++--- apps/web/src/lib/library.test.ts | 23 +++++++++++++++++++++++ apps/web/src/lib/library.ts | 14 ++++++++++++-- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 apps/web/src/lib/library.test.ts diff --git a/apps/server/src/remote.test.ts b/apps/server/src/remote.test.ts index 07dcbc4..c8dc8b6 100644 --- a/apps/server/src/remote.test.ts +++ b/apps/server/src/remote.test.ts @@ -227,11 +227,17 @@ describe.skipIf(!ip)(`over the Wi-Fi (${ip})`, () => { }); test("a removal survives quitting right after it (SIGTERM, as the Mac app quits)", async () => { + // The device this pairing added, as the one id that wasn't there before: earlier tests paired + // phones with the same name, and their times can tie with this one's to the millisecond. + const ids = async () => ((await admin("/api/remote")).devices as { id: string }[]).map((d) => d.id); + const before = new Set(await ids()); const { code } = (await admin("/api/remote/code", {})) as { code: { code: string } }; const lost = cookieOf(await pairWith(code.code)); - const { devices } = await admin("/api/remote"); - const id = devices.find((d: { name: string; lastSeen: number }) => d.name === "Test phone" && d.lastSeen === Math.max(...devices.map((x: { lastSeen: number }) => x.lastSeen))).id; - await admin("/api/remote/remove", { id }); + const added = (await ids()).filter((id) => !before.has(id)); + expect(added).toHaveLength(1); + expect((await lan("/api/state", { headers: { cookie: lost } })).status).toBe(200); + await admin("/api/remote/remove", { id: added[0] }); + expect((await lan("/api/state", { headers: { cookie: lost } })).status).toBe(401); proc.kill("SIGTERM"); await proc.exited; await start(); diff --git a/apps/web/src/lib/library.test.ts b/apps/web/src/lib/library.test.ts new file mode 100644 index 0000000..178e201 --- /dev/null +++ b/apps/web/src/lib/library.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, test } from "bun:test"; +import { QueryClient } from "@tanstack/react-query"; +import { libraryKeys } from "./library"; + +describe("the library's cache keys", () => { + test("a show whose id is \"orgs\" keeps its library apart from the list of shows", async () => { + const client = new QueryClient(); + await client.fetchQuery({ queryKey: libraryKeys.orgs, queryFn: async () => ["the list of shows"] }); + await client.fetchQuery({ queryKey: libraryKeys.org("orgs"), queryFn: async () => ["the Orgs show's library"] }); + expect(client.getQueryData(libraryKeys.orgs)).toEqual(["the list of shows"]); + expect(client.getQueryData(libraryKeys.org("orgs"))).toEqual(["the Orgs show's library"]); + }); + + test("every id gets its own key, and all of them are refreshed with the library", async () => { + const ids = ["orgs", "org", "library", "daisy", ""]; + const keys = [libraryKeys.orgs, ...ids.map(libraryKeys.org)].map((k) => JSON.stringify(k)); + expect(new Set(keys).size).toBe(keys.length); + const client = new QueryClient(); + for (const id of ids) await client.fetchQuery({ queryKey: libraryKeys.org(id), queryFn: async () => id }); + await client.invalidateQueries({ queryKey: ["library"] }); + expect(ids.every((id) => client.getQueryState(libraryKeys.org(id))?.isInvalidated)).toBe(true); + }); +}); diff --git a/apps/web/src/lib/library.ts b/apps/web/src/lib/library.ts index 03cd961..6f6c0ff 100644 --- a/apps/web/src/lib/library.ts +++ b/apps/web/src/lib/library.ts @@ -3,8 +3,18 @@ import { useQuery } from "@tanstack/react-query"; import { useParams } from "@tanstack/react-router"; import { api } from "./api"; +/** + * The cache keys for what the server's library holds. Each kind has its own place in the key, so no + * org id can name another kind ("orgs" is a fine name for a show). Everything is under "library", + * which a change to the library refreshes as one. + */ +export const libraryKeys = { + orgs: ["library", "orgs"] as const, + org: (id: string | undefined) => ["library", "org", id] as const, +}; + export function useOrgs() { - return useQuery({ queryKey: ["library", "orgs"], queryFn: api.orgs }); + return useQuery({ queryKey: libraryKeys.orgs, queryFn: api.orgs }); } /** The org in the URL (/$org/...), if any. */ @@ -13,7 +23,7 @@ export function useOrgId(): string | undefined { } export function useLibrary(org: string | undefined) { - return useQuery({ queryKey: ["library", org], queryFn: () => api.library(org!), enabled: !!org }); + return useQuery({ queryKey: libraryKeys.org(org), queryFn: () => api.library(org!), enabled: !!org }); } const LAST_ORG = "viewswitcher.org"; From 0da1dc0e5c03119dc9486f95f85754320d0bebd5 Mon Sep 17 00:00:00 2001 From: 2witstudios <2witstudios@gmail.com> Date: Wed, 25 Nov 2026 22:04:38 -0600 Subject: [PATCH 04/34] fix(server): a new org is filled in staging and renamed into place; the sweep clears the library's staging too (ISSUE-31) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QyQdJ4G3VLsm4D1srj2oKF --- apps/server/src/library-org.test.ts | 90 +++++++++++++++++++++++++++++ apps/server/src/library.ts | 60 ++++++++++++++----- apps/server/src/library/contain.ts | 14 ++++- apps/server/src/packs.ts | 13 +++-- 4 files changed, 154 insertions(+), 23 deletions(-) create mode 100644 apps/server/src/library-org.test.ts diff --git a/apps/server/src/library-org.test.ts b/apps/server/src/library-org.test.ts new file mode 100644 index 0000000..cf8e638 --- /dev/null +++ b/apps/server/src/library-org.test.ts @@ -0,0 +1,90 @@ +// A new org from the starter kit, on a real (temporary) library: it appears whole, filled in for +// its name, or not at all. +import { afterEach, beforeEach, describe, expect, test } from "bun:test"; +import { mkdir, mkdtemp, readdir, readFile, rm, symlink } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join, resolve } from "node:path"; +import { createOrg, listOrgs } from "./library"; + +const starter = resolve(import.meta.dir, "../starter"); +let root = ""; +const dirs: string[] = []; +beforeEach(async () => { + root = await mkdtemp(join(tmpdir(), "vs-org-")); + dirs.push(root); +}); +afterEach(async () => { + for (const d of dirs.splice(0)) await rm(d, { recursive: true, force: true }); +}); +const staged = () => readdir(join(root, ".viewswitcher/staging")).catch(() => [] as string[]); + +describe("createOrg", () => { + test("fills the starter in for the org and leaves nothing in staging", async () => { + const { orgId } = await createOrg(root, starter, "R&B Night"); + expect(orgId).toBe("r-b-night"); + const ending = await readFile(join(root, orgId, "templates/ending.html"), "utf8"); + expect(ending).toContain("R&B Night"); + expect(ending).toContain(`/library/${orgId}/templates/_shared/`); + expect(ending).not.toContain("{{"); + expect(JSON.parse(await readFile(join(root, orgId, "org.json"), "utf8")).name).toBe("R&B Night"); + expect((await readdir(join(root, orgId))).sort()).toEqual(expect.arrayContaining(["assets", "org.json", "projects", "templates"])); + expect(await staged()).toEqual([]); + expect((await listOrgs(root)).map((o) => o.id)).toEqual([orgId]); + }); + + test("the org appears whole: while it's made, its folder never shows a placeholder or half the starter", async () => { + let done = false; + const seen = new Set(); + const watcher = (async () => { + while (!done) { + for (const id of await readdir(root).catch(() => [] as string[])) { + if (id.startsWith(".")) continue; + const files = await readdir(join(root, id)).catch(() => [] as string[]); + seen.add(files.length === 0 ? "empty" : files.includes("org.json") && files.includes("templates") ? "whole" : `partial:${files.join(",")}`); + const ending = await readFile(join(root, id, "templates/ending.html"), "utf8").catch(() => ""); + if (ending.includes("{{")) seen.add("placeholder"); + } + await Bun.sleep(0); + } + })(); + for (let i = 0; i < 5; i++) await createOrg(root, starter, `Show ${i}`); + done = true; + await watcher; + expect([...seen].filter((s) => s !== "empty" && s !== "whole")).toEqual([]); + }); + + test("the same name twice at once: two orgs, each filled with its own id", async () => { + const [a, b] = await Promise.all([createOrg(root, starter, "Daisy"), createOrg(root, starter, "Daisy")]); + expect([a.orgId, b.orgId].sort()).toEqual(["daisy", "daisy-2"]); + for (const id of [a.orgId, b.orgId]) expect(await readFile(join(root, id, "org.json"), "utf8")).not.toContain("{{"); + expect(await staged()).toEqual([]); + }); + + test("a dangling link where the org would go: the next name, nothing written through it", async () => { + const away = await mkdtemp(join(tmpdir(), "vs-org-away-")); + dirs.push(away); + await symlink(join(away, "nowhere"), join(root, "daisy")); + expect((await createOrg(root, starter, "Daisy")).orgId).toBe("daisy-2"); + expect(await readdir(away)).toEqual([]); + }); + + test("a create that fails leaves nothing behind", async () => { + await expect(createOrg(root, join(root, "no-starter-here"), "Daisy")).rejects.toThrow(); + expect((await readdir(root)).filter((n) => !n.startsWith("."))).toEqual([]); + expect(await staged()).toEqual([]); + }); + + test("the library's .viewswitcher/ linked outside: refused, nothing written there", async () => { + const away = await mkdtemp(join(tmpdir(), "vs-org-away-")); + dirs.push(away); + await symlink(away, join(root, ".viewswitcher")); + await expect(createOrg(root, starter, "Daisy")).rejects.toThrow("link"); + expect(await readdir(away)).toEqual([]); + await rm(join(root, ".viewswitcher")); + await mkdir(join(root, ".viewswitcher")); + await symlink(away, join(root, ".viewswitcher/staging")); + await expect(createOrg(root, starter, "Daisy")).rejects.toThrow("link"); + expect(await readdir(away)).toEqual([]); + expect((await readdir(root)).filter((n) => !n.startsWith("."))).toEqual([]); + }); +}); diff --git a/apps/server/src/library.ts b/apps/server/src/library.ts index b282e08..2b1de7f 100644 --- a/apps/server/src/library.ts +++ b/apps/server/src/library.ts @@ -1,11 +1,12 @@ import { constants as fsConstants } from "node:fs"; -import { copyFile, cp, lstat, mkdir, readFile, rm, stat, writeFile } from "node:fs/promises"; +import { randomBytes } from "node:crypto"; +import { copyFile, cp, lstat, mkdir, readFile, rename, rm, rmdir, stat, writeFile } from "node:fs/promises"; import { dirname, extname, join, relative } from "node:path"; import { fillPlaceholders, graphemes, isTextFile, ORG_TRANSITION, parseTemplateId, placeholderVars, readTitle, setTitle, slugify, TRANSITION_FILE as TRANSITION, transitionCandidates } from "@viewswitcher/shared"; import type { Org } from "@viewswitcher/shared"; import { walkFiles } from "@viewswitcher/packs"; import { writeAtomic } from "./atomic"; -import { resolveInLibrary } from "./library/contain"; +import { libraryStaging, resolveInLibrary } from "./library/contain"; import { dirs, readJson } from "./library/read"; import { inside, PathError, plainName } from "./paths"; @@ -33,26 +34,57 @@ export async function listOrgs(libraryRoot: string): Promise { return orgs.sort((a, b) => a.name.localeCompare(b.name)); } -/** A new org from the starter kit: neutral templates that use the org's own name and colors. */ +/** + * A new org from the starter kit: neutral templates that use the org's own name and colors. It's + * filled in a staging folder and renamed into place, so the watcher and a client scanning meanwhile + * never see raw {{ORG_NAME}} placeholders or half an org; a create that fails leaves nothing behind. + */ export async function createOrg(libraryRoot: string, starter: string, name: string, accent = ORG_DEFAULTS.accent, ground = ORG_DEFAULTS.ground) { if (!name?.trim()) throw new PathError("A show needs a name"); const base = slugify(name); - let id = base, n = 2; - while (await exists(join(libraryRoot, id))) id = `${base}-${n++}`; - const dir = join(libraryRoot, id); - await cp(starter, dir, { recursive: true }); - const vars = placeholderVars({ id, name, accent, ground }); + const staging = await libraryStaging(libraryRoot); + await mkdir(staging, { recursive: true }); + const work = join(staging, randomBytes(12).toString("hex")); + try { + for (let n = 1; ; n++) { + const id = n === 1 ? base : `${base}-${n}`; + const dir = join(libraryRoot, id); + if (await taken(dir)) continue; // a dangling link counts: copying through it could land anywhere + // The org id goes into its files ({{ORG_ID}}), so an id taken meanwhile is filled again for the next. + await rm(work, { recursive: true, force: true }); + await fillStarter(starter, work, placeholderVars({ id, name, accent, ground })); + // Claim the name first: mkdir without recursive fails if the folder appeared meanwhile (two + // creates at once, an agent), where rename alone would quietly replace an empty one. + try { + await mkdir(dir); + } catch (e) { + if ((e as NodeJS.ErrnoException).code === "EEXIST") continue; + throw e; + } + await rename(work, dir).catch(async (e) => { + await rmdir(dir).catch(() => {}); // only if still empty: never someone else's files + throw e; + }); + return { orgId: id }; + } + } finally { + await rm(work, { recursive: true, force: true }); + } +} + +/** The starter kit copied to `dest` with every text file filled in, plus the empty folders an org has. */ +async function fillStarter(starter: string, dest: string, vars: ReturnType) { + await cp(starter, dest, { recursive: true }); await Promise.all( - (await walkFiles(dir)).filter(isTextFile).map(async (rel) => { - const p = join(dir, rel); + (await walkFiles(dest)).filter(isTextFile).map(async (rel) => { + const p = join(dest, rel); const text = await readFile(p, "utf8"); const filled = fillPlaceholders(rel, text, vars); - if (filled !== text) await writeAtomic(p, filled); + if (filled !== text) await writeFile(p, filled); }), ); - await mkdir(join(dir, "assets"), { recursive: true }); - await mkdir(join(dir, "projects"), { recursive: true }); - return { orgId: id }; + await mkdir(join(dest, "assets"), { recursive: true }); + await mkdir(join(dest, "projects"), { recursive: true }); } // ---------------------------------------------------------------- templates diff --git a/apps/server/src/library/contain.ts b/apps/server/src/library/contain.ts index c1fc989..ebb2707 100644 --- a/apps/server/src/library/contain.ts +++ b/apps/server/src/library/contain.ts @@ -69,13 +69,21 @@ export async function resolveInLibrary(libraryRoot: string, clientPath: unknown, * be a link at all: a pack is written there and anything older than an hour deleted, so a link would * aim both at wherever it points. Folders that aren't there yet are made by whoever writes. */ -export async function stagingIn(libraryRoot: string, orgId: string): Promise { - let at = await resolveInLibrary(libraryRoot, orgId, { forWrite: true }); +export const stagingIn = async (libraryRoot: string, orgId: string): Promise => plainStaging(await resolveInLibrary(libraryRoot, orgId, { forWrite: true })); + +/** + * The library's own staging folder (/.viewswitcher/staging), where a new org is filled in + * before it's renamed into place; the same rule as an org's (no links), or a PathError. + */ +export const libraryStaging = (libraryRoot: string): Promise => plainStaging(libraryRoot); + +async function plainStaging(dir: string): Promise { + let at = dir; for (const part of STAGING.split("/")) { at = join(at, part); const s = await lstat(at).catch(() => null); // A link or a file where a folder should be: never followed, never replaced. - if (s && !s.isDirectory()) throw new PathError("The show's staging folder is a link or a file; packs are only unpacked into a plain folder in the library"); + if (s && !s.isDirectory()) throw new PathError("A staging folder (.viewswitcher/staging) is a link or a file; the switcher only stages into a plain folder in the library"); } return at; } diff --git a/apps/server/src/packs.ts b/apps/server/src/packs.ts index 57f720f..073a768 100644 --- a/apps/server/src/packs.ts +++ b/apps/server/src/packs.ts @@ -15,7 +15,7 @@ import { checkPack, fillPlaceholders, installedPath, isTextFile, libraryUrl, PAC import type { PackEntry, PackFile, PackManifest, StagedPack } from "@viewswitcher/shared"; import { writeAtomic } from "./atomic"; import { exists, readOrg } from "./library"; -import { resolveInLibrary, STAGING, STAGING_TOKEN, stagingIn } from "./library/contain"; +import { libraryStaging, resolveInLibrary, STAGING, STAGING_TOKEN, stagingIn } from "./library/contain"; import { limit } from "./limit"; import { inside, PathError, plainName } from "./paths"; import { listZip, readZipEntry, walkFiles, ZipError } from "@viewswitcher/packs"; @@ -62,13 +62,14 @@ async function fillCopy(raw: string, dest: string, files: string[], vars: Return } } -/** Clear staged packs older than an hour (a closed tab never cancels its own). */ +/** Clear staged packs (and new orgs) older than an hour: a closed tab never cancels its own, a crash never finishes. */ export async function sweepStaging(libraryRoot: string) { const now = Date.now(); - for (const org of await readdir(libraryRoot).catch(() => [] as string[])) { - if (org.startsWith(".")) continue; - // An org (or its staging folder) that leads outside the library is left alone: nothing there is ours to delete. - const dir = await stagingIn(libraryRoot, org).catch(() => null); + const orgs = (await readdir(libraryRoot).catch(() => [] as string[])).filter((org) => !org.startsWith(".")); + // Each org's, and the library's own (a new org being filled in, library.ts createOrg). One that + // leads outside the library is left alone: nothing there is ours to delete. + const folders = [libraryStaging(libraryRoot), ...orgs.map((org) => stagingIn(libraryRoot, org))]; + for (const dir of await Promise.all(folders.map((f) => f.catch(() => null)))) { if (!dir) continue; for (const name of await readdir(dir).catch(() => [] as string[])) { // lstat: a link in staging is judged (and removed) as the link, never followed. From 1e9340d82b77fcd30e69bca2a041509a12bbde01 Mon Sep 17 00:00:00 2001 From: 2witstudios <2witstudios@gmail.com> Date: Wed, 25 Nov 2026 22:05:34 -0600 Subject: [PATCH 05/34] fix(server): a hand-edited settings.json is followed while the server runs, so the agents' guard is too (ISSUE-18) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QyQdJ4G3VLsm4D1srj2oKF --- apps/server/src/main.ts | 7 +++- apps/server/src/settings-follow.test.ts | 46 +++++++++++++++++++++++++ apps/server/src/settings.ts | 16 +++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 apps/server/src/settings-follow.test.ts diff --git a/apps/server/src/main.ts b/apps/server/src/main.ts index baa357f..4ec4bd9 100644 --- a/apps/server/src/main.ts +++ b/apps/server/src/main.ts @@ -25,7 +25,7 @@ import { sweepStaging } from "./packs"; import { Pairing, sha3, tokenCookie, tokenFromCookie } from "./pairing"; import { createPreviewer } from "./preview"; import { pathScrub } from "./scrub"; -import { readSettings } from "./settings"; +import { followSettings, readSettings } from "./settings"; import { createSlotOrder } from "./slot-order"; import { startUsbBridge, usbAvailable } from "./usb-bridge"; @@ -168,9 +168,14 @@ let changed = new Set(); const serverRun = crypto.randomUUID(); let librarySeq = 0; let flushTimer: ReturnType | undefined; +// settings.json changed outside the switcher (by hand, a git checkout): agents follow what it says now. +const settingsChanged = followSettings(config.library, (s) => { + if (s.agentOnAir !== state.agent.onAir) store.update({ agent: { ...state.agent, onAir: s.agentOnAir } }); +}); watch(config.library, { recursive: true }, (_event, filename) => { if (!filename) return; const rel = filename.split(sep).join("/"); + if (rel === ".viewswitcher" || rel === ".viewswitcher/settings.json") settingsChanged(); if (rel.startsWith(".git") || rel.startsWith(".viewswitcher") || rel.includes("/.") || rel.endsWith("~")) return; changed.add(rel); clearTimeout(flushTimer); diff --git a/apps/server/src/settings-follow.test.ts b/apps/server/src/settings-follow.test.ts new file mode 100644 index 0000000..8b03c0c --- /dev/null +++ b/apps/server/src/settings-follow.test.ts @@ -0,0 +1,46 @@ +// settings.json edited by hand while the real server runs (from source, OBS offline, no USB, a temp +// library): the agent on-air setting in live state, which the agents' guard reads, follows the file. +import { afterAll, beforeAll, expect, test } from "bun:test"; +import type { Subprocess } from "bun"; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { freePort, SERVER_START_MS, startServer } from "./test-server"; + +let port = 0; +let proc: Subprocess; +const library = mkdtempSync(join(tmpdir(), "vs-settings-")); +const file = join(library, ".viewswitcher/settings.json"); +const onAir = async () => ((await (await fetch(`http://127.0.0.1:${port}/api/state`)).json()) as { agent: { onAir: string } }).agent.onAir; +/** The setting once it reads `want`, or what it still read after 10 s. */ +async function settlesOn(want: string) { + let now = ""; + for (const end = Date.now() + 10_000; Date.now() < end; await Bun.sleep(50)) if ((now = await onAir()) === want) break; + return now; +} + +beforeAll(async () => { + port = await freePort(); + proc = await startServer({ PORT: String(port), OBS_URL: "ws://127.0.0.1:1", VIEWSWITCHER_USB: "0", VIEWSWITCHER_LIBRARY: library, VIEWSWITCHER_ORIGINS: "", VIEWSWITCHER_PARENT_PID: "" }, () => + fetch(`http://127.0.0.1:${port}/api/state`).then((r) => r.ok), + ); +}, SERVER_START_MS); +afterAll(() => { + proc?.kill(); + rmSync(library, { recursive: true, force: true }); +}); + +test("a hand edit is followed: a choice, a file that can't be read (Never), the file gone (the default)", async () => { + expect(await onAir()).toBe("not-live"); + mkdirSync(join(library, ".viewswitcher"), { recursive: true }); + writeFileSync(file, JSON.stringify({ agentOnAir: "always" })); + expect(await settlesOn("always")).toBe("always"); + writeFileSync(file, "{ not json"); + expect(await settlesOn("never")).toBe("never"); + writeFileSync(file, JSON.stringify({ agentOnAir: "not-live", other: 1 })); + expect(await settlesOn("not-live")).toBe("not-live"); + writeFileSync(file, JSON.stringify({ agentOnAir: "always" })); + expect(await settlesOn("always")).toBe("always"); + rmSync(file); + expect(await settlesOn("not-live")).toBe("not-live"); +}, 60_000); diff --git a/apps/server/src/settings.ts b/apps/server/src/settings.ts index 456c622..b67b4e2 100644 --- a/apps/server/src/settings.ts +++ b/apps/server/src/settings.ts @@ -67,4 +67,20 @@ export function writeSettings(root: string, patch: Partial): Promise void, delayMs = 100): () => void { + let timer: ReturnType | undefined; + return () => { + clearTimeout(timer); + timer = setTimeout(() => { + const run = queue.then(async () => apply(await readSettings(root))); + queue = run.catch((e) => console.error("[settings]", (e as Error).message)); + }, delayMs); + }; +} + export class SettingsError extends Error {} From 09e0932ba2dc216fdb20ecb159cc342458a6c8d5 Mon Sep 17 00:00:00 2001 From: 2witstudios <2witstudios@gmail.com> Date: Wed, 25 Nov 2026 22:10:39 -0600 Subject: [PATCH 06/34] =?UTF-8?q?fix(apple):=20each=20build=20has=20its=20?= =?UTF-8?q?own=20server=20log,=20the=20ad=20hoc=20build=20passes=20its=20h?= =?UTF-8?q?ardened-runtime=20check,=20Kit=20builds=20clean=20in=20Swift=20?= =?UTF-8?q?6=20mode=20in=20CI=20(ISSUE-20=20=C2=B7=20ISSUE-19=20=C2=B7=20I?= =?UTF-8?q?SSUE-17)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QyQdJ4G3VLsm4D1srj2oKF --- .github/workflows/ci.yml | 4 +++ .../ViewSwitcherKit/ServerController.swift | 22 ++++++++++-- .../ServerControllerTests.swift | 13 +++++++ apps/apple/Mac/Environment.swift | 3 +- apps/apple/scripts/build.sh | 5 +-- apps/apple/scripts/e2e.ts | 5 +++ apps/apple/scripts/sign-check.sh | 11 ++++++ apps/apple/scripts/sign-check.test.ts | 34 +++++++++++++++++++ 8 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 apps/apple/scripts/sign-check.sh create mode 100644 apps/apple/scripts/sign-check.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d8b044..79c4087 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,5 +46,9 @@ jobs: - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 with: bun-version-file: .bun-version + # Swift 6 language mode makes a possible data race (a captured var mutated from another + # thread, say) a build error, where the package's own mode only warns. + - run: swift build --build-tests -Xswiftc -swift-version -Xswiftc 6 -Xswiftc -warnings-as-errors + working-directory: apps/apple/Kit - run: swift test working-directory: apps/apple/Kit diff --git a/apps/apple/Kit/Sources/ViewSwitcherKit/ServerController.swift b/apps/apple/Kit/Sources/ViewSwitcherKit/ServerController.swift index d69abd6..711476e 100644 --- a/apps/apple/Kit/Sources/ViewSwitcherKit/ServerController.swift +++ b/apps/apple/Kit/Sources/ViewSwitcherKit/ServerController.swift @@ -55,6 +55,22 @@ public struct Launch: Sendable { } } +/// The installed app's bundle id: its server log is the one people (and support) look for. +public let releaseBundleID = "com.twowitstudios.viewswitcher.mac" + +/// Where this build's server log goes, so builds never share one: the installed app's is +/// ~/Library/Logs/ViewSwitcher/server.log; another build of the app (Debug's `.mac.dev`) gets its own +/// file beside it (server-dev.log); an end-to-end run writes into its own folder. Sharing one would +/// mix their lines in Show Server Log, and a run's capLog could start the installed app's log over. +public func serverLogFile(home: URL, bundleID: String?, e2eDir: URL?) -> URL { + if let e2eDir { return e2eDir.appendingPathComponent("server.log") } + let logs = home.appendingPathComponent("Library/Logs/ViewSwitcher") + guard let id = bundleID, id != releaseBundleID else { return logs.appendingPathComponent("server.log") } + let suffix = id.hasPrefix(releaseBundleID + ".") ? String(id.dropFirst(releaseBundleID.count + 1)) : id + let safe = suffix.map { $0.isLetter || $0.isNumber || $0 == "." || $0 == "-" ? $0 : "-" } + return logs.appendingPathComponent("server-\(String(safe)).log") +} + public enum ServerError: LocalizedError, Equatable { case portTaken(String) case startFailed(String) @@ -245,8 +261,10 @@ func processFacts(_ pid: Int32) -> ProcessFacts? { let size = Int32(MemoryLayout.size) guard proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &info, size) == size else { return nil } var buf = [CChar](repeating: 0, count: Int(MAXPATHLEN) * 4) - guard proc_pidpath(pid, &buf, UInt32(buf.count)) > 0 else { return nil } - return ProcessFacts(path: String(cString: buf), uid: info.pbi_uid, ppid: info.pbi_ppid) + let length = proc_pidpath(pid, &buf, UInt32(buf.count)) + guard length > 0 else { return nil } + let path = String(decoding: buf.prefix(Int(length)).map { UInt8(bitPattern: $0) }, as: UTF8.self) + return ProcessFacts(path: path, uid: info.pbi_uid, ppid: info.pbi_ppid) } /// Whether `pid` is a leftover of the server this app launches: that same executable, run by this diff --git a/apps/apple/Kit/Tests/ViewSwitcherKitTests/ServerControllerTests.swift b/apps/apple/Kit/Tests/ViewSwitcherKitTests/ServerControllerTests.swift index a6f3196..c52cdef 100644 --- a/apps/apple/Kit/Tests/ViewSwitcherKitTests/ServerControllerTests.swift +++ b/apps/apple/Kit/Tests/ViewSwitcherKitTests/ServerControllerTests.swift @@ -357,5 +357,18 @@ final class ServerControllerTests: XCTestCase { capLog(log, max: 1000) XCTAssertEqual(try Data(contentsOf: log).count, 0, "a big log starts over") } + + func testEachBuildHasItsOwnServerLog() { + let home = URL(fileURLWithPath: "/Users/someone") + let logs = "/Users/someone/Library/Logs/ViewSwitcher/" + XCTAssertEqual(serverLogFile(home: home, bundleID: releaseBundleID, e2eDir: nil).path, logs + "server.log", "the installed app") + XCTAssertEqual(serverLogFile(home: home, bundleID: releaseBundleID + ".dev", e2eDir: nil).path, logs + "server-dev.log", "bun run mac:dev") + XCTAssertEqual(serverLogFile(home: home, bundleID: nil, e2eDir: nil).path, logs + "server.log") + XCTAssertEqual(serverLogFile(home: home, bundleID: "org.example/odd", e2eDir: nil).path, logs + "server-org.example-odd.log", "never a path out of the folder") + let e2e = URL(fileURLWithPath: "/tmp/vs-e2e-control") + XCTAssertEqual(serverLogFile(home: home, bundleID: releaseBundleID, e2eDir: e2e).path, "/tmp/vs-e2e-control/server.log", "an end-to-end run, whatever its build") + let all = [serverLogFile(home: home, bundleID: releaseBundleID, e2eDir: nil), serverLogFile(home: home, bundleID: releaseBundleID + ".dev", e2eDir: nil), serverLogFile(home: home, bundleID: releaseBundleID, e2eDir: e2e)] + XCTAssertEqual(Set(all).count, all.count) + } } #endif diff --git a/apps/apple/Mac/Environment.swift b/apps/apple/Mac/Environment.swift index ad724f6..ffd8875 100644 --- a/apps/apple/Mac/Environment.swift +++ b/apps/apple/Mac/Environment.swift @@ -11,7 +11,8 @@ enum Env { static var e2e: Bool { e2eDir != nil } static let updatesEnabled = vars["VIEWSWITCHER_UPDATES"] != "0" static let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "0" - static let logFile = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Library/Logs/ViewSwitcher/server.log") + /// This build's own server log (serverLogFile): the installed app's, Debug's or an e2e run's. + static let logFile = serverLogFile(home: FileManager.default.homeDirectoryForCurrentUser, bundleID: Bundle.main.bundleIdentifier, e2eDir: e2eDir) /// A new secret each launch, for the pairing endpoints only this app may call (apps/server: /api/remote…). /// It goes to the server in its environment and never leaves this Mac. static let adminToken: String = { diff --git a/apps/apple/scripts/build.sh b/apps/apple/scripts/build.sh index d26f9e9..0dbd79e 100755 --- a/apps/apple/scripts/build.sh +++ b/apps/apple/scripts/build.sh @@ -185,8 +185,9 @@ has() { local out; out="$("${@:2}" 2>&1 || true)"; [[ "$out" == *"$1"* ]]; } has "x86_64 arm64" lipo -archs "$APP/Contents/MacOS/ViewSwitcher" || { echo "the app isn't universal" >&2; exit 1; } has "x86_64 arm64" lipo -archs "$APP/Contents/Helpers/viewswitcher-server" || { echo "the sidecar isn't universal" >&2; exit 1; } has "com.apple.security.cs.allow-jit" codesign -d --entitlements - --xml "$APP/Contents/Helpers/viewswitcher-server" || { echo "the sidecar lost its allow-jit entitlement" >&2; exit 1; } -has "flags=0x10000(runtime)" codesign -dv "$APP/Contents/Helpers/viewswitcher-server" || { echo "the sidecar isn't on the hardened runtime" >&2; exit 1; } -has "flags=0x10000(runtime)" codesign -dv "$APP" || { echo "the app isn't on the hardened runtime" >&2; exit 1; } +source "$APPLE/scripts/sign-check.sh" +hardened_runtime "$APP/Contents/Helpers/viewswitcher-server" || { echo "the sidecar isn't on the hardened runtime" >&2; exit 1; } +hardened_runtime "$APP" || { echo "the app isn't on the hardened runtime" >&2; exit 1; } if [ -n "$IDENTITY" ]; then has "TeamIdentifier=$TEAM" codesign -dv "$APP" || { echo "the app isn't signed by $TEAM" >&2; exit 1; } has "TeamIdentifier=$TEAM" codesign -dv "$APP/Contents/Helpers/viewswitcher-server" || { echo "the sidecar isn't signed by $TEAM" >&2; exit 1; } diff --git a/apps/apple/scripts/e2e.ts b/apps/apple/scripts/e2e.ts index a8166f6..0cba8c9 100644 --- a/apps/apple/scripts/e2e.ts +++ b/apps/apple/scripts/e2e.ts @@ -195,6 +195,11 @@ try { const o = (await state()).opened; return o.includes(`${BASE}/`) && o.some((p) => resolve(p) === resolve(library) || p.endsWith(library.split("/").pop()!)); }, 5000), "menu bar: Open in Browser and Open Library Folder"); + // This run's server log is its own, never the installed app's (~/Library/Logs/ViewSwitcher/server.log). + const ownLog = join(control, "server.log"); + check(existsSync(ownLog) && readFileSync(ownLog, "utf8").includes("[viewswitcher]"), "the server logs into this run's own folder"); + await cmd("menu", { item: "Show Server Log" }); + check(await until(async () => (await state()).opened.includes(ownLog), 5000), "Show Server Log opens this run's log"); // ------------------------------------------------------------ the page may change things; other sites may not const fromPage = await evalJs(`return (await fetch("/api/onair", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ path: ${JSON.stringify(orgScene)}, label: "Be right back" }) })).status`); diff --git a/apps/apple/scripts/sign-check.sh b/apps/apple/scripts/sign-check.sh new file mode 100644 index 0000000..4ced4c7 --- /dev/null +++ b/apps/apple/scripts/sign-check.sh @@ -0,0 +1,11 @@ +# Checks build.sh runs on what it signed. Sourced; also sourced by sign-check.test.ts. + +# Whether the code at is signed for the hardened runtime: the runtime bit (0x10000) of its +# code directory's flags, whatever else is set beside it. A Developer ID signature reads +# flags=0x10000(runtime), an ad hoc one (mac:build --unsigned) flags=0x10002(adhoc,runtime). +hardened_runtime() { + local out flags + out="$(codesign -dv "$1" 2>&1 || true)" + flags="$(sed -n 's/.*CodeDirectory .*flags=0x\([0-9a-fA-F]*\).*/\1/p' <<<"$out" | head -1)" + [ -n "$flags" ] && (( (16#$flags & 16#10000) != 0 )) +} diff --git a/apps/apple/scripts/sign-check.test.ts b/apps/apple/scripts/sign-check.test.ts new file mode 100644 index 0000000..b42a2cf --- /dev/null +++ b/apps/apple/scripts/sign-check.test.ts @@ -0,0 +1,34 @@ +// sign-check.sh's hardened-runtime check on real code signatures (copies of /usr/bin/true, signed +// here), run through macOS's own bash (3.2), as build.sh runs it. +import { afterAll, describe, expect, test } from "bun:test"; +import { copyFileSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; + +const check = join(import.meta.dir, "sign-check.sh"); +const dir = mkdtempSync(join(tmpdir(), "vs-sign-")); +afterAll(() => rmSync(dir, { recursive: true, force: true })); +const canSign = process.platform === "darwin" && Bun.which("codesign") !== null; + +/** A copy of /usr/bin/true signed ad hoc with `options`; its path. */ +function signed(name: string, options: string[]) { + const path = join(dir, name); + copyFileSync("/usr/bin/true", path); + const r = Bun.spawnSync(["codesign", "--force", ...options, "--sign", "-", path]); + if (r.exitCode !== 0) throw new Error(r.stderr.toString()); + return path; +} +const hardened = (path: string) => Bun.spawnSync(["/bin/bash", "-c", `source "${check}"; hardened_runtime "$1"`, "_", path]).exitCode === 0; + +describe.skipIf(!canSign)("hardened_runtime", () => { + test("an ad hoc signature on the hardened runtime (mac:build --unsigned) passes", () => { + expect(hardened(signed("adhoc-runtime", ["--options", "runtime"]))).toBe(true); + }); + test("a signature without the runtime fails, and so does unsigned or missing code", () => { + expect(hardened(signed("adhoc", []))).toBe(false); + expect(hardened(join(dir, "nothing-here"))).toBe(false); + const plain = join(dir, "plain.txt"); + writeFileSync(plain, "not code"); + expect(hardened(plain)).toBe(false); + }); +}); From aa655eb5821ba07e9d26d4442203211444fdfaa9 Mon Sep 17 00:00:00 2001 From: 2witstudios <2witstudios@gmail.com> Date: Wed, 25 Nov 2026 22:12:06 -0600 Subject: [PATCH 07/34] =?UTF-8?q?feat(shared):=20checkPack=20warns=20about?= =?UTF-8?q?=20a=20show's=20name=20or=20initial=20in=20a=20script,=20a=20st?= =?UTF-8?q?yle,=20an=20on=E2=80=A6=20attribute=20or=20a=20.js=20file=20(IS?= =?UTF-8?q?SUE-30)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QyQdJ4G3VLsm4D1srj2oKF --- docs/template-packs.md | 2 +- packages/shared/src/template-pack.test.ts | 21 ++++++++++++ packages/shared/src/template-pack.ts | 39 +++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/docs/template-packs.md b/docs/template-packs.md index 7c6ea54..5b0cf49 100644 --- a/docs/template-packs.md +++ b/docs/template-packs.md @@ -64,7 +64,7 @@ Every `.html`, `.css`, `.js`, `.json`, `.svg`, `.md` and `.txt` file is filled i Anything else in `{{LIKE_THIS}}` stays as typed (with a warning). -Values are escaped for the file they land in: in `.html` and `.svg` they're HTML-escaped (a show named `R&B ` reads as text and can't add markup), in `.json` they're escaped for a JSON string, in `.css` only `*/` is broken up (so a value can't close a comment), and elsewhere (`.js`, `.md`, `.txt`) they're as typed. So in a view, put `{{ORG_NAME}}` in text or an attribute, not inside an inline ``, + "_shared/scene.js": `document.title = "{{ORG_NAME}}";`, + })); + if (!r.ok) throw new Error(r.error); + const w = r.warnings.find((x) => x.includes("in a script, a style or an on… attribute")); + expect(w).toBeDefined(); + expect(w).toStartWith("{{ORG_NAME}}, {{ORG_INITIAL}} are in a script"); + for (const where of ["templates/main.html

{{ORG_NAME}}

{{ORG_INITIAL}}`, + "_shared/scene.js": `fetch("{{PACK}}/_shared/data.json");`, + })); + expect(r.ok && r.warnings.filter((x) => x.includes("in a script"))).toEqual([]); + }); + test("javascript: links count as code", () => { const r = checkPack(planned(basic), texts({ "templates/main.html": `x` })); expect(r.ok && r.scripts.inline).toEqual(["templates/main.html"]); diff --git a/packages/shared/src/template-pack.ts b/packages/shared/src/template-pack.ts index c8631c1..d2cc79b 100644 --- a/packages/shared/src/template-pack.ts +++ b/packages/shared/src/template-pack.ts @@ -275,6 +275,35 @@ function remoteScripts(html: string): string[] { return out; } +/** + * The placeholders whose value is free text a person typed (a show's name and its initial), which + * can hold quotes, "&" or "<". The others are a slug, a color or a URL the switcher makes, which + * read the same in any of these places. + */ +const TEXT_PLACEHOLDERS: readonly PackPlaceholder[] = ["ORG_NAME", "ORG_INITIAL"]; + +/** + * Text placeholders in code: an inline `, + "templates/main.html": `

{{ORG_NAME}}

y

`, "_shared/scene.js": `document.title = "{{ORG_NAME}}";`, })); if (!r.ok) throw new Error(r.error); - const w = r.warnings.find((x) => x.includes("in a script, a style or an on… attribute")); + const w = r.warnings.find((x) => x.includes("in a script, a style, or an on… or style attribute")); expect(w).toBeDefined(); expect(w).toStartWith("{{ORG_NAME}}, {{ORG_INITIAL}} are in a script"); - for (const where of ["templates/main.html

{{ORG_NAME}}

{{ORG_INITIAL}}`, + "templates/main.html": `

{{ORG_NAME}}

{{ORG_INITIAL}}`, "_shared/scene.js": `fetch("{{PACK}}/_shared/data.json");`, })); expect(r.ok && r.warnings.filter((x) => x.includes("in a script"))).toEqual([]); diff --git a/packages/shared/src/template-pack.ts b/packages/shared/src/template-pack.ts index d2cc79b..4fe6b65 100644 --- a/packages/shared/src/template-pack.ts +++ b/packages/shared/src/template-pack.ts @@ -283,7 +283,7 @@ function remoteScripts(html: string): string[] { const TEXT_PLACEHOLDERS: readonly PackPlaceholder[] = ["ORG_NAME", "ORG_INITIAL"]; /** - * Text placeholders in code: an inline `, "_shared/scene.js": `fetch("{{PACK}}/_shared/data.json");`, + "_shared/theme.css": `/* {{ORG_NAME}}, made for the show */ :root { --accent: {{ACCENT}} }`, })); expect(r.ok && r.warnings.filter((x) => x.includes("in a script"))).toEqual([]); }); diff --git a/packages/shared/src/template-pack.ts b/packages/shared/src/template-pack.ts index 4fe6b65..5c4836c 100644 --- a/packages/shared/src/template-pack.ts +++ b/packages/shared/src/template-pack.ts @@ -283,7 +283,8 @@ function remoteScripts(html: string): string[] { const TEXT_PLACEHOLDERS: readonly PackPlaceholder[] = ["ORG_NAME", "ORG_INITIAL"]; /** - * Text placeholders in code: an inline