provisioningSyncEvidence.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { describe, expect, it } from "vitest";
  2. import { parseProvisioningSyncEvents } from "./e2e/helpers/provisioning-sync-evidence.js";
  3. const context = {
  4. environmentKey: "env-a",
  5. trigger: "personal-config",
  6. status: "failed",
  7. durationMs: 14,
  8. };
  9. const warning = `[2026-09-25 00:10:00] [warn] [pid:123] [main] [provider-provisioning] Environment sync did not apply ${JSON.stringify(context)}`;
  10. describe("真实 Main Provisioning 结果取证", () => {
  11. it("保留成功与失败两类事件,供提交数和返回数对账", () => {
  12. const completed = warning
  13. .replace("[warn]", "[info]")
  14. .replace("sync did not apply", "sync completed")
  15. .replace('"status":"failed"', '"status":"applied"');
  16. expect(parseProvisioningSyncEvents(`${completed}\n${warning}\n`)).toEqual([
  17. { kind: "completed", ...context, status: "applied" },
  18. { kind: "warning", ...context },
  19. ]);
  20. });
  21. it("识别结构化 warning,不把 renderer 转述算成 Main 执行结果", () => {
  22. expect(
  23. parseProvisioningSyncEvents(`${warning}\n${warning.replace("[main]", "[renderer]")}\n`),
  24. ).toEqual([{ kind: "warning", ...context }]);
  25. });
  26. it("完成日志与失败状态矛盾时拒绝取证,不能伪装成已应用", () => {
  27. const wrong = warning
  28. .replace("[warn]", "[info]")
  29. .replace("sync did not apply", "sync completed");
  30. expect(() => parseProvisioningSyncEvents(`${wrong}\n`)).toThrow();
  31. });
  32. it("仅忽略正在追加的末行,完整写入后保留真实事件", () => {
  33. expect(parseProvisioningSyncEvents(warning)).toEqual([]);
  34. expect(parseProvisioningSyncEvents(`${warning}\n`)).toHaveLength(1);
  35. });
  36. it("缺少 Environment 身份的完整记录必须报错", () => {
  37. expect(() =>
  38. parseProvisioningSyncEvents(`${warning.replace('"environmentKey":"env-a",', "")}\n`),
  39. ).toThrow();
  40. });
  41. });