Files
obsidian-excalidraw-plugin/scripts/testing/fileAliases.test.mjs
zsviczian 6a3e2eb2e4 Harden file insertion, heading embeds, SVG exports and focused Save As
Implement the scoped fixes for PR #3046:
- Ignore unsupported aliases while retaining whole string/list aliases and paths.
- Use Obsidian source-heading identities for section targets, preserving legacy
  image-transclusion matching.
- Block Ctrl/Cmd+Shift+S only in the focused drawing editor, retaining normal
  save and explicit legacy export.
- Honor internal-link removal in manual vault and clipboard SVG exports through
  the existing scene filter without mutating source elements or changing hooks.

Add source and native regressions, including standalone H2 wikilinks, aliased
and unresolved wikilinks, save/reopen, image decoding and ordinary section-link
navigation in Reading and Live Preview. Preserve the original NBSP attachment
with provenance. Add the requested CLI troubleshooting guidance and remove the
temporary plan-only handoff.

Validation: 993 portable cases passed; 776 fast/source tests passed; all ten
PR-specific native cases passed in main and popout, including the expanded
wikilink matrix. Production build and all five bundle tests passed. No new lint
diagnostics; the repository retains 116 existing errors. The exact tested build
was deployed to Zsolt's Brain with backed-up artifacts and unchanged settings.

The complete native profile remains failed: table controls also fail on the
unchanged baseline; the offscreen phone toolbar remains unclassified against
baseline. Initial zoom-settling and popout code-image reopen failures passed
focused reruns. macOS, physical mobile and minimum-version Obsidian remain
untested. Original SVG escaping (#2570) and NBSP (#2389) reports did not reproduce
on this Windows host; they gain coverage without speculative serializer/cache
changes. Optional simple-columns compatibility (#2858) is deferred.
2026-11-12 22:03:32 +01:00

44 lines
2.1 KiB
JavaScript

/** Run the actual picker constructor against unsupported frontmatter and valid aliases. */
import assert from "node:assert/strict";
import test from "node:test";
import { readFileSync } from "node:fs";
import vm from "node:vm";
import ts from "typescript";
const exports = {};
class SuggestionModal {
constructor(app, input, items) { this.app = app; this.inputEl = input; this.items = items; }
setPlaceholder() {}
}
vm.runInNewContext(ts.transpileModule(readFileSync(new URL("../../src/shared/Suggesters/FileSuggestionModal.ts", import.meta.url), "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
}).outputText, { exports, require: name => ({
"./SuggestionModal": { SuggestionModal }, "src/lang/helpers": { t: value => value },
"src/utils/styleUtils": { setStyle() {} },
}[name] ?? {}) });
function picker(values) {
const items = values.map((aliases, i) => ({ path: `Notes/File-${i}.md`, aliases }));
const app = { metadataCache: { getFileCache: file => ({ frontmatter: { aliases: file.aliases } }) } };
const input = { inputEl: { clientWidth: 200, addEventListener() {} } };
return { items, modal: new exports.FileSuggestionModal(app, input, items, {}) };
}
test("unsupported alias metadata cannot hide mixed vault files or mutate YAML values", () => {
const values = [undefined, null, {}, { "[object Object]": null }, 1, true, [null, {}, false, 7, ""]];
const before = structuredClone(values);
const { items, modal } = picker(values);
assert.equal(modal.getItems().length, items.length);
assert.deepEqual(Array.from(modal.getItems(), item => item.path), items.map(item => item.path));
assert.deepEqual(values, before);
});
test("string aliases remain whole and valid list members remain searchable after reopening", () => {
for (let i = 0; i < 2; i++) {
const { modal } = picker(["Whole alias", ["First", null, {}, "Second", ""]]);
assert.deepEqual(Array.from(modal.getItems(), item => modal.getItemText(item)), [
"Notes/File-0.md", "Notes/File-0.md|Whole alias", "Notes/File-1.md", "Notes/File-1.md|First", "Notes/File-1.md|Second",
]);
}
});