diff --git a/tests/test_monitoring.py b/tests/test_monitoring.py index 9df4b81..e7db466 100644 --- a/tests/test_monitoring.py +++ b/tests/test_monitoring.py @@ -75,25 +75,26 @@ def fail(*a,**kw):raise OSError('SECRET-CREDENTIAL-MUST-NOT-LEAK') monkeypatch.undo() assert writer.export() and decode_snapshot(path.read_bytes())['monitoring_export_failures']==1 -def test_local_registration_provider_cache_presentation(tmp_path,snapshot): - path=tmp_path/'snapshot.json';writer=TelemetryWriter(path,snapshot);writer.update(metrics={'loss/ce':.7}) - registry=tmp_path/'registry.json';register(registry,path,'local') - batch=collect_snapshots(registry) - env=merge_snapshots(None,batch) - view=presentation(env) +def test_local_registration_preserves_last_valid_snapshot(tmp_path, snapshot): + path = tmp_path / 'snapshot.json' + assert TelemetryWriter(path, snapshot).update(metrics={'loss/ce': .7}) + registry = tmp_path / 'registry.json' + register(registry, path, 'local') + env = merge_snapshots(None, collect_snapshots(registry)) + view = presentation(env) assert len(view['runs'])==1 and view['runs'][0]['association']['status']=='local' assert view['runs'][0]['provider_status']['skypilot'] is None assert view['runs'][0]['git_url'].endswith('/commit/'+'a'*40) assert view['runs'][0]['resume']['capable'] is False assert not view['warnings'] -def test_corrupt_source_keeps_last_valid_and_reports_error(tmp_path,snapshot): - path=tmp_path/'snapshot.json';TelemetryWriter(path,snapshot).export() - registry=tmp_path/'registry.json';register(registry,path,'local') - env=merge_snapshots(None,collect_snapshots(registry)) + last_valid = copy.deepcopy(env['records']) + assert last_valid[0]['snapshot']['metrics'] == {'loss/ce': .7} path.write_text('{corrupt') - merged=merge_snapshots(env,collect_snapshots(registry)) - assert len(merged['records'])==1 and merged['warnings'] + merged = merge_snapshots(env, collect_snapshots(registry)) + assert merged['records'] == last_valid + warnings = [(warning['source_id'], warning['code']) for warning in merged['warnings']] + assert warnings == [('local', 'source_unavailable_or_invalid')] def test_disabled_optional_transports_not_imported(tmp_path,monkeypatch,snapshot): path=tmp_path/'snapshot.json';TelemetryWriter(path,snapshot).export()