-
Notifications
You must be signed in to change notification settings - Fork 0
improvements #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improvements #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,35 +28,52 @@ for arg in "$@"; do | |
| fi | ||
| done | ||
|
|
||
| # Check if authenticated with GitHub Copilot (skip if --skip-auth or --stop) | ||
| # Check if authenticated (skip if --skip-auth or --stop) | ||
| if [ "$SKIP_AUTH" = "false" ] && [ "$1" != "--stop" ]; then | ||
| AUTH_FILE="$HOME/.local/share/opencode/auth.json" | ||
| if [ ! -f "$AUTH_FILE" ] || ! grep -q "github-copilot" "$AUTH_FILE" 2>/dev/null; then | ||
| if [ ! -f "$AUTH_FILE" ] || [ ! -s "$AUTH_FILE" ]; then | ||
| echo "" | ||
| echo "GitHub Copilot authentication required." | ||
| echo "OpenCode authentication required." | ||
| echo "A browser/device code flow will be initiated..." | ||
| echo "" | ||
| opencode auth login github-copilot | ||
| opencode auth login | ||
|
|
||
| # Verify auth succeeded | ||
| if [ ! -f "$AUTH_FILE" ] || ! grep -q "github-copilot" "$AUTH_FILE" 2>/dev/null; then | ||
| echo "GitHub Copilot authentication failed or was cancelled." | ||
| if [ ! -f "$AUTH_FILE" ] || [ ! -s "$AUTH_FILE" ]; then | ||
| echo "Authentication failed or was cancelled." | ||
| exit 1 | ||
| fi | ||
| echo "GitHub Copilot authentication successful." | ||
| echo "Authentication successful." | ||
| echo "" | ||
| fi | ||
| fi | ||
|
|
||
| # Determine data directory: use .opencode-server in the repo root if inside a git | ||
| # repo, otherwise fall back to ~/.config | ||
| if git rev-parse --show-toplevel &>/dev/null; then | ||
| GIT_ROOT="$(git rev-parse --show-toplevel)" | ||
| DATA_DIR="$GIT_ROOT/.opencode-server" | ||
| mkdir -p "$DATA_DIR" | ||
|
|
||
|
Comment on lines
+53
to
+57
|
||
| # Locally ignore the data directory so it's never committed | ||
| EXCLUDE_FILE="$GIT_ROOT/.git/info/exclude" | ||
| mkdir -p "$(dirname "$EXCLUDE_FILE")" | ||
| if ! grep -qxF '.opencode-server' "$EXCLUDE_FILE" 2>/dev/null; then | ||
| echo '.opencode-server' >> "$EXCLUDE_FILE" | ||
| fi | ||
|
Comment on lines
+58
to
+63
|
||
| else | ||
| DATA_DIR="$HOME/.config" | ||
| fi | ||
|
|
||
| # Configuration | ||
| PASSWORD_FILE="$HOME/.config/opencode-server-local" | ||
| PID_FILE="$HOME/.config/opencode-server.pid" | ||
| STOP_FLAG="$HOME/.config/opencode-server.stop" | ||
| CERT_DIR="$HOME/.config/opencode-certs" | ||
| PASSWORD_FILE="$DATA_DIR/opencode-server-local" | ||
| PID_FILE="$DATA_DIR/opencode-server.pid" | ||
| STOP_FLAG="$DATA_DIR/opencode-server.stop" | ||
| CERT_DIR="$DATA_DIR/opencode-certs" | ||
| CERT_FILE="$CERT_DIR/cert.pem" | ||
| KEY_FILE="$CERT_DIR/key.pem" | ||
| CADDYFILE="$HOME/.config/opencode-caddyfile" | ||
| LOG_FILE="$HOME/.config/opencode-server.log" | ||
| CADDYFILE="$DATA_DIR/opencode-caddyfile" | ||
| LOG_FILE="$DATA_DIR/opencode-server.log" | ||
| MONITOR_INTERVAL=${OPENCODE_MONITOR_INTERVAL:-5} | ||
|
|
||
| OPENCODE_INTERNAL_PORT="4097" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,6 +263,152 @@ else | |
| echo "$PROCS" | ||
| fi | ||
|
|
||
| # ============================================================================== | ||
| # GIT REPO DATA DIRECTORY TESTS | ||
| # ============================================================================== | ||
| echo "" | ||
| echo -e "${YELLOW}Setting up git repo tests...${NC}" | ||
|
|
||
| # Stop any running server and clean up state from previous tests | ||
| docker exec "$CONTAINER_NAME" bash /workspace/opencode-server.sh --stop >/dev/null 2>&1 | ||
| sleep 2 | ||
|
|
||
| # Create a git repo inside the container | ||
| docker exec "$CONTAINER_NAME" bash -c \ | ||
| 'mkdir -p /tmp/test-repo && cd /tmp/test-repo && git init && git config user.email "test@test.com" && git config user.name "Test"' >/dev/null 2>&1 | ||
|
|
||
| # Copy the script into the repo (since /workspace is read-only) | ||
| docker exec "$CONTAINER_NAME" bash -c 'cp /workspace/opencode-server.sh /tmp/test-repo/' >/dev/null 2>&1 | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "=== Test 15: Data is stored in .opencode-server/ inside a git repo ===" | ||
| OUTPUT=$(docker exec "$CONTAINER_NAME" bash -c \ | ||
| "cd /tmp/test-repo && OPENCODE_PORT=$TEST_PORT bash opencode-server.sh --skip-auth 2>&1") | ||
| if echo "$OUTPUT" | grep -q "OpenCode server started"; then | ||
| # Check that data dir was created inside the repo | ||
| if docker exec "$CONTAINER_NAME" bash -c 'test -d /tmp/test-repo/.opencode-server'; then | ||
| pass "Data directory .opencode-server/ created inside git repo" | ||
| else | ||
| fail "Data directory .opencode-server/ not found inside git repo" | ||
| fi | ||
| else | ||
| fail "Script did not start server from git repo" | ||
| echo "$OUTPUT" | ||
| fi | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "=== Test 16: .git/info/exclude contains .opencode-server ===" | ||
| EXCLUDE_CONTENT=$(docker exec "$CONTAINER_NAME" bash -c 'cat /tmp/test-repo/.git/info/exclude' 2>/dev/null) | ||
| if echo "$EXCLUDE_CONTENT" | grep -qxF '.opencode-server'; then | ||
| pass ".opencode-server is in .git/info/exclude" | ||
| else | ||
| fail ".opencode-server not found in .git/info/exclude" | ||
| echo "Exclude file contents: $EXCLUDE_CONTENT" | ||
| fi | ||
|
Comment on lines
+300
to
+307
|
||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "=== Test 17: Password file is inside .opencode-server/ ===" | ||
| GIT_PASSWORD=$(docker exec "$CONTAINER_NAME" bash -c 'cat /tmp/test-repo/.opencode-server/opencode-server-local' 2>/dev/null) | ||
| if [ -n "$GIT_PASSWORD" ]; then | ||
| pass "Password file found in .opencode-server/: ${GIT_PASSWORD:0:8}..." | ||
| else | ||
| fail "Password file not found in .opencode-server/" | ||
| fi | ||
|
Comment on lines
+310
to
+316
|
||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "=== Test 18: PID file is inside .opencode-server/ ===" | ||
| if docker exec "$CONTAINER_NAME" bash -c 'test -f /tmp/test-repo/.opencode-server/opencode-server.pid'; then | ||
| pass "PID file found in .opencode-server/" | ||
| else | ||
| fail "PID file not found in .opencode-server/" | ||
| fi | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "=== Test 19: Certs are inside .opencode-server/ ===" | ||
| if docker exec "$CONTAINER_NAME" bash -c 'test -f /tmp/test-repo/.opencode-server/opencode-certs/cert.pem'; then | ||
| pass "Certificate found in .opencode-server/opencode-certs/" | ||
| else | ||
| fail "Certificate not found in .opencode-server/opencode-certs/" | ||
| fi | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "=== Test 20: Log file is inside .opencode-server/ ===" | ||
| if docker exec "$CONTAINER_NAME" bash -c 'test -f /tmp/test-repo/.opencode-server/opencode-server.log'; then | ||
| pass "Log file found in .opencode-server/" | ||
| else | ||
| fail "Log file not found in .opencode-server/" | ||
| fi | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "=== Test 21: Server responds on HTTPS port (git repo mode) ===" | ||
| HTTP_CODE=$(docker exec "$CONTAINER_NAME" bash -c \ | ||
| "curl -k -s -o /dev/null -w '%{http_code}' https://127.0.0.1:$TEST_PORT" 2>&1) | ||
| if [ "$HTTP_CODE" = "401" ]; then | ||
| pass "Server responds with 401 on port $TEST_PORT (git repo mode)" | ||
| else | ||
| fail "Expected HTTP 401, got: $HTTP_CODE (git repo mode)" | ||
| fi | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "=== Test 22: Stop works in git repo mode ===" | ||
| docker exec "$CONTAINER_NAME" bash -c \ | ||
| "cd /tmp/test-repo && bash opencode-server.sh --stop" >/dev/null 2>&1 | ||
| sleep 2 | ||
| LISTENING=$(docker exec "$CONTAINER_NAME" bash -c "ss -tlnp | grep $TEST_PORT || echo 'not listening'" 2>&1) | ||
| if [[ "$LISTENING" == *"not listening"* ]]; then | ||
| pass "Server stopped in git repo mode" | ||
| else | ||
| fail "Server still listening after stop in git repo mode" | ||
| echo "$LISTENING" | ||
| fi | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "=== Test 23: Password persists after restart in git repo mode ===" | ||
| docker exec "$CONTAINER_NAME" bash -c \ | ||
| "cd /tmp/test-repo && OPENCODE_PORT=$TEST_PORT bash opencode-server.sh --skip-auth" >/dev/null 2>&1 | ||
| GIT_PASSWORD2=$(docker exec "$CONTAINER_NAME" bash -c 'cat /tmp/test-repo/.opencode-server/opencode-server-local' 2>/dev/null) | ||
| if [ "$GIT_PASSWORD" = "$GIT_PASSWORD2" ]; then | ||
| pass "Password persisted across restart in git repo mode" | ||
| else | ||
| fail "Password changed after restart in git repo mode" | ||
| fi | ||
|
|
||
| # Stop server before next test | ||
| docker exec "$CONTAINER_NAME" bash -c \ | ||
| "cd /tmp/test-repo && bash opencode-server.sh --stop" >/dev/null 2>&1 | ||
| sleep 2 | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "=== Test 24: .git/info/exclude entry is not duplicated on repeated runs ===" | ||
| EXCLUDE_COUNT=$(docker exec "$CONTAINER_NAME" bash -c \ | ||
| 'grep -cx ".opencode-server" /tmp/test-repo/.git/info/exclude' 2>/dev/null) | ||
| if [ "$EXCLUDE_COUNT" = "1" ]; then | ||
| pass ".opencode-server appears exactly once in .git/info/exclude" | ||
| else | ||
| fail ".opencode-server appears $EXCLUDE_COUNT times in .git/info/exclude (expected 1)" | ||
| fi | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "=== Test 25: Data stored in ~/.config/ when not in a git repo ===" | ||
| # Run from /tmp which is not a git repo | ||
| OUTPUT=$(docker exec "$CONTAINER_NAME" bash -c \ | ||
| "cd /tmp && OPENCODE_PORT=$TEST_PORT bash /workspace/opencode-server.sh --skip-auth 2>&1") | ||
| if echo "$OUTPUT" | grep -q "OpenCode server started"; then | ||
| if docker exec "$CONTAINER_NAME" bash -c 'test -f ~/.config/opencode-server.pid'; then | ||
| pass "Data stored in ~/.config/ when not in a git repo" | ||
| else | ||
| fail "PID file not found in ~/.config/ when not in a git repo" | ||
| fi | ||
| else | ||
| fail "Script did not start server from non-git directory" | ||
| echo "$OUTPUT" | ||
| fi | ||
|
|
||
| # Stop the non-git-repo server | ||
| docker exec "$CONTAINER_NAME" bash -c \ | ||
| "cd /tmp && bash /workspace/opencode-server.sh --stop" >/dev/null 2>&1 | ||
| sleep 2 | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| echo "" | ||
| echo "========================================" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The auth gate is skipped only when
--stopis the first argument ($1). If--stopis provided after other flags, the script may incorrectly prompt for auth and the stop handler won’t run. Consider parsing--stopthe same way as--skip-auth(scan all args) so stop works regardless of argument order.