|
| 1 | +# Test Structure Recommendation |
| 2 | + |
| 3 | +## Current State |
| 4 | + |
| 5 | +99 TypeScript test files + ~310 Rust tests across 5 crates. The main problem is `packages/core/tests/` — 57 files in a flat directory with no grouping. The Rust side is better but has a few monoliths and no fast/slow distinction. |
| 6 | + |
| 7 | +## TypeScript: Target Structure |
| 8 | + |
| 9 | +``` |
| 10 | +packages/core/tests/ |
| 11 | +├── unit/ # No VM, no sidecar — pure logic tests |
| 12 | +│ ├── host-tools-argv.test.ts |
| 13 | +│ ├── host-tools-prompt.test.ts |
| 14 | +│ ├── host-tools-shims.test.ts |
| 15 | +│ ├── mount-descriptors.test.ts |
| 16 | +│ ├── root-filesystem-descriptors.test.ts |
| 17 | +│ ├── sidecar-permission-descriptors.test.ts |
| 18 | +│ ├── sidecar-placement.test.ts |
| 19 | +│ ├── os-instructions.test.ts |
| 20 | +│ ├── cron-manager.test.ts |
| 21 | +│ ├── cron-timer-driver.test.ts |
| 22 | +│ ├── allowed-node-builtins.test.ts |
| 23 | +│ ├── list-agents.test.ts |
| 24 | +│ └── software-projection.test.ts |
| 25 | +│ |
| 26 | +├── filesystem/ # VM filesystem operations |
| 27 | +│ ├── crud.test.ts # (was filesystem.test.ts) |
| 28 | +│ ├── move-delete.test.ts |
| 29 | +│ ├── batch-ops.test.ts |
| 30 | +│ ├── readdir-recursive.test.ts |
| 31 | +│ ├── overlay.test.ts # (was overlay-backend.test.ts) |
| 32 | +│ ├── layers.test.ts |
| 33 | +│ ├── mount.test.ts |
| 34 | +│ ├── host-dir.test.ts |
| 35 | +│ └── base-filesystem.test.ts |
| 36 | +│ |
| 37 | +├── process/ # Process execution, signals, trees |
| 38 | +│ ├── execute.test.ts |
| 39 | +│ ├── management.test.ts |
| 40 | +│ ├── tree.test.ts |
| 41 | +│ ├── all-processes.test.ts |
| 42 | +│ ├── spawn-flat-api.test.ts |
| 43 | +│ └── shell-flat-api.test.ts |
| 44 | +│ |
| 45 | +├── session/ # ACP session lifecycle and protocol |
| 46 | +│ ├── lifecycle.test.ts |
| 47 | +│ ├── events.test.ts |
| 48 | +│ ├── capabilities.test.ts |
| 49 | +│ ├── mcp.test.ts |
| 50 | +│ ├── cancel.test.ts |
| 51 | +│ ├── protocol.test.ts # (was acp-protocol.test.ts) |
| 52 | +│ └── e2e.test.ts # (merge session.test.ts + session-comprehensive + session-mock-e2e) |
| 53 | +│ |
| 54 | +├── agents/ # Per-agent adapter tests |
| 55 | +│ ├── pi/ |
| 56 | +│ │ ├── headless.test.ts |
| 57 | +│ │ ├── acp-adapter.test.ts |
| 58 | +│ │ ├── sdk-adapter.test.ts |
| 59 | +│ │ └── tool-llmock.test.ts |
| 60 | +│ ├── claude/ |
| 61 | +│ │ ├── investigate.test.ts |
| 62 | +│ │ ├── sdk-adapter.test.ts |
| 63 | +│ │ └── session.test.ts |
| 64 | +│ ├── opencode/ |
| 65 | +│ │ ├── acp.test.ts |
| 66 | +│ │ ├── headless.test.ts |
| 67 | +│ │ └── session.test.ts |
| 68 | +│ └── codex/ |
| 69 | +│ └── session.test.ts |
| 70 | +│ |
| 71 | +├── wasm/ # WASM command and permission tests |
| 72 | +│ ├── commands.test.ts |
| 73 | +│ └── permission-tiers.test.ts |
| 74 | +│ |
| 75 | +├── network/ |
| 76 | +│ ├── network.test.ts |
| 77 | +│ └── host-tools-server.test.ts |
| 78 | +│ |
| 79 | +├── sidecar/ |
| 80 | +│ ├── client.test.ts |
| 81 | +│ └── native-process.test.ts |
| 82 | +│ |
| 83 | +├── cron/ |
| 84 | +│ └── integration.test.ts |
| 85 | +│ |
| 86 | +└── helpers/ # Shared test utilities (stays as-is) |
| 87 | +``` |
| 88 | + |
| 89 | +### Registry tests |
| 90 | + |
| 91 | +``` |
| 92 | +registry/tests/ |
| 93 | +├── e2e/ # Rename kernel/ → e2e/ for clarity |
| 94 | +│ ├── npm/ # Group the 9 npm e2e tests |
| 95 | +│ │ ├── install.test.ts |
| 96 | +│ │ ├── scripts.test.ts |
| 97 | +│ │ ├── suite.test.ts |
| 98 | +│ │ ├── lifecycle.test.ts |
| 99 | +│ │ ├── version-init.test.ts |
| 100 | +│ │ ├── npx-and-pipes.test.ts |
| 101 | +│ │ ├── concurrently.test.ts |
| 102 | +│ │ ├── nextjs-build.test.ts |
| 103 | +│ │ └── project-matrix.test.ts |
| 104 | +│ ├── cross-runtime/ # Group the 3 cross-runtime tests |
| 105 | +│ │ ├── network.test.ts |
| 106 | +│ │ ├── pipes.test.ts |
| 107 | +│ │ └── terminal.test.ts |
| 108 | +│ ├── bridge-child-process.test.ts |
| 109 | +│ ├── ctrl-c-shell-behavior.test.ts |
| 110 | +│ ├── dispose-behavior.test.ts |
| 111 | +│ ├── error-propagation.test.ts |
| 112 | +│ ├── exec-integration.test.ts |
| 113 | +│ ├── fd-inheritance.test.ts |
| 114 | +│ ├── module-resolution.test.ts |
| 115 | +│ ├── node-binary-behavior.test.ts |
| 116 | +│ ├── signal-forwarding.test.ts |
| 117 | +│ ├── tree-test.test.ts |
| 118 | +│ └── vfs-consistency.test.ts |
| 119 | +├── wasmvm/ # Already well organized — keep as-is |
| 120 | +├── projects/ # Fixtures — keep as-is |
| 121 | +└── smoke.test.ts |
| 122 | +``` |
| 123 | + |
| 124 | +## Rust: Target Structure |
| 125 | + |
| 126 | +The per-crate layout is already good. The changes are surgical: |
| 127 | + |
| 128 | +### Split `execution/tests/javascript.rs` (46 tests) |
| 129 | + |
| 130 | +``` |
| 131 | +crates/execution/tests/ |
| 132 | +├── javascript/ |
| 133 | +│ ├── mod.rs # common setup |
| 134 | +│ ├── builtin_interception.rs # require('fs') → polyfill routing |
| 135 | +│ ├── module_resolution.rs # ESM/CJS loading, import paths |
| 136 | +│ ├── env_hardening.rs # env stripping, process proxy, guest env |
| 137 | +│ └── sync_rpc.rs # sync RPC bridge, timeouts |
| 138 | +├── python.rs # (15 tests — fine as-is) |
| 139 | +├── python_prewarm.rs # (2 tests — fine as-is) |
| 140 | +├── wasm.rs # (20 tests — fine as-is) |
| 141 | +├── permission_flags.rs # (6 tests — fine as-is) |
| 142 | +├── benchmark.rs |
| 143 | +└── smoke.rs |
| 144 | +``` |
| 145 | + |
| 146 | +### Mark slow sidecar integration tests |
| 147 | + |
| 148 | +Tests that spawn real sidecar processes (`crash_isolation`, `session_isolation`, `vm_lifecycle`, `process_isolation`) should use `#[ignore]`: |
| 149 | + |
| 150 | +```rust |
| 151 | +#[test] |
| 152 | +#[ignore] // spawns sidecar process — run with: cargo test -- --ignored |
| 153 | +fn crash_isolation() { ... } |
| 154 | +``` |
| 155 | + |
| 156 | +This lets `cargo test` stay fast; CI runs `cargo test -- --include-ignored`. |
| 157 | + |
| 158 | +### Keep kernel/tests/ as-is |
| 159 | + |
| 160 | +The 1-file-per-subsystem pattern (vfs, fd_table, process_table, pipe_manager, etc.) already maps cleanly to kernel modules. No changes needed. |
| 161 | + |
| 162 | +### Summary |
| 163 | + |
| 164 | +| Crate | Status | Action | |
| 165 | +|-------|--------|--------| |
| 166 | +| `kernel/tests/` (19 files, 161 tests) | Good — 1:1 with subsystems | Keep as-is | |
| 167 | +| `execution/tests/` (8 files, 95 tests) | `javascript.rs` is a monolith | Split into submodule | |
| 168 | +| `sidecar/tests/` (14 files, 49 tests) | Mixes fast/slow | `#[ignore]` on integration tests | |
| 169 | +| `bridge/tests/` (2 files, 1 test) | Fine | Keep as-is | |
| 170 | +| `sidecar-browser/tests/` (3 files, 5 tests) | Fine | Keep as-is | |
| 171 | + |
| 172 | +## Migration Approach |
| 173 | + |
| 174 | +This should be done incrementally, one directory at a time: |
| 175 | + |
| 176 | +1. Create subdirectories and move files (git mv preserves history) |
| 177 | +2. Update vitest config globs / Cargo test paths after each move |
| 178 | +3. Verify CI passes after each batch |
| 179 | +4. Do not combine restructuring with functional changes in the same PR |
0 commit comments