Spaces:
Running
Running
| import { describe, expect, it } from "vitest"; | |
| const { recoverInvalidLlmResponse } = await import("./llm-response").catch( | |
| () => ({ recoverInvalidLlmResponse: undefined }), | |
| ); | |
| describe("recoverInvalidLlmResponse", () => { | |
| it("keeps a live ask reply even when the model does not return JSON", () => { | |
| expect(recoverInvalidLlmResponse).toBeTypeOf("function"); | |
| const response = recoverInvalidLlmResponse?.({ | |
| rawText: | |
| "The validation of verbal concept output explains how the concept statement should be checked with users before visual development.", | |
| parsedCommand: { | |
| referencedPackageName: "Final Concept", | |
| mode: "ask", | |
| instruction: "What does this sentence mean?", | |
| }, | |
| }); | |
| expect(response?.assistantMessage).toContain( | |
| "validation of verbal concept output", | |
| ); | |
| expect(response?.boardAction.type).toBe("none"); | |
| }); | |
| it("extracts a human assistant message from a JSON-looking ask reply", () => { | |
| expect(recoverInvalidLlmResponse).toBeTypeOf("function"); | |
| const response = recoverInvalidLlmResponse?.({ | |
| rawText: | |
| '{"assistantMessage":"Verification method explains how each requirement will be tested.","boardAction":{"type":"none","workPackageId":null}}', | |
| parsedCommand: { | |
| referencedPackageName: "System Requirements Specification", | |
| mode: "ask", | |
| instruction: "What does verification method mean?", | |
| }, | |
| }); | |
| expect(response?.assistantMessage).toBe( | |
| "Verification method explains how each requirement will be tested.", | |
| ); | |
| expect(response?.assistantMessage.trim().startsWith("{")).toBe(false); | |
| expect(response?.boardAction.type).toBe("none"); | |
| }); | |
| it("falls back to a structured local response for change commands", () => { | |
| expect(recoverInvalidLlmResponse).toBeTypeOf("function"); | |
| const response = recoverInvalidLlmResponse?.({ | |
| rawText: "Sure, I would update the objective and keep the package in progress.", | |
| parsedCommand: { | |
| referencedPackageName: "SRS", | |
| mode: "change", | |
| instruction: "Add cybersecurity acceptance criteria.", | |
| }, | |
| fallbackResponse: { | |
| assistantMessage: "Updated SRS locally.", | |
| boardAction: { | |
| type: "update", | |
| workPackageId: "wp-srs", | |
| fields: { | |
| objective: "Updated objective", | |
| }, | |
| }, | |
| }, | |
| }); | |
| expect(response?.assistantMessage).toContain("Updated SRS locally"); | |
| expect(response?.boardAction.type).toBe("update"); | |
| }); | |
| }); | |