Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions PR-204-REVIEW-REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,7 @@ $ npm run test:e2e
- Less flexible

3. **Subshell with export** (chosen)

```bash
(export VAR=val; command)
```
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-validator/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
11 changes: 6 additions & 5 deletions examples/typescript-validator/src/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "tailwindcss";
@import 'tailwindcss';

@theme {
/* Cloudflare Accent Colors */
Expand Down Expand Up @@ -31,14 +31,15 @@

body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
font-family:
-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background-color: var(--color-bg-cream);
}

code, pre {
code,
pre {
font-family: 'Monaco', 'Courier New', 'Courier', monospace;
}
2 changes: 1 addition & 1 deletion examples/typescript-validator/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"containers": [
{
"class_name": "Sandbox",
"image": "./Dockerfile",
"image": "./Dockerfile"
}
],
"durable_objects": {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"version": "0.0.0",
"description": "an api for computers",
"scripts": {
"typecheck": "turbo run typecheck",
"typecheck": "turbo run typecheck && npm run typecheck:e2e",
"typecheck:e2e": "tsc --noEmit --project tests/e2e/tsconfig.json",
"format": "prettier --write .",
"check": "sherif && biome check && turbo run typecheck",
"check": "sherif && biome check && turbo run typecheck && npm run typecheck:e2e",
"fix": "biome check --fix && turbo run typecheck",
"build": "turbo run build",
"build:clean": "turbo run build --force",
Expand Down
2 changes: 1 addition & 1 deletion packages/sandbox-container/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Container runtime for Cloudflare Sandbox SDK",
"type": "module",
"scripts": {
"build": "tsc --project tsconfig.json",
"build": "tsc --project tsconfig.build.json",
"typecheck": "tsc --noEmit",
"test": "bun test tests",
"test:watch": "bun test --watch tests",
Expand Down
1 change: 1 addition & 0 deletions packages/sandbox-container/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export interface PortNotFoundResponse {
export interface ProxyErrorResponse {
error: string;
message: string;
port: number;
}

export interface Middleware {
Expand Down
22 changes: 8 additions & 14 deletions packages/sandbox-container/src/handlers/interpreter-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,15 @@ export class InterpreterHandler extends BaseHandler<Request, Response> {
} else {
// Special handling for interpreter not ready - return 503 with Retry-After header
if (result.error.code === 'INTERPRETER_NOT_READY') {
return new Response(
JSON.stringify({
success: false,
error: result.error,
timestamp: new Date().toISOString()
}),
{
status: 503,
headers: {
'Content-Type': 'application/json',
'Retry-After': String(result.error.details?.retryAfter || 5),
...context.corsHeaders
}
const errorResponse = this.enrichServiceError(result.error);
return new Response(JSON.stringify(errorResponse), {
status: 503,
headers: {
'Content-Type': 'application/json',
'Retry-After': String(result.error.details?.retryAfter || 5),
...context.corsHeaders
}
);
});
}

return this.createErrorResponse(result.error, context);
Expand Down
8 changes: 7 additions & 1 deletion packages/sandbox-container/src/handlers/misc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { ErrorCode } from '@repo/shared/errors';
import type { RequestContext } from '../core/types';
import { BaseHandler } from './base-handler';

export interface VersionResult {
success: boolean;
version: string;
timestamp: string;
}

export class MiscHandler extends BaseHandler<Request, Response> {
async handle(request: Request, context: RequestContext): Promise<Response> {
const url = new URL(request.url);
Expand Down Expand Up @@ -74,7 +80,7 @@ export class MiscHandler extends BaseHandler<Request, Response> {
): Promise<Response> {
const version = process.env.SANDBOX_VERSION || 'unknown';

const response = {
const response: VersionResult = {
success: true,
version,
timestamp: new Date().toISOString()
Expand Down
46 changes: 23 additions & 23 deletions packages/sandbox-container/src/services/port-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import type {
PortNotExposedContext
} from '@repo/shared/errors';
import { ErrorCode } from '@repo/shared/errors';
import type { PortInfo, ServiceResult } from '../core/types';
import type {
PortInfo,
ProxyErrorResponse,
ServiceResult
} from '../core/types';
import { PortManager } from '../managers/port-manager';

export interface SecurityService {
Expand Down Expand Up @@ -281,17 +285,15 @@ export class PortService {
// Check if port is exposed
const portInfo = await this.store.get(port);
if (!portInfo) {
return new Response(
JSON.stringify({
error: 'Port not found',
message: `Port ${port} is not exposed`,
port
}),
{
status: 404,
headers: { 'Content-Type': 'application/json' }
}
);
const errorResponse: ProxyErrorResponse = {
error: 'Port not found',
message: `Port ${port} is not exposed`,
port
};
return new Response(JSON.stringify(errorResponse), {
status: 404,
headers: { 'Content-Type': 'application/json' }
});
}

// Parse proxy path using manager
Expand Down Expand Up @@ -323,17 +325,15 @@ export class PortService {
{ port }
);

return new Response(
JSON.stringify({
error: 'Proxy error',
message: `Failed to proxy request to port ${port}: ${errorMessage}`,
port
}),
{
status: 502,
headers: { 'Content-Type': 'application/json' }
}
);
const errorResponse: ProxyErrorResponse = {
error: 'Proxy error',
message: `Failed to proxy request to port ${port}: ${errorMessage}`,
port
};
return new Response(JSON.stringify(errorResponse), {
status: 502,
headers: { 'Content-Type': 'application/json' }
});
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/sandbox-container/src/services/process-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { SessionManager } from './session-manager';

// Re-export types for use by ProcessStore implementations
export type { ProcessRecord, ProcessStatus } from '../core/types';
export type { ProcessStore } from './process-store';

export interface ProcessFilters {
status?: ProcessStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { beforeEach, describe, expect, it, vi } from 'bun:test';
import type { ExecResult, ProcessStartResult } from '@repo/shared';
import type { ExecResult, Logger, ProcessStartResult } from '@repo/shared';
import type { ErrorResponse } from '@repo/shared/errors';
import type {
ExecuteRequest,
Logger,
RequestContext,
ServiceResult
} from '@sandbox-container/core/types.ts';
} from '@sandbox-container/core/types';
import { ExecuteHandler } from '@sandbox-container/handlers/execute-handler.js';
import type { ProcessService } from '@sandbox-container/services/process-service.ts';
import type { ProcessService } from '@sandbox-container/services/process-service';
import { mocked } from '../test-utils';

// Mock the service dependencies
Expand All @@ -21,12 +20,14 @@ const mockProcessService = {
streamProcessLogs: vi.fn()
} as unknown as ProcessService;

const mockLogger: Logger = {
const mockLogger = {
info: vi.fn(),
error: vi.fn(),
warn: vi.fn(),
debug: vi.fn()
};
debug: vi.fn(),
child: vi.fn()
} as Logger;
mockLogger.child = vi.fn(() => mockLogger);

// Mock request context
const mockContext: RequestContext = {
Expand Down
11 changes: 7 additions & 4 deletions packages/sandbox-container/tests/handlers/file-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { beforeEach, describe, expect, it, vi } from 'bun:test';
import type {
DeleteFileResult,
FileExistsResult,
Logger,
MkdirResult,
MoveFileResult,
ReadFileResult,
RenameFileResult,
WriteFileResult
} from '@repo/shared';
import type { ErrorResponse } from '@repo/shared/errors';
import type { Logger, RequestContext } from '@sandbox-container/core/types';
import type { RequestContext } from '@sandbox-container/core/types';
import { FileHandler } from '@sandbox-container/handlers/file-handler';
import type { FileService } from '@sandbox-container/services/file-service';

Expand All @@ -33,12 +34,14 @@ const mockFileService = {
// Remove private properties to avoid type conflicts
} as unknown as FileService;

const mockLogger: Logger = {
const mockLogger = {
info: vi.fn(),
error: vi.fn(),
warn: vi.fn(),
debug: vi.fn()
};
debug: vi.fn(),
child: vi.fn()
} as Logger;
mockLogger.child = vi.fn(() => mockLogger);

// Mock request context
const mockContext: RequestContext = {
Expand Down
12 changes: 7 additions & 5 deletions packages/sandbox-container/tests/handlers/git-handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, it, vi } from 'bun:test';
import type { GitCheckoutResult } from '@repo/shared';
import type { GitCheckoutResult, Logger } from '@repo/shared';
import type { ErrorResponse } from '@repo/shared/errors';
import type { Logger, RequestContext } from '@sandbox-container/core/types.ts';
import type { RequestContext } from '@sandbox-container/core/types';
import { GitHandler } from '@sandbox-container/handlers/git-handler';
import type { GitService } from '@sandbox-container/services/git-service';

Expand All @@ -13,12 +13,14 @@ const mockGitService = {
listBranches: vi.fn()
} as unknown as GitService;

const mockLogger: Logger = {
const mockLogger = {
info: vi.fn(),
error: vi.fn(),
warn: vi.fn(),
debug: vi.fn()
};
debug: vi.fn(),
child: vi.fn()
} as Logger;
mockLogger.child = vi.fn(() => mockLogger);

// Mock request context
const mockContext: RequestContext = {
Expand Down
Loading
Loading