e2eProviderConfigSeedBoundary.test.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { readdirSync, readFileSync } from "node:fs";
  2. import { extname, join } from "node:path";
  3. import { describe, expect, it } from "vitest";
  4. const source = readFileSync(new URL("../wdio.conf.ts", import.meta.url), "utf8");
  5. const seedHelperSource = readFileSync(
  6. new URL("./e2e/helpers/model-provider-restart-config.ts", import.meta.url),
  7. "utf8",
  8. );
  9. const e2eRoot = new URL("./e2e/", import.meta.url);
  10. describe("Desktop E2E Provider seed boundary", () => {
  11. it("普通 WDIO fixture 不再写旧 model-providers.json", () => {
  12. expect(source).not.toContain("E2E_MODEL_PROVIDERS_FILE");
  13. expect(source).toContain("seedPersonalProviderConfig");
  14. });
  15. it("普通 WDIO fixture 不再把 Provider 复制到旧 CLI Config", () => {
  16. const writerStart = source.indexOf("function seedE2EWorkerModelStreamConfig");
  17. const writerEnd = source.indexOf("async function seedModelOutputTokenProviders");
  18. const cliWriterSource = source.slice(writerStart, writerEnd);
  19. expect(writerStart).toBeGreaterThanOrEqual(0);
  20. expect(writerEnd).toBeGreaterThan(writerStart);
  21. // 这里只约束 Provider seed 的写入边界。其他 E2E(例如 workspace plugin)也会
  22. // 合法读写同一个 CLI config,不能用全文件引用次数间接表达 Provider 契约。
  23. expect(cliWriterSource).toContain("E2E_CLI_CONFIG_FILE");
  24. expect(cliWriterSource).not.toContain("provider:");
  25. expect(cliWriterSource).not.toContain("model:");
  26. });
  27. it("Personal Config seed 不再以旧 Provider Store DTO 为输入", () => {
  28. expect(source).not.toMatch(/\bModelProviderConfig\b/u);
  29. expect(seedHelperSource).not.toMatch(/\bModelProviderConfig\b/u);
  30. expect(seedHelperSource).not.toContain("isModelProviderModelConfig");
  31. expect(seedHelperSource).not.toContain("resolveModelProviderApiFormat");
  32. });
  33. it("E2E 观察与断言不再依赖旧 Provider Store 顶层 DTO", () => {
  34. const legacyReferences = collectTypeScriptSources(e2eRoot).filter(({ source }) =>
  35. /\bModelProviderConfig\b/u.test(source),
  36. );
  37. expect(legacyReferences.map(({ path }) => path)).toEqual([]);
  38. });
  39. });
  40. function collectTypeScriptSources(root: URL): Array<{ path: string; source: string }> {
  41. const result: Array<{ path: string; source: string }> = [];
  42. for (const entry of readdirSync(root, { withFileTypes: true })) {
  43. const child = new URL(`${entry.name}${entry.isDirectory() ? "/" : ""}`, root);
  44. if (entry.isDirectory()) {
  45. result.push(...collectTypeScriptSources(child));
  46. } else if (extname(entry.name) === ".ts") {
  47. result.push({
  48. path: join(root.pathname, entry.name),
  49. source: readFileSync(child, "utf8"),
  50. });
  51. }
  52. }
  53. return result;
  54. }