Files
SkillFactory/tests/test_contact_cycle_gui_shutdown_v041.py
chenlin c528dd268f feat: checkpoint Go2 FL simulation performance v0.4.2
Include callable skill and live-GUI prerequisites, epoch sensor reads, packed snapshots, sampled bit-exact kinematics, and verified-tick rendering without changing the physical/control schedule.

Record bounded analytic S1 GUI/headless qualification, original failures and CPU evidence (1557 passed, 6 skipped). Preserve accepted_skill=false and sub-real-time limitations. Exclude native authorities, caches, large media and local delivery copies; retain sealed artifact digest.
2026-10-16 15:46:01 +08:00

60 lines
2.5 KiB
Python

"""CPU-only explicit shutdown ownership handoff; never accepts unknown GPU PIDs."""
import json
from pathlib import Path
import sys
from types import SimpleNamespace as NS
import pytest
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
import skill_launch_v4 as launch
import evaluate_cycle_functional_flow as runner
def guard(output):
def write(path, value):
path.write_text(json.dumps(value))
return NS(deadline=100., check=lambda **_: None, write=write)
def test_shutdown_no_receipt_never_releases(tmp_path):
gpu = NS(check=lambda *_: pytest.fail('No result means not ready to release'))
assert runner.release_shutdown(tmp_path, guard(tmp_path), gpu, None) is None
assert list(tmp_path.iterdir()) == []
@pytest.mark.parametrize('fault', ['missing_ready', 'gpu_fail', 'none'])
def test_shutdown_release_requires_ready_and_original_strict_live_check(tmp_path, fault):
receipt = {'shutdown_handoff_ready': fault != 'missing_ready'}
(tmp_path / 'worker-result.json').write_text(json.dumps(receipt))
def check(_):
if fault == 'gpu_fail':
raise RuntimeError('original GPU ownership failure')
return {'clean': False, 'task_compute': 'present and owned'}
gpu = NS(check=check)
if fault != 'none':
with pytest.raises(RuntimeError):
runner.release_shutdown(tmp_path, guard(tmp_path), gpu, None)
assert not (tmp_path / 'shutdown-release.json').exists()
else:
result = runner.release_shutdown(tmp_path, guard(tmp_path), gpu, None)
assert result['released'] and result['last_live_gpu']['clean'] is False
assert json.loads((tmp_path / 'shutdown-release.json').read_text()) == {
'worker_result_sha256': launch.b.digest(tmp_path / 'worker-result.json')}
launch.wait_shutdown_release(tmp_path, guard(tmp_path))
def test_worker_rejects_altered_release_digest(tmp_path):
(tmp_path / 'worker-result.json').write_text('{}')
(tmp_path / 'shutdown-release.json').write_text(json.dumps({'worker_result_sha256': '0' * 64}))
with pytest.raises(RuntimeError, match='identity_shutdown_release_mismatch'):
launch.wait_shutdown_release(tmp_path, guard(tmp_path))
def test_worker_wait_is_bounded_and_guarded(tmp_path, monkeypatch):
(tmp_path / 'worker-result.json').write_text('{}')
times = iter((0, 31))
monkeypatch.setattr(launch.b, 'boottime', lambda: next(times))
with pytest.raises(RuntimeError, match='process_shutdown_release_timeout'):
launch.wait_shutdown_release(tmp_path, guard(tmp_path))