Skip to content

nxl801/industrial-copilot-template

Repository files navigation

工业自动化产品测试 Copilot 模板(HMI / PLC / 变频器 / 伺服)

English version: README_EN.md

这是一套可直接拷贝到 VS Code / GitHub Copilot 自定义目录中使用的模板项目,目标是帮助团队建立如下工作流:

  1. 从产品 Spec / 需求文档中提取可测试需求
  2. 从需求生成结构化测试用例
  3. 由主 agent + subagent 并行补全 testcase 覆盖率
  4. 通过 coverage auditor 做去重、补洞、命名规范化、覆盖率审计
  5. 自动判定测试用例属于:自动化 / 半自动 / 手工
  6. 对可自动化用例生成脚本骨架
  7. 为执行结果生成证据包与报告模板

项目定位

这不是单纯的 prompt 集合,而是一套面向工业自动化产品测试的 AI 测试设计与自动化模板仓骨架

适用对象包括:

  • HMI
  • PLC
  • 变频器(VFD)
  • 伺服(Servo)
  • Modbus 接口
  • OPC UA 接口

适用目标包括:

  • Spec → requirement → testcase
  • testcase 并行生成与 coverage 审计
  • auto / semi-auto / manual 分流
  • HMI / 协议层脚本生成
  • evidence / report 结构化输出

目录说明

industrial-copilot-template/
├─ .github/
│  └─ copilot/
│     ├─ instructions/
│     │  └─ industrial-testing.instructions.md
│     ├─ prompts/
│     │  ├─ 01_spec_to_requirements.prompt.md
│     │  ├─ 02_requirements_to_testcases.prompt.md
│     │  ├─ 03_testcase_automation_triage.prompt.md
│     │  ├─ 04_testcase_to_script.prompt.md
│     │  ├─ 05_evidence_pack_generator.prompt.md
│     │  ├─ 06_test_report_generator.prompt.md
│     │  ├─ hmi/
│     │  ├─ plc/
│     │  ├─ modbus/
│     │  └─ opcua/
│     └─ agents/
│        ├─ spec-analyst.agent.md
│        ├─ test-designer.agent.md
│        ├─ automation-triage.agent.md
│        ├─ script-generator.agent.md
│        ├─ evidence-reporter.agent.md
│        ├─ orchestrator.agent.md
│        ├─ parallel-testcase-orchestrator.agent.md
│        └─ coverage-auditor.agent.md
├─ artifacts/
├─ logs/
├─ reports/
├─ tests/
│  ├─ playwright/
│  └─ pytest/
├─ templates/
├─ examples/
├─ governance/
├─ subagent-task-templates/
├─ config/
├─ .env.example
├─ pytest.ini
├─ playwright.config.ts
└─ package.json

是否需要 Agent 和 Subagent?

结论:需要 Agent,且 testcase 生成强烈建议使用 Subagent 并行

对于你的目标,建议建立 Agent,因为这不是单一步骤任务,而是稳定的多阶段工作流。

推荐角色:

  • Spec Analyst:读取 Spec,提取 requirement
  • Test Designer:生成测试用例
  • Automation Triage:判断 auto / semi-auto / manual
  • Script Generator:仅对 scriptable 用例生成脚本
  • Evidence Reporter:生成 evidence checklist 和报告
  • Orchestrator:统一编排调用顺序
  • Parallel Testcase Orchestrator:把 Spec 拆成多个子任务并行生成 testcase
  • Coverage Auditor:做覆盖率审计、去重、补洞建议

为什么建议并行?

因为工业产品 spec 往往混合了:

  • 功能行为
  • 异常与边界
  • 恢复与稳定性
  • 权限与安全
  • 日志与证据
  • 协议层行为

单一 agent 容易:

  • 漏边界场景
  • 漏恢复场景
  • 漏权限类场景
  • 重复 testcase
  • 让 automation 判定前后不一致

并行生成 + coverage 审计更适合追求覆盖更完善的 testcase 设计。

推荐编排

  • 简单场景:只用 orchestrator 一个 agent 串行调用 prompt
  • 中型场景:orchestrator + 5 个专职 agent
  • 强覆盖场景:parallel-testcase-orchestrator + 多个 subagent + coverage-auditor
  • 大型场景:再按产品线或协议拆 subagent

推荐的主流程

Spec
→ requirement extraction
→ parallel testcase generation
→ coverage audit / dedup / gap fill
→ automation triage
→ script generation(only auto + scriptable)
→ evidence pack
→ report

Prompt 使用顺序建议

通用流程

  1. 01_spec_to_requirements.prompt.md
  2. 02_requirements_to_testcases.prompt.md
  3. 03_testcase_automation_triage.prompt.md
  4. 04_testcase_to_script.prompt.md
  5. 05_evidence_pack_generator.prompt.md
  6. 06_test_report_generator.prompt.md

HMI 场景

  1. 01_spec_to_requirements.prompt.md
  2. 02_requirements_to_testcases.prompt.md
  3. 03_testcase_automation_triage.prompt.md
  4. prompts/hmi/hmi_testcase_to_playwright.prompt.md
  5. 05_evidence_pack_generator.prompt.md
  6. 06_test_report_generator.prompt.md

PLC 场景

  1. prompts/plc/plc_protocol_requirement_extractor.prompt.md
  2. 02_requirements_to_testcases.prompt.md
  3. 03_testcase_automation_triage.prompt.md
  4. prompts/plc/plc_testcase_to_pytest.prompt.md
  5. 05_evidence_pack_generator.prompt.md
  6. 06_test_report_generator.prompt.md

Modbus 场景

  1. prompts/modbus/modbus_requirement_to_testcases.prompt.md
  2. 03_testcase_automation_triage.prompt.md
  3. prompts/modbus/modbus_testcase_to_pytest.prompt.md
  4. 05_evidence_pack_generator.prompt.md
  5. 06_test_report_generator.prompt.md

OPC UA 场景

  1. prompts/opcua/opcua_requirement_to_testcases.prompt.md
  2. 03_testcase_automation_triage.prompt.md
  3. prompts/opcua/opcua_testcase_to_pytest.prompt.md
  4. 05_evidence_pack_generator.prompt.md
  5. 06_test_report_generator.prompt.md

并行 testcase 生成框架(核心)

已包含内容

  • parallel-testcase-orchestrator.agent.md
  • coverage-auditor.agent.md
  • subagent-task-templates/
    • functional.md
    • negative-boundary.md
    • recovery-robustness.md
    • security-permission.md
    • observability-evidence.md
  • templates/coverage-matrix.template.yaml
  • governance/dedup-rules.md
  • governance/testcase-naming.md
  • governance/parallel-generation-playbook.md
  • examples/parallel/spec_split_example.md
  • examples/parallel/coverage_audit_example.yaml

推荐默认拆分方式

对中等复杂工业 spec,推荐拆成 5 个 subagent:

  • functional
  • negative-boundary
  • recovery-robustness
  • security-permission
  • observability-evidence

如果协议行为很重,再追加:

  • Modbus specialist
  • OPC UA specialist
  • HMI specialist
  • PLC specialist

Coverage Auditor 负责什么

  • 检查每个 requirement 是否被覆盖
  • 检查是否存在 positive / negative / boundary / recovery coverage
  • 检查是否漏掉权限、安全、日志、证据类 case
  • 做重复 testcase 识别与去重记录
  • 统一 testcase ID 和命名规则
  • 输出 gap list 和 follow-up 建议

快速开始(建议公开仓库保留)

1. 克隆并进入项目

git clone <your-public-repo-url>
cd industrial-copilot-template

2. 准备环境变量

cp .env.example .env

根据你的测试环境修改:

  • HMI 地址与账号
  • Modbus 主机、端口、站号、寄存器
  • OPC UA endpoint、namespace、node id

3. Python 测试侧(pytest)

建议自行创建虚拟环境并安装所需依赖,例如:

python -m venv .venv
source .venv/bin/activate
pip install pytest
# 按你的协议场景补充:pymodbus / opcua / asyncua / pyserial 等

运行示例:

pytest

4. HMI / Web UI 测试侧(Playwright)

npm install
npx playwright install
npm run test:hmi

5. 推荐首次试跑场景

优先从低风险案例开始:

  • HMI 登录 / 权限
  • Modbus 非法功能码 / 非法地址
  • OPC UA browse / read / unauthorized write rejection
  • 参数配置合法值 / 非法值

工程壳(最后一层,已补齐)

本模板已提供最小工程壳,方便直接作为测试项目起点:

工程文件

  • .env.example
  • pytest.ini
  • playwright.config.ts
  • package.json
  • tests/pytest/conftest.py
  • tests/pytest/test_placeholder.py
  • tests/playwright/example_hmi.spec.ts
  • config/project-structure.md

目录用途

  • artifacts/:截图、抓包、导出的诊断信息、状态快照
  • logs/:执行日志、调试日志
  • reports/:Markdown / HTML 报告
  • tests/playwright/:HMI / Web UI 自动化
  • tests/pytest/:协议与 Python 脚本测试

安全边界(非常重要)

本模板默认采用保守策略:

  • 未明确批准时,不生成危险运动命令
  • 未明确批准时,不生成功率级相关动作
  • 涉及急停 / STO / 联锁 / 高速运动 / 电机拖动的测试,默认不直接自动化
  • 厂商私有寄存器、对象字典、控制字、状态字未知时,输出 TODO,不猜测
  • 真机行为不明确时,优先输出 simulator / stub 占位
  • script generation 仅建议用于 auto + scriptable 的 testcase

这部分不是保守过头,而是工业测试里保护人、设备和线体的基本护栏。


推荐的 Skills / MCP / Plugins / Hooks(仅推荐,不随模板安装)

以下内容建议团队按需自行安装或接入。

一、推荐 MCP

1. GitHub MCP Server

2. Playwright MCP

二、推荐测试框架 / 能力库

1. Robot Framework Browser

2. Robot Framework Requests

3. Robot Framework SerialLibrary

三、工业协议建议(按生态选)

  • OPC UA:建议 Python 生态(如 opcua / asyncua)
  • Modbus TCP/RTU:建议 pymodbus
  • S7:如环境匹配,可考虑 python-snap7
  • Serial:pyserial

四、Plugins 建议

如果团队要进一步扩展,可考虑让 Copilot / Agent 平台接入:

  • GitHub / Issue 管理插件
  • 文档知识库插件
  • 内部错误码 / 协议字典检索插件
  • 测试平台结果回填插件

五、Hooks 建议

如果平台支持 hooks,建议只做低风险自动动作:

  1. 生成脚本后自动执行格式化
  2. 生成脚本后自动插入日志/超时模板
  3. 输出 testcase 后自动检查 schema 字段是否齐全
  4. 输出报告前自动补 traceability 检查

不建议 通过 hooks 自动触发:

  • 真机动作
  • 参数写入设备
  • 升级设备
  • 电机运动
  • 安全联锁测试

示例与关键文件索引

HMI

  • .github/copilot/prompts/hmi/hmi_spec_to_testcases.prompt.md
  • .github/copilot/prompts/hmi/hmi_testcase_to_playwright.prompt.md
  • examples/chains/hmi_login_flow.md
  • examples/hmi/generated/example_playwright_test.ts
  • templates/playwright_hmi_test.ts

PLC

  • .github/copilot/prompts/plc/plc_protocol_requirement_extractor.prompt.md
  • .github/copilot/prompts/plc/plc_testcase_to_pytest.prompt.md
  • examples/chains/plc_modbus_flow.md
  • examples/plc/generated/example_pytest_modbus.py

Modbus

  • .github/copilot/prompts/modbus/modbus_requirement_to_testcases.prompt.md
  • .github/copilot/prompts/modbus/modbus_testcase_to_pytest.prompt.md
  • templates/pytest_modbus_test.py
  • examples/chains/modbus_invalid_request_flow.md
  • examples/modbus/generated/example_modbus_pytest.py

OPC UA

  • .github/copilot/prompts/opcua/opcua_requirement_to_testcases.prompt.md
  • .github/copilot/prompts/opcua/opcua_testcase_to_pytest.prompt.md
  • templates/pytest_opcua_test.py
  • examples/chains/opcua_browse_read_flow.md
  • examples/opcua/generated/example_opcua_pytest.py

如何拷贝到 VS Code / GitHub Copilot

推荐做法:

  1. 将本项目中的 .github/copilot/ 整个拷贝到目标仓库
  2. templates/examples/governance/subagent-task-templates/ 一并带过去
  3. .env.examplepytest.iniplaywright.config.tspackage.json 一并带过去
  4. 结合你们的产品、协议、命名规范做轻微定制

推荐落地顺序

第 1 步:低风险先跑通

优先从这些场景开始:

  • HMI 登录 / 权限
  • 参数配置页面
  • Modbus 读写与错误响应
  • OPC UA browse / read / unauthorized write rejection

第 2 步:启用并行 testcase 生成

  • 用主 agent 切分 spec
  • 用多个 subagent 并行出 testcase 草稿
  • 用 coverage auditor 去重与补洞

第 3 步:再启用脚本生成

  • 仅对 auto + scriptable case 生成脚本
  • 保持 manual / semi-auto 场景仍由人控边界

License / Copyright

License

当前采用 MIT License,便于团队和社区复用、修改和二次集成。

Copyright

当前公开仓库使用更克制的公开写法:

Copyright (c) 2026 nxl801

这样更适合公开发布场景;如果你后续想改成公司名义、组织名义或 contributors 形式,也可以再调整。


当前完成状态

本模板已包含:

  • Instructions
  • 通用 Prompt files
  • HMI / PLC / Modbus / OPC UA 专版 Prompt files
  • Agents
  • 并行 testcase 生成框架
  • Subagent 编排建议
  • Schema templates
  • Governance 规则
  • 工程壳(Playwright / pytest 起步结构)
  • 示例链路
  • 示例脚本
  • 中文 README

可以直接作为你在 VS Code / GitHub Copilot 下的起始模板使用。

About

Industrial automation testing Copilot template for HMI, PLC, VFD, Servo, Modbus, and OPC UA

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors