138 lines
5.8 KiB
Bash
Executable File
138 lines
5.8 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"
|
|
prepare_import="$repository_root/tests/prepare-import.yml"
|
|
ansible_playbook="$workspace_venv/bin/ansible-playbook"
|
|
binary_path=/usr/local/bin/notarius
|
|
config_path=/usr/local/etc/notarius/config.yml
|
|
imported_pipeline_path=/usr/local/etc/notarius/test-pipelines.yml
|
|
|
|
cleanup() {
|
|
exit_status=$?
|
|
trap - EXIT
|
|
"$ansible_playbook" -i "$inventory" "$converge" >/dev/null 2>&1 || true
|
|
sudo rm -f -- "$imported_pipeline_path"
|
|
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" "$@" "$converge" | tee "$output_file"
|
|
}
|
|
|
|
validate_config() {
|
|
"$binary_path" config validate --config "$config_path"
|
|
}
|
|
|
|
require_retry_zero() {
|
|
"$workspace_venv/bin/python" - "$1" <<'PY'
|
|
import sys
|
|
|
|
import yaml
|
|
|
|
with open(sys.argv[1], encoding="utf-8") as stream:
|
|
config = yaml.safe_load(stream)
|
|
assert config["promptkit"]["transient_retries"] == 0
|
|
PY
|
|
}
|
|
|
|
cd "$repository_root"
|
|
"$workspace_venv/bin/ansible-galaxy" collection install \
|
|
-r collections/requirements.yml \
|
|
-p "$ANSIBLE_COLLECTIONS_PATH"
|
|
"$ansible_playbook" -i "$inventory" --syntax-check "$converge"
|
|
"$workspace_venv/bin/ansible-lint" "$converge" "$prepare_import"
|
|
|
|
baseline_log="$test_tmp/baseline.log"
|
|
run_converge "$baseline_log" -e '{"notarius_promptkit_transient_retries": null}'
|
|
"$binary_path" --version
|
|
validate_config
|
|
"$workspace_venv/bin/python" - "$config_path" <<'PY'
|
|
import sys
|
|
|
|
import yaml
|
|
|
|
with open(sys.argv[1], encoding="utf-8") as stream:
|
|
config = yaml.safe_load(stream)
|
|
assert "transient_retries" not in config.get("promptkit", {})
|
|
PY
|
|
baseline_repeat_log="$test_tmp/baseline-repeat.log"
|
|
run_converge "$baseline_repeat_log" -e '{"notarius_promptkit_transient_retries": null}'
|
|
require_clean_recap "$baseline_repeat_log"
|
|
|
|
retry_config='{"notarius_promptkit_transient_retries":0}'
|
|
retry_log="$test_tmp/retry.log"
|
|
run_converge "$retry_log" -e "$retry_config"
|
|
validate_config
|
|
require_retry_zero "$config_path"
|
|
retry_effective_config="$test_tmp/retry-effective-config.yml"
|
|
"$binary_path" config effective --config "$config_path" > "$retry_effective_config"
|
|
require_retry_zero "$retry_effective_config"
|
|
retry_repeat_log="$test_tmp/retry-repeat.log"
|
|
run_converge "$retry_repeat_log" -e "$retry_config"
|
|
require_clean_recap "$retry_repeat_log"
|
|
|
|
selected_release_log="$test_tmp/selected-release.log"
|
|
run_converge "$selected_release_log" -e notarius_version=v0.7.0
|
|
[[ "$("$binary_path" --version)" == 'notarius v0.7.0' ]]
|
|
|
|
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 notarius_version=v0.7.0 \
|
|
-e '{"notarius_manage_build_dependencies": false}' \
|
|
-e "notarius_go_binary=$custom_go_binary"
|
|
grep -q . "$custom_go_invocations"
|
|
[[ "$("$binary_path" --version)" == 'notarius v0.7.0' ]]
|
|
recovery_repeat_log="$test_tmp/recovery-repeat.log"
|
|
run_converge "$recovery_repeat_log" \
|
|
-e notarius_version=v0.7.0 \
|
|
-e '{"notarius_manage_build_dependencies": false}' \
|
|
-e "notarius_go_binary=$custom_go_binary"
|
|
require_clean_recap "$recovery_repeat_log"
|
|
|
|
pipeline_group_one='{"dnd-session":{"llm_profile":"dnd-extraction","input":{"module":"seriatim"},"artifacts":{"spells":{"extract":{"module":"dnd/spells"},"normalize":{"module":"dnd/spells"}}}}}'
|
|
pipeline_group_two='{"dnd-archive":{"llm_profile":"dnd-extraction","input":{"module":"seriatim"},"artifacts":{"spells":{"extract":{"module":"dnd/spells"},"normalize":{"module":"dnd/spells"}}}}}'
|
|
representative_config="{\"notarius_pipeline_group_one\":$pipeline_group_one,\"notarius_pipeline_group_two\":$pipeline_group_two,\"notarius_configkit_imports\":[{\"path\":\"test-pipelines.yml\"}],\"notarius_promptkit_transient_retries\":0,\"notarius_promptkit_local_backend_endpoint\":\"http://localhost:8000/v1\",\"notarius_promptkit_local_backend_concurrency_limit\":0,\"notarius_cache_checkpoints_enabled\":false,\"notarius_cache_chunk_plans_mode\":\"bypass\",\"notarius_cache_chunk_plans_directory\":\"/tmp/notarius-cache/chunk-plans\",\"notarius_cache_checkpoints_directory\":\"/tmp/notarius-cache/checkpoints\",\"notarius_output_directory\":\"/tmp/notarius-output\",\"notarius_promptkit_profile_dir\":null,\"notarius_promptkit_profile_file\":null,\"notarius_debug_directory\":null}"
|
|
"$ansible_playbook" -i "$inventory" "$prepare_import" -e "$representative_config"
|
|
representative_log="$test_tmp/representative.log"
|
|
run_converge "$representative_log" -e "$representative_config"
|
|
"$binary_path" config validate --config "$config_path" --pipeline dnd-session
|
|
effective_config="$test_tmp/effective-config.yml"
|
|
"$binary_path" config effective --config "$config_path" > "$effective_config"
|
|
grep -Fq 'dnd-session:' "$effective_config"
|
|
grep -Fq 'dnd-archive:' "$effective_config"
|
|
grep -Fq 'mode: bypass' "$effective_config"
|
|
grep -Fq 'enabled: false' "$effective_config"
|
|
grep -Fq 'directory: /tmp/notarius-cache/chunk-plans' "$effective_config"
|
|
require_retry_zero "$config_path"
|
|
require_retry_zero "$effective_config"
|
|
representative_repeat_log="$test_tmp/representative-repeat.log"
|
|
run_converge "$representative_repeat_log" -e "$representative_config"
|
|
require_clean_recap "$representative_repeat_log"
|