Skip to content

Commit d66d8f2

Browse files
committed
fix(web): tolerate legacy auth snapshots
1 parent 12664b7 commit d66d8f2

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

packages/app/src/web/api-auth-schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const AuthProviderSnapshotFields = {
2828
claudeAuthPath: Schema.String,
2929
geminiAuthEntries: Schema.Number,
3030
geminiAuthPath: Schema.String,
31-
grokAuthEntries: Schema.Number,
32-
grokAuthPath: Schema.String,
31+
grokAuthEntries: Schema.optionalWith(Schema.Number, { default: () => 0 }),
32+
grokAuthPath: Schema.optionalWith(Schema.String, { default: () => "" }),
3333
githubTokenEntries: Schema.Number,
3434
gitTokenEntries: Schema.Number
3535
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as ParseResult from "@effect/schema/ParseResult"
2+
import * as Schema from "@effect/schema/Schema"
3+
import { describe, expect, it } from "@effect/vitest"
4+
import { Either } from "effect"
5+
6+
import { AuthSnapshotResponseSchema } from "../../src/web/api-auth-schema.js"
7+
8+
type LegacyAuthSnapshotResponse = {
9+
readonly snapshot: {
10+
readonly claudeAuthEntries: number
11+
readonly claudeAuthPath: string
12+
readonly geminiAuthEntries: number
13+
readonly geminiAuthPath: string
14+
readonly gitTokenEntries: number
15+
readonly gitUserEntries: number
16+
readonly githubTokenEntries: number
17+
readonly globalEnvPath: string
18+
readonly totalEntries: number
19+
}
20+
}
21+
22+
const decodeAuthSnapshotResponse = (payload: LegacyAuthSnapshotResponse) =>
23+
ParseResult.decodeUnknownEither(Schema.parseJson(AuthSnapshotResponseSchema))(JSON.stringify(payload))
24+
25+
describe("web auth api schema", () => {
26+
it("accepts auth snapshots from controllers without Grok fields", () => {
27+
const decoded = decodeAuthSnapshotResponse({
28+
snapshot: {
29+
claudeAuthEntries: 3,
30+
claudeAuthPath: "/home/dev/.docker-git/.orch/auth/claude",
31+
geminiAuthEntries: 2,
32+
geminiAuthPath: "/home/dev/.docker-git/.orch/auth/gemini",
33+
gitTokenEntries: 0,
34+
gitUserEntries: 0,
35+
githubTokenEntries: 1,
36+
globalEnvPath: "/home/dev/.docker-git/.orch/env/global.env",
37+
totalEntries: 1
38+
}
39+
})
40+
41+
expect(Either.isRight(decoded)).toBe(true)
42+
if (Either.isRight(decoded)) {
43+
expect(decoded.right.snapshot.grokAuthEntries).toBe(0)
44+
expect(decoded.right.snapshot.grokAuthPath).toBe("")
45+
}
46+
})
47+
})

0 commit comments

Comments
 (0)