Commit 905b022
authored
cli: add custom chrome policy flags to browser and pool commands (#180)
## Summary
Adds CLI support for setting a custom Chrome enterprise policy (the
API's `chrome_policy` field, already supported by the Go SDK) on three
commands:
- `kernel browsers create`
- `kernel browser-pools create`
- `kernel browser-pools update`
Each gains two mutually-exclusive flags:
- `--chrome-policy '<json>'` — an inline JSON object
- `--chrome-policy-file <path>` — read the object from a file (`-` reads
stdin)
This mirrors the existing `--payload` / `--payload-file` and `--data` /
`--data-file` conventions.
```bash
kernel browsers create --chrome-policy '{"BookmarkBarEnabled": false}'
kernel browsers create --chrome-policy-file policy.json
cat policy.json | kernel browser-pools update my-pool --chrome-policy-file -
```
## Design notes
- A shared `parseChromePolicy` helper parses into `map[string]any`, so
non-object JSON (arrays, scalars, `null`) is rejected with a clear error
before any request is sent.
- `chrome_policy` uses `omitzero`, which only drops a **nil** map — a
non-nil empty `{}` would serialize as `"chrome_policy":{}`. Assignment
is therefore guarded by `len > 0`, so an empty object is treated as
"unset".
- On `browser-pools update`, an empty `{}` cannot clear an existing
policy (omitzero strips it before it reaches the server). Rather than
silently no-op, this surfaces a warning in human output (suppressed
under `-o json` to keep stdout valid).
- Kernel-managed policies (extensions, proxy, automation) are enforced
**server-side**. The CLI forwards the object verbatim and surfaces the
API's error, rather than duplicating a blocklist that would drift.
## Scope
- `browsers update` and `invoke` are intentionally excluded: their SDK
params structs (`BrowserUpdateParams`, `InvocationNewParams`) carry no
`chrome_policy` field, so there's nothing to wire until the SDK is
regenerated.
- The policy echoes back via `--output json` with no printer changes
(response structs already carry the field).
## Test plan
- [x] Unit tests for all three commands: inline policy applied, empty
`{}` omitted (asserted at both the Go field and the serialized JSON),
invalid JSON / `null` rejected, parser covers file + stdin + whitespace
+ missing-file, and the pool-lease conflict contract is locked
(`--chrome-policy` stays out of the allowed-flag set).
- [x] `make test` (go vet + go test ./...) passes; gofmt clean.
- [x] E2E against a live environment via the built binary:
inline/file/stdin create echo the policy; pool create + get persist it;
pool update replaces it and an empty `{}` no-ops without clearing;
invalid/null/mutual-exclusion exit non-zero before any API call; and the
server correctly rejects `ProxyMode` / `ExtensionInstallForcelist` with
the CLI surfacing the error.
## Note (pre-existing, unrelated)
When a browser-config flag is combined with `--pool-id`/`--pool-name`,
the existing conflict-confirmation prompt
(`pterm.DefaultInteractiveConfirm`) does not treat EOF / non-TTY stdin
as "no", so it blocks in a non-interactive pipeline. This predates this
change and affects all config flags equally; flagging it as a possible
follow-up.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> CLI-only feature forwarding JSON to existing API fields; validation is
local and server enforces blocked policies. No auth or data-path
changes.
>
> **Overview**
> Adds **`--chrome-policy`** and **`--chrome-policy-file`** (mutually
exclusive, `-` for stdin) to `kernel browsers create` and `kernel
browser-pools create` / `update`, wiring the API’s `chrome_policy` field
through a shared **`parseChromePolicy`** helper.
>
> Policies are only sent when the parsed object is non-empty (`len >
0`), so `{}` is not serialized on create. On **pool update**, passing
`{}` does not clear an existing policy; the CLI warns in human output
and stays silent with `-o json`. **`poolLeaseAllowedFlags`** is
extracted so `--chrome-policy` is **not** treated as allowed alongside
`--pool-id`/`--pool-name`, surfacing the existing pool-lease conflict
warning instead of ignoring the flag.
>
> README documents flags, examples, and the pool-update clearing
limitation. Unit tests cover parsing, SDK params, JSON omission,
warnings, and pool-lease behavior.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
6a470a3. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Co-authored-by: rgarcia <72655+rgarcia@users.noreply.github.com>1 parent 7b35b0e commit 905b022
5 files changed
Lines changed: 380 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
| 224 | + | |
223 | 225 | | |
224 | 226 | | |
225 | 227 | | |
| |||
258 | 260 | | |
259 | 261 | | |
260 | 262 | | |
| 263 | + | |
261 | 264 | | |
262 | 265 | | |
263 | 266 | | |
264 | 267 | | |
265 | | - | |
| 268 | + | |
266 | 269 | | |
267 | 270 | | |
268 | 271 | | |
| |||
657 | 660 | | |
658 | 661 | | |
659 | 662 | | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
660 | 667 | | |
661 | 668 | | |
662 | 669 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
| |||
166 | 168 | | |
167 | 169 | | |
168 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
169 | 179 | | |
170 | 180 | | |
171 | 181 | | |
| |||
245 | 255 | | |
246 | 256 | | |
247 | 257 | | |
| 258 | + | |
| 259 | + | |
248 | 260 | | |
249 | 261 | | |
250 | 262 | | |
| |||
316 | 328 | | |
317 | 329 | | |
318 | 330 | | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
319 | 344 | | |
320 | 345 | | |
321 | 346 | | |
| |||
541 | 566 | | |
542 | 567 | | |
543 | 568 | | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
544 | 572 | | |
545 | 573 | | |
546 | 574 | | |
| |||
559 | 587 | | |
560 | 588 | | |
561 | 589 | | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
562 | 593 | | |
563 | 594 | | |
564 | 595 | | |
| |||
615 | 646 | | |
616 | 647 | | |
617 | 648 | | |
| 649 | + | |
| 650 | + | |
618 | 651 | | |
619 | 652 | | |
620 | 653 | | |
| |||
632 | 665 | | |
633 | 666 | | |
634 | 667 | | |
| 668 | + | |
| 669 | + | |
635 | 670 | | |
636 | 671 | | |
637 | 672 | | |
| |||
664 | 699 | | |
665 | 700 | | |
666 | 701 | | |
| 702 | + | |
| 703 | + | |
667 | 704 | | |
668 | 705 | | |
669 | 706 | | |
| |||
684 | 721 | | |
685 | 722 | | |
686 | 723 | | |
| 724 | + | |
| 725 | + | |
687 | 726 | | |
688 | 727 | | |
689 | 728 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
| |||
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
35 | 43 | | |
36 | 44 | | |
37 | 45 | | |
| |||
128 | 136 | | |
129 | 137 | | |
130 | 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 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
0 commit comments