mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 10:37:35 +00:00
* feat(accounts): link standalone GLM Coding Plans Adapt the reviewed GLM accounts contribution to current main, retain Antigravity behavior, guard late credential results, expose storage protection, and redact quota errors. Co-authored-by: Luchong <lu740528977@gmail.com> * fix(accounts): retain GLM credential results during quota refresh * fix(accounts): make GLM credential editing desktop-only * fix(accounts): mirror the host GLM site in paired clients * fix(accounts): report unknown GLM host details and split web settings tests Apply the independently reviewed Accounts correction from697284a without the v2 adapter commits. Preserve the saved-key store and serialized write behavior. * fix(zcode): ship required GLM account translation entries * chore: record GLM reconciliation hook validation * chore: validate installed GLM commit hooks * test: complete GLM account fixtures and web API inventory --------- Co-authored-by: Luchong <lu740528977@gmail.com>
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { registerZcodePlanCredentialsHandlers } from './zcode-plan-credentials'
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
handle: vi.fn(),
|
|
hasKey: vi.fn(() => false),
|
|
protection: vi.fn<() => 'sealed' | 'plaintext' | null>(() => null),
|
|
hasCli: vi.fn(() => false),
|
|
save: vi.fn(),
|
|
clear: vi.fn()
|
|
}))
|
|
vi.mock('electron', () => ({ ipcMain: { handle: mocks.handle } }))
|
|
vi.mock('../zcode/zcode-plan-api-key-store', () => ({
|
|
hasZcodePlanApiKey: mocks.hasKey,
|
|
getZcodePlanApiKeyProtection: mocks.protection,
|
|
saveZcodePlanApiKey: mocks.save,
|
|
clearZcodePlanApiKey: mocks.clear
|
|
}))
|
|
vi.mock('../rate-limits/zcode-usage-fetcher', () => ({ hasZcodeCliPlanCredentials: mocks.hasCli }))
|
|
|
|
function handler(channel: string) {
|
|
const registration = mocks.handle.mock.calls.find(([name]) => name === channel)
|
|
if (!registration) {
|
|
throw new Error('Handler missing')
|
|
}
|
|
return registration[1]
|
|
}
|
|
|
|
describe('GLM credential IPC', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mocks.hasKey.mockReturnValue(false)
|
|
mocks.hasCli.mockReturnValue(false)
|
|
mocks.protection.mockReturnValue(null)
|
|
registerZcodePlanCredentialsHandlers(null)
|
|
})
|
|
|
|
it('returns only presence and protection without exposing the key', () => {
|
|
mocks.hasKey.mockReturnValue(true)
|
|
mocks.hasCli.mockReturnValue(true)
|
|
mocks.protection.mockReturnValue('sealed')
|
|
expect(handler('zcodePlanCredentials:getStatus')()).toEqual({
|
|
apiKeyConfigured: true,
|
|
zcodeCliConfigured: true,
|
|
apiKeyProtection: 'sealed'
|
|
})
|
|
})
|
|
|
|
it('validates an untyped IPC key before persistence', () => {
|
|
expect(() => handler('zcodePlanCredentials:saveApiKey')(null, 42)).toThrow('must be a string')
|
|
expect(mocks.save).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('saves and removes keys while returning status only', () => {
|
|
mocks.save.mockImplementationOnce(() => mocks.hasKey.mockReturnValue(true))
|
|
mocks.clear.mockImplementationOnce(() => mocks.hasKey.mockReturnValue(false))
|
|
expect(handler('zcodePlanCredentials:saveApiKey')(null, 'synthetic-key')).toEqual({
|
|
apiKeyConfigured: true,
|
|
zcodeCliConfigured: false,
|
|
apiKeyProtection: null
|
|
})
|
|
expect(handler('zcodePlanCredentials:clearApiKey')()).toEqual({
|
|
apiKeyConfigured: false,
|
|
zcodeCliConfigured: false,
|
|
apiKeyProtection: null
|
|
})
|
|
})
|
|
})
|