From 375d2d7db562ffdbac96e925d0d65c7255b76744 Mon Sep 17 00:00:00 2001 From: humuhumu33 <68450279+humuhumu33@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:02:57 +0000 Subject: [PATCH] Sealed workspace: keep undefined fields, leave gallery pictures plain, and two tests that read past the seal A record kept a key whose value is undefined, and modules check record shapes exactly: the codec now restores it. A gallery card's picture is a Blob, which cannot be read inside a transaction to be sealed, and the card is made to be published, so gallery refs stay plain. The settings fault injection keyed on the stored value, which is now sealed; it keys on the store and key. The gallery test read through the plain handle. Co-Authored-By: Claude Opus 5.5 --- studio/shell/inference.js | 18 +++++++++++++++--- .../tools/atomic_browser_settings_browser.mjs | 2 +- studio/tools/source_bound_gallery_browser.mjs | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/studio/shell/inference.js b/studio/shell/inference.js index d4a8e099..306a4096 100644 --- a/studio/shell/inference.js +++ b/studio/shell/inference.js @@ -85,7 +85,8 @@ export const prismFrame = (globalThis.__prismFrame ??= () => (globalThis.__prism // case once, as the workspace opens. Left plain: what the service worker reads (the grants and published // .holo bytes, public and addressed by their content) and the audit it writes. const SEALED = new Set(["settings", "apps", "chats", "files", "objects", "refs", "versions"]); -const plainPlace = (store, key) => !SEALED.has(store) || (store === "refs" && /^(capabilities|holo):/.test(key)); +// A gallery card is made to be published, and its picture is a Blob, which cannot be read inside a transaction. +const plainPlace = (store, key) => !SEALED.has(store) || (store === "refs" && /^(capabilities|holo|gallery):/.test(key)); const isSealed = (value) => value?.sealedWork instanceof Uint8Array; const word = (n) => [0, 8, 16, 24].map((shift) => ((n >>> shift) & 255).toString(16).padStart(2, "0")).join(""); export const workspaceRequest = (...words) => "workspace " + [1, ...words].map(word).join(""); @@ -98,9 +99,20 @@ const refusal = (code) => Object.assign(new Error(code), { code }); // including what was told before it mounted. export const tell = (answer) => { (globalThis.__workspaceTold ??= []).push(answer); window.dispatchEvent(new CustomEvent("foundry:workspace", { detail: answer })); }; const base64 = (bytes) => { let text = ""; for (let i = 0; i < bytes.length; i += 32768) text += String.fromCharCode(...bytes.subarray(i, i + 32768)); return btoa(text); }; -const encode = (value) => enc.encode(JSON.stringify(value, function (name, v) { const raw = this[name]; return raw instanceof Uint8Array ? { $bytes: base64(raw) } : raw instanceof Date ? { $date: v } : v; })); +// Values as JSON, as IndexedDB would keep them: bytes, dates and a key whose value is undefined are tagged, then +// restored by assignment, so the key stays (a reviver returning undefined would drop it). +const encode = (value) => enc.encode(JSON.stringify(value, function (name, v) { const raw = this[name]; return raw instanceof Uint8Array ? { $bytes: base64(raw) } : raw instanceof Date ? { $date: v } : raw === undefined ? { $undefined: 1 } : v; })); const unbase64 = (text) => Uint8Array.from(atob(text), (c) => c.charCodeAt(0)); -const decode = (bytes) => JSON.parse(new TextDecoder().decode(bytes), (name, v) => (v?.$bytes !== undefined ? unbase64(v.$bytes) : v?.$date !== undefined ? new Date(v.$date) : v)); +const tagged = (v, tag) => Object.keys(v).length === 1 && tag in v; +const restore = (v) => { + if (!v || typeof v !== "object") return v; + if (tagged(v, "$bytes")) return unbase64(v.$bytes); + if (tagged(v, "$date")) return new Date(v.$date); + if (tagged(v, "$undefined")) return undefined; + for (const k of Object.keys(v)) v[k] = restore(v[k]); + return v; +}; +const decode = (bytes) => restore(JSON.parse(new TextDecoder().decode(bytes))); const wrap = (target, own) => new Proxy(target, { get: (t, p) => (p in own ? own[p] : typeof t[p] === "function" ? t[p].bind(t) : t[p]), set: (t, p, v) => ((t[p] = v), true) }); let workspaceOpen = null; export const workspace = () => (workspaceOpen ??= openWorkspace()); diff --git a/studio/tools/atomic_browser_settings_browser.mjs b/studio/tools/atomic_browser_settings_browser.mjs index 0fa08b6c..33febeea 100644 --- a/studio/tools/atomic_browser_settings_browser.mjs +++ b/studio/tools/atomic_browser_settings_browser.mjs @@ -55,7 +55,7 @@ try { const before=await page.evaluate(()=>window.__host.get('settings','user')); const late=await page.evaluate(async()=>{ const put=IDBObjectStore.prototype.put;let injected=false; - IDBObjectStore.prototype.put=function(value,key){const q=put.call(this,value,key);if(this.name==='settings'&&key==='user'&&value.enableAppBlueprint===true){injected=true;q.addEventListener('success',()=>this.transaction.abort(),{once:true});}return q;}; + IDBObjectStore.prototype.put=function(value,key){const q=put.call(this,value,key);if(this.name==='settings'&&key==='user'&&!injected){injected=true;q.addEventListener('success',()=>this.transaction.abort(),{once:true});}return q;}; try{await window.electron.ipcRenderer.invoke('set-user-settings',{enableAppBlueprint:true});return {injected,code:null};}catch(e){return {injected,code:e.code};}finally{IDBObjectStore.prototype.put=put;} });assert.deepEqual(late,{injected:true,code:'settingsStorageFailed'});assert.deepEqual(await page.evaluate(()=>window.__host.get('settings','user')),before); await peer.reload();await peer.locator('[role=textbox]').waitFor();assert.equal((await peer.evaluate(()=>window.electron.ipcRenderer.invoke('get-user-settings'))).enableAppBlueprint,false); diff --git a/studio/tools/source_bound_gallery_browser.mjs b/studio/tools/source_bound_gallery_browser.mjs index 465b986e..d1583295 100644 --- a/studio/tools/source_bound_gallery_browser.mjs +++ b/studio/tools/source_bound_gallery_browser.mjs @@ -28,7 +28,7 @@ try { const context=await browser.newContext({serviceWorkers:'block'}),page=await context.newPage(),peer=await context.newPage(),errors=[]; for(const p of [page,peer])p.on('pageerror',e=>errors.push(e.message)); await context.route('**/*',r=>new URL(r.request().url()).origin===origin?r.continue():r.abort()); - const initialize=async p=>{await p.goto(base);await p.waitForFunction(()=>!!window.__host&&!!window.electron);await p.evaluate(async base=>{window.gallery=await import(base+'gallery-store.mjs');window.sourceModule=await import(base+'project-edit.mjs');window.database=await (await import(base+'inference.js')).db();},base);}; + const initialize=async p=>{await p.goto(base);await p.waitForFunction(()=>!!window.__host&&!!window.electron);await p.evaluate(async base=>{window.gallery=await import(base+'gallery-store.mjs');window.sourceModule=await import(base+'project-edit.mjs');window.database=await (await import(base+'inference.js')).workspace();},base);}; await initialize(page);await initialize(peer); const call=(channel,input)=>page.evaluate(({channel,input})=>window.electron.ipcRenderer.invoke(channel,input),{channel,input}); const make=async name=>(await call('create-app',{name,initialChatMode:'build'})).app.id;