import assert from 'node:assert/strict'; import { test } from 'node:test'; import { documents, findDocument, linkedDocument, templateDownloadUrl, FEISHU_TEMPLATE_DIRECTORY } from '../lib/documents.ts'; test('document registry retains legacy names and points visible downloads to Word', () => { for (const document of documents) { assert.equal(findDocument(document.filename)?.id, document.id); assert.equal(findDocument(document.id)?.filename, document.filename); const url = new URL(templateDownloadUrl(document.id), 'https://example.test'); assert.equal(url.searchParams.get('format'), 'docx'); assert.equal(decodeURIComponent(url.pathname.split('/').at(-1)!), document.filename); } assert.equal(findDocument('../../.env'), undefined); assert.equal(findDocument('not-a-document'), undefined); }); test('links between built-in documents resolve to the correct preview and preserve the provided Feishu directory', () => { assert.equal(linkedDocument('开发SOP附件/附件03_数据来源填写模板.md')?.id, 'data-source'); assert.equal(linkedDocument(encodeURIComponent('附件02_需求文档模板.md'))?.id, 'requirement'); assert.equal(linkedDocument('%invalid'), undefined); assert.equal(linkedDocument('javascript:alert(1)'), undefined); assert.equal(FEISHU_TEMPLATE_DIRECTORY, 'https://ecnldnvsv8es.feishu.cn/wiki/Bvnbw852biK7qRkhwJkcOIvun4f?from=from_copylink'); });