Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.9 KB
Raw Blame
import { beforeEach, describe, expect, it, vi } from 'vitest'

vi.mock('expo-file-system', () => ({ Directory: class {}, File: class {}, Paths: { cache: '' } }))
vi.mock('./generation-store-file-system', async () => {
  const { createFakeGenerationFileSystem } = await import('./generation-file-system-fake')
  const fileSystem = createFakeGenerationFileSystem()
  return { createExpoGenerationFileSystem: () => fileSystem }
})

import { createGenerationStore } from './generation-store'
import { createExpoGenerationFileSystem } from './generation-store-file-system'
import { forgetHostUpdateFailures } from './removed-host-shell-cache'

function store() {
  return createGenerationStore({ fileSystem: createExpoGenerationFileSystem() })
}

async function seed(hostId: string): Promise<void> {
  await store().recordUpdateFailure({
    hostId,
    at: 1,
    reason: 'connection-lost',
    hostCode: null,
    offeredBuildId: null,
    cachedBuildId: null,
    outcome: 'opened-cached',
    wall: null
  })
}

describe('forgetHostUpdateFailures', () => {
  beforeEach(async () => {
    await store().forgetHostUpdateFailures('host-1')
    await store().forgetHostUpdateFailures('host-2')
  })

  it("drops the removed host's records and keeps the rest", async () => {
    await seed('host-1')
    await seed('host-2')
    await forgetHostUpdateFailures('host-1')
    expect((await store().readUpdateFailures()).map((entry) => entry.hostId)).toEqual(['host-2'])
  })

  it('writes nothing when nothing was recorded', async () => {
    const fileSystem = createExpoGenerationFileSystem()
    expect(await fileSystem.readText(`${fileSystem.rootUri}/update-failures.json`)).toBeNull()
    const write = vi.spyOn(fileSystem, 'writeText')
    try {
      await forgetHostUpdateFailures('host-1')
      expect(write).not.toHaveBeenCalled()
      expect(await fileSystem.readText(`${fileSystem.rootUri}/update-failures.json`)).toBeNull()
    } finally {
      write.mockRestore()
    }
  })
})