Skip to content

Add unit tests for src/cli/ui/presets.ts #100

@esengine

Description

@esengine

Background

src/cli/ui/presets.ts defines the three model bundles (auto / flash / pro) and two pure helpers — resolvePreset and canonicalPresetName — used wherever the CLI maps a preset name to model + reasoning settings. The helpers also keep three legacy aliases alive (fastflash+high, smartauto, maxpro) so older config.json files don't break.

There are zero tests for this file. A drift on the alias table or a typo in the legacy mapping would silently change every user's session settings — exactly the kind of thing a small unit-test file pins down forever.

Current state

  • src/cli/ui/presets.ts (~80 lines) — pure functions only, no I/O, no React
  • tests/presets.test.ts — does not exist

Expected behaviour

A new tests/presets.test.ts exercising the public surface:

  • resolvePreset("auto") / "flash" / "pro" — returns the canonical bundle
  • resolvePreset("fast") — returns flash but with reasoningEffort: "high" (alias rewires effort)
  • resolvePreset("smart") — returns the auto bundle byte-for-byte
  • resolvePreset("max") — returns the pro bundle byte-for-byte
  • resolvePreset(undefined) and unknown names — fall through to auto
  • canonicalPresetName(...) — only returns "auto" | "flash" | "pro"; legacy and unknown values normalize to "auto"
  • Branch / harvest invariant — every preset has harvest: false and branch: 1 (the project rule that branch and harvest are NEVER auto-enabled)

Files to touch

  • tests/presets.test.ts (new, ~50-80 lines)

Acceptance criteria

  • All 6+ behaviours above covered with it(...) blocks
  • An invariant test asserts that every entry in PRESETS has harvest === false && branch === 1 (so the rule is enforced even if a future preset is added)
  • No new dependencies; uses existing vitest setup
  • npm run verify passes

Hints

  • Look at tests/clipboard.test.ts (closed via Add unit tests for src/cli/ui/clipboard.ts #18) for the shape of a small pure-function test file in this repo.
  • Use describe("resolvePreset", () => { ... }) / describe("canonicalPresetName", () => { ... }) blocks.
  • For the invariant test: for (const [name, p] of Object.entries(PRESETS)) + a single expect(p.harvest).toBe(false) plus expect(p.branch).toBe(1).
  • Don't import PresetName from config.ts if you don't need it — the helpers accept string | undefined semantically; cast at the call site.

Out of scope

  • Adding new presets
  • Changing the alias table (the legacy mappings exist for a reason — old configs still load)
  • React / Ink component tests

Difficulty

2 hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions