Something went wrong. Try again.
personal memory agent
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090# SPDX-License-Identifier: AGPL-3.0-only# Copyright (c) 2026 sol pbc
"""Tests for think.segment."""
import argparseimport jsonimport logging
import pytest
from solstone.think.segment import cmd_inspect, cmd_list, cmd_move, cmd_verify
def _make_segment( base, day, stream, segment, *, stream_json=None, audio=True, screen=True, talents=None,): """Create a minimal segment fixture directory.""" seg_dir = base / "chronicle" / day / stream / segment seg_dir.mkdir(parents=True) if stream_json is not None: (seg_dir / "stream.json").write_text(json.dumps(stream_json)) if audio: (seg_dir / "audio.jsonl").write_text('{"t":0}\n') if screen: (seg_dir / "screen.jsonl").write_text('{"t":0}\n') if talents: talents_dir = seg_dir / "talents" talents_dir.mkdir() for name in talents: (talents_dir / name).write_text("# talent output\n") return seg_dir
def test_list_basic(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, talents=["audio.md"], ) _make_segment( tmp_path, "20240101", "default", "140000_300", stream_json={ "stream": "default", "prev_day": "20240101", "prev_segment": "090000_300", "seq": 2, }, talents=["audio.md", "screen.md"], )
args = argparse.Namespace( day="20240101", stream=None, json_output=False, subcommand="list" ) cmd_list(args) out = capsys.readouterr().out
assert "STREAM" in out assert "SEGMENT" in out assert "default" in out assert "090000_300" in out assert "140000_300" in out
def test_list_stream_filter(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) _make_segment( tmp_path, "20240101", "custom", "100000_300", stream_json={ "stream": "custom", "prev_day": None, "prev_segment": None, "seq": 1, }, )
args = argparse.Namespace( day="20240101", stream="default", json_output=False, subcommand="list" ) cmd_list(args) out = capsys.readouterr().out
assert "090000_300" in out assert "100000_300" not in out
def test_list_json(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, talents=["audio.md"], )
args = argparse.Namespace( day="20240101", stream=None, json_output=True, subcommand="list" ) cmd_list(args) data = json.loads(capsys.readouterr().out)
assert isinstance(data, list) assert data[0]["stream"] == "default" assert data[0]["segment"] == "090000_300" assert data[0]["talents"] == 1
def test_list_empty_day(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path))
args = argparse.Namespace( day="20240101", stream=None, json_output=False, subcommand="list" ) cmd_list(args) out = capsys.readouterr().out
assert "No segments found for 20240101" in out
def test_inspect_basic(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, talents=["audio.md"], )
args = argparse.Namespace( path="20240101/default/090000_300", json_output=False, subcommand="inspect" ) cmd_inspect(args) out = capsys.readouterr().out
assert "Segment: 20240101/default/090000_300" in out assert "Stream: default (seq 1)" in out assert "09:00:00 - 09:05:00" in out assert "stream.json" in out assert "audio.md" in out
def test_inspect_bad_path(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path))
args = argparse.Namespace(path="bad/path", json_output=False, subcommand="inspect") with pytest.raises(SystemExit) as excinfo: cmd_inspect(args)
err = capsys.readouterr().err assert excinfo.value.code == 1 assert "Segment path must be day/stream/segment" in err
def test_inspect_missing_segment(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path))
args = argparse.Namespace( path="20240101/default/090000_300", json_output=False, subcommand="inspect" ) with pytest.raises(SystemExit) as excinfo: cmd_inspect(args)
err = capsys.readouterr().err assert excinfo.value.code == 1 assert "Segment not found" in err
def test_inspect_json(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, talents=["audio.md"], )
args = argparse.Namespace( path="20240101/default/090000_300", json_output=True, subcommand="inspect" ) cmd_inspect(args) data = json.loads(capsys.readouterr().out)
assert data["stream"] == "default" assert data["segment"] == "090000_300" assert data["chain"]["prev"] == "(none)" assert "stats" in data
def test_inspect_chain(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) _make_segment( tmp_path, "20240101", "default", "140000_300", stream_json={ "stream": "default", "prev_day": "20240101", "prev_segment": "090000_300", "seq": 2, }, ) _make_segment( tmp_path, "20240101", "default", "180000_300", stream_json={ "stream": "default", "prev_day": "20240101", "prev_segment": "140000_300", "seq": 3, }, )
args = argparse.Namespace( path="20240101/default/140000_300", json_output=False, subcommand="inspect" ) cmd_inspect(args) out = capsys.readouterr().out
assert "prev: 20240101/default/090000_300" in out assert "next: 20240101/default/180000_300" in out
def test_verify_all_pass(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, screen=False, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/default/090000_300", day=None, json_output=False, subcommand="verify", ) with pytest.raises(SystemExit) as excinfo: cmd_verify(args)
out = capsys.readouterr().out assert excinfo.value.code == 0 assert "PASS directory exists" in out assert "PASS forward chain" in out assert "7/7 checks passed" in out
def test_verify_browser_content_passes(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) segment = _make_segment( tmp_path, "20240101", "suze.browser", "090000_300", stream_json={ "stream": "suze.browser", "prev_day": None, "prev_segment": None, "seq": 1, }, audio=False, screen=False, ) (segment / "browser_mail-google-com.jsonl").write_text( '{"t":"segment_start","ts":1}\n', encoding="utf-8", ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "suze.browser.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/suze.browser/090000_300", day=None, json_output=False, subcommand="verify", ) with pytest.raises(SystemExit) as excinfo: cmd_verify(args)
out = capsys.readouterr().out assert excinfo.value.code == 0 assert "PASS content files present" in out
def test_verify_missing_stream_json(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment(tmp_path, "20240101", "default", "090000_300", stream_json=None) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/default/090000_300", day=None, json_output=False, subcommand="verify", ) with pytest.raises(SystemExit) as excinfo: cmd_verify(args)
out = capsys.readouterr().out assert excinfo.value.code == 1 assert "FAIL stream.json exists: stream.json missing" in out
def test_verify_missing_content(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, audio=False, screen=False, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/default/090000_300", day=None, json_output=False, subcommand="verify", ) with pytest.raises(SystemExit) as excinfo: cmd_verify(args)
out = capsys.readouterr().out assert excinfo.value.code == 1 assert ( "FAIL content files present: no audio.jsonl, screen.jsonl, or browser_*.jsonl" in out )
def test_verify_broken_backward_chain(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "140000_300", stream_json={ "stream": "default", "prev_day": "20240101", "prev_segment": "090000_300", "seq": 2, }, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "140000_300", "seq": 2}) )
args = argparse.Namespace( path="20240101/default/140000_300", day=None, json_output=False, subcommand="verify", ) with pytest.raises(SystemExit) as excinfo: cmd_verify(args)
out = capsys.readouterr().out assert excinfo.value.code == 1 assert ( "FAIL backward chain: missing previous segment 20240101/default/090000_300" in out )
def test_verify_day_mode(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) _make_segment( tmp_path, "20240101", "default", "140000_300", stream_json={ "stream": "default", "prev_day": "20240101", "prev_segment": "090000_300", "seq": 2, }, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "140000_300", "seq": 2}) )
args = argparse.Namespace( path=None, day="20240101", json_output=False, subcommand="verify" ) with pytest.raises(SystemExit) as excinfo: cmd_verify(args)
out = capsys.readouterr().out assert excinfo.value.code == 0 assert "--- 20240101/default/090000_300 ---" in out assert "--- 20240101/default/140000_300 ---" in out assert "Summary: 14/14 checks passed" in out
def test_verify_json(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/default/090000_300", day=None, json_output=True, subcommand="verify", ) with pytest.raises(SystemExit) as excinfo: cmd_verify(args)
data = json.loads(capsys.readouterr().out) assert excinfo.value.code == 0 assert isinstance(data, list) assert any(item["check"] == "directory exists" for item in data)
def test_verify_reports_index_read_error(tmp_path, monkeypatch, capsys, caplog): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, screen=False, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) ) index_dir = tmp_path / "indexer" index_dir.mkdir() (index_dir / "journal.sqlite").write_bytes(b"not a sqlite database") caplog.set_level(logging.WARNING, logger="solstone.think.segment")
args = argparse.Namespace( path="20240101/default/090000_300", day=None, json_output=False, subcommand="verify", ) with pytest.raises(SystemExit) as excinfo: cmd_verify(args)
out = capsys.readouterr().out assert excinfo.value.code == 1 assert "FAIL index presence: journal index error:" in out assert "run: journal indexer --rescan" in out assert "journal index not available" not in out assert "Segment index read failed for 20240101/default/090000_300" in caplog.text assert "file is not a database" in caplog.text
def test_verify_no_args(tmp_path, monkeypatch, capsys): monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path))
args = argparse.Namespace( path=None, day=None, json_output=False, subcommand="verify" ) with pytest.raises(SystemExit) as excinfo: cmd_verify(args)
err = capsys.readouterr().err assert excinfo.value.code == 1 assert "verify requires a segment path or --day" in err
def test_main_no_subcommand(monkeypatch, capsys): from solstone.think.segment import main
monkeypatch.setattr("sys.argv", ["sol"]) with pytest.raises(SystemExit) as excinfo: main()
assert excinfo.value.code == 1
# --- move tests ---
def test_move_basic(tmp_path, monkeypatch, capsys): """Basic move from one day to another.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/default/090000_300", to_day="20240115", to_time=None, dry_run=False, subcommand="move", ) cmd_move(args)
assert not (tmp_path / "chronicle" / "20240101" / "default" / "090000_300").exists() assert (tmp_path / "chronicle" / "20240115" / "default" / "090000_300").is_dir() from solstone.think import streams
marker = streams.read_segment_stream( tmp_path / "chronicle" / "20240115" / "default" / "090000_300" ) assert marker["stream"] == "default" assert marker["seq"] == 1
def test_move_with_to_time(tmp_path, monkeypatch, capsys): """Move with --to-time changes the segment key, preserving duration.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/default/090000_300", to_day="20240101", to_time="140000", dry_run=False, subcommand="move", ) cmd_move(args)
assert not (tmp_path / "chronicle" / "20240101" / "default" / "090000_300").exists() assert (tmp_path / "chronicle" / "20240101" / "default" / "140000_300").is_dir()
def test_move_dry_run(tmp_path, monkeypatch, capsys): """--dry-run prints plan without moving.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/default/090000_300", to_day="20240115", to_time=None, dry_run=True, subcommand="move", ) cmd_move(args) out = capsys.readouterr().out
assert "[dry run]" in out assert "090000_300" in out assert (tmp_path / "chronicle" / "20240101" / "default" / "090000_300").is_dir()
def test_move_collision_no_to_time(tmp_path, monkeypatch, capsys): """Collision without --to-time is an error.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) _make_segment( tmp_path, "20240115", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240115", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/default/090000_300", to_day="20240115", to_time=None, dry_run=False, subcommand="move", ) with pytest.raises(SystemExit) as excinfo: cmd_move(args)
err = capsys.readouterr().err assert excinfo.value.code == 1 assert "already exists" in err
def test_move_no_events_jsonl(tmp_path, monkeypatch, capsys): """Segment with no events.jsonl moves cleanly.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, audio=False, screen=False, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/default/090000_300", to_day="20240115", to_time=None, dry_run=False, subcommand="move", ) cmd_move(args) out = capsys.readouterr().out
assert (tmp_path / "chronicle" / "20240115" / "default" / "090000_300").is_dir() assert "events.jsonl lines: 0" in out
def test_move_patches_successor(tmp_path, monkeypatch, capsys): """Moving a segment patches the successor's prev_day/prev_segment.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) _make_segment( tmp_path, "20240101", "default", "140000_300", stream_json={ "stream": "default", "prev_day": "20240101", "prev_segment": "090000_300", "seq": 2, }, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "140000_300", "seq": 2}) )
args = argparse.Namespace( path="20240101/default/090000_300", to_day="20240115", to_time=None, dry_run=False, subcommand="move", ) cmd_move(args)
from solstone.think import streams
succ_marker = streams.read_segment_stream( tmp_path / "chronicle" / "20240101" / "default" / "140000_300" ) assert succ_marker["prev_day"] == "20240115" assert succ_marker["prev_segment"] == "090000_300"
def test_move_stream_tail(tmp_path, monkeypatch, capsys): """Moving the stream tail (no successor) works cleanly.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) _make_segment( tmp_path, "20240101", "default", "140000_300", stream_json={ "stream": "default", "prev_day": "20240101", "prev_segment": "090000_300", "seq": 2, }, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "140000_300", "seq": 2}) )
args = argparse.Namespace( path="20240101/default/140000_300", to_day="20240115", to_time=None, dry_run=False, subcommand="move", ) cmd_move(args) out = capsys.readouterr().out
assert "successor to patch: (none - stream tail)" in out assert (tmp_path / "chronicle" / "20240115" / "default" / "140000_300").is_dir()
def test_move_rewrites_events_jsonl(tmp_path, monkeypatch, capsys): """events.jsonl day and segment fields are updated after move.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) seg_dir = _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, audio=False, screen=False, ) events = [ { "tract": "observe", "event": "start", "day": "20240101", "segment": "090000_300", }, {"tract": "think", "event": "done", "day": "20240101", "segment": "090000_300"}, ] (seg_dir / "events.jsonl").write_text( "\n".join(json.dumps(e) for e in events) + "\n" ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/default/090000_300", to_day="20240115", to_time="140000", dry_run=False, subcommand="move", ) cmd_move(args)
new_events_path = ( tmp_path / "chronicle" / "20240115" / "default" / "140000_300" / "events.jsonl" ) assert new_events_path.exists() lines = [ json.loads(line) for line in new_events_path.read_text().splitlines() if line.strip() ] assert all(event["day"] == "20240115" for event in lines) assert all(event["segment"] == "140000_300" for event in lines)
def test_move_touches_health_markers(tmp_path, monkeypatch, capsys): """Health markers are touched on both source and destination days.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, ) streams_dir = tmp_path / "streams" streams_dir.mkdir() (streams_dir / "default.json").write_text( json.dumps({"last_day": "20240101", "last_segment": "090000_300", "seq": 1}) )
args = argparse.Namespace( path="20240101/default/090000_300", to_day="20240115", to_time=None, dry_run=False, subcommand="move", ) cmd_move(args)
assert (tmp_path / "chronicle" / "20240101" / "health" / "stream.updated").exists() assert (tmp_path / "chronicle" / "20240115" / "health" / "stream.updated").exists()
def test_move_same_location_refused(tmp_path, monkeypatch, capsys): """Moving to the same location is refused.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, )
args = argparse.Namespace( path="20240101/default/090000_300", to_day="20240101", to_time=None, dry_run=False, subcommand="move", ) with pytest.raises(SystemExit) as excinfo: cmd_move(args) assert excinfo.value.code == 1 assert "same" in capsys.readouterr().err
def test_move_invalid_to_time(tmp_path, monkeypatch, capsys): """Invalid --to-time format is rejected.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, )
args = argparse.Namespace( path="20240101/default/090000_300", to_day="20240115", to_time="bad", dry_run=False, subcommand="move", ) with pytest.raises(SystemExit) as excinfo: cmd_move(args) assert excinfo.value.code == 1 assert "Invalid --to-time" in capsys.readouterr().err
def test_move_invalid_to_day(tmp_path, monkeypatch, capsys): """Invalid --to-day format is rejected.""" monkeypatch.setenv("SOLSTONE_JOURNAL", str(tmp_path)) _make_segment( tmp_path, "20240101", "default", "090000_300", stream_json={ "stream": "default", "prev_day": None, "prev_segment": None, "seq": 1, }, )
args = argparse.Namespace( path="20240101/default/090000_300", to_day="not-a-day", to_time=None, dry_run=False, subcommand="move", ) with pytest.raises(SystemExit) as excinfo: cmd_move(args) assert excinfo.value.code == 1 assert "Invalid --to-day" in capsys.readouterr().err