From 5da56b5b04abb04179aeed93d86dd0a5febc2f11 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Fri, 4 Jul 2025 18:46:07 +0800 Subject: [PATCH] chore(server): fix unstable test (#13037) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### PR Dependency Tree * **PR #13037** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) ## Summary by CodeRabbit * **Tests** * Improved test reliability by generating unique user accounts and prompt names for each test run. * Updated test setup to streamline database initialization. --- .../server/src/__tests__/copilot.e2e.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/backend/server/src/__tests__/copilot.e2e.ts b/packages/backend/server/src/__tests__/copilot.e2e.ts index d47e1f48f9..122e85a6f5 100644 --- a/packages/backend/server/src/__tests__/copilot.e2e.ts +++ b/packages/backend/server/src/__tests__/copilot.e2e.ts @@ -134,14 +134,16 @@ test.before(async t => { t.context.jobs = jobs; }); -const textPromptName = 'prompt'; -const imagePromptName = 'prompt-image'; +let textPromptName = 'prompt'; +let imagePromptName = 'prompt-image'; + test.beforeEach(async t => { Sinon.restore(); const { app, prompt } = t.context; - await app.initTestingDB(); await prompt.onApplicationBootstrap(); - t.context.u1 = await app.signupV1('u1@affine.pro'); + t.context.u1 = await app.signupV1(); + textPromptName = randomUUID().replaceAll('-', ''); + imagePromptName = randomUUID().replaceAll('-', ''); await prompt.set(textPromptName, 'test', [ { role: 'system', content: 'hello {{word}}' }, @@ -189,7 +191,7 @@ test('should create session correctly', async t => { } { - const u2 = await app.createUser('u2@affine.pro'); + const u2 = await app.createUser(); const { id } = await createWorkspace(app); await app.login(u2); await assertCreateSession(id, '', async x => { @@ -253,8 +255,8 @@ test('should update session correctly', async t => { } { - await app.signupV1('test@affine.pro'); - const u2 = await app.createUser('u2@affine.pro'); + await app.signupV1(); + const u2 = await app.createUser(); const { id: workspaceId } = await createWorkspace(app); const inviteId = await inviteUser(app, workspaceId, u2.email); await app.login(u2); @@ -356,7 +358,7 @@ test('should fork session correctly', async t => { } { - const u2 = await app.signupV1('u2@affine.pro'); + const u2 = await app.signupV1(); await assertForkSession(id, sessionId, randomUUID(), '', async x => { await t.throwsAsync( x, @@ -712,7 +714,7 @@ test('should reject message from different session', async t => { test('should reject request from different user', async t => { const { app, u1 } = t.context; - const u2 = await app.createUser('u2@affine.pro'); + const u2 = await app.createUser(); const { id } = await createWorkspace(app); const sessionId = await createCopilotSession( app, @@ -789,7 +791,7 @@ test('should be able to list history', async t => { test('should reject request that user have not permission', async t => { const { app, u1 } = t.context; - const u2 = await app.createUser('u2@affine.pro'); + const u2 = await app.createUser(); const { id: workspaceId } = await createWorkspace(app); // should reject request that user have not permission