---
id: 11646
title: Phase 5C — KB Unit Test Coverage Expansion (close 32-vs-12 parity gap with MC)
state: CLOSED
labels:
  - enhancement
  - ai
  - testing
assignees:
  - neo-gpt
createdAt: '2026-05-19T12:09:24Z'
updatedAt: '2026-05-20T06:02:10Z'
githubUrl: 'https://github.com/neomjs/neo/issues/11646'
author: neo-opus-ada
commentsCount: 0
parentIssue: 11643
subIssues: []
subIssuesCompleted: 0
subIssuesTotal: 0
blockedBy: []
blocking: []
closedAt: '2026-05-20T06:02:10Z'
---
# Phase 5C — KB Unit Test Coverage Expansion (close 32-vs-12 parity gap with MC)

## Context

Sub of Phase 5 Epic [#11643](https://github.com/neomjs/neo/issues/11643) (meta-Epic [#11624](https://github.com/neomjs/neo/issues/11624)).

**Cross-cutting; can start any time.** Audits + backfills KB unit test coverage gaps to approach MC parity.

## The Problem

Empirical parity gap (V-B-A grounded; **calibrated 2026-05-19T13:42Z per GPT epic-review on #11643** — initial path-glob was too broad):

Path-scoped counts (canonical `test/playwright/unit/ai/services/`):
- `memory-core/*.spec.mjs` (incl. subtree): **23 specs**
- `knowledge-base/*.spec.mjs` (incl. subtree): **17 specs**
- KB has ~74% of MC's unit test density

Initial framing (`find -path "*memory-core*"` → 32 vs `*knowledge-base*` → 12) swept broader subtrees including `ai/daemons/services/` and incorrect path roots. The path-scoped count is the canonical metric.

While the 6-spec delta is smaller than initially framed, substantial coverage gaps likely still exist in:

- `DatabaseService` (570 lines — orchestrator; backup/restore methods; lifecycle)
- `VectorService` (308 lines — embedding pipeline; content-hash delta; #10572 volume gate behavior)
- `QueryService` (222 lines — Chroma query construction)
- `SearchService` (170 lines — file hydration path)
- `HealthService` (374 lines — health surface)
- `KBRecorderService` (450 lines — telemetry pipeline; Memory Core SQLite integration)
- `ChromaManager` (142 lines — Chroma client lifecycle)

Operator framing: *"and /unit-tests too"* — explicit directive to close the gap.

## The Fix

1. **Audit current KB unit coverage** — for each KB service, enumerate public methods + identify which have unit-test coverage vs which don't. Produce gap report.
2. **Prioritize backfill targets** — focus on:
   - Methods that will be MODIFIED in Phase 0/1, 2, 4 (regression-protection priority)
   - Methods with non-trivial logic (error paths, edge cases, state transitions)
   - Methods that interact with shared substrate (Chroma, Memory Core SQLite, AgentIdentity)
3. **Backfill targeted unit tests** — author new `.spec.mjs` files OR extend existing specs
4. **Track parity progress** — measure KB spec count after backfill via path-scoped count of `test/playwright/unit/ai/services/knowledge-base/**/*.spec.mjs`; target ≥20 specs (~87% of MC's 23 path-scoped count; pragmatic V1 target)

## Acceptance Criteria

- [ ] KB unit-coverage audit report committed to `test/playwright/unit/ai/services/knowledge-base/COVERAGE_AUDIT.md` (or similar; format TBD by implementer)
- [ ] Backfill targets prioritized + documented; rationale per service
- [ ] At least 3 NEW unit spec files added (path-scoped 17 → ≥20)
- [ ] Coverage emphasizes Phase 0/1, 2, 4 modification surfaces (regression-protection priority)
- [ ] All new specs pass via `npm run test-unit` (NOT `npx playwright`)
- [ ] No flakiness introduced (existing test stability preserved)
- [ ] Optional: coverage tool report (istanbul / c8) showing pre/post backfill delta

## Out of Scope

- Integration tests (Phase 5A/B own that)
- E2E tests (Phase 2F owns that)
- Closing the FULL 32-spec gap if pragmatic 25+ is achievable in single sub (further backfill can spawn follow-up ticket if needed)
- Refactoring tested code to be more-testable (testing AS-IS; refactoring is separate concern)
- Performance regression testing

## Avoided Traps

| Trap | Why rejected |
|---|---|
| Distributing test backfill across Phase 0/1/2/4 subs silently | Without explicit cross-cutting ticket, the 32-vs-12 gap closes informally and unmeasurably |
| Targeting 100% method coverage | Diminishing returns; meta-Epic's other phases will land their own per-feature tests. 80% MC parity is pragmatic V1 |
| Over-engineering test-helper abstractions | Match existing KB unit test patterns; refactoring helpers is a separate concern |

## Related

- **Parent:** [#11643](https://github.com/neomjs/neo/issues/11643)
- **Empirical anchor:** `find test/playwright/unit/ai -path "*memory-core*" -name "*.spec.mjs" | wc -l` = 32; KB equivalent = 12 (verified 2026-05-19)
- **Reference patterns:** `test/playwright/unit/ai/memory-core/*.spec.mjs` (MC unit test conventions)

## Origin Session ID

`7360e917-1733-4cdd-a6f3-5ac51c34b838`

## Handoff Retrieval Hints

- Start with the audit phase — gap report INFORMS prioritization; don't backfill blindly
- Memory anchor: `feedback_npx_bypass_test_isolation.md` — `npm run test-unit` not `npx playwright`
- Memory anchor: `feedback_mcp_test_location.md` — KB unit tests under `test/playwright/unit/ai/knowledge-base/`
- `KBRecorderService.mjs` is high-priority backfill target — 450 lines + extends into Phase 4A
- `VectorService.mjs:188-274` is high-priority (Phase 0/1C modification surface)
- `QueryService.mjs:116-128` is high-priority (Phase 0/1D modification surface)



## Timeline

- 2026-05-19T12:09:26Z @neo-opus-ada added the `enhancement` label
- 2026-05-19T12:09:26Z @neo-opus-ada added the `ai` label
- 2026-05-19T12:09:26Z @neo-opus-ada added the `testing` label
- 2026-05-19T12:09:48Z @neo-opus-ada added parent issue #11643
- 2026-05-19T12:10:35Z @neo-opus-ada cross-referenced by #11624
- 2026-05-19T13:38:30Z @neo-gpt cross-referenced by #11643
- 2026-05-19T14:55:12Z @neo-opus-ada cross-referenced by PR #11648
- 2026-05-20T01:31:38Z @neo-gpt assigned to @neo-gpt
- 2026-05-20T01:38:06Z @neo-opus-ada cross-referenced by #11665
- 2026-05-20T01:43:50Z @neo-gpt cross-referenced by PR #11666
- 2026-05-20T01:50:36Z @neo-opus-ada cross-referenced by PR #11667
- 2026-05-20T06:02:10Z @tobiu referenced in commit `fabfa34` - "test(kb): expand service unit coverage (#11646) (#11666)

Co-authored-by: tobiu <tobiasuhlig78@gmail.com>"
- 2026-05-20T06:02:10Z @tobiu closed this issue

