|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { scorePrompt } from "../src/tools/prompt-score.js"; |
| 3 | + |
| 4 | +describe("scorePrompt", () => { |
| 5 | + it("gives high specificity for prompts with file paths", () => { |
| 6 | + const result = scorePrompt("Fix the bug in src/lib/parser.ts where it crashes on empty input"); |
| 7 | + expect(result.specificity).toBe(25); |
| 8 | + }); |
| 9 | + |
| 10 | + it("gives high specificity for prompts with backtick identifiers", () => { |
| 11 | + const result = scorePrompt("Rename `handleClick` to `onButtonPress`"); |
| 12 | + expect(result.specificity).toBe(25); |
| 13 | + }); |
| 14 | + |
| 15 | + it("gives medium specificity for generic component references", () => { |
| 16 | + const result = scorePrompt("Update the component to handle errors"); |
| 17 | + expect(result.specificity).toBe(15); |
| 18 | + }); |
| 19 | + |
| 20 | + it("gives low specificity for vague prompts", () => { |
| 21 | + const result = scorePrompt("Make it better"); |
| 22 | + expect(result.specificity).toBe(5); |
| 23 | + }); |
| 24 | + |
| 25 | + it("gives high scope for bounded tasks", () => { |
| 26 | + const result = scorePrompt("Only change the return type of this single function"); |
| 27 | + expect(result.scope).toBe(25); |
| 28 | + }); |
| 29 | + |
| 30 | + it("gives low scope for broad tasks", () => { |
| 31 | + const result = scorePrompt("Fix all bugs"); |
| 32 | + expect(result.scope).toBe(10); |
| 33 | + }); |
| 34 | + |
| 35 | + it("gives high actionability for specific verbs", () => { |
| 36 | + const result = scorePrompt("Refactor the auth module"); |
| 37 | + expect(result.actionability).toBe(25); |
| 38 | + }); |
| 39 | + |
| 40 | + it("gives medium actionability for vague verbs", () => { |
| 41 | + const result = scorePrompt("Make the auth module work"); |
| 42 | + expect(result.actionability).toBe(15); |
| 43 | + }); |
| 44 | + |
| 45 | + it("gives high done-condition for verifiable outcomes", () => { |
| 46 | + const result = scorePrompt("Fix the parser so it should return null for empty input"); |
| 47 | + expect(result.doneCondition).toBe(25); |
| 48 | + }); |
| 49 | + |
| 50 | + it("gives high done-condition for questions", () => { |
| 51 | + const result = scorePrompt("Why does the parser crash on empty input?"); |
| 52 | + expect(result.doneCondition).toBe(20); |
| 53 | + }); |
| 54 | + |
| 55 | + it("gives low done-condition when no verifiable outcome", () => { |
| 56 | + const result = scorePrompt("Clean up the code"); |
| 57 | + expect(result.doneCondition).toBe(5); |
| 58 | + }); |
| 59 | + |
| 60 | + it("returns grade A+ for perfect prompts", () => { |
| 61 | + const result = scorePrompt( |
| 62 | + "Refactor `parseInput` in src/lib/parser.ts to only handle strings, and it should return null for empty input" |
| 63 | + ); |
| 64 | + expect(result.total).toBeGreaterThanOrEqual(90); |
| 65 | + expect(result.grade).toBe("A+"); |
| 66 | + }); |
| 67 | + |
| 68 | + it("returns low grade for vague prompts", () => { |
| 69 | + const result = scorePrompt("Fix it"); |
| 70 | + expect(result.total).toBeLessThan(55); |
| 71 | + expect(["D", "F"]).toContain(result.grade); |
| 72 | + }); |
| 73 | + |
| 74 | + it("provides feedback for missing dimensions", () => { |
| 75 | + const result = scorePrompt("Do something"); |
| 76 | + expect(result.feedback.length).toBeGreaterThan(0); |
| 77 | + expect(result.feedback.some(f => f.includes("📁"))).toBe(true); |
| 78 | + }); |
| 79 | + |
| 80 | + it("provides congratulatory feedback for excellent prompts", () => { |
| 81 | + const result = scorePrompt( |
| 82 | + "Add a test in `tests/parser.test.ts` to only verify that `parseInput` should return null for empty strings" |
| 83 | + ); |
| 84 | + if (result.total >= 90) { |
| 85 | + expect(result.feedback[0]).toContain("🏆"); |
| 86 | + } |
| 87 | + }); |
| 88 | + |
| 89 | + it("total is sum of all dimensions", () => { |
| 90 | + const result = scorePrompt("Rename `foo` to `bar` in src/index.ts so it should compile"); |
| 91 | + expect(result.total).toBe( |
| 92 | + result.specificity + result.scope + result.actionability + result.doneCondition |
| 93 | + ); |
| 94 | + }); |
| 95 | +}); |
0 commit comments