Await Markdown image test cleanup and add host-only migration control

This commit is contained in:
zsviczian committed 2026-10-29 22:53:42 +01:00
1 parent 4199a3dd38
commit 9cb6c5eb1f
9 files changed
+172 -9

No files matched your search

+12
View File
@@ -3224,3 +3224,15 @@ remain strict pending maintainer classification; no production changes.
retirement steps to distinguish pending native cleanup from a product loop.
Existing delays, actions, assertions and deadlines remain unchanged pending
evidence. Focused image/web-drop predecessor reproduction is next.
- 2026-10-29 (#3022): Read-only native evidence at 4199a3dd proves the crop
helper retires its drawing with a live Markdown-image owner; the non-crop
helper's 100-ms sample has already released ownership. Replaced only this
test overlap with bounded ownership/persistence completion, including error
cleanup and a preserve-unsettled-work deadline regression. Existing geometry,
crop, save/reopen/export assertions remain. Both migration routes after the
full desktop predecessors pass, while the preceding reproduction captures
four direct-route illegal-access exceptions. Cause remains intermittent and
unproven. Added one bounded six-cycle host-only Markdown control with both
community runtimes unloaded, outside acceptance coverage. No installer,
production behavior, observer or diagnostic exclusion changed.
+6 -6
View File
@@ -1,6 +1,7 @@
/** #3014/#2947: real formula bounds and resized Markdown sidepanel edits. */
import { runLegacyTask } from "./legacyTask.mjs";
import { exerciseMarkdownCrop } from "./markdownImageCrop.mjs";
import { closeMarkdownImageTab } from "./markdownImageClose.mjs";
const CONTROL = "__excalidrawImageGeometry";
@@ -77,6 +78,7 @@ async function exerciseMarkdown(control, drawingPath) {
const c = globalThis[control], plugin = app.plugins.plugins["obsidian-excalidraw-plugin"];
const leaf = app.workspace.getLeavesOfType("excalidraw").find(l => l.view.file?.path === drawingPath);
const view = leaf.view, doc = view.ownerDocument;
c.editorView = view;
c.previous = app.workspace.activeLeaf;
if (doc.querySelector(".excalidraw-markdown-image-editor .cm-content")) throw Error("close the existing Markdown-image editor before testing");
const waitFor = async (predicate, label) => {
@@ -145,11 +147,9 @@ async function exerciseMarkdown(control, drawingPath) {
await setContent("Shorter shared content");
const sharedBounds = checkSharedWidth();
c.results.push({ kind: "markdown-shared-width", copies: 2, previousWidth, nextWidth, displayed: sharedBounds, fileId: image.fileId });
c.tab.close(); c.tab = null;
const closeEvidence = { kind: "markdown-image-close-evidence", afterSignal: { active: view.sameFileEditGate.hasActiveOwners, grace: view.sameFileEditGate.isInGracePeriod, saving: view.isSaveInProgress() } };
const closeEvidence = { kind: "markdown-image-close-evidence", beforeClose: { active: view.sameFileEditGate.hasActiveOwners, grace: view.sameFileEditGate.isInGracePeriod, saving: view.isSaveInProgress() } };
c.results.push(closeEvidence);
await new Promise(resolve => setTimeout(resolve, 100));
closeEvidence.after100ms = { active: view.sameFileEditGate.hasActiveOwners, grace: view.sameFileEditGate.isInGracePeriod, saving: view.isSaveInProgress() };
await closeMarkdownImageTab(c, view);
await view.forceSave(true, true);
closeEvidence.beforeRetire = { active: view.sameFileEditGate.hasActiveOwners, grace: view.sameFileEditGate.isInGracePeriod, saving: view.isSaveInProgress() };
await leaf.setViewState({ type: "empty", state: {} });
@@ -168,7 +168,7 @@ async function cleanup(control) {
if (c.hadOwn) c.gateway.getMathJax = c.original;
else delete c.gateway.getMathJax;
}
c.tab?.close();
if(c.tab || c.closingView) await closeMarkdownImageTab(c, c.closingView || c.editorView);
if (c.pop) {
const win=c.pop.view.containerEl.ownerDocument.defaultView;
if(win===app.workspace.containerEl.ownerDocument.defaultView){await c.pop.setViewState({type:'empty',state:{}});c.pop.detach();}
@@ -182,7 +182,7 @@ async function cleanup(control) {
export async function runImageGeometryScenario({ cli, drawingPath, realRenderer = false }) {
const cases=[];
for(const [popout,scenario] of [[false,exercise],[true,exercise],[false,exerciseMarkdown],[false,exerciseMarkdownCrop]]){
const result=await runLegacyTask({cli,control:CONTROL,execute:scenario,cleanup,args:[drawingPath,popout,realRenderer],timeoutMs:90000,cleanupMs:120000});
const result=await runLegacyTask({cli,control:CONTROL,execute:scenario,cleanup,helpers:[closeMarkdownImageTab],args:[drawingPath,popout,realRenderer],timeoutMs:90000,cleanupMs:120000});
cases.push({window:popout?'popout':'main',...result});
}
return {id:realRenderer?'image-geometry-real-3014':'image-geometry-3014',renderer:realRenderer?'extras-mathjax':'deterministic-svg',status:'passed',cases};
+2 -1
View File
@@ -1,11 +1,12 @@
/** Retire polling-only native probes through the shared settle-before-cleanup contract. */
import assert from 'node:assert/strict';
import {runInAppTask} from './inAppTask.mjs';
export async function runLegacyTask({cli,control,execute,cleanup=async()=>{},args=[],timeoutMs=120000,cleanupMs=180000}){
export async function runLegacyTask({cli,control,execute,cleanup=async()=>{},helpers=[],args=[],timeoutMs=120000,cleanupMs=180000}){
assert.match(control,/^__[a-zA-Z0-9_]+$/,'Legacy controller must be a named owned test global');
// Both functions are local repository helpers, serialized exactly as existing
// native probes are. No remote code, production instrumentation or source-coverage credit.
const adapter=new Function(`return async function(c,control,args){
${helpers.map(helper=>helper.toString()).join(';')}
if(globalThis[control])throw Error('Existing native controller: '+control);
const legacy={state:'pending'};globalThis[control]=legacy;
Object.defineProperty(legacy,'cancelled',{get:()=>c.cancelled});
@@ -0,0 +1,20 @@
/** Await feature-owned close work before a test retires its drawing. Never cancel it. */
export async function closeMarkdownImageTab(c, view, {
timeoutMs = 20000, now = () => Date.now(),
wait = ms => new Promise(resolve => setTimeout(resolve, ms)),
} = {}) {
if (!view?.sameFileEditGate) throw Error("Markdown-image close owner is unavailable");
c.closingView = view;
c.tab?.close();
c.tab = null;
const end = now() + timeoutMs;
while (view.sameFileEditGate.hasActiveOwners || view.isSaveInProgress()) {
if (now() >= end) {
const error = Error("Markdown-image close is unsettled; preserve its drawing for recovery");
error.cleanupFailed = true;
throw error;
}
await wait(25);
}
c.closingView = null;
}
@@ -0,0 +1,31 @@
import assert from "node:assert/strict";
import test from "node:test";
import { closeMarkdownImageTab } from "./markdownImageClose.mjs";
test("Markdown-image fixture retirement waits for asynchronous owner release and persistence", async () => {
let clock = 0, closes = 0, released = false, saved = false;
const view = { sameFileEditGate: { get hasActiveOwners() { return !released; } },
isSaveInProgress: () => !saved };
const c = { tab: { close() { closes++; } } };
await closeMarkdownImageTab(c, view, { now: () => clock, wait: async ms => {
assert.equal(c.closingView, view, "pending close retains recovery ownership");
clock += ms;
if (clock >= 25) released = true;
if (clock >= 50) saved = true;
} });
assert.equal(closes, 1);
assert.equal(clock, 50);
assert.equal(c.closingView, null);
assert.equal(c.tab, null);
});
test("a close deadline fails and retains the live owner without cancelling native work", async () => {
let clock = 0;
const view = { sameFileEditGate: { hasActiveOwners: true }, isSaveInProgress: () => false };
const c = { tab: { close() {} } };
await assert.rejects(closeMarkdownImageTab(c, view, {
timeoutMs: 50, now: () => clock, wait: async ms => { clock += ms; },
}), error => error.cleanupFailed === true && /preserve/.test(error.message));
assert.equal(c.closingView, view);
assert.equal(view.sameFileEditGate.hasActiveOwners, true);
});
+3 -2
View File
@@ -3,6 +3,7 @@ export async function exerciseMarkdownCrop(control, drawingPath) {
const c = globalThis[control], plugin = app.plugins.plugins["obsidian-excalidraw-plugin"];
const leaf = app.workspace.getLeavesOfType("excalidraw").find(l => l.view.file?.path === drawingPath);
const view = leaf.view;
c.editorView = view;
c.previous = app.workspace.activeLeaf;
const waitFor = async (predicate, label) => {
for (let i = 0; i < 400; i++) {
@@ -95,8 +96,8 @@ export async function exerciseMarkdownCrop(control, drawingPath) {
const png = await view.ownerWindow.ExcalidrawLib.exportToBlob({ ...exportOptions, mimeType: "image/png" });
if (!png?.size) throw Error("PNG crop export failed");
const expected = copies().map(element => ({ id: element.id, crop: { ...element.crop }, width: element.width, height: element.height }));
c.tab.close(); c.tab = null;
const closeEvidence = { afterSignal: { active: view.sameFileEditGate.hasActiveOwners, grace: view.sameFileEditGate.isInGracePeriod, saving: view.isSaveInProgress() } };
const closeEvidence = { beforeClose: { active: view.sameFileEditGate.hasActiveOwners, grace: view.sameFileEditGate.isInGracePeriod, saving: view.isSaveInProgress() } };
await closeMarkdownImageTab(c, view);
await view.forceSave(true, true);
closeEvidence.beforeRetire = { active: view.sameFileEditGate.hasActiveOwners, grace: view.sameFileEditGate.isInGracePeriod, saving: view.isSaveInProgress() };
await leaf.setViewState({ type: "empty", state: {} });
@@ -0,0 +1,88 @@
/** Bounded host-only comparison. No Excalidraw runtime, forced scene flush or acceptance credit. */
import assert from "node:assert/strict";
import { runInAppTask } from "./inAppTask.mjs";
export async function runMarkdownMigrationControl({ cli, drawingPath }) {
assert.ok(drawingPath.startsWith("__excalidraw_cli_smoke_"));
const result = await runInAppTask({ cli, execute: exerciseMarkdownMigration,
args: [drawingPath], timeoutMs: 180000, cleanupMs: 60000 });
return { id: "diagnostic-markdown-migration", status: "passed", ...result };
}
async function exerciseMarkdownMigration(c, drawingPath) {
const workspace = app.workspace, doc = workspace.containerEl.ownerDocument;
const prefix = drawingPath.replace(/\.(excalidraw\.md|excalidraw|md)$/, "") + "_markdown_migration";
const ids = ["excalidraw-extras", "obsidian-excalidraw-plugin"];
const check = (value, label) => { if (!value) throw Error(label); };
check(!doc.querySelector("body > .print"), "Native print work must settle before host-only control");
const base = workspace.getLeavesOfType("excalidraw").find(l => l.view.file?.path === drawingPath);
check(base, "Owned drawing missing");
await base.setViewState({ type: "empty", state: {} });
const previous = workspace.activeLeaf, owned = new Set();
c.defer(async () => {
for (const id of ids) if (!app.plugins.plugins[id]) await app.plugins.enablePlugin(id);
await c.waitForCleanup(() => app.plugins.plugins[ids[1]]?.isReady && app.plugins.plugins[ids[0]]?.api, "restore both community runtimes");
});
c.defer(async () => {
for (const leaf of owned) {
const win = leaf.view.containerEl.ownerDocument.defaultView;
if (win !== doc.defaultView && !win.closed) {
await leaf.view.save(); win.close(); await c.waitForCleanup(() => win.closed, "host-only popout close");
} else if (leaf.containerEl.isConnected) {
await leaf.setViewState({ type: "empty", state: {} }); leaf.detach();
}
}
const folder = app.vault.getFolderByPath(prefix);
if (folder) { check(prefix.startsWith("__excalidraw_cli_smoke_"), "unowned host-only folder"); await app.vault.delete(folder, true); }
if (previous?.containerEl.isConnected) workspace.setActiveLeaf(previous, { focus: true });
});
for (const id of [...ids].reverse()) await app.plugins.disablePlugin(id);
check(ids.every(id => !app.plugins.plugins[id]), "Community runtime remains active in host-only control");
await app.vault.createFolder(prefix);
for (let cycle = 0; cycle < 6; cycle++) {
const route = cycle % 2 ? "host-drag" : "direct";
await c.case(`diagnostic:markdown-migration:${route}:${cycle}`, ["P03"], async () => {
let anchor; workspace.iterateAllLeaves(l => { if (!anchor && l.getRoot() === workspace.rootSplit) anchor = l; });
check(anchor, "Main workspace anchor missing"); workspace.setActiveLeaf(anchor, { focus: true });
const file = await app.vault.create(prefix + "/" + cycle + ".md", "Initial host-only note.");
const leaf = workspace.getLeaf("tab"); owned.add(leaf);
await leaf.setViewState({ type: "markdown", state: { file: file.path, mode: "source", source: true } });
await c.waitFor(() => leaf.view.editor && leaf.view.containerEl.ownerDocument === doc, "main Markdown editor");
workspace.moveLeafToPopout(leaf);
await c.waitFor(() => leaf.view.containerEl.ownerDocument !== doc && leaf.view.editor, "Markdown popout");
const popWindow = leaf.view.containerEl.ownerDocument.defaultView;
const marker = "Dirty host-only Markdown cycle " + cycle;
leaf.view.editor.setValue(marker);
check(leaf.view.editor.getValue() === marker && await app.vault.read(file) !== marker, "Markdown migration fixture is not dirty");
const target = anchor.parent;
if (route === "host-drag") {
const source = leaf.tabHeaderEl, destination = anchor.tabHeaderEl;
const sr = source.getBoundingClientRect(), tr = destination.getBoundingClientRect();
check(sr.width > 0 && tr.width > 0, "Host-only tab headers are not visible");
const end = new popWindow.DragEvent("dragend", { bubbles: true }); let dropped = false;
source.dispatchEvent(new popWindow.DragEvent("dragstart", { bubbles: true, cancelable: true,
clientX: sr.x + sr.width / 2, clientY: sr.y + sr.height / 2, dataTransfer: new popWindow.DataTransfer() }));
try {
const point = { clientX: tr.x + tr.width / 2, clientY: tr.y + tr.height * 0.8 };
const over = new doc.defaultView.DragEvent("dragover", { bubbles: true, cancelable: true, ...point, dataTransfer: new doc.defaultView.DataTransfer() });
destination.dispatchEvent(over);
check(workspace.getDropLocation(over) === target, "Host-only drag targeted another group");
dropped = true;
destination.dispatchEvent(new doc.defaultView.DragEvent("drop", { bubbles: true, cancelable: true, ...point, dataTransfer: new doc.defaultView.DataTransfer() }));
} finally { if (!dropped) source.dispatchEvent(end); }
} else {
leaf.parent.removeChild(leaf); leaf.setDimension(null); target.insertChild(-1, leaf);
target.selectTabIndex(target.children.indexOf(leaf)); workspace.requestResize();
}
await c.waitFor(() => leaf.view.containerEl.ownerDocument === doc && leaf.view.editor, "Markdown return to main");
await c.waitFor(() => popWindow.closed, "Markdown source window teardown");
check(leaf.view.editor.getValue() === marker, "Markdown migration lost unsaved text");
await leaf.view.save(); check(await app.vault.read(file) === marker, "Markdown physical save differs");
check(ids.every(id => !app.plugins.plugins[id]), "Community runtime activated during host-only control");
await leaf.setViewState({ type: "empty", state: {} }); leaf.detach(); owned.delete(leaf);
return { route, input: "public Markdown editor API; synthetic host drag where specified", communityPluginsLoaded: false,
assertions: ["dirty Markdown survives popout-to-main", "actual source window closes", "physical save matches", "both community runtimes remain unloaded"] };
});
}
return { tests: c.tests };
}
+6
View File
@@ -22,6 +22,7 @@ import { runWorkflowFixesScenario } from "./workflowFixes.mjs";
import { acquireHostLock } from "./hostLock.mjs";
import { runDataIntegrityScenario } from "./dataIntegrity.mjs";
import { runLifecycleScenario } from "./lifecycle.mjs";
import { runMarkdownMigrationControl } from "./markdownMigrationControl.mjs";
import { runExtrasServicesScenario } from "./extrasServices.mjs";
import { runStabilityScenario } from "./stability.mjs";
import { runAutomateScenario } from "./automate.mjs";
@@ -63,8 +64,11 @@ const fullProfile = profile === "full" || profile === "regression";
const coreOnly=process.argv.includes("--core"),coreScenarios=fullProfile||coreOnly;
const lifecycle = coreScenarios || process.argv.includes("--lifecycle");
const migrationComparison = process.argv.includes("--migration-comparison");
const markdownMigrationControl = process.argv.includes("--markdown-migration-control");
if (fullProfile && migrationComparison)
throw Error("Migration comparison is a focused diagnostic, not a full-profile replacement");
if (fullProfile && markdownMigrationControl)
throw Error("Host-only Markdown migration is a focused diagnostic, not full coverage");
const extrasServices =
coreScenarios || process.argv.includes("--extras-services");
const devices =
@@ -125,6 +129,7 @@ const flags = [
"--behavior-matrix",
"--lifecycle",
"--migration-comparison",
"--markdown-migration-control",
"--extras-services",
"--devices",
"--data-integrity",
@@ -275,6 +280,7 @@ try {
context => runLifecycleScenario(context),
context => runLifecycleScenario(context, { migrationRoute: "host-drag" }),
] : []),
...(markdownMigrationControl ? [runMarkdownMigrationControl] : []),
...(extrasServices ? [runExtrasServicesScenario] : []),
...(dataIntegrity ? [runDataIntegrityScenario] : []),
...(workflowFixes ? [runWorkflowFixesScenario] : []),
+4
View File
@@ -2477,6 +2477,10 @@
"path": "scripts/testing/host/legacyTask.test.mjs",
"mode": "isolated-or-extracted"
},
{
"path": "scripts/testing/host/markdownImageClose.test.mjs",
"mode": "direct-module-or-tooling"
},
{
"path": "scripts/testing/host/pluginDiscovery.test.mjs",
"mode": "isolated-or-extracted"