Retain bounded invalid ASR output and atomic failure evidence
This commit is contained in:
1 parent
c33047998b
commit
b002399217
3 files changed
+99
-3
No files matched your search
@@ -10,9 +10,33 @@ import importlib.util
|
||||
import hashlib
|
||||
from run import segments, run_owned, recognized_window, decode_command, decoded_frames, primary_audio_range
|
||||
from score import score, require_eligible
|
||||
from run import parse_asr_output, AsrOutputError, MAX_OUTPUT, checkpoint_report
|
||||
|
||||
|
||||
class ContractTests(unittest.TestCase):
|
||||
def test_atomic_checkpoint_failure_preserves_previous_evidence(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
path = Path(directory) / "report.json"
|
||||
checkpoint_report(path, {"complete": False, "rows": []})
|
||||
old = path.read_bytes()
|
||||
with self.assertRaises(TypeError):
|
||||
checkpoint_report(path, {"invalid": object()})
|
||||
self.assertEqual(path.read_bytes(), old)
|
||||
def test_invalid_asr_utf8_and_json_retain_exact_bounded_bytes(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
parent = Path(directory)
|
||||
path = parent / "output.json"
|
||||
for raw in [b'{"text":"\xe2\x28\xa1"}', b'{"text":']:
|
||||
path.write_bytes(raw)
|
||||
with self.assertRaises(AsrOutputError) as caught:
|
||||
parse_asr_output(path, parent)
|
||||
failure = caught.exception.failure
|
||||
self.assertEqual(Path(failure["raw_output_path"]).read_bytes(), raw)
|
||||
self.assertEqual(failure["raw_output_sha256"], hashlib.sha256(raw).hexdigest())
|
||||
self.assertEqual(failure["raw_output_bytes"], len(raw))
|
||||
path.write_bytes(b"x" * (MAX_OUTPUT + 1))
|
||||
with self.assertRaises(ValueError):
|
||||
parse_asr_output(path, parent)
|
||||
def test_harness_source_hash_is_captured_before_file_changes(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
path = Path(directory) / "run-copy.py"
|
||||
|
||||
Reference in new issue
Block a user