Record published companion artifacts

This commit is contained in:
john
2026-07-02 21:47:10 +08:00
parent b38dd5961f
commit c86a3fd15b
2 changed files with 178 additions and 0 deletions
+73
View File
@@ -275,6 +275,79 @@ test('registerPublicationArtifactForConversation records public html artifact',
]);
});
test('collectPublicationCompanionArtifacts finds real download and long-image files', async () => {
const publishDir = await fs.mkdtemp(path.join(os.tmpdir(), 'publication-companions-'));
await fs.mkdir(path.join(publishDir, 'public'), { recursive: true });
await fs.writeFile(path.join(publishDir, 'public', 'report.docx'), 'docx');
await fs.writeFile(path.join(publishDir, 'public', 'report.long.png'), 'png');
await fs.writeFile(path.join(publishDir, 'public', 'appendix.pdf'), 'pdf');
const artifacts = await publicationInternals.collectPublicationCompanionArtifacts({
publishDir,
htmlRelativePath: 'public/report.html',
html: '<a href="appendix.pdf" download>PDF</a>',
});
assert.deepEqual(
artifacts.map((item) => item.workspacePath).sort(),
['public/appendix.pdf', 'public/report.docx', 'public/report.long.png'],
);
});
test('registerPublicationArtifactForConversation records public companions', async () => {
const publishDir = await fs.mkdtemp(path.join(os.tmpdir(), 'publication-companions-'));
await fs.mkdir(path.join(publishDir, 'public'), { recursive: true });
await fs.writeFile(path.join(publishDir, 'public', 'report.docx'), 'docx');
await fs.writeFile(path.join(publishDir, 'public', 'report.long.png'), 'png');
const calls = [];
const registry = {
async ensurePackage(input) {
calls.push(['ensurePackage', input]);
return { id: 'cp_session-1' };
},
async recordArtifact(input) {
calls.push(['recordArtifact', input]);
return input;
},
async writeManifestForSession(input) {
calls.push(['writeManifestForSession', input]);
return { storageKey: 'users/user-1/conversations/session-1/manifest.json' };
},
};
await publicationInternals.registerPublicationArtifactForConversation({
registry,
userId: 'user-1',
page: {
page_id: 'page-1',
title: '发布页',
source_session_id: 'session-1',
source_message_id: 'message-1',
source_relative_path: 'public/report.html',
},
publication: {
id: 'pub-1',
publicUrl: 'https://m.tkmind.cn/u/john/pages/published',
publishedAt: 3000,
},
bundleAssetId: 'asset-pub',
storageKey: 'users/user-1/publications/pub-1/index.html',
htmlBytes: 256,
html: '<!doctype html><title>发布页</title>',
publishDir,
now: 3000,
});
const artifactKinds = calls
.filter(([name]) => name === 'recordArtifact')
.map(([, input]) => input.artifactKind)
.sort();
assert.deepEqual(artifactKinds, ['docx', 'long_image', 'public_html']);
const docx = calls.find(([, input]) => input?.artifactKind === 'docx')?.[1];
assert.equal(docx.displayName, 'report.docx');
assert.match(docx.canonicalUrl, /\/MindSpace\/user-1\/public\/report\.docx$/);
});
test('registerPublicationArtifactForConversation skips pages without source session', async () => {
assert.equal(
await publicationInternals.registerPublicationArtifactForConversation({