Skip to content

feat: add schema drift detection (#50)#99

Open
Astro-Han wants to merge 2 commits intojackwener:mainfrom
Astro-Han:worktree-schema-drift
Open

feat: add schema drift detection (#50)#99
Astro-Han wants to merge 2 commits intojackwener:mainfrom
Astro-Han:worktree-schema-drift

Conversation

@Astro-Han
Copy link
Contributor

Summary

  • New src/drift.ts module with detectDrift() and formatDriftWarning() — standalone, no side effects
  • Warns on stderr when command output columns have >= 80% empty values, indicating upstream API schema changes
  • Integrated into main.ts between command execution and output rendering (warning only, no exit code change)
  • 14 unit tests covering all edge cases (threshold boundaries, mixed empty types, non-object rows, minimum sample guard)

Closes #50 (core detection layer — CI cron and LLM repair interface deferred to follow-up)

How it works

After a command executes and before output renders, detectDrift() checks each declared column's empty-value ratio (null, undefined, ''). If any column is >= 80% empty across valid object rows (minimum 3), a yellow warning is printed to stderr:

⚠ Schema drift detected (bilibili/hot):
  • field 'author' — empty in 15/15 rows (100%)
  • field 'danmaku' — empty in 12/15 rows (80%)

Test plan

  • npx vitest run src/drift.test.ts — 14 tests pass
  • npm run typecheck — no errors
  • npm run dev -- hackernews top --limit 3 — normal output, no false positive

- New `src/drift.ts` module with `detectDrift()` and `formatDriftWarning()`
- Warns on stderr when columns have >= 80% empty values
- Integrated into main.ts between command execution and output rendering
- 13 unit tests covering all edge cases
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.

Feature Request: daily contract check for API schema drift with test accounts

1 participant