#!/bin/sh set -eu cd "$(dirname "$0")/.." if [ "${1:-}" = "--cleanup-failure" ] && [ -z "${PREPROCESS_SMOKE_CHILD:-}" ]; then child_project="thoth-preprocess-failure-$$" child_tmp=$(mktemp -d "${TMPDIR:-/tmp}/thoth-preprocess-failure.XXXXXX") set +e PREPROCESS_SMOKE_CHILD=1 PREPROCESS_SMOKE_INJECT_FAILURE=1 \ PREPROCESS_SMOKE_PROJECT="$child_project" PREPROCESS_SMOKE_TMP="$child_tmp" "$0" child_status=$? set -e test "$child_status" -eq 97 test ! -e "$child_tmp" test -z "$(docker ps -aq --filter "label=com.docker.compose.project=$child_project")" test -z "$(docker volume ls -q --filter "label=com.docker.compose.project=$child_project")" test -z "$(docker network ls -q --filter "label=com.docker.compose.project=$child_project")" echo "injected preprocessing failure preserved status and cleaned every owned resource." exit 0 fi tmp=${PREPROCESS_SMOKE_TMP:-$(mktemp -d "${TMPDIR:-/tmp}/thoth-preprocess.XXXXXX")} project=${PREPROCESS_SMOKE_PROJECT:-thoth-preprocess-$$} compose="" cleanup() { original_status=$? cleanup_failed=0 set +e if [ -n "$compose" ]; then $compose down --volumes >/dev/null test "$?" -eq 0 || cleanup_failed=1 fi test -z "$(docker ps -aq --filter "label=com.docker.compose.project=$project")" || cleanup_failed=1 test -z "$(docker volume ls -q --filter "label=com.docker.compose.project=$project")" || cleanup_failed=1 test -z "$(docker network ls -q --filter "label=com.docker.compose.project=$project")" || cleanup_failed=1 rm -rf "$tmp" test ! -e "$tmp" || cleanup_failed=1 if [ "$original_status" -ne 0 ]; then exit "$original_status" fi if [ "$cleanup_failed" -ne 0 ]; then exit 1 fi } trap cleanup EXIT trap 'exit 129' HUP trap 'exit 130' INT trap 'exit 143' TERM mkdir -p "$tmp/source/evidence" printf '%s\n' '# Evidence' 'generation one' >"$tmp/source/evidence/a.md" bundle="$tmp/thothii.secrets" { printf 'THT_VECTOR_BOOTSTRAP_PASSWORD=smoke-bootstrap-%s\n' "$project" printf 'THT_VECTOR_MIGRATOR_PASSWORD=smoke-migrator-%s\n' "$project" printf 'THT_VECTOR_READER_PASSWORD=smoke-reader-%s\n' "$project" printf 'THT_VECTOR_WRITER_PASSWORD=smoke-writer-%s\n' "$project" } >"$bundle" chmod 0600 "$bundle" export THT_SECRETS_FILE="$bundle" export THT_OLLAMA_URL=http://mock-embeddings:8081 printf '%s\n' '{}' >"$tmp/pi-auth.json" chmod 0600 "$tmp/pi-auth.json" printf '%s\n' \ 'THT_WORKSPACE_GIT_REMOTE=https://git.example.invalid/platform/thoth-workspaces.git' \ "PI_AUTH_FILE=$tmp/pi-auth.json" \ "THT_SECRETS_FILE=$bundle" \ 'THT_OLLAMA_URL=http://mock-embeddings:8081' >"$tmp/operator.env" cat >"$tmp/smoke.yaml" <>"$tmp/source/evidence/a.md" third=$($compose run --rm preprocess-evidence) after_third=$(generation_count) dwh=$($compose run --rm preprocess-dwh) python3 - "$first" "$second" "$third" "$before" "$after_first" "$after_second" "$after_third" <<'PY' import json, sys a, b, c = map(json.loads, sys.argv[1:4]) before, first_count, second_count, third_count = map(int, sys.argv[4:]) assert len(a["changed"]) == 1 and not a["unchanged"] assert len(b["unchanged"]) == 1 and not b["changed"] assert len(c["changed"]) == 1 and c["generation"] != a["generation"] assert a["published"] and not b["published"] and c["published"] assert first_count == before + 1 assert second_count == first_count assert third_count == second_count + 1 PY python3 - "$dwh" <<'PY' import json, sys assert json.loads(sys.argv[1])["status"] == "succeeded" PY active=$($compose run --rm --no-deps --entrypoint sh preprocess-evidence -c \ 'cat /data/workspaces/preprocess-evidence/corpus/ACTIVE') python3 - "$third" "$active" <<'PY' import json, sys assert json.loads(sys.argv[1])["generation"] == sys.argv[2].strip() PY echo "real Compose preprocessing unchanged rerun, mutation, DWH job, and ACTIVE publish passed."