Show persistent timestamps for operation and teacher messages

This commit is contained in:
鲨鱼辣椒 committed 2026-09-29 18:02:54 +08:00
1 parent 3a175101c9
commit ead3407890
24 files changed
+355 -9

No files matched your search

+19
View File
@@ -33,6 +33,25 @@ function baseSnapshot(): ConversationSnapshot {
const zeroCost = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 };
describe('Pi session projector', () => {
it('restores send and completion times from durable entries and leaves undated history unknown', async () => {
const sent = '2026-09-28T08:01:02.000Z', finished = '2026-09-28T08:01:42.000Z';
const input = { snapshot: baseSnapshot(), workerGeneration: 1,
state: { sessionId: 'times', isStreaming: false, isCompacting: false },
entries: { leafId: 'old', entries: [
{ type: 'message', id: 'u', parentId: null, timestamp: finished, message: { role: 'user', timestamp: Date.parse(sent), content: '你好' } },
{ type: 'message', id: 'a', parentId: 'u', timestamp: finished, message: { role: 'assistant', timestamp: Date.parse(sent), stopReason: 'stop', content: [{ type: 'text', text: '你好呀' }] } },
{ type: 'message', id: 'fallback', parentId: 'a', timestamp: sent, message: { role: 'user', timestamp: 'invalid', content: '较早问题' } },
{ type: 'message', id: 'old', parentId: 'fallback', timestamp: 'invalid', message: { role: 'assistant', timestamp: Date.parse(sent), stopReason: 'stop', content: [{ type: 'text', text: '无完成时间' }] } },
] } };
const snapshot = await projectPiSessionSnapshot(input);
expect(snapshot.nodes).toMatchObject([
{ role: 'user', timestamp: Date.parse(sent) }, { role: 'assistant', timestamp: Date.parse(finished) },
{ role: 'user', timestamp: Date.parse(sent) }, { role: 'assistant', timestamp: undefined },
]);
expect((await projectPiSessionSnapshot({ ...input, snapshot })).nodes).toEqual(snapshot.nodes);
expect(input.entries.entries[3].timestamp).toBe('invalid');
});
it('restores the observed expired Works Square session as a safe login recovery notice', async () => {
const snapshot = await projectPiSessionSnapshot({
snapshot: baseSnapshot(), workerGeneration: 1,