# 5B config schema 實作與驗收紀錄

本文件記錄第五階段 5B config schema 的程式實作、測試、停止線與提交驗收。5B 僅完成 appsettings metadata-only schema 與 validator，不代表系統已啟用真實 PluginLoader、外部 DLL 載入、DB audit、auth / Swagger 或 Windows Service。

## 0. 基本資訊

| 項目 | 內容 |
|---|---|
| 驗收日期 | 2026-06-07 |
| 對應節點 | 第五階段 5B config schema |
| 程式 repo | `hs-device-control-template` |
| 程式 branch | `poc/nmodbus-tcp` |
| 程式 commit | `1f635d6` |
| Commit 訊息 | 新增 5B config schema 驗證 |
| GitHub Actions | `27087431249` success |
| 文件 repo 自動狀態同步 | `27087433624` success |

## 1. 程式修改範圍

| 類別 | 檔案 |
|---|---|
| Config model | `src/HS.DeviceControl.Core/Configuration/AppSettingsConfig.cs` |
| Config validator | `src/HS.DeviceControl.Core/Configuration/ConfigValidator.cs` |
| Sample config | `samples/config/appsettings.json` |
| Core tests | `tests/HS.DeviceControl.Core.Tests/ConfigValidatorTests.cs` |
| Loader sample test | `tests/HS.DeviceControl.Core.Tests/ConfigLoaderTests.cs` |
| Config 文件 | `docs/config-schema.md` |
| README | `README.md` |

## 2. 實作內容

| 項目 | 結果 |
|---|---|
| `PluginLoader` schema | 新增 `Enabled`、`ExpectedContractVersion`、`ExpectedChecksum`、`AllowManualExternalDllVerification`、`AllowDisabledPluginReview`。 |
| safe default | `Enabled`、`AllowManualExternalDllVerification`、`AllowDisabledPluginReview` 預設皆為 `false`。 |
| `Plugins` schema | 新增 metadata-only plugin 清單，包含 `PluginId`、`Version`、`DisplayName`、`ContractVersion`、`Checksum`、`SourceSummary`、`Enabled`、`DisabledReason`、`Capabilities`。 |
| validator | 驗證 PluginId 必填 / 不重複、必要 metadata、capability 必填、停用 plugin 必填 reason、敏感字串與 unsafe source summary 拒絕。 |
| sample config | 新增安全範例，PluginLoader gate 預設關閉，plugin metadata 使用 `internal-reviewed-catalog`，不保存路徑或正式連線資訊。 |
| config 文件 | 新增程式 repo `docs/config-schema.md`，記錄 5B schema 與停止線。 |

## 3. 測試與驗收結果

| 驗證項目 | 結果 |
|---|---|
| `dotnet test tests\HS.DeviceControl.Core.Tests\HS.DeviceControl.Core.Tests.csproj --no-restore` | 196 passed / 0 failed / 0 skipped |
| `dotnet test tests\HS.DeviceControl.Application.Tests\HS.DeviceControl.Application.Tests.csproj --no-restore` | 57 passed / 0 failed / 0 skipped |
| `dotnet test HS.DeviceControl.sln --no-restore` | 516 passed / 0 failed / 0 skipped |
| 5B config source 停止線掃描 | 本次修改的 Core config / sample config 未命中外部載入 API、plugin folder scan、DB DDL、Swagger 或 Windows Service。 |
| 污染字串掃描 | 未命中指定八項污染字串。 |
| `git diff --cached --check` | 通過 |
| GitHub Actions | `27087431249` completed success |

備註：solution 測試仍有既有 `.NET 5.0` EOL warning，與本次 5B schema 修改無關。

## 4. 停止線確認

本次 5B 實作沒有做下列事項：

- 不載入外部 DLL。
- 不掃描 plugin folder。
- 不保存 DLL path、plugin folder、正式 IP、port、secret、token 或 connection string。
- 不修改 `PluginLoaderOptions` / `ExternalDllManualVerifierOptions` public contract。
- 不修改 WebApi route、auth 或 Swagger。
- 不修改 ServiceHost 或 Windows Service。
- 不新增 DB audit table。
- 不執行 DDL / ALTER TABLE / formal Apply。
- 不修改 Adapter public contract。

## 5. 驗收結論

5B config schema 已完成本批核准範圍：appsettings metadata-only schema、validator、safe sample config、Core tests 與 config schema 文件均已建立並通過驗證。下一步可進入 5C DB audit 邊界分析與實作前確認；任何 DB audit table、DDL、正式 Apply 或真實 DB 寫入仍需停下確認。
