feat(python): durable transaction subsystem and Kiro IDE 1.0 adapter

Land the crash-recoverable managed-file transaction engine (journal,
staging, commit, restart recovery, opaque snapshots, private artifacts,
Windows DACL hardening) and the Kiro IDE 1.0 workspace hook plugin with
legacy migration.

Repair five defects that kept the suite red (426 failures to zero):

- Anchor the transaction state directory at ~/.elydora/transactions
  instead of the shared system temp directory. The recovery journal now
  shares fate with the runtimes it repairs, survives temp cleaners, and
  isolates naturally under per-test fake homes.
- Skip pending-transaction recovery when no state directory exists so
  rejected installs never create runtime directories.
- Create the runtime root's parent before hardening it, matching the Go
  SDK's expand behavior for fresh homes.
- Stop using file timestamps as identity evidence: Windows exposes
  mtime/ctime with delayed cross-handle visibility. Reads now prove
  stability through a verification re-read; snapshots compare device,
  inode, size, and SHA-256.
- Stop comparing synthetic Windows permission bits across stat
  boundaries: path stats derive execute bits from file extensions while
  handle stats do not, which falsely flagged every managed .cmd wrapper.
  Snapshots store raw modes for restoration and compare portable bits.

Reservation cleanup now verifies content before discarding so a
concurrent writer's file at a rollback path is preserved, and the
install-failure tests assert the precise contract: no agent runtime
residue, with the durable state directory allowed to remain.

Gates: pytest 807 passed, mypy clean, pip check clean, wheel builds.
This commit is contained in:
ZacharyZhang-NY committed 2026-07-21 18:53:06 -04:00
1 parent dce7d1288a
commit e37418c489
53 files changed
+11855 -531

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
from __future__ import annotations
import os
from pathlib import Path
import subprocess
import sys
import pytest
from elydora.plugins import _transaction
def _subprocess_environment(home: Path) -> dict[str, str]:
environment = os.environ.copy()
environment["HOME"] = str(home)
environment["USERPROFILE"] = str(home)
return environment
def test_process_exit_after_secret_staging_recovers_owned_artifact(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
) -> None:
home = tmp_path / "home"
home.mkdir()
target = tmp_path / "target.txt"
target.write_bytes(b"old\n")
monkeypatch.setenv("HOME", str(home))
monkeypatch.setenv("USERPROFILE", str(home))
script = """
import os
import sys
from elydora.plugins import _transaction, _transaction_staging
target = sys.argv[1]
change = _transaction.source_change(target, "target", "old\\n", "secret-new\\n", 0o600)
assert change is not None
real_write_staged = _transaction_staging.write_staged
def terminate_after_secret_staging(*args, **kwargs):
real_write_staged(*args, **kwargs)
os._exit(78)
_transaction_staging.write_staged = terminate_after_secret_staging
_transaction.write_changes([change], "initialization crash recovery")
"""
completed = subprocess.run(
[sys.executable, "-c", script, str(target)],
cwd=Path(__file__).resolve().parents[1],
env=_subprocess_environment(home),
check=False,
)
assert completed.returncode == 78
staged = list(tmp_path.glob(".target.txt.*.tmp"))
assert len(staged) == 1
assert staged[0].read_text(encoding="utf-8") == "secret-new\n"
try:
_transaction.recover_pending_transactions()
assert target.read_text(encoding="utf-8") == "old\n"
assert list(tmp_path.glob(".target.txt.*.tmp")) == []
finally:
for artifact in tmp_path.glob(".target.txt.*.tmp"):
artifact.unlink()