4D 最小 Application plugin contract 實作與驗收紀錄

返回

4D 最小 Application plugin contract 實作與驗收紀錄

本文件承接 4D 最小 Application plugin contract 實作前最後確認表,記錄 4D 最小 Application plugin contract 的程式實作範圍、測試結果與停止線。

本次完成不代表真正 PluginLoader 已完成,不代表建立 IPluginLoader,不代表掃描 plugin folder、載入外部 DLL、執行外部 plugin 程式碼、修改 Adapter public contract、修改 config schema、執行 DB DDL 或接真實硬體。

0. 驗收狀態

項目內容
文件狀態已完成
整理日期2026-06-06
對應階段第四階段 4D 最小 Application plugin contract
程式 repohs-device-control-template
程式 branchpoc/nmodbus-tcp
前一程式基準 commita846212 新增 4C ServiceHost 第一版與驗收測試
4D 程式 commit6f34bb9 新增 4D 最小 Application plugin contract
push 狀態已 push 至 origin/poc/nmodbus-tcp
GitHub ActionsRun 27064992270 success
使用者確認4D 最小 contract 確認 七項皆同意
本次定位Application 層 plugin metadata / verification / state / audit 最小 contract
本次驗收結論通過;Application.Tests 40 passed,solution tests 492 passed,程式 repo commit / push / Actions success

1. 程式實作範圍

類型檔案說明
新增 state enumsrc/HS.DeviceControl.Application/Plugins/PluginLoadState.cs定義 DiscoveredVerifiedRejectedDisabledFaultedLoadedLoaded 僅保留未來語意,第一版不產生。
新增 verification checksrc/HS.DeviceControl.Application/Plugins/PluginVerificationCheck.cs定義單一檢查項目的 NameSuccessCodeMessage
新增 verification resultsrc/HS.DeviceControl.Application/Plugins/PluginVerificationResult.cs定義 SuccessCodeMessagePluginIdStateChecksWarningsTimeTakenMsError
新增 audit recordsrc/HS.DeviceControl.Application/Plugins/PluginAuditRecord.cs定義 AuditIdPluginIdDecisionReasonOperatorSourceChecksumCreatedAtUtc
新增內部安全 helpersrc/HS.DeviceControl.Application/Plugins/PluginContractTextSafety.cs只供 Application plugin contract 內部判斷 sensitive marker 與疑似正式路徑,不是 public Loader contract。
擴充 descriptorsrc/HS.DeviceControl.Application/Plugins/PluginDescriptor.cs相容擴充 ContractVersionSourceEnabledDisabledReason,既有 constructor 仍保留。
擴充 catalog validationsrc/HS.DeviceControl.Application/Plugins/PluginCatalogService.cs補 contract version、source、disabled reason 與 sensitive metadata 驗證;仍不讀檔、不掃描 folder。
擴充錯誤碼src/HS.DeviceControl.Application/Common/ApplicationErrorCodes.cs新增 APP-0332APP-0335
新增與擴充測試tests/HS.DeviceControl.Application.Tests/*補 verification result、audit record、catalog contract version/source/disabled 驗證。

2. Contract 行為

Contract行為
PluginLoadState成功驗證只回 VerifiedLoaded 只保留未來語意。
PluginVerificationResult.OkSuccess=trueCode=NONEState=Verified,可承接 checks / warnings / timeTakenMs。
PluginVerificationResult.FailSuccess=false,若外部傳入 Loaded 會降為 Rejected,避免第一版產生載入狀態。
PluginVerificationCheckmessage 會做敏感資訊與路徑遮罩。
PluginAuditRecord不寫 DB,會遮罩 token / password / connection string / 正式路徑。
PluginDescriptormetadata 加上 contract version、source、enabled、disabled reason;啟用不代表可載入 DLL。
PluginCatalogService只驗 metadata,不建立 Loader,不讀取 DLL,不掃描 plugin folder。

3. 驗證紀錄

驗證項目指令 / 方法結果
Application tests 初次執行dotnet test tests/HS.DeviceControl.Application.Tests/HS.DeviceControl.Application.Tests.csproj第一次因 NuGet AppData lock 無法取得鎖定而中止,不是測試失敗。
Application tests 重跑dotnet test tests/HS.DeviceControl.Application.Tests/HS.DeviceControl.Application.Tests.csprojPassed:40 passed / 0 failed / 0 skipped。
Solution testsdotnet test HS.DeviceControl.slnPassed:492 passed / 0 failed / 0 skipped。
Loader / DLL 停止線掃描rg "Assembly\.Load\|LoadFrom\(\|LoadFile\(\|IPluginLoader\|class PluginLoader" src tests samples無命中。
diff checkgit diff --check無 whitespace error;僅有 LF/CRLF 提醒。
尾端空白掃描rg "\s+$" 掃描本次程式檔無命中。

4. 測試覆蓋

測試驗證內容
PluginCatalogServiceTestsmetadata 不載入 DLL、缺少 PluginId、敏感資訊、缺少 capability、缺 contract version、unsafe source、disabled reason。
PluginVerificationResultTests成功狀態為 Verified、失敗狀態不可產生 Loaded、失敗訊息遮罩、disabled state 可表達。
PluginAuditRecordTestssafe summary 保留、敏感 reason 與正式路徑遮罩、AuditId 缺省時自動產生。

5. 停止線稽核

停止線本次結果
不建立 IPluginLoader遵守
不建立 PluginLoader遵守
不掃描 plugin folder遵守
不載入外部 DLL遵守
不執行外部 plugin 程式碼遵守
不改 Adapter public contract遵守
不改 config schema遵守
不新增 WebApi route / ServiceHost lifecycle遵守
不寫 DB、不執行 DDL / ALTER TABLE / Apply遵守
不保存密碼、Token、connection string 或正式 DLL 路徑遵守

6. 完成判定

4D 最小 Application plugin contract 第一版已完成本機實作與測試驗證,可作為未來真正 PluginLoader 前的 metadata / verification / state / audit contract 基礎。

本次仍未建立動態 Loader;外部 DLL 載入、簽章驗證、版本信任模型落地、plugin folder 掃描、config schema 與 Adapter contract 仍需另行確認。

7. 建議下一步

建議接著查看 4D PluginLoader 完成稽核表,再同步文件 repo stage / commit / push 與線上部署查驗。