---
estimated_steps: 18
estimated_files: 2
skills_used: []
---

# T03: Update test harness for new body_sections structure and add citation reporting

Update the test harness word-count and section-count logic to walk the new list-of-objects body_sections structure instead of dict.values(). Add citation coverage reporting using the citation_utils from T01. This closes the slice — the harness can parse and report on v2 synthesis output.

## Steps

1. Read `backend/pipeline/test_harness.py` fully.
2. Read `backend/pipeline/schemas.py` (updated in T01) and `backend/pipeline/citation_utils.py` (created in T01).
3. Update line ~283-289 (per-page summary in `run_synthesis`): replace `sections.values()` iteration with walking `BodySection` objects. Word count = sum of `section.content` words + sum of all `subsection.content` words. Section count = len(body_sections). Report subsection count too.
4. Update line ~457 (metadata total_words): same dict→list-of-objects change for the output metadata calculation.
5. Add citation reporting after per-page summary: import `validate_citations` from citation_utils, call it with `page.body_sections` and `len(page.moment_indices)`, log citation coverage % and any invalid indices.
6. Create a small test script `backend/pipeline/test_harness_v2_format.py` that:
   - Constructs a mock SynthesisResult with the new body_sections format (list of BodySection objects)
   - Verifies word counting works correctly (known content → expected count)
   - Verifies citation validation integrates correctly
   - Does NOT require an LLM call

## Must-Haves

- [ ] Word count logic handles list[BodySection] including subsection content
- [ ] Section count reports H2 count and subsection count
- [ ] Citation coverage logged per-page
- [ ] Metadata total_words uses new structure
- [ ] Test script passes with mock v2 data

## Inputs

- ``backend/pipeline/test_harness.py` — current harness with dict-based word counting`
- ``backend/pipeline/schemas.py` — updated schema from T01`
- ``backend/pipeline/citation_utils.py` — citation utilities from T01`

## Expected Output

- ``backend/pipeline/test_harness.py` — updated word-count/section-count logic for list[BodySection]`
- ``backend/pipeline/test_harness_v2_format.py` — test script validating harness handles v2 format`

## Verification

cd /home/aux/projects/content-to-kb-automator && python -m pytest backend/pipeline/test_harness_v2_format.py -v && python -m pytest backend/pipeline/test_citation_utils.py -v
