Files
CCLite/Python/checkers/audit_real_workers.py
T

140 lines
4.8 KiB
Python

from __future__ import annotations
import argparse
import json
import subprocess
from pathlib import Path
def run_command(command: list[str]) -> dict:
try:
completed = subprocess.run(command, text=True, capture_output=True, timeout=10.0)
except subprocess.TimeoutExpired as exc:
return {
"command": command,
"exit_code": None,
"stdout": exc.stdout or "",
"stderr": exc.stderr or "",
"status": "TIMEOUT",
}
return {
"command": command,
"exit_code": completed.returncode,
"stdout": completed.stdout,
"stderr": completed.stderr,
"status": "RAW",
}
def run_standard_worker_probe(exe: Path, solver_id: str, case_file: Path) -> dict:
result = run_command([
str(exe),
"--cclite-worker",
"--solver-id",
solver_id,
"--case",
str(case_file),
"--ipc-name",
"CCLITE_REAL_WORKER_AUDIT",
"--timeout-ms",
"100",
])
output = (result.get("stdout") or "") + "\n" + (result.get("stderr") or "")
recognized = "--solver-id" not in output and "unknown argument" not in output
unsupported = "not implemented" in output.lower() or "unsupported" in output.lower()
result["status"] = classify_standard_probe(recognized, unsupported, result["exit_code"])
result["recognized_worker_cli"] = recognized
result["ipc_implemented"] = recognized and result["exit_code"] == 0 and not unsupported
return result
def run_femlite_mock_probe(exe: Path, case_file: Path, report_path: Path) -> dict:
output_dir = report_path.parent / "femlite_worker_mock"
log_file = report_path.parent / "femlite_worker_mock.log"
result = run_command([
str(exe),
"--cclite-worker",
"--case",
str(case_file),
"--ipc-name",
"CCLITE_FEMLITE_WORKER_MOCK_AUDIT",
"--log",
str(log_file),
"--output-dir",
str(output_dir),
"--mock-steps",
"1",
])
output = (result.get("stdout") or "") + "\n" + (result.get("stderr") or "")
if result["exit_code"] == 0 and "worker mock completed" in output.lower():
result["status"] = "WORKER_MOCK_AVAILABLE"
elif "unknown worker argument" in output.lower() or "unknown argument" in output.lower():
result["status"] = "MISSING_WORKER_MOCK_CLI"
else:
result["status"] = "WORKER_MOCK_FAILED"
result["log_file"] = str(log_file)
result["output_dir"] = str(output_dir)
return result
def classify_standard_probe(recognized: bool, unsupported: bool, exit_code: int | None) -> str:
if recognized and unsupported:
return "CONTROLLED_UNSUPPORTED"
if recognized and exit_code == 0:
return "READY_FOR_REAL_IPC"
if not recognized:
return "MISSING_STANDARD_WORKER_ARGS"
return "FAILED"
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--sph-exe", required=True)
parser.add_argument("--fem-exe", required=True)
parser.add_argument("--case-dir", required=True)
parser.add_argument("--fem-case", required=True)
parser.add_argument("--report", required=True)
args = parser.parse_args()
case_dir = Path(args.case_dir)
report_path = Path(args.report)
sph_standard = run_standard_worker_probe(Path(args.sph_exe), "SPH", case_dir / "mock_sph.inp")
fem_standard = run_standard_worker_probe(Path(args.fem_exe), "FEM", Path(args.fem_case))
fem_mock = run_femlite_mock_probe(Path(args.fem_exe), Path(args.fem_case), report_path)
status = "PARTIAL_EXTERNAL_WORKER_SUPPORT"
if sph_standard["ipc_implemented"] and fem_standard["ipc_implemented"]:
status = "READY_FOR_REAL_IPC"
elif fem_mock["status"] != "WORKER_MOCK_AVAILABLE":
status = "CONTROLLED_GAP"
report = {
"status": status,
"required_worker_args": [
"--cclite-worker",
"--solver-id <SPH|FEM>",
"--case <solver.inp>",
"--ipc-name <prefix>",
"--timeout-ms <milliseconds>",
],
"sphlite_standard_ipc": sph_standard,
"femlite_standard_ipc": fem_standard,
"femlite_worker_mock": fem_mock,
"conclusion": [
"SPHLite 0.8.2 recognizes worker mode but reports real IPC as not implemented.",
"FEMLite 0.6.4 provides a self-running CCLite worker mock.",
"FEMLite 0.6.4 does not yet accept the full CCLite standard IPC worker argument set.",
"CCLite 0.1.9 keeps mock-worker IPC integration as the executable acceptance path.",
],
}
report_path.parent.mkdir(parents=True, exist_ok=True)
report_path.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
print(f"real worker audit -> {report_path}")
return 0
if __name__ == "__main__":
raise SystemExit(main())