[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M786FX1T26RVVTFRHCPHMYP8":3,"skill-same:01M786FX1T26RVVTFRHCPHMYP8":49},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":29,"commitSha":30,"skillDirectory":31,"forksCount":14,"repositoryHtmlUrl":32,"repositoryHomepageUrl":6,"ownerHtmlUrl":33,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":34,"install":35,"resources":48},"01M786FX1T26RVVTFRHCPHMYP8","zig-testing",null,"Use ONLY when user explicitly requests Zig test code, built-in test runner configuration, test failure diagnosis, or coverage for Zig projects.\nTriggers: \"write test zig\", \"zig test\", \"testing.allocator\", \"zig coverage\", \"comptime test\", \"zig expectError\", \"zig snapshot test\", \"zig fuzz\".\nDo NOT activate for: general Zig coding without test context, build.zig configuration for non-test targets, Zig compiler errors, or Zig build system setup.","chenziyang110\u002Flaunchdeck","chenziyang110","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43693913?v=4","01M7863EBWK1D0P6A29YGEMAS4","Robin11","01M7863ECM1VB6RXDMHTW90D2T",0,"MIT","https:\u002F\u002Fgithub.com\u002Fchenziyang110\u002Flaunchdeck\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fzig-testing\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: \"zig-testing\"\ndescription: \"Use ONLY when user explicitly requests Zig test code, built-in test runner configuration,\ntest failure diagnosis, or coverage for Zig projects.\n\nTriggers: \\\"write test zig\\\", \\\"zig test\\\", \\\"testing.allocator\\\", \\\"zig coverage\\\",\n\\\"comptime test\\\", \\\"zig expectError\\\", \\\"zig snapshot test\\\", \\\"zig fuzz\\\".\n\nDo NOT activate for: general Zig coding without test context, build.zig configuration\nfor non-test targets, Zig compiler errors, or Zig build system setup.\n\"\ncompatibility: \"Requires spec-kit project structure with .specify\u002F directory\"\nmetadata:\n  author: \"github-spec-kit\"\n  source: \"templates\u002Fpassive-skills\u002Fzig-testing\u002FSKILL.md\"\n---\n\n\n# Zig Testing (Agent Skill)\n\nAgent-focused testing workflow for Zig using the built-in test framework — zero dependencies, first-class language support with `comptime` test discovery.\n\n## When to Use\n\n- Writing new Zig tests or fixing existing tests\n- Designing unit\u002Fintegration test coverage for Zig components\n- Adding test coverage, CI gating, or regression protection\n- Configuring `zig test` workflows for consistent execution\n- Investigating test failures\n- Testing system-level or embedded Zig code\n\n### When NOT to Use\n\n- Implementing new product features without test changes\n- Large-scale refactors unrelated to test coverage or failures\n- Performance tuning without test regressions to validate\n- Non-Zig projects or non-test tasks\n\n### Stop Conditions — When to ASK instead of generating\n\nBefore generating any test code, STOP and ask the user if:\n- The code under test has **zero testability** (all comptime, no runtime public API, hard-coded system calls)\n- **No test blocks** exist in the project and no test step in build.zig\n- The request is **ambiguous**: \"test my code\" or \"add tests\" without specifying files or functions\n- The code requires **external tooling not yet configured** (kcov, zcoverage)\n- The test would require **secrets, real credentials, or production system access**\n\n## Core Concepts\n\n- **TDD loop**: red → green → refactor (tests first, minimal fix, then cleanups).\n- **First-class tests**: `test` blocks are language built-ins, discovered by `zig test`.\n- **Comptime evaluation**: tests can run at compile time via `comptime`.\n- **Test layout**: tests co-located with source using `test` blocks, or in separate `test\u002F` files.\n- **No external framework**: everything is built into the Zig compiler.\n- **CI signal**: `zig test src\u002Fmain.zig` with `--test-no-exec` for compile-time checks.\n\n## Agent Execution Protocol\n\nWhen this skill is activated, follow this exact execution sequence:\n\n### Phase 1: Context Analysis\nBefore writing any test code:\n1. Identify the Zig version (0.13+\u002Fmaster) and build configuration (`build.zig`).\n2. Check for existing test files (`test` blocks in source, `test\u002F`, `*_test.zig`) to infer style.\n3. Analyze the code under test: identify public API surface, allocator usage, `comptime` evaluation, and I\u002FO boundaries.\n4. Determine request type: (a) new tests, (b) fixing broken tests, (c) coverage improvement, (d) flaky test diagnosis.\n\n### Phase 2: Strategy Selection\nBased on Phase 1, select the appropriate strategy:\n- **Pure functions \u002F utilities**: co-located `test` blocks in source files, no mocks. Use `testing.expectEqual`.\n- **External dependencies (I\u002FO, network)**: use interfaces (structs with function pointers) for dependency injection; write manual test doubles.\n- **Allocator-dependent code**: always use `testing.allocator` to detect memory leaks automatically.\n- **Comptime code**: use `comptime` test blocks to validate compile-time logic.\n\n### Decision Tree (Complex Scenarios)\n\n```text\nQ1: External I\u002FO (filesystem, network, hardware)?\n  → Yes → Q2\n  → No  → Pure unit test, no mocks needed\n\nQ2: Mockable (function pointer struct, comptime interface)?\n  → Yes → Manual test double via function pointer injection\n  → No  → Q3\n\nQ3: Allocator-dependent code?\n  → Yes → Always use testing.allocator for leak detection\n  → No  → Standard test block\n\nQ4: Compile-time validation?\n  → Yes → comptime test block\n  → No  → Q5\n\nQ5: Snapshot\u002Ferror union testing?\n  → Yes → @embedFile for snapshots, expectError for error cases\n  → No  → Standard testing.expectEqual\n```\n\n### Phase 3: Test Case Design\nApply systematic test design before coding:\n1. **Happy path**: normal input → expected output.\n2. **Boundary values**: empty slices, `null`, `0`, `std.math.maxInt(T)`, empty strings.\n3. **Error cases**: error unions (`error.SomeError`), `catch unreachable` pitfalls, allocation failures.\n4. **Memory & safety**: memory leaks (`testing.allocator` + `defer`), slice bounds, integer overflow.\n\n### Phase 4: Code Generation\nOutput tests in this exact structure:\n```\n#### Test Strategy Summary\n- [ ] Scope: Unit \u002F Integration \u002F Comptime\n- [ ] Framework: built-in test runner + build.zig\n- [ ] Mocking: Yes\u002FNo — manual struct-based DI\n- [ ] Edge cases covered: \u003Clist>\n\n#### Generated Test Code\n\u003Cfile_path>\n\u003Ccode>\n\n#### Running Commands\n```bash\nzig test src\u002Fmain.zig\nzig test src\u002Fmain.zig -- --test-filter \"add\"\nzig build test\n```\n\n#### Coverage Impact (if applicable)\n- Estimated coverage change: \u003CX%>\n- Command to verify: `kcov --exclude-pattern=zig-cache coverage .\u002Fzig-out\u002Fbin\u002Ftest`\n```\n\n### Phase 5: Verification Checklist\nBefore completing, verify:\n- [ ] Tests compile and pass (`zig test src\u002Fmain.zig`).\n- [ ] Each test has exactly one logical assertion focus.\n- [ ] Allocators are properly deinitialized (`defer store.deinit()`).\n- [ ] No `std.time.sleep` used for synchronization (use atomic operations or event loops).\n- [ ] Flaky test guardrails applied (`testing.allocator`, deterministic seeds, no real network in unit tests).\n\n## TDD Workflow\n\n```zig\n\u002F\u002F src\u002Fmath.zig\nfn add(a: i32, b: i32) i32 { @compileError(\"stub\"); } \u002F\u002F stub\n\ntest \"adds two numbers\" { \u002F\u002F RED\n    try testing.expectEqual(add(2, 3), 5);\n}\n\n\u002F\u002F src\u002Fmath.zig\nfn add(a: i32, b: i32) i32 { return a + b; } \u002F\u002F GREEN\n\n\u002F\u002F REFACTOR: once tests pass\n```\n\n## Code Examples\n\n### Basic Unit Test\n\n```zig\n\u002F\u002F src\u002Fcalculator.zig\nconst std = @import(\"std\");\nconst testing = std.testing;\n\nfn add(a: i32, b: i32) i32 {\n    return a + b;\n}\n\ntest \"adds two numbers\" {\n    try testing.expectEqual(add(2, 3), 5);\n}\n\ntest \"handles negative numbers\" {\n    try testing.expectEqual(add(-1, 1), 0);\n}\n```\n\n### Multiple Test Files\n\n```zig\n\u002F\u002F test\u002Fmath_test.zig\nconst std = @import(\"std\");\nconst testing = std.testing;\nconst math = @import(\"..\u002Fsrc\u002Fmath.zig\");\n\ntest \"add returns correct sum\" {\n    try testing.expectEqual(math.add(2, 3), 5);\n}\n\ntest \"add handles negatives\" {\n    try testing.expectEqual(math.add(-1, 1), 0);\n}\n```\n\n### Allocator Testing\n\n```zig\n\u002F\u002F src\u002Fuser_store.zig\nconst std = @import(\"std\");\nconst testing = std.testing;\nconst Allocator = std.mem.Allocator;\n\nconst User = struct {\n    name: []const u8,\n};\n\nconst UserStore = struct {\n    allocator: Allocator,\n    users: std.ArrayList(User),\n\n    fn init(allocator: Allocator) UserStore {\n        return .{\n            .allocator = allocator,\n            .users = std.ArrayList(User).init(allocator),\n        };\n    }\n\n    fn deinit(self: *UserStore) void {\n        self.users.deinit();\n    }\n\n    fn seed(self: *UserStore, users: []const User) !void {\n        try self.users.appendSlice(users);\n    }\n\n    fn find(self: *UserStore, name: []const u8) ?User {\n        for (self.users.items) |user| {\n            if (std.mem.eql(u8, user.name, name)) return user;\n        }\n        return null;\n    }\n};\n\ntest \"finds existing user\" {\n    var store = UserStore.init(testing.allocator);\n    defer store.deinit();\n\n    try store.seed(&[_]User{\n        .{ .name = \"alice\" },\n        .{ .name = \"bob\" },\n    });\n\n    const user = store.find(\"alice\");\n    try testing.expect(user != null);\n    try testing.expectEqualStrings(\"alice\", user.?.name);\n}\n\ntest \"returns null for missing user\" {\n    var store = UserStore.init(testing.allocator);\n    defer store.deinit();\n\n    try testing.expect(store.find(\"charlie\") == null);\n}\n```\n\n### Error Testing\n\n```zig\ntest \"expect error\" {\n    const result = mightFail();\n    try testing.expectError(error.SomeError, result);\n}\n\nfn mightFail() !void {\n    return error.SomeError;\n}\n```\n\n### Comptime Test\n\n```zig\ntest \"compile-time evaluation\" {\n    const result = comptime add(2, 3);\n    try testing.expectEqual(result, 5);\n}\n```\n\n### Snapshot \u002F Approvals (Manual)\n\n```zig\ntest \"snapshot test\" {\n    const output = generateOutput();\n    const expected = @embedFile(\"snapshots\u002Ftest1.txt\");\n    try testing.expectEqualSlices(u8, expected, output);\n}\n```\n\n### Parametrized (Manual Loop)\n\n```zig\ntest \"add parametrized\" {\n    const cases = [_]struct { a: i32, b: i32, expected: i32 }{\n        .{ .a = 1, .b = 2, .expected = 3 },\n        .{ .a = -1, .b = 1, .expected = 0 },\n        .{ .a = 0, .b = 0, .expected = 0 },\n        .{ .a = 100, .b = 200, .expected = 300 },\n    };\n\n    for (cases) |c| {\n        const result = add(c.a, c.b);\n        try testing.expectEqual(c.expected, result);\n    }\n}\n```\n\n## Build.zig Configuration\n\n```zig\n\u002F\u002F build.zig\nconst std = @import(\"std\");\n\npub fn build(b: *std.Build) void {\n    const target = b.standardTargetOptions(.{});\n    const optimize = b.standardOptimizeOption(.{});\n\n    const exe = b.addExecutable(.{\n        .name = \"myapp\",\n        .root_source_file = .{ .path = \"src\u002Fmain.zig\" },\n        .target = target,\n        .optimize = optimize,\n    });\n\n    \u002F\u002F Test configuration\n    const exe_tests = b.addTest(.{\n        .root_source_file = .{ .path = \"src\u002Fmain.zig\" },\n        .target = target,\n        .optimize = optimize,\n    });\n\n    const test_step = b.step(\"test\", \"Run all tests\");\n    test_step.dependOn(&exe_tests.step);\n\n    \u002F\u002F Separate test files\n    inline for (&[_][]const u8{\n        \"test\u002Fmath_test.zig\",\n    }) |test_file| {\n        const t = b.addTest(.{\n            .root_source_file = .{ .path = test_file },\n            .target = target,\n            .optimize = optimize,\n        });\n        test_step.dependOn(&t.step);\n    }\n\n    b.default_step.dependOn(&exe.step);\n    b.installArtifact(exe);\n}\n```\n\n## Running Tests\n\n```bash\nzig test src\u002Fmain.zig                  # run all test blocks in file\nzig test src\u002Fmath.zig                  # run tests in specific file\nzig test src\u002Fmain.zig -- --test-filter \"add\"  # filter by name\nzig test src\u002Fmain.zig --test-no-exec   # compile-only check (CI)\nzig test src\u002Fmain.zig -lc              # link against libc if needed\nzig build test                         # if build.zig defines test step\n```\n\n## Coverage\n\nZig does not have built-in coverage. Use external tools:\n\n### kcov (Linux\u002FmacOS)\n\n```bash\n# 1. Install kcov\n# Ubuntu: sudo apt install kcov\n# macOS: brew install kcov\n\n# 2. Build a test binary (requires build.zig test step to produce executable)\nzig build test -Doptimize=Debug\n\n# 3. Run kcov against the test binary\nkcov --clean \\\n     --include-path=src\u002F \\\n     --exclude-pattern=zig-cache,test,test_ \\\n     coverage-report \\\n     .\u002Fzig-out\u002Fbin\u002Ftest\n\n# 4. View the report\n# open coverage-report\u002Findex.html\n```\n\n### zcoverage (community, cross-platform)\n\n```bash\n# https:\u002F\u002Fgithub.com\u002Fnicopap\u002Fzcoverage\nzig build test --summary all\nzcoverage .\u002Fzig-out\u002Fbin\u002Ftest\n```\n\n> **Interpreting results**: kcov shows line and branch coverage per file. Aim for ≥80% line coverage for critical code paths. The report highlights uncovered lines in red — focus on covering error paths and edge cases first.\n\n## Debugging Failures\n\n1. Re-run with `--test-filter` to isolate the failing test.\n2. Add `std.debug.print(\"{any}\\n\", .{value});` for debug output.\n3. Use `testing.allocator` with `--test-filter` for memory leak detection.\n4. Use `@import(\"std\").log` for scoped logging.\n5. Expand to full suite once the root cause is fixed.\n\n## CI\u002FCD Integration (GitHub Actions)\n\n```yaml\n# .github\u002Fworkflows\u002Ftest.yml\nname: Test\non: [push, pull_request]\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v4\n      - uses: goto-bus-stop\u002Fsetup-zig@v2\n        with: { version: '0.13.0' }\n      - run: zig build test --summary all\n```\n\n## Flaky Tests Guardrails\n\n- Never use `std.time.sleep` for synchronization; use atomic operations or event loops.\n- Use `testing.allocator` to detect memory leaks automatically.\n- Avoid real network or filesystem dependencies in unit tests.\n- Use `std.Random` with a deterministic seed from `testing.random`.\n\n## Test Case Design Patterns\n\nApply these systematic patterns before writing test code to ensure robust coverage beyond the happy path.\n\n### 1. Boundary Value Analysis\nTest at the edges of valid input domains: empty, zero, maximum, null, and just-outside valid ranges.\n\n```zig\n\u002F\u002F src\u002Fvalidator.zig\ntest \"rejects invalid input\" {\n    try testing.expectError(error.InvalidInput, validateInput(\"\"));\n    try testing.expectError(error.InvalidInput, validateInput(\" \"));\n    const long = \"a\" ** 10001;\n    try testing.expectError(error.InvalidInput, validateInput(long));\n}\n```\n\n### 2. Negative \u002F Error Case Testing\nVerify the system behaves correctly under invalid or unexpected conditions.\n\n```zig\n\u002F\u002F src\u002Fmath.zig\ntest \"divide by zero returns error\" {\n    try testing.expectError(error.DivideByZero, divide(10, 0));\n}\n```\n\n### 3. State-Based Testing\nFor objects with internal state, verify transitions between states are correct and irreversible where expected.\n\n```zig\n\u002F\u002F src\u002Fconnection.zig\ntest \"connection state transitions\" {\n    var conn = Connection.init(testing.allocator);\n    defer conn.deinit();\n    try testing.expectEqual(conn.state(), .closed);\n    try conn.open();\n    try testing.expectEqual(conn.state(), .open);\n    try conn.close();\n    try testing.expectEqual(conn.state(), .closed);\n    \u002F\u002F Idempotency\n    try conn.close();\n    try testing.expectEqual(conn.state(), .closed);\n}\n```\n\n## Common Test Smells to Avoid\n\n- **Assertion Roulette**: Many assertions without descriptive messages, making failure diagnosis ambiguous. *Fix: Use `testing.expectEqual(expected, actual)` with clear test block names and comments.*\n- **Happy Path Bias**: Only testing successful scenarios, leaving error paths uncovered. *Fix: Test `null` pointers, `error` unions with `expectError`, boundary values.*\n- **Mock Overdose**: Too many function-pointer fakes hiding integration issues. *Fix: Mock only at I\u002FO boundaries; test real implementations for pure logic.*\n- **The Free Ride**: Tests that execute code but assert nothing meaningful. *Fix: Every test must have at least one specific, falsifiable `testing.expect*` call.*\n- **Obscure Test**: Large test blocks with no clear setup\u002Fverify structure. *Fix: Follow AAA, use `defer` for cleanup, keep test blocks focused on single behavior.*\n- **Flaky Test**: Non-deterministic results from allocator state or shared mutability. *Fix: Use `testing.allocator` for leak detection, deterministic seeds, avoid shared mutable state.*\n\n## Best Practices\n\n### DO\n\n- Co-locate `test` blocks directly in source files for unit tests\n- Use `try testing.expectEqual` \u002F `try testing.expect` for assertions\n- Use `testing.allocator` for memory leak detection\n- Use `defer` for cleanup in tests\n- Separate integration tests in `test\u002F` directory\n- Use `@import` to bring in source files for external test files\n\n### DON'T\n\n- Don't use `std.time.sleep` for synchronization\n- Don't depend on real time, network, or external services in unit tests\n- Don't ignore memory leaks — always use `testing.allocator` for test allocations\n- Don't use `@panic` in test helpers — propagate errors with `try`\u002F`!`\n- Don't write tests that depend on test execution order\n\n### Common Pitfalls\n\n- **Memory leaks** → Always use `testing.allocator` and ensure `deinit` is called.\n- **No isolated allocators** → Pass allocators explicitly rather than using global ones.\n- **Flaky file system tests** → Use `std.testing.tmpDir` or `std.fs.cwd().openDir`.\n- **Over-reliance on `@embedFile`** → Keep snapshot files under version control.\n- **Missing `try` in test assertions** → Always prefix assertion calls with `try`.\n- **Slow compile times** → Separate large test files from frequently changed source files.\n\n## Optional: Fuzzing\n\nZig's test framework can be used for fuzz-like testing with random inputs:\n\n```zig\ntest \"fuzz add\" {\n    var prng = std.rand.DefaultPrng.init(42);\n    const random = prng.random();\n\n    var i: usize = 0;\n    while (i \u003C 1000) : (i += 1) {\n        const a = random.int(i32);\n        const b = random.int(i32);\n        const result = add(a, b);\n        \u002F\u002F property: a + b == b + a\n        try testing.expectEqual(result, add(b, a));\n    }\n}\n```\n\n## Optional: Property-Based Testing\n\nZig supports property-based testing via manual random input generation. Use `std.Random` with a fixed seed for reproducibility:\n\n```zig\nconst std = @import(\"std\");\nconst testing = std.testing;\n\nfn add(a: i32, b: i32) i32 { return a + b; }\n\ntest \"add is commutative (property)\" {\n    var prng = std.Random.DefaultPrng.init(42);\n    const rand = prng.random();\n    for (0..1000) |_| {\n        const a = rand.int(i32);\n        const b = rand.int(i32);\n        try testing.expectEqual(add(a, b), add(b, a));\n    }\n}\n\ntest \"add identity (property)\" {\n    var prng = std.Random.DefaultPrng.init(42);\n    const rand = prng.random();\n    for (0..1000) |_| {\n        const a = rand.int(i32);\n        try testing.expectEqual(add(a, 0), a);\n    }\n}\n```\n\n> **Best practice**: Use deterministic seeds for reproducibility, run ≥1000 trials, and test mathematical invariants (commutativity, associativity, identity).\n","# Zig Testing (Agent Skill)\n\nAgent-focused testing workflow for Zig using the built-in test framework — zero dependencies, first-class language support with `comptime` test discovery.\n\n## When to Use\n\n- Writing new Zig tests or fixing existing tests\n- Designing unit\u002Fintegration test coverage for Zig components\n- Adding test coverage, CI gating, or regression protection\n- Configuring `zig test` workflows for consistent execution\n- Investigating test failures\n- Testing system-level or embedded Zig code\n\n### When NOT to Use\n\n- Implementing new product features without test changes\n- Large-scale refactors unrelated to test coverage or failures\n- Performance tuning without test regressions to validate\n- Non-Zig projects or non-test tasks\n\n### Stop Conditions — When to ASK instead of generating\n\nBefore generating any test code, STOP and ask the user if:\n- The code under test has **zero testability** (all comptime, no runtime public API, hard-coded system calls)\n- **No test blocks** exist in the project and no test step in build.zig\n- The request is **ambiguous**: \"test my code\" or \"add tests\" without specifying files or functions\n- The code requires **external tooling not yet configured** (kcov, zcoverage)\n- The test would require **secrets, real credentials, or production system access**\n\n## Core Concepts\n\n- **TDD loop**: red → green → refactor (tests first, minimal fix, then cleanups).\n- **First-class tests**: `test` blocks are language built-ins, discovered by `zig test`.\n- **Comptime evaluation**: tests can run at compile time via `comptime`.\n- **Test layout**: tests co-located with source using `test` blocks, or in separate `test\u002F` files.\n- **No external framework**: everything is built into the Zig compiler.\n- **CI signal**: `zig test src\u002Fmain.zig` with `--test-no-exec` for compile-time checks.\n\n## Agent Execution Protocol\n\nWhen this skill is activated, follow this exact execution sequence:\n\n### Phase 1: Context Analysis\nBefore writing any test code:\n1. Identify the Zig version (0.13+\u002Fmaster) and build configuration (`build.zig`).\n2. Check for existing test files (`test` blocks in source, `test\u002F`, `*_test.zig`) to infer style.\n3. Analyze the code under test: identify public API surface, allocator usage, `comptime` evaluation, and I\u002FO boundaries.\n4. Determine request type: (a) new tests, (b) fixing broken tests, (c) coverage improvement, (d) flaky test diagnosis.\n\n### Phase 2: Strategy Selection\nBased on Phase 1, select the appropriate strategy:\n- **Pure functions \u002F utilities**: co-located `test` blocks in source files, no mocks. Use `testing.expectEqual`.\n- **External dependencies (I\u002FO, network)**: use interfaces (structs with function pointers) for dependency injection; write manual test doubles.\n- **Allocator-dependent code**: always use `testing.allocator` to detect memory leaks automatically.\n- **Comptime code**: use `comptime` test blocks to validate compile-time logic.\n\n### Decision Tree (Complex Scenarios)\n\n```text\nQ1: External I\u002FO (filesystem, network, hardware)?\n  → Yes → Q2\n  → No  → Pure unit test, no mocks needed\n\nQ2: Mockable (function pointer struct, comptime interface)?\n  → Yes → Manual test double via function pointer injection\n  → No  → Q3\n\nQ3: Allocator-dependent code?\n  → Yes → Always use testing.allocator for leak detection\n  → No  → Standard test block\n\nQ4: Compile-time validation?\n  → Yes → comptime test block\n  → No  → Q5\n\nQ5: Snapshot\u002Ferror union testing?\n  → Yes → @embedFile for snapshots, expectError for error cases\n  → No  → Standard testing.expectEqual\n```\n\n### Phase 3: Test Case Design\nApply systematic test design before coding:\n1. **Happy path**: normal input → expected output.\n2. **Boundary values**: empty slices, `null`, `0`, `std.math.maxInt(T)`, empty strings.\n3. **Error cases**: error unions (`error.SomeError`), `catch unreachable` pitfalls, allocation failures.\n4. **Memory & safety**: memory leaks (`testing.allocator` + `defer`), slice bounds, integer overflow.\n\n### Phase 4: Code Generation\nOutput tests in this exact structure:\n```\n#### Test Strategy Summary\n- [ ] Scope: Unit \u002F Integration \u002F Comptime\n- [ ] Framework: built-in test runner + build.zig\n- [ ] Mocking: Yes\u002FNo — manual struct-based DI\n- [ ] Edge cases covered: \u003Clist>\n\n#### Generated Test Code\n\u003Cfile_path>\n\u003Ccode>\n\n#### Running Commands\n```bash\nzig test src\u002Fmain.zig\nzig test src\u002Fmain.zig -- --test-filter \"add\"\nzig build test\n```\n\n#### Coverage Impact (if applicable)\n- Estimated coverage change: \u003CX%>\n- Command to verify: `kcov --exclude-pattern=zig-cache coverage .\u002Fzig-out\u002Fbin\u002Ftest`\n```\n\n### Phase 5: Verification Checklist\nBefore completing, verify:\n- [ ] Tests compile and pass (`zig test src\u002Fmain.zig`).\n- [ ] Each test has exactly one logical assertion focus.\n- [ ] Allocators are properly deinitialized (`defer store.deinit()`).\n- [ ] No `std.time.sleep` used for synchronization (use atomic operations or event loops).\n- [ ] Flaky test guardrails applied (`testing.allocator`, deterministic seeds, no real network in unit tests).\n\n## TDD Workflow\n\n```zig\n\u002F\u002F src\u002Fmath.zig\nfn add(a: i32, b: i32) i32 { @compileError(\"stub\"); } \u002F\u002F stub\n\ntest \"adds two numbers\" { \u002F\u002F RED\n    try testing.expectEqual(add(2, 3), 5);\n}\n\n\u002F\u002F src\u002Fmath.zig\nfn add(a: i32, b: i32) i32 { return a + b; } \u002F\u002F GREEN\n\n\u002F\u002F REFACTOR: once tests pass\n```\n\n## Code Examples\n\n### Basic Unit Test\n\n```zig\n\u002F\u002F src\u002Fcalculator.zig\nconst std = @import(\"std\");\nconst testing = std.testing;\n\nfn add(a: i32, b: i32) i32 {\n    return a + b;\n}\n\ntest \"adds two numbers\" {\n    try testing.expectEqual(add(2, 3), 5);\n}\n\ntest \"handles negative numbers\" {\n    try testing.expectEqual(add(-1, 1), 0);\n}\n```\n\n### Multiple Test Files\n\n```zig\n\u002F\u002F test\u002Fmath_test.zig\nconst std = @import(\"std\");\nconst testing = std.testing;\nconst math = @import(\"..\u002Fsrc\u002Fmath.zig\");\n\ntest \"add returns correct sum\" {\n    try testing.expectEqual(math.add(2, 3), 5);\n}\n\ntest \"add handles negatives\" {\n    try testing.expectEqual(math.add(-1, 1), 0);\n}\n```\n\n### Allocator Testing\n\n```zig\n\u002F\u002F src\u002Fuser_store.zig\nconst std = @import(\"std\");\nconst testing = std.testing;\nconst Allocator = std.mem.Allocator;\n\nconst User = struct {\n    name: []const u8,\n};\n\nconst UserStore = struct {\n    allocator: Allocator,\n    users: std.ArrayList(User),\n\n    fn init(allocator: Allocator) UserStore {\n        return .{\n            .allocator = allocator,\n            .users = std.ArrayList(User).init(allocator),\n        };\n    }\n\n    fn deinit(self: *UserStore) void {\n        self.users.deinit();\n    }\n\n    fn seed(self: *UserStore, users: []const User) !void {\n        try self.users.appendSlice(users);\n    }\n\n    fn find(self: *UserStore, name: []const u8) ?User {\n        for (self.users.items) |user| {\n            if (std.mem.eql(u8, user.name, name)) return user;\n        }\n        return null;\n    }\n};\n\ntest \"finds existing user\" {\n    var store = UserStore.init(testing.allocator);\n    defer store.deinit();\n\n    try store.seed(&[_]User{\n        .{ .name = \"alice\" },\n        .{ .name = \"bob\" },\n    });\n\n    const user = store.find(\"alice\");\n    try testing.expect(user != null);\n    try testing.expectEqualStrings(\"alice\", user.?.name);\n}\n\ntest \"returns null for missing user\" {\n    var store = UserStore.init(testing.allocator);\n    defer store.deinit();\n\n    try testing.expect(store.find(\"charlie\") == null);\n}\n```\n\n### Error Testing\n\n```zig\ntest \"expect error\" {\n    const result = mightFail();\n    try testing.expectError(error.SomeError, result);\n}\n\nfn mightFail() !void {\n    return error.SomeError;\n}\n```\n\n### Comptime Test\n\n```zig\ntest \"compile-time evaluation\" {\n    const result = comptime add(2, 3);\n    try testing.expectEqual(result, 5);\n}\n```\n\n### Snapshot \u002F Approvals (Manual)\n\n```zig\ntest \"snapshot test\" {\n    const output = generateOutput();\n    const expected = @embedFile(\"snapshots\u002Ftest1.txt\");\n    try testing.expectEqualSlices(u8, expected, output);\n}\n```\n\n### Parametrized (Manual Loop)\n\n```zig\ntest \"add parametrized\" {\n    const cases = [_]struct { a: i32, b: i32, expected: i32 }{\n        .{ .a = 1, .b = 2, .expected = 3 },\n        .{ .a = -1, .b = 1, .expected = 0 },\n        .{ .a = 0, .b = 0, .expected = 0 },\n        .{ .a = 100, .b = 200, .expected = 300 },\n    };\n\n    for (cases) |c| {\n        const result = add(c.a, c.b);\n        try testing.expectEqual(c.expected, result);\n    }\n}\n```\n\n## Build.zig Configuration\n\n```zig\n\u002F\u002F build.zig\nconst std = @import(\"std\");\n\npub fn build(b: *std.Build) void {\n    const target = b.standardTargetOptions(.{});\n    const optimize = b.standardOptimizeOption(.{});\n\n    const exe = b.addExecutable(.{\n        .name = \"myapp\",\n        .root_source_file = .{ .path = \"src\u002Fmain.zig\" },\n        .target = target,\n        .optimize = optimize,\n    });\n\n    \u002F\u002F Test configuration\n    const exe_tests = b.addTest(.{\n        .root_source_file = .{ .path = \"src\u002Fmain.zig\" },\n        .target = target,\n        .optimize = optimize,\n    });\n\n    const test_step = b.step(\"test\", \"Run all tests\");\n    test_step.dependOn(&exe_tests.step);\n\n    \u002F\u002F Separate test files\n    inline for (&[_][]const u8{\n        \"test\u002Fmath_test.zig\",\n    }) |test_file| {\n        const t = b.addTest(.{\n            .root_source_file = .{ .path = test_file },\n            .target = target,\n            .optimize = optimize,\n        });\n        test_step.dependOn(&t.step);\n    }\n\n    b.default_step.dependOn(&exe.step);\n    b.installArtifact(exe);\n}\n```\n\n## Running Tests\n\n```bash\nzig test src\u002Fmain.zig                  # run all test blocks in file\nzig test src\u002Fmath.zig                  # run tests in specific file\nzig test src\u002Fmain.zig -- --test-filter \"add\"  # filter by name\nzig test src\u002Fmain.zig --test-no-exec   # compile-only check (CI)\nzig test src\u002Fmain.zig -lc              # link against libc if needed\nzig build test                         # if build.zig defines test step\n```\n\n## Coverage\n\nZig does not have built-in coverage. Use external tools:\n\n### kcov (Linux\u002FmacOS)\n\n```bash\n# 1. Install kcov\n# Ubuntu: sudo apt install kcov\n# macOS: brew install kcov\n\n# 2. Build a test binary (requires build.zig test step to produce executable)\nzig build test -Doptimize=Debug\n\n# 3. Run kcov against the test binary\nkcov --clean \\\n     --include-path=src\u002F \\\n     --exclude-pattern=zig-cache,test,test_ \\\n     coverage-report \\\n     .\u002Fzig-out\u002Fbin\u002Ftest\n\n# 4. View the report\n# open coverage-report\u002Findex.html\n```\n\n### zcoverage (community, cross-platform)\n\n```bash\n# https:\u002F\u002Fgithub.com\u002Fnicopap\u002Fzcoverage\nzig build test --summary all\nzcoverage .\u002Fzig-out\u002Fbin\u002Ftest\n```\n\n> **Interpreting results**: kcov shows line and branch coverage per file. Aim for ≥80% line coverage for critical code paths. The report highlights uncovered lines in red — focus on covering error paths and edge cases first.\n\n## Debugging Failures\n\n1. Re-run with `--test-filter` to isolate the failing test.\n2. Add `std.debug.print(\"{any}\\n\", .{value});` for debug output.\n3. Use `testing.allocator` with `--test-filter` for memory leak detection.\n4. Use `@import(\"std\").log` for scoped logging.\n5. Expand to full suite once the root cause is fixed.\n\n## CI\u002FCD Integration (GitHub Actions)\n\n```yaml\n# .github\u002Fworkflows\u002Ftest.yml\nname: Test\non: [push, pull_request]\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v4\n      - uses: goto-bus-stop\u002Fsetup-zig@v2\n        with: { version: '0.13.0' }\n      - run: zig build test --summary all\n```\n\n## Flaky Tests Guardrails\n\n- Never use `std.time.sleep` for synchronization; use atomic operations or event loops.\n- Use `testing.allocator` to detect memory leaks automatically.\n- Avoid real network or filesystem dependencies in unit tests.\n- Use `std.Random` with a deterministic seed from `testing.random`.\n\n## Test Case Design Patterns\n\nApply these systematic patterns before writing test code to ensure robust coverage beyond the happy path.\n\n### 1. Boundary Value Analysis\nTest at the edges of valid input domains: empty, zero, maximum, null, and just-outside valid ranges.\n\n```zig\n\u002F\u002F src\u002Fvalidator.zig\ntest \"rejects invalid input\" {\n    try testing.expectError(error.InvalidInput, validateInput(\"\"));\n    try testing.expectError(error.InvalidInput, validateInput(\" \"));\n    const long = \"a\" ** 10001;\n    try testing.expectError(error.InvalidInput, validateInput(long));\n}\n```\n\n### 2. Negative \u002F Error Case Testing\nVerify the system behaves correctly under invalid or unexpected conditions.\n\n```zig\n\u002F\u002F src\u002Fmath.zig\ntest \"divide by zero returns error\" {\n    try testing.expectError(error.DivideByZero, divide(10, 0));\n}\n```\n\n### 3. State-Based Testing\nFor objects with internal state, verify transitions between states are correct and irreversible where expected.\n\n```zig\n\u002F\u002F src\u002Fconnection.zig\ntest \"connection state transitions\" {\n    var conn = Connection.init(testing.allocator);\n    defer conn.deinit();\n    try testing.expectEqual(conn.state(), .closed);\n    try conn.open();\n    try testing.expectEqual(conn.state(), .open);\n    try conn.close();\n    try testing.expectEqual(conn.state(), .closed);\n    \u002F\u002F Idempotency\n    try conn.close();\n    try testing.expectEqual(conn.state(), .closed);\n}\n```\n\n## Common Test Smells to Avoid\n\n- **Assertion Roulette**: Many assertions without descriptive messages, making failure diagnosis ambiguous. *Fix: Use `testing.expectEqual(expected, actual)` with clear test block names and comments.*\n- **Happy Path Bias**: Only testing successful scenarios, leaving error paths uncovered. *Fix: Test `null` pointers, `error` unions with `expectError`, boundary values.*\n- **Mock Overdose**: Too many function-pointer fakes hiding integration issues. *Fix: Mock only at I\u002FO boundaries; test real implementations for pure logic.*\n- **The Free Ride**: Tests that execute code but assert nothing meaningful. *Fix: Every test must have at least one specific, falsifiable `testing.expect*` call.*\n- **Obscure Test**: Large test blocks with no clear setup\u002Fverify structure. *Fix: Follow AAA, use `defer` for cleanup, keep test blocks focused on single behavior.*\n- **Flaky Test**: Non-deterministic results from allocator state or shared mutability. *Fix: Use `testing.allocator` for leak detection, deterministic seeds, avoid shared mutable state.*\n\n## Best Practices\n\n### DO\n\n- Co-locate `test` blocks directly in source files for unit tests\n- Use `try testing.expectEqual` \u002F `try testing.expect` for assertions\n- Use `testing.allocator` for memory leak detection\n- Use `defer` for cleanup in tests\n- Separate integration tests in `test\u002F` directory\n- Use `@import` to bring in source files for external test files\n\n### DON'T\n\n- Don't use `std.time.sleep` for synchronization\n- Don't depend on real time, network, or external services in unit tests\n- Don't ignore memory leaks — always use `testing.allocator` for test allocations\n- Don't use `@panic` in test helpers — propagate errors with `try`\u002F`!`\n- Don't write tests that depend on test execution order\n\n### Common Pitfalls\n\n- **Memory leaks** → Always use `testing.allocator` and ensure `deinit` is called.\n- **No isolated allocators** → Pass allocators explicitly rather than using global ones.\n- **Flaky file system tests** → Use `std.testing.tmpDir` or `std.fs.cwd().openDir`.\n- **Over-reliance on `@embedFile`** → Keep snapshot files under version control.\n- **Missing `try` in test assertions** → Always prefix assertion calls with `try`.\n- **Slow compile times** → Separate large test files from frequently changed source files.\n\n## Optional: Fuzzing\n\nZig's test framework can be used for fuzz-like testing with random inputs:\n\n```zig\ntest \"fuzz add\" {\n    var prng = std.rand.DefaultPrng.init(42);\n    const random = prng.random();\n\n    var i: usize = 0;\n    while (i \u003C 1000) : (i += 1) {\n        const a = random.int(i32);\n        const b = random.int(i32);\n        const result = add(a, b);\n        \u002F\u002F property: a + b == b + a\n        try testing.expectEqual(result, add(b, a));\n    }\n}\n```\n\n## Optional: Property-Based Testing\n\nZig supports property-based testing via manual random input generation. Use `std.Random` with a fixed seed for reproducibility:\n\n```zig\nconst std = @import(\"std\");\nconst testing = std.testing;\n\nfn add(a: i32, b: i32) i32 { return a + b; }\n\ntest \"add is commutative (property)\" {\n    var prng = std.Random.DefaultPrng.init(42);\n    const rand = prng.random();\n    for (0..1000) |_| {\n        const a = rand.int(i32);\n        const b = rand.int(i32);\n        try testing.expectEqual(add(a, b), add(b, a));\n    }\n}\n\ntest \"add identity (property)\" {\n    var prng = std.Random.DefaultPrng.init(42);\n    const rand = prng.random();\n    for (0..1000) |_| {\n        const a = rand.int(i32);\n        try testing.expectEqual(add(a, 0), a);\n    }\n}\n```\n\n> **Best practice**: Use deterministic seeds for reproducibility, run ≥1000 trials, and test mathematical invariants (commutativity, associativity, identity).\n",{"name":5,"metadata":24,"description":27,"compatibility":28},{"author":25,"source":26},"github-spec-kit","templates\u002Fpassive-skills\u002Fzig-testing\u002FSKILL.md","Use ONLY when user explicitly requests Zig test code, built-in test runner configuration, test failure diagnosis, or coverage for Zig projects.\nTriggers: \"write test zig\", \"zig test\", \"testing.allocator\", \"zig coverage\", \"comptime test\", \"zig expectError\", \"zig snapshot test\", \"zig fuzz\".\nDo NOT activate for: general Zig coding without test context, build.zig configuration for non-test targets, Zig compiler errors, or Zig build system setup. ","Requires spec-kit project structure with .specify\u002F directory","main","021f5cbe02157229460a577e9a585f2da6d78cb0",".claude\u002Fskills\u002Fzig-testing","https:\u002F\u002Fgithub.com\u002Fchenziyang110\u002Flaunchdeck","https:\u002F\u002Fgithub.com\u002Fchenziyang110","2026-08-07 18:10:54",{"source":8,"skillName":5,"commands":36,"prompt":46,"zipAvailable":47},[37,40,43],{"tool":38,"command":39},"npx","npx skills add chenziyang110\u002Flaunchdeck --skill zig-testing",{"tool":41,"command":42},"bunx","bunx skills add chenziyang110\u002Flaunchdeck --skill zig-testing",{"tool":44,"command":45},"pnpm","pnpm dlx skills add chenziyang110\u002Flaunchdeck --skill zig-testing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fchenziyang110\u002Flaunchdeck\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fzig-testing\u002FSKILL.md",true,[],[50,57,63,69,75,84],{"skillNo":51,"name":52,"nameZh":6,"description":53,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":19},"01M7875F3HQ1GF5F6BR36KY3JE","launchdeck-agent","Codex host adapter contract fixture for Launchdeck.","https:\u002F\u002Fgithub.com\u002Fchenziyang110\u002Flaunchdeck\u002Fblob\u002Fmain\u002Ftest\u002Ffixtures\u002Fagent-hosts\u002Fcodex\u002Fskill\u002FSKILL.md",[],[],{"skillNo":58,"name":52,"nameZh":6,"description":59,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":19},"01M7875DV2DQR33K1NFJHKAMZP","Claude host adapter contract fixture for Launchdeck.","https:\u002F\u002Fgithub.com\u002Fchenziyang110\u002Flaunchdeck\u002Fblob\u002Fmain\u002Ftest\u002Ffixtures\u002Fagent-hosts\u002Fclaude\u002Fskill\u002FSKILL.md",[],[],{"skillNo":64,"name":52,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M78759JQ7A6FQ8KDQTNYS3X9","Use this skill aggressively for local project lifecycle operations even when the user does not mention Launchdeck: start this project, run the dev server, dev, build, test, restart service, stop service, show logs, inspect ports, port is occupied, clean cache; and when the user explicitly asks to configure this local project for Launchdeck or create or generate a project-adapted `.launchdeck.yml`, including 为这个项目生成 Launchdeck 配置. Do not use for ordinary code edits, docs-only work, general explanations, API design discussion, or production deployment unless the user also asks to operate or configure a local project or service.","https:\u002F\u002Fgithub.com\u002Fchenziyang110\u002Flaunchdeck\u002Fblob\u002Fmain\u002Fagent\u002Finstaller-payload\u002Fskill\u002Flaunchdeck-agent\u002FSKILL.md",[],[],{"skillNo":70,"name":5,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M78753ZJQ7G2CZT1W1G8WRJV","Use ONLY when user explicitly requests Zig test code, built-in test runner configuration,\ntest failure diagnosis, or coverage for Zig projects.\n\nTriggers: \"write test zig\", \"zig test\", \"testing.allocator\", \"zig coverage\",\n\"comptime test\", \"zig expectError\", \"zig snapshot test\", \"zig fuzz\".\n\nDo NOT activate for: general Zig coding without test context, build.zig configuration\nfor non-test targets, Zig compiler errors, or Zig build system setup.","https:\u002F\u002Fgithub.com\u002Fchenziyang110\u002Flaunchdeck\u002Fblob\u002Fmain\u002F.specify\u002Ftemplates\u002Fpassive-skills\u002Fzig-testing\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":79,"licenseFileUrl":80,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M78750JXY4Z5D5W1EX3PQ31Z","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fchenziyang110\u002Flaunchdeck\u002Fblob\u002Fmain\u002F.specify\u002Ftemplates\u002Fpassive-skills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fchenziyang110\u002Flaunchdeck\u002Fblob\u002Fmain\u002F.specify\u002Ftemplates\u002Fpassive-skills\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M7874X2T83EQQFRCEY5SJJVC","verification-before-completion","Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always","https:\u002F\u002Fgithub.com\u002Fchenziyang110\u002Flaunchdeck\u002Fblob\u002Fmain\u002F.specify\u002Ftemplates\u002Fpassive-skills\u002Fverification-before-completion\u002FSKILL.md",[],[]]