-
-
Notifications
You must be signed in to change notification settings - Fork 532
Expand file tree
/
Copy pathagentCommandOptions.test.ts
More file actions
179 lines (159 loc) · 6.35 KB
/
Copy pathagentCommandOptions.test.ts
File metadata and controls
179 lines (159 loc) · 6.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import { describe, expect, it } from 'vitest'
import { GEMINI_PERMISSION_MODES, OPENCODE_PERMISSION_MODES } from '@hapi/protocol/modes'
import { parseRemoteAgentCommandOptions } from './agentCommandOptions'
describe('parseRemoteAgentCommandOptions', () => {
it('parses common remote agent flags', () => {
expect(parseRemoteAgentCommandOptions([
'--started-by', 'runner',
'--hapi-starting-mode', 'remote',
'--permission-mode', 'yolo',
'--resume', 'session-1',
'--model', 'model-a'
], GEMINI_PERMISSION_MODES)).toEqual({
startedBy: 'runner',
startingMode: 'remote',
permissionMode: 'yolo',
resumeSessionId: 'session-1',
model: 'model-a'
})
})
it('does not let --yolo override an explicit permission mode that appeared first', () => {
expect(parseRemoteAgentCommandOptions([
'--permission-mode', 'default',
'--yolo'
], OPENCODE_PERMISSION_MODES).permissionMode).toBe('default')
})
it('accepts OpenCode plan permission mode', () => {
expect(parseRemoteAgentCommandOptions([
'--permission-mode',
'plan'
], OPENCODE_PERMISSION_MODES).permissionMode).toBe('plan')
})
it('keeps current unknown-arg behavior by ignoring unrecognized flags', () => {
expect(parseRemoteAgentCommandOptions([
'--unknown',
'value',
'--model',
'model-a'
], GEMINI_PERMISSION_MODES)).toEqual({
model: 'model-a'
})
})
it('rejects invalid constrained values', () => {
expect(() => parseRemoteAgentCommandOptions([
'--hapi-starting-mode',
'sideways'
], GEMINI_PERMISSION_MODES)).toThrow('Invalid --hapi-starting-mode')
expect(() => parseRemoteAgentCommandOptions([
'--permission-mode',
'bypassPermissions'
], GEMINI_PERMISSION_MODES)).toThrow('Invalid --permission-mode value')
})
it('parses model reasoning effort', () => {
expect(parseRemoteAgentCommandOptions([
'--model-reasoning-effort',
'high'
], OPENCODE_PERMISSION_MODES).modelReasoningEffort).toBe('high')
})
it('requires values for resume and model flags', () => {
expect(() => parseRemoteAgentCommandOptions(['--resume'], OPENCODE_PERMISSION_MODES)).toThrow('Missing --resume value')
expect(() => parseRemoteAgentCommandOptions(['--model'], OPENCODE_PERMISSION_MODES)).toThrow('Missing --model value')
expect(() => parseRemoteAgentCommandOptions(['--model-reasoning-effort'], OPENCODE_PERMISSION_MODES)).toThrow('Missing --model-reasoning-effort value')
})
})
describe('parseRemoteAgentCommandOptions — pi flavor', () => {
// Pi RPC mode has no permission switching, so the command passes an empty
// allow-list. These tests cover the non-permission flags using a non-empty
// allow-list purely as a parser fixture — the parser's behavior is
// independent of the modes' contents.
const ALLOWED = OPENCODE_PERMISSION_MODES
it('accepts --model and stores it on options', () => {
const result = parseRemoteAgentCommandOptions(
['--model', 'claude-sonnet-4-5'],
ALLOWED
)
expect(result.model).toBe('claude-sonnet-4-5')
})
it('--session-id stores the value as resumeSessionId (Pi-specific flag)', () => {
// Pi uses --session-id for exact session resume (RPC mode), not the
// generic --resume that other flavors use.
const result = parseRemoteAgentCommandOptions(
['--session-id', 'pi-sess-123'],
ALLOWED
)
expect(result.resumeSessionId).toBe('pi-sess-123')
})
it('--resume is also accepted as an alias for session resume', () => {
// Some flavor paths pass --resume; the parser should accept it
// uniformly so callers do not need to branch on flavor.
const result = parseRemoteAgentCommandOptions(
['--resume', 'sess-id'],
ALLOWED
)
expect(result.resumeSessionId).toBe('sess-id')
})
it('a later --resume overrides a prior --session-id (last-write-wins)', () => {
const result = parseRemoteAgentCommandOptions(
['--session-id', 'first', '--resume', 'second'],
ALLOWED
)
expect(result.resumeSessionId).toBe('second')
})
it('rejects --session-id with no value', () => {
expect(() => parseRemoteAgentCommandOptions(
['--session-id'],
ALLOWED
)).toThrow('Missing --session-id value')
})
it('parses --started-by runner', () => {
const result = parseRemoteAgentCommandOptions(
['--started-by', 'runner'],
ALLOWED
)
expect(result.startedBy).toBe('runner')
})
it('parses --started-by terminal', () => {
const result = parseRemoteAgentCommandOptions(
['--started-by', 'terminal'],
ALLOWED
)
expect(result.startedBy).toBe('terminal')
})
it('parses --hapi-starting-mode remote', () => {
const result = parseRemoteAgentCommandOptions(
['--hapi-starting-mode', 'remote'],
ALLOWED
)
expect(result.startingMode).toBe('remote')
})
it('parses --hapi-starting-mode local', () => {
const result = parseRemoteAgentCommandOptions(
['--hapi-starting-mode', 'local'],
ALLOWED
)
expect(result.startingMode).toBe('local')
})
it('rejects invalid --hapi-starting-mode', () => {
expect(() => parseRemoteAgentCommandOptions(
['--hapi-starting-mode', 'invalid'],
ALLOWED
)).toThrow('Invalid --hapi-starting-mode')
})
it('handles a full pi invocation end-to-end', () => {
const result = parseRemoteAgentCommandOptions(
[
'--started-by', 'runner',
'--hapi-starting-mode', 'remote',
'--model', 'claude-sonnet-4-5',
'--session-id', 'pi-sess-full',
],
ALLOWED
)
expect(result).toEqual({
startedBy: 'runner',
startingMode: 'remote',
model: 'claude-sonnet-4-5',
resumeSessionId: 'pi-sess-full',
})
})
})