fix(watch): repair SSH probe script broken by embedded quote in os_release parse

Use chr(34) inside the bash-wrapped python -c probe so monitor slots work again after hardware detail rollout.
This commit is contained in:
Nexus Agent
2026-06-13 16:10:32 +08:00
parent 4acbf04322
commit adee25deb6
4 changed files with 69 additions and 2 deletions
@@ -0,0 +1,28 @@
# 审计 — SSH 监测探针引号修复
**Changelog**: `docs/changelog/2026-06-13-ssh-watch-probe-quote-fix.md`
## 审计范围
| 文件 | 变更 | 状态 |
|------|------|------|
| `server/infrastructure/ssh/remote_probe.py` | `strip(chr(34))` | ☑ |
| `tests/test_watch_metrics.py` | 探针脚本回归 | ☑ |
## Step 3 规则扫描
| H | 规则 | 结论 |
|---|------|------|
| H1 | 无新攻击面 | SAFE |
| H2 | 恢复监测可用性 | SAFE — 热修复 |
## Closure
| H | 判定 | 依据 |
|---|------|------|
| H1H2 | SAFE | 本地 bash 执行探针返回 status ok |
## DoD
- [x] `test_ssh_watch_metrics_cmd_runs_locally` passed
- [x] changelog / audit
@@ -0,0 +1,22 @@
# 修复 SSH 监测探针脚本语法错误
**日期**2026-06-13
## 变更摘要
修复 `SSH_WATCH_METRICS_CMD``.strip('"')` 破坏 bash 双引号包裹导致探针全部 `ssh_probe_failed`、实时监测不可用的问题。
## 动机
硬件详情上线后监测插槽无数据;根因为嵌入脚本的 `"` 提前结束 `python3 -c "..."` 字符串。
## 涉及文件
- `server/infrastructure/ssh/remote_probe.py` — 改用 `strip(chr(34))`
- `tests/test_watch_metrics.py` — 本地执行探针脚本回归
## 验证
```bash
.venv/bin/pytest tests/test_watch_metrics.py::test_ssh_watch_metrics_cmd_runs_locally -q
```
+2 -2
View File
@@ -99,7 +99,7 @@ try:
try:
for _line in open('/etc/os-release'):
if _line.startswith('PRETTY_NAME='):
os_release = _line.split('=', 1)[1].strip().strip('"')[:120]
os_release = _line.split('=', 1)[1].strip().strip(chr(34))[:120]
break
except Exception:
pass
@@ -189,7 +189,7 @@ try:
try:
for _line in open('/etc/os-release'):
if _line.startswith('PRETTY_NAME='):
os_release = _line.split('=', 1)[1].strip().strip('"')[:120]
os_release = _line.split('=', 1)[1].strip().strip(chr(34))[:120]
break
except Exception:
pass
+17
View File
@@ -202,6 +202,23 @@ def test_merge_redis_and_ssh_prefers_ssh_io():
assert merged.net_bytes_sent == 99
def test_ssh_watch_metrics_cmd_runs_locally():
import subprocess
from server.infrastructure.ssh.remote_probe import SSH_WATCH_METRICS_CMD, _parse_json_stdout
result = subprocess.run(
["bash", "-c", SSH_WATCH_METRICS_CMD],
capture_output=True,
text=True,
timeout=20,
)
parsed = _parse_json_stdout(result.stdout)
assert parsed is not None
assert parsed.get("status") == "ok"
assert parsed.get("cpu_cores") is not None
def test_normalize_watch_ttl_minutes():
assert normalize_watch_ttl_minutes(30) == 30
assert normalize_watch_ttl_minutes(60) == 60