tool-execution-telemetry.test.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { describe, expect, it } from "vitest";
  2. import { ToolExecutionTelemetrySchema } from "../src/tools/performance.js";
  3. describe("ToolExecutionTelemetrySchema", () => {
  4. it("命令 detail 接受真实退出码", () => {
  5. expect(
  6. ToolExecutionTelemetrySchema.parse({
  7. detail: {
  8. kind: "command",
  9. command: {
  10. exitCode: 2,
  11. name: "git",
  12. status: "failed",
  13. },
  14. },
  15. totalMs: 20,
  16. }),
  17. ).toMatchObject({
  18. detail: {
  19. kind: "command",
  20. command: {
  21. exitCode: 2,
  22. },
  23. },
  24. });
  25. });
  26. it("文件 detail 在类型和运行时 Schema 中都不接受退出码", () => {
  27. expect(() =>
  28. ToolExecutionTelemetrySchema.parse({
  29. detail: {
  30. kind: "filesystem",
  31. filesystem: {
  32. exitCode: 0,
  33. readMs: 10,
  34. },
  35. },
  36. }),
  37. ).toThrow();
  38. });
  39. it("顶层不再接受兼容 exitCode", () => {
  40. expect(() =>
  41. ToolExecutionTelemetrySchema.parse({
  42. exitCode: 0,
  43. }),
  44. ).toThrow();
  45. });
  46. });