"""Tests for session management."""

from regimen.session import Session, StepResult, make_slug


def test_make_slug():
    slug = make_slug("path/to/checks.md")
    assert slug.startswith("checks-")
    assert len(slug) > 8


def test_session_save_load(tmp_path, monkeypatch):
    monkeypatch.setattr("regimen.session.SESSION_DIR", tmp_path / ".regimen")

    session = Session(
        slug="test-abc123",
        file_path="/tmp/test.md",
        regimen_title="Test",
        total_steps=2,
        current_step=1,
        created_at=1000.0,
        status="active",
        results=[
            StepResult(
                outputs=[{"command": "echo hi", "stdout": "hi\n", "stderr": "", "exit_code": 0}],
            )
        ],
    )
    session.save()

    loaded = Session.load("test-abc123")
    assert loaded.slug == "test-abc123"
    assert loaded.current_step == 1
    assert loaded.total_steps == 2
    assert len(loaded.results) == 1
    assert loaded.results[0].outputs[0]["exit_code"] == 0
    assert loaded.results[0].run_count == 1
