# 5E Windows Service 實作測試案例與停止線稽核表

本文件承接 [5E Windows Service 邊界分析](phase-five-e-windows-service-boundary-analysis.md)、[5E Windows Service 實作前確認表](phase-five-e-windows-service-preimplementation-checklist.md) 與 [5E Windows Service 程式 repo 結構檢查與實作前盤點](phase-five-e-windows-service-code-structure-preimplementation-checklist.md)。本表定義 5E 第一批程式實作後需要通過的測試與停止線。

## 0. 文件狀態

| 項目 | 內容 |
|---|---|
| 文件狀態 | 已建立，等待 5E 七項確認 |
| 建立日期 | 2026-06-07 |
| 對應節點 | 第五階段 5E Windows Service |
| 程式基準 | `c92342b` |
| 本次是否修改程式 repo | 否 |

## 1. 建議測試案例

| 編號 | 類型 | 測試重點 |
|---|---|---|
| 1 | Options | service name / display name / description 不可為空，且不得包含敏感資訊。 |
| 2 | Disabled path | 預設不啟用 Windows Service path，既有 console smoke path 保持可用。 |
| 3 | Start delegation | service hosting wrapper 啟動時呼叫 `IServiceHostRuntime.Start()`。 |
| 4 | Stop delegation | service hosting wrapper 停止時呼叫 `IServiceHostRuntime.Stop()`。 |
| 5 | Fault mapping | runtime start 失敗時 service hosting path 回報可追蹤錯誤，不吞 exception。 |
| 6 | Status | service hosting path 可取得 state、host name、operator、source。 |
| 7 | Manual-only gate | install / uninstall / start / stop script 若存在，預設必須拒絕執行。 |
| 8 | No production secret | 測試或掃描確認沒有 service account、password、token、正式 IP、正式路徑。 |
| 9 | Existing tests | 既有 `ServiceHostRuntimeTests` 全部通過。 |
| 10 | Stop-line scan | 未新增 DB DDL、WebApi auth / Swagger、外部 DLL 載入、plugin folder scan 或 Adapter public contract 變更。 |

## 2. 必跑測試

| 測試範圍 | 指令 |
|---|---|
| ServiceHost tests | `dotnet test tests\HS.DeviceControl.ServiceHost.Tests\HS.DeviceControl.ServiceHost.Tests.csproj --no-restore` |
| Application tests | `dotnet test tests\HS.DeviceControl.Application.Tests\HS.DeviceControl.Application.Tests.csproj --no-restore` |
| Solution tests | `dotnet test HS.DeviceControl.sln --no-restore` |
| 污染字串掃描 | 使用既定污染關鍵字清單掃描文件與程式候選檔，不把污染字串寫入文件內容。 |

## 3. 停止線掃描

| 停止線 | 掃描方向 |
|---|---|
| 未確認 service install | 不得出現自動執行的 `sc.exe create`、`New-Service`、service delete。 |
| 未確認 service account | 不得出現正式帳號、密碼、token、正式 IP、正式網域。 |
| 未確認正式路徑 | 不得硬寫 production log path、config path 或機器名稱。 |
| 未確認 WebApi auth / Swagger | 不得修改 WebApi auth / Swagger 程式。 |
| 未確認 DB | 不得新增 DDL、ALTER TABLE、formal Apply 或真實 DB 寫入。 |
| 未確認外部 DLL | 不得新增外部 DLL 載入、plugin folder scan 或未知 DLL 執行。 |

## 4. 驗收紀錄需要包含

- 程式 commit。
- 本機測試結果。
- GitHub Actions run。
- 停止線掃描結果。
- 是否有 manual-only runbook。
- 是否安裝過 Windows Service；若未安裝需明確寫「未安裝」。
- 未完成項與後續 5F 整合驗收前提。

## 5. 結論

5E 第一批實作需先證明 ServiceHost 可以以可測試的 service hosting contract 承接 Windows Service 化；正式 service install、service account、recovery、正式 log / config path 與部署權限仍應作為後續 manual-only 驗收或獨立確認節點。
