Assistant: codex Assistant-Model: gpt-6.1-sol Assistant-Session: 01a10391-6355-7b41-b0fa-3e14e874f091
56 lines
2.9 KiB
Python
56 lines
2.9 KiB
Python
"""Exact frozen sources retain bytes and bindings while new work stays canonical."""
|
|
import hashlib
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from repo_manager import historical_sources as hs
|
|
from repo_manager.identifiers import ensure_missing_work_record_identifiers
|
|
from repo_manager.record_identity import scan_record_identities
|
|
|
|
|
|
def _fixture(tmp_path,monkeypatch,repo='activity-core'):
|
|
root=tmp_path/repo
|
|
path=root/'workplans/old.md';path.parent.mkdir(parents=True)
|
|
rid='custodian-WP-0001' if repo=='activity-core' else 'CUST-WP-ADHOC-2026-08-25-RETIRED'
|
|
data=(f'---\nid: {rid}\ntype: workplan\nrepo: {repo}\nstatus: finished\n'
|
|
'state_hub_workstream_id: e22516cc-4fdf-4dad-a928-a9e04a9fa7c7\n---\n').encode()
|
|
path.write_bytes(data)
|
|
monkeypatch.setattr(hs,'BINDINGS',[dict(repo=repo,path='workplans/old.md',sha256=hashlib.sha256(data).hexdigest())])
|
|
prefix='ACTIVITY' if repo=='activity-core' else 'CUST'
|
|
current=root/'workplans/current.md'
|
|
current.write_text(f'---\nid: {prefix}-WP-9999\ntype: workplan\nstatus: active\n---\n')
|
|
return root,path,current,data
|
|
|
|
|
|
@pytest.mark.parametrize('repo',['activity-core','the-custodian'])
|
|
def test_frozen_source_retains_bytes_and_existing_uuid(tmp_path,monkeypatch,repo):
|
|
root,path,current,data=_fixture(tmp_path,monkeypatch,repo)
|
|
report=ensure_missing_work_record_identifiers(root)
|
|
assert path.read_bytes()==data
|
|
assert len(report['historical_invalid_identifiers'])==1
|
|
assert len(report['assignments'])==1 and report['assignments'][0]['path']=='workplans/current.md'
|
|
assert not scan_record_identities(root)['ok']
|
|
assert ensure_missing_work_record_identifiers(root)['assignments']==[]
|
|
|
|
|
|
@pytest.mark.parametrize('change',['id','uuid','status','missing','symlink','extra'])
|
|
def test_unreviewed_history_refuses_before_any_allocation(tmp_path,monkeypatch,change):
|
|
root,path,current,data=_fixture(tmp_path,monkeypatch)
|
|
original=current.read_bytes()
|
|
if change=='id':path.write_bytes(data.replace(b'custodian-WP-0001',b'custodian-WP-0002'))
|
|
elif change=='uuid':path.write_bytes(data.replace(b'e22516cc',b'f22516cc'))
|
|
elif change=='status':path.write_bytes(data.replace(b'finished',b'active'))
|
|
elif change=='missing':path.unlink()
|
|
elif change=='symlink':
|
|
path.unlink();target=root/'other.md';target.write_bytes(data);path.symlink_to(target)
|
|
else:(root/'workplans/unreviewed.md').write_bytes(data.replace(b'custodian-WP-0001',b'custodian-WP-0099'))
|
|
with pytest.raises(ValueError):ensure_missing_work_record_identifiers(root)
|
|
assert current.read_bytes()==original
|
|
|
|
|
|
def test_other_repo_cannot_inherit_frozen_exception(tmp_path,monkeypatch):
|
|
root,path,current,data=_fixture(tmp_path,monkeypatch)
|
|
other=root.with_name('other-repo');root.rename(other)
|
|
with pytest.raises(ValueError,match='identities are not safe'):
|
|
ensure_missing_work_record_identifiers(other)
|