mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-08 13:12:08 +00:00
feat(desktop): add project and coding stores
This commit is contained in:
parent
344415892f
commit
74352a1e61
8 changed files with 1205 additions and 45 deletions
74
apps/desktop/src/store/coding-status.test.ts
Normal file
74
apps/desktop/src/store/coding-status.test.ts
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { HermesRepoStatus } from '@/global'
|
||||
|
||||
import { $repoStatus, refreshRepoStatus } from './coding-status'
|
||||
import { $currentCwd } from './session'
|
||||
|
||||
const sampleStatus: HermesRepoStatus = {
|
||||
branch: 'feature/login',
|
||||
defaultBranch: 'main',
|
||||
detached: false,
|
||||
ahead: 1,
|
||||
behind: 0,
|
||||
staged: 1,
|
||||
unstaged: 2,
|
||||
untracked: 0,
|
||||
conflicted: 0,
|
||||
changed: 3,
|
||||
added: 12,
|
||||
removed: 4,
|
||||
files: []
|
||||
}
|
||||
|
||||
function stubProbe(impl: (cwd: string) => Promise<HermesRepoStatus | null>) {
|
||||
;(window as unknown as { hermesDesktop?: unknown }).hermesDesktop = { git: { repoStatus: impl } }
|
||||
}
|
||||
|
||||
describe('refreshRepoStatus', () => {
|
||||
beforeEach(() => {
|
||||
$repoStatus.set(null)
|
||||
$currentCwd.set('')
|
||||
delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop
|
||||
})
|
||||
|
||||
it('populates $repoStatus from the probe for an explicit cwd', async () => {
|
||||
stubProbe(async () => sampleStatus)
|
||||
await refreshRepoStatus('/repo')
|
||||
expect($repoStatus.get()).toEqual(sampleStatus)
|
||||
})
|
||||
|
||||
it('falls back to the active session cwd when none is passed', async () => {
|
||||
const probe = vi.fn(async () => sampleStatus)
|
||||
stubProbe(probe)
|
||||
$currentCwd.set('/active/repo')
|
||||
await refreshRepoStatus()
|
||||
expect(probe).toHaveBeenCalledWith('/active/repo')
|
||||
})
|
||||
|
||||
it('clears status when there is no cwd', async () => {
|
||||
stubProbe(async () => sampleStatus)
|
||||
$repoStatus.set(sampleStatus)
|
||||
await refreshRepoStatus(' ')
|
||||
expect($repoStatus.get()).toBeNull()
|
||||
})
|
||||
|
||||
it('clears status when the probe is unavailable (remote backend)', async () => {
|
||||
$repoStatus.set(sampleStatus)
|
||||
await refreshRepoStatus('/repo')
|
||||
expect($repoStatus.get()).toBeNull()
|
||||
})
|
||||
|
||||
it('clears status when the probe throws', async () => {
|
||||
stubProbe(async () => {
|
||||
throw new Error('not a repo')
|
||||
})
|
||||
$repoStatus.set(sampleStatus)
|
||||
await refreshRepoStatus('/repo')
|
||||
expect($repoStatus.get()).toBeNull()
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue