feat(commands): multi-select ordered command pipeline with step reordering and single-pass composition (AI-05, AI-07)

This commit is contained in:
Yun Chan 2026-10-31 02:54:54 +09:00
parent f49acf0105
commit 10af20a0ad
157 changed files with 29455 additions and 913 deletions

View file

@ -0,0 +1,30 @@
"""Scheduling headroom, including small PCs and restricted process CPU capacity."""
import sys
import unittest
from pathlib import Path
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
import cpu_budget
class CpuBudgetTest(unittest.TestCase):
def test_reserves_headroom_and_caps_workers(self) -> None:
for cpus, expected in [(1, 1), (2, 1), (3, 1), (4, 2), (6, 4), (8, 4), (16, 4), (64, 4)]:
with self.subTest(cpus=cpus):
self.assertEqual(cpu_budget.inference_cpu_threads(cpus), expected)
def test_unknown_capacity_uses_one_worker(self) -> None:
for cpus in (None, 0, -1):
with self.subTest(cpus=cpus):
self.assertEqual(cpu_budget.inference_cpu_threads(cpus), 1)
def test_prefers_process_capacity_when_available(self) -> None:
with mock.patch.object(cpu_budget.os, "process_cpu_count", return_value=4, create=True):
with mock.patch.object(cpu_budget.os, "cpu_count", return_value=64):
self.assertEqual(cpu_budget.local_inference_cpu_threads(), 2)
if __name__ == "__main__":
unittest.main()

View file

@ -168,6 +168,7 @@ class FakeWhisperModel:
self.source = source
self.device = device
self.compute_type = compute_type
self.cpu_threads = cpu_threads
FakeWhisperModel.created.append(self)
def transcribe(self, audio: np.ndarray, **_kwargs: object) -> tuple[Iterator[_Segment], _Info]:
@ -232,6 +233,16 @@ class SidecarGpuFallbackTest(unittest.TestCase):
self.assertEqual(self._transcribe().status_code, 200)
self.assertTrue(self.client.get("/health").json()["gpu"])
def test_primary_aux_and_cpu_fallback_use_worker_budget(self) -> None:
_FakeGpuEnv.cublas_missing = True
with mock.patch("cpu_budget.os.process_cpu_count", return_value=4, create=True):
primary = self.client.post("/load", json={"model_id": "medium"})
auxiliary = self.client.post("/load", json={"model_id": "small", "slot": "aux"})
self.assertEqual(primary.status_code, 200)
self.assertEqual(auxiliary.status_code, 200)
self.assertEqual([m.device for m in FakeWhisperModel.created], ["cuda", "cpu", "cpu"])
self.assertEqual([m.cpu_threads for m in FakeWhisperModel.created], [2, 2, 2])
def test_missing_cublas_detected_at_load_uses_cpu(self) -> None:
_FakeGpuEnv.cublas_missing = True
res = self.client.post("/load", json={"model_id": "medium"})