forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutionPolicy.test.ts
More file actions
159 lines (144 loc) · 5.81 KB
/
Copy pathexecutionPolicy.test.ts
File metadata and controls
159 lines (144 loc) · 5.81 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
// Port-parity tests for executionPolicy.ts (macOS execution-policy.ts). Covers
// the leaf-role control-tool guard (INV-AGENT) and the provider-boundary
// resolution that pins a session to its adapter's credential scope.
import { describe, expect, it } from 'vitest'
import {
LEAF_AGENT_CONTROL_TOOLS,
credentialScopeForBoundary,
executionRoleAllowsTool,
executionRoleForSurface,
providerBoundaryForAdapter,
resolveAdapterWithinBoundary
} from './executionPolicy'
describe('executionPolicy — leaf-role guards', () => {
it('blocks leaf workers from every agent-control tool', () => {
for (const tool of LEAF_AGENT_CONTROL_TOOLS) {
expect(executionRoleAllowsTool('leaf', tool)).toBe(false)
}
})
it('allows leaf workers non-control tools and allows coordinators everything', () => {
expect(executionRoleAllowsTool('leaf', 'search_memory')).toBe(true)
expect(executionRoleAllowsTool('coordinator', 'spawn_background_agent')).toBe(true)
expect(executionRoleAllowsTool('coordinator', 'send_agent_message')).toBe(true)
})
it('classifies delegated/background/pill surfaces as leaf, everything else coordinator', () => {
expect(executionRoleForSurface({ surfaceKind: 'delegated_agent' })).toBe('leaf')
expect(executionRoleForSurface({ surfaceKind: 'background_agent' })).toBe('leaf')
expect(executionRoleForSurface({ surfaceKind: 'floating_bar', externalRefKind: 'pill' })).toBe(
'leaf'
)
expect(executionRoleForSurface({ surfaceKind: 'floating_bar', externalRefKind: 'chat' })).toBe(
'coordinator'
)
expect(executionRoleForSurface({ surfaceKind: 'main_chat' })).toBe('coordinator')
})
})
describe('executionPolicy — provider boundaries', () => {
it('derives a local_user boundary for every local-user Windows adapter', () => {
expect(providerBoundaryForAdapter('acp')).toBe('local_user:acp')
expect(providerBoundaryForAdapter('openclaw')).toBe('local_user:openclaw')
expect(providerBoundaryForAdapter('hermes')).toBe('local_user:hermes')
expect(providerBoundaryForAdapter('codex')).toBe('local_user:codex')
})
it('pins the managed-cloud pi-mono adapter to the managed_cloud boundary', () => {
// PR-D registered pi-mono as a managed_cloud production adapter, so its
// production-ness + credential scope now flow through isProductionAdapterId
// (the MANAGED_CLOUD_ADAPTER_IDS special-case was deleted).
expect(providerBoundaryForAdapter('pi-mono')).toBe('managed_cloud')
})
it('maps a boundary back to a credential scope', () => {
expect(credentialScopeForBoundary('local_user:acp')).toBe('local_user')
expect(credentialScopeForBoundary('managed_cloud')).toBe('managed_cloud')
})
it('keeps a request within its pinned local boundary', () => {
expect(
resolveAdapterWithinBoundary({
providerBoundary: 'local_user:acp',
defaultAdapterId: 'acp',
requestedAdapterId: 'acp'
})
).toBe('acp')
expect(
resolveAdapterWithinBoundary({
providerBoundary: 'local_user:openclaw',
defaultAdapterId: 'openclaw',
requestedAdapterId: 'openclaw'
})
).toBe('openclaw')
})
it('rejects Local Claude unless the User Claude boundary is selected', () => {
expect(() =>
resolveAdapterWithinBoundary({
providerBoundary: 'local_user:openclaw',
defaultAdapterId: 'openclaw',
requestedAdapterId: 'acp'
})
).toThrow(/User Claude mode/)
})
it('rejects crossing from one pinned local provider to another', () => {
expect(() =>
resolveAdapterWithinBoundary({
providerBoundary: 'local_user:openclaw',
defaultAdapterId: 'openclaw',
requestedAdapterId: 'hermes'
})
).toThrow(/pinned to openclaw/)
})
it('rejects an unknown production adapter', () => {
expect(() =>
resolveAdapterWithinBoundary({
providerBoundary: 'local_user:acp',
defaultAdapterId: 'acp',
requestedAdapterId: 'nope'
})
).toThrow(/Unknown production adapter/)
})
it('resolves pi-mono within the managed_cloud boundary (no longer an unknown adapter)', () => {
// Before PR-D, resolveAdapterWithinBoundary threw "Unknown production adapter:
// pi-mono" because isProductionAdapterId('pi-mono') was false. The matrix entry
// makes the managed_cloud boundary fully reachable.
expect(
resolveAdapterWithinBoundary({
providerBoundary: 'managed_cloud',
defaultAdapterId: 'pi-mono',
requestedAdapterId: 'pi-mono'
})
).toBe('pi-mono')
})
it('honors the managed_cloud pin: a local adapter cannot run in the managed boundary', () => {
expect(() =>
resolveAdapterWithinBoundary({
providerBoundary: 'managed_cloud',
defaultAdapterId: 'pi-mono',
requestedAdapterId: 'openclaw'
})
).toThrow(/Managed Omi agents can only use Omi cloud routing/)
})
it('rejects rerouting a pinned local session to the managed pi-mono adapter', () => {
// Cross-boundary reroute stays rejected: a session pinned to local acp may not
// jump to the managed-cloud provider.
expect(() =>
resolveAdapterWithinBoundary({
providerBoundary: 'local_user:acp',
defaultAdapterId: 'acp',
requestedAdapterId: 'pi-mono'
})
).toThrow(/pinned to acp/)
})
it('lets a non-production (test) adapter keep only its own identity', () => {
expect(
resolveAdapterWithinBoundary({
providerBoundary: 'local_user:test-adapter',
defaultAdapterId: 'test-adapter',
requestedAdapterId: 'test-adapter'
})
).toBe('test-adapter')
expect(() =>
resolveAdapterWithinBoundary({
providerBoundary: 'local_user:test-adapter',
defaultAdapterId: 'test-adapter',
requestedAdapterId: 'acp'
})
).toThrow(/outside the owning execution boundary/)
})
})