feat: complete mindspace conversation packages
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
conversationPackageVerifyInternals,
|
||||
verifyConversationPackageManifest,
|
||||
} from './mindspace-conversation-package-verify.mjs';
|
||||
|
||||
test('verifyConversationPackageManifest accepts readable urls and package storage objects', async () => {
|
||||
const result = await verifyConversationPackageManifest(
|
||||
{
|
||||
packageId: 'cp_session-1',
|
||||
userId: 'user-1',
|
||||
sessionId: 'session-1',
|
||||
storagePrefix: 'users/user-1/conversations/session-1',
|
||||
artifacts: [
|
||||
{
|
||||
artifactId: 'ca_page',
|
||||
kind: 'page',
|
||||
canonicalUrl: '/api/mindspace/v1/pages/page-1/preview',
|
||||
},
|
||||
{
|
||||
artifactId: 'ca_docx',
|
||||
kind: 'docx',
|
||||
storageKey: 'users/user-1/conversations/session-1/artifacts/ca_docx/report.docx',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
async statObject(key) {
|
||||
return { key, exists: true };
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
assert.deepEqual(result.issues, []);
|
||||
});
|
||||
|
||||
test('verifyConversationPackageManifest reports missing or unsafe artifact references', async () => {
|
||||
const result = await verifyConversationPackageManifest(
|
||||
{
|
||||
packageId: 'cp_session-1',
|
||||
userId: 'user-1',
|
||||
sessionId: 'session-1',
|
||||
storagePrefix: 'users/user-1/conversations/session-1',
|
||||
artifacts: [
|
||||
{ artifactId: 'ca_missing', kind: 'generated_file' },
|
||||
{ artifactId: 'ca_missing', kind: 'generated_file', canonicalUrl: 'file:///tmp/secret.txt' },
|
||||
{
|
||||
artifactId: 'ca_escape',
|
||||
kind: 'docx',
|
||||
storageKey: 'users/user-1/other/session-1/report.docx',
|
||||
},
|
||||
{
|
||||
artifactId: 'ca_gone',
|
||||
kind: 'docx',
|
||||
storageKey: 'users/user-1/conversations/session-1/report.docx',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
async statObject(key) {
|
||||
return { key, exists: key !== 'users/user-1/conversations/session-1/report.docx' };
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
assert.deepEqual(
|
||||
result.issues.map((item) => item.code),
|
||||
[
|
||||
'artifact_without_backing_reference',
|
||||
'duplicate_artifact_id',
|
||||
'invalid_canonical_url',
|
||||
'storage_key_outside_package',
|
||||
'missing_backing_object',
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
test('conversation package verify internals classify supported URLs', () => {
|
||||
assert.equal(conversationPackageVerifyInternals.isReadableUrl('https://m.tkmind.cn/MindSpace/u/public/a.html'), true);
|
||||
assert.equal(conversationPackageVerifyInternals.isReadableUrl('/api/mindspace/v1/assets/a/download'), true);
|
||||
assert.equal(conversationPackageVerifyInternals.isReadableUrl('/MindSpace/u/public/a.html'), true);
|
||||
assert.equal(conversationPackageVerifyInternals.isReadableUrl('file:///tmp/a.html'), false);
|
||||
});
|
||||
Reference in New Issue
Block a user