Repository navigation
refactor(runtime): dedupe isLikelySandboxDenial into sandbox/detect l… - #1438
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
No correctness issue found. The new leaf owns the regex and sandbox gate, while each caller keeps its own input shaping.
Suggested follow-up: add direct tests for the predicate and PTY flattening. The current suite covers a pipes/stderr match, but not the PTY text fields, stdout matches, the other regex branches, near-misses, or all three callers. This is not blocking the refactor.
|
Thanks for the review! Pushed a follow-up commit (
The two commits are cleanly separated: |
|
LGTM! Merging. |
Astro-Han
left a comment
There was a problem hiding this comment.
Reviewed f86097f. The new tests cover the sandbox-denial patterns and near-misses, stdout and stderr, all three PTY text fields, newline boundaries, and the three call sites.
Production code did not change. All required checks pass. No findings. Approving.
Summary
Dedupe the
isLikelySandboxDenialpredicate — three copies (shell-tools.ts, builtin-tools.ts, and a PTY-aware variant in shell-run-tool-result.ts) shared the same regex but differed in input shape. Extracts one primitiveisLikelySandboxDenial({ stdout, stderr, sandboxed })into a newsandbox/detect.tsleaf, so the regex and the sandboxed-gating live in exactly one place. Addresses the "Sandbox-denial predicate" slice from #1404.The three call sites keep their own input shaping, since that's where their scenarios genuinely differ:
sandboxedsourceshell-tools.ts'sandboxed' in result && result.sandboxed === trueresult.stdout/result.stderr(BoundedShellResult lacks the field, so theinnarrowing stays at the call site)builtin-tools.tsresult.sandboxed === trueresult.stdout/result.stderrshell-run-tool-result.tstrue(wrapper already gated onsandboxExecution.enforced)flattenSandboxDenialText(output)— preserves the original pipes-vs-pty flattening (pty:scrollback+screen+lastAlternateScreen→ stdout)Behavior-neutral: the regex is byte-identical to all three originals, and the PTY-flattened text matches the original variant's output (leading
\nfrom the empty stderr doesn't affect regex matching). No public surface change — all three call sites are internal,isLikelySandboxDenialis an internal leaf consumed only by these three files (not re-exported fromsandbox/index.tsbarrel, sinceruntime/index.tsdoesn't expose it externally).Verification
npm --workspace @maka/runtime run typecheck— cleannpm --workspace @maka/runtime test— 2403 pass, 0 fail, 7 skipped (full suite, including theshell-run-tool-resultsandbox-denial projection tests that cover the variant call site)npm run lint— clean (2041 files)npm run format:check— clean (1019 files)git diff origin/main...HEAD --check— no whitespace errorsReview focus
shell-run-tool-result.ts) is the only non-mechanical change. ConfirmflattenSandboxDenialTextpreserves the original PTY text shape — the pty branch stuffsscrollback+screen+lastAlternateScreeninto thestdoutslot and leavesstderrempty, so the primitive's${stderr}\n${stdout}reconstructs the original${scrollback}\n${screen}\n${lastAlternateScreen}(with a leading\nthat doesn't affect the regex).sandboxedresolution lives at each call site, not in the primitive — this is deliberate (each scenario computes "is this a sandboxed run" from different data: asandboxed?field, a'sandboxed' in resultnarrowing, or an upstreamsandboxExecution.enforcedgate). Confirm the three resolutions are equivalent to the originals.