# 诊断与测试

> Doc Ver: 1.2 · 2026-08-12  
> 场站运维 / 集成商 / 值班 / Agent 的**统一入口**：先选对工具，再体检或联测。  
> **Doctor（体检）≠ Test（联测）≠ Runtime（进程监督）≠ sax（智能层）≠ 网页对话帮助**。

## 三角（先选对程序）

| 程序 | 有没有模型 | 干什么 | 不干什么 |
|------|------------|--------|----------|
| **[sa_doctor](sa_doctor-quickstart.md)** | 不需要 | 可重复的只读体检，PASS/FAIL | 不聊天、不写配置 |
| **[sa_tui](sa_tui-quickstart.md)** | 不需要 | 确定操作台（对齐 sa_web 页面） | 不体检编排、不上模型 |
| **[sax](sax-quickstart.md)** | **必须** | 自然语言、周报、Skills、中心机 IM | 不复制 doctor/tui；无模型则不用；**不是** [网页对话帮助](assistant.md) |

sax 经 MCP 调用 `doctor_run` 只是「用手」，不是把体检做成 sax 的功能模块。网页问手册（无需模型）见 [在线对话帮助](assistant.md)。

## 日常请先用 sa_doctor（主推）

**无论是否专业**，场站巡检、异地排障、交付验收前的健康确认，优先使用：

| 文档 | 适合谁 | 内容 |
|------|--------|------|
| **[sa_doctor 快速使用](sa_doctor-quickstart.md)** | 所有人（含非开发） | 5 分钟：装好 → 改 IP → 设账号 → 一条命令 → 看懂结果 |
| **[sa_doctor 详解](sa_doctor.md)** | 需要深入配置/排障时 | 分层、yaml 字段、场景手册、排障大表 |

```text
# Windows / 运维机（默认诊断 TUI）
sa_doctor.exe -init cluster -o targets.yaml
# 记事本改 IP → set CONTROL_USER / CONTROL_PASS
sa_doctor.exe -c targets.yaml
# 只要文本：sa_doctor.exe -c targets.yaml --cli
```

特点：**只读、可远程、支持 Windows**，不会启停服务。

---

## 1. 先选对工具

| 场景 | 用什么 | 说明 |
|------|--------|------|
| 日常巡检、异地笔记本看场站是否健康 | **[sa_doctor](sa_doctor-quickstart.md)** | 只读远程探测 |
| 本机进程是否在跑、有无崩溃循环 | **sa_run status** / systemctl | Runtime，不是体检 |
| 实验室回归、启停三进程、集群 e2e | **tests/** 脚本 | 会启停/部署，仅实验室 |
| Agent 一键体检 | **sa_mcp** `doctor_run` | 需本机已安装 sa_doctor |
| 自然语言问整栈 / 周报 / 值班 IM | **[sax](sax-quickstart.md)** | 必须有 Ollama 或云模型；device/server/wind 包根都有（不进 run.json）；`--im` 建议中心机 |
| 网页问手册（无需模型） | **[在线对话帮助](assistant.md)** | [http://112.74.47.129:9999](http://112.74.47.129:9999)；不是 sa_file，也不是 sax |
| Cursor 在目标机代装 | 安装门户 `llms.txt` · [install.md](install.md) | **不是** sax，也**不是**工程仓 `AGENT.md` |

禁止：把 `cluster_e2e_test.sh` / `single_device_test.sh` 当场站「全面体检」——它们会改进程生命周期。

## 2. sa_doctor 速览

| 项 | 说明 |
|----|------|
| 分层 | **L0** 配置 · **L1** 服务可达 · **L2** 数据有无/是否正常 |
| 配置 | `targets.yaml`；密码用环境变量，不写进文件 |
| 退出码 | `0` 通过 · `1` 有失败 · `2` 仅警告 · `3` 参数/配置错 |
| 常用参数 | `--layer 1` 加快；`--json` 发给支持；`--target control` 单目标 |

完整步骤与常见首错 → **[快速使用](sa_doctor-quickstart.md)**。  
字段与排障大表 → **[详解](sa_doctor.md)**。  
源码与构建：子模块 `src/sa_doctor/`。

## 3. 内置健康探针（可直接 curl）

> 不会用命令行时，优先跑 sa_doctor，不必手敲 curl。

| 组件 | 探针 | 备注 |
|------|------|------|
| sa_web | `GET :8080/health`、`/api/system/heartbeat` | 单机 Web |
| sa_daq | `GET :8081/api/version`、heartbeat | 常仅 loopback |
| sa_control | `GET :8090/api/health`（存活+broker） | 深检：`/api/cluster/health`（需登录） |
| sa_control | `/api/cluster/sensors/health`、`/api/cluster/snapshots` | 传感器与 PV |
| sa_wt | `GET :3010/api/health` | 风电孪生 |
| sa_dt | `GET :3020/api/health` | 通用孪生内核（可选 target `kind: sa_dt`） |
| EMQX | `GET :18083/api/v5/status`；TCP `:1883` | 管理 API 可能需凭据 |
| Influx | `GET :8086/health` | |
| Grafana | `GET :3000/api/health` | |

## 4. 配置校验入口

- REST：`POST /api/save/config/validate`（及 sensors / run / upload 等 validate）
- UI：sa_web 配置页；**sa_tui** 校验页
- 全面「配置是否坏」优先走 **sa_doctor L0**（远程 API）

## 5. 测试方法汇总（实验室 / CI）

> 以下脚本**可能启停进程**或依赖固定实验室 IP，详见仓库 `tests/README.md`。

| 入口 | 用途 | 与 sa_doctor |
|------|------|--------------|
| `tests/quick_verify.sh` | 实验室快速冒烟 | **只读部分已内置** doctor（api/auth/proxy/rate） |
| `tests/sa_web_auth_smoke.sh` | 鉴权冒烟 | **已内置** `auth.*` |
| `tests/deploy_scada.sh verify` | SCADA 验收断言 | **只读部分已内置** `data.scada_*` / `auth.wt_*` |
| `src/sa_daq_c/scripts/guard_dup_procs.sh --check` | 双进程检测 | **本机** `--local` → `host.dup_procs`（无 --auto） |
| `src/sa_daq_c/scripts/single_device_test.sh` | 单机三进程 + manage/REST/WS | 仍实验室（会启停） |
| `tests/cluster_e2e_test.sh` | 集群端到端 | 仍实验室（会写命令/部署） |
| `tests/deploy_scada.sh deploy` | 部署 SCADA | **不进** doctor |
| `tests/stability_monitor.sh` | 长稳只读监控 | 互补；doctor 偏快检 |
| `tests/run_all_tests.sh` | 三层编排 | CI/实验室 |

日常场站：**优先 sa_doctor**。上表「已内置」项不必再手跑脚本。

## 6. 场景速查

| 问题 | 优先 | 备选 |
|------|------|------|
| 今天场站还健康吗？ | [sa_doctor 快速使用](sa_doctor-quickstart.md) | — |
| 传感器有没有数？ | doctor L2 | control 传感器/快照 API |
| 数据正不正常？ | doctor L2 PV/采样率 | PV `errorCode` / alert |
| 配置是否被破坏？ | doctor L0 | validate API、sa_tui |
| 服务在不在？ | doctor L1 | 上表 curl；本机 `sa_run status` |
| Agent 一键体检 | sa_mcp `doctor_run` | 本机 PATH 需有二进制 |

## 7. 边界说明

```text
Doctor  sa_doctor     只读探测 · 可远程 · 可 Windows · 日常主推
TUI     sa_tui        确定操作台 · 无 LLM
Intel   sax           对话 / Skills / IM · 必须有模型
Test    tests/*       回归联测 · 可启停 · 偏实验室
Runtime sa_run/systemd 守护进程 · 装机本机
```

日常班组：优先 **一条 `sa_doctor -c targets.yaml`**（见 [快速使用](sa_doctor-quickstart.md)）；人在机柜再辅以 `sa_run status`。
