state-hub/tests/test_brief_generation.py
tegwick 39b51a21a5
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s
Build and Publish Multi-Context Image / build-and-push (push) Successful in 28s
Keep generated orientation briefs local without Git writeback
Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a15374-f59f-7a31-86d2-d23b5d2ed181
2026-10-19 13:46:45 +02:00

49 lines
2.2 KiB
Python

"""Rendering-only briefs must preserve existing data on incomplete API snapshots."""
from unittest.mock import Mock
import pytest
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
import consistency_check as owner
def responses(base, path, params=None, **kwargs):
if path.startswith('/repos/'):
return {'id': 'repo-1', 'domain_slug': 'infotech'}
return []
def test_render_does_not_commit_and_timestamp_only_retry_is_unchanged(tmp_path, monkeypatch):
monkeypatch.setattr(owner, '_api_get', responses)
commit = Mock(side_effect=AssertionError('Git operations forbidden'))
monkeypatch.setattr(owner, '_git_commit_writeback', commit)
assert owner._write_custodian_brief('unused', 'demo', str(tmp_path), strict=True)
before = (tmp_path / '.custodian-brief.md').read_bytes()
assert not owner._write_custodian_brief('unused', 'demo', str(tmp_path), strict=True)
assert (tmp_path / '.custodian-brief.md').read_bytes() == before
commit.assert_not_called()
@pytest.mark.parametrize('failed_path', ['/repos/demo', '/workplans', '/repo-goals', '/messages', '/tasks'])
@pytest.mark.parametrize('failure', [None, {'_error': 'offline'}, 'malformed'])
def test_partial_snapshot_preserves_existing_brief(tmp_path, monkeypatch, failed_path, failure):
def read(base, path, params=None, **kwargs):
if path == failed_path:
return failure
if path == '/workplans':
return [{'id': 'wp-1', 'title': 'Waiting'}]
return responses(base, path, params, **kwargs)
monkeypatch.setattr(owner, '_api_get', read)
path = tmp_path / '.custodian-brief.md'; path.write_text('preserved')
with pytest.raises(ValueError, match='unavailable or malformed'):
owner._write_custodian_brief('unused', 'demo', str(tmp_path), strict=True)
assert path.read_text() == 'preserved'
def test_check_has_no_write(tmp_path, monkeypatch):
monkeypatch.setattr(owner, '_api_get', responses)
path = tmp_path / '.custodian-brief.md'; path.write_text('preserved')
with pytest.raises(ValueError, match='differs'):
owner._write_custodian_brief('unused', 'demo', str(tmp_path), strict=True, check=True)
assert path.read_text() == 'preserved'