Skip to content

Commit ce1468a

Browse files
Enable TypeScript checking for test files (#238)
* Enable TypeScript checking for test files * Enable TypeScript checking for e2e tests Added tests/e2e/ to typecheck pipeline. Created test-worker/types.ts defining response types for test infrastructure endpoints. All tests now use proper SDK types from @repo/shared for SDK operations and test-worker types for test infrastructure. Removed non-null assertions with proper type guards. Found and fixed bugs where tests used wrong field names (contextId vs id, processId vs id) that were masked by inline types. * Fix incorrect assertions * Use public Process interface correctly * Revert enum usage * Enrich interpreter error * Fix TypeScript build output paths Build output was going to dist/src/ instead of dist/ due to rootDir: "." in tsconfig, breaking Docker container startup which expects dist/index.js. Split tsconfig into separate build and typecheck configs. Build emits src only to dist/, typecheck includes tests.
1 parent 455ed50 commit ce1468a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+958
-743
lines changed

PR-204-REVIEW-REPORT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,7 @@ $ npm run test:e2e
18701870
- Less flexible
18711871

18721872
3. **Subshell with export** (chosen)
1873+
18731874
```bash
18741875
(export VAR=val; command)
18751876
```

examples/typescript-validator/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />

examples/typescript-validator/src/index.css

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "tailwindcss";
1+
@import 'tailwindcss';
22

33
@theme {
44
/* Cloudflare Accent Colors */
@@ -31,14 +31,15 @@
3131

3232
body {
3333
margin: 0;
34-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
35-
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
36-
sans-serif;
34+
font-family:
35+
-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
36+
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
3737
-webkit-font-smoothing: antialiased;
3838
-moz-osx-font-smoothing: grayscale;
3939
background-color: var(--color-bg-cream);
4040
}
4141

42-
code, pre {
42+
code,
43+
pre {
4344
font-family: 'Monaco', 'Courier New', 'Courier', monospace;
4445
}

examples/typescript-validator/wrangler.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"containers": [
1515
{
1616
"class_name": "Sandbox",
17-
"image": "./Dockerfile",
17+
"image": "./Dockerfile"
1818
}
1919
],
2020
"durable_objects": {

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"version": "0.0.0",
44
"description": "an api for computers",
55
"scripts": {
6-
"typecheck": "turbo run typecheck",
6+
"typecheck": "turbo run typecheck && npm run typecheck:e2e",
7+
"typecheck:e2e": "tsc --noEmit --project tests/e2e/tsconfig.json",
78
"format": "prettier --write .",
8-
"check": "sherif && biome check && turbo run typecheck",
9+
"check": "sherif && biome check && turbo run typecheck && npm run typecheck:e2e",
910
"fix": "biome check --fix && turbo run typecheck",
1011
"build": "turbo run build",
1112
"build:clean": "turbo run build --force",

packages/sandbox-container/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Container runtime for Cloudflare Sandbox SDK",
66
"type": "module",
77
"scripts": {
8-
"build": "tsc --project tsconfig.json",
8+
"build": "tsc --project tsconfig.build.json",
99
"typecheck": "tsc --noEmit",
1010
"test": "bun test tests",
1111
"test:watch": "bun test --watch tests",

packages/sandbox-container/src/core/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export interface PortNotFoundResponse {
183183
export interface ProxyErrorResponse {
184184
error: string;
185185
message: string;
186+
port: number;
186187
}
187188

188189
export interface Middleware {

packages/sandbox-container/src/handlers/interpreter-handler.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,15 @@ export class InterpreterHandler extends BaseHandler<Request, Response> {
9999
} else {
100100
// Special handling for interpreter not ready - return 503 with Retry-After header
101101
if (result.error.code === 'INTERPRETER_NOT_READY') {
102-
return new Response(
103-
JSON.stringify({
104-
success: false,
105-
error: result.error,
106-
timestamp: new Date().toISOString()
107-
}),
108-
{
109-
status: 503,
110-
headers: {
111-
'Content-Type': 'application/json',
112-
'Retry-After': String(result.error.details?.retryAfter || 5),
113-
...context.corsHeaders
114-
}
102+
const errorResponse = this.enrichServiceError(result.error);
103+
return new Response(JSON.stringify(errorResponse), {
104+
status: 503,
105+
headers: {
106+
'Content-Type': 'application/json',
107+
'Retry-After': String(result.error.details?.retryAfter || 5),
108+
...context.corsHeaders
115109
}
116-
);
110+
});
117111
}
118112

119113
return this.createErrorResponse(result.error, context);

packages/sandbox-container/src/handlers/misc-handler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import { ErrorCode } from '@repo/shared/errors';
55
import type { RequestContext } from '../core/types';
66
import { BaseHandler } from './base-handler';
77

8+
export interface VersionResult {
9+
success: boolean;
10+
version: string;
11+
timestamp: string;
12+
}
13+
814
export class MiscHandler extends BaseHandler<Request, Response> {
915
async handle(request: Request, context: RequestContext): Promise<Response> {
1016
const url = new URL(request.url);
@@ -74,7 +80,7 @@ export class MiscHandler extends BaseHandler<Request, Response> {
7480
): Promise<Response> {
7581
const version = process.env.SANDBOX_VERSION || 'unknown';
7682

77-
const response = {
83+
const response: VersionResult = {
7884
success: true,
7985
version,
8086
timestamp: new Date().toISOString()

packages/sandbox-container/src/services/port-service.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import type {
88
PortNotExposedContext
99
} from '@repo/shared/errors';
1010
import { ErrorCode } from '@repo/shared/errors';
11-
import type { PortInfo, ServiceResult } from '../core/types';
11+
import type {
12+
PortInfo,
13+
ProxyErrorResponse,
14+
ServiceResult
15+
} from '../core/types';
1216
import { PortManager } from '../managers/port-manager';
1317

1418
export interface SecurityService {
@@ -281,17 +285,15 @@ export class PortService {
281285
// Check if port is exposed
282286
const portInfo = await this.store.get(port);
283287
if (!portInfo) {
284-
return new Response(
285-
JSON.stringify({
286-
error: 'Port not found',
287-
message: `Port ${port} is not exposed`,
288-
port
289-
}),
290-
{
291-
status: 404,
292-
headers: { 'Content-Type': 'application/json' }
293-
}
294-
);
288+
const errorResponse: ProxyErrorResponse = {
289+
error: 'Port not found',
290+
message: `Port ${port} is not exposed`,
291+
port
292+
};
293+
return new Response(JSON.stringify(errorResponse), {
294+
status: 404,
295+
headers: { 'Content-Type': 'application/json' }
296+
});
295297
}
296298

297299
// Parse proxy path using manager
@@ -323,17 +325,15 @@ export class PortService {
323325
{ port }
324326
);
325327

326-
return new Response(
327-
JSON.stringify({
328-
error: 'Proxy error',
329-
message: `Failed to proxy request to port ${port}: ${errorMessage}`,
330-
port
331-
}),
332-
{
333-
status: 502,
334-
headers: { 'Content-Type': 'application/json' }
335-
}
336-
);
328+
const errorResponse: ProxyErrorResponse = {
329+
error: 'Proxy error',
330+
message: `Failed to proxy request to port ${port}: ${errorMessage}`,
331+
port
332+
};
333+
return new Response(JSON.stringify(errorResponse), {
334+
status: 502,
335+
headers: { 'Content-Type': 'application/json' }
336+
});
337337
}
338338
}
339339

0 commit comments

Comments
 (0)