883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
62 lines
2.6 KiB
Python
62 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""No credentials or network: exercise the local test's replay boundary."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / 'ops'))
|
|
import run_source_local_fixture as fixture
|
|
|
|
|
|
class OneShotStateTest(unittest.TestCase):
|
|
def test_reservation_interruption_failure_and_success(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = Path(directory) / 'attempt.state'
|
|
fd = fixture.claim_once_state(path)
|
|
self.assertEqual(json.loads(path.read_text())['status'], 'reserved')
|
|
with self.assertRaises(BlockingIOError):
|
|
fixture.claim_once_state(path)
|
|
os.close(fd)
|
|
with self.assertRaises(ValueError):
|
|
fixture.claim_once_state(path)
|
|
path.write_text('{"status":"failed"}\n')
|
|
with self.assertRaises(ValueError):
|
|
fixture.claim_once_state(path)
|
|
path.write_text('{"status":"success"}\n')
|
|
fd = fixture.claim_once_state(path)
|
|
self.assertEqual(json.loads(path.read_text())['status'], 'reserved')
|
|
os.close(fd)
|
|
|
|
def test_malformed_or_symlink_state_is_rejected(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = Path(directory) / 'attempt.state'
|
|
path.write_text('[]')
|
|
path.chmod(0o600)
|
|
with self.assertRaises(ValueError):
|
|
fixture.claim_once_state(path)
|
|
path.unlink()
|
|
path.symlink_to(Path(directory) / 'other')
|
|
with self.assertRaises(OSError):
|
|
fixture.claim_once_state(path)
|
|
|
|
def test_legacy_failure_blocks_and_verified_success_allows(self):
|
|
with tempfile.TemporaryDirectory() as directory, mock.patch.object(fixture, 'LEGACY', Path(directory)):
|
|
root = Path(directory)
|
|
self.assertTrue(fixture.legacy_result_safe())
|
|
(root / 'local-account-real-once.lock').write_text('reserved')
|
|
self.assertFalse(fixture.legacy_result_safe())
|
|
(root / 'local-account-once-result.private.json').write_text(json.dumps({'exit_code': 0, 'attempts': 1}))
|
|
(root / 'local-account-once.stdout.private').write_text('GW_LOCAL_PROFILE genuine-realm-prepared\n')
|
|
self.assertTrue(fixture.legacy_result_safe())
|
|
(root / 'local-account-once-result.private.json').write_text('[]')
|
|
self.assertFalse(fixture.legacy_result_safe())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|