Skip to content

Commit 3ea0993

Browse files
committed
test(e2e): assert auto-ssh after clone
1 parent e354f19 commit 3ea0993

2 files changed

Lines changed: 37 additions & 90 deletions

File tree

scripts/e2e/ci.sh

Lines changed: 0 additions & 82 deletions
This file was deleted.

scripts/e2e/opencode-autoconnect.sh

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ SSH_PORT="$(( (RANDOM % 1000) + 20000 ))"
2323
export DOCKER_GIT_PROJECTS_ROOT="$ROOT"
2424
export DOCKER_GIT_STATE_AUTO_SYNC=0
2525

26+
REPO_URL="https://github.com/octocat/Hello-World/issues/1"
27+
TARGET_DIR="/home/dev/octocat/hello-world/issue-1"
28+
29+
SSH_LOG_PATH="$ROOT/ssh.log"
30+
SSH_WRAPPER_BIN="$ROOT/.e2e-bin"
31+
32+
fail() {
33+
echo "e2e/opencode-autoconnect: $*" >&2
34+
exit 1
35+
}
36+
2637
on_error() {
2738
local line="$1"
2839
echo "e2e/opencode-autoconnect: failed at line $line" >&2
@@ -66,6 +77,20 @@ trap cleanup EXIT
6677
mkdir -p "$ROOT/.orch/auth/codex" "$ROOT/.orch/env"
6778
: > "$ROOT/authorized_keys"
6879

80+
# Wrap `ssh` so CI doesn't hang in interactive mode; we only assert the invocation.
81+
mkdir -p "$SSH_WRAPPER_BIN"
82+
cat > "$SSH_WRAPPER_BIN/ssh" <<'EOF'
83+
#!/usr/bin/env bash
84+
set -euo pipefail
85+
86+
: "${SSH_LOG_PATH:?SSH_LOG_PATH is required}"
87+
printf "ssh %s\n" "$*" >> "$SSH_LOG_PATH"
88+
exit 0
89+
EOF
90+
chmod +x "$SSH_WRAPPER_BIN/ssh"
91+
export PATH="$SSH_WRAPPER_BIN:$PATH"
92+
export SSH_LOG_PATH
93+
6994
# Seed a fake (but structurally valid) Codex auth.json so the entrypoint can
7095
# auto-connect OpenCode without manual /connect.
7196
node <<'NODE' > "$ROOT/.orch/auth/codex/auth.json"
@@ -101,14 +126,18 @@ OPENCODE_SHARE_AUTH=1
101126
OPENCODE_AUTO_CONNECT=1
102127
EOF_ENV
103128

104-
pnpm run docker-git clone https://github.com/octocat/Hello-World \
105-
--force \
106-
--repo-ref master \
107-
--ssh-port "$SSH_PORT" \
108-
--out-dir "$OUT_DIR_REL" \
109-
--container-name "$CONTAINER_NAME" \
110-
--service-name "$SERVICE_NAME" \
111-
--volume-name "$VOLUME_NAME"
129+
# Auto-open SSH happens only in an interactive TTY; wrap with `script` to allocate a pseudo-TTY.
130+
command -v script >/dev/null 2>&1 || fail "missing 'script' command (util-linux)"
131+
rm -f "$SSH_LOG_PATH"
132+
script -q -e -c "pnpm run docker-git clone \"$REPO_URL\" --force --ssh-port \"$SSH_PORT\" --out-dir \"$OUT_DIR_REL\" --container-name \"$CONTAINER_NAME\" --service-name \"$SERVICE_NAME\" --volume-name \"$VOLUME_NAME\"" /dev/null
133+
134+
[[ -s "$SSH_LOG_PATH" ]] || fail "expected ssh to be invoked; log is empty: $SSH_LOG_PATH"
135+
grep -q -- "dev@localhost" "$SSH_LOG_PATH" || fail "expected ssh args to include dev@localhost"
136+
grep -q -- "-p $SSH_PORT" "$SSH_LOG_PATH" || fail "expected ssh args to include -p $SSH_PORT"
137+
138+
docker exec -u dev "$CONTAINER_NAME" bash -lc "test -d '$TARGET_DIR/.git'" || fail "expected repo to be cloned at: $TARGET_DIR"
139+
branch="$(docker exec -u dev "$CONTAINER_NAME" bash -lc "cd '$TARGET_DIR' && git rev-parse --abbrev-ref HEAD")"
140+
[[ "$branch" == "issue-1" ]] || fail "expected HEAD branch issue-1, got: $branch"
112141

113142
# Basic sanity checks.
114143
docker ps --format '{{.Names}}' | grep -qx "$CONTAINER_NAME"

0 commit comments

Comments
 (0)