Skip to content

test(integration): refine() round-trip integration tests — closes #106#124

Merged
CodeNinjaSarthak merged 2 commits into
mainfrom
test/refine-integration
May 4, 2026
Merged

test(integration): refine() round-trip integration tests — closes #106#124
CodeNinjaSarthak merged 2 commits into
mainfrom
test/refine-integration

Conversation

@CodeNinjaSarthak

Copy link
Copy Markdown
Owner

Summary

  • Adds tests/integration/test_refine_roundtrip.py with 6 integration tests covering the full SessionManager.refine() lifecycle against FakeAsyncRedis (no mocks, real state persistence)
  • Fixes a data-loss bug on the no-op refinement path: when re_derive_brief returns an identical brief the background task was restoring status="complete" but leaving plan=None and findings=None because new_state already had them cleared; now original_plan and original_findings are captured before clearing and explicitly restored in the noop branch

Tests added

Test What it covers
test_refine_full_pipeline_runs_and_persists_final_state Full pipeline runs, state is complete, plan and cost records persist
test_refine_noop_skips_pipeline_and_restores_complete Identical brief → pipeline skipped, original plan preserved
test_refine_lock_is_released_after_completion Lock is released after background task finishes
test_refine_rejects_at_iteration_cap ValueError raised when iteration >= MAX_REFINEMENTS
test_refine_rejects_duplicate_of_last_history_answer ValueError raised for duplicate input
test_refine_raises_409_when_lock_already_held RefinementInProgressError raised when lock is pre-held

Production fix (manager.py)

refine() now captures original_plan / original_findings before nulling them and passes both to _run_refinement. The noop branch restores them so a no-op refinement leaves the session data fully intact.

Closes #106.

Test plan

  • uv run pytest tests/ --no-cov — 375 passed, 3 skipped
  • All 6 new integration tests pass
  • Pre-commit hooks (black, isort, ruff, mypy, bandit) all pass

When re_derive_brief returns an identical brief the background task
skipped the pipeline but rebuilt noop_state from new_state (which
already had plan=None and findings=None), silently losing both fields.

Fix: capture original_plan and original_findings in refine() before
clearing them, thread them through _run_refinement's signature, and
restore them explicitly in the noop branch.

Closes #106.
@CodeNinjaSarthak CodeNinjaSarthak merged commit f3c5b27 into main May 4, 2026
2 checks passed
@CodeNinjaSarthak CodeNinjaSarthak deleted the test/refine-integration branch May 4, 2026 11:54
CodeNinjaSarthak added a commit that referenced this pull request May 5, 2026
#124)

* test: integration test for full refine() round-trip with real SessionState persistence

Closes #106.

* fix: restore plan and findings on no-op refinement path

When re_derive_brief returns an identical brief the background task
skipped the pipeline but rebuilt noop_state from new_state (which
already had plan=None and findings=None), silently losing both fields.

Fix: capture original_plan and original_findings in refine() before
clearing them, thread them through _run_refinement's signature, and
restore them explicitly in the noop branch.

Closes #106.
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.

test: integration test for full refine() round-trip with real SessionState persistence

1 participant