memory.test.ts
This file
Path
packages/drafting/test/memory.test.ts
57 lines · 1.8 KiB · TypeScript
Last changed by
Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
History of this fileTake it
Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
lines 1–27why, one step back1import { describe, expect, it } from "@effect/vitest";2import { AskId, LandedSha, ProjectName, RepoPath } from "@repo/protocol/ids";3import { Effect } from "effect";45import { DraftFailed } from "../src/drafted.ts";6import type { DraftedAsk, DraftInput } from "../src/drafted.ts";7import { Drafter } from "../src/drafter.ts";8import { DrafterMemory, DraftsAsked } from "../src/drafter/memory.ts";910const drafted: DraftedAsk = {11 id: AskId.make("iso-week"),12 kind: "fix",13 rationale: "The parser has no week dates.",14 territory: [RepoPath.make("src/parse.ts")],15 test: {16 path: RepoPath.make("test/iso-week.test.ts"),17 source: 'it("parses", () => expect(parse("2026-W01")).toBe(1));\n',18 },19 want: "An ISO week date parses to the Monday of that week.",20};2122const input = (attempt: number): DraftInput => ({23 attempt,24 context: {25 at: LandedSha.make("4".repeat(40)),26 files: [],27 policy: "kinds: fix",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 28why, one step back28 project: ProjectName.make("oscabriel/datekit"),Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
lines 29–57why, one step back29 },30 want: "Parse ISO week dates.",31});3233describe("the memory drafter", () => {34 it.effect(35 "answers its script in order, failures too, and keeps every input",36 () =>37 Effect.gen(function* () {38 const drafter = yield* Drafter;39 const failed = new DraftFailed({ reason: "schema" });4041 const first = yield* Effect.flip(drafter.draft(input(1)));42 const second = yield* drafter.draft(input(2));4344 expect(first).toStrictEqual(failed);45 expect(second).toStrictEqual(drafted);46 expect(47 (yield* DraftsAsked.use(({ inputs }) => inputs)).map(48 ({ attempt }) => attempt49 )50 ).toStrictEqual([1, 2]);51 }).pipe(52 Effect.provide(53 DrafterMemory([new DraftFailed({ reason: "schema" }), drafted])54 )55 )56 );57});