mirror of
https://github.com/stablyai/orca.git
synced 2026-10-12 16:03:03 +00:00
* test: remove mock echoes and duplicate contracts that only reading finds
Two veins in one wave, both requiring the production path to be read rather than
pattern-matched.
Mock echoes (36 strongest candidates reviewed, 2 real): the flagged shape —
literals shared between a mock factory and an expect matcher — is almost always
a test feeding an input and asserting a transform. The two genuine echoes are in
`pty-management.test.ts`, where the handler returns
`getDaemonFolderAccessMismatch(identity)` verbatim, so asserting the mock's own
`evidence('allowed')` object and its `null` proved only the mock. One case's own
comment conceded the handler makes no decision. The branch-exercising cases in
that file stay.
Semantic sweep of 80 files no detector flagged, 27 junk cases removed. What it
found has no mechanical signature:
- a handler that is literally `() => getComputerUsePermissionStatus()`, so
`resolves.toBe(result)` guarded nothing;
- "does not mutate a stale registration off Linux" whose refusal came from a
DIFFERENT guard — `cli.ts` has no platform check, and the test's own mock made
`resolveAppImageRuntimeIdentity` return null, which a sibling case already owns;
- "keeps probing a host that is still retained" asserting a no-op, because
`retainScopes` only cancels queued probes and stores no state;
- two cases comparing against `referenceAllowedRoots`, a verbatim copy of the
pre-change algorithm kept in the test file — expected values produced by the
thing under test. The third such case stays: it calls the old algorithm to
COUNT its work (100_000 containment checks vs 100), a real bound on the
authorization hot path;
- a remote-folder refusal that came from the fake provider's own rejection
message rather than any Orca guard;
- "advertises each capability once", where a duplicate entry is inert in
production because membership is `includes`;
- an Antigravity `scaffold self-check` built on a hand-typed five-line screen —
the exact fixture shape docs/reference/antigravity-readiness-evidence.md blames
for five failed detector attempts — whose banner had already drifted to
`Antigravity CLI 1.0.3` against a real captured `1.2.0`. The raw-capture
provenance guard and the transcript checklist ratchet in that file stay.
No production file is touched and no test file is deleted.
* test: retire duplicate daemon and filesystem cases the sweep found
Continues the semantic sweep into src/main/ipc filesystem handlers and
src/main/daemon. 16 cases removed across 13 files; no production file touched.
The recurring shape is a case that reaches the same branch as its sibling by a
different-looking route:
- `parseArgs` is a flag-scanning loop, so "handles flags in any order" asserts the
identical result object as the in-order case, and "throws with no args" lands on
the same `Usage:` throw the two missing-flag cases already reach;
- an ENOENT case with "no code at all" and its sibling with a numeric transport
code both fall through to the same `ENOENT_MESSAGE.test` branch;
- "establishes connection with hello handshake" and "receives stream events" are
strict subsets of cases that require two matching authenticated sockets and a
frame split inside a multibyte character.
Two were vacuous rather than duplicated: a fixture self-comparison asserting
`String.normalize` gives different NFC and NFD spellings, and a
`not.toThrow` batch case whose 200k events are truncated by
`MAX_BATCHED_WATCHER_EVENTS = 5_000` long before the argument spread it was
written to exercise.
One whole-file deletion was reversed: `freebuff-detection.test.ts` looked like a
table restatement, but the sibling detection test covers only dependency ordering
and platform gating, not freebuff/codebuff independence — and those two names
share a suffix, so it is the only guard against one shadowing the other.
203 lines
6.8 KiB
TypeScript
203 lines
6.8 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import {
|
|
handlers,
|
|
store,
|
|
WORKTREE_FEATURE_PATH,
|
|
commitChangesMock,
|
|
bulkDiscardChangesMock,
|
|
getSshGitProviderMock,
|
|
resetFilesystemIpcMocks
|
|
} from './filesystem-test-harness'
|
|
|
|
vi.mock('electron', async () => (await import('./filesystem-test-harness')).electronMock)
|
|
vi.mock('fs/promises', async () => (await import('./filesystem-test-harness')).fsPromisesMock)
|
|
vi.mock(
|
|
'../wsl-unc-delete',
|
|
async () => (await import('./filesystem-test-harness')).wslUncDeleteMock
|
|
)
|
|
vi.mock(
|
|
'../crash-reporting/crash-breadcrumb-store',
|
|
async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock
|
|
)
|
|
vi.mock(
|
|
'../local-downloaded-folder-promotion',
|
|
async () => (await import('./filesystem-test-harness')).folderPromotionMock
|
|
)
|
|
vi.mock(
|
|
'../git/status',
|
|
async () => (await import('./filesystem-test-harness')).gitStatusModuleMock
|
|
)
|
|
vi.mock(
|
|
'../git/check-ignored-paths',
|
|
async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock
|
|
)
|
|
vi.mock('../git/worktree', async () => (await import('./filesystem-test-harness')).gitWorktreeMock)
|
|
vi.mock(
|
|
'../providers/ssh-filesystem-dispatch',
|
|
async () => (await import('./filesystem-test-harness')).sshFilesystemDispatchMock
|
|
)
|
|
vi.mock(
|
|
'../providers/ssh-git-dispatch',
|
|
async () => (await import('./filesystem-test-harness')).sshGitDispatchMock
|
|
)
|
|
vi.mock(
|
|
'../text-generation/commit-message-text-generation',
|
|
async () => (await import('./filesystem-test-harness')).textGenerationModuleMock
|
|
)
|
|
vi.mock(
|
|
'../text-generation/pull-request-context',
|
|
async () => (await import('./filesystem-test-harness')).pullRequestContextMock
|
|
)
|
|
vi.mock(
|
|
'../source-control/pull-request-template',
|
|
async () => (await import('./filesystem-test-harness')).pullRequestTemplateMock
|
|
)
|
|
vi.mock(
|
|
'../source-control/pull-request-linked-issue',
|
|
async () => (await import('./filesystem-test-harness')).pullRequestLinkedIssueMock
|
|
)
|
|
|
|
import { registerFilesystemHandlers } from './filesystem'
|
|
import { invalidateAuthorizedRootsCache } from './registered-worktree-roots-cache'
|
|
|
|
describe('registerFilesystemHandlers', () => {
|
|
beforeEach(() => {
|
|
resetFilesystemIpcMocks()
|
|
// Reset module-level auth cache so each test starts with a fresh dirty
|
|
// flag — prevents stale worktree data from a prior test's cache rebuild.
|
|
invalidateAuthorizedRootsCache()
|
|
})
|
|
|
|
it('routes local git:commit through commitChanges and returns success', async () => {
|
|
commitChangesMock.mockResolvedValue({ success: true })
|
|
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await expect(
|
|
handlers.get('git:commit')!(null, {
|
|
worktreePath: WORKTREE_FEATURE_PATH,
|
|
message: 'feat: ship commit'
|
|
})
|
|
).resolves.toEqual({ success: true })
|
|
|
|
expect(commitChangesMock).toHaveBeenCalledWith(WORKTREE_FEATURE_PATH, 'feat: ship commit', {
|
|
admissionTier: 'interactive'
|
|
})
|
|
})
|
|
|
|
it('routes ssh git:commit through the SSH provider instead of local commitChanges', async () => {
|
|
const sshCommitMock = vi.fn().mockResolvedValue({ success: true })
|
|
getSshGitProviderMock.mockReturnValue({ commit: sshCommitMock })
|
|
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await expect(
|
|
handlers.get('git:commit')!(null, {
|
|
worktreePath: '/remote/repo',
|
|
message: 'feat: remote commit',
|
|
connectionId: 'conn-1'
|
|
})
|
|
).resolves.toEqual({ success: true })
|
|
|
|
expect(sshCommitMock).toHaveBeenCalledWith('/remote/repo', 'feat: remote commit')
|
|
expect(commitChangesMock).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('routes ssh git:remoteCommitUrl through the SSH provider', async () => {
|
|
const sha = '0123456789abcdef0123456789abcdef01234567'
|
|
const sshRemoteCommitUrlMock = vi.fn().mockResolvedValue('https://github.com/org/repo/commit/x')
|
|
getSshGitProviderMock.mockReturnValue({ getRemoteCommitUrl: sshRemoteCommitUrlMock })
|
|
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await expect(
|
|
handlers.get('git:remoteCommitUrl')!(null, {
|
|
worktreePath: '/remote/repo',
|
|
sha,
|
|
connectionId: 'conn-1'
|
|
})
|
|
).resolves.toBe('https://github.com/org/repo/commit/x')
|
|
|
|
expect(sshRemoteCommitUrlMock).toHaveBeenCalledWith('/remote/repo', sha)
|
|
})
|
|
|
|
it('rejects git:remoteCommitUrl with a short hash before SSH dispatch', async () => {
|
|
const sshRemoteCommitUrlMock = vi.fn()
|
|
getSshGitProviderMock.mockReturnValue({ getRemoteCommitUrl: sshRemoteCommitUrlMock })
|
|
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await expect(
|
|
handlers.get('git:remoteCommitUrl')!(null, {
|
|
worktreePath: '/remote/repo',
|
|
sha: 'abc123',
|
|
connectionId: 'conn-1'
|
|
})
|
|
).rejects.toThrow('sha must be a full git object id')
|
|
|
|
expect(sshRemoteCommitUrlMock).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('routes ssh git:bulkDiscard through the SSH provider', async () => {
|
|
const sshBulkDiscardMock = vi.fn().mockResolvedValue(undefined)
|
|
getSshGitProviderMock.mockReturnValue({ bulkDiscardChanges: sshBulkDiscardMock })
|
|
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await handlers.get('git:bulkDiscard')!(null, {
|
|
worktreePath: '/remote/repo',
|
|
filePaths: ['a.ts', 'b.ts'],
|
|
connectionId: 'conn-1'
|
|
})
|
|
|
|
expect(sshBulkDiscardMock).toHaveBeenCalledWith('/remote/repo', ['a.ts', 'b.ts'])
|
|
expect(bulkDiscardChangesMock).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('routes ssh git:fastForward through the SSH provider', async () => {
|
|
const sshFastForwardMock = vi.fn().mockResolvedValue(undefined)
|
|
const pushTarget = { remoteName: 'fork', branchName: 'feature/fix' }
|
|
getSshGitProviderMock.mockReturnValue({ fastForwardBranch: sshFastForwardMock })
|
|
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await handlers.get('git:fastForward')!(null, {
|
|
worktreePath: '/remote/repo',
|
|
connectionId: 'conn-1',
|
|
pushTarget
|
|
})
|
|
|
|
expect(sshFastForwardMock).toHaveBeenCalledWith('/remote/repo', pushTarget)
|
|
})
|
|
|
|
it('rejects git:commit with whitespace-only message and does not call commitChanges', async () => {
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await expect(
|
|
handlers.get('git:commit')!(null, {
|
|
worktreePath: WORKTREE_FEATURE_PATH,
|
|
message: ' '
|
|
})
|
|
).rejects.toThrow('Commit message is required')
|
|
|
|
expect(commitChangesMock).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('rejects git:commit with whitespace-only message before SSH dispatch', async () => {
|
|
const sshCommitMock = vi.fn().mockResolvedValue({ success: true })
|
|
getSshGitProviderMock.mockReturnValue({ commit: sshCommitMock })
|
|
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await expect(
|
|
handlers.get('git:commit')!(null, {
|
|
worktreePath: '/remote/repo',
|
|
message: '\n',
|
|
connectionId: 'conn-1'
|
|
})
|
|
).rejects.toThrow('Commit message is required')
|
|
|
|
expect(sshCommitMock).not.toHaveBeenCalled()
|
|
})
|
|
})
|