Skip to content

Commit 5908cad

Browse files
committed
refactor: reorganize test suites by language and move runtime-driver tests to subdirectories
1 parent d2e78d1 commit 5908cad

33 files changed

Lines changed: 930 additions & 403 deletions

File tree

CLAUDE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
- the matrix runs each fixture in host Node and secure-exec and compares normalized `code`, `stdout`, and `stderr`
3838
- no known-mismatch classification is allowed; parity mismatches stay failing until runtime/bridge behavior is fixed
3939

40+
## Test Structure
41+
42+
- `tests/test-suite/{node,python}.test.ts` are integration suite drivers; `tests/test-suite/{node,python}/` hold the shared suite definitions
43+
- test suites test generic runtime functionality with any pluggable SystemDriver (exec, run, stdio, env, filesystem, network, timeouts, log buffering); prefer adding tests here because they run against all environments (node, browser, python)
44+
- `tests/runtime-driver/` tests behavior specific to a single runtime driver (e.g. Node-only `memoryLimit`/`timingMitigation`, Python-only warm state or `secure_exec` hooks) that cannot be expressed through the shared suite context
45+
- within `test-suite/{node,python}/`, files are named by domain (e.g. `runtime.ts`, `network.ts`)
46+
4047
## Comment Pattern
4148

4249
Follow the style in `packages/secure-exec/src/index.ts`.

docs-internal/friction.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Sandboxed Node Friction Log
22

3+
## 2026-03-09
4+
5+
1. **[resolved]** Python `exec()` env overrides bypassed `permissions.env`.
6+
- Symptom: `PyodideRuntimeDriver` filtered constructor-level runtime env, but per-execution `exec(..., { env })` overrides were forwarded into the worker without permission filtering.
7+
- Fix: Python `exec()` now filters override keys through the shared `filterEnv(...)` path before applying them in the worker, matching Node runtime behavior.
8+
- Follow-up: keep future Python capability additions on the same host-side permission boundary so worker-facing APIs never receive unapproved capability input.
9+
310
## 2026-03-03
411

512
1. **[resolved]** Python runtime contract split needed explicit cross-runtime `exec()` parity and warm-state guardrails.

docs-internal/todo.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464

6565
## Security & Hardening
6666

67+
- [x] Filter Python `exec(..., { env })` overrides through `permissions.env`.
68+
- Fix: `PyodideRuntimeDriver.exec()` now applies the shared `filterEnv(...)` gate before env overrides reach the worker, and runtime-driver tests cover both denied-by-default and explicitly-allowed cases.
69+
- `packages/secure-exec/src/python/driver.ts`, `packages/secure-exec/tests/runtime-driver/python.test.ts`
70+
6771
- [x] Bridge `crypto.getRandomValues` / `randomUUID` to host `node:crypto` instead of `Math.random()`.
6872
- Fix: runtime now wires host `node:crypto` references from `packages/secure-exec/src/index.ts` into the isolate and uses them in `packages/secure-exec/src/bridge/process.ts`.
6973
- Fail-closed contract: bridge throws deterministic `crypto.getRandomValues is not supported in sandbox` / `crypto.randomUUID is not supported in sandbox` errors when host entropy hooks are unavailable.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Context
2+
3+
`NodeExecutionDriver` already filters per-execution env overrides with `filterEnv(...)` before they reach sandbox code. `PyodideRuntimeDriver` filters constructor-level runtime env, but its `exec()` request path currently passes `options.env` through unchanged.
4+
5+
## Decision
6+
7+
Filter Python `exec()` env overrides with the existing shared `filterEnv(...)` helper before sending them to the worker.
8+
9+
## Rationale
10+
11+
- Keeps Python permission behavior aligned with the Node runtime contract.
12+
- Reuses the existing `permissions.env` decision model instead of introducing Python-specific policy logic.
13+
- Fixes the contract at the host boundary, so the worker only sees already-approved env keys.
14+
15+
## Validation
16+
17+
Add Python runtime-driver tests that verify:
18+
19+
1. Env overrides are denied by default.
20+
2. Env overrides are visible when `permissions.env` explicitly allows them.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Why
2+
3+
The Python runtime is intended to reuse the same permission model as the Node runtime, but the current `PyodideRuntimeDriver.exec()` path forwards `options.env` into the worker without filtering it through `permissions.env`. That makes the active Python change spec ahead of the code and creates a cross-runtime policy mismatch.
4+
5+
## What Changes
6+
7+
- Filter Python `exec()` env overrides through the existing `SystemDriver.permissions.env` gate before applying them in the Pyodide worker.
8+
- Add regression coverage showing denied env overrides stay hidden by default and allowed env overrides remain available when explicitly permitted.
9+
- Record the fix in the internal to-do/friction tracking so the repo state matches the code.
10+
11+
## Impact
12+
13+
- Affected code: `packages/secure-exec/src/python/driver.ts`
14+
- Affected tests: `packages/secure-exec/tests/runtime-driver/python.test.ts`
15+
- Affected specs: `python-runtime`
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## ADDED Requirements
2+
3+
### Requirement: Python Exec Env Overrides Must Respect Env Permissions
4+
Python `exec()` env overrides SHALL be filtered through the configured `SystemDriver.permissions.env` gate before they are applied inside the runtime.
5+
6+
#### Scenario: Python exec env overrides are denied by default
7+
- **WHEN** a caller passes `exec(..., { env })` to `PythonRuntime` and `permissions.env` does not allow those keys
8+
- **THEN** the denied env keys MUST NOT become visible inside the Python runtime
9+
10+
#### Scenario: Python exec env overrides are exposed only when permitted
11+
- **WHEN** a caller passes `exec(..., { env })` to `PythonRuntime` and `permissions.env` explicitly allows a key
12+
- **THEN** that key MUST be visible inside the Python runtime with the provided value
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## 1. Python Env Permission Alignment
2+
3+
- [x] 1.1 Filter `PyodideRuntimeDriver.exec()` env overrides through `permissions.env` before dispatching worker requests.
4+
- [x] 1.2 Add regression coverage for denied-by-default and explicitly-allowed Python env overrides.
5+
- [x] 1.3 Update internal to-do/friction tracking so the documented follow-up state matches the code.

packages/sandboxed-node/tests/projects/rivetkit/fixture.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/sandboxed-node/tests/projects/rivetkit/package.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/sandboxed-node/tests/projects/rivetkit/src/index.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)