e2eUnreadContextContract.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { readFile } from "node:fs/promises";
  2. import { resolve } from "node:path";
  3. import ts from "typescript";
  4. import { expect, it } from "vitest";
  5. it("MRO03 pending与formal保持普通上下文,显式compact用例仍用小窗口", async () => {
  6. const source = await readFile(resolve(import.meta.dirname, "../wdio.conf.ts"), "utf8");
  7. const file = ts.createSourceFile("wdio.conf.ts", source, ts.ScriptTarget.Latest, true);
  8. const expressions = new Map<string, string>();
  9. const visit = (node: ts.Node) => {
  10. if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer)
  11. expressions.set(node.name.text, node.initializer.getText(file));
  12. ts.forEachChild(node, visit);
  13. };
  14. visit(file);
  15. const auto = expressions.get("autoCompactSpec");
  16. const window = expressions.get("contextWindow");
  17. if (!auto || !window) throw new Error("Missing real WDIO replay context configuration");
  18. // 执行实际配置表达式;其它专项布尔门禁均关闭,避免为测试import启动整套WDIO。
  19. const unrelated = [
  20. ...new Set([...auto.matchAll(/!([A-Za-z]+Spec)\b/gu)].map((match) => match[1]!)),
  21. ];
  22. const readWindow = new Function(
  23. "specs",
  24. "upstreamE2EContextWindowOverride",
  25. ...unrelated,
  26. `const autoCompactSpec = ${auto}; return ${window};`,
  27. ) as (specs: string[], override: undefined, ...flags: boolean[]) => number;
  28. for (const path of [
  29. "./test/e2e/conversation-session/manual-review/pending/conversation-session-web-remote-unread.test.ts",
  30. "./test/e2e/conversation-session/conversation-session-web-remote-unread.test.ts",
  31. ])
  32. expect(readWindow([path], undefined, ...unrelated.map(() => false))).toBe(128000);
  33. expect(
  34. readWindow(
  35. ["./test/e2e/conversation-session/conversation-session-compact-auto.test.ts"],
  36. undefined,
  37. ...unrelated.map(() => false),
  38. ),
  39. ).toBe(240);
  40. });