fix(server): rerank scores calc (#13016)

fix AI-257
This commit is contained in:
DarkSky
2025-07-07 23:05:02 +08:00
committed by GitHub
parent 2d050a317f
commit 181ccf5a45
18 changed files with 329 additions and 109 deletions

View File

@@ -199,9 +199,11 @@ export class ChatPanelUtils {
}
public static async chatWithDoc(page: Page, docName: string) {
const withButton = await page.getByTestId('chat-panel-with-button');
const withButton = page.getByTestId('chat-panel-with-button');
await withButton.hover();
await withButton.click();
const withMenu = await page.getByTestId('ai-add-popover');
const withMenu = page.getByTestId('ai-add-popover');
await withMenu.waitFor({ state: 'visible' });
await withMenu.getByText(docName).click();
await page.getByTestId('chat-panel-chips').getByText(docName);
}
@@ -221,9 +223,20 @@ export class ChatPanelUtils {
await withButton.hover();
await withButton.click();
const withMenu = page.getByTestId('ai-add-popover');
await withMenu.waitFor({ state: 'visible' });
await withMenu.getByTestId('ai-chat-with-files').click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(attachment);
await expect(async () => {
const states = await page
.getByTestId('chat-panel-chip')
.evaluateAll(elements =>
elements.map(el => el.getAttribute('data-state'))
);
expect(states.every(state => state === 'finished')).toBe(true);
}).toPass({ timeout: 20000 });
}
await expect(async () => {
const states = await page
@@ -267,9 +280,11 @@ export class ChatPanelUtils {
public static async chatWithTags(page: Page, tags: string[]) {
for (const tag of tags) {
const withButton = await page.getByTestId('chat-panel-with-button');
const withButton = page.getByTestId('chat-panel-with-button');
await withButton.hover();
await withButton.click();
const withMenu = await page.getByTestId('ai-add-popover');
const withMenu = page.getByTestId('ai-add-popover');
await withMenu.waitFor({ state: 'visible' });
await withMenu.getByTestId('ai-chat-with-tags').click();
await withMenu.getByText(tag).click();
await page.getByTestId('chat-panel-chips').getByText(tag);
@@ -282,9 +297,11 @@ export class ChatPanelUtils {
public static async chatWithCollections(page: Page, collections: string[]) {
for (const collection of collections) {
const withButton = await page.getByTestId('chat-panel-with-button');
const withButton = page.getByTestId('chat-panel-with-button');
await withButton.hover();
await withButton.click();
const withMenu = await page.getByTestId('ai-add-popover');
const withMenu = page.getByTestId('ai-add-popover');
await withMenu.waitFor({ state: 'visible' });
await withMenu.getByTestId('ai-chat-with-collections').click();
await withMenu.getByText(collection).click();
await page.getByTestId('chat-panel-chips').getByText(collection);

View File

@@ -207,4 +207,53 @@ export class SettingsPanelUtils {
await searcher.getByTestId('doc-selector-confirm-button').click();
}
}
private static async waitForEmbeddingStatus(
page: Page,
timeout: number,
status = 'synced'
) {
await expect(async () => {
await this.openSettingsPanel(page);
const title = page.getByTestId('embedding-progress-title');
// oxlint-disable-next-line prefer-dom-node-dataset
const progressAttr = await title.getAttribute('data-progress');
expect(progressAttr).not.toBe('loading');
expect(progressAttr).toBe(status);
}).toPass({ timeout });
}
public static async waitForEmbeddingComplete(page: Page, timeout = 30000) {
await this.waitForEmbeddingStatus(page, timeout);
// check embedding progress count
await expect(async () => {
const count = page.getByTestId('embedding-progress-count');
const countText = await count.textContent();
if (countText) {
const [embedded, total] = countText.split('/').map(Number);
expect(embedded).toBe(total);
expect(embedded).toBeGreaterThan(0);
}
}).toPass({ timeout });
}
public static async waitForFileEmbeddingReadiness(
page: Page,
expectedFileCount: number,
timeout = 30000
) {
await expect(async () => {
const attachmentList = page.getByTestId(
'workspace-embedding-setting-attachment-list'
);
const attachmentItems = attachmentList.getByTestId(
'workspace-embedding-setting-attachment-item'
);
await expect(attachmentItems).toHaveCount(expectedFileCount);
}).toPass({ timeout });
await this.waitForEmbeddingComplete(page, timeout);
}
}