openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
59c89d2815453fceb8b8a3f86e99f283326a3c70

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

scripts/mock

57lines · modecode

1#!/usr/bin/env bash
2
3set -e
4
5cd "$(dirname "$0")/.."
6
7if [[ -n "$1" && "$1" != '--'* ]]; then
8 URL="$1"
9 shift
10else
11 URL="$(grep 'openapi_spec_url' .stats.yml | cut -d' ' -f2)"
12fi
13
14# Check if the URL is empty
15if [ -z "$URL" ]; then
16 echo "Error: No OpenAPI spec path/url provided or found in .stats.yml"
17 exit 1
18fi
19
20echo "==> Starting mock server with URL ${URL}"
21
22if [ ! -x "node_modules/.bin/steady" ]; then
23 echo "Error: missing pinned steady CLI. Run 'corepack pnpm install --frozen-lockfile' first."
24 exit 1
25fi
26
27# Run steady mock on the given spec
28if [ "$1" == "--daemon" ]; then
29 # Pre-install the package so the download doesn't eat into the startup timeout
30 corepack pnpm exec steady --version
31
32 corepack pnpm exec steady --host 127.0.0.1 -p 4010 --validator-query-array-format=brackets --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log &
33
34 # Wait for server to come online via health endpoint (max 30s)
35 echo -n "Waiting for server"
36 attempts=0
37 while ! curl --silent --fail "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1; do
38 if ! kill -0 $! 2>/dev/null; then
39 echo
40 cat .stdy.log
41 exit 1
42 fi
43 attempts=$((attempts + 1))
44 if [ "$attempts" -ge 300 ]; then
45 echo
46 echo "Timed out waiting for Steady server to start"
47 cat .stdy.log
48 exit 1
49 fi
50 echo -n "."
51 sleep 0.1
52 done
53
54 echo
55else
56 corepack pnpm exec steady --host 127.0.0.1 -p 4010 --validator-query-array-format=brackets --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL"
57fi
58