Repository navigation
Add backup exclude options and defaults - #437
whoiskatrin wants to merge 15 commits into
Conversation
🦋 Changeset detectedLatest commit: 9bdedbc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
🐳 Docker Images Published
Usage: FROM cloudflare/sandbox:0.0.0-pr-437-2aecdffVersion: 📦 Standalone BinaryFor arbitrary Dockerfiles: COPY --from=cloudflare/sandbox:0.0.0-pr-437-2aecdff /container-server/sandbox /sandbox
ENTRYPOINT ["/sandbox"]Download via GitHub CLI: gh run download 22720770848 -n sandbox-binaryExtract from Docker: docker run --rm cloudflare/sandbox:0.0.0-pr-437-2aecdff cat /container-server/sandbox > sandbox && chmod +x sandbox |
There was a problem hiding this comment.
OpenCode Review
This PR adds a much-needed feature for backup exclusion patterns - the implementation looks solid overall. The approach is clean: new optional parameters flow through all three layers (SDK → DO → Container), with proper validation at each boundary.
Strengths:
- Proper three-layer architecture flow (SDK validates, container executes)
- Good default exclude patterns (node_modules, .git, dist, build, etc.)
- Comprehensive E2E tests that verify actual behavior
- Shell escaping for security (preventing injection)
- Temporary exclude file cleanup
- Clear changeset with user-focused description
A few technical considerations:
The duplicate validation between packages/sandbox/src/sandbox.ts:192-213 and packages/sandbox-container/src/handlers/backup-handler.ts:24-42 follows the pattern of defense-in-depth validation but could be consolidated into shared utilities since the logic is identical.
The control character regex /[\u0000-\u001f\u007f]/ is correctly implemented in both places - this covers C0 control chars plus DEL, which is appropriate for shell safety.
The E2E tests properly verify end-to-end behavior rather than just mocking - they create actual files, exclude patterns, and verify the restored state. This gives good confidence the feature works as intended.
Minor improvement opportunities:
- Consider extracting the control character validation to
@repo/sharedsince it's duplicated - The temporary exclude file cleanup could benefit from explicit error handling (currently just logs warnings)
Documentation consideration:
The feature is well-documented in the type definitions, but the Cloudflare docs should be updated to include the new exclude and excludeDefaults parameters in the backup API documentation.
Overall this is a clean, well-tested implementation that follows the project's patterns. Ready to merge.
ghostwriternr
left a comment
There was a problem hiding this comment.
The only overarching issue I have with this PR is that ideally, this should behave similar to how most unix tools behave, which is gitignore, if present, is respected by default, but can be disabled with a flag. And there's an explicit flag for passing a list of paths to ignore. Us maintaining a list of "default" paths to ignore imo is definitely not a good path to pursue.
This adds end-to-end support for backup exclude patterns so users can skip dependency and build directories during createBackup. It also adds an excludeDefaults option for common paths and covers both exclude and default excludes with backup workflow E2E tests.
Use regex for control character detection in the SDK layer, matching the pattern already used for backup name validation. Add the same control character check to the container handler for defense-in-depth. Log warnings on exclude file cleanup failures instead of silently swallowing errors.
51f89b0 to
a23c2da
Compare
🐳 Docker Images Published
Usage: FROM cloudflare/sandbox:0.0.0-pr-437-9bdedbcVersion: 📦 Standalone BinaryFor arbitrary Dockerfiles: COPY --from=cloudflare/sandbox:0.0.0-pr-437-9bdedbc /container-server/sandbox /sandbox
ENTRYPOINT ["/sandbox"]Download via GitHub CLI: gh run download 22848212875 -n sandbox-binaryExtract from Docker: docker run --rm cloudflare/sandbox:0.0.0-pr-437-9bdedbc cat /container-server/sandbox > sandbox && chmod +x sandbox |
|
/bonk check why the tests are failing and fix it |
mksquashfs -ef matches patterns containing '/' against the full absolute source path, not relative to the source directory root. The git ls-files output was relative, so no files were excluded.
Co-authored-by: whoiskatrin <whoiskatrin@users.noreply.github.com>
SummaryTwo E2E backup tests were failing:
Root cause: Fix ( |
Emit both direct and sticky mksquashfs exclude patterns so .gitignore-derived paths are excluded regardless of how the source directory is rooted in the archive.
f7fe2d9 to
ae42c52
Compare
Switch from newline to null-byte delimiters when listing gitignored files to handle paths containing spaces, quotes, and non-ASCII characters. Remove .git from hardcoded excludes since git ls-files already omits it.
|
Closing to reopen as a cleaner PR with focused review |
Summary
This PR changes backup exclusion behavior to follow
.gitignoreby default instead of maintaining a hardcoded default ignore list.createBackup() now supports:
useGitignore?: booleanto control whether git ignore rules are appliedDefault behavior:
useGitignore: false, gitignored paths are includedWhy
The previous approach maintained a built-in list of default excluded paths. Based on review feedback, this PR moves away from that model and aligns backup behavior with standard tooling that respects
.gitignoreby default.API and behavior
Changes in this PR:
excludeexcludeDefaultsuseGitignore?: booleanwith defaulttrue.gitwhen gitignore-based exclusion is enabledTests
Updated backup workflow E2E coverage for:
.gitignoreby defaultuseGitignore: false.gitignorebehaviorValidation run locally:
npm run typecheckReviewer notes
This PR now addresses the feedback to stop maintaining a default ignore list and instead use gitignore-driven defaults.