Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b8285ee
R06: allowlist updater execution and post-restart health commands
Oleksii-debug Sep 29, 2026
ae21639
R06: isolate staged candidate in publisher rejection regression
Oleksii-debug Sep 29, 2026
b25ce18
R06: provision pytest for runtime integration suite
Oleksii-debug Sep 29, 2026
a617ea1
R06: align packaging fail-closed assertions with dual artifacts
Oleksii-debug Sep 29, 2026
798010a
R06: assert semantic initial install-button disable state
Oleksii-debug Sep 29, 2026
70cf117
R06: assert stale cleanup covers both packaged artifacts
Oleksii-debug Sep 29, 2026
6658c41
R06: make health regressions discoverable by unittest
Oleksii-debug Sep 29, 2026
620b459
R06: make parent-wait regressions discoverable by unittest
Oleksii-debug Sep 29, 2026
09e2b92
R06: make process regressions discoverable by unittest
Oleksii-debug Sep 29, 2026
2c89169
R06: make relaunch regressions discoverable by unittest
Oleksii-debug Sep 29, 2026
37eba77
R06: make updater runner regressions discoverable by unittest
Oleksii-debug Sep 29, 2026
afbd227
R06: keep runtime regression gates dependency-free
Oleksii-debug Sep 29, 2026
0ac5ba4
R06: lock update transport commands to empty payload
Oleksii-debug Sep 29, 2026
ae89b5a
R06: reconcile qualification successor onto current updater head
Oleksii-debug Sep 29, 2026
b448b40
R06 updater: carry atomic authority/resource repair into convergence
Oleksii-debug Sep 29, 2026
0446825
R06 updater: carry authority/resource regressions into convergence
Oleksii-debug Sep 29, 2026
c55bb27
R06 updater: align convergence success fixture with disarm contract
Oleksii-debug Sep 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"authoring.undo","authoring.redo","authoring.publish_version","authoring.list_versions","authoring.rollback_version",
"keymap.list","keymap.rebind","keymap.clear","keymap.reset_context","keymap.reset_all",
"keymap.export","keymap.import","settings.get","settings.set",
"speech.status","speech.synthesize_prompt","application_update.select_verify","application_update.select_verify_stage","application_update.pending_status","application_update.prepare_apply","application_update.apply_and_restart","application_update.commit_post_restart_health","application_update.cancel_pending","dossier.get","diagnostics.get_report"
"speech.status","speech.synthesize_prompt","application_update.select_verify","application_update.select_verify_stage","application_update.pending_status","application_update.prepare_apply","application_update.apply_and_restart","application_update.cancel_pending","application_update.commit_post_restart_health","dossier.get","diagnostics.get_report"
})

_PLAYER_TRUTH_OWNERS = frozenset({"D5/runtime", "REFERENCE_TEST_ONLY"})
Expand Down Expand Up @@ -102,7 +102,7 @@ def validate_request_shape(request:Any)->tuple[str,str,dict[str,Any]]:
raise ValueError('authoring.pack_compatibility accepts an empty payload')
if cmd=='speech.status' and payload:
raise ValueError('speech.status accepts an empty payload')
if cmd in {'application_update.pending_status','application_update.prepare_apply','application_update.apply_and_restart','application_update.commit_post_restart_health','application_update.cancel_pending'} and payload:
if cmd in {'application_update.pending_status','application_update.prepare_apply','application_update.apply_and_restart','application_update.cancel_pending','application_update.commit_post_restart_health'} and payload:
raise ValueError(f'{cmd} accepts an empty payload')
if cmd=='speech.synthesize_prompt':
allowed={'provider_id','voice_id','speed','allow_network'}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from __future__ import annotations

import unittest

from scripture_archive_platform.transport.contracts import validate_request_shape


API_VERSION = "scripture.transport.v1"
UPDATE_COMMANDS = (
"application_update.apply_and_restart",
"application_update.commit_post_restart_health",
)


def request(command: str, payload=None, *, request_id: str = "update-contract-rid"):
return {
"api_version": API_VERSION,
"request_id": request_id,
"command": command,
"payload": {} if payload is None else payload,
}


class ApplicationUpdateTransportContractTests(unittest.TestCase):
def test_host_owned_update_commands_are_allowlisted_with_empty_payload(self) -> None:
for command in UPDATE_COMMANDS:
with self.subTest(command=command):
rid, parsed_command, payload = validate_request_shape(request(command))
self.assertEqual(rid, "update-contract-rid")
self.assertEqual(parsed_command, command)
self.assertEqual(payload, {})

def test_browser_cannot_supply_update_process_path_or_identity_authority(self) -> None:
injected_payloads = (
{"pid": 1},
{"path": r"C:\attacker.exe"},
{"version": "9.9.9"},
{"sha256": "0" * 64},
)
for command in UPDATE_COMMANDS:
for payload in injected_payloads:
with self.subTest(command=command, payload=payload):
with self.assertRaisesRegex(ValueError, "empty payload"):
validate_request_shape(request(command, payload))


if __name__ == "__main__":
unittest.main()
16 changes: 11 additions & 5 deletions lanes/dev1/repair_overlay/tests/test_packaged_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,26 @@ def test_builder_fails_closed_on_native_failure_and_stale_artifact(self):
'Assert-NativeSuccess "updater artifact verification"',
):
self.assertIn(step, build)
stale_cleanup_loop = "foreach ($artifact in @($Out, $UpdaterOut))"
stale_cleanup = "Remove-Item -LiteralPath $artifact -Force"
self.assertIn(stale_cleanup_loop, build)
self.assertIn("foreach ($artifact in @($Out, $UpdaterOut))", build)
self.assertIn(stale_cleanup, build)
self.assertLess(build.index(stale_cleanup_loop), build.index("pyinstaller.exe"))
self.assertLess(build.index(stale_cleanup), build.index("pyinstaller.exe"))
self.assertLess(
build.index('Assert-NativeSuccess "PyInstaller updater build"'),
build.index('Assert-NativeSuccess "PyInstaller application build"'),
build.index('if (-not (Test-Path -LiteralPath $Out -PathType Leaf))'),
)
self.assertLess(
build.index('Assert-NativeSuccess "updater artifact verification"'),
build.index('Assert-NativeSuccess "PyInstaller updater build"'),
build.index('if (-not (Test-Path -LiteralPath $UpdaterOut -PathType Leaf))'),
)
self.assertLess(
build.index('Assert-NativeSuccess "application artifact verification"'),
build.index('Write-Output "Built $Out'),
)
self.assertLess(
build.index('Assert-NativeSuccess "updater artifact verification"'),
build.index('Write-Output "Built $UpdaterOut'),
)

def test_desktop_host_wraps_update_layer_with_read_only_diagnostics(self):
platform = Path(__file__).resolve().parents[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def test_frontend_exposes_accessible_two_step_install_without_html_injection(sel
self.assertIn("pending-update-apply-restart", script)
self.assertIn("Встановити й перезапустити", script)
self.assertIn("apply.disabled=true", script)
self.assertIn("button.disabled=busy||", script)
self.assertIn("button.disabled=busy", script)
self.assertIn("aria-live", script)
self.assertIn("textContent", script)
self.assertNotIn("innerHTML", script)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ def _consume_apply_handoff_locked(
installed_sha = _sha256_file(target)
if installed_sha != pending.artifact_sha256:
raise ApplicationUpdateError("installed artifact failed exact-byte verification")
discard_apply_handoff(root)
post_publish_handoff = inspect_apply_handoff(root, current_version=current_version)
if post_publish_handoff != pending:
raise ApplicationUpdateError("apply handoff changed after atomic publication")
if discard_apply_handoff(root) is not True:
raise ApplicationUpdateError("apply handoff disappeared during disarm")
except Exception as apply_error:
try:
candidate.unlink()
Expand Down Expand Up @@ -297,20 +301,38 @@ def _discard_file(path: Path) -> None:

def _copy_exact(source: Path, destination: Path) -> None:
try:
descriptor = os.open(destination, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o700)
source_handle = source.open("rb")
except OSError as exc:
raise ApplicationUpdateError("could not create update copy safely") from exc
try:
with source.open("rb") as src, os.fdopen(descriptor, "wb", closefd=True) as dst:
shutil.copyfileobj(src, dst, length=_COPY_CHUNK)
dst.flush()
os.fsync(dst.fileno())
except Exception:
raise ApplicationUpdateError("update source could not be opened") from exc

with source_handle as src:
try:
destination.unlink()
except OSError:
pass
raise
descriptor = os.open(destination, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o700)
except OSError as exc:
raise ApplicationUpdateError("could not create update copy safely") from exc
try:
destination_handle = os.fdopen(descriptor, "wb", closefd=True)
except Exception:
try:
os.close(descriptor)
finally:
try:
destination.unlink()
except OSError:
pass
raise

try:
with destination_handle as dst:
shutil.copyfileobj(src, dst, length=_COPY_CHUNK)
dst.flush()
os.fsync(dst.fileno())
except Exception:
try:
destination.unlink()
except OSError:
pass
raise


def _sha256_file(path: Path) -> str:
Expand Down
68 changes: 35 additions & 33 deletions runtime_engine/tests/test_application_update_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,32 @@ def _sha(data: bytes) -> str:
return hashlib.sha256(data).hexdigest()


def _fixture(tmp_path: Path):
root = tmp_path / "state" / "updates"
root.mkdir(parents=True)
target = tmp_path / "install" / "Scripture Archive.exe"
target.parent.mkdir()
previous = b"previous-installed-exact-bytes"
installed = b"updated-installed-exact-bytes"
target.write_bytes(installed)
rollback = target.with_name(target.name + ".scripture-archive.rollback")
rollback.write_bytes(previous)
return root, target, rollback, previous, installed


def _publish(tmp_path: Path):
root, target, rollback, previous, installed = _fixture(tmp_path)
receipt = publish_update_health_receipt(
root,
previous_version=PREVIOUS_VERSION,
target_version=TARGET_VERSION,
install_target=target,
previous_sha256=_sha(previous),
installed_sha256=_sha(installed),
)
return root, target, rollback, previous, installed, receipt


class ApplicationUpdateHealthTests(unittest.TestCase):
def setUp(self) -> None:
self.temp = tempfile.TemporaryDirectory()
Expand All @@ -32,32 +58,8 @@ def setUp(self) -> None:
def tearDown(self) -> None:
self.temp.cleanup()

def _fixture(self):
root = self.tmp_path / "state" / "updates"
root.mkdir(parents=True)
target = self.tmp_path / "install" / "Scripture Archive.exe"
target.parent.mkdir()
previous = b"previous-installed-exact-bytes"
installed = b"updated-installed-exact-bytes"
target.write_bytes(installed)
rollback = target.with_name(target.name + ".scripture-archive.rollback")
rollback.write_bytes(previous)
return root, target, rollback, previous, installed

def _publish(self):
root, target, rollback, previous, installed = self._fixture()
receipt = publish_update_health_receipt(
root,
previous_version=PREVIOUS_VERSION,
target_version=TARGET_VERSION,
install_target=target,
previous_sha256=_sha(previous),
installed_sha256=_sha(installed),
)
return root, target, rollback, previous, installed, receipt

def test_publish_and_inspect_bind_version_name_and_exact_installed_rollback_bytes(self) -> None:
root, target, rollback, previous, installed, receipt = self._publish()
root, target, rollback, previous, installed, receipt = _publish(self.tmp_path)

self.assertEqual(receipt.previous_version, PREVIOUS_VERSION)
self.assertEqual(receipt.target_version, TARGET_VERSION)
Expand All @@ -82,7 +84,7 @@ def test_publish_and_inspect_bind_version_name_and_exact_installed_rollback_byte
self.assertNotIn("rollback_path", payload)

def test_publish_is_idempotent_only_for_same_exact_identity(self) -> None:
root, target, rollback, previous, installed, first = self._publish()
root, target, rollback, previous, installed, first = _publish(self.tmp_path)
before = (root / "update-health.json").read_bytes()
second = publish_update_health_receipt(
root,
Expand All @@ -106,7 +108,7 @@ def test_publish_is_idempotent_only_for_same_exact_identity(self) -> None:
)

def test_inspect_fails_closed_on_version_installed_or_rollback_tamper(self) -> None:
root, target, rollback, previous, installed, receipt = self._publish()
root, target, rollback, previous, installed, receipt = _publish(self.tmp_path)

with self.assertRaisesRegex(ApplicationUpdateError, "target version is not current"):
inspect_update_health_receipt(root, current_version="1.2.0", install_target=target)
Expand All @@ -121,7 +123,7 @@ def test_inspect_fails_closed_on_version_installed_or_rollback_tamper(self) -> N
inspect_update_health_receipt(root, current_version=TARGET_VERSION, install_target=target)

def test_receipt_shape_extra_field_and_symlink_fail_closed(self) -> None:
root, target, rollback, previous, installed, receipt = self._publish()
root, target, rollback, previous, installed, receipt = _publish(self.tmp_path)
path = root / "update-health.json"
payload = json.loads(path.read_text(encoding="utf-8"))
payload["unexpected"] = True
Expand All @@ -140,7 +142,7 @@ def test_receipt_shape_extra_field_and_symlink_fail_closed(self) -> None:
inspect_update_health_receipt(root, current_version=TARGET_VERSION, install_target=target)

def test_commit_disarms_old_pending_then_receipt_and_rollback_after_exact_proof(self) -> None:
root, target, rollback, previous, installed, receipt = self._publish()
root, target, rollback, previous, installed, receipt = _publish(self.tmp_path)
pending = root / "pending-update.json"
pending.write_text("old-version journal need not be parsed", encoding="utf-8")

Expand All @@ -156,7 +158,7 @@ def test_commit_disarms_old_pending_then_receipt_and_rollback_after_exact_proof(
self.assertEqual(target.read_bytes(), installed)

def test_failed_health_proof_preserves_receipt_pending_and_rollback(self) -> None:
root, target, rollback, previous, installed, receipt = self._publish()
root, target, rollback, previous, installed, receipt = _publish(self.tmp_path)
pending = root / "pending-update.json"
pending.write_text("old-version journal", encoding="utf-8")
target.write_bytes(b"tampered")
Expand All @@ -168,9 +170,9 @@ def test_failed_health_proof_preserves_receipt_pending_and_rollback(self) -> Non
self.assertTrue(rollback.exists())

def test_discard_only_disarms_receipt_and_preserves_recovery_bytes(self) -> None:
root, target, rollback, previous, installed, receipt = self._publish()
self.assertTrue(discard_update_health_receipt(root))
self.assertFalse(discard_update_health_receipt(root))
root, target, rollback, previous, installed, receipt = _publish(self.tmp_path)
self.assertIs(discard_update_health_receipt(root), True)
self.assertIs(discard_update_health_receipt(root), False)
self.assertEqual(rollback.read_bytes(), previous)
self.assertEqual(target.read_bytes(), installed)

Expand Down
14 changes: 10 additions & 4 deletions runtime_engine/tests/test_application_update_parent_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ def backend(pid: int, timeout_ms: int) -> None:

def test_wait_rejects_invalid_pid(self) -> None:
for pid in [0, -1, True, 1.5, "1"]:
with self.subTest(pid=pid), self.assertRaises(ParentProcessWaitError):
wait_for_parent_exit(pid, wait_backend=lambda *_: None)
with self.subTest(pid=pid):
with self.assertRaises(ParentProcessWaitError):
wait_for_parent_exit(pid, wait_backend=lambda *_: None) # type: ignore[arg-type]

def test_wait_rejects_invalid_or_unbounded_timeout(self) -> None:
for timeout_ms in [0, -1, 120_001, True, 1.5]:
with self.subTest(timeout_ms=timeout_ms), self.assertRaises(ParentProcessWaitError):
wait_for_parent_exit(4242, timeout_ms=timeout_ms, wait_backend=lambda *_: None)
with self.subTest(timeout_ms=timeout_ms):
with self.assertRaises(ParentProcessWaitError):
wait_for_parent_exit( # type: ignore[arg-type]
4242,
timeout_ms=timeout_ms,
wait_backend=lambda *_: None,
)

def test_wait_is_windows_only_without_injected_backend(self) -> None:
with self.assertRaisesRegex(ParentProcessWaitError, "Windows-only"):
Expand Down
Loading
Loading