Skip to content

Refactor sbx manager into focused lifecycle modules - #11598

Merged
lpcox merged 4 commits into
mainfrom
copilot/refactor-sbx-manager-to-modular
Nov 14, 2026
Merged

lpcox merged 4 commits into
mainfrom
copilot/refactor-sbx-manager-to-modular

Conversation

@lpcox

@lpcox lpcox commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

sbx-manager.ts combined five responsibilities in 882 lines, with global credential state coupling creation and teardown. This refactor separates those concerns and makes lifecycle state independently testable.

  • Module boundaries: Extract credential handling, creation/environment setup, execution/PATH handling, and runtime verification into src/sbx/; retain a 124-line facade.
  • State ownership: Encapsulate backups in CredentialScrubHandle and creation guards in SbxLifecycleManager. Preserve the default singleton API, testHelpers, and existing credential safeguards.
  • Regression coverage: Add focused cases for independent handles, restoration retries, parent substitution, and lifecycle guards; update the integration guide’s module references.

@lpcox lpcox changed the title [WIP] Refactor src/sbx-manager.ts into focused modules Refactor sbx manager into focused lifecycle modules Nov 14, 2026
Comment thread src/sbx/sandbox-exec.ts Resolved
@lpcox
lpcox marked this pull request as ready for review November 14, 2026 19:52
Copilot AI adaptive review requested due to automatic review settings November 14, 2026 19:52
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Documentation has been built for this PR.

Download preview artifact

To view locally:

  1. Download the docs-preview-pr-11598 artifact from the workflow run
  2. Unzip and open index.html in your browser

Built from commit 5f0af47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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)

Comment on lines +208 to +214
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);
@lpcox

lpcox commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot address all review feedback

Copilot AI commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

@copilot address all review feedback

Updated the regression test to record stop/rm arguments and credential-presence state inside the mock, then assert them after teardown returns. Committed as 1f7919f.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Copilot review passed with no inline comments.

@lpcox Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 93.92% 93.94% 📈 +0.02%
Statements 92.48% 92.50% 📈 +0.02%
Functions 93.14% 93.18% 📈 +0.04%
Branches 86.87% 86.90% 📈 +0.03%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/commands/main-action-cleanup.ts 96.9% → 97.9% (+1.03%) 97.0% → 98.0% (+0.99%)
src/sbx-manager.ts 97.6% → 100.0% (+2.41%) 96.5% → 100.0% (+3.53%)
✨ New Files (4 files)
  • src/sbx/credential-scrub.ts: 96.1% lines
  • src/sbx/sandbox-create.ts: 100.0% lines
  • src/sbx/sandbox-exec.ts: 100.0% lines
  • src/sbx/sandbox-verify.ts: 100.0% lines

Coverage comparison generated by scripts/ci/compare-coverage.ts

@lpcox
lpcox merged commit 1bcd076 into main Nov 14, 2026
42 of 43 checks passed
@lpcox
lpcox deleted the copilot/refactor-sbx-manager-to-modular branch November 14, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactoring] Split src/sbx-manager.ts into focused modules

4 participants