From 754fbe5c3022e2b5f17e9e9bd4d377b54d066931 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Tue, 24 Feb 2026 22:06:33 -0500 Subject: [PATCH] test(integration): Verify history persistence and AI context inclusion --- tests/test_ai_context_history.py | 25 ++++++++++++++++++ tests/test_history_persistence.py | 44 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tests/test_ai_context_history.py create mode 100644 tests/test_history_persistence.py diff --git a/tests/test_ai_context_history.py b/tests/test_ai_context_history.py new file mode 100644 index 0000000..d8c048d --- /dev/null +++ b/tests/test_ai_context_history.py @@ -0,0 +1,25 @@ +import pytest +import tomli_w +from pathlib import Path +import aggregate +import project_manager + +def test_aggregate_includes_segregated_history(tmp_path): + proj_path = tmp_path / "manual_slop.toml" + hist_path = tmp_path / "manual_slop_history.toml" + + # Setup segregated project + proj_data = project_manager.default_project("test-aggregate") + proj_data["discussion"]["discussions"]["main"]["history"] = ["@2026-02-24T14:00:00\nUser:\nShow me history"] + + # Save (will segregate) + project_manager.save_project(proj_data, proj_path) + + # Run aggregate + loaded_proj = project_manager.load_project(proj_path) + config = project_manager.flat_config(loaded_proj) + + markdown, output_file, file_items = aggregate.run(config) + + assert "## Discussion History" in markdown + assert "Show me history" in markdown diff --git a/tests/test_history_persistence.py b/tests/test_history_persistence.py new file mode 100644 index 0000000..879ad9a --- /dev/null +++ b/tests/test_history_persistence.py @@ -0,0 +1,44 @@ +import pytest +import tomli_w +import tomllib +from pathlib import Path +from project_manager import load_project, save_project, default_project, entry_to_str + +def test_history_persistence_across_turns(tmp_path): + proj_path = tmp_path / "manual_slop.toml" + hist_path = tmp_path / "manual_slop_history.toml" + + # 1. Start project + proj = default_project("test-persistence") + save_project(proj, proj_path) + + # 2. Add a turn + proj = load_project(proj_path) + entry1 = {"role": "User", "content": "Hello", "ts": "2026-02-24T13:00:00"} + proj["discussion"]["discussions"]["main"]["history"].append(entry_to_str(entry1)) + save_project(proj, proj_path) + + # Verify separation + with open(proj_path, "rb") as f: + p_disk = tomllib.load(f) + assert "discussion" not in p_disk + + with open(hist_path, "rb") as f: + h_disk = tomllib.load(f) + assert h_disk["discussions"]["main"]["history"] == ["@2026-02-24T13:00:00\nUser:\nHello"] + + # 3. Add another turn + proj = load_project(proj_path) + entry2 = {"role": "AI", "content": "Hi there!", "ts": "2026-02-24T13:01:00"} + proj["discussion"]["discussions"]["main"]["history"].append(entry_to_str(entry2)) + save_project(proj, proj_path) + + # Verify persistence + with open(hist_path, "rb") as f: + h_disk = tomllib.load(f) + assert len(h_disk["discussions"]["main"]["history"]) == 2 + assert h_disk["discussions"]["main"]["history"][1] == "@2026-02-24T13:01:00\nAI:\nHi there!" + + # 4. Reload and check + proj_final = load_project(proj_path) + assert len(proj_final["discussion"]["discussions"]["main"]["history"]) == 2