-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlive-e2e.sh
More file actions
executable file
·215 lines (184 loc) · 6.1 KB
/
Copy pathlive-e2e.sh
File metadata and controls
executable file
·215 lines (184 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
ENV_FILE="${ROOT_DIR}/.env"
SEED_PATH=""
SEED_CONTENT=""
WAIT_SECONDS=90
SKIP_BUILD=0
FOLLOW_LOGS=0
usage() {
cat <<USAGE
Usage: scripts/live-e2e.sh [options]
Options:
--env-file <path> Env file for docker compose (default: .env)
--seed-path <path> Remote file path to seed (default: <remote-root>/AgentGuide.md)
--seed-content <text> Seed markdown content (default: timestamped heading)
--wait-seconds <n> Max wait for health/materialization (default: 90)
--skip-build Start compose without --build
--follow-logs Tail relayfile and mountsync logs at the end
-h, --help Show this help
USAGE
}
while [[ $# -gt 0 ]]; do
case "$1" in
--env-file)
ENV_FILE="$2"
shift 2
;;
--seed-path)
SEED_PATH="$2"
shift 2
;;
--seed-content)
SEED_CONTENT="$2"
shift 2
;;
--wait-seconds)
WAIT_SECONDS="$2"
shift 2
;;
--skip-build)
SKIP_BUILD=1
shift
;;
--follow-logs)
FOLLOW_LOGS=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "unknown option: $1" >&2
usage
exit 1
;;
esac
done
if [[ "${ENV_FILE}" != /* ]]; then
ENV_FILE="${ROOT_DIR}/${ENV_FILE}"
fi
if ! command -v docker >/dev/null 2>&1; then
echo "docker is required" >&2
exit 1
fi
if ! docker compose version >/dev/null 2>&1; then
echo "docker compose is required" >&2
exit 1
fi
if [[ ! -f "${ENV_FILE}" ]]; then
if [[ -f "${ROOT_DIR}/compose.env.example" ]]; then
cp "${ROOT_DIR}/compose.env.example" "${ENV_FILE}"
echo "created ${ENV_FILE} from compose.env.example"
else
echo "missing env file: ${ENV_FILE}" >&2
exit 1
fi
fi
# shellcheck disable=SC1090
set -a; source "${ENV_FILE}"; set +a
RELAYFILE_PORT="${RELAYFILE_PORT:-8080}"
RELAYFILE_WORKSPACE="${RELAYFILE_WORKSPACE:-ws_live}"
RELAYFILE_REMOTE_PATH="${RELAYFILE_REMOTE_PATH:-/}"
RELAYFILE_JWT_SECRET="${RELAYFILE_JWT_SECRET:-dev-secret}"
RELAYFILE_INTERNAL_HMAC_SECRET="${RELAYFILE_INTERNAL_HMAC_SECRET:-dev-internal-secret}"
if [[ -z "${SEED_PATH}" ]]; then
remote_root_trimmed="${RELAYFILE_REMOTE_PATH%/}"
if [[ -z "${remote_root_trimmed}" ]]; then
remote_root_trimmed="/"
fi
if [[ "${remote_root_trimmed}" == "/" ]]; then
SEED_PATH="/AgentGuide.md"
else
SEED_PATH="${remote_root_trimmed}/AgentGuide.md"
fi
fi
if [[ -z "${SEED_CONTENT}" ]]; then
SEED_CONTENT="# agent walkthrough $(date -u +%Y-%m-%dT%H:%M:%SZ)"
fi
if [[ -z "${RELAYFILE_TOKEN:-}" ]]; then
RELAYFILE_TOKEN="$(${ROOT_DIR}/scripts/generate-dev-token.sh "${RELAYFILE_WORKSPACE}")"
fi
mkdir -p "${ROOT_DIR}/.livefs"
compose() {
env RELAYFILE_TOKEN="${RELAYFILE_TOKEN}" docker compose --env-file "${ENV_FILE}" "$@"
}
echo "[info] Provider writeback is handled externally via the generic webhook API and writeback queue."
echo "[info] External services should poll /v1/workspaces/{ws}/writeback/pending and acknowledge via /v1/workspaces/{ws}/writeback/{id}/ack"
echo "[step] starting compose stack"
if [[ "${SKIP_BUILD}" -eq 1 ]]; then
compose up -d
else
compose up --build -d
fi
base_url="http://127.0.0.1:${RELAYFILE_PORT}"
echo "[step] waiting for relayfile health at ${base_url}/health"
health_deadline=$((SECONDS + WAIT_SECONDS))
until curl -fsS "${base_url}/health" >/dev/null 2>&1; do
if (( SECONDS >= health_deadline )); then
echo "timed out waiting for relayfile health" >&2
compose logs --tail=200 relayfile mountsync || true
exit 1
fi
sleep 2
done
echo "[step] starting agent-workspace profile"
compose --profile agent up -d agent-workspace
echo "[step] sending signed internal webhook envelope"
RELAYFILE_BASE_URL="${base_url}" \
RELAYFILE_WORKSPACE="${RELAYFILE_WORKSPACE}" \
RELAYFILE_INTERNAL_HMAC_SECRET="${RELAYFILE_INTERNAL_HMAC_SECRET}" \
"${ROOT_DIR}/scripts/send-internal-envelope.sh" "${SEED_PATH}" "${SEED_CONTENT}" >/dev/null
target_rel="${SEED_PATH}"
remote_prefix="${RELAYFILE_REMOTE_PATH%/}"
if [[ -n "${remote_prefix}" && "${remote_prefix}" != "/" && "${target_rel}" == "${remote_prefix}"* ]]; then
target_rel="${target_rel#"${remote_prefix}"}"
fi
target_rel="${target_rel#/}"
if [[ -z "${target_rel}" ]]; then
target_rel="AgentGuide.md"
fi
local_target="${ROOT_DIR}/.livefs/${target_rel}"
echo "[step] waiting for mount materialization: ${local_target}"
file_deadline=$((SECONDS + WAIT_SECONDS))
until [[ -f "${local_target}" ]]; do
if (( SECONDS >= file_deadline )); then
echo "timed out waiting for mounted file" >&2
compose logs --tail=200 relayfile mountsync || true
exit 1
fi
sleep 1
done
echo "[step] agent container traverses mounted workspace"
compose exec -T agent-workspace sh -lc 'echo "[agent] files under /workspace:"; find /workspace -maxdepth 4 -type f | sort'
echo "[step] agent container reads seeded file"
compose exec -T agent-workspace sh -lc "echo '[agent] preview /workspace/${target_rel}:'; sed -n '1,80p' '/workspace/${target_rel}'"
echo "[step] agent container edits file"
agent_line="# agent edit $(date -u +%Y-%m-%dT%H:%M:%SZ)"
compose exec -T agent-workspace sh -lc "printf '%s\n' '${agent_line}' >> '/workspace/${target_rel}'"
sleep 3
ops_corr="corr_live_e2e_ops_$(date +%s)"
admin_corr="corr_live_e2e_admin_$(date +%s)"
echo "[step] latest ops feed"
curl -fsS \
-H "Authorization: Bearer ${RELAYFILE_TOKEN}" \
-H "X-Correlation-Id: ${ops_corr}" \
"${base_url}/v1/workspaces/${RELAYFILE_WORKSPACE}/ops?limit=20"
echo
echo "[step] backend status"
curl -fsS \
-H "Authorization: Bearer ${RELAYFILE_TOKEN}" \
-H "X-Correlation-Id: ${admin_corr}" \
"${base_url}/v1/admin/backends"
echo
echo "[done] live e2e flow complete"
echo "- mounted workspace: ${ROOT_DIR}/.livefs"
echo "- agent shell: env RELAYFILE_TOKEN='${RELAYFILE_TOKEN}' docker compose --env-file '${ENV_FILE}' exec agent-workspace sh"
echo "- stop stack: docker compose --env-file '${ENV_FILE}' down"
if [[ "${FOLLOW_LOGS}" -eq 1 ]]; then
echo "[step] following relayfile + mountsync logs"
compose logs -f relayfile mountsync
fi