57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
import pytest
|
|
import tomli_w
|
|
import tomllib
|
|
from pathlib import Path
|
|
from project_manager import load_project, save_project, default_project
|
|
|
|
def test_migration_on_load(tmp_path):
|
|
# Setup legacy project file with discussion
|
|
proj_path = tmp_path / "manual_slop.toml"
|
|
hist_path = tmp_path / "manual_slop_history.toml"
|
|
|
|
legacy_data = default_project("test-project")
|
|
legacy_data["discussion"]["discussions"]["main"]["history"] = ["Hello", "World"]
|
|
|
|
with open(proj_path, "wb") as f:
|
|
tomli_w.dump(legacy_data, f)
|
|
|
|
# Load project - should trigger migration
|
|
loaded_data = load_project(proj_path)
|
|
|
|
# Assertions
|
|
assert "discussion" in loaded_data
|
|
assert loaded_data["discussion"]["discussions"]["main"]["history"] == ["Hello", "World"]
|
|
|
|
# Check that it's NOT in the main file on disk anymore
|
|
with open(proj_path, "rb") as f:
|
|
on_disk = tomllib.load(f)
|
|
assert "discussion" not in on_disk
|
|
|
|
# Check history file
|
|
assert hist_path.exists()
|
|
with open(hist_path, "rb") as f:
|
|
hist_data = tomllib.load(f)
|
|
assert hist_data["discussions"]["main"]["history"] == ["Hello", "World"]
|
|
|
|
def test_save_separation(tmp_path):
|
|
# Setup fresh project data
|
|
proj_path = tmp_path / "manual_slop.toml"
|
|
hist_path = tmp_path / "manual_slop_history.toml"
|
|
|
|
proj_data = default_project("test-project")
|
|
proj_data["discussion"]["discussions"]["main"]["history"] = ["Saved", "Separately"]
|
|
|
|
# Save project - should save both files
|
|
save_project(proj_data, proj_path)
|
|
|
|
assert proj_path.exists()
|
|
assert hist_path.exists()
|
|
|
|
with open(proj_path, "rb") as f:
|
|
p = tomllib.load(f)
|
|
assert "discussion" not in p
|
|
|
|
with open(hist_path, "rb") as f:
|
|
h = tomllib.load(f)
|
|
assert h["discussions"]["main"]["history"] == ["Saved", "Separately"]
|