78 lines
4.5 KiB
Bash
Executable File
78 lines
4.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Seed a running local stack (e2e/stack.sh) through the dashboard's own HTTP
|
|
# API, so the seed exercises real validation. Safe to run again: each step
|
|
# skips what already exists.
|
|
set -euo pipefail
|
|
|
|
base=${ARCHIE_E2E_API:-http://localhost:8484}
|
|
here=$(cd "$(dirname "$0")" && pwd)
|
|
cookie=$(mktemp)
|
|
trap 'rm -f "$cookie"' EXIT
|
|
H=(-b "$cookie" -c "$cookie" -H 'Content-Type: application/json' -H 'X-Archie-CSRF: 1' -H "Origin: $base")
|
|
|
|
get() { curl -fsS -b "$cookie" "$base$1"; }
|
|
post() { curl -fsS -X POST "$base$1" "${H[@]}" -d "$2"; }
|
|
# jq-free JSON reads: py EXPR, with the parsed body as d.
|
|
py() { python3 -c "import sys, json; d = json.load(sys.stdin); print($1)"; }
|
|
|
|
# This account belongs only to the isolated local test stack.
|
|
email=${ARCHIE_E2E_EMAIL:-operator@example.test}
|
|
password=${ARCHIE_E2E_PASSWORD:-archie-local-e2e-password}
|
|
account=$(python3 -c 'import json,sys; print(json.dumps(dict(email=sys.argv[1], password=sys.argv[2], display_name="E2E operator", organisation_name="E2E", workspace_name="Local test", public_url=sys.argv[3])))' "$email" "$password" "${ARCHIE_E2E_URL:-http://localhost:5173}")
|
|
if [ "$(get /api/auth/status | py 'd["setup_required"]')" = "True" ]; then
|
|
post /api/auth/setup "$account" >/dev/null
|
|
else
|
|
if ! post /api/auth/login "$account" >/dev/null; then
|
|
echo "Test account sign-in failed. Set ARCHIE_E2E_EMAIL and ARCHIE_E2E_PASSWORD to this test stack's account credentials." >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Repository policy. archied applies it live; the pause lets the watch publish it.
|
|
if ! get /api/control-plane/resources/repository-policies | grep -q '"widgets"'; then
|
|
version=$(get /api/control-plane/resources/repository-policies | py 'd["resource"]["version"]')
|
|
post /api/control-plane/resources/repository-policies/commands/replace \
|
|
"{\"value\":[{\"owner\":\"acme\",\"name\":\"widgets\",\"base\":\"main\"}],\"expected_version\":$version}" >/dev/null
|
|
sleep 5
|
|
fi
|
|
|
|
# Work requests. Without Docker they park within a minute, which fills
|
|
# Needs you, Quality gates and the task pages.
|
|
tasks=$(get /api/tasks)
|
|
for t in "Fix flaky login test" "Add retry to webhook sender" "Document the gate" "Speed up the CI cache" "Recovery probe"; do
|
|
grep -qF "\"$t\"" <<<"$tasks" && continue
|
|
post /api/work-requests "{\"repository\":\"acme/widgets\",\"workflow\":\"triage\",\"title\":\"$t\",\"instructions\":\"Do it.\"}" >/dev/null
|
|
done
|
|
|
|
# An unsigned capture source with one delivery, an event type, a mapping and
|
|
# a binding left pending approval.
|
|
src=e2e-hook
|
|
if ! get /api/sources | grep -q "\"$src\""; then
|
|
post /api/sources "{\"path\":\"$src\"}" >/dev/null
|
|
post "/api/sources/$src/signing" '{"signed":false}' >/dev/null
|
|
post "/api/sources/$src/approve-unsigned" '{}' >/dev/null
|
|
bash "$here/../tools/webhook-send.sh" --url "$base" --source "$src" --kind github-issue --quiet >/dev/null
|
|
fi
|
|
et=$(get /api/event-types | py '"".join(t["id"] for t in (d.get("event_types", []) if isinstance(d, dict) else d) if t["name"] == "issue-opened")')
|
|
if [ -z "$et" ]; then
|
|
et=$(post /api/event-types "{\"source\":\"$src\",\"name\":\"issue-opened\",\"rule\":{\"headers\":[],\"payload\":[{\"path\":\"action\",\"op\":\"equals\",\"value\":\"opened\"}]},\"example\":{\"headers\":{},\"body\":\"{\\\"action\\\":\\\"opened\\\",\\\"issue\\\":{\\\"title\\\":\\\"x\\\"}}\"}}" | py 'd["id"]')
|
|
fi
|
|
if ! get /api/bindings | grep -q '"e2e-binding"'; then
|
|
mapping=$(post /api/mappings "{\"name\":\"e2e-issue\",\"source_hint\":\"$src\",\"event_type_id\":\"$et\",\"fields\":[{\"name\":\"title\",\"path\":\"issue.title\",\"type\":\"string\",\"required\":true}]}" | py 'd["id"]')
|
|
post /api/bindings "{\"name\":\"e2e-binding\",\"matcher\":{\"source\":\"$src\"},\"mapping_id\":\"$mapping\",\"workflow\":\"feasibility\",\"owner\":\"acme\",\"repo\":\"widgets\"}" >/dev/null
|
|
fi
|
|
|
|
# Two more orgs: the operator owns Beta, so the org selector offers it; Gamma
|
|
# belongs to an identity the operator is not a member of, so selecting it is refused.
|
|
orgs=$(get /api/orgs)
|
|
if ! grep -q '"org-beta"' <<<"$orgs"; then
|
|
operator=$(get /api/identities | py '"".join(i["id"] for i in d["identities"] if i["display_name"] == "E2E operator")')
|
|
post /api/orgs "{\"id\":\"org-beta\",\"name\":\"Beta\",\"owner_identity\":\"$operator\"}" >/dev/null
|
|
fi
|
|
if ! grep -q '"org-gamma"' <<<"$orgs"; then
|
|
outsider=$(post /api/identities '{"display_name":"E2E outsider","kind":"user"}' | py 'd["id"]')
|
|
post /api/orgs "{\"id\":\"org-gamma\",\"name\":\"Gamma\",\"owner_identity\":\"$outsider\"}" >/dev/null
|
|
fi
|
|
|
|
echo "seeded: $(get /api/tasks | py 'len(d.get("tasks", d) if isinstance(d, dict) else d)') tasks"
|