Skip to content

Commit f5677b6

Browse files
committed
ci/cocalc-api: restart hub to enable jupyter api
1 parent 8dac10f commit f5677b6

File tree

3 files changed

+80
-7
lines changed

3 files changed

+80
-7
lines changed

.github/workflows/make-and-test.yml

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,23 +178,99 @@ jobs:
178178
- name: Create CI admin user and API key
179179
run: |
180180
cd src/packages/hub
181-
node dist/run/test-create-admin.js > ../../api_key.txt
181+
OUTPUT=$(node dist/run/test-create-admin.js)
182+
# Split output into account_id and API key (format: UUID;api-key)
183+
ACCOUNT_ID=$(echo "$OUTPUT" | cut -d';' -f1)
184+
API_KEY=$(echo "$OUTPUT" | cut -d';' -f2)
185+
186+
# Store in separate files
187+
echo "$ACCOUNT_ID" > ../../account_id.txt
188+
echo "$API_KEY" > ../../api_key.txt
189+
190+
# Validate account ID (UUID format)
191+
if ! echo "$ACCOUNT_ID" | grep -qE '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'; then
192+
echo "Error: Invalid account ID format: $ACCOUNT_ID"
193+
exit 1
194+
fi
195+
182196
# Validate API key was created
183197
if [ ! -s ../../api_key.txt ]; then
184198
echo "Error: API key file is empty or missing"
185199
exit 1
186200
fi
187-
API_KEY=$(cat ../../api_key.txt)
188201
if ! echo "$API_KEY" | grep -qE '^sk-[A-Za-z0-9]+$'; then
189202
echo "Error: Invalid API key format: $API_KEY"
190203
exit 1
191204
fi
205+
206+
echo "Account ID: $ACCOUNT_ID"
192207
echo "API key created successfully"
193208
env:
194209
PGDATABASE: smc
195210
PGUSER: smc
196211
PGHOST: localhost
197212

213+
- name: Restart CoCalc Hub
214+
run: |
215+
HUB_PID=$(cat src/packages/hub/hub.pid)
216+
echo "Stopping hub with PID $HUB_PID"
217+
kill $HUB_PID || true
218+
# Wait a bit for graceful shutdown
219+
sleep 5
220+
# Force kill if still running
221+
kill -9 $HUB_PID 2>/dev/null || true
222+
223+
# Read the admin account ID created in the previous step
224+
cd src/packages/hub
225+
ADMIN_ACCOUNT_ID=$(cat ../../account_id.txt)
226+
echo "Using admin account ID: $ADMIN_ACCOUNT_ID"
227+
228+
# Export env vars for the hub process
229+
export COCALC_SETTING_JUPYTER_API_ENABLED=yes
230+
export COCALC_SETTING_JUPYTER_ACCOUNT_ID=$ADMIN_ACCOUNT_ID
231+
export COCALC_SETTING_JUPYTER_PROJECT_POOL_SIZE=1
232+
233+
# Start hub with new configuration
234+
pnpm run hub-project-dev-nobuild > hub.log 2>&1 &
235+
HUB_PID=$!
236+
echo $HUB_PID > hub.pid
237+
echo "Hub restarted with PID $HUB_PID"
238+
239+
# Check if process is still running after a moment
240+
sleep 2
241+
if ! kill -0 $HUB_PID 2>/dev/null; then
242+
echo "Error: Hub process died immediately after restarting"
243+
echo "Hub log:"
244+
cat hub.log
245+
exit 1
246+
fi
247+
248+
# Wait for hub to be ready
249+
MAX_ATTEMPTS=30
250+
READY=false
251+
for i in $(seq 1 $MAX_ATTEMPTS); do
252+
if curl -sf --max-time 3 http://localhost:5000/healthcheck > /dev/null; then
253+
echo "Hub is ready after restart"
254+
READY=true
255+
break
256+
fi
257+
echo "Waiting for hub to be ready... ($i/$MAX_ATTEMPTS)"
258+
sleep 3
259+
done
260+
if [ "$READY" = "false" ]; then
261+
echo "Hub failed to become ready after restart"
262+
echo "Hub log:"
263+
cat hub.log
264+
exit 1
265+
fi
266+
env:
267+
PGDATABASE: smc
268+
PGUSER: smc
269+
PGHOST: localhost
270+
COCALC_MODE: single-user
271+
COCALC_TEST_MODE: yes
272+
DEBUG: 'cocalc:*,-cocalc:silly:*,hub:*,project:*'
273+
198274
- name: Install uv for cocalc-api tests
199275
run: curl -LsSf https://astral.sh/uv/install.sh | sh && echo "$HOME/.local/bin" >> $GITHUB_PATH
200276

src/packages/hub/run/test-create-admin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ async function main() {
5959
console.error(`API key created with id=${apiKey.id}: ${apiKey.secret}`);
6060
console.error(`Last 6 chars: ${apiKey.secret.slice(-6)}`);
6161

62-
// Output the key for CI
63-
process.stdout.write(apiKey.secret);
62+
// Output the account_id and API key for CI in format: UUID;api-key
63+
process.stdout.write(`${account_id};${apiKey.secret}`);
6464
}
6565

6666
main().catch((err) => {

src/python/cocalc-api/tests/test_jupyter.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def test_python3_kernel_available(self, hub, temporary_project):
6868
class TestJupyterExecuteViaHub:
6969
"""Tests for executing code via hub.jupyter.execute()."""
7070

71-
@pytest.mark.skip(reason="hub.jupyter.execute() has timeout issues - use project.system.jupyter_execute() instead")
7271
def test_execute_simple_sum(self, hub, temporary_project):
7372
"""Test executing a simple sum using the python3 kernel."""
7473
project_id = temporary_project["project_id"]
@@ -90,7 +89,6 @@ def test_execute_simple_sum(self, hub, temporary_project):
9089
assert "text/plain" in first_output["data"]
9190
assert first_output["data"]["text/plain"] == "4950"
9291

93-
@pytest.mark.skip(reason="hub.jupyter.execute() has timeout issues - use project.system.jupyter_execute() instead")
9492
def test_execute_with_history(self, hub, temporary_project):
9593
"""Test executing code with history context."""
9694
project_id = temporary_project["project_id"]
@@ -109,7 +107,6 @@ def test_execute_with_history(self, hub, temporary_project):
109107
assert "text/plain" in first_output["data"]
110108
assert first_output["data"]["text/plain"] == "5050"
111109

112-
@pytest.mark.skip(reason="hub.jupyter.execute() has timeout issues - use project.system.jupyter_execute() instead")
113110
def test_execute_print_statement(self, hub, temporary_project):
114111
"""Test executing code that prints output."""
115112
project_id = temporary_project["project_id"]

0 commit comments

Comments
 (0)