Skip to content

feat: validate kiqr.yaml and config.yaml with zod schemas - #11

Merged
kjellberg merged 1 commit into
kiqr:mainfrom
kjellbergzoey:feat/zod-config-validation
Jun 7, 2026
Merged

feat: validate kiqr.yaml and config.yaml with zod schemas#11
kjellberg merged 1 commit into
kiqr:mainfrom
kjellbergzoey:feat/zod-config-validation

Conversation

@kjellbergzoey

Copy link
Copy Markdown
Contributor

Summary

Replaces the unsafe YAML.parse(content) as ProjectConfig / as LocalConfig casts in src/lib/config.ts with zod schema parsing (zod is already a dependency).

A malformed or hand-edited kiqr.yaml / config.yaml now fails fast with a clear, actionable message instead of crashing somewhere downstream:

  • Validation failure: kiqr.yaml is invalid: name: ... (file + field named)
  • Bad YAML syntax: config.yaml is not valid YAML: <detail>

Details

  • Schemas are defined alongside the readers and constrained to the existing interfaces in src/types/config.ts via satisfies z.ZodType<ProjectConfig> / <LocalConfig>. This keeps the public TS types and every import of them unchanged, and the satisfies check guarantees the schemas stay in sync with the types at compile time.
  • A small helper flattens zod issues into a single readable line.

Tests

Adds coverage in tests/lib/config.test.ts:

  • valid config parses (existing tests still pass)
  • missing required field throws a clear, file+field-scoped error
  • wrong field type throws
  • malformed YAML throws the "not valid YAML" error
  • both kiqr.yaml and config.yaml

npm run typecheck, npm test (75 passing), and npm run build all green.

🤖 Generated with Claude Code

Replace the unsafe `YAML.parse(content) as ProjectConfig` / `as LocalConfig`
casts in src/lib/config.ts with zod schema parsing. A malformed or
hand-edited config now produces a clear, actionable error naming the file
and the offending field (e.g. "kiqr.yaml is invalid: name: ...") instead
of a cryptic downstream crash, and invalid YAML reports
"<file> is not valid YAML: <detail>".

The schemas are constrained to the existing interfaces in
src/types/config.ts via `satisfies z.ZodType<...>`, so the public TS types
and all their imports are unchanged.

Adds tests covering valid parse, missing required field, wrong field type,
and malformed YAML for both config files.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kjellberg
kjellberg merged commit 3c80540 into kiqr:main Jun 7, 2026
3 checks passed
kjellbergzoey added a commit to kjellbergzoey/cli that referenced this pull request Jun 7, 2026
Adds @biomejs/biome with a project config (biome.json): 2-space indent,
single quotes, no bracket spacing, organize-imports, recommended lint
rules (with a few project-specific rules disabled where they clash with
the strict tsconfig or Ink/React patterns). Adds 'lint' and 'format'
npm scripts and a dedicated lint job in CI.

The large diff is the one-time 'biome check --write' format pass over
the existing codebase. Two lint fixes beyond formatting: a string-concat
-> template literal in db/list.tsx, and an empty destructure pattern in
wp.tsx.

Rebuilt on current main (post kiqr#11-kiqr#16) to resolve merge conflicts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
kjellberg pushed a commit that referenced this pull request Jun 7, 2026
Adds @biomejs/biome with a project config (biome.json): 2-space indent,
single quotes, no bracket spacing, organize-imports, recommended lint
rules (with a few project-specific rules disabled where they clash with
the strict tsconfig or Ink/React patterns). Adds 'lint' and 'format'
npm scripts and a dedicated lint job in CI.

The large diff is the one-time 'biome check --write' format pass over
the existing codebase. Two lint fixes beyond formatting: a string-concat
-> template literal in db/list.tsx, and an empty destructure pattern in
wp.tsx.

Rebuilt on current main (post #11-#16) to resolve merge conflicts.

Co-authored-by: kjellbergzoey <kjellbergzoey@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants