target.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { describe, expect, it } from "vitest";
  2. import { parseGoalCompletionVerificationText } from "../src/tools/target.js";
  3. describe("goal target contracts", () => {
  4. it("parses completion verification from fenced json responses", () => {
  5. expect(
  6. parseGoalCompletionVerificationText(
  7. '```json\n{"nextAction":"Run pnpm test","passed":false,"reason":"Missing evidence"}\n```',
  8. ),
  9. ).toEqual({
  10. nextAction: "Run pnpm test",
  11. passed: false,
  12. reason: "Missing evidence",
  13. });
  14. });
  15. it("parses completion verification when a fenced response is json-string encoded", () => {
  16. expect(
  17. parseGoalCompletionVerificationText(
  18. JSON.stringify(
  19. '```json\n{"nextAction":"","passed":true,"reason":"All requirements are complete."}\n```',
  20. ),
  21. ),
  22. ).toEqual({
  23. passed: true,
  24. reason: "All requirements are complete.",
  25. });
  26. });
  27. it("treats malformed verifier json as passed fail-open", () => {
  28. expect(
  29. parseGoalCompletionVerificationText(
  30. '```json\n{"passed": true, "reason": "目标"继续修环境和做完所有开发"已全部完成。", "nextAction": ""}\n```',
  31. ),
  32. ).toEqual({
  33. passed: true,
  34. reason: "The completion verifier did not return valid JSON.",
  35. });
  36. });
  37. it("treats non-json verifier text as passed fail-open", () => {
  38. expect(parseGoalCompletionVerificationText("done")).toEqual({
  39. passed: true,
  40. reason: "The completion verifier did not return valid JSON.",
  41. });
  42. });
  43. });