GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: preserve network approval for quoted package-manager options · Twigpine/zero@e212793

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • internal
    • sandbox
      • risk.go
      • unparseable_network_superset_test.go
    • tui
      • permission_mode_offer_test.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎internal/sandbox/risk.go‎

Copy file name to clipboardExpand all lines: internal/sandbox/risk.go
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import (
99
"strings"
1010
)
1111

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+
1217
// leadingOptionsPattern spans the global options a package manager accepts
1318
// before its subcommand, including the word an option consumes as its value:
1419
// `npm --prefix ./web run dev` and `pnpm -C ./web run dev` are documented usage,
@@ -19,7 +24,7 @@ import (
1924
// direction this fallback is already documented to favour: it runs only after
2025
// the command was declared too complex to parse, where catching an obvious
2126
// 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 + `)?)*`
2328

2429
var (
2530
// destructiveCommandPattern matches the highest-risk shell forms:
Collapse file

‎internal/sandbox/unparseable_network_superset_test.go‎

Copy file name to clipboardExpand all lines: internal/sandbox/unparseable_network_superset_test.go
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,41 @@ func TestUnparseableFallbackCoversEveryPythonLauncher(t *testing.T) {
172172
})
173173
}
174174
}
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

‎internal/tui/permission_mode_offer_test.go‎

Copy file name to clipboardExpand all lines: internal/tui/permission_mode_offer_test.go
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ func TestConfirmOnlyCommitsAnOfferTheFooterShowed(t *testing.T) {
245245
// ctrl+g cannot. Wider and pet-free layouts are the controls, so the rule
246246
// cannot pass by refusing confirmation everywhere.
247247
func TestOfferConfirmsOnlyWhereTheFooterShowsItsKey(t *testing.T) {
248+
chipWidth := ansi.StringWidth(" ● " + unsafeOfferLabel)
248249
for _, testCase := range []struct {
249250
name string
250251
width int
@@ -254,6 +255,8 @@ func TestOfferConfirmsOnlyWhereTheFooterShowsItsKey(t *testing.T) {
254255
{"24 columns with a docked pet", 24, true, false},
255256
{"30 columns with a docked pet", 30, true, false},
256257
{"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},
257260
{"96 columns with a docked pet", 96, true, true},
258261
} {
259262
t.Run(testCase.name, func(t *testing.T) {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.