Skip to content

feat: refactor client + containers to be testable, and add tests #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a4071d9
Initial testing setup
ghostwriternr Jul 28, 2025
ca9fb7b
WIP: Refactor sandbox client
ghostwriternr Jul 28, 2025
6b49aee
Fix expose/unexpose ports
ghostwriternr Jul 28, 2025
bf2eac8
Move away from guessable preview URLs
ghostwriternr Jul 28, 2025
5664c2b
Fix process streaming endpoint
ghostwriternr Jul 28, 2025
38d4a34
Improve error handling
ghostwriternr Jul 28, 2025
2b4bb48
Improve exports
ghostwriternr Jul 28, 2025
be4b440
Add unit tests for clients
ghostwriternr Jul 28, 2025
c0dac99
Add integration tests
ghostwriternr Jul 28, 2025
1e3a6e5
Add container testing with dynamic build ID support
ghostwriternr Jul 29, 2025
2fe9d07
Add e2e tests
ghostwriternr Jul 29, 2025
a2c466d
Test request handler
ghostwriternr Jul 29, 2025
8efc363
Add tests into CI
ghostwriternr Jul 29, 2025
c255514
Document testing setup
ghostwriternr Jul 29, 2025
a231ce4
Make test suite action read-only
ghostwriternr Jul 29, 2025
3be8332
Arbitrary attempt at fixing e2e tests
ghostwriternr Jul 29, 2025
b126eca
Revert "Arbitrary attempt at fixing e2e tests"
ghostwriternr Jul 29, 2025
3e30ca3
First pass at refactoring container
ghostwriternr Jul 29, 2025
cbae2d4
Improve type safety
ghostwriternr Jul 29, 2025
cfb3da8
Fix broken streaming contracts
ghostwriternr Jul 29, 2025
61863ef
Add container integration tests
ghostwriternr Jul 29, 2025
480c5e9
Add docs for working with codebase
ghostwriternr Jul 29, 2025
1c12390
Commit Claude planning files
ghostwriternr Jul 29, 2025
1d66293
Revert "Commit Claude planning files"
ghostwriternr Jul 29, 2025
f0bff2e
Test on node 20
ghostwriternr Jul 29, 2025
99417cf
Fix tests
ghostwriternr Jul 29, 2025
1c6eb96
Fix PR action permissions
ghostwriternr Jul 29, 2025
61dd586
Fix type errors and remove integration tests
ghostwriternr Jul 30, 2025
f0a6eb5
Complete transition away from integration tests
ghostwriternr Jul 30, 2025
75e024d
Integrate tests with actions
ghostwriternr Jul 30, 2025
a90cb78
Build before typecheck
ghostwriternr Jul 30, 2025
f04beb4
Format
ghostwriternr Jul 30, 2025
1911385
Fix biome complaints
ghostwriternr Jul 30, 2025
54a359b
Fix broken tests
ghostwriternr Jul 30, 2025
2f48fe5
Fix docs
ghostwriternr Jul 30, 2025
35444a3
Get rid of contract tests for now
ghostwriternr Jul 30, 2025
bc88a15
Purge contract tests
ghostwriternr Jul 31, 2025
4c134ce
Move tests around
ghostwriternr Jul 31, 2025
9b23b58
Fix tests
ghostwriternr Jul 31, 2025
ae7dda6
Rename post method
ghostwriternr Jul 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fruity-banks-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudflare/sandbox": patch
---

comprehensive testing infrastructure and client architecture improvements

Establishes complete testing suite (476 tests) with unit, integration, container, and e2e coverage. Refactors monolithic HttpClient into domain-specific clients (Command, File, Process, Port, Git, Utility) with enhanced error handling. Fixes critical port access control vulnerability and enhances preview URL security with mandatory tokens. Solves Build ID problem enabling container testing. Maintains 100% backward compatibility.
17 changes: 13 additions & 4 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,26 @@ jobs:
node-version: 20
cache: "npm"

- run: npm install
- name: Install dependencies
run: npm install

- name: Modify package.json version
run: npx tsx .github/version-script.ts

- name: Resolve workspace dependencies
run: npx tsx .github/resolve-workspace-versions.ts

- run: npm run build
- run: npm run check
- run: CI=true npm run test
- name: Run type checking
run: npm run typecheck

- name: Run linting
run: npm run check

- name: Build packages
run: npm run build

- name: Run full test suite
run: npm test

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down
31 changes: 17 additions & 14 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
name: Pull Request
permissions:
contents: read

on: pull_request

jobs:
check:
timeout-minutes: 5
strategy:
matrix:
os: [
ubuntu-24.04,
# windows-latest,
# macos-latest,
]
runs-on: ${{ matrix.os }}
pr-validation:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -23,7 +17,16 @@ jobs:
node-version: 20
cache: "npm"

- run: npm install
- run: npm run build
- run: npm run check
- run: CI=true npm run test
- name: Install dependencies
run: npm ci

- name: Run quality checks
run: |
npm run build
npm run typecheck
npm run check

- name: Run test suite
run: |
npm run test:unit
npm run test:container
16 changes: 14 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@ jobs:
node-version: 20
cache: "npm"

- run: npm install
- run: npm run build
- name: Install dependencies
run: npm install

- name: Run type checking
run: npm run typecheck

- name: Run linting
run: npm run check

- name: Build packages
run: npm run build

- name: Run full test suite
run: npm test

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down
147 changes: 147 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
name: Test Suite
permissions:
contents: read

on:
push:
branches: [main, develop]

jobs:
quality-checks:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Build packages
run: npm run build

- name: Run type checking
run: npm run typecheck

- name: Run linting
run: npm run check

test:
runs-on: ubuntu-latest
needs: quality-checks
strategy:
matrix:
test-suite: [unit, contracts, container]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Run ${{ matrix.test-suite }} tests
run: npm run test:${{ matrix.test-suite }}

coverage:
runs-on: ubuntu-latest
needs: test

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Generate coverage report
run: npm run test:coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./packages/sandbox/coverage/lcov.info
fail_ci_if_error: true

build:
runs-on: ubuntu-latest
needs: coverage

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Build sandbox package
run: npm run build
working-directory: packages/sandbox

- name: Cache build artifacts
uses: actions/cache/save@v4
with:
path: |
packages/sandbox/dist
packages/sandbox/node_modules
key: build-${{ github.sha }}-${{ hashFiles('**/package-lock.json') }}

- name: Build Docker image
run: npm run docker:local
working-directory: packages/sandbox

example-test:
runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"

- name: Restore build artifacts
uses: actions/cache/restore@v4
with:
path: |
packages/sandbox/dist
packages/sandbox/node_modules
key: build-${{ github.sha }}-${{ hashFiles('**/package-lock.json') }}
fail-on-cache-miss: true

- name: Install root dependencies
run: npm ci

- name: Test example application
run: |
npm ci
npm run build
working-directory: examples/basic
Loading