This commit is contained in:
root
2026-05-18 06:48:30 +00:00
parent f1145e3a36
commit e638a4656c
14 changed files with 172 additions and 11 deletions

View File

@@ -132,6 +132,34 @@ class ConfigGovernanceTests(unittest.TestCase):
self.assertGreaterEqual(calls["n"], 2)
self.assertFalse(hist_dir.exists())
def test_save_managed_file_surfaces_permission_hint(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
tmp_path = Path(tmp)
root_path = tmp_path / "config"
root_path.mkdir(parents=True, exist_ok=True)
target = root_path / "youtube.demo.ini"
target.write_text("[youtube]\nkey = old\n", encoding="utf-8")
root = ManagedRoot(
root_id="app-config",
label="App Config",
description="test",
path=root_path,
explicit_names=("youtube.demo.ini",),
)
real_write_text = Path.write_text
def deny_write(self, *args, **kwargs):
if self == target:
raise OSError(errno.EACCES, "Permission denied")
return real_write_text(self, *args, **kwargs)
with mock.patch("src.config_governance.resolve_managed_file", return_value=(root, Path("youtube.demo.ini"), target)):
with mock.patch("pathlib.Path.write_text", new=deny_write):
with self.assertRaises(PermissionError) as ctx:
save_managed_file("app-config", "youtube.demo.ini", "[youtube]\nkey = new\n")
self.assertIn("backup_config", str(ctx.exception))
if __name__ == "__main__":
unittest.main()

View File

@@ -1,9 +1,11 @@
from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
from src.runtime_bootstrap import compute_nofile_target, load_msg_push_exports
from src.runtime_bootstrap import compute_nofile_target, ensure_runtime_layout, load_msg_push_exports
class RuntimeBootstrapTests(unittest.TestCase):
@@ -18,6 +20,20 @@ class RuntimeBootstrapTests(unittest.TestCase):
result = funcs[0]("demo")
self.assertTrue(result["disabled"])
def test_ensure_runtime_layout_creates_expected_directories(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
issues = ensure_runtime_layout(Path(tmp))
self.assertEqual(issues, [])
self.assertTrue((Path(tmp) / "backup_config").is_dir())
self.assertTrue((Path(tmp) / ".process_runner").is_dir())
def test_ensure_runtime_layout_reports_unwritable_directory(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
with patch("src.runtime_bootstrap.os.access", side_effect=lambda p, mode: str(p) != str(root / "logs")):
issues = ensure_runtime_layout(root)
self.assertTrue(any("logs" in issue for issue in issues))
if __name__ == "__main__":
unittest.main()

View File

@@ -67,6 +67,17 @@ class YoutubeRuntimeTests(unittest.TestCase):
self.assertEqual(enc, "")
self.assertIn("renderD", note)
def test_x86_qsv_falls_back_to_vaapi_for_safe_linux_stack(self) -> None:
enc, note = resolve_live_video_encoder(
"h264_qsv",
"h264_qsv\nh264_vaapi\n",
"x86_64",
has_mpp_service=False,
has_render_node=True,
)
self.assertEqual(enc, "h264_vaapi")
self.assertIn("fallback", note)
def test_arm_rejects_v4l2m2m_without_video_nodes(self) -> None:
enc, note = resolve_live_video_encoder(
"h264_v4l2m2m",