mirror of
https://github.com/stablyai/orca.git
synced 2026-11-06 03:57:35 +00:00
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
145 lines
4.4 KiB
TypeScript
145 lines
4.4 KiB
TypeScript
import type * as GitRunner from './git/runner'
|
|
|
|
import { join } from 'node:path'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import {
|
|
TEST_GITIGNORE_PATH,
|
|
TEST_ISSUE_COMMAND_PATH,
|
|
TEST_REPO_ORCA_YAML_PATH,
|
|
TEST_REPO_PATH
|
|
} from './hooks-test-fixtures'
|
|
|
|
vi.mock('fs', () => ({
|
|
readFileSync: vi.fn(),
|
|
existsSync: vi.fn(),
|
|
mkdirSync: vi.fn(),
|
|
writeFileSync: vi.fn(),
|
|
rmSync: vi.fn(),
|
|
chmodSync: vi.fn()
|
|
}))
|
|
|
|
const { gitExecFileSyncMock } = vi.hoisted(() => ({
|
|
gitExecFileSyncMock: vi.fn()
|
|
}))
|
|
|
|
vi.mock('child_process', () => ({
|
|
exec: vi.fn(),
|
|
execFile: vi.fn(),
|
|
execFileSync: vi.fn(),
|
|
spawn: vi.fn()
|
|
}))
|
|
|
|
vi.mock('./git/runner', async () => ({
|
|
...(await vi.importActual<typeof GitRunner>('./git/runner')),
|
|
gitExecFileSync: gitExecFileSyncMock
|
|
}))
|
|
|
|
vi.mock('./git/check-ignored-paths', () => ({
|
|
checkIgnoredPaths: vi.fn().mockResolvedValue([])
|
|
}))
|
|
|
|
describe('readIssueCommand', () => {
|
|
it('prefers the local override over the shared orca.yaml command', async () => {
|
|
const fs = await import('node:fs')
|
|
vi.mocked(fs.existsSync).mockImplementation(
|
|
(path) => path === TEST_ISSUE_COMMAND_PATH || path === TEST_REPO_ORCA_YAML_PATH
|
|
)
|
|
vi.mocked(fs.readFileSync).mockImplementation((path) => {
|
|
if (path === TEST_ISSUE_COMMAND_PATH) {
|
|
return 'local command\n'
|
|
}
|
|
if (path === TEST_REPO_ORCA_YAML_PATH) {
|
|
return 'issueCommand: |\n shared command\n'
|
|
}
|
|
return ''
|
|
})
|
|
|
|
const { readIssueCommand } = await import('./issue-command-file')
|
|
expect(readIssueCommand(TEST_REPO_PATH)).toEqual({
|
|
localContent: 'local command',
|
|
sharedContent: 'shared command',
|
|
effectiveContent: 'local command',
|
|
localFilePath: TEST_ISSUE_COMMAND_PATH,
|
|
source: 'local'
|
|
})
|
|
})
|
|
|
|
it('falls back to the shared orca.yaml command when no local override exists', async () => {
|
|
const fs = await import('node:fs')
|
|
vi.mocked(fs.existsSync).mockImplementation((path) => path === TEST_REPO_ORCA_YAML_PATH)
|
|
vi.mocked(fs.readFileSync).mockImplementation((path) => {
|
|
if (path === TEST_REPO_ORCA_YAML_PATH) {
|
|
return 'issueCommand: |\n shared command\n'
|
|
}
|
|
return ''
|
|
})
|
|
|
|
const { readIssueCommand } = await import('./issue-command-file')
|
|
expect(readIssueCommand(TEST_REPO_PATH)).toEqual({
|
|
localContent: null,
|
|
sharedContent: 'shared command',
|
|
effectiveContent: 'shared command',
|
|
localFilePath: TEST_ISSUE_COMMAND_PATH,
|
|
source: 'shared'
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('writeIssueCommand', () => {
|
|
it('checks file ignore rules in the selected WSL distro', async () => {
|
|
const { writeIssueCommand } = await import('./issue-command-file')
|
|
const { checkIgnoredPaths } = await import('./git/check-ignored-paths')
|
|
const fs = await import('node:fs')
|
|
vi.mocked(checkIgnoredPaths).mockResolvedValueOnce(['.orca/issue-command'])
|
|
vi.mocked(fs.writeFileSync).mockClear()
|
|
|
|
await writeIssueCommand(TEST_REPO_PATH, 'local command', { wslDistro: 'Ubuntu' })
|
|
|
|
expect(checkIgnoredPaths).toHaveBeenLastCalledWith(TEST_REPO_PATH, ['.orca/issue-command'], {
|
|
wslDistro: 'Ubuntu'
|
|
})
|
|
expect(fs.writeFileSync).toHaveBeenCalledExactlyOnceWith(
|
|
TEST_ISSUE_COMMAND_PATH,
|
|
'local command\n',
|
|
'utf-8'
|
|
)
|
|
})
|
|
|
|
it('writes only the local override file and keeps .orca ignored locally', async () => {
|
|
const fs = await import('node:fs')
|
|
vi.mocked(fs.existsSync).mockImplementation(
|
|
(path) => path === TEST_GITIGNORE_PATH || path === join(TEST_REPO_PATH, '.orca')
|
|
)
|
|
vi.mocked(fs.readFileSync).mockImplementation((path) => {
|
|
if (path === TEST_GITIGNORE_PATH) {
|
|
return 'node_modules/\n'
|
|
}
|
|
return ''
|
|
})
|
|
|
|
const { writeIssueCommand } = await import('./issue-command-file')
|
|
await writeIssueCommand(TEST_REPO_PATH, 'local command')
|
|
|
|
expect(vi.mocked(fs.writeFileSync)).toHaveBeenCalledWith(
|
|
TEST_GITIGNORE_PATH,
|
|
'node_modules/\n.orca\n',
|
|
'utf-8'
|
|
)
|
|
expect(vi.mocked(fs.writeFileSync)).toHaveBeenCalledWith(
|
|
TEST_ISSUE_COMMAND_PATH,
|
|
'local command\n',
|
|
'utf-8'
|
|
)
|
|
})
|
|
|
|
it('deletes the local override when the override is cleared', async () => {
|
|
const { writeIssueCommand } = await import('./issue-command-file')
|
|
const fs = await import('node:fs')
|
|
await writeIssueCommand(TEST_REPO_PATH, ' ')
|
|
|
|
expect(vi.mocked(fs.rmSync)).toHaveBeenCalledWith(TEST_ISSUE_COMMAND_PATH, {
|
|
force: true
|
|
})
|
|
})
|
|
})
|