Record page drafts in conversation packages
This commit is contained in:
@@ -132,3 +132,78 @@ test('normalizeWorkspaceRelativePath unifies bare html filenames under public/',
|
||||
assert.equal(normalizeWorkspaceRelativePath('public/ai-robot-report.html'), 'public/ai-robot-report.html');
|
||||
assert.equal(normalizeWorkspaceRelativePath('/public/demo.html'), 'public/demo.html');
|
||||
});
|
||||
|
||||
test('registerPageArtifactForConversation records page artifact and refreshes manifest', async () => {
|
||||
const calls = [];
|
||||
const registry = {
|
||||
async ensurePackage(input) {
|
||||
calls.push(['ensurePackage', input]);
|
||||
return { id: 'cp_session-1' };
|
||||
},
|
||||
async recordArtifact(input) {
|
||||
calls.push(['recordArtifact', input]);
|
||||
return input;
|
||||
},
|
||||
async writeManifestForSession(input) {
|
||||
calls.push(['writeManifestForSession', input]);
|
||||
return { storageKey: 'users/user-1/conversations/session-1/manifest.json' };
|
||||
},
|
||||
};
|
||||
|
||||
const result = await pageInternals.registerPageArtifactForConversation({
|
||||
registry,
|
||||
userId: 'user-1',
|
||||
source: { sessionId: 'session-1', messageId: 'message-1' },
|
||||
page: {
|
||||
id: 'page-1',
|
||||
currentVersionId: 'version-1',
|
||||
title: '旅行计划',
|
||||
sourceMessageId: 'message-fallback',
|
||||
},
|
||||
contentAssetId: 'asset-1',
|
||||
contentMimeType: 'text/html',
|
||||
contentBytes: 128,
|
||||
storageKey: 'users/user-1/pages/page-1/versions/v1.html',
|
||||
versionNo: 1,
|
||||
now: 1000,
|
||||
});
|
||||
|
||||
assert.equal(result.id, 'ca_page-1_version-1');
|
||||
assert.deepEqual(calls[0], [
|
||||
'ensurePackage',
|
||||
{
|
||||
userId: 'user-1',
|
||||
sessionId: 'session-1',
|
||||
title: '旅行计划',
|
||||
now: 1000,
|
||||
},
|
||||
]);
|
||||
assert.equal(calls[1][1].artifactKind, 'page');
|
||||
assert.equal(calls[1][1].messageId, 'message-1');
|
||||
assert.equal(calls[1][1].storageKey, 'users/user-1/pages/page-1/versions/v1.html');
|
||||
assert.deepEqual(calls[2], [
|
||||
'writeManifestForSession',
|
||||
{ userId: 'user-1', sessionId: 'session-1' },
|
||||
]);
|
||||
});
|
||||
|
||||
test('registerPageArtifactForConversation skips missing registry or session safely', async () => {
|
||||
assert.equal(
|
||||
await pageInternals.registerPageArtifactForConversation({
|
||||
registry: null,
|
||||
userId: 'user-1',
|
||||
source: { sessionId: 'session-1' },
|
||||
page: { id: 'page-1' },
|
||||
}),
|
||||
null,
|
||||
);
|
||||
assert.equal(
|
||||
await pageInternals.registerPageArtifactForConversation({
|
||||
registry: { ensurePackage: async () => assert.fail('should not be called') },
|
||||
userId: 'user-1',
|
||||
source: {},
|
||||
page: { id: 'page-1' },
|
||||
}),
|
||||
null,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user