Skip to content

feat(qa): rule-based consistency checker for MVP-β #14#40

Merged
DankerMu merged 1 commit into
mainfrom
feat/consistency-check
Feb 21, 2026
Merged

feat(qa): rule-based consistency checker for MVP-β #14#40
DankerMu merged 1 commit into
mainfrom
feat/consistency-check

Conversation

@DankerMu
Copy link
Copy Markdown
Owner

Summary

  • Implements 5 consistency checks: character_status, timeline, possession, plot_thread, repetition
  • API: POST /api/qa/check with project_id, ngram_n, ngram_threshold
  • Service: run_consistency_check() with scene indexing and KG analysis
  • Tests: 12 tests covering all check types and API endpoint

Changes

  • backend/app/api/qa.py: QA API endpoint
  • backend/app/services/consistency.py: Rule-based consistency checker (427 lines)
  • backend/tests/test_consistency.py: 12 comprehensive tests (318 lines)
  • backend/app/api/schemas.py: ConsistencyResult schema
  • backend/app/main.py: Register QA router
  • frontend/src/lib/types.ts: TypeScript types for consistency results

Test Plan

  • All 12 backend tests passing
  • Frontend UI integration (pending)
  • Manual testing with sample project

Closes #14

🤖 Generated with Claude Code

- M1: add project existence check (404) in QA endpoint
- M2: batch-fetch KGNode IDs in possession check (eliminate N+1)
- M3/M4: lower confidence to 0.6 when death/resolved location absent
- L1: rename _loads to _safe_loads for codebase consistency
- L2: move func import to module top level
- Add timeline conflict tests (2 tests)
- Add plot_thread conflict tests (2 tests)
- Fix line length and input validation (Pydantic Field)

All 16 tests passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DankerMu DankerMu force-pushed the feat/consistency-check branch from 683d841 to a38cb3a Compare February 21, 2026 04:23
Copy link
Copy Markdown
Owner Author

@DankerMu DankerMu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent Team Review - PASS (96/100)

Previous Findings Verification

ID Finding Status
M1 No project existence check ✅ FIXED
M2 N+1 queries in _check_possession ✅ FIXED
M3 confidence=1.0 misleading (character_status) ✅ FIXED
M4 confidence=1.0 misleading (plot_thread) ✅ FIXED
L1 _loads naming inconsistency ✅ FIXED
L2 Inline func import ✅ FIXED
CI Line too long ✅ FIXED
CI Merge commit ✅ FIXED

All 8 previous findings: FIXED.

Highlights

  • Batch-fetch pattern cleanly eliminates N+1
  • Confidence 1.0 vs 0.6 accurately communicates certainty
  • 16 tests covering all 5 check types with positive/negative cases
  • Pydantic Field validation prevents nonsensical inputs

Minor (non-blocking)

  • Missing 404 test for invalid project_id
  • KGProposal imported inside test functions instead of module top

Recommendation: Merge.

@DankerMu
Copy link
Copy Markdown
Owner Author

Agent Team Review - PASS (96/100)

All 8 previous findings verified as FIXED. 16 tests passing. CI green.

@DankerMu DankerMu merged commit 1e0d503 into main Feb 21, 2026
7 checks passed
@DankerMu DankerMu deleted the feat/consistency-check branch February 21, 2026 04:32
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.

Consistency Check: 规则引擎一致性校验

1 participant