Decode behavioral evidence with CORS and retire missing-source fixtures safely

This commit is contained in:
zsviczian committed 2026-10-30 05:38:39 +01:00
1 parent bebf652f50
commit 9b2874ba17
5 files changed
+81 -25

No files matched your search

+14
View File
@@ -3259,3 +3259,17 @@ remain strict pending maintainer classification; no production changes.
explicit maintainer decision, not a presumed fix. Next risk checks are dirty
migration and popout teardown on an approved host, Lucide idle, and two complete
matching-build repeats; physical mobile and other native OSes remain separate.
- 2026-10-30 (#3022): Current-host core sequence captures eight Markdown
verification failures: canvas pixel reads of vault-resource URLs lack CORS
opt-in. Native default/anonymous/fetched-blob comparison proves identical
resources decode correctly with CORS (PNG 4x2, two transparent/red/blue pixels;
SVG 8216 red and 6718 blue pixels). Corrected only the verifier to request
anonymous CORS before loading and create its canvas detached in the owning
document. No security bypass or version branch. Missing-asset setup also
deleted a source with its editor alive and required an incidental ENOENT log;
one context recovered with zero logs. Retire the editor first and remove that
error allowance, retaining all reference/recovery/pixel assertions and making
every unexpected console error fail. Two actual-helper regressions pass.
The first new-runtime run still has storms; no production change or exception
waiver. Focused native confirmation precedes another full attempt.
@@ -0,0 +1,58 @@
import assert from "node:assert/strict";
import test from "node:test";
import vm from "node:vm";
import { readFileSync } from "node:fs";
import ts from "typescript";
test("actual behavior decoder requests CORS before loading and never attaches a canvas to the workspace", async () => {
const text = readFileSync(new URL("./behaviorEnvironment.mjs", import.meta.url), "utf8");
const file = ts.createSourceFile("behaviorEnvironment.mjs", text, ts.ScriptTarget.Latest, true);
let initializer;
function visit(node) {
if (ts.isVariableDeclaration(node) && node.name.getText(file) === "decode") initializer = node.initializer;
ts.forEachChild(node, visit);
}
visit(file); assert.ok(initializer);
let image, requestedCORS, adopted = 0;
const created = [], revoked = [];
class Image {
naturalWidth = 4; naturalHeight = 2;
set src(value) { this.source = value; requestedCORS = this.crossOrigin; }
async decode() { assert.equal(requestedCORS, "anonymous"); }
}
const pixels = new Uint8ClampedArray([
255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,0,
255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,0,
]);
const canvas = { getContext: () => ({ drawImage(value) { image = value; }, getImageData: () => ({ data: pixels }) }) };
const fragment = { createEl(tag) { assert.equal(tag, "canvas"); return canvas; } };
const doc = { body: { createEl() { throw Error("Verification mutated the live layout"); } },
adoptNode(value) { assert.equal(value, fragment); adopted++; return value; } };
const decode = vm.runInNewContext(`(${initializer.getText(file)})`, {
win: { Image, URL: { createObjectURL(value) { created.push(value); return "blob:owned"; }, revokeObjectURL(value) { revoked.push(value); } } },
doc, createFragment: () => fragment, check: (value, label) => assert.ok(value, label),
});
for (const source of ["app://fixture/Transparency.png", { type: "image/png" }]) {
const result = await decode(source);
assert.equal(result.width, 4); assert.equal(result.height, 2);
assert.equal(result.red, 2); assert.equal(result.green, 2); assert.equal(result.blue, 2); assert.equal(result.transparent, 2);
}
assert.equal(image.crossOrigin, "anonymous"); assert.equal(adopted, 2);
assert.equal(created.length, 1); assert.deepEqual(revoked, ["blob:owned"]);
});
test("missing-source setup retires the old editor before deleting its file", async () => {
const text = readFileSync(new URL("./imageBehavior.mjs", import.meta.url), "utf8");
const start = text.indexOf("const drawing = view.file"), end = text.indexOf("const missing = current()", start);
assert.ok(start > 0 && end > start);
let retired = false, removed = false, opened = false;
const file = { path: "owned-drawing.md" }, asset = { path: "owned-source.svg" };
const leaf = { view: {}, async setViewState(state) { assert.equal(state.type, "empty"); retired = true; },
async openFile(value) { assert.equal(value, file); assert.equal(removed, true); opened = true; } };
const execute = vm.runInNewContext(`(async()=>{${text.slice(start, end)}})`, {
view: { file }, source: asset,
env: { leaf, async ready(value) { assert.equal(value, leaf); assert.equal(opened, true); } },
app: { vault: { async delete(value) { assert.equal(value, asset); assert.equal(retired, true, "Live file deletion creates an incidental loader race"); removed = true; } } },
});
await execute(); assert.equal(opened, true);
});
+4 -2
View File
@@ -402,10 +402,12 @@ export async function behaviorEnvironment(
url =
typeof source === "string" ? source : win.URL.createObjectURL(source);
try {
// Read the actual resource through its CORS contract, without a version branch.
image.crossOrigin = "anonymous";
image.src = url;
await image.decode();
const canvas = doc.body.createEl("canvas");
canvas.remove();
// Keep verification out of the observed workspace layout in every window.
const canvas = doc.adoptNode(createFragment()).createEl("canvas");
canvas.width = image.naturalWidth;
canvas.height = image.naturalHeight;
check(
+1 -23
View File
@@ -147,8 +147,8 @@ export async function exerciseImageBehavior(c, env, rows) {
ea = p.ea.getAPI(view);
const drawing = view.file,
reference = source.path;
await app.vault.delete(source);
await env.leaf.setViewState({ type: "empty", state: {} });
await app.vault.delete(source);
await env.leaf.openFile(drawing);
await env.ready(env.leaf);
view = env.leaf.view;
@@ -191,28 +191,6 @@ export async function exerciseImageBehavior(c, env, rows) {
edited,
restored,
missing: { imageIdRetained: true, referenceRetained: true },
expectedConsoleErrors: [
{
containsAll: [
'"value":"EmbeddedFileLoader._getObsidianImage"',
'"value":"' + reference + '"',
'"name":"depth","type":"number","value":"0"',
'"name":"code","type":"string","value":"ENOENT"',
'"name":"syscall","type":"string","value":"open"',
JSON.stringify({
name: "path",
type: "string",
value: require("node:path").join(
app.vault.adapter.getBasePath(),
reference,
),
}),
],
excludes: ["[preview truncated]"],
min: 1,
max: 1,
},
],
};
}
const markdown = await env.create(
+4
View File
@@ -2445,6 +2445,10 @@
"path": "scripts/testing/fullscreen.test.mjs",
"mode": "isolated-or-extracted"
},
{
"path": "scripts/testing/host/behaviorDecoding.test.mjs",
"mode": "isolated-or-extracted"
},
{
"path": "scripts/testing/host/browserDiagnostics.test.mjs",
"mode": "isolated-or-extracted"