feat: complete mindspace conversation packages
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
DOCX_MIME_TYPE,
|
||||
registerChatDocxArtifactForConversation,
|
||||
} from './mindspace-chat-docx-package.mjs';
|
||||
|
||||
test('registerChatDocxArtifactForConversation writes docx object and artifact manifest entry', async () => {
|
||||
const calls = [];
|
||||
const buffer = Buffer.from('docx-body');
|
||||
const registry = {
|
||||
async putObjectForSession(input) {
|
||||
calls.push(['putObjectForSession', input]);
|
||||
return {
|
||||
packageRecord: { id: 'cp_session-1' },
|
||||
writeResult: {
|
||||
key: `users/user-1/conversations/session-1/${input.relativePath}`,
|
||||
},
|
||||
};
|
||||
},
|
||||
async recordArtifact(input) {
|
||||
calls.push(['recordArtifact', input]);
|
||||
return input;
|
||||
},
|
||||
async writeManifestForSession(input) {
|
||||
calls.push(['writeManifestForSession', input]);
|
||||
return input;
|
||||
},
|
||||
};
|
||||
|
||||
const artifact = await registerChatDocxArtifactForConversation({
|
||||
registry,
|
||||
user: { id: 'user-1' },
|
||||
bundle: { source: { session: { name: 'Docx session' } } },
|
||||
requestBody: {
|
||||
session_id: 'session-1',
|
||||
message_id: 'message-1',
|
||||
selected_link_index: 2,
|
||||
},
|
||||
filename: '研究报告.docx',
|
||||
buffer,
|
||||
now: 1000,
|
||||
});
|
||||
|
||||
assert.equal(artifact.artifactKind, 'docx');
|
||||
assert.equal(artifact.messageId, 'message-1');
|
||||
assert.equal(artifact.mimeType, DOCX_MIME_TYPE);
|
||||
assert.equal(artifact.sizeBytes, buffer.length);
|
||||
assert.match(artifact.id, /^ca_docx_[a-f0-9]{16}$/);
|
||||
assert.match(
|
||||
artifact.canonicalUrl,
|
||||
/^\/api\/mindspace\/v1\/conversation-packages\/session-1\/artifacts\/ca_docx_[a-f0-9]{16}\/download$/,
|
||||
);
|
||||
assert.deepEqual(calls[0][1], {
|
||||
userId: 'user-1',
|
||||
sessionId: 'session-1',
|
||||
title: 'Docx session',
|
||||
relativePath: `artifacts/${artifact.id}/研究报告.docx`,
|
||||
body: buffer,
|
||||
});
|
||||
assert.deepEqual(calls.at(-1), [
|
||||
'writeManifestForSession',
|
||||
{ userId: 'user-1', sessionId: 'session-1' },
|
||||
]);
|
||||
});
|
||||
|
||||
test('registerChatDocxArtifactForConversation skips missing session or message source', async () => {
|
||||
const registry = {
|
||||
async putObjectForSession() {
|
||||
assert.fail('should not write object without source');
|
||||
},
|
||||
};
|
||||
assert.equal(
|
||||
await registerChatDocxArtifactForConversation({
|
||||
registry,
|
||||
user: { id: 'user-1' },
|
||||
requestBody: { session_id: 'session-1' },
|
||||
filename: 'report.docx',
|
||||
buffer: Buffer.from('docx'),
|
||||
}),
|
||||
null,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user