fix(renderer): accept both marked image renderer signatures

marked <= 14 calls renderer.image(href, title, text); marked >= 15 passes
the token instead. With only the positional form handled, an upgrade of the
pinned CDN build would turn every session image into fallback text without
any error, so normalise both shapes and cover them with a unit test.

The tag name moves into session-image-contract.js so the Markdown renderer
no longer reaches it through the module that imports the .vue component,
which is what kept it out of Node's test runner.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
tommy0103
2026-08-03 01:28:45 +08:00
co-authored by Claude Opus 5
parent e4a03fa58f
commit 34bd3aed83
4 changed files with 67 additions and 7 deletions
+36
View File
@@ -0,0 +1,36 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { normalizeMarkdownImageToken } from '../app/src/renderer/src/markdown-image-renderer.js';
// marked <= 14 calls renderer.image(href, title, text); marked >= 15 passes the
// token. Getting this wrong degrades silently: every session image turns into
// fallback text because the href is no longer a string.
test('accepts the positional renderer signature', () => {
assert.deepEqual(
normalizeMarkdownImageToken('http://example.test/a.png', 'A title', 'Alt text'),
{ href: 'http://example.test/a.png', title: 'A title', text: 'Alt text' },
);
});
test('accepts the token renderer signature', () => {
assert.deepEqual(
normalizeMarkdownImageToken({
type: 'image',
href: 'http://example.test/a.png',
title: 'A title',
text: 'Alt text',
}),
{ href: 'http://example.test/a.png', title: 'A title', text: 'Alt text' },
);
});
test('fills in the fields marked leaves null', () => {
assert.deepEqual(
normalizeMarkdownImageToken({ href: 'http://example.test/a.png', title: null, text: '' }),
{ href: 'http://example.test/a.png', title: '', text: '' },
);
assert.deepEqual(
normalizeMarkdownImageToken('http://example.test/a.png', null, null),
{ href: 'http://example.test/a.png', title: '', text: '' },
);
});