Repository navigation
Refactor sbx manager into focused lifecycle modules - #11598
Conversation
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Documentation PreviewDocumentation has been built for this PR. To view locally:
Built from commit 5f0af47 |
There was a problem hiding this comment.
🟡 Changes recommended
The regression test can miss incorrect sbx stop arguments because removeSandbox() catches and ignores assertion failures thrown inside the mock.
1 open issue
What changed in this PR
Refactors AWF’s Docker sbx lifecycle manager into focused modules, addressing #11593 while retaining the existing function-based API.
Changes:
- Separates credential handling, creation, execution, and runtime verification.
- Encapsulates credential backups and creation guards in lifecycle objects while preserving the default singleton and test helpers.
- Adds lifecycle-isolation regression tests and updates integration documentation.
| File | Description |
|---|---|
src/sbx/sandbox-verify.ts |
Extracts API proxy readiness and egress enforcement probes. |
src/sbx/sandbox-exec.ts |
Extracts command execution and PATH handling. |
src/sbx/sandbox-create.ts |
Extracts creation, mount setup, and environment handling. |
src/sbx/credential-scrub.ts |
Encapsulates credential backup and restoration state. |
src/sbx-manager.ts |
Provides the lifecycle class and compatibility facade. |
src/sbx-manager-isolation.test.ts |
Covers independent handles, restoration retries, and lifecycle guards. |
docs/sbx-integration.md |
Documents module boundaries and lifecycle constraints. |
Review effort: Max (dynamic)
| mockExecaFn.mockImplementation(async (_command, args) => { | ||
| expect(entries.has(first.secret)).toBe(false); | ||
| expect(args).toEqual(args[0] === 'stop' ? ['stop', 'first'] : ['rm', '--force', 'first']); | ||
| return success; | ||
| }); | ||
| await firstManager.removeSandbox('first'); | ||
| expect(mockExecaFn).toHaveBeenCalledTimes(2); |
|
@copilot address all review feedback |
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Updated the regression test to record stop/rm arguments and credential-presence state inside the mock, then assert them after teardown returns. Committed as |
|
✅ Copilot review passed with no inline comments. @lpcox Add the |
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (2 files)
✨ New Files (4 files)
Coverage comparison generated by |

sbx-manager.tscombined five responsibilities in 882 lines, with global credential state coupling creation and teardown. This refactor separates those concerns and makes lifecycle state independently testable.src/sbx/; retain a 124-line facade.CredentialScrubHandleand creation guards inSbxLifecycleManager. Preserve the default singleton API,testHelpers, and existing credential safeguards.