Skip to content

feat: add CategoryStore with contract tests and in-memory implementation - #31

Merged
TechnicPotato merged 3 commits into
mainfrom
category-store
Nov 18, 2026
Merged

TechnicPotato merged 3 commits into
mainfrom
category-store

Conversation

@TechnicPotato

@TechnicPotato TechnicPotato commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

The category data layer, following the decisions in ADR 0001. Nothing is wired into the API or UI yet; tasks still use the category string.

Changes

  • Types (lib/categories/types.ts): Category (id, name) and the CategoryStore interface. create and rename return a CategoryWriteResult<Reason> discriminated union, so expected failures (name-taken, not-found) are part of the return type rather than thrown. get returns Category | null, and delete returns boolean.
  • Schemas (lib/categories/schemas.ts): a shared categoryNameSchema (trimmed, 1–50 characters, no /, and not the reserved "Uncategorized" label in any case), used by the create and rename input schemas. normalizeCategoryName is the single place that decides how names are compared.
  • Contract tests (category-store-contract.ts): 18 tests that every CategoryStore implementation must pass, covering case-insensitive uniqueness, two concurrent creates of the same name, case-only renames, names being freed after rename or delete, sorting, and returning copies.
  • In-memory store (in-memory-category-store.ts): passes the full contract. The name check and the save happen with no await in between, so concurrent creates can't both succeed.

Notes

  • The store checks uniqueness, and the schemas check format. The store assumes its input has already been validated, the same split as tasks.
  • Deleting a category doesn't touch tasks yet. Moving tasks to Uncategorized comes in step 8, once tasks have a categoryId.
  • The Firestore implementation (step 3) will run the same contract.

Test plan

  • vitest: 18/18 category contract tests pass against the in-memory store
  • Prettier, tsc and ESLint are clean on lib/categories/
  • CI: Test, Docker and Terraform pass

@TechnicPotato
TechnicPotato merged commit f3fba93 into main Nov 18, 2026
4 checks passed
@TechnicPotato
TechnicPotato deleted the category-store branch November 18, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant