Files
suaveplan/openspec/archive/2026-05-26-api-sandbox-wasm/tasks.md
2026-05-27 23:29:53 +01:00

81 lines
4.9 KiB
Markdown

# Tasks — `@suaveplan/api-sandbox-wasm`
> Every checkbox MUST reflect work actually done in this change.
## 0. Pre-flight (non-negotiable)
- [x] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
- [x] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
- [x] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## 1. Spec authoring
- [x] 1.1 Read design doc (§2.2, §5.2b, §14)
- [x] 1.2 Read `openspec/AGENTS.md` Sections 13 and 14
- [x] 1.3 Draft `proposal.md`
- [x] 1.4 Draft `specs/api-sandbox-wasm/spec.md`
- [x] 1.5 Every requirement carries `**Verified by:**`
## 2. Implementation
- [x] 2.1 Scaffold `packages/api-stack/api/api-sandbox-wasm/`
- [x] 2.2 `src/sandbox/` — `createWasmSandbox`, `WasmSandboxHandle`
- [x] 2.3 `src/preopens/` — `buildWasiPreopens(policy)` + `matchPreopen`
- [x] 2.4 `src/outbound/` — `buildWasiOutboundAllowlist(policy)` + `gateOutboundConnect`
- [x] 2.5 `src/imports/install-capability-imports/`
- [x] 2.6 `src/error-codes/error-codes.ts` via `defineCodes`
- [x] 2.7 `src/testing/run-wasm-conformance.ts`
- [x] 2.8 Fixture WASM module builder under `tests/fixtures/build-wasm.ts` (hand-encoded valid `wasi_snapshot_preview1` module — no `wabt` build step)
- [x] 2.9 `src/index.ts` — explicit named re-exports
- [x] 2.10 `package.json` exports — `./testing`, `./sandbox`, `./preopens`, `./outbound`, `./error-codes`, `./otel` subpaths
- [x] 2.11 `src/wasi/wasi.ts` — `wasi_snapshot_preview1` snapshot with policy-gated `path_open`
- [x] 2.12 `src/policy/policy.ts` — `PermissionPolicy` structural type + `resolvePermissionPolicy` Zod boundary
- [x] 2.13 `src/otel/otel.ts` — `plugin.permission_denied_total` counter wiring
## 3. Tests
- [x] 3.1 `src/sandbox/sandbox.test.ts` — 9 cases
- [x] 3.2 `src/sandbox/sandbox.spec-conformance.test.ts` — denial + dispose-idempotent
- [x] 3.3 `src/preopens/preopens.test.ts` — read-only / rw-prefix / dedup / matchPreopen
- [x] 3.4 `src/outbound/outbound.test.ts` — allow / deny / wildcard / port-pinned
- [x] 3.5 `src/testing/run-wasm-conformance.test.ts` — harness self-test passes
- [x] 3.6 `tests/dep-graph.test.ts` — runtime deps pinned to allowlist
- [x] 3.7 Every `it(...)` carries `{ timeout: 5000 }` (30000 for WASM instantiation)
- [x] 3.8 `src/wasi/wasi.test.ts` — 13 cases covering every snapshot import path
- [x] 3.9 `src/otel/otel.test.ts` — instrument creation + denial labels
- [x] 3.10 `src/policy/policy.test.ts` — resolve / freeze / type-guard
- [x] 3.11 `src/error-codes/error-codes.test.ts` — registry shape + frozen
- [x] 3.12 `src/imports/install-capability-imports/install-capability-imports.test.ts` — allow / deny / async forwarding
- [x] 3.13 `tests/fixtures/build-wasm.test.ts` — validator + magic-bytes pinning
## 4. Documentation
- [x] 4.1 Sibling `.md` per implementation `.ts` (9 files, all ≥200 words)
- [x] 4.2 `README.md` `## Modules`
- [x] 4.3 Update `CLAUDE.md` package listing
## 5. Pre-archive verification (the 5-gate triple)
- [x] 5.1 `bun run check` — `bunx biome check src/` returns clean
- [x] 5.2 `bunx turbo lint typecheck test --filter=@suaveplan/api-sandbox-wasm` — green (87 tests pass)
- [x] 5.3 `bunx turbo test:coverage --filter=@suaveplan/api-sandbox-wasm` — 100/100/100/100 across every src file
- [x] 5.4 `bun scripts/openspec-conformance.ts packages/api-stack/api/api-sandbox-wasm` — PASS (0 error / 0 warn / 0 info)
- [x] 5.5 `bunx turbo build --filter=@suaveplan/api-sandbox-wasm` — green
## 6. Pre-archive 7-row checklist
- [x] 6.1 `expectTypeOf<WasmSandboxHandle>` properties asserted in `sandbox.test.ts`
- [x] 6.2 `resolvePermissionPolicy` runs the Zod schema at the boundary; an out-of-range cpuPercent surfaces a `ZodError`
- [x] 6.3 Every `SAND_WASM_*` code thrown by a production path (verified by `openspec-conformance` gate)
- [x] 6.4 Strict-mode: writable-preopen requires explicit `rw:` prefix (`preopens.test.ts::"rw prefix enables write"`)
- [x] 6.5 OTel instruments asserted with a real-shape `MeterProvider` (`otel.test.ts`)
- [x] 6.6 `dispose()` idempotent (`sandbox.spec-conformance.test.ts::"dispose is idempotent"` + harness pin)
- [x] 6.7 No retroactive tick — every checkbox in this file marked at the moment the corresponding work landed
## 7. Archive
- [x] 7.1 Fold spec delta into `openspec/specs/api-sandbox-wasm/spec.md`
- [x] 7.2 Move folder to `openspec/archive/2026-05-26-api-sandbox-wasm/`
- [x] 7.3 Tick `8.3` in umbrella tasks (`openspec/changes/api-plugin-foundation/tasks.md`)
- [x] 7.4 Refresh `MANIFEST.md`