Show persistent timestamps for operation and teacher messages
This commit is contained in:
1 parent
3a175101c9
commit
ead3407890
24 files changed
+355
-9
No files matched your search
@@ -164,6 +164,35 @@ async function fixture({ durableSource = false, sourceContext = context, liveMod
|
||||
};
|
||||
}
|
||||
describe('cloud coding teacher', () => {
|
||||
it.each([false, true])('persists terminal times for local/cloud=%s replies across restart', async cloudTeacher => {
|
||||
const f = await fixture({ cloudTeacher, mockCloud: cloudTeacher });
|
||||
const topic = await f.service.create(f.scope, undefined, undefined, cloudTeacher ? 9 : undefined);
|
||||
const id = '22222222-2222-4222-8222-222222222222';
|
||||
await f.service.send(f.scope, topic.id, { requestId: id, text: '解释一下' });
|
||||
const running = (await f.service.read(f.scope, topic.id)).requests[0];
|
||||
expect(running.finishedAt).toBeUndefined();
|
||||
const endingAfter = Date.now();
|
||||
f.finish();
|
||||
await vi.waitFor(async () => expect((await f.service.read(f.scope, topic.id)).requests[0].finishedAt).toBeTruthy());
|
||||
const saved = (await f.service.read(f.scope, topic.id)).requests[0];
|
||||
expect(saved.createdAt).toBe(running.createdAt);
|
||||
expect(Date.parse(saved.finishedAt!)).toBeGreaterThanOrEqual(endingAfter);
|
||||
expect(Date.parse(saved.finishedAt!)).toBeLessThanOrEqual(Date.now());
|
||||
const restarted = await f.restart();
|
||||
expect((await restarted.read(f.scope, topic.id)).requests[0]).toEqual(saved);
|
||||
});
|
||||
it.each(['cancelled', 'failed'] as const)('also saves the actual terminal time for %s replies', async status => {
|
||||
const f = await fixture();
|
||||
if (status === 'failed') f.run.mockRejectedValueOnce(new Error('failure'));
|
||||
const topic = await f.service.create(f.scope);
|
||||
const id = '22222222-2222-4222-8222-222222222222';
|
||||
await f.service.send(f.scope, topic.id, { requestId: id, text: '解释一下' });
|
||||
if (status === 'cancelled') await f.service.cancel(f.scope, topic.id, id);
|
||||
await vi.waitFor(async () => expect((await f.service.read(f.scope, topic.id)).requests[0]).toMatchObject({ status, finishedAt: expect.any(String) }));
|
||||
const saved = (await f.service.read(f.scope, topic.id)).requests[0];
|
||||
expect((await (await f.restart()).read(f.scope, topic.id)).requests[0].finishedAt).toBe(saved.finishedAt);
|
||||
});
|
||||
|
||||
it('does not change the selected discussion when the companion polls an older topic', async () => {
|
||||
const f = await fixture();
|
||||
const old = await f.service.create(f.scope);
|
||||
|
||||
Reference in new issue
Block a user