MicroFish/backend/tests/interviews
Christian Moellmann 6e1489fe08 fix(interviews): wire Zep updater/memory/hooks correctly for production runs (C1-C5)
Five tightly-coupled fixes that were causing the interview subsystem to silently
degrade in production:

- C1+C2: `_build_orchestrator` now resolves `graph_id` from
  `SimulationManager().get_simulation(sim_id).graph_id` (the real persisted
  state) instead of a `graph_id.txt` that nothing in the codebase writes.
  `ZepGraphMemoryUpdater(graph_id=...)` is now called with the correct
  positional argument; the bare `try/except Exception` that was swallowing the
  TypeError is replaced with a narrow fallback that logs explicitly.
- C3: `SimulationManager._on_ready_hooks` / `_on_completed_hooks` are now
  class-level (mirroring `SimulationRunner._on_completed_callbacks`).
  Hooks registered at app startup now survive across the per-request
  `SimulationManager()` instances created by the Flask API, so the T0
  longitudinal auto-survey actually fires.
- C4: `ZepGraphMemoryUpdater` gains an explicit `add_text_episode(graph_id, text)`
  method for synchronous text writes. `InterviewZepWriter._emit` no longer
  silently falls back to a dict-shaped `add_activity` call that the real
  implementation rejects (its `add_activity` requires an `AgentActivity`
  dataclass).
- C5: `FileSystemPersonaProvider.agent_to_entity()` builds an
  `{agent_id: zep_entity_uuid}` map from the persisted profile files; the map
  is now passed to `ZepMemoryProvider` so `get_entity_with_context` is called
  with real Zep UUIDs instead of `str(agent_id)`. To make this work,
  `OasisProfileGenerator._save_reddit_json` and `_save_twitter_csv` now persist
  `source_entity_uuid` (Reddit JSON: optional field; Twitter CSV: appended
  column).

Tests: 51 unit + 2 integration pass (was 40 + 2). New tests lock in each fix:
- `test_hooks_survive_across_instances` (C3)
- `test_build_orchestrator_reads_graph_id_from_state` (C1+C2+C5)
- `test_build_orchestrator_falls_back_when_state_missing` (C1+C2)
- `test_emit_uses_add_text_episode_with_graph_id`,
  `test_emit_raises_when_updater_lacks_add_text_episode`,
  `test_real_updater_exposes_add_text_episode` (C4)
- `test_agent_to_entity_from_reddit_json`,
  `test_agent_to_entity_empty_when_no_field`,
  `test_agent_to_entity_falls_back_to_twitter_csv`,
  `test_agent_to_entity_reddit_takes_precedence` (C5)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 13:27:47 +02:00
..
__init__.py feat(interviews): add pydantic models for instruments and responses 2026-05-23 12:04:45 +02:00
test_adapters.py fix(interviews): wire Zep updater/memory/hooks correctly for production runs (C1-C5) 2026-05-23 13:27:47 +02:00
test_api_interview.py fix(interviews): wire Zep updater/memory/hooks correctly for production runs (C1-C5) 2026-05-23 13:27:47 +02:00
test_base_interviewer.py feat(interviews): StakeholderInterviewer base with in-character prompting and schema retry 2026-05-23 12:10:01 +02:00
test_delphi.py feat(interviews): Delphi subagent (3 rounds: open, rate, revise) + convergence metrics 2026-05-23 12:19:07 +02:00
test_diversity.py feat(interviews): diversity subagent with Q-sort + 6 Likert axes + PCA/k-means typology 2026-05-23 12:16:21 +02:00
test_instrument_loader.py feat(interviews): YAML instrument loader with pydantic validation and hash freezing 2026-05-23 12:06:52 +02:00
test_lifecycle.py feat(interviews): auto-trigger lifecycle hooks + bridge SimulationRunner→Manager on COMPLETED 2026-05-23 12:51:13 +02:00
test_llm_stub.py feat(interviews): LLM stub mode for deterministic CI tests 2026-05-23 12:08:29 +02:00
test_longitudinal.py feat(interviews): longitudinal subagent + 12-item Likert instrument 2026-05-23 12:12:46 +02:00
test_models.py feat(interviews): add pydantic models for instruments and responses 2026-05-23 12:04:45 +02:00
test_orchestrator.py feat(interviews): orchestrator with two-phase lifecycle, parallel fan-out, isolated failures 2026-05-23 12:27:47 +02:00
test_scenario.py feat(interviews): scenario subagent with 4 futures × 4 dimensions + polarity matrix 2026-05-23 12:21:21 +02:00
test_simulation_hooks.py fix(interviews): wire Zep updater/memory/hooks correctly for production runs (C1-C5) 2026-05-23 13:27:47 +02:00
test_storage.py feat(interviews): JSONL/JSON storage layout with run_id directories and latest pointer 2026-05-23 12:23:06 +02:00
test_synthesizer.py feat(interviews): synthesiser emits cross-method report + tidy CSV + limitations section 2026-05-23 12:32:14 +02:00
test_zep_writer.py fix(interviews): wire Zep updater/memory/hooks correctly for production runs (C1-C5) 2026-05-23 13:27:47 +02:00