1008946-knowledge-status-polling.spec.ts 1.83 KB
import { test, expect } from "@playwright/test";

/**
 * 缺陷 1008946 - 上传到知识库的文件解析完之后,不更新前端的状态
 *
 * 根因:Workspace.vue 缺少对 knowledgeStatus === 'processing' 文件的轮询机制。
 * 文件上传 SSE 在任务提交给知识服务后即关闭,知识处理(向量化)异步完成后
 * 前端无感知,状态停留在 processing 直到手动刷新。
 *
 * 修复:在 Workspace.vue 增加 hasProcessingFiles computed + 10 秒轮询,
 * 与 KnowledgeBase/FileList.vue 保持一致。
 */
test.describe("知识库文件状态自动更新 (#1008946)", () => {
  test("hasProcessingFiles 逻辑:递归扫描树中 processing 文件", async () => {
    type FileNode = {
      type: "file" | "folder";
      knowledgeStatus?: string;
      children?: FileNode[];
    };

    const check = (nodes: FileNode[]): boolean =>
      nodes.some((n) =>
        n.type === "file"
          ? n.knowledgeStatus === "processing"
          : check(n.children || []),
      );

    // 无 processing 文件
    expect(
      check([
        { type: "folder", children: [{ type: "file", knowledgeStatus: "completed" }] },
        { type: "file", knowledgeStatus: "not_supported" },
      ]),
    ).toBe(false);

    // 顶层 processing 文件
    expect(check([{ type: "file", knowledgeStatus: "processing" }])).toBe(true);

    // 深层嵌套 processing 文件
    expect(
      check([
        {
          type: "folder",
          children: [
            {
              type: "folder",
              children: [{ type: "file", knowledgeStatus: "processing" }],
            },
          ],
        },
      ]),
    ).toBe(true);

    // 空树
    expect(check([])).toBe(false);

    // processing 完成后变为 completed
    expect(check([{ type: "file", knowledgeStatus: "completed" }])).toBe(false);
  });
});