test(core): common setup for ai tests (#11644)

### TL:DR

By sharing initialization logic, accelerate test case execution.

### What Changed

* Global setup for copilot e2e
  * Login
  * Create Workspace
* Enable fully parallel for ci

### Optimization Comparison​

Comparing with PR [fix(core): ask AI input box in the whiteboard is blocked by the menu …](https://github.com/toeverything/AFFiNE/pull/11634):

|           |    Shard 1   |2|3|4|5|6|7|8|
| ------|----|----|----|----|----|---|---|--|
|Before|15min|14min|14min|14min|14min|13min|15min|10min|
|After|8min|11min|8min|8min|8min|8min|8min|7min|

### Trade-Off

Since all copilot use cases currently share a single user and workspace, some test cases need to focus on **isolation** and **independence**.
For example, when testing Embedding-related workflows:
* Different document contents should be used to avoid interference.
* After each test case execution, **cleanup** operations are also required.
* Some tests should be configured to **serial** mode.

```ts
test.describe.configure({ mode: 'serial' });

test.describe('AIChatWith/Collections', () => {
  test.beforeEach(async ({ loggedInPage: page, utils }) => {
    await utils.testUtils.setupTestEnvironment(page);
    await utils.chatPanel.openChatPanel(page);
    await utils.editor.clearAllCollections(page);

    await utils.testUtils.createNewPage(page);
  });

  test.afterEach(async ({ loggedInPage: page, utils }) => {
    // clear all collections
    await utils.editor.clearAllCollections(page);
  });

  test('should support chat with collection', async ({
    loggedInPage: page,
    utils,
  }) => {
    // Create two collections
    await utils.editor.createCollectionAndDoc(
      page,
      'Collection 1',
      'CollectionAAaa is a cute dog'
    );

    await utils.chatPanel.chatWithCollections(page, ['Collection 1']);
    await utils.chatPanel.makeChat(page, 'What is CollectionAAaa(Use English)');
    // ...
  });

  test('should support chat with multiple collections', async ({
    loggedInPage: page,
    utils,
  }) => {
    // Create two collections
    await utils.editor.createCollectionAndDoc(
      page,
      'Collection 2',
      'CollectionEEee is a cute cat'
    );

    await utils.editor.createCollectionAndDoc(
      page,
      'Collection 3',
      'CollectionFFff is a cute dog'
    );

    await utils.chatPanel.chatWithCollections(page, [
      'Collection 2',
      'Collection 3',
    ]);
    await utils.chatPanel.makeChat(
      page,
      'What is CollectionEEee? What is CollectionFFff?(Use English)'
    );
    // ...
  });
});

```

> CLOSE AI-51
This commit is contained in:
yoyoyohamapi
2025-04-14 02:42:06 +00:00
parent 11d1b2fae5
commit d494394c8d
58 changed files with 564 additions and 410 deletions
@@ -1,18 +1,18 @@
import { loginUser } from '@affine-test/kit/utils/cloud';
import { expect } from '@playwright/test';
import { test } from '../base/base-test';
test.describe('AIChatWith/Attachments', () => {
test.beforeEach(async ({ page, utils }) => {
const user = await utils.testUtils.getUser();
await loginUser(page, user);
test.beforeEach(async ({ loggedInPage: page, utils }) => {
await utils.testUtils.setupTestEnvironment(page);
await utils.chatPanel.openChatPanel(page);
});
test('support chat with attachment', async ({ page, utils }) => {
const textContent = 'EEee is a cute cat';
test('support chat with attachment', async ({
loggedInPage: page,
utils,
}) => {
const textContent = 'AttachmentEEee is a cute cat';
const buffer = Buffer.from(textContent);
await utils.chatPanel.chatWithAttachments(
@@ -24,13 +24,13 @@ test.describe('AIChatWith/Attachments', () => {
buffer: buffer,
},
],
'What is EEee?'
'What is AttachmentEEee?'
);
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'What is EEee?',
content: 'What is AttachmentEEee?',
},
{
role: 'assistant',
@@ -44,9 +44,12 @@ test.describe('AIChatWith/Attachments', () => {
}).toPass({ timeout: 10000 });
});
test('support chat with multiple attachments', async ({ page, utils }) => {
const textContent1 = 'EEee is a cute cat';
const textContent2 = 'FFff is a cute dog';
test('support chat with multiple attachments', async ({
loggedInPage: page,
utils,
}) => {
const textContent1 = 'AttachmentEEee is a cute cat';
const textContent2 = 'AttachmentFFff is a cute dog';
const buffer1 = Buffer.from(textContent1);
const buffer2 = Buffer.from(textContent2);
@@ -64,13 +67,13 @@ test.describe('AIChatWith/Attachments', () => {
buffer: buffer2,
},
],
'What is EEee? What is FFff?'
'What is AttachmentEEee? What is AttachmentFFff?'
);
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'What is EEee? What is FFff?',
content: 'What is AttachmentEEee? What is AttachmentFFff?',
},
{
role: 'assistant',
@@ -81,8 +84,8 @@ test.describe('AIChatWith/Attachments', () => {
await expect(async () => {
const { content, message } =
await utils.chatPanel.getLatestAssistantMessage(page);
expect(content).toMatch(/EEee/);
expect(content).toMatch(/FFff/);
expect(content).toMatch(/AttachmentEEee/);
expect(content).toMatch(/AttachmentFFff/);
expect(await message.locator('affine-footnote-node').count()).toBe(2);
}).toPass({ timeout: 20000 });
});