Skip to content
Myr

prompt.test.ts

This file

Path

packages/drafting/test/prompt.test.ts

122 lines · 3.7 KiB · TypeScript

Last changed by

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

History of this file

Take it

Merge branch 'build/908-drafter-workers-ai'oscabrielbefore adoption004e40e

lines 1–57why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { Brand } from "@repo/brand";3import type { Policy } from "@repo/protocol/domain/policy";4import { VisibilityPolicy } from "@repo/protocol/domain/visibility";5import { LandedSha, ProjectName, RepoPath } from "@repo/protocol/ids";6import { NotRedFirst } from "@repo/protocol/refusal";7import { aProject } from "@repo/testkit/scenarios";8import { Option, Schema } from "effect";910import type { DraftInput } from "../src/drafted.ts";11import {12 feedbackText,13 policyDigest,14 systemPrompt,15 userPrompt,16} from "../src/prompt.ts";1718const { policy } = aProject();1920const visibility = Schema.decodeSync(VisibilityPolicy)({21 checks: {22 areas: { export: "src/sealed-area/**" },23 attempts: { perClaim: 3, perPersonPerAreaPerWeek: 5 },24 canary: true,25 commit: "salted-sha256-merkle",26 layer: "keepers",27 pin: "claim",28 result: "area-bit",29 },30 env: { setters: "deciders" },31 flows: { noWriteDown: true, release: "deciders" },32 layers: [33 {34 audience: "maintainers",35 disclose: "sealed",36 holds: ["checks"],37 name: "keepers",38 readers: "deciders",39 reason: "The sealed-rubric for exports",40 repo: "datekit--keepers",41 writers: "deciders",42 },43 ],44 notice: { narrowingDays: 7 },45});4647const firstInput = (attempt: number): DraftInput => ({48 attempt,49 context: {50 at: LandedSha.make("4".repeat(40)),51 files: [52 {53 content: "export const parseISO = () => 0;\n",54 path: RepoPath.make("src/parse.ts"),55 },56 ],57 policy: policyDigest(policy, Option.some("test/asks")),

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 58why, one step back
58 project: ProjectName.make("oscabriel/datekit"),

Merge branch 'build/908-drafter-workers-ai'oscabrielbefore adoption004e40e

lines 59–122why, one step back
59 },
60 want: "Parse ISO week dates.",61});6263const input = (attempt: number, feedback?: string): DraftInput =>64 feedback === undefined65 ? firstInput(attempt)66 : { ...firstInput(attempt), feedback };6768describe("the prompts", () => {69 it("never carry a layer's name, repo, reason or paths", () => {70 // A whole policy is a PublicPolicy too; the digest reads only its public fields.71 const withLayers: Policy = { ...policy, visibility };72 const digest = policyDigest(withLayers, Option.some("test/asks"));7374 const system = systemPrompt(digest);7576 for (const secret of [77 "keepers",78 "datekit--keepers",79 "sealed-rubric",80 "src/sealed-area",81 ]) {82 expect(system).not.toContain(secret);83 }8485 expect(system).toContain(Brand.name);86 expect(system).toContain("bun test {path}");87 expect(system).toContain("test/asks");88 expect(system).toContain("fix");89 });9091 it("give attempt 2 the rendered refusal and the output's tail, cut at 4 KB", () => {92 const stdout = `${"early line\n".repeat(1000)}expected 2 to be 3\n`;9394 const feedback = feedbackText({95 diagnosis: "Passed",96 excerpt: stdout,97 refusal: new NotRedFirst({}),98 });99100 const prompt = userPrompt(input(2, feedback));101102 expect(prompt).toContain(103 "NotRedFirst: the ask's check must fail on main twice in the same way, by an assertion"104 );105 expect(prompt).toContain("diagnosis: Passed");106107 const tail = feedback.slice(feedback.indexOf("output (its end):\n") + 18);108109 expect(new TextEncoder().encode(tail).length).toBeLessThanOrEqual(4 * 1024);110 expect(tail.endsWith("early line\nexpected 2 to be 3\n")).toBeTruthy();111 expect(tail.startsWith("early line\n")).toBeTruthy();112 });113114 it("give attempt 1 the want and the files, and no feedback", () => {115 const prompt = userPrompt(input(1));116117 expect(prompt).toContain("Parse ISO week dates.");118 expect(prompt).toContain("src/parse.ts");119 expect(prompt).toContain("export const parseISO = () => 0;");120 expect(prompt).not.toContain("NotRedFirst");121 });122});