# 5E Windows Service 最小實作前最後確認表

本文件承接 [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 Windows Service 實作前文件線上驗收紀錄](phase-five-e-windows-service-preimplementation-online-acceptance-record.md)。

5E 是 ServiceHost 正式服務化邊界節點，會影響作業系統服務生命週期、安裝權限、服務帳號、正式 log / config path 與 recovery 行為。因此本文件是進入程式 repo 修改前的最後確認 gate；未完成七項確認前，不得修改 ServiceHost 程式或建立 Windows Service。

## 0. 文件狀態

| 項目 | 內容 |
|---|---|
| 文件狀態 | 待確認 |
| 建立日期 | 2026-06-07 |
| 對應節點 | 第五階段 5E Windows Service |
| 程式 repo | `hs-device-control-template` |
| 程式 branch | `poc/nmodbus-tcp` |
| 程式基準 | `c92342b` |
| 本文件是否授權程式修改 | 尚未；需等待使用者回覆七項皆同意 |

## 1. 最小實作範圍

| 範圍 | 最小版本決策 |
|---|---|
| Service hosting | 只建立可測試的最小 service hosting 結構，不自動安裝正式服務。 |
| Console path | 保留既有 console smoke path，不破壞現有 ServiceHost runtime tests。 |
| Options | 僅允許非敏感 options；正式 service account、正式 path 與正式機器名稱不得寫入 repo。 |
| Recovery | 先以文件與可測 options 固定候選行為，正式 recovery 設定需另行驗收。 |
| Install gate | 任何 install / uninstall / start / stop script 皆需 manual-only gate，預設不得執行。 |
| Tests | 需新增或更新 ServiceHost tests，並保留 Application / solution tests。 |
| 文件 | 完成後需補實作紀錄、驗收紀錄、README / status / progress / public mirror 與線上驗收。 |

## 2. 最後七項確認

| 編號 | 確認項 | 同意內容 |
|---|---|---|
| 1 | 最小 service hosting | 同意 5E 第一批只建立可測試的最小 Windows Service hosting 邊界，不自動安裝正式服務。 |
| 2 | Console path 保留 | 同意保留既有 console smoke path，新增 service hosting path 不得破壞現有啟動與測試。 |
| 3 | 安裝停止線 | 同意本批不執行 service create / delete / install / uninstall，不修改正式機器。 |
| 4 | 敏感資訊安全 | 同意 repo 不保存 service account、password、token、正式 IP、正式網域、正式路徑或正式機器名稱。 |
| 5 | Recovery / log / config | 同意先以非敏感 options 與文件固定候選行為，正式 recovery、log path 與 config path 需另行驗收。 |
| 6 | 測試與停止線 | 同意實作後執行 ServiceHost tests、Application tests、solution tests、停止線掃描、污染掃描與 commit 前檢查。 |
| 7 | 排除項目 | 同意本批不做 WebApi auth / Swagger、DB DDL、正式 DB 寫入、外部 DLL 載入、plugin folder 掃描、Adapter public contract、正式部署權限設定或 GitHub / Cloudflare secret 設定。 |

## 3. 程式候選檔案

| 類型 | 候選檔案 |
|---|---|
| Service options | `src/HS.DeviceControl.ServiceHost/Options/` |
| Hosting / wrapper | `src/HS.DeviceControl.ServiceHost/Services/` 或 `src/HS.DeviceControl.ServiceHost/Hosting/` |
| Startup path | `src/HS.DeviceControl.ServiceHost/Program.cs` |
| Project package | `src/HS.DeviceControl.ServiceHost/HS.DeviceControl.ServiceHost.csproj`，若需新增 package 必須先確認 |
| Tests | `tests/HS.DeviceControl.ServiceHost.Tests` |
| Manual-only docs / script | `docs/` 或 `scripts/`，不得預設安裝正式服務 |

若實作時需要新增核心套件、修改啟動方式、保存正式 service account、執行服務安裝、修改正式機器設定或調整部署設定，需停下重新確認。

## 4. 必要驗收

| 驗收項目 | 預期 |
|---|---|
| Existing console path | 既有 ServiceHost console smoke path 不被破壞。 |
| Service lifecycle | 可測 start / stop / status / failure mapping，不依賴正式 OS service。 |
| Options safety | 非敏感欄位可驗證；正式 path、account、secret 不進 repo。 |
| Manual-only gate | install / uninstall / start / stop script 預設不執行。 |
| Stop-line scan | 未新增正式 service account、production path、DB DDL、WebApi auth / Swagger 或外部 DLL 載入。 |
| Tests | ServiceHost tests、Application tests、solution tests 通過。 |

## 5. 建議回覆格式

若同意進入 5E 最小 Windows Service 程式實作，請回覆：

```text
5E Windows Service 最小實作前最後確認：
1. 同意
2. 同意
3. 同意
4. 同意
5. 同意
6. 同意
7. 同意
```

## 6. 未確認前停止線

在使用者完成七項確認前，不得修改程式 repo，不得新增 Windows Service package、`UseWindowsService`、hosted service、service installer、安裝腳本、正式 service account、正式 log path、正式 config path 或正式部署設定。
