okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge main (87dfca0e7) into f-own-int: the 0.2.14 app branch, fixtures and CI fixes, the Qwen4-readiness tools, the shape-engine build scriptsffb3d9b31

main
2.0 KiB47 linesraw
1"""Without /proc (macOS) an ended child that is not reaped yet (a zombie) is not "running" (lane 8 on a real Mac: a finished strata_install read as running).
2Runs on Linux too: the /proc branch is switched off, so the ps branch (the one a Mac takes) is what decides."""
3from __future__ import annotations
4
5import subprocess
6import sys
7import time
8import unittest
9from pathlib import Path
10from unittest import mock
11
12ROOT = Path(__file__).resolve().parents[1]
13sys.path.insert(0, str(ROOT))
14sys.path.insert(0, str(ROOT / "tools"))
15import strata_mcp  # noqa: E402
16
17
18@unittest.skipIf(strata_mcp.WIN, "POSIX process states")
19class ZombieWithoutProc(unittest.TestCase):
20    def test_an_ended_unreaped_child_is_not_running(self):
21        child = subprocess.Popen([sys.executable, "-c", "pass"])
22        try:
23            time.sleep(1.0)                              # it has ended; nobody has waited for it, so it is a zombie now
24            with mock.patch.object(strata_mcp, "_has_proc", return_value=False):
25                self.assertIsNone(strata_mcp.proc_identity(child.pid))
26                self.assertFalse(strata_mcp.proc_alive(child.pid, "pid"))
27        finally:
28            child.wait()
29
30    def test_a_running_child_is_running_and_a_gone_one_is_not(self):
31        child = subprocess.Popen([sys.executable, "-c", "import time; time.sleep(30)"])
32        try:
33            with mock.patch.object(strata_mcp, "_has_proc", return_value=False):
34                self.assertEqual(strata_mcp.proc_identity(child.pid), "pid")
35        finally:
36            child.kill()
37            child.wait()
38        with mock.patch.object(strata_mcp, "_has_proc", return_value=False):
39            self.assertIsNone(strata_mcp.proc_identity(child.pid))
40
41    def test_without_ps_the_old_check_stays(self):
42        with mock.patch.object(strata_mcp, "_has_proc", return_value=False), mock.patch.object(strata_mcp, "_ps_state", return_value=None):
43            self.assertEqual(strata_mcp.proc_identity(strata_mcp.os.getpid()), "pid")
44
45
46if __name__ == "__main__":
47    unittest.main()