From 2dab5f89cb083e0e4ea10e16006ada75777301ea Mon Sep 17 00:00:00 2001 From: Daniel Areste Hernandez Date: Mon, 13 Oct 2025 15:15:36 +0200 Subject: [PATCH 1/4] feat: add manifest validation to integration test --- .github/scripts/verify-manifest.sh | 90 ++++++++++++++++++++++++++ .github/workflows/integration-test.yml | 4 ++ 2 files changed, 94 insertions(+) create mode 100755 .github/scripts/verify-manifest.sh diff --git a/.github/scripts/verify-manifest.sh b/.github/scripts/verify-manifest.sh new file mode 100755 index 0000000..9c8041b --- /dev/null +++ b/.github/scripts/verify-manifest.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Exit codes: +# 0 - success +# 2 - usage / bad args +# 3 - missing dependency (jq) +# 4 - manifest.json not found +# 5 - manifest.json exists but is not a regular file +# 6 - manifest.json is not valid JSON +# 7 - missing required JSON keys + +if [[ ${#} -ne 1 ]]; then + usage +fi + +dir="$1" +manifest="$dir/manifest.json" + +if ! command -v jq >/dev/null 2>&1; then + echo "ERROR: jq is required but not found in PATH" >&2 + exit 3 +fi + +if [[ ! -e "$manifest" ]]; then + echo "ERROR: manifest.json not found in directory: $dir" >&2 + exit 4 +fi + +if [[ ! -f "$manifest" ]]; then + echo "ERROR: $manifest exists but is not a regular file" >&2 + exit 5 +fi + +# Validate JSON +if ! jq empty "$manifest" >/dev/null 2>&1; then + echo "ERROR: $manifest is not valid JSON" >&2 + # show where jq fails (best-effort) + jq . "$manifest" 2>/dev/null || true + exit 6 +fi + +required=( + "version" + "ts.start" + "ts.stop" + "package_type" + "root_dir" + "commands" + "platform_info.platform_type" + "platform_info.hostname" + "platform_info.serial_number" + "product_info.product" + "product_info.version" + "product_info.build" +) + +missing=() +for p in "${required[@]}"; do + # split dot-separated path into array elements and build a jq array literal + IFS='.' read -r -a parts <<< "$p" + # build JSON array like ["a","b"] + jq_array="[" + first=1 + for part in "${parts[@]}"; do + if [[ $first -eq 1 ]]; then + jq_array+="\"${part}\"" + first=0 + else + jq_array+=",\"${part}\"" + fi + done + jq_array+="]" + + # Test presence: use getpath(array) and check that it exists and is not null + if ! jq -e "getpath($jq_array) != null" "$manifest" >/dev/null 2>&1; then + missing+=("$p") + fi +done + +if [[ ${#missing[@]} -ne 0 ]]; then + echo "ERROR: manifest.json is missing required keys:" >&2 + for m in "${missing[@]}"; do + echo " - $m" >&2 + done + exit 7 +fi + +echo "OK: $manifest is valid and contains all required keys" +exit 0 diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index e55bde2..8677318 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -106,6 +106,10 @@ jobs: # Verify expected files exist bash .github/scripts/verify-contents.sh extracted_test + - name: Validate manifest file + run: | + bash .github/scripts/verify-manifest.sh extracted_test + - name: Upload test artifacts if: always() uses: actions/upload-artifact@v4 From f3b256c5d46a3a09239544915c88e1aa2e53e6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Arest=C3=A9?= <5310624+dareste@users.noreply.github.com> Date: Mon, 13 Oct 2025 15:20:41 +0200 Subject: [PATCH 2/4] Update .github/scripts/verify-manifest.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/scripts/verify-manifest.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/scripts/verify-manifest.sh b/.github/scripts/verify-manifest.sh index 9c8041b..afc460c 100755 --- a/.github/scripts/verify-manifest.sh +++ b/.github/scripts/verify-manifest.sh @@ -10,6 +10,10 @@ set -euo pipefail # 6 - manifest.json is not valid JSON # 7 - missing required JSON keys +usage() { + echo "Usage: $0 " >&2 + exit 2 +} if [[ ${#} -ne 1 ]]; then usage fi From a73b9c3febf9b2aed55065036a7ca38f1a84b127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Arest=C3=A9?= <5310624+dareste@users.noreply.github.com> Date: Mon, 13 Oct 2025 15:24:07 +0200 Subject: [PATCH 3/4] Update .github/scripts/verify-manifest.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/scripts/verify-manifest.sh | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/.github/scripts/verify-manifest.sh b/.github/scripts/verify-manifest.sh index afc460c..c6dd57c 100755 --- a/.github/scripts/verify-manifest.sh +++ b/.github/scripts/verify-manifest.sh @@ -61,23 +61,8 @@ required=( missing=() for p in "${required[@]}"; do - # split dot-separated path into array elements and build a jq array literal - IFS='.' read -r -a parts <<< "$p" - # build JSON array like ["a","b"] - jq_array="[" - first=1 - for part in "${parts[@]}"; do - if [[ $first -eq 1 ]]; then - jq_array+="\"${part}\"" - first=0 - else - jq_array+=",\"${part}\"" - fi - done - jq_array+="]" - - # Test presence: use getpath(array) and check that it exists and is not null - if ! jq -e "getpath($jq_array) != null" "$manifest" >/dev/null 2>&1; then + # Test presence: use getpath(split(".")) and check that it exists and is not null + if ! jq -e --arg p "$p" 'getpath($p | split(".")) != null' "$manifest" >/dev/null 2>&1; then missing+=("$p") fi done From 91a568ab727977b35acb989b9cf133bcacdf74a9 Mon Sep 17 00:00:00 2001 From: Daniel Areste Hernandez Date: Tue, 14 Oct 2025 11:55:15 +0200 Subject: [PATCH 4/4] feat: check correspondence between files in supportpkg and manifest --- .github/scripts/verify-manifest.sh | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/scripts/verify-manifest.sh b/.github/scripts/verify-manifest.sh index c6dd57c..2c003d8 100755 --- a/.github/scripts/verify-manifest.sh +++ b/.github/scripts/verify-manifest.sh @@ -3,17 +3,14 @@ set -euo pipefail # Exit codes: # 0 - success -# 2 - usage / bad args # 3 - missing dependency (jq) # 4 - manifest.json not found # 5 - manifest.json exists but is not a regular file # 6 - manifest.json is not valid JSON # 7 - missing required JSON keys +# 8 - missing files in the supportpkg +# 9 - missing files in the manifest -usage() { - echo "Usage: $0 " >&2 - exit 2 -} if [[ ${#} -ne 1 ]]; then usage fi @@ -75,5 +72,23 @@ if [[ ${#missing[@]} -ne 0 ]]; then exit 7 fi -echo "OK: $manifest is valid and contains all required keys" +# Check that there is a 1:1 correspondence between manifest and tarball content + +find "${dir}" -type f -mindepth 1 | cut -c "$(( ${#dir} + 1 ))"- > find-output.txt +jq -r '.commands[].output' "${dir}"/manifest.json > manifest-output.txt +printf "/manifest.json\n/supportpkg.log" >> manifest-output.txt +if grep -vxFf find-output.txt manifest-output.txt >/dev/null; then + echo "ERROR: Manifest contains files not present in the supportpkg:" + grep -vxFf find-output.txt manifest-output.txt + exit 8 +fi +if grep -vxFf manifest-output.txt find-output.txt >/dev/null; then + echo "ERROR: Supportpkg contains files not present in the manifest:" + grep -vxFf manifest-output.txt find-output.txt + exit 9 +fi + +# All good if we reached this point + +echo "OK: $manifest is valid and consistent with the supportpkg contents" exit 0