#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # Use an isolated cursor file so smoke runs do not mutate normal sync state. export CURSOR_FILE="${ROOT_DIR}/.cursor.smoke.$$" # shellcheck source=/dev/null source "${ROOT_DIR}/src/app_v2.sh" require_jq() { if ! command -v jq >/dev/null 2>&1; then echo "smoke_v2.sh: jq is required" >&2 exit 2 fi } fail() { echo "smoke_v2.sh: FAIL: $1" >&2 exit 1 } step() { echo "== $1 ==" } cleanup() { rm -f "${CURSOR_FILE}" >/dev/null 2>&1 || true } trap cleanup EXIT require_jq app_init run_id="$(date +%s)" idempotency_key="smoke-seed-${run_id}" doc_name="smokedoc${run_id}" topic_name="smoketopic${run_id}" goal_pred="ms.within_domain" step "startup" startup_out="$(app_startup_checks)" || fail "startup checks failed" printf '%s' "${startup_out}" | grep -q '"ok":true' || fail "readyz did not report ok=true" step "ingest" payload="$(cat </dev/null || fail "tombstone call failed" post_retrieve="$(app_retrieve_with_fallback "${doc_name}" "${goal_pred}")" || fail "post-tombstone retrieve failed" post_edges_count="$(printf '%s' "${post_retrieve}" | jq '.edges | length')" [[ "${post_edges_count}" == "0" ]] || fail "tombstoned edge still visible in default retrieval" amduat_api_call GET "/v2/graph/subgraph?roots[]=${doc_name}&max_depth=2&dir=outgoing&limit_nodes=200&limit_edges=400&include_tombstoned=true&max_result_bytes=1048576" || fail "include_tombstoned subgraph failed" visible_out="${AMDUAT_LAST_BODY}" visible_has_edge="$(printf '%s' "${visible_out}" | jq --arg edge_ref "${edge_ref}" '[.edges[] | select(.edge_ref == $edge_ref)] | length')" [[ "${visible_has_edge}" != "0" ]] || fail "tombstoned edge not visible with include_tombstoned=true" echo "smoke_v2.sh: PASS"