Quick Start: Run Persistence Tests

Status note (documentation review): scripts/test_reasoning_protection.py no longer exists in the repository. This guide documents the ad hoc diagnostic script and methodology used to investigate a past task/issue/result persistence bug; it is kept as a reference for reproducing a similar diagnostic script if a similar persistence issue needs investigating again, not as a currently runnable test.

One-Command Test

# From the project root directory
.venv\Scripts\Activate.ps1
python scripts\test_reasoning_protection.py

What You'll See

Test 1-4: Protection Mechanism Tests (Expected Warnings/Errors)

These tests intentionally trigger errors to verify protection is working: - ❌ ERROR messages when writes happen without write_context ✓ EXPECTED - ⚠️ WARNING messages when reads happen without read_context ✓ EXPECTED

Test 5-7: CRITICAL PERSISTENCE TESTS (Look for PASS/FAIL)

Test 5: Task Persistence

Tests this scenario:

# Write
with doc.write_context(lock):
    task.set_status(TaskStatus.TS_IN_PROGRESS)
    task.set_description("Updated description")

# Read back
with doc.read_context():
    status = task.status()  # Should be TS_IN_PROGRESS
    desc = task.description()  # Should be "Updated description"

Result: ✓ Task persistence test PASSED or ❌ FAILED

Test 6: Issue Persistence

Same pattern as Test 5 but for issues (severity, status, description)

Result: ✓ Issue persistence test PASSED or ❌ FAILED

Test 7: Result Persistence

Same pattern but for task results (content)

Result: ✓ Result persistence test PASSED or ❌ FAILED

Final Summary

At the end you'll see:

ALL TESTS COMPLETED
==================================================
Persistence Test Results:
  • Task persistence:   ✓ PASSED (or ❌ FAILED)
  • Issue persistence:  ✓ PASSED (or ❌ FAILED)
  • Result persistence: ✓ PASSED (or ❌ FAILED)
==================================================

✓✓✓ ALL PERSISTENCE TESTS PASSED ✓✓✓

Exit Codes

If Tests Fail

The failing test output will show exactly what went wrong:

❌ Status NOT persisted! Expected TS_IN_PROGRESS, got ts_open
❌ Description NOT persisted! Expected 'Updated task description', got 'Initial task description'

Then check: 1. Look for ERROR/WARNING logs before the failure 2. Check if Neo4j operations succeeded (look for "Successfully saved") 3. Check if cache operations happened (look for "Cached document") 4. Enable more verbose logging if needed

Testing Different Scenarios

Test Just Task Persistence

Edit scripts/test_reasoning_protection.py main() to call only:

try:
    test_task_persistence()

Test With Debug Logging

Python 3.10+:

# Set environment to show debug logs
$env:LOG_LEVEL="DEBUG"
python scripts\test_reasoning_protection.py

Verify Cache is Working

Look for these in output:

✓ Using cached document state for write_context
✓ Using cached document state for read_context

If you see "Cache miss" frequently, cache isn't persisting between operations.

Troubleshooting

"ModuleNotFoundError" errors

"No tests passed" or immediate failure

Tests timeout

Success Criteria

✅ All three persistence tests (5, 6, 7) should show:

✓ Task/Issue/Result found
✓ Status persisted correctly
✓ Description/Content persisted correctly
✓ Task/Issue/Result persistence test PASSED

If you see any ❌ in tests 5-7, data is being lost somewhere in the write-read cycle.