GeezerVison is showing github.com — fix: preserve network approval for quoted package-manager options · Twigpine/zero@e212793
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: internal/sandbox/risk.go +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,11 @@ import ( | 9 | 9 | "strings" | 10 | 10 | ) | 11 | 11 |
| | 12 | +// optionWordPattern keeps quoted and escaped fragments together, including | | 13 | +// when a quoted value is attached to its option with "=". Backslashes can also | | 14 | +// be literal in Windows paths, so the fallback accepts either reading. | | 15 | +const optionWordPattern = `(?:\\[^\r\n]|[^\s"';&|()<>]|"(?:\\[^\r\n]|[^"\r\n])*"|'[^'\r\n]*')+` | | 16 | + | 12 | 17 | // leadingOptionsPattern spans the global options a package manager accepts | 13 | 18 | // before its subcommand, including the word an option consumes as its value: | 14 | 19 | // `npm --prefix ./web run dev` and `pnpm -C ./web run dev` are documented usage, | @@ -19,7 +24,7 @@ import ( | 19 | 24 | // direction this fallback is already documented to favour: it runs only after | 20 | 25 | // the command was declared too complex to parse, where catching an obvious | 21 | 26 | // network program matters more than proving exact shell syntax. | 22 | | -const leadingOptionsPattern = `(\s+-{1,2}\S+(\s+\S+)?)*` | | 27 | +const leadingOptionsPattern = `(?:\s+-{1,2}` + optionWordPattern + `(?:\s+` + optionWordPattern + `)?)*` | 23 | 28 |
| 24 | 29 | var ( | 25 | 30 | // destructiveCommandPattern matches the highest-risk shell forms: | |
Collapse file Copy file name to clipboardExpand all lines: internal/sandbox/unparseable_network_superset_test.go +38Lines changed: 38 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -172,3 +172,41 @@ func TestUnparseableFallbackCoversEveryPythonLauncher(t *testing.T) { | 172 | 172 | }) | 173 | 173 | } | 174 | 174 | } | | 175 | + | | 176 | +func TestPackageManagerOptionsPreserveNetworkApproval(t *testing.T) { | | 177 | + engine := NewEngine(EngineOptions{Policy: Policy{Mode: ModeEnforce, Network: NetworkDeny}}) | | 178 | + for _, testCase := range []struct { | | 179 | + name string | | 180 | + command string | | 181 | + wantNetwork bool | | 182 | + }{ | | 183 | + {"double quoted fetch", `npm --prefix "./web app" ci`, true}, | | 184 | + {"quoted Windows path", `npm --prefix "C:\work\web app" ci`, true}, | | 185 | + {"single quoted fetch", `npm --prefix './web app' ci`, true}, | | 186 | + {"escaped space", `npm --prefix ./web\ app ci`, true}, | | 187 | + {"attached quoted value", `npm --prefix="./web app folder" ci`, true}, | | 188 | + {"quoted value before serving", `pnpm --silent -C "./web app" run dev`, true}, | | 189 | + {"valueless flag", `npm --silent ci`, true}, | | 190 | + {"local version check", `npm --prefix "./web app" --version`, false}, | | 191 | + } { | | 192 | + t.Run(testCase.name, func(t *testing.T) { | | 193 | + unparseable := `if "%OS%"=="Windows_NT" (` + testCase.command + ") else (true)" | | 194 | + if AnalyzeCommand(testCase.command).TooComplex || !AnalyzeCommand(unparseable).TooComplex { | | 195 | + t.Fatal("expected the standalone command to parse and the conditional to use the fallback") | | 196 | + } | | 197 | + for _, command := range []string{testCase.command, unparseable} { | | 198 | + decision := engine.Evaluate(t.Context(), Request{ | | 199 | + ToolName: "bash", | | 200 | + SideEffect: SideEffectShell, | | 201 | + PermissionGranted: true, | | 202 | + Args: map[string]any{"command": command}, | | 203 | + }) | | 204 | + network := HasRiskCategory(decision.Risk, "network") | | 205 | + prompt := decision.Action == ActionPrompt && decision.Reason == ReasonNetworkBlocked | | 206 | + if network != testCase.wantNetwork || prompt != testCase.wantNetwork { | | 207 | + t.Errorf("%q: network=%v, decision=%s (%s), want network approval=%v", command, network, decision.Action, decision.Reason, testCase.wantNetwork) | | 208 | + } | | 209 | + } | | 210 | + }) | | 211 | + } | | 212 | +} |
Collapse file Copy file name to clipboardExpand all lines: internal/tui/permission_mode_offer_test.go +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -245,6 +245,7 @@ func TestConfirmOnlyCommitsAnOfferTheFooterShowed(t *testing.T) { | 245 | 245 | // ctrl+g cannot. Wider and pet-free layouts are the controls, so the rule | 246 | 246 | // cannot pass by refusing confirmation everywhere. | 247 | 247 | func TestOfferConfirmsOnlyWhereTheFooterShowsItsKey(t *testing.T) { | | 248 | + chipWidth := ansi.StringWidth(" ● " + unsafeOfferLabel) | 248 | 249 | for _, testCase := range []struct { | 249 | 250 | name string | 250 | 251 | width int | @@ -254,6 +255,8 @@ func TestOfferConfirmsOnlyWhereTheFooterShowsItsKey(t *testing.T) { | 254 | 255 | {"24 columns with a docked pet", 24, true, false}, | 255 | 256 | {"30 columns with a docked pet", 30, true, false}, | 256 | 257 | {"30 columns without a pet", 30, false, true}, | | 258 | + {"offer chip fits exactly without a pet", chipWidth, false, true}, | | 259 | + {"offer chip fits exactly with a docked pet", chipWidth + petReservedColumns, true, true}, | 257 | 260 | {"96 columns with a docked pet", 96, true, true}, | 258 | 261 | } { | 259 | 262 | t.Run(testCase.name, func(t *testing.T) { | |
|