feat(cli): add tab profile lifecycle commands (#1397)
Co-authored-by: Orca <help@stably.ai> Co-authored-by: Nikolatesla-lj <Nikolatesla-lj@users.noreply.github.com> Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
This commit is contained in:
co-authored by
Orca
Nikolatesla-lj
Jinwoo-H
parent
f90da6ea37
commit
9bf339eeb9
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable max-lines -- Why: this file groups every CLI browser-command test (page targeting, profiles, waits, viewport) so test-fixture imports and the runtime-client mock stay shared in one place. */
|
||||
import path from 'path'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
@@ -128,6 +129,151 @@ describe('orca cli browser page targeting', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('orca cli browser tab profiles', () => {
|
||||
beforeEach(() => {
|
||||
callMock.mockReset()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('lists browser tab profiles', async () => {
|
||||
queueFixtures(
|
||||
callMock,
|
||||
okFixture('req_profiles', {
|
||||
profiles: [
|
||||
{ id: 'default', scope: 'default', label: 'Default', partition: 'persist:orca-browser' },
|
||||
{
|
||||
id: 'work',
|
||||
scope: 'isolated',
|
||||
label: 'Work',
|
||||
partition: 'persist:orca-browser-session-work'
|
||||
}
|
||||
]
|
||||
})
|
||||
)
|
||||
vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
|
||||
await main(['tab', 'profile', 'list', '--json'], '/tmp/not-an-orca-worktree')
|
||||
|
||||
expect(callMock).toHaveBeenCalledTimes(1)
|
||||
expect(callMock).toHaveBeenCalledWith('browser.profileList')
|
||||
})
|
||||
|
||||
it('reports an empty browser tab profile list with a friendly message', async () => {
|
||||
queueFixtures(callMock, okFixture('req_profiles', { profiles: [] }))
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
|
||||
await main(['tab', 'profile', 'list'], '/tmp/not-an-orca-worktree')
|
||||
|
||||
expect(callMock).toHaveBeenCalledTimes(1)
|
||||
expect(callMock).toHaveBeenCalledWith('browser.profileList')
|
||||
expect(logSpy).toHaveBeenCalledWith('No browser profiles found.')
|
||||
})
|
||||
|
||||
it('creates isolated browser tab profiles by default', async () => {
|
||||
queueFixtures(
|
||||
callMock,
|
||||
okFixture('req_profile_create', {
|
||||
profile: {
|
||||
id: 'work',
|
||||
scope: 'isolated',
|
||||
label: 'Work',
|
||||
partition: 'persist:orca-browser-session-work'
|
||||
}
|
||||
})
|
||||
)
|
||||
vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
|
||||
await main(
|
||||
['tab', 'profile', 'create', '--label', 'Work', '--json'],
|
||||
'/tmp/not-an-orca-worktree'
|
||||
)
|
||||
|
||||
expect(callMock).toHaveBeenCalledTimes(1)
|
||||
expect(callMock).toHaveBeenCalledWith('browser.profileCreate', {
|
||||
label: 'Work',
|
||||
scope: 'isolated'
|
||||
})
|
||||
})
|
||||
|
||||
it('forwards --scope imported through to the runtime', async () => {
|
||||
queueFixtures(
|
||||
callMock,
|
||||
okFixture('req_profile_create', {
|
||||
profile: {
|
||||
id: 'imp',
|
||||
scope: 'imported',
|
||||
label: 'From Chrome',
|
||||
partition: 'persist:orca-browser-session-imp'
|
||||
}
|
||||
})
|
||||
)
|
||||
vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
|
||||
await main(
|
||||
['tab', 'profile', 'create', '--label', 'From Chrome', '--scope', 'imported', '--json'],
|
||||
'/tmp/not-an-orca-worktree'
|
||||
)
|
||||
|
||||
expect(callMock).toHaveBeenCalledWith('browser.profileCreate', {
|
||||
label: 'From Chrome',
|
||||
scope: 'imported'
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects unknown --scope values instead of silently defaulting to isolated', async () => {
|
||||
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
|
||||
await main(
|
||||
['tab', 'profile', 'create', '--label', 'Work', '--scope', 'isloated'],
|
||||
'/tmp/not-an-orca-worktree'
|
||||
)
|
||||
|
||||
expect(callMock).not.toHaveBeenCalled()
|
||||
expect(errorSpy).toHaveBeenCalledWith('--scope must be "isolated" or "imported"')
|
||||
})
|
||||
|
||||
it('surfaces a runtime error if the registry refuses to create a profile', async () => {
|
||||
queueFixtures(callMock, okFixture('req_profile_create', { profile: null }))
|
||||
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
|
||||
await main(['tab', 'profile', 'create', '--label', 'Bogus'], '/tmp/not-an-orca-worktree')
|
||||
|
||||
expect(callMock).toHaveBeenCalledTimes(1)
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
'Failed to create browser profile (label=Bogus, scope=isolated)'
|
||||
)
|
||||
})
|
||||
|
||||
it('deletes browser tab profiles by id', async () => {
|
||||
queueFixtures(callMock, okFixture('req_profile_delete', { deleted: true, profileId: 'work' }))
|
||||
vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
|
||||
await main(
|
||||
['tab', 'profile', 'delete', '--profile', 'work', '--json'],
|
||||
'/tmp/not-an-orca-worktree'
|
||||
)
|
||||
|
||||
expect(callMock).toHaveBeenCalledTimes(1)
|
||||
expect(callMock).toHaveBeenCalledWith('browser.profileDelete', { profileId: 'work' })
|
||||
})
|
||||
|
||||
it('reports a not-deleted profile in text mode without throwing', async () => {
|
||||
queueFixtures(
|
||||
callMock,
|
||||
okFixture('req_profile_delete', { deleted: false, profileId: 'default' })
|
||||
)
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
|
||||
await main(['tab', 'profile', 'delete', '--profile', 'default'], '/tmp/not-an-orca-worktree')
|
||||
|
||||
expect(callMock).toHaveBeenCalledWith('browser.profileDelete', { profileId: 'default' })
|
||||
expect(logSpy).toHaveBeenCalledWith('Profile default was not deleted')
|
||||
})
|
||||
})
|
||||
|
||||
describe('orca cli browser waits and viewport flags', () => {
|
||||
beforeEach(() => {
|
||||
callMock.mockReset()
|
||||
|
||||
Reference in New Issue
Block a user