Skip to content

Commit ea661f8

Browse files
authored
fix(app): patch openapi-effect randomUUID fallback (#444)
* fix(app): patch openapi-effect randomUUID fallback * fix(api): copy bun patches into controller deps stage
1 parent 5400aa6 commit ea661f8

5 files changed

Lines changed: 88 additions & 2 deletions

File tree

bun.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,8 @@
8080
"url": "https://github.com/ProverCoderAI/docker-git/issues"
8181
},
8282
"homepage": "https://github.com/ProverCoderAI/docker-git#readme",
83-
"license": "MIT"
83+
"license": "MIT",
84+
"patchedDependencies": {
85+
"@prover-coder-ai/openapi-effect@1.0.27": "patches/@prover-coder-ai%2Fopenapi-effect@1.0.27.patch"
86+
}
8487
}

packages/api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ RUN set -eu; \
7676
FROM controller-base AS workspace-deps
7777

7878
COPY package.json bun.lock bunfig.toml tsconfig.base.json tsconfig.json ./
79+
COPY patches ./patches
7980
RUN mkdir -p packages/api packages/app packages/auth-oauth packages/container packages/docker-git-session-sync packages/lib packages/openapi packages/terminal
8081
COPY packages/api/package.json ./packages/api/package.json
8182
COPY packages/app/package.json ./packages/app/package.json
@@ -108,7 +109,6 @@ RUN set -eu; \
108109

109110
FROM workspace-deps AS workspace-static
110111

111-
COPY patches ./patches
112112
COPY scripts ./scripts
113113
COPY packages/container ./packages/container
114114
COPY packages/auth-oauth ./packages/auth-oauth

packages/app/tests/docker-git/openapi-effect-client.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createClient } from "@prover-coder-ai/docker-git-openapi"
33
import type { ApiFailure } from "@prover-coder-ai/docker-git-openapi"
44
import { Effect } from "effect"
55
import * as fc from "fast-check"
6+
import { afterEach, vi } from "vitest"
67

78
import type { JsonValue } from "../../src/shared/json-schema.js"
89
import { renderDockerGitOpenApiFailure } from "../../src/web/api-http.js"
@@ -95,6 +96,11 @@ const assertOpenApiClientProperty = <PropertyArgs>(property: fc.IAsyncProperty<P
9596
try: () => fc.assert(property, { numRuns: 25 })
9697
})
9798

99+
afterEach(() => {
100+
vi.restoreAllMocks()
101+
vi.unstubAllGlobals()
102+
})
103+
98104
describe("docker-git OpenAPI Effect client", () => {
99105
it.effect("executes typed GET requests directly through openapi-effect", () =>
100106
Effect.gen(function*(_) {
@@ -223,4 +229,70 @@ describe("docker-git OpenAPI Effect client", () => {
223229
expect(requests[0]?.method).toBe("POST")
224230
expect(new URL(requests[0]?.url ?? "").pathname).toBe("/projects/down-all")
225231
}))
232+
233+
it.effect("falls back to getRandomValues when randomUUID is unavailable", () =>
234+
Effect.gen(function*(_) {
235+
const requests: Array<CapturedRequest> = []
236+
const capturedIds: Array<string> = []
237+
vi.stubGlobal("crypto", {
238+
getRandomValues: (values: Uint8Array): Uint8Array => {
239+
values.set([0x10, 0x32, 0x54, 0x76, 0x98])
240+
return values
241+
}
242+
})
243+
244+
const api = createClient({
245+
baseUrl: "https://docker-git.example.test",
246+
fetch: createMockFetch(
247+
requests,
248+
createJsonResponse(200, {
249+
cwd: "/workspace",
250+
ok: true,
251+
projectsRoot: "/workspace/projects",
252+
revision: null
253+
})
254+
)
255+
})
256+
api.use({
257+
onRequest: ({ id }) => {
258+
capturedIds.push(id)
259+
}
260+
})
261+
262+
const success = yield* _(api.GET("/health"))
263+
264+
expect(success.status).toBe(200)
265+
expect(capturedIds).toEqual(["103254769"])
266+
expect(requests).toHaveLength(1)
267+
}))
268+
269+
it.effect("falls back to a clock-based request id when Web Crypto is missing", () =>
270+
Effect.gen(function*(_) {
271+
const capturedIds: Array<string> = []
272+
vi.stubGlobal("crypto", undefined)
273+
vi.spyOn(Date, "now").mockReturnValue(0x1234567)
274+
275+
const api = createClient({
276+
baseUrl: "https://docker-git.example.test",
277+
fetch: createMockFetch(
278+
[],
279+
createJsonResponse(200, {
280+
cwd: "/workspace",
281+
ok: true,
282+
projectsRoot: "/workspace/projects",
283+
revision: null
284+
})
285+
)
286+
})
287+
api.use({
288+
onRequest: ({ id }) => {
289+
capturedIds.push(id)
290+
}
291+
})
292+
293+
const success = yield* _(api.GET("/health"))
294+
295+
expect(success.status).toBe(200)
296+
expect(capturedIds).toEqual(["123456700"])
297+
}))
226298
})

patches/@prover-coder-ai%2Fopenapi-effect@1.0.27.patch

Lines changed: 8 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)