Skip to content

Commit 4090399

Browse files
committed
cocalc-api: fix the CI test
1 parent 5faae38 commit 4090399

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

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

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,13 @@ jobs:
128128
name: "test-results-node-${{ matrix.node-version }}-pg-${{ matrix.pg-version }}"
129129
path: 'src/packages/*/junit.xml'
130130

131-
- name: Create CI admin user and API key
132-
run: |
133-
cd src/packages/hub
134-
node run/test-create-admin.js > ../../api_key.txt
135-
# Validate API key was created
136-
if [ ! -s ../../api_key.txt ]; then
137-
echo "Error: API key file is empty or missing"
138-
exit 1
139-
fi
140-
API_KEY=$(cat ../../api_key.txt)
141-
if ! echo "$API_KEY" | grep -qE '^sk-[A-Za-z0-9]+$'; then
142-
echo "Error: Invalid API key format: $API_KEY"
143-
exit 1
144-
fi
145-
echo "API key created successfully"
146-
env:
147-
PGDATABASE: smc
148-
PGUSER: smc
149-
PGHOST: localhost
150-
151131
- name: Start CoCalc Hub
152132
run: |
133+
# Create conat password for hub internal authentication
134+
mkdir -p src/data/secrets
135+
echo "test-conat-password-$(date +%s)" > src/data/secrets/conat-password
136+
chmod 600 src/data/secrets/conat-password
137+
153138
cd src/packages/hub
154139
pnpm run hub-project-dev-nobuild > hub.log 2>&1 &
155140
HUB_PID=$!
@@ -168,13 +153,15 @@ jobs:
168153
PGUSER: smc
169154
PGHOST: localhost
170155
COCALC_MODE: single-user
156+
COCALC_TEST_MODE: yes
157+
DEBUG: 'cocalc:*,-cocalc:silly:*,hub:*,project:*'
171158

172159
- name: Wait for hub readiness
173160
run: |
174161
MAX_ATTEMPTS=30
175162
READY=false
176163
for i in $(seq 1 $MAX_ATTEMPTS); do
177-
if curl -f --max-time 3 http://localhost:5000/healthcheck; then
164+
if curl -sf --max-time 3 http://localhost:5000/healthcheck > /dev/null; then
178165
echo "Hub is ready"
179166
READY=true
180167
break
@@ -189,6 +176,26 @@ jobs:
189176
exit 1
190177
fi
191178
179+
- name: Create CI admin user and API key
180+
run: |
181+
cd src/packages/hub
182+
node dist/run/test-create-admin.js > ../../api_key.txt
183+
# Validate API key was created
184+
if [ ! -s ../../api_key.txt ]; then
185+
echo "Error: API key file is empty or missing"
186+
exit 1
187+
fi
188+
API_KEY=$(cat ../../api_key.txt)
189+
if ! echo "$API_KEY" | grep -qE '^sk-[A-Za-z0-9]+$'; then
190+
echo "Error: Invalid API key format: $API_KEY"
191+
exit 1
192+
fi
193+
echo "API key created successfully"
194+
env:
195+
PGDATABASE: smc
196+
PGUSER: smc
197+
PGHOST: localhost
198+
192199
- name: Install uv for cocalc-api tests
193200
run: curl -LsSf https://astral.sh/uv/install.sh | sh && echo "$HOME/.local/bin" >> $GITHUB_PATH
194201

src/packages/hub/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
"cocalc-hub-maintenance-expired": "./run/maintenance-expired.js",
9797
"cocalc-hub-maintenance-syncstrings": "./run/maintenance-syncstrings.js",
9898
"cocalc-hub-maintenance-blobs": "./run/maintenance-blobs.js",
99-
"cocalc-hub-stripe-sync": "./run/stripe-sync.js",
100-
"cocalc-hub-test-create-admin": "./run/test-create-admin.js"
99+
"cocalc-hub-stripe-sync": "./run/stripe-sync.js"
101100
}
102101
}

src/packages/hub/run/test-create-admin.js renamed to src/packages/hub/run/test-create-admin.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import { v4 as uuidv4 } from "uuid";
9+
910
import createAccount from "@cocalc/server/accounts/create-account";
1011
import manageApiKeys from "@cocalc/server/api/manage";
1112
import getPool from "@cocalc/database/pool";
@@ -17,7 +18,7 @@ async function main() {
1718
const firstName = "CI";
1819
const lastName = "Admin";
1920

20-
console.log(`Creating admin account ${account_id}...`);
21+
console.error(`Creating admin account ${account_id}...`);
2122

2223
// Create the account
2324
await createAccount({
@@ -38,7 +39,7 @@ async function main() {
3839
account_id,
3940
]);
4041

41-
console.log("Creating API key...");
42+
console.error("Creating API key...");
4243

4344
// Create API key
4445
const keys = await manageApiKeys({
@@ -52,7 +53,11 @@ async function main() {
5253
}
5354

5455
const apiKey = keys[0];
55-
console.log(`API key created: ${apiKey.secret}`);
56+
if (!apiKey.secret) {
57+
throw new Error("API key secret is missing");
58+
}
59+
console.error(`API key created with id=${apiKey.id}: ${apiKey.secret}`);
60+
console.error(`Last 6 chars: ${apiKey.secret.slice(-6)}`);
5661

5762
// Output the key for CI
5863
process.stdout.write(apiKey.secret);
@@ -61,4 +66,4 @@ async function main() {
6166
main().catch((err) => {
6267
console.error("Error:", err);
6368
process.exit(1);
64-
});
69+
});

0 commit comments

Comments
 (0)