Files
hermes-agent/tests/scripts/desktop_update/test_desktop_update_windows_timestamp.py
Teknium 4f8fb4b263 test(update): windows marker timestamp test pins the run-identity line
87c67de3778 made the Windows claim carry its stable run:<id> line, so the
self-test marker is pid / started / ct / run. Pin the four-line body and the
run token grammar instead of the pre-run three-line count.

(cherry picked from commit f2bc6d679a17b17d996a27797116fe4dd7304776)
2026-10-06 05:44:21 -07:00

43 lines
2.1 KiB
Python

"""The Windows handoff writes numeric Unix seconds under comma-decimal locales."""
import json
import re
import os
from pathlib import Path
import shutil
import subprocess
import time
import pytest
@pytest.mark.platforms("windows")
def test_windows_update_writes_locale_independent_marker_and_result(tmp_path, monkeypatch):
shell = shutil.which("powershell.exe")
assert shell, "native Windows acceptance requires PowerShell"
script = Path(__file__).resolve().parent.parent.parent.parent / "scripts/desktop-update/windows.ps1"
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
monkeypatch.delenv("HERMES_UPDATE_STARTED_AT", raising=False)
# -SelfTestMarker runs the actual claim and finally/result publication,
# but never updates a checkout, waits on Desktop, or launches processes.
command = (
"[Threading.Thread]::CurrentThread.CurrentCulture = [Globalization.CultureInfo]::GetCultureInfo('es-ES'); "
"& $env:HERMES_TIMESTAMP_TEST_SCRIPT -InstallRoot $env:HERMES_HOME -NoUi -NoMarkerCleanup -SelfTestMarker"
)
started = int(time.time())
result = subprocess.run([shell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", command],
env={**os.environ, "HERMES_TIMESTAMP_TEST_SCRIPT": str(script)},
capture_output=True, text=True, timeout=60)
finished = int(time.time())
assert result.returncode == 0, result.stdout + result.stderr
marker = (tmp_path / ".hermes-update-in-progress").read_text(encoding="utf-8-sig").splitlines()
receipt = json.loads((tmp_path / ".hermes-update-result.json").read_text(encoding="utf-8-sig"))
# v2 body (contract C1): the creation-time line is culture-invariant too,
# and the claim names its stable run identity (receipt correlation).
assert len(marker) == 4 and int(marker[0]) > 0
assert re.fullmatch(r"ct:\d+\.\d{3}", marker[2]), marker
assert re.fullmatch(r"run:[A-Za-z0-9._-]{1,128}", marker[3]), marker
assert started <= int(marker[1]) <= finished
assert type(receipt["finished_at"]) is int
assert started <= receipt["finished_at"] <= finished
assert receipt["exit_code"] == 0