rein-aharness/tests/test_fi_research_brief.py
tegwick 11020e8f00
Some checks failed
Governed runtime contract / contract (push) Failing after 26s
Publish FI briefs to origin or fail the day
FI-WP-0004 grants origin publication. Local commit without push no
longer posts fi_daily_brief (that cleared due while losing the file).
Prompt/context refuse re-announcing cataloged models and invented sizes.

Assistant: grok
Assistant-Session: 01a09c6a-1cfc-75b1-a78d-c13eaf22241d
2026-09-13 22:45:43 +02:00

106 lines
3 KiB
Python

from __future__ import annotations
import json
import subprocess
from datetime import date
from pathlib import Path
from rein_aharness import fi_research_brief
def _git(cwd: Path, *args: str) -> None:
subprocess.run(["git", "-C", str(cwd), *args], check=True, capture_output=True)
def _repo(tmp_path: Path) -> Path:
repo = tmp_path / "freedom-intelligence"
repo.mkdir()
subprocess.run(["git", "init", "-q", "-b", "main"], cwd=repo, check=True)
(repo / "README.md").write_text("baseline\n", encoding="utf-8")
subprocess.run(["git", "add", "."], cwd=repo, check=True)
subprocess.run(
[
"git",
"-c",
"user.email=test@example.invalid",
"-c",
"user.name=test",
"commit",
"-qm",
"baseline",
],
cwd=repo,
check=True,
)
return repo
def _with_origin(tmp_path: Path, repo: Path) -> Path:
remote = tmp_path / "origin.git"
subprocess.run(["git", "init", "--bare", "-q", "-b", "main", str(remote)], check=True)
_git(repo, "remote", "add", "origin", str(remote))
_git(repo, "push", "-u", "origin", "HEAD:main")
return remote
def _complete(_prompt: str) -> str:
return json.dumps(
{
"headline_deltas": ["No material delta after allowlist review."],
"axis_a": [],
"axis_b": [],
"axis_c": [],
"axis_d": [],
"collection_candidates": [],
"lab_implications": ["Recheck tomorrow."],
}
)
def test_fi_brief_pushes_to_origin_and_records_sha(tmp_path: Path) -> None:
repo = _repo(tmp_path)
_with_origin(tmp_path, repo)
result = fi_research_brief.run_fi_research_brief(
repo,
day=date(2026, 9, 13),
report_to_hub=False,
complete_fn=_complete,
)
assert result.ok is True
assert result.committed is True
assert result.pushed is True
assert result.origin_sha
remote_head = subprocess.run(
["git", "-C", str(tmp_path / "origin.git"), "rev-parse", "HEAD"],
check=True,
capture_output=True,
text=True,
).stdout.strip()
assert remote_head == result.origin_sha
brief = repo / "briefs" / "2026" / "09" / "2026-09-13.md"
assert brief.is_file()
def test_fi_brief_push_failure_is_not_a_completed_day(
tmp_path: Path, monkeypatch
) -> None:
repo = _repo(tmp_path)
posted: list[dict] = []
def fake_post(**kwargs):
posted.append(kwargs)
monkeypatch.setattr(fi_research_brief.hub, "post_progress_event", fake_post)
result = fi_research_brief.run_fi_research_brief(
repo,
day=date(2026, 9, 13),
report_to_hub=True,
complete_fn=_complete,
)
assert result.ok is False
assert result.committed is True
assert result.pushed is False
assert "origin publish failed" in result.reason
assert posted
assert posted[-1]["event_type"] == "executor_run"
assert posted[-1]["detail"]["pushed"] is False