Publish curated Unraid-AppOps-Gateway source from ef07e484d2ff369f8d57d6cf3c10bd00c59b5fe1

This commit is contained in:
Public Source Publisher committed 2026-10-11 11:12:40 +00:00
1 parent 85b113f9a1
commit 616f313e2a
4 files changed
+82 -7

No files matched your search

@@ -3530,7 +3530,12 @@ def test_specialization_stage_fixture_quiesces_old_before_registering_and_never_
monkeypatch.setattr(specialize, "specialization_state", lambda: "active" if marker_active["value"] else "blocked")
if probe_fails:
monkeypatch.setattr(specialize, "_rollback_before_activation", lambda _journal: True)
monkeypatch.setattr(specialize, "_record_migration_failure", lambda _journal, _error: events.append("failure-recorded"))
def rollback(_journal):
assert "failure-recorded" in events
events.append("rollback")
return True
monkeypatch.setattr(specialize, "_rollback_before_activation", rollback)
with pytest.raises(
specialize.RunnerFleetSpecializeError,
match="failed_rolled_back",
@@ -1,6 +1,7 @@
from __future__ import annotations
import hashlib
import json
import os
import shutil
from pathlib import Path
@@ -11,6 +12,75 @@ import pytest
from test_runner_fleet_specialize import specialize # noqa: F401
@pytest.mark.parametrize("cause", [
"resource_cgroup_process_mapping_invalid", "resource_cgroup_probe_failed",
"resource_cgroup_probe_lock_busy", "resource_cgroup_probe_lock_untrusted",
"resource_cgroup_probe_lock_store_untrusted", "resource_cgroup_probe_lock_unavailable",
"resource_cgroup_command_failed", "resource_cgroup_command_unavailable",
"resource_cgroup_probe_io_failed", "resource_cgroup_probe_path_invalid",
"secret-value", "resource_cgroup_probe_failed\nsecret-value",
])
def test_rollback_diagnostic_preserves_only_fixed_codes(specialize, monkeypatch, tmp_path, cause):
root = tmp_path / "backups"
root.mkdir(mode=0o700)
backup = root / "specialized-owned"
backup.mkdir(mode=0o700)
monkeypatch.setattr(specialize, "_SPECIALIZED_BACKUP_ROOT", root)
journal = {"backupDirectory": str(backup), "sourceRevision": "a" * 40,
"sourceTree": "b" * 40, "stage": "state_prepared"}
error = specialize.RunnerFleetSpecializeError("runner_fleet_specialization_cgroup_family_unavailable")
error.__cause__ = RuntimeError(cause)
specialize._record_migration_failure(journal, error)
raw = (backup / "migration-failure.json").read_bytes()
record = json.loads(raw)
assert record == {"schemaVersion": 1, "sourceRevision": "a" * 40, "sourceTree": "b" * 40,
"stage": "state_prepared", "failureCode": str(error),
"causeCode": cause if cause in specialize._RESOURCE_FAILURE_CODES else str(error)}
assert b"secret-value" not in raw
@pytest.mark.parametrize("code", [
"runner_fleet_specialization_container_health_timeout",
"runner_fleet_specialization_dind_population_invalid",
"runner_fleet_specialization_cgroup_family_result_invalid",
])
def test_dind_preparation_codes_survive_both_finite_boundaries(specialize, monkeypatch, capsys, code):
def fail():
raise specialize.RunnerFleetSpecializeError(code)
monkeypatch.setattr(specialize, "_apply_from_fixed_script", fail)
assert specialize._main(["--apply-fixed", "--confirm", specialize.CONFIRMATION]) == 1
captured = capsys.readouterr()
assert captured.out == ""
assert captured.err == f"APPOPS_SPECIALIZATION_FAILURE:{code}\n"
result = SimpleNamespace(returncode=1, stdout="", stderr=captured.err)
assert specialize._script_failure_code(result) == code
@pytest.mark.parametrize("defect", ["foreign", "symlink", "stage", "revision", "write"])
def test_rollback_diagnostic_refuses_untrusted_storage_and_never_prevents_rollback(
specialize, monkeypatch, tmp_path, defect,
):
root = tmp_path / "backups"
root.mkdir(mode=0o700)
backup = root / "specialized-owned"
backup.mkdir(mode=0o700)
monkeypatch.setattr(specialize, "_SPECIALIZED_BACKUP_ROOT", root)
journal = {"backupDirectory": str(backup), "sourceRevision": "a" * 40,
"sourceTree": "b" * 40, "stage": "state_prepared"}
if defect == "foreign":
journal["backupDirectory"] = str(tmp_path)
elif defect == "symlink":
monkeypatch.setattr(specialize, "_trusted_directory", lambda _path: (_ for _ in ()).throw(OSError("private-secret")))
elif defect == "stage":
journal["stage"] = "secret-value"
elif defect == "revision":
journal["sourceRevision"] = "secret-value"
else:
monkeypatch.setattr(specialize, "_write_private_atomic", lambda *_a, **_k: (_ for _ in ()).throw(OSError("private-secret")))
specialize._record_migration_failure(journal, RuntimeError("secret-value"))
assert not (backup / "migration-failure.json").exists()
def test_child_fixed_failure_is_finite_and_does_not_echo_exception(specialize, monkeypatch, capsys):
def fail():
raise specialize.RunnerFleetSpecializeError("runner_fleet_specialization_entrypoint_untrusted")