From 6fb3bdd9337946bc0970c4b8f9b9f854dfcaa0fc Mon Sep 17 00:00:00 2001 From: Ahmedhossamdev Date: Fri, 13 Mar 2026 21:14:17 -0700 Subject: [PATCH 1/4] Add scripts to check and update OpenAPI specification --- scripts/check-openapi.sh | 21 +++++++++++++++++++++ scripts/update-openapi.sh | 17 +++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 scripts/check-openapi.sh create mode 100755 scripts/update-openapi.sh diff --git a/scripts/check-openapi.sh b/scripts/check-openapi.sh new file mode 100755 index 00000000..cdfd5c35 --- /dev/null +++ b/scripts/check-openapi.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +UPSTREAM_URL="https://raw.githubusercontent.com/OneBusAway/sdk-config/main/openapi.yml" +LOCAL="testdata/openapi.yml" +TMP="$(mktemp /tmp/openapi.XXXXXX.yml)" + +cleanup() { rm -f "$TMP"; } +trap cleanup EXIT + +echo "Checking upstream OpenAPI spec for changes..." +curl -sSfL "$UPSTREAM_URL" -o "$TMP" + +# Skip the 2-line header when comparing +if tail -n +3 "$LOCAL" | cmp -s "$TMP" -; then + echo "openapi.yml is up to date with upstream" +else + echo "WARNING: upstream openapi.yml has changed. Run 'make update-openapi' to update." + echo "If you find issues in the upstream spec, open an issue at: https://github.com/OneBusAway/sdk-config/issues" + exit 1 +fi diff --git a/scripts/update-openapi.sh b/scripts/update-openapi.sh new file mode 100755 index 00000000..47c69898 --- /dev/null +++ b/scripts/update-openapi.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +UPSTREAM_URL="https://raw.githubusercontent.com/OneBusAway/sdk-config/main/openapi.yml" +DEST="testdata/openapi.yml" +TMP="$(mktemp /tmp/openapi.XXXXXX.yml)" + +cleanup() { rm -f "$TMP"; } +trap cleanup EXIT + +echo "Fetching upstream OpenAPI spec from sdk-config..." +curl -sSfL "$UPSTREAM_URL" -o "$TMP" + +printf '# Source: https://github.com/OneBusAway/sdk-config/blob/main/openapi.yml\n# Fetched: %s\n' "$(date +%Y-%m-%d)" > "$DEST" +cat "$TMP" >> "$DEST" + +echo "Updated $DEST" From 9ebedc24817fe0aab02c222f754ab57a278a8a6c Mon Sep 17 00:00:00 2001 From: Ahmedhossamdev Date: Fri, 13 Mar 2026 21:14:23 -0700 Subject: [PATCH 2/4] Refactor OpenAPI update and check scripts to use dedicated bash scripts --- Makefile | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 7a69390d..19c4b1d1 100644 --- a/Makefile +++ b/Makefile @@ -99,26 +99,12 @@ models: # Fetch the latest upstream OpenAPI spec and overwrite testdata/openapi.yml. update-openapi: - @echo "Fetching upstream OpenAPI spec from sdk-config..." - curl -sSfL "https://raw.githubusercontent.com/OneBusAway/sdk-config/main/openapi.yml" \ - -o /tmp/openapi.latest.yml - @printf '# Source: https://github.com/OneBusAway/sdk-config/blob/main/openapi.yml\n# Fetched: %s\n' "$$(date +%Y-%m-%d)" > testdata/openapi.yml - cat /tmp/openapi.latest.yml >> testdata/openapi.yml - @echo "Updated testdata/openapi.yml" + bash scripts/update-openapi.sh # Check whether testdata/openapi.yml matches the live upstream (skipping header). # Exits 1 if out of date (useful for CI checks). check-openapi: - @echo "Checking upstream OpenAPI spec for changes..." - @curl -sSfL "https://raw.githubusercontent.com/OneBusAway/sdk-config/main/openapi.yml" \ - -o /tmp/openapi.check.yml - @if tail -n +3 testdata/openapi.yml | cmp -s /tmp/openapi.check.yml -; then \ - echo "openapi.yml is up to date with upstream"; \ - else \ - echo "WARNING: upstream openapi.yml has changed. Run 'make update-openapi' to update."; \ - echo "If you find issues in the upstream spec, please open an issue at: https://github.com/OneBusAway/sdk-config/issues"; \ - exit 1; \ - fi + bash scripts/check-openapi.sh watch: air From 699636504f815173bf376a42ea340149fcf77d68 Mon Sep 17 00:00:00 2001 From: Ahmedhossamdev Date: Fri, 13 Mar 2026 21:14:35 -0700 Subject: [PATCH 3/4] Update OpenAPI check step in CI to use bash script --- .github/workflows/go.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 78ec4a5f..a97e81be 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -55,8 +55,7 @@ jobs: run: go mod verify - name: Check OpenAPI spec is up to date with upstream - if: matrix.os == 'ubuntu-latest' - run: make check-openapi + run: bash scripts/check-openapi.sh shell: bash - name: Run tests (fast mode) From a07bbcdae933ef3fe411d003fe767c1a22704cb2 Mon Sep 17 00:00:00 2001 From: Ahmedhossamdev Date: Fri, 13 Mar 2026 21:27:54 -0700 Subject: [PATCH 4/4] refactor: context timeout in TestBlockHandlerContextCancellation to use a past deadline for immediate DeadlineExceeded response --- internal/restapi/block_handler_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/restapi/block_handler_test.go b/internal/restapi/block_handler_test.go index aab45b17..8f7f53a5 100644 --- a/internal/restapi/block_handler_test.go +++ b/internal/restapi/block_handler_test.go @@ -514,18 +514,17 @@ func TestBlockHandlerContextCancellation(t *testing.T) { req, err := http.NewRequest("GET", "/api/where/block/25_1.json?key=TEST", nil) require.NoError(t, err) - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) + // Use a deadline in the past — context.Err() is DeadlineExceeded immediately, + // no timer resolution dependency (avoids Windows ~15ms minimum sleep issue). + ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(-1*time.Second)) defer cancel() req = req.WithContext(ctx) - time.Sleep(time.Microsecond) - w := httptest.NewRecorder() mux := http.NewServeMux() api.SetRoutes(mux) mux.ServeHTTP(w, req) - // With a 1ns timeout and 1µs sleep the context is always DeadlineExceeded assert.Equal(t, http.StatusGatewayTimeout, w.Code, "Expected 504 Gateway Timeout for DeadlineExceeded context, got: %d", w.Code) })