unbound-cli 1.26.1 → 1.26.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LOCAL_DEV.md +1 -1
- package/README.md +6 -6
- package/package.json +1 -1
- package/src/commands/delivery.js +17 -9
- package/src/commands/policy.js +6 -22
- package/src/lib/pack-config-schema.js +2 -5
- package/src/lib/pack-schema.js +1 -2
- package/test/delivery.test.js +5 -2
- package/test/pack-plan.test.js +2 -1
- package/test/pack-schema.test.js +5 -1
- package/test/policy-security-guardrail-actions.test.js +74 -0
package/LOCAL_DEV.md
CHANGED
|
@@ -147,7 +147,7 @@ node src/index.js policy model create --name "Sonnet Only" --allowed claude-3-5-
|
|
|
147
147
|
|
|
148
148
|
# Security policies
|
|
149
149
|
node src/index.js policy security create --name "Block PII" --sub-type guardrails \
|
|
150
|
-
--guardrail PII:BLOCK --guardrail Secrets:
|
|
150
|
+
--guardrail PII:BLOCK --guardrail Secrets:AUDIT
|
|
151
151
|
node src/index.js policy security create --name "Route 429s" --sub-type error-code-routing \
|
|
152
152
|
--error-route 429:gpt-4:claude-3-5-sonnet
|
|
153
153
|
|
package/README.md
CHANGED
|
@@ -173,9 +173,9 @@ unbound policy cost list
|
|
|
173
173
|
Security policy examples:
|
|
174
174
|
|
|
175
175
|
```bash
|
|
176
|
-
# Block PII
|
|
176
|
+
# Block PII and audit secrets for the engg group
|
|
177
177
|
unbound policy security create --name "Block PII" --sub-type guardrails \
|
|
178
|
-
--guardrail PII:BLOCK --guardrail Secrets:
|
|
178
|
+
--guardrail PII:BLOCK --guardrail Secrets:AUDIT --group engg
|
|
179
179
|
|
|
180
180
|
# Default-route gpt-4 traffic to claude-3-5-sonnet
|
|
181
181
|
unbound policy security create --name "Prefer Sonnet" --sub-type default-routing \
|
|
@@ -339,11 +339,11 @@ Needs Admin or Analytics Viewer over the whole organization (a token needs `anal
|
|
|
339
339
|
| Command | Description |
|
|
340
340
|
|---------|-------------|
|
|
341
341
|
| `unbound delivery summary` | AI branches, PRs opened and merged, merge rate, AI spend, cost per PR and time to first PR |
|
|
342
|
-
| `unbound delivery branches` | AI branches with their PR, ticket, work group, users and cost (`--outcome`, `--ticket-status`, `--work-group`, `--search`, `--sort
|
|
342
|
+
| `unbound delivery branches` | AI branches with their PR, ticket, work group, users and cost (`--outcome`, `--ticket-status`, `--work-group`, `--search`, `--sort first-seen\|cost`) |
|
|
343
343
|
| `unbound delivery branch <id>` | One branch with its PR and ticket links, timeline and sessions |
|
|
344
|
-
| `unbound delivery users` | AI spend, PRs raised and merged per person (`--sort
|
|
344
|
+
| `unbound delivery users` | AI spend, PRs raised and merged per person (`--sort ai-spend`, `merge-rate-pct`, ...) |
|
|
345
345
|
| `unbound delivery teams` | The same per department, with active AI users and share of branches with a ticket |
|
|
346
|
-
| `unbound delivery spend --by outcome\|work-group` | AI spend by PR outcome, or by work group (`--pr-state all\|merged\|open\|
|
|
346
|
+
| `unbound delivery spend --by outcome\|work-group` | AI spend by PR outcome, or by work group (`--pr-state all\|merged\|open\|no-pr`) |
|
|
347
347
|
| `unbound delivery repos` | Repositories with AI work in the window, the values `--repo` takes |
|
|
348
348
|
|
|
349
349
|
Every command except `branch` takes `--time-window ONE_DAY|THREE_DAYS|SEVEN_DAYS|FOURTEEN_DAYS|THIRTY_DAYS` (default `THIRTY_DAYS`) or `--start/--end YYYY-MM-DD` (max 31 days, within the last 31 days). `summary`, `branches`, `users`, `teams` and `spend` also filter by `--user` (user IDs, not emails), `--team`, `--manager`, `--tool` and `--repo`. `--json` prints the raw response.
|
|
@@ -352,7 +352,7 @@ Every command except `branch` takes `--time-window ONE_DAY|THREE_DAYS|SEVEN_DAYS
|
|
|
352
352
|
unbound delivery summary --time-window SEVEN_DAYS
|
|
353
353
|
unbound delivery branches --outcome merged --json | jq '.results[] | {name, pr: .pr.number, cost}'
|
|
354
354
|
unbound delivery branch 4821
|
|
355
|
-
unbound delivery users --sort
|
|
355
|
+
unbound delivery users --sort merge-rate-pct --team Platform
|
|
356
356
|
unbound delivery spend --by work-group --pr-state merged
|
|
357
357
|
```
|
|
358
358
|
|
package/package.json
CHANGED
package/src/commands/delivery.js
CHANGED
|
@@ -88,11 +88,19 @@ function normalizeChoice(value) {
|
|
|
88
88
|
return String(value).trim().toLowerCase().replace(/-/g, '_');
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
function dashed(choice) {
|
|
92
|
+
return String(choice).replace(/_/g, '-');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function listChoices(choices, separator = ', ') {
|
|
96
|
+
return choices.map(dashed).join(separator);
|
|
97
|
+
}
|
|
98
|
+
|
|
91
99
|
function parseChoice(flag, value, choices) {
|
|
92
100
|
if (value === undefined) return undefined;
|
|
93
101
|
const choice = normalizeChoice(value);
|
|
94
102
|
if (!choices.includes(choice)) {
|
|
95
|
-
throw new Error(`Invalid ${flag} "${value}". Must be one of: ${choices
|
|
103
|
+
throw new Error(`Invalid ${flag} "${value}". Must be one of: ${listChoices(choices)}.`);
|
|
96
104
|
}
|
|
97
105
|
return choice;
|
|
98
106
|
}
|
|
@@ -380,7 +388,7 @@ function peopleColumn(key) {
|
|
|
380
388
|
function warnSortFallback(data, requestedSort) {
|
|
381
389
|
if (!requestedSort || !data.sort_by || data.sort_by === requestedSort) return;
|
|
382
390
|
const reason = data.github ? 'is shown only when GitHub is not connected' : 'needs GitHub connected';
|
|
383
|
-
output.warn(`Sorted by ${safe(data.sort_by)}: ${requestedSort} ${reason}.`);
|
|
391
|
+
output.warn(`Sorted by ${dashed(safe(data.sort_by))}: ${dashed(requestedSort)} ${reason}.`);
|
|
384
392
|
}
|
|
385
393
|
|
|
386
394
|
async function listPeople(noun, opts) {
|
|
@@ -471,10 +479,10 @@ function addFilterOptions(command) {
|
|
|
471
479
|
|
|
472
480
|
function addTableOptions(command, sortChoices, defaultSort) {
|
|
473
481
|
return command
|
|
474
|
-
.option('--ticket-status <statuses>', `Ticket status, comma-separated: ${TICKET_STATUSES
|
|
475
|
-
.option('--work-group <groups>', `Work group, comma-separated: ${WORK_GROUPS
|
|
482
|
+
.option('--ticket-status <statuses>', `Ticket status, comma-separated: ${listChoices(TICKET_STATUSES)}`)
|
|
483
|
+
.option('--work-group <groups>', `Work group, comma-separated: ${listChoices(WORK_GROUPS)}`)
|
|
476
484
|
.option('--search <text>', 'Search text')
|
|
477
|
-
.option('--sort <column>', `${sortChoices
|
|
485
|
+
.option('--sort <column>', `${listChoices(sortChoices, ' | ')} (default ${dashed(defaultSort)})`)
|
|
478
486
|
.option('--order <order>', 'desc | asc (default desc)')
|
|
479
487
|
.option('--page <n>', 'Page number')
|
|
480
488
|
.option('--page-size <n>', `Rows per page, up to ${MAX_PAGE_SIZE} (default 10)`)
|
|
@@ -492,7 +500,7 @@ Examples:
|
|
|
492
500
|
$ unbound delivery branches --outcome merged --sort cost
|
|
493
501
|
$ unbound delivery branches --outcome merged --json | jq '.results[] | {name, pr: .pr.number, cost}'
|
|
494
502
|
$ unbound delivery branch 4821
|
|
495
|
-
$ unbound delivery users --sort
|
|
503
|
+
$ unbound delivery users --sort merge-rate-pct --team Platform
|
|
496
504
|
$ unbound delivery spend --by work-group --pr-state merged
|
|
497
505
|
|
|
498
506
|
A PR appears only when an agent's own tool call created it.
|
|
@@ -511,10 +519,10 @@ Admin or Analytics Viewer (whole organization).
|
|
|
511
519
|
addTableOptions(addFilterOptions(delivery
|
|
512
520
|
.command('branches')
|
|
513
521
|
.description('List AI branches created in the window.')
|
|
514
|
-
.option('--outcome <outcome>', `PR outcome: ${OUTCOMES
|
|
522
|
+
.option('--outcome <outcome>', `PR outcome: ${listChoices(OUTCOMES)}`)), BRANCH_SORTS, 'first_seen')
|
|
515
523
|
.addHelpText('after', `${WINDOW_HELP}${FILTER_HELP}
|
|
516
524
|
Examples:
|
|
517
|
-
$ unbound delivery branches --outcome
|
|
525
|
+
$ unbound delivery branches --outcome no-pr --sort cost
|
|
518
526
|
$ unbound delivery branches --ticket-status done --work-group fix
|
|
519
527
|
$ unbound delivery branches --repo acme/web --page 2 --json
|
|
520
528
|
|
|
@@ -545,7 +553,7 @@ With --work-group, branches are windowed by PR time (merged, else opened) instea
|
|
|
545
553
|
.command('spend')
|
|
546
554
|
.description('Show AI spend by PR outcome or by work group.')
|
|
547
555
|
.option('--by <dimension>', 'outcome | work-group (default outcome)')
|
|
548
|
-
.option('--pr-state <state>', `With --by work-group: ${PR_STATES
|
|
556
|
+
.option('--pr-state <state>', `With --by work-group: ${listChoices(PR_STATES)} (default all)`)
|
|
549
557
|
.option('--json', 'Output the raw JSON response'))
|
|
550
558
|
.addHelpText('after', `${WINDOW_HELP}${FILTER_HELP}
|
|
551
559
|
Examples:
|
package/src/commands/policy.js
CHANGED
|
@@ -15,7 +15,7 @@ const DOCS_SECURITY = 'https://docs.getunbound.ai/policies/security-policies';
|
|
|
15
15
|
const DOCS_TOOL = 'https://docs.getunbound.ai/policies/tool-policies';
|
|
16
16
|
|
|
17
17
|
const POLICY_TYPES = ['SECURITY', 'MODEL', 'COST'];
|
|
18
|
-
const GUARDRAIL_ACTIONS = ['BLOCK', '
|
|
18
|
+
const GUARDRAIL_ACTIONS = ['BLOCK', 'AUDIT'];
|
|
19
19
|
const TOOL_ACTIONS = ['AUDIT', 'BLOCK', 'WARN', 'REQUIRE_SLACK_APPROVAL'];
|
|
20
20
|
const SECURITY_SUB_TYPES = ['guardrails', 'default_routing', 'error_code_routing'];
|
|
21
21
|
const MCP_ACTION_TYPES = ['read', 'write', 'destructive'];
|
|
@@ -229,7 +229,7 @@ function parseJsonOrThrow(str, flagName = '--config') {
|
|
|
229
229
|
* {guardrail_id, action, threshold, route_model_id, entities, enabled} shape
|
|
230
230
|
* the backend expects. Resolves the name and validates the action.
|
|
231
231
|
*/
|
|
232
|
-
function parseGuardrailSpec(spec, allGuardrails
|
|
232
|
+
function parseGuardrailSpec(spec, allGuardrails) {
|
|
233
233
|
const parts = spec.split(':');
|
|
234
234
|
if (parts.length < 2 || parts.length > 3) {
|
|
235
235
|
throw new Error(`Invalid --guardrail spec "${spec}". Expected format: <name>:<action>[:<threshold>]`);
|
|
@@ -254,10 +254,6 @@ function parseGuardrailSpec(spec, allGuardrails, routeModelId) {
|
|
|
254
254
|
);
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
if (action === 'ROUTE' && !routeModelId) {
|
|
258
|
-
throw new Error(`Guardrail "${guardrail.name}" uses ROUTE but --route-model was not provided.`);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
257
|
const threshold = thresholdRaw != null ? Number(thresholdRaw) : 1;
|
|
262
258
|
if (Number.isNaN(threshold) || threshold < 1 || threshold > 100) {
|
|
263
259
|
throw new Error(`Invalid threshold "${thresholdRaw}" for guardrail "${guardrail.name}". Must be 1-100.`);
|
|
@@ -268,7 +264,7 @@ function parseGuardrailSpec(spec, allGuardrails, routeModelId) {
|
|
|
268
264
|
enabled: true,
|
|
269
265
|
action,
|
|
270
266
|
threshold,
|
|
271
|
-
route_model_id:
|
|
267
|
+
route_model_id: null,
|
|
272
268
|
entities: (guardrail.entities || []).map((e) => ({ entity_id: e.id, enabled: true })),
|
|
273
269
|
};
|
|
274
270
|
}
|
|
@@ -1118,7 +1114,7 @@ function registerSecurity(policy) {
|
|
|
1118
1114
|
.description('Manage Security policies. Guardrails for PII/secrets and model routing rules.')
|
|
1119
1115
|
.addHelpText('after', `
|
|
1120
1116
|
Security policies come in three sub-types:
|
|
1121
|
-
guardrails Detect
|
|
1117
|
+
guardrails Detect sensitive content (PII, secrets, etc.) and block or audit it
|
|
1122
1118
|
default-routing Route one model's traffic to another
|
|
1123
1119
|
error-code-routing Re-route on specific HTTP error codes (e.g. 429 → fallback model)
|
|
1124
1120
|
|
|
@@ -1167,7 +1163,6 @@ Subcommands:
|
|
|
1167
1163
|
.requiredOption('--name <name>', 'Policy name (required)')
|
|
1168
1164
|
.option('--sub-type <type>', 'Sub-type: guardrails | default-routing | error-code-routing')
|
|
1169
1165
|
.option('--guardrail <spec>', 'Guardrail spec: <name>:<action>[:<threshold>]. Repeatable. For guardrails sub-type.', (val, prev = []) => [...prev, val])
|
|
1170
|
-
.option('--route-model <name>', 'Target model name for guardrail ROUTE actions')
|
|
1171
1166
|
.option('--route <spec>', 'Default routing rule: <source-model>:<target-model>. Repeatable. For default-routing sub-type.', (val, prev = []) => [...prev, val])
|
|
1172
1167
|
.option('--error-route <spec>', 'Error routing rule: <error-code>:<source-model>:<target-model>. Repeatable. For error-code-routing sub-type.', (val, prev = []) => [...prev, val])
|
|
1173
1168
|
.option('--group <names|ids>', 'Comma-separated user group names or IDs to scope this policy to')
|
|
@@ -1179,10 +1174,7 @@ Subcommands:
|
|
|
1179
1174
|
Examples:
|
|
1180
1175
|
Guardrails sub-type:
|
|
1181
1176
|
$ unbound policy security create --name "Block PII" --sub-type guardrails \\
|
|
1182
|
-
--guardrail PII:BLOCK --guardrail Secrets:
|
|
1183
|
-
|
|
1184
|
-
$ unbound policy security create --name "Route PII To Safe Model" --sub-type guardrails \\
|
|
1185
|
-
--guardrail PII:ROUTE --route-model claude-3-5-sonnet
|
|
1177
|
+
--guardrail PII:BLOCK --guardrail Secrets:AUDIT --group engg
|
|
1186
1178
|
|
|
1187
1179
|
Default routing sub-type:
|
|
1188
1180
|
$ unbound policy security create --name "Prefer Sonnet" --sub-type default-routing \\
|
|
@@ -1220,15 +1212,7 @@ Learn more: ${DOCS_SECURITY}
|
|
|
1220
1212
|
}
|
|
1221
1213
|
const formData = await loadFormData();
|
|
1222
1214
|
const guardrails = formData.guardrails || [];
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
let routeModelId = null;
|
|
1226
|
-
if (opts.routeModel) {
|
|
1227
|
-
const m = resolveFull(models, opts.routeModel, { kind: 'model' })[0];
|
|
1228
|
-
routeModelId = m.id;
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
configObj.guardrails = opts.guardrail.map((spec) => parseGuardrailSpec(spec, guardrails, routeModelId));
|
|
1215
|
+
configObj.guardrails = opts.guardrail.map((spec) => parseGuardrailSpec(spec, guardrails));
|
|
1232
1216
|
} else if (subType === 'default_routing') {
|
|
1233
1217
|
if (!opts.route || opts.route.length === 0) {
|
|
1234
1218
|
throw new Error('At least one --route is required for sub-type default-routing.');
|
|
@@ -85,8 +85,8 @@ function validateSecurityConfig(config, file) {
|
|
|
85
85
|
if (item.enabled != null && typeof item.enabled !== 'boolean') {
|
|
86
86
|
fail(`${path}.enabled`, 'must be a boolean');
|
|
87
87
|
}
|
|
88
|
-
if (item.action != null && !['AUDIT', 'BLOCK'
|
|
89
|
-
fail(`${path}.action`, 'must be one of: AUDIT, BLOCK
|
|
88
|
+
if (item.action != null && !['AUDIT', 'BLOCK'].includes(item.action)) {
|
|
89
|
+
fail(`${path}.action`, 'must be one of: AUDIT, BLOCK');
|
|
90
90
|
}
|
|
91
91
|
if (item.threshold != null && (!Number.isInteger(item.threshold) || item.threshold < 1 || item.threshold > 100)) {
|
|
92
92
|
fail(`${path}.threshold`, 'must be an integer from 1 to 100');
|
|
@@ -94,9 +94,6 @@ function validateSecurityConfig(config, file) {
|
|
|
94
94
|
if (item.route_model_id !== undefined && item.route_model_id !== null && item.route_model_id !== '' && !isPositiveInteger(item.route_model_id)) {
|
|
95
95
|
fail(`${path}.route_model_id`, 'must be a positive integer ID');
|
|
96
96
|
}
|
|
97
|
-
if (item.action === 'ROUTE' && !item.route_model_id) {
|
|
98
|
-
fail(`${path}.route_model_id`, 'is required when action is ROUTE');
|
|
99
|
-
}
|
|
100
97
|
if (item.priority != null && !Number.isInteger(item.priority)) {
|
|
101
98
|
fail(`${path}.priority`, 'must be an integer');
|
|
102
99
|
}
|
package/src/lib/pack-schema.js
CHANGED
|
@@ -21,7 +21,7 @@ const POLICY_KINDS = ['tool', 'security', 'model', 'cost'];
|
|
|
21
21
|
const GENERIC_KINDS = ['security', 'model', 'cost'];
|
|
22
22
|
const TOOL_TYPES = ['TERMINAL_COMMAND', 'MCP_TOOL'];
|
|
23
23
|
const TOOL_ACTIONS = ['AUDIT', 'BLOCK', 'WARN', 'REQUIRE_SLACK_APPROVAL'];
|
|
24
|
-
const GUARDRAIL_ACTIONS = ['BLOCK', '
|
|
24
|
+
const GUARDRAIL_ACTIONS = ['BLOCK', 'AUDIT'];
|
|
25
25
|
const MCP_ACTION_TYPES = ['read', 'write', 'destructive'];
|
|
26
26
|
|
|
27
27
|
const SLUG_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
@@ -203,7 +203,6 @@ function validateGuardrails(guardrails, where, file) {
|
|
|
203
203
|
if (g.entities !== undefined && !isStringArray(g.entities)) throw new PackError(`${gw}.entities must be a list of entity names`, { file });
|
|
204
204
|
if (g.routeModel !== undefined && typeof g.routeModel !== 'string') throw new PackError(`${gw}.routeModel must be a model name`, { file });
|
|
205
205
|
if (g.enabled !== undefined && typeof g.enabled !== 'boolean') throw new PackError(`${gw}.enabled must be true or false`, { file });
|
|
206
|
-
if (g.action === 'ROUTE' && !g.routeModel) throw new PackError(`${gw}.routeModel is required when action is ROUTE`, { file });
|
|
207
206
|
});
|
|
208
207
|
}
|
|
209
208
|
|
package/test/delivery.test.js
CHANGED
|
@@ -381,7 +381,7 @@ test('branch detail says when only the newest 100 sessions are shown', async ()
|
|
|
381
381
|
|
|
382
382
|
test('users and teams send sort, page and ticket filters and print the columns the server lists', async () => {
|
|
383
383
|
await withBackend(async ({ seen, run }) => {
|
|
384
|
-
const users = await run(['delivery', 'users', '--sort', '
|
|
384
|
+
const users = await run(['delivery', 'users', '--sort', 'merge-rate-pct', '--page', '2', '--ticket-status', 'todo',
|
|
385
385
|
'--work-group', 'fix', '--team', 'Platform']);
|
|
386
386
|
assert.equal(users.code, 0, users.stderr);
|
|
387
387
|
assert.equal(seen[0].path, `${BASE}/users/`);
|
|
@@ -434,7 +434,7 @@ test('users and teams warn when the server sorted by another column', async () =
|
|
|
434
434
|
await withBackend(async ({ run }) => {
|
|
435
435
|
const r = await run(['delivery', 'teams', '--sort', 'merge_rate_pct']);
|
|
436
436
|
assert.equal(r.code, 0, r.stderr);
|
|
437
|
-
assert.match(r.stderr, /Sorted by
|
|
437
|
+
assert.match(r.stderr, /Sorted by ai-spend: merge-rate-pct needs GitHub connected\./);
|
|
438
438
|
const asked = await run(['delivery', 'teams', '--sort', 'ai_spend']);
|
|
439
439
|
assert.doesNotMatch(asked.stderr, /Sorted by/);
|
|
440
440
|
const unsorted = await run(['delivery', 'teams']);
|
|
@@ -510,6 +510,9 @@ test('bad input fails before any request is sent', async () => {
|
|
|
510
510
|
[['delivery', 'users', '--sort', 'name'], /Invalid --sort "name"/],
|
|
511
511
|
[['delivery', 'users', '--sort', 'active_ai_users'], /Invalid --sort "active_ai_users"/],
|
|
512
512
|
[['delivery', 'teams', '--sort', 'last_active'], /Invalid --sort "last_active"/],
|
|
513
|
+
[['delivery', 'teams', '--sort', 'last-active'],
|
|
514
|
+
/Must be one of: active-ai-users, ai-branches, prs-raised, prs-merged, merge-rate-pct, ai-spend, cost-per-merged-pr,/],
|
|
515
|
+
[['delivery', 'branches', '--outcome', 'open'], /Must be one of: merged, in-review, closed, no-pr, pr-raised\./],
|
|
513
516
|
[['delivery', 'teams', '--order', 'up'], /Invalid --order "up"/],
|
|
514
517
|
[['delivery', 'branch', 'abc'], /Invalid branch ID "abc"/],
|
|
515
518
|
[['delivery', 'spend', '--by', 'tool'], /Invalid --by "tool"/],
|
package/test/pack-plan.test.js
CHANGED
|
@@ -54,7 +54,8 @@ test('toDesired: builds write bodies with resolved ids', () => {
|
|
|
54
54
|
test('toDesired: unresolved names fail before any write', () => {
|
|
55
55
|
assert.throws(() => plan.toDesired(pack([{ ...TERMINAL, scope: { userGroups: ['Nope'] } }]), REF), /no user group named "Nope"/);
|
|
56
56
|
assert.throws(() => plan.toDesired(pack([{ ...SECURITY, guardrails: [{ name: 'Secrets', action: 'BLOCK' }] }]), REF), /no guardrail named "Secrets"/);
|
|
57
|
-
|
|
57
|
+
const blockOnly = { ...REF, guardrails: [{ ...REF.guardrails[0], supported_actions: ['BLOCK'] }] };
|
|
58
|
+
assert.throws(() => plan.toDesired(pack([{ ...SECURITY, guardrails: [{ name: 'PII', action: 'AUDIT' }] }]), blockOnly), /does not support AUDIT/);
|
|
58
59
|
assert.throws(() => plan.toDesired(pack([{ ...MODEL, models: { allowed: ['llama'] } }]), REF), /no model named "llama"/);
|
|
59
60
|
assert.throws(() => plan.toDesired(pack([{ ...COST, scope: { toolTypes: ['vim'] } }]), REF), /unknown tool type vim/);
|
|
60
61
|
assert.throws(() => plan.toDesired(pack([{ ...SECURITY, labels: ['nope'] }]), REF), /no label named "nope"/);
|
package/test/pack-schema.test.js
CHANGED
|
@@ -109,7 +109,11 @@ test('validatePack: tool policy rules', () => {
|
|
|
109
109
|
|
|
110
110
|
test('validatePack: generic policy rules', () => {
|
|
111
111
|
assert.throws(() => load(BASE.replace(' threshold: 5', ' threshold: 500')), /threshold must be an integer from 1 to 100/);
|
|
112
|
-
|
|
112
|
+
for (const action of ['REDACT', 'ROUTE']) {
|
|
113
|
+
assert.throws(() => load(BASE.replace(' action: BLOCK', ` action: ${action}`)), /action must be one of: BLOCK, AUDIT/);
|
|
114
|
+
const rawConfig = BASE.replace(' guardrails:\n - name: PII\n action: BLOCK\n threshold: 5', ` config:\n guardrails:\n - guardrail_id: 1\n action: ${action}`);
|
|
115
|
+
assert.throws(() => load(rawConfig), /action: must be one of: AUDIT, BLOCK$/);
|
|
116
|
+
}
|
|
113
117
|
assert.throws(() => load(BASE.replace(' config:\n monthly_budget: 5000', ' config: {}')), /cost policy needs a config/);
|
|
114
118
|
assert.throws(() => load(BASE.replace(' priority: 10', ' priority: 10\n config:\n guardrails: []')), /either guardrails or config.guardrails/);
|
|
115
119
|
const modelBad = BASE.replace(' kind: cost\n enabled: false\n config:\n monthly_budget: 5000', ' kind: model\n models:\n allowed: [a]\n allowAll: true');
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const { Command } = require('commander');
|
|
4
|
+
const config = require('../src/config');
|
|
5
|
+
const api = require('../src/api');
|
|
6
|
+
const output = require('../src/output');
|
|
7
|
+
const { register } = require('../src/commands/policy');
|
|
8
|
+
|
|
9
|
+
// Data policy guardrails take BLOCK or AUDIT, as the backend's form data lists them.
|
|
10
|
+
|
|
11
|
+
const ALL = ['BLOCK', 'REDACT', 'ROUTE', 'AUDIT'];
|
|
12
|
+
const FORM_DATA = {
|
|
13
|
+
guardrails: [
|
|
14
|
+
{ id: 1, name: 'PII', supported_actions: ALL, entities: [] },
|
|
15
|
+
{ id: 2, name: 'Secrets', supported_actions: ALL, entities: [] },
|
|
16
|
+
],
|
|
17
|
+
ai_models: [],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function stub() {
|
|
21
|
+
const orig = {
|
|
22
|
+
isLoggedIn: config.isLoggedIn, get: api.get, post: api.post,
|
|
23
|
+
success: output.success, error: output.error, json: output.json,
|
|
24
|
+
exitCode: process.exitCode,
|
|
25
|
+
};
|
|
26
|
+
const seen = { postBody: null, errors: [] };
|
|
27
|
+
config.isLoggedIn = () => true;
|
|
28
|
+
api.get = async () => FORM_DATA;
|
|
29
|
+
api.post = async (_p, { body }) => { seen.postBody = body; return { policy: { id: 9, ...body } }; };
|
|
30
|
+
output.success = () => {};
|
|
31
|
+
output.error = (m) => { seen.errors.push(m); };
|
|
32
|
+
output.json = () => {};
|
|
33
|
+
return {
|
|
34
|
+
seen,
|
|
35
|
+
restore() {
|
|
36
|
+
config.isLoggedIn = orig.isLoggedIn; api.get = orig.get; api.post = orig.post;
|
|
37
|
+
output.success = orig.success; output.error = orig.error; output.json = orig.json;
|
|
38
|
+
process.exitCode = orig.exitCode;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function create(...guardrails) {
|
|
44
|
+
const program = new Command();
|
|
45
|
+
register(program);
|
|
46
|
+
const flags = guardrails.flatMap((g) => ['--guardrail', g]);
|
|
47
|
+
await program.parseAsync(['node', 'x', 'policy', 'security', 'create', '--name', 'P', '--sub-type', 'guardrails', ...flags, '--json']);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (const action of ['REDACT', 'ROUTE']) {
|
|
51
|
+
test(`a ${action} guardrail is refused before anything is sent`, async () => {
|
|
52
|
+
const { seen, restore } = stub();
|
|
53
|
+
try {
|
|
54
|
+
await create('PII:BLOCK', `Secrets:${action}`);
|
|
55
|
+
assert.equal(seen.postBody, null);
|
|
56
|
+
assert.equal(seen.errors.length, 1);
|
|
57
|
+
assert.match(seen.errors[0], new RegExp(`Invalid guardrail action "${action}"\\. Must be one of: BLOCK, AUDIT`));
|
|
58
|
+
assert.equal(process.exitCode, 1);
|
|
59
|
+
} finally {
|
|
60
|
+
restore();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
test('the help example, BLOCK and AUDIT, is sent as given', async () => {
|
|
66
|
+
const { seen, restore } = stub();
|
|
67
|
+
try {
|
|
68
|
+
await create('PII:BLOCK', 'Secrets:AUDIT');
|
|
69
|
+
assert.deepEqual(seen.errors, []);
|
|
70
|
+
assert.deepEqual(seen.postBody.config.guardrails.map((g) => [g.guardrail_id, g.action]), [[1, 'BLOCK'], [2, 'AUDIT']]);
|
|
71
|
+
} finally {
|
|
72
|
+
restore();
|
|
73
|
+
}
|
|
74
|
+
});
|