101 lines
3.4 KiB
Bash
Executable File
101 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
repository_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
|
workspace_venv="$repository_root/../.venv"
|
|
test_tmp=$(mktemp -d)
|
|
chmod 0700 "$test_tmp"
|
|
|
|
export ANSIBLE_COLLECTIONS_PATH="$test_tmp/collections"
|
|
export ANSIBLE_ROLES_PATH="$(dirname "$repository_root")"
|
|
|
|
inventory="$repository_root/tests/inventory"
|
|
converge="$repository_root/tests/converge.yml"
|
|
verify_config="$repository_root/tests/verify-config.yml"
|
|
ansible_playbook="$workspace_venv/bin/ansible-playbook"
|
|
binary_path=/usr/local/bin/audita
|
|
config_root="$test_tmp/config"
|
|
config_path="$config_root/config.yml"
|
|
profile_dir="$config_root/profiles"
|
|
|
|
cleanup() {
|
|
exit_status=$?
|
|
trap - EXIT
|
|
rm -rf -- "$test_tmp"
|
|
exit "$exit_status"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
require_clean_recap() {
|
|
grep -Eq 'changed=0 .*failed=0' "$1"
|
|
}
|
|
|
|
run_converge() {
|
|
output_file=$1
|
|
shift
|
|
"$ansible_playbook" -i "$inventory" "${baseline_args[@]}" "$@" "$converge" | tee "$output_file"
|
|
}
|
|
|
|
validate_config() {
|
|
"$binary_path" config validate --config "$config_path"
|
|
}
|
|
|
|
mkdir -p "$profile_dir"
|
|
printf '%s\n' \
|
|
'id: fixture-proposal' \
|
|
'backend: fixture' \
|
|
'model: offline-fixture' \
|
|
'timeout_seconds: 30' > "$profile_dir/fixture-proposal.yaml"
|
|
|
|
baseline_args=(
|
|
-e "audita_config_path=$config_path"
|
|
-e "audita_config_owner=$(id -un)"
|
|
-e "audita_config_group=$(id -gn)"
|
|
-e '{"audita_backends": {"fixture": {"endpoint": "http://127.0.0.1:11434/v1", "credential": null}}, "audita_llm_proposal_profile": "fixture-proposal"}'
|
|
)
|
|
|
|
cd "$repository_root"
|
|
"$workspace_venv/bin/ansible-galaxy" collection install \
|
|
-r collections/requirements.yml \
|
|
-p "$ANSIBLE_COLLECTIONS_PATH"
|
|
"$ansible_playbook" -i "$inventory" "${baseline_args[@]}" --syntax-check "$converge"
|
|
"$workspace_venv/bin/ansible-lint" "$converge" "$verify_config"
|
|
|
|
baseline_log="$test_tmp/baseline.log"
|
|
run_converge "$baseline_log"
|
|
validate_config
|
|
"$binary_path" config print-effective --config "$config_path" --view profiles > "$test_tmp/baseline-profiles.yml"
|
|
baseline_repeat_log="$test_tmp/baseline-repeat.log"
|
|
run_converge "$baseline_repeat_log"
|
|
require_clean_recap "$baseline_repeat_log"
|
|
|
|
representative_config='{"audita_pipeline_modules": ["glossary"], "audita_context_description": "", "audita_output_schema": null, "audita_llm_validation_profile": null}'
|
|
representative_log="$test_tmp/representative-config.log"
|
|
run_converge "$representative_log" -e "$representative_config"
|
|
validate_config
|
|
"$ansible_playbook" -i "$inventory" -e "audita_test_config_path=$config_path" "$verify_config"
|
|
representative_repeat_log="$test_tmp/representative-config-repeat.log"
|
|
run_converge "$representative_repeat_log" -e "$representative_config"
|
|
require_clean_recap "$representative_repeat_log"
|
|
|
|
custom_go_binary="$test_tmp/go"
|
|
custom_go_invocations="$test_tmp/go-invocations.log"
|
|
printf '%s\n' \
|
|
'#!/usr/bin/env bash' \
|
|
'set -euo pipefail' \
|
|
"printf '%s\\n' \"\$*\" >> '$custom_go_invocations'" \
|
|
'exec /snap/bin/go "$@"' > "$custom_go_binary"
|
|
chmod 0755 "$custom_go_binary"
|
|
sudo rm -f -- "$binary_path"
|
|
recovery_log="$test_tmp/recovery.log"
|
|
run_converge "$recovery_log" \
|
|
-e '{"audita_manage_build_dependencies": false}' \
|
|
-e "audita_go_binary=$custom_go_binary"
|
|
grep -q . "$custom_go_invocations"
|
|
validate_config
|
|
recovery_repeat_log="$test_tmp/recovery-repeat.log"
|
|
run_converge "$recovery_repeat_log" \
|
|
-e '{"audita_manage_build_dependencies": false}' \
|
|
-e "audita_go_binary=$custom_go_binary"
|
|
require_clean_recap "$recovery_repeat_log"
|