Files
orca/src/cli/browser-empty-values.test.ts
T
Neil 6607c54984 perf(ci): cut redundant tests and reuse expensive setup (#28669)
* perf(ci): reduce test overhead and reuse expensive build work

* test(ci): keep worker startup outside failure-case deadlines

* test: isolate push fixture advisory locks

* test(ci): preserve fixed drain retry allowance

* Align CI contracts with current triggers and guide content

* Stabilize consolidated reveal scenarios and retain behavioral CI contracts

* Fix upstream lint blockers while retaining behavior and assertions

* Classify global Jira preferences in the WSL migration inventory

* Align Jira test fixtures with startup and build safety checks

* Include package-test routing dependency in CI checkouts and fixtures

* Keep native stream classes intact in transcript dependency tests
2026-10-14 16:14:27 -07:00

214 lines
6.4 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const callMock = vi.fn()
vi.mock('./runtime-client', () => {
class RuntimeClient {
call = callMock
getCliStatus = vi.fn()
openOrca = vi.fn()
}
class RuntimeClientError extends Error {
readonly code: string
constructor(code: string, message: string) {
super(message)
this.code = code
}
}
class RuntimeRpcFailureError extends RuntimeClientError {
readonly response: unknown
constructor(response: unknown) {
super('runtime_error', 'runtime_error')
this.response = response
}
}
return {
RuntimeClient,
RuntimeClientError,
RuntimeRpcFailureError
}
})
import { main } from './index'
import { okFixture, queueFixtures } from './test-fixtures'
// Why: StorageKeyValue requires a non-empty key but accepts any string value, empty included.
describe('orca cli storage set preserves an empty value', () => {
beforeEach(() => {
callMock.mockReset()
process.exitCode = undefined
})
afterEach(() => {
vi.restoreAllMocks()
})
it('passes an empty --value through to browser.storage.local.set', async () => {
queueFixtures(callMock, okFixture('req_storage_local_set', { success: true }))
vi.spyOn(console, 'log').mockImplementation(() => {})
await main(
['storage', 'local', 'set', '--key', 'flag', '--value', '', '--worktree', 'all', '--json'],
'/tmp/not-an-orca-worktree'
)
expect(callMock).toHaveBeenCalledTimes(1)
expect(callMock).toHaveBeenCalledWith('browser.storage.local.set', {
key: 'flag',
value: '',
worktree: undefined
})
})
it('passes an empty --value through to browser.storage.session.set', async () => {
queueFixtures(callMock, okFixture('req_storage_session_set', { success: true }))
vi.spyOn(console, 'log').mockImplementation(() => {})
await main(
['storage', 'session', 'set', '--key', 'flag', '--value', '', '--worktree', 'all', '--json'],
'/tmp/not-an-orca-worktree'
)
expect(callMock).toHaveBeenCalledTimes(1)
expect(callMock).toHaveBeenCalledWith('browser.storage.session.set', {
key: 'flag',
value: '',
worktree: undefined
})
})
// Why: PowerShell 5.1 drops empty native-exe args, so `--value=` is the Windows escape hatch.
it('passes an empty --value= (equals form) through to browser.storage.local.set', async () => {
queueFixtures(callMock, okFixture('req_storage_local_set', { success: true }))
vi.spyOn(console, 'log').mockImplementation(() => {})
await main(
['storage', 'local', 'set', '--key=flag', '--value=', '--worktree', 'all', '--json'],
'/tmp/not-an-orca-worktree'
)
expect(callMock).toHaveBeenCalledTimes(1)
expect(callMock).toHaveBeenCalledWith('browser.storage.local.set', {
key: 'flag',
value: '',
worktree: undefined
})
})
it('still rejects an empty --key before RPC dispatch', async () => {
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
const priorExitCode = process.exitCode
await main(
['storage', 'local', 'set', '--key', '', '--value', 'x', '--worktree', 'all'],
'/tmp/not-an-orca-worktree'
)
expect(callMock).not.toHaveBeenCalled()
expect(errorSpy.mock.calls.flat().join('\n')).toContain('Missing required --key')
expect(process.exitCode).toBe(1)
process.exitCode = priorExitCode
})
it('still rejects a missing --value before RPC dispatch', async () => {
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
const priorExitCode = process.exitCode
await main(
['storage', 'local', 'set', '--key', 'flag', '--worktree', 'all'],
'/tmp/not-an-orca-worktree'
)
expect(callMock).not.toHaveBeenCalled()
expect(errorSpy.mock.calls.flat().join('\n')).toContain('Missing required --value')
expect(process.exitCode).toBe(1)
process.exitCode = priorExitCode
})
})
// Why: CookieSet.value and SetCredentials.pass accept any string, empty included,
// while name and user require a non-empty one.
describe('orca cli cookie set and set credentials preserve an empty value', () => {
beforeEach(() => {
callMock.mockReset()
process.exitCode = undefined
})
afterEach(() => {
vi.restoreAllMocks()
})
it('passes an empty --value through to browser.cookie.set', async () => {
queueFixtures(callMock, okFixture('req_cookie_set', { success: true }))
vi.spyOn(console, 'log').mockImplementation(() => {})
await main(
['cookie', 'set', '--name', 'sid', '--value', '', '--worktree', 'all', '--json'],
'/tmp/not-an-orca-worktree'
)
expect(callMock).toHaveBeenCalledTimes(1)
expect(callMock).toHaveBeenCalledWith('browser.cookie.set', {
name: 'sid',
value: '',
worktree: undefined
})
})
it('passes an empty --pass through to browser.setCredentials', async () => {
queueFixtures(callMock, okFixture('req_set_credentials', { success: true }))
vi.spyOn(console, 'log').mockImplementation(() => {})
await main(
['set', 'credentials', '--user', 'token', '--pass', '', '--worktree', 'all', '--json'],
'/tmp/not-an-orca-worktree'
)
expect(callMock).toHaveBeenCalledTimes(1)
expect(callMock).toHaveBeenCalledWith('browser.setCredentials', {
user: 'token',
pass: '',
worktree: undefined
})
})
it('still rejects an empty --name before RPC dispatch', async () => {
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
const priorExitCode = process.exitCode
await main(
['cookie', 'set', '--name', '', '--value', 'x', '--worktree', 'all'],
'/tmp/not-an-orca-worktree'
)
expect(callMock).not.toHaveBeenCalled()
expect(errorSpy.mock.calls.flat().join('\n')).toContain('Missing required --name')
expect(process.exitCode).toBe(1)
process.exitCode = priorExitCode
})
it('still rejects a missing --pass before RPC dispatch', async () => {
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
const priorExitCode = process.exitCode
await main(
['set', 'credentials', '--user', 'token', '--worktree', 'all'],
'/tmp/not-an-orca-worktree'
)
expect(callMock).not.toHaveBeenCalled()
expect(errorSpy.mock.calls.flat().join('\n')).toContain('Missing required --pass')
expect(process.exitCode).toBe(1)
process.exitCode = priorExitCode
})
})