Files
orca/src/shared/codex-reset-credit-attempt-ledger.test.ts
T
kazu-42andBrennan Benson 4a71a0ecb2 feat(mobile): add safe Codex rate-limit resets (#9394)
* feat(mobile): add safe Codex rate-limit resets

* fix(mobile): address reset credit review feedback

* review: purge removed-account reset attempts, shared capability constant, rebase test mocks

* review: preserve host compatibility and reset durability

* fix(mobile): recover reset capability after cutover

* fix(mobile): validate runtime capability payloads

* fix(mobile): enforce capability payload contract

* fix(mobile): route mock terminals to selected worktree

* test(mobile): pin malformed probe retry behavior

---------

Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
2026-07-24 14:42:04 -07:00

126 lines
3.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
EMPTY_CODEX_RESET_CREDIT_ATTEMPT_LEDGER,
parseCodexResetCreditAttemptLedger
} from './codex-reset-credit-attempt-ledger'
const hostScope = {
target: { runtime: 'host' as const, wslDistro: null },
accountId: 'account-host',
accountRevision: 42,
offerRevision: 'v1:offer-host'
}
describe('Codex reset credit attempt ledger', () => {
it('strictly accepts pending and settled durable attempts', () => {
expect(
parseCodexResetCreditAttemptLedger({
version: 1,
attempts: [
{
idempotencyKey: '11111111-1111-4111-8111-111111111111',
expectedScope: hostScope,
state: 'providerPending'
},
{
idempotencyKey: '22222222-2222-4222-8222-222222222222',
expectedScope: {
...hostScope,
offerRevision: 'v1:offer-settled'
},
state: 'settled',
outcome: 'alreadyRedeemed'
}
]
})
).toMatchObject({ version: 1, attempts: [{ state: 'providerPending' }, { state: 'settled' }] })
expect(parseCodexResetCreditAttemptLedger(undefined)).toEqual(
EMPTY_CODEX_RESET_CREDIT_ATTEMPT_LEDGER
)
})
it.each([
{
name: 'unknown field',
value: { version: 1, attempts: [], extra: true }
},
{
name: 'duplicate idempotency key',
value: {
version: 1,
attempts: [
{
idempotencyKey: '11111111-1111-4111-8111-111111111111',
expectedScope: hostScope,
state: 'providerPending'
},
{
idempotencyKey: '11111111-1111-4111-8111-111111111111',
expectedScope: { ...hostScope, offerRevision: 'v1:other' },
state: 'settled',
outcome: 'reset'
}
]
}
},
{
name: 'duplicate claimed offer',
value: {
version: 1,
attempts: [
{
idempotencyKey: '11111111-1111-4111-8111-111111111111',
expectedScope: hostScope,
state: 'settled',
outcome: 'reset'
},
{
idempotencyKey: '22222222-2222-4222-8222-222222222222',
expectedScope: hostScope,
state: 'settled',
outcome: 'alreadyRedeemed'
}
]
}
},
{
name: 'duplicate pending account scope',
value: {
version: 1,
attempts: [
{
idempotencyKey: '11111111-1111-4111-8111-111111111111',
expectedScope: hostScope,
state: 'providerPending'
},
{
idempotencyKey: '22222222-2222-4222-8222-222222222222',
expectedScope: { ...hostScope, offerRevision: 'v1:other' },
state: 'providerPending'
}
]
}
},
{
name: 'invalid WSL target',
value: {
version: 1,
attempts: [
{
idempotencyKey: '11111111-1111-4111-8111-111111111111',
expectedScope: {
...hostScope,
target: { runtime: 'wsl', wslDistro: null }
},
state: 'providerPending'
}
]
}
}
])('rejects $name as a corrupt ledger', ({ value }) => {
expect(() => parseCodexResetCreditAttemptLedger(value)).toThrow(
'Codex reset-credit attempt ledger is corrupt'
)
})
})