fix(onboarding-diag): jq-normalize single-element facts arrays (cc5dbdfa)

PowerShell ConvertTo-Json collapses a single-element array into a bare
object (or, for string arrays, a bare string). The runner iterated/joined
several facts.* fields, so single-volume / single-NIC / single-admin
machines silently dropped the Fixed Volumes table and errored the network
adapter, local-administrator, and installed-software-diff lines.

Fix jq-side in the runner (backward-compatible with already-written
immutable baselines; PS1 untouched per the todo decision) using
`if type=="array" then . elif .==null then [] else [.] end` at:
volumes, network_adapters (+ inner ip/dns), local_administrators, and
installed_software (both sides of the diff). Verified with synthetic
single-element JSON and a multi-element no-regression check.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 14:12:30 -07:00
parent 4d91a1fb63
commit a735d8c220

View File

@@ -415,21 +415,21 @@ echo "$DIAG_JSON" | jq '.' > "$JSON_PATH"
"- **Pending reboot:** " + (($f.pending_reboot // false)|tostring) + "\n" +
"- **Installed software count:** " + (($f.installed_software_count // 0)|tostring) + "\n" +
"- **Scheduled tasks (non-MS, enabled):** " + (($f.scheduled_tasks_count // 0)|tostring) + "\n" +
"- **Local administrators:** " + (($f.local_administrators // []) | join(", "))
"- **Local administrators:** " + (($f.local_administrators | if type=="array" then . elif .==null then [] else [.] end) | join(", "))
'
echo ""
echo "### Fixed volumes"
echo ""
echo "$DIAG_JSON" | jq -r '
(.facts.volumes // []) | .[] |
(.facts.volumes | if type=="array" then . elif .==null then [] else [.] end) | .[] |
"- " + (.drive // "?") + " - " + ((.free_gb // 0)|tostring) + " GB free of " + ((.size_gb // 0)|tostring) + " GB (" + ((.free_pct // 0)|tostring) + "%)"
'
echo ""
echo "### Network adapters"
echo ""
echo "$DIAG_JSON" | jq -r '
(.facts.network_adapters // []) | .[] |
"- " + (.description // "?") + " - IP: " + ((.ip // []) | join(", ")) + " - DNS: " + ((.dns // []) | join(", ")) + " - DHCP: " + ((.dhcp // false)|tostring)
(.facts.network_adapters | if type=="array" then . elif .==null then [] else [.] end) | .[] |
"- " + (.description // "?") + " - IP: " + ((.ip | if type=="array" then . elif .==null then [] else [.] end) | join(", ")) + " - DNS: " + ((.dns | if type=="array" then . elif .==null then [] else [.] end) | join(", ")) + " - DHCP: " + ((.dhcp // false)|tostring)
'
echo ""
@@ -504,15 +504,15 @@ echo "$DIAG_JSON" | jq '.' > "$JSON_PATH"
SW_ADDED="$(jq -n \
--slurpfile cur "$JSON_PATH" \
--slurpfile old "$PRIOR_JSON" '
((($old[0].facts.installed_software // []) | map(.name)) | unique) as $o |
((($cur[0].facts.installed_software // []) | map(.name)) | unique) as $c |
((($old[0].facts.installed_software | if type=="array" then . elif .==null then [] else [.] end) | map(.name)) | unique) as $o |
((($cur[0].facts.installed_software | if type=="array" then . elif .==null then [] else [.] end) | map(.name)) | unique) as $c |
[ $c[] | select(. as $n | ($o | index($n)) | not) ]
')"
SW_REMOVED="$(jq -n \
--slurpfile cur "$JSON_PATH" \
--slurpfile old "$PRIOR_JSON" '
((($old[0].facts.installed_software // []) | map(.name)) | unique) as $o |
((($cur[0].facts.installed_software // []) | map(.name)) | unique) as $c |
((($old[0].facts.installed_software | if type=="array" then . elif .==null then [] else [.] end) | map(.name)) | unique) as $o |
((($cur[0].facts.installed_software | if type=="array" then . elif .==null then [] else [.] end) | map(.name)) | unique) as $c |
[ $o[] | select(. as $n | ($c | index($n)) | not) ]
')"