|
| 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