writing-tests

Guides writing and maintaining bun:test tests with mock isolation and cross-platform CI rules.

Updated Sep 14, 2026
One-click install
npx skills add https://github.com/pandejesal/drone-nav-sar --skill writing-tests-pandejesal
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-tests
Source: https://github.com/pandejesal/drone-nav-sar/tree/main/.swarm/bundled-skills/writing-tests
Command: npx skills add https://github.com/pandejesal/drone-nav-sar --skill writing-tests-pandejesal

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing tests in the opencode-swarm repository is error-prone because Bun's shared module cache leaks mocks across test files, Windows path and environment behavior breaks naive tests, and broad test-runner scopes can stall the agent. This Skill encodes the repository's testing conventions so new or modified tests pass on all three CI platforms. ## Core Features & Use Cases - Mock isolation rules: Enforces a three-tier mocking strategy (_test_exports, _internals DI seams, mock.module) with mandatory cleanup patterns to prevent cross-file pollution. - Cross-platform test patterns: Covers path resolution, symlink differences, temp directory handling, per-platform environment variable redirection, and line-ending normalization for ubuntu, macOS, and Windows CI. - CI pipeline structure and file placement: Documents the six CI test steps, per-file isolation loops, sharding, quarantine filters, and naming conventions for unit, adversarial, integration, and regression tests. - Use Case: Before adding a test for a new hook factory, load this Skill to choose the correct mock tier, place the file in tests/unit/hooks/, and avoid the Windows EBUSY and mock-restore pitfalls that previously caused hundreds of CI failures. ## Quick Start Load the writing-tests skill before writing or modifying any test file in the opencode-swarm repository.

Frequently Asked Questions about writing-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write tests with bun:test in the opencode-swarm repository?

Import describe, test, expect, mock, and spyOn from bun:test, place the file under tests/unit/ matching the source directory, and follow the two-tier mock convention. Run tests with per-file shell loops like bun --smol test <file> --timeout 60000 rather than broad test_runner scopes.

Why do my Bun tests pass individually but fail when run together?

Bun's --smol mode shares the module cache between test files in one process, so mock.module calls leak across files. Diagnose by running the file alone, then paired with its suspected polluting neighbor, and migrate to the _internals DI seam pattern to eliminate the pollution.

When should I use _internals versus mock.module for mocking?

Use _internals seams to mock functions within the same module you are testing, and mock.module only for cross-module dependencies like Node built-ins. Note that _internals cannot intercept functions captured by reference at module definition time; test those via observable outcomes instead.

Why do mock.module mocks throw SyntaxError: Export named not found in Bun?

Bun validates the full export set at dynamic-import time, so the mock factory must stub every runtime export of the target module, not just the ones your test calls. List exports with grep and provide minimal stubs such as a generic Zod stub for schemas.

How do I make tests work on Windows CI without EBUSY or path failures?

Construct mock keys with path.resolve instead of hardcoded Unix paths, redirect HOME, LOCALAPPDATA, and APPDATA together when isolating environment variables, and skip tests spawning async child processes on Windows using test.skipIf(process.platform === 'win32') to avoid EBUSY errors.

Can I use the test_runner tool to run the full test suite?

No. The test_runner scope 'all' is gated behind the SWARM_ALLOW_FULL_SUITE=1 environment variable and multi-file convention or graph scopes are rejected by a scope_exceeded guard. Use per-file shell loops matching CI behavior for repo-wide validation.