diff --git a/scripts/cluster/cross-node-file-e2e.mjs b/scripts/cluster/cross-node-file-e2e.mjs index 8a2b775..b6c4de5 100755 --- a/scripts/cluster/cross-node-file-e2e.mjs +++ b/scripts/cluster/cross-node-file-e2e.mjs @@ -55,7 +55,9 @@ const baseURL = process.env.AI_GATEWAY_E2E_BASE_URL || 'http://10.77.0.1:18089' const account = Buffer.from(process.env.E2E_ACCOUNT_B64 || '', 'base64').toString('utf8') const password = Buffer.from(process.env.E2E_PASSWORD_B64 || '', 'base64').toString('utf8') const model = process.env.AI_GATEWAY_E2E_IMAGE_MODEL || 'openai:gpt-image-1' +const imageSize = process.env.AI_GATEWAY_E2E_IMAGE_SIZE || '2048x2048' assert(account && password, 'E2E login credentials are unavailable') +assert(/^\d+x\d+$/.test(imageSize), 'E2E image size is invalid') async function request(path, { method = 'GET', token, body, form } = {}) { const headers = { Host: 'ai.51easyai.com' } @@ -95,6 +97,13 @@ const login = await request('/api/v1/auth/login', { const jwt = login.payload.accessToken assert(typeof jwt === 'string' && jwt.length > 20, 'login did not return an access token') +const existingKeys = await request('/api/v1/api-keys', { token: jwt }) +for (const item of existingKeys.payload.items || []) { + if (typeof item?.id === 'string' && item?.name?.startsWith('cluster-cross-node-')) { + await request(`/api/v1/api-keys/${item.id}`, { method: 'DELETE', token: jwt }) + } +} + const keyName = `cluster-cross-node-${Date.now()}` const keyResult = await request('/api/v1/api-keys', { method: 'POST', @@ -102,8 +111,9 @@ const keyResult = await request('/api/v1/api-keys', { body: { name: keyName }, }) const apiKey = keyResult.payload.secret -const apiKeyId = keyResult.payload.id || keyResult.payload.item?.id +const apiKeyId = keyResult.payload.apiKey?.id assert(typeof apiKey === 'string' && apiKey.startsWith('sk-gw-'), 'API key creation failed') +assert(typeof apiKeyId === 'string' && apiKeyId.length > 0, 'API key ID is unavailable') let result try { @@ -112,7 +122,7 @@ try { const form = new FormData() form.append('model', model) form.append('prompt', `Cross-node HA acceptance ${randomUUID()}: add a thin white border`) - form.append('size', '1024x1024') + form.append('size', imageSize) form.append('image', new Blob([fixture], { type: 'image/png' }), 'cluster-e2e.png') const accepted = await request('/api/v1/images/edits', { method: 'POST', diff --git a/scripts/cluster/run-cross-node-file-e2e.sh b/scripts/cluster/run-cross-node-file-e2e.sh index bfd1fed..e6591da 100755 --- a/scripts/cluster/run-cross-node-file-e2e.sh +++ b/scripts/cluster/run-cross-node-file-e2e.sh @@ -38,12 +38,16 @@ REMOTE credentials_file=$(mktemp "$cluster_root/.local-secrets/cluster/e2e.XXXXXX") trap 'rm -f -- "$credentials_file"; restore_workers' EXIT HUP INT TERM chmod 0600 "$credentials_file" -printf 'E2E_ACCOUNT_B64=%s\n' "$(printf '%s' "$AI_GATEWAY_ONLINE_ACCOUNT" | base64 | tr -d '\n')" \ - >"$credentials_file" -printf 'E2E_PASSWORD_B64=%s\n' "$(printf '%s' "$AI_GATEWAY_ONLINE_PASSWORD" | base64 | tr -d '\n')" \ - >>"$credentials_file" -printf 'AI_GATEWAY_E2E_IMAGE_MODEL=%s\n' "${AI_GATEWAY_E2E_IMAGE_MODEL:-openai:gpt-image-1}" \ - >>"$credentials_file" +{ + printf 'E2E_ACCOUNT_B64=%s\n' \ + "$(printf '%s' "$AI_GATEWAY_ONLINE_ACCOUNT" | base64 | tr -d '\n')" + printf 'E2E_PASSWORD_B64=%s\n' \ + "$(printf '%s' "$AI_GATEWAY_ONLINE_PASSWORD" | base64 | tr -d '\n')" + printf 'AI_GATEWAY_E2E_IMAGE_MODEL=%s\n' \ + "${AI_GATEWAY_E2E_IMAGE_MODEL:-openai:gpt-image-1}" + printf 'AI_GATEWAY_E2E_IMAGE_SIZE=%s\n' \ + "${AI_GATEWAY_E2E_IMAGE_SIZE:-2048x2048}" +} >"$credentials_file" cluster_scp "$credentials_file" "$CLUSTER_NINGBO_HOST:/root/easyai-cross-node-e2e.env" cluster_scp "$script_dir/cross-node-file-e2e.mjs" \ "$CLUSTER_NINGBO_HOST:/root/easyai-cross-node-file-e2e.mjs"