feat: finalize mindspace service extraction phase a
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs/promises';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
createConversationPackagePublicHtmlHydrator,
|
||||
registerPublicHtmlArtifactsForConversationPackage,
|
||||
} from './mindspace-conversation-package-public-html.mjs';
|
||||
|
||||
test('registerPublicHtmlArtifactsForConversationPackage records existing public html files', async () => {
|
||||
const h5Root = await fs.mkdtemp(path.join(os.tmpdir(), 'mindspace-public-html-helper-'));
|
||||
const publishDir = path.join(h5Root, 'MindSpace', 'user-1');
|
||||
await fs.mkdir(path.join(publishDir, 'public'), { recursive: true });
|
||||
await fs.writeFile(path.join(publishDir, 'public', 'landing.html'), '<html>ok</html>', 'utf8');
|
||||
|
||||
const recorded = [];
|
||||
const registry = {
|
||||
async readManifestForSession() {
|
||||
return null;
|
||||
},
|
||||
async ensurePackage() {
|
||||
return { id: 'pkg-1' };
|
||||
},
|
||||
async recordArtifact(payload) {
|
||||
recorded.push(payload);
|
||||
},
|
||||
async writeManifestForSession() {
|
||||
return { ok: true };
|
||||
},
|
||||
};
|
||||
|
||||
const result = await registerPublicHtmlArtifactsForConversationPackage({
|
||||
conversationPackageRegistry: registry,
|
||||
h5Root,
|
||||
env: { H5_PUBLIC_BASE_URL: 'https://example.com' },
|
||||
user: { id: 'user-1' },
|
||||
publishDir,
|
||||
sessionId: 'session-1',
|
||||
relativePaths: ['public/landing.html'],
|
||||
});
|
||||
|
||||
assert.equal(result.length, 1);
|
||||
assert.equal(recorded.length, 1);
|
||||
assert.equal(recorded[0].packageId, 'pkg-1');
|
||||
assert.equal(recorded[0].canonicalUrl, 'https://example.com/MindSpace/user-1/public/landing.html');
|
||||
});
|
||||
|
||||
test('createConversationPackagePublicHtmlHydrator resolves snapshot artifacts through shared registration helper', async () => {
|
||||
const h5Root = await fs.mkdtemp(path.join(os.tmpdir(), 'mindspace-public-html-hydrator-'));
|
||||
const publishDir = path.join(h5Root, 'MindSpace', 'user-1');
|
||||
await fs.mkdir(path.join(publishDir, 'public'), { recursive: true });
|
||||
await fs.writeFile(path.join(publishDir, 'public', 'landing.html'), '<html>ok</html>', 'utf8');
|
||||
|
||||
const calls = [];
|
||||
const hydrator = createConversationPackagePublicHtmlHydrator({
|
||||
h5Root,
|
||||
resolveSessionSnapshot: async () => ({
|
||||
session: { name: 'Chat publish' },
|
||||
messages: [
|
||||
{
|
||||
role: 'assistant',
|
||||
content: [{ type: 'text', text: 'See public/landing.html' }],
|
||||
},
|
||||
],
|
||||
}),
|
||||
registerPublicHtmlArtifactsForConversation: async (payload) => {
|
||||
calls.push(payload);
|
||||
return payload.artifactRefs;
|
||||
},
|
||||
});
|
||||
|
||||
const result = await hydrator({
|
||||
user: { id: 'user-1' },
|
||||
sessionId: 'session-1',
|
||||
});
|
||||
|
||||
assert.equal(result.length, 1);
|
||||
assert.equal(calls.length, 1);
|
||||
assert.equal(calls[0].publishDir, publishDir);
|
||||
assert.equal(calls[0].artifactRefs[0].relativePath, 'public/landing.html');
|
||||
});
|
||||
Reference in New Issue
Block a user