Task #253 follow-up — fix test-all.ps1 StrictMode crash on missing JSON keys #215
Reference in New Issue
Block a user
Delete Branch "task-253d-e2e-debug-harness"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Running the e2e suite end-to-end surfaced one more harness bug:
test-all.ps1crashed with "The property 'X' cannot be found on this object" whenever the sidecar JSON omitted an optional key.Root cause
_common.ps1setsSet-StrictMode -Version 3.0. Under strict mode, missing-property access on aPSCustomObject(whatConvertFrom-Jsonreturns by default) throws. Every$config.<driver>.<optional> ?? $default+if ($config.<missing-section>)was unsafe.Fix
ConvertFrom-Json -AsHashtable— hashtables tolerate.ContainsKey()/ indexer lookup under strict mode.Get-Orhelper:Get-Or $table "key" $defaultreturns the value if present, else the default.Verified end-to-end
With
docker compose upfor pymodbus / ab_server / python-snap7 fixtures, plus the three driver sections populated in a locale2e-config.json:Also ran each per-driver script directly:
test-modbus.ps1/test-abcip.ps1/test-s7.ps1— 2/5 PASS (probe + driver loopback), 3/5 FAIL at the bridge as expected (server-wiring blocker #209).test-focas.ps1/test-twincat.ps1/test-ablegacy.ps1— SKIP with clear gate messages when the respective*_TRUST_WIREenv var isn't set.Test plan
Running `test-all.ps1` end-to-end with a partial sidecar (only modbus/ abcip/s7 populated, no focas/twincat/phase7) crashed: [FAIL] modbus runner crashed: The property 'opcUaUrl' cannot be found on this object. Verify that the property exists. Root cause: `_common.ps1` sets `Set-StrictMode -Version 3.0`, which turns missing-property access on PSCustomObject into a throw. Every `$config.<driver>.<optional-field> ?? $default` and `if ($config.<missing-section>)` check is therefore unsafe against a normal JSON where optional fields are omitted. Fix: switch to `ConvertFrom-Json -AsHashtable` and add a `Get-Or` helper. Hashtables tolerate `.ContainsKey()` / indexer access even under StrictMode, so the per-driver sections now read: $modbus = Get-Or $config "modbus" if ($modbus) { ... -OpcUaUrl (Get-Or $modbus "opcUaUrl" $OpcUaUrl) ... } Verified end-to-end with live docker-compose fixtures: - Modbus / AB CIP / S7 each run to completion, report 2/5 PASS (the driver-only stages) and FAIL the 3 server-bridge stages (expected — server-side factory wiring is blocked on #209). - The FINAL MATRIX header renders cleanly with SKIP rows for the drivers not present in the sidecar + FAIL rows for the present ones. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>