From 1f83f8a097845167e9ae8d0692771b865512f4c8 Mon Sep 17 00:00:00 2001 From: gibKim Date: Sun, 22 Nov 2026 10:51:15 +0900 Subject: [PATCH 1/2] fix: distinguish ambiguous bootstrap metadata files Report multiple dependency or runtime configuration files separately from missing files while preserving selection and exit codes. Add bootstrap regression checks to the Linux unit test entry point. Fixes #1430 Assisted-by: Codex/GPT-6 --- .../changes/bootstrap-ambiguous-metadata.json | 11 +++ .../Amazon.Lambda.RuntimeSupport/bootstrap.sh | 12 ++- ...zon.Lambda.RuntimeSupport.UnitTests.csproj | 4 + .../bootstrap-tests.sh | 85 +++++++++++++++++++ 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 .autover/changes/bootstrap-ambiguous-metadata.json create mode 100644 Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/bootstrap-tests.sh diff --git a/.autover/changes/bootstrap-ambiguous-metadata.json b/.autover/changes/bootstrap-ambiguous-metadata.json new file mode 100644 index 000000000..25f658361 --- /dev/null +++ b/.autover/changes/bootstrap-ambiguous-metadata.json @@ -0,0 +1,11 @@ +{ + "Projects": [ + { + "Name": "Amazon.Lambda.RuntimeSupport", + "Type": "Patch", + "ChangelogMessages": [ + "Distinguish multiple dependency or runtime configuration files from missing files in bootstrap diagnostics." + ] + } + ] +} diff --git a/Libraries/src/Amazon.Lambda.RuntimeSupport/bootstrap.sh b/Libraries/src/Amazon.Lambda.RuntimeSupport/bootstrap.sh index 2c4a517f9..558843d63 100644 --- a/Libraries/src/Amazon.Lambda.RuntimeSupport/bootstrap.sh +++ b/Libraries/src/Amazon.Lambda.RuntimeSupport/bootstrap.sh @@ -68,6 +68,11 @@ else if ! [ -f "${DEPS_FILE}" ]; then DEPS_FILES=( "${LAMBDA_TASK_ROOT}"/*.deps.json ) + if [ "${#DEPS_FILES[@]}" -gt 1 ]; then + echo "Error: Found multiple .deps.json files in ${LAMBDA_TASK_ROOT}. Expected ${ASSEMBLY_NAME}.deps.json." 1>&2 + exit 105 + fi + # Check if there were any matches to the *.deps.json glob, and that the glob was resolved # This makes the matching independent from the global `nullopt` shopt's value (https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html) if [ "${#DEPS_FILES[@]}" -ne 1 ] || echo "${DEPS_FILES[0]}" | grep -q -F '*'; then @@ -81,6 +86,11 @@ else if ! [ -f "${RUNTIMECONFIG_FILE}" ]; then RUNTIMECONFIG_FILES=( "${LAMBDA_TASK_ROOT}"/*.runtimeconfig.json ) + if [ "${#RUNTIMECONFIG_FILES[@]}" -gt 1 ]; then + echo "Error: Found multiple .runtimeconfig.json files in ${LAMBDA_TASK_ROOT}. Expected ${ASSEMBLY_NAME}.runtimeconfig.json." 1>&2 + exit 106 + fi + # Check if there were any matches to the *.runtimeconfig.json glob, and that the glob was resolved # This makes the matching independent from the global `nullopt` shopt's value (https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html) if [ "${#RUNTIMECONFIG_FILES[@]}" -ne 1 ] || echo "${RUNTIMECONFIG_FILES[0]}" | grep -q -F '*'; then @@ -118,4 +128,4 @@ else else exec -- "${AWS_LAMBDA_EXEC_WRAPPER}" "${DOTNET_BIN}" "${DOTNET_EXEC}" "${DOTNET_ARGS[@]}" fi -fi \ No newline at end of file +fi diff --git a/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/Amazon.Lambda.RuntimeSupport.UnitTests.csproj b/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/Amazon.Lambda.RuntimeSupport.UnitTests.csproj index e951ed51a..51d2014f0 100644 --- a/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/Amazon.Lambda.RuntimeSupport.UnitTests.csproj +++ b/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/Amazon.Lambda.RuntimeSupport.UnitTests.csproj @@ -42,4 +42,8 @@ Always + + + + diff --git a/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/bootstrap-tests.sh b/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/bootstrap-tests.sh new file mode 100644 index 000000000..3c54e9d77 --- /dev/null +++ b/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/bootstrap-tests.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# SPDX-License-Identifier: Apache-2.0 + +set -eu + +script_directory="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +bootstrap="${script_directory}/../../../src/Amazon.Lambda.RuntimeSupport/bootstrap.sh" +test_directory="$(mktemp -d)" +trap 'rm -rf "${test_directory}"' EXIT + +wrapper="${test_directory}/wrapper" +printf '#!/bin/bash\nprintf "%%s\\n" "$@"\n' > "${wrapper}" +chmod +x "${wrapper}" + +failures=0 +tests=0 + +run_case() { + local name="$1" nullglob="$2" expected_exit="$3" expected_message="$4" + local expected_deps="$5" expected_runtimeconfig="$6" + shift 6 + local directory="${test_directory}/${name}-${nullglob}" + mkdir "${directory}" + for file in "$@"; do + printf '{}\n' > "${directory}/${file}" + done + + local actual_exit=0 + env -u BASH_ENV -u SHELLOPTS -u BASHOPTS -u LAMBDA_DOTNET_MAIN_ASSEMBLY -u _HANDLER \ + LAMBDA_TASK_ROOT="${directory}" AWS_LAMBDA_EXEC_WRAPPER="${wrapper}" \ + bash "${nullglob}" nullglob "${bootstrap}" 'Example::Function::Handle' \ + > "${directory}/stdout" 2> "${directory}/stderr" || actual_exit=$? + + tests=$((tests + 1)) + if [ "${actual_exit}" -ne "${expected_exit}" ]; then + printf 'FAIL %s (%s): expected exit %s, got %s\n' "${name}" "${nullglob}" "${expected_exit}" "${actual_exit}" >&2 + cat "${directory}/stderr" >&2 + failures=$((failures + 1)) + return + fi + + if [ "${expected_exit}" -ne 0 ]; then + if ! grep -F -q -- "${expected_message}" "${directory}/stderr"; then + printf 'FAIL %s (%s): missing diagnostic: %s\n' "${name}" "${nullglob}" "${expected_message}" >&2 + cat "${directory}/stderr" >&2 + failures=$((failures + 1)) + fi + return + fi + + printf '%s\n' /var/lang/bin/dotnet exec \ + --depsfile "${directory}/${expected_deps}" \ + --runtimeconfig "${directory}/${expected_runtimeconfig}" \ + /var/runtime/Amazon.Lambda.RuntimeSupport.dll 'Example::Function::Handle' \ + > "${directory}/expected" + if ! cmp -s "${directory}/expected" "${directory}/stdout" || [ -s "${directory}/stderr" ]; then + printf 'FAIL %s (%s): unexpected bootstrap arguments or error output\n' "${name}" "${nullglob}" >&2 + cat "${directory}/stderr" >&2 + failures=$((failures + 1)) + fi +} + +for nullglob in +O -O; do + run_case exact "${nullglob}" 0 '' Example.deps.json Example.runtimeconfig.json \ + Example.deps.json Example.runtimeconfig.json + run_case missing-deps "${nullglob}" 105 'missing the required .deps.json file' '' '' \ + Example.runtimeconfig.json + run_case ambiguous-deps "${nullglob}" 105 'multiple .deps.json files' '' '' \ + First.deps.json Second.deps.json Example.runtimeconfig.json + run_case missing-runtimeconfig "${nullglob}" 106 'missing the required .runtimeconfig.json file' '' '' \ + Example.deps.json + run_case ambiguous-runtimeconfig "${nullglob}" 106 'multiple .runtimeconfig.json files' '' '' \ + Example.deps.json First.runtimeconfig.json Second.runtimeconfig.json + run_case single-fallback "${nullglob}" 0 '' Alternate.deps.json Alternate.runtimeconfig.json \ + Alternate.deps.json Alternate.runtimeconfig.json + run_case exact-with-extras "${nullglob}" 0 '' Example.deps.json Example.runtimeconfig.json \ + Example.deps.json Example.runtimeconfig.json First.deps.json Second.deps.json First.runtimeconfig.json Second.runtimeconfig.json + run_case both-ambiguous "${nullglob}" 105 'multiple .deps.json files' '' '' \ + First.deps.json Second.deps.json First.runtimeconfig.json Second.runtimeconfig.json + run_case spaced-fallback "${nullglob}" 0 '' 'Alternate assembly.deps.json' 'Alternate assembly.runtimeconfig.json' \ + 'Alternate assembly.deps.json' 'Alternate assembly.runtimeconfig.json' +done + +printf 'Bootstrap metadata tests: %s passed, %s failed\n' "$((tests - failures))" "${failures}" +[ "${failures}" -eq 0 ] From 2c42bf9d3e638d1d798b233e1625e15457c23a65 Mon Sep 17 00:00:00 2001 From: gibKim Date: Wed, 25 Nov 2026 07:40:47 +0900 Subject: [PATCH 2/2] fix: apply ambiguous metadata diagnostics to .NET 8 bootstrap Run the existing metadata regression cases against both bootstrap scripts. Assisted-by: Codex/GPT-6 --- .../bootstrap.net8.sh | 10 ++++ .../bootstrap-tests.sh | 51 ++++++++++--------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/Libraries/src/Amazon.Lambda.RuntimeSupport/bootstrap.net8.sh b/Libraries/src/Amazon.Lambda.RuntimeSupport/bootstrap.net8.sh index 9dc77ab3a..a1f1d0906 100644 --- a/Libraries/src/Amazon.Lambda.RuntimeSupport/bootstrap.net8.sh +++ b/Libraries/src/Amazon.Lambda.RuntimeSupport/bootstrap.net8.sh @@ -79,6 +79,11 @@ else if ! [ -f "${DEPS_FILE}" ]; then DEPS_FILES=( "${LAMBDA_TASK_ROOT}"/*.deps.json ) + if [ "${#DEPS_FILES[@]}" -gt 1 ]; then + echo "Error: Found multiple .deps.json files in ${LAMBDA_TASK_ROOT}. Expected ${ASSEMBLY_NAME}.deps.json." 1>&2 + exit 105 + fi + # Check if there were any matches to the *.deps.json glob, and that the glob was resolved # This makes the matching independent from the global `nullopt` shopt's value (https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html) if [ "${#DEPS_FILES[@]}" -ne 1 ] || echo "${DEPS_FILES[0]}" | grep -q -F '*'; then @@ -92,6 +97,11 @@ else if ! [ -f "${RUNTIMECONFIG_FILE}" ]; then RUNTIMECONFIG_FILES=( "${LAMBDA_TASK_ROOT}"/*.runtimeconfig.json ) + if [ "${#RUNTIMECONFIG_FILES[@]}" -gt 1 ]; then + echo "Error: Found multiple .runtimeconfig.json files in ${LAMBDA_TASK_ROOT}. Expected ${ASSEMBLY_NAME}.runtimeconfig.json." 1>&2 + exit 106 + fi + # Check if there were any matches to the *.runtimeconfig.json glob, and that the glob was resolved # This makes the matching independent from the global `nullopt` shopt's value (https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html) if [ "${#RUNTIMECONFIG_FILES[@]}" -ne 1 ] || echo "${RUNTIMECONFIG_FILES[0]}" | grep -q -F '*'; then diff --git a/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/bootstrap-tests.sh b/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/bootstrap-tests.sh index 3c54e9d77..d65e84448 100644 --- a/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/bootstrap-tests.sh +++ b/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/bootstrap-tests.sh @@ -4,7 +4,7 @@ set -eu script_directory="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -bootstrap="${script_directory}/../../../src/Amazon.Lambda.RuntimeSupport/bootstrap.sh" +bootstrap_directory="${script_directory}/../../../src/Amazon.Lambda.RuntimeSupport" test_directory="$(mktemp -d)" trap 'rm -rf "${test_directory}"' EXIT @@ -19,7 +19,7 @@ run_case() { local name="$1" nullglob="$2" expected_exit="$3" expected_message="$4" local expected_deps="$5" expected_runtimeconfig="$6" shift 6 - local directory="${test_directory}/${name}-${nullglob}" + local directory="${test_directory}/${bootstrap_name}-${name}-${nullglob}" mkdir "${directory}" for file in "$@"; do printf '{}\n' > "${directory}/${file}" @@ -33,7 +33,7 @@ run_case() { tests=$((tests + 1)) if [ "${actual_exit}" -ne "${expected_exit}" ]; then - printf 'FAIL %s (%s): expected exit %s, got %s\n' "${name}" "${nullglob}" "${expected_exit}" "${actual_exit}" >&2 + printf 'FAIL %s/%s (%s): expected exit %s, got %s\n' "${bootstrap_name}" "${name}" "${nullglob}" "${expected_exit}" "${actual_exit}" >&2 cat "${directory}/stderr" >&2 failures=$((failures + 1)) return @@ -41,7 +41,7 @@ run_case() { if [ "${expected_exit}" -ne 0 ]; then if ! grep -F -q -- "${expected_message}" "${directory}/stderr"; then - printf 'FAIL %s (%s): missing diagnostic: %s\n' "${name}" "${nullglob}" "${expected_message}" >&2 + printf 'FAIL %s/%s (%s): missing diagnostic: %s\n' "${bootstrap_name}" "${name}" "${nullglob}" "${expected_message}" >&2 cat "${directory}/stderr" >&2 failures=$((failures + 1)) fi @@ -54,31 +54,34 @@ run_case() { /var/runtime/Amazon.Lambda.RuntimeSupport.dll 'Example::Function::Handle' \ > "${directory}/expected" if ! cmp -s "${directory}/expected" "${directory}/stdout" || [ -s "${directory}/stderr" ]; then - printf 'FAIL %s (%s): unexpected bootstrap arguments or error output\n' "${name}" "${nullglob}" >&2 + printf 'FAIL %s/%s (%s): unexpected bootstrap arguments or error output\n' "${bootstrap_name}" "${name}" "${nullglob}" >&2 cat "${directory}/stderr" >&2 failures=$((failures + 1)) fi } -for nullglob in +O -O; do - run_case exact "${nullglob}" 0 '' Example.deps.json Example.runtimeconfig.json \ - Example.deps.json Example.runtimeconfig.json - run_case missing-deps "${nullglob}" 105 'missing the required .deps.json file' '' '' \ - Example.runtimeconfig.json - run_case ambiguous-deps "${nullglob}" 105 'multiple .deps.json files' '' '' \ - First.deps.json Second.deps.json Example.runtimeconfig.json - run_case missing-runtimeconfig "${nullglob}" 106 'missing the required .runtimeconfig.json file' '' '' \ - Example.deps.json - run_case ambiguous-runtimeconfig "${nullglob}" 106 'multiple .runtimeconfig.json files' '' '' \ - Example.deps.json First.runtimeconfig.json Second.runtimeconfig.json - run_case single-fallback "${nullglob}" 0 '' Alternate.deps.json Alternate.runtimeconfig.json \ - Alternate.deps.json Alternate.runtimeconfig.json - run_case exact-with-extras "${nullglob}" 0 '' Example.deps.json Example.runtimeconfig.json \ - Example.deps.json Example.runtimeconfig.json First.deps.json Second.deps.json First.runtimeconfig.json Second.runtimeconfig.json - run_case both-ambiguous "${nullglob}" 105 'multiple .deps.json files' '' '' \ - First.deps.json Second.deps.json First.runtimeconfig.json Second.runtimeconfig.json - run_case spaced-fallback "${nullglob}" 0 '' 'Alternate assembly.deps.json' 'Alternate assembly.runtimeconfig.json' \ - 'Alternate assembly.deps.json' 'Alternate assembly.runtimeconfig.json' +for bootstrap_name in bootstrap.sh bootstrap.net8.sh; do + bootstrap="${bootstrap_directory}/${bootstrap_name}" + for nullglob in +O -O; do + run_case exact "${nullglob}" 0 '' Example.deps.json Example.runtimeconfig.json \ + Example.deps.json Example.runtimeconfig.json + run_case missing-deps "${nullglob}" 105 'missing the required .deps.json file' '' '' \ + Example.runtimeconfig.json + run_case ambiguous-deps "${nullglob}" 105 'multiple .deps.json files' '' '' \ + First.deps.json Second.deps.json Example.runtimeconfig.json + run_case missing-runtimeconfig "${nullglob}" 106 'missing the required .runtimeconfig.json file' '' '' \ + Example.deps.json + run_case ambiguous-runtimeconfig "${nullglob}" 106 'multiple .runtimeconfig.json files' '' '' \ + Example.deps.json First.runtimeconfig.json Second.runtimeconfig.json + run_case single-fallback "${nullglob}" 0 '' Alternate.deps.json Alternate.runtimeconfig.json \ + Alternate.deps.json Alternate.runtimeconfig.json + run_case exact-with-extras "${nullglob}" 0 '' Example.deps.json Example.runtimeconfig.json \ + Example.deps.json Example.runtimeconfig.json First.deps.json Second.deps.json First.runtimeconfig.json Second.runtimeconfig.json + run_case both-ambiguous "${nullglob}" 105 'multiple .deps.json files' '' '' \ + First.deps.json Second.deps.json First.runtimeconfig.json Second.runtimeconfig.json + run_case spaced-fallback "${nullglob}" 0 '' 'Alternate assembly.deps.json' 'Alternate assembly.runtimeconfig.json' \ + 'Alternate assembly.deps.json' 'Alternate assembly.runtimeconfig.json' + done done printf 'Bootstrap metadata tests: %s passed, %s failed\n' "$((tests - failures))" "${failures}"