feat: complete mindspace conversation packages
This commit is contained in:
@@ -7,6 +7,8 @@ import path from 'node:path';
|
||||
import {
|
||||
hasRecentOwnPublicHtmlReference,
|
||||
isStubPublicHtmlContent,
|
||||
collectOwnPublicHtmlArtifactRefs,
|
||||
collectOwnPublicHtmlRelativePaths,
|
||||
materializeMissingPublicHtmlWrites,
|
||||
materializePublicHtmlWritesFromSessionEvent,
|
||||
syncPublicDocxDownloads,
|
||||
@@ -123,6 +125,7 @@ test('materializeMissingPublicHtmlWrites writes html from sandbox write_file too
|
||||
try {
|
||||
const messages = [
|
||||
{
|
||||
id: 'msg-public-1',
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
@@ -158,6 +161,7 @@ test('syncPublicHtmlAfterFinish forwards session source to workspace sync', asyn
|
||||
const calls = [];
|
||||
const messages = [
|
||||
{
|
||||
id: 'msg-public-1',
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
@@ -186,7 +190,115 @@ test('syncPublicHtmlAfterFinish forwards session source to workspace sync', asyn
|
||||
});
|
||||
|
||||
assert.equal(result.synced, true);
|
||||
assert.deepEqual(calls, [[CURRENT_USER.id, { categoryCode: 'public', sourceSessionId: 'session-1' }]]);
|
||||
assert.deepEqual(calls, [[
|
||||
CURRENT_USER.id,
|
||||
{
|
||||
categoryCode: 'public',
|
||||
sourceSessionId: 'session-1',
|
||||
sourceMessageId: 'msg-public-1',
|
||||
},
|
||||
]]);
|
||||
} finally {
|
||||
fs.rmSync(publishDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('syncPublicHtmlAfterFinish registers existing public html artifacts for the session', async () => {
|
||||
const publishDir = fs.mkdtempSync(path.join(os.tmpdir(), 'public-finish-sync-'));
|
||||
try {
|
||||
fs.mkdirSync(path.join(publishDir, 'public'), { recursive: true });
|
||||
fs.writeFileSync(path.join(publishDir, 'public/123.html'), '<!doctype html><title>一二三</title>');
|
||||
const calls = [];
|
||||
const messages = [
|
||||
{
|
||||
id: 'msg-public-1',
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `[一二三](https://m.tkmind.cn/MindSpace/${CURRENT_USER.id}/public/123.html)`,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const result = await syncPublicHtmlAfterFinish({
|
||||
messages,
|
||||
currentUser: CURRENT_USER,
|
||||
publishDir,
|
||||
sessionId: 'session-1',
|
||||
syncWorkspaceAssets: async () => {},
|
||||
registerPublicHtmlArtifacts: async (...args) => {
|
||||
calls.push(args);
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(result.publicHtmlRelativePaths, ['public/123.html']);
|
||||
assert.deepEqual(calls, [
|
||||
[
|
||||
CURRENT_USER.id,
|
||||
{
|
||||
sessionId: 'session-1',
|
||||
relativePaths: ['public/123.html'],
|
||||
artifactRefs: [{ relativePath: 'public/123.html', messageId: 'msg-public-1' }],
|
||||
},
|
||||
],
|
||||
]);
|
||||
} finally {
|
||||
fs.rmSync(publishDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('collectOwnPublicHtmlArtifactRefs includes source message ids when available', () => {
|
||||
const publishDir = fs.mkdtempSync(path.join(os.tmpdir(), 'public-finish-sync-'));
|
||||
try {
|
||||
fs.mkdirSync(path.join(publishDir, 'public'), { recursive: true });
|
||||
fs.writeFileSync(path.join(publishDir, 'public/own.html'), '<!doctype html><title>Own</title>');
|
||||
const refs = collectOwnPublicHtmlArtifactRefs({
|
||||
publishDir,
|
||||
currentUser: CURRENT_USER,
|
||||
messages: [
|
||||
{
|
||||
id: 'assistant-msg-1',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `https://m.tkmind.cn/MindSpace/${CURRENT_USER.id}/public/own.html`,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
assert.deepEqual(refs, [{ relativePath: 'public/own.html', messageId: 'assistant-msg-1' }]);
|
||||
} finally {
|
||||
fs.rmSync(publishDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('collectOwnPublicHtmlRelativePaths ignores missing and other-user public html links', () => {
|
||||
const publishDir = fs.mkdtempSync(path.join(os.tmpdir(), 'public-finish-sync-'));
|
||||
try {
|
||||
fs.mkdirSync(path.join(publishDir, 'public'), { recursive: true });
|
||||
fs.writeFileSync(path.join(publishDir, 'public/own.html'), '<!doctype html><title>Own</title>');
|
||||
const paths = collectOwnPublicHtmlRelativePaths({
|
||||
publishDir,
|
||||
currentUser: CURRENT_USER,
|
||||
messages: [
|
||||
{
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: [
|
||||
`https://m.tkmind.cn/MindSpace/${CURRENT_USER.id}/public/own.html`,
|
||||
`https://m.tkmind.cn/MindSpace/${CURRENT_USER.id}/public/missing.html`,
|
||||
'https://m.tkmind.cn/MindSpace/other-user/public/other.html',
|
||||
].join('\n'),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
assert.deepEqual(paths, ['public/own.html']);
|
||||
} finally {
|
||||
fs.rmSync(publishDir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user