Record synced workspace artifacts in packages
This commit is contained in:
@@ -142,21 +142,65 @@ test('syncUserWorkspace imports new workspace files into asset library', async (
|
||||
},
|
||||
};
|
||||
|
||||
const packageCalls = [];
|
||||
const conversationPackageRegistry = {
|
||||
async ensurePackage(input) {
|
||||
packageCalls.push(['ensurePackage', input]);
|
||||
return { id: 'cp-session-1' };
|
||||
},
|
||||
async recordArtifact(input) {
|
||||
packageCalls.push(['recordArtifact', input]);
|
||||
return input;
|
||||
},
|
||||
async writeManifestForSession(input) {
|
||||
packageCalls.push(['writeManifestForSession', input]);
|
||||
return input;
|
||||
},
|
||||
};
|
||||
const sync = createWorkspaceAssetSync({
|
||||
pool,
|
||||
storageRoot,
|
||||
h5Root,
|
||||
maxFileBytes: 1024 * 1024,
|
||||
idFactory: () => `id-${++nextId}`,
|
||||
conversationPackageRegistry,
|
||||
});
|
||||
|
||||
const result = await sync.syncUserWorkspace('user-1', { categoryCode: 'oa' });
|
||||
const result = await sync.syncUserWorkspace('user-1', {
|
||||
categoryCode: 'oa',
|
||||
sourceSessionId: 'session-1',
|
||||
sourceMessageId: 'message-1',
|
||||
title: 'Workspace chat',
|
||||
});
|
||||
assert.equal(result.imported, 1);
|
||||
assert.equal(state.assets.length, 1);
|
||||
assert.equal(state.assets[0].original_filename, 'memo.txt');
|
||||
assert.ok(state.versions.length === 1);
|
||||
assert.match(state.versions[0].storage_key, /^workspace:\/\/user-1\/oa\/memo\.txt$/);
|
||||
assert.equal(await fs.readFile(path.join(workspace, 'oa', 'memo.txt'), 'utf8'), 'hello workspace\n');
|
||||
assert.deepEqual(packageCalls[0], [
|
||||
'ensurePackage',
|
||||
{
|
||||
userId: 'user-1',
|
||||
sessionId: 'session-1',
|
||||
title: 'Workspace chat',
|
||||
now: packageCalls[0][1].now,
|
||||
},
|
||||
]);
|
||||
const artifactCall = packageCalls.find(([name]) => name === 'recordArtifact')?.[1];
|
||||
assert.equal(artifactCall.packageId, 'cp-session-1');
|
||||
assert.equal(artifactCall.artifactKind, 'generated_file');
|
||||
assert.equal(artifactCall.role, 'assistant');
|
||||
assert.equal(artifactCall.assetId, 'id-1');
|
||||
assert.equal(artifactCall.messageId, 'message-1');
|
||||
assert.equal(artifactCall.displayName, 'memo.txt');
|
||||
assert.equal(artifactCall.mimeType, 'text/plain');
|
||||
assert.equal(artifactCall.storageKey, 'workspace://user-1/oa/memo.txt');
|
||||
assert.equal(artifactCall.canonicalUrl, '/api/mindspace/v1/assets/id-1/download');
|
||||
assert.deepEqual(packageCalls.at(-1), [
|
||||
'writeManifestForSession',
|
||||
{ userId: 'user-1', sessionId: 'session-1' },
|
||||
]);
|
||||
});
|
||||
|
||||
test('syncUserWorkspace imports nested workspace files into asset library', async () => {
|
||||
|
||||
Reference in New Issue
Block a user