[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-107937":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":14,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":16,"rankGlobal":9,"rankLanguage":9,"license":17,"archived":18,"fork":18,"defaultBranch":19,"hasWiki":20,"hasPages":18,"topics":21,"createdAt":9,"pushedAt":22,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":15,"starSnapshotCount":15,"syncStatus":26,"lastSyncTime":27,"discoverSource":28},107937,"mutant-cafe","joelhooks\u002Fmutant-cafe","joelhooks","🧀 mutation testing for Effect TypeScript",null,"TypeScript",65,3,1,4,0,42.21,"MIT License",false,"main",true,[],"2026-11-14 19:37:45","2026-11-11 15:43:45","# mutant.cafe\n\n![MUTANT CAFE: a feral rat leaping a row of snap traps, some sprung and some not](https:\u002F\u002Fraw.githubusercontent.com\u002Fjoelhooks\u002Fmutant-cafe\u002Fmain\u002Fassets\u002Fbanner.jpg)\n\nMutation testing for [Effect](https:\u002F\u002Feffect.website) TypeScript. mutant.cafe reads your types, breaks your functions in ways that still type-check, runs the tests related to each break, and lists the breaks your tests miss.\n\nmutant.cafe is part of [rat-stack](https:\u002F\u002Fratstack.sh).\n\nIt is inspired by [cargo-mutants](https:\u002F\u002Fmutants.rs) by Martin Pool ([source](https:\u002F\u002Fgithub.com\u002Fsourcefrog\u002Fcargo-mutants), MIT). The core idea, replacing a function body with a plausible value of its return type and reporting what the tests don't notice, comes from cargo-mutants, and so does the operator experience: a baseline run first, a scratch copy of your tree, per-mutant timeouts, `--in-diff`, and a `mutants.out` directory of results. mutant.cafe ports those ideas to Effect; it shares no code with cargo-mutants.\n\n## What it adds for Effect\n\nAn `Effect\u003CA, E, R>` declares its failures in `E`. For each tagged error in `E`, mutant.cafe makes a mutant that swallows that error and succeeds instead. If no value of `A` can be synthesized, a separate `TagToDefect` mutant turns that tag into a defect. That is not a successful recovery: it checks whether tests distinguish typed failures from defects, rather than only asserting `Exit.isFailure`.\n\nOther mutants, all chosen from the checker's view of the return type:\n\n- `Effect.succeed(value)` for plausible values of `A`, `Effect.fail` of each tag, `Effect.die`, and `Effect.never` behind a measured timeout\n- `Option.none()` and `Option.some(value)`\n- `Stream.empty`, a one-element stream, and a failing stream\n- a `Layer` that dies at build, even when its error type is `never`, plus one failing build per error tag\n- flipped booleans and cycled literal unions\n\n## Use it\n\nNeeds Node 24 or later, a `tsconfig.json`, and a vitest suite that passes.\n\n```sh\nnpm install -D mutant-cafe\nnpx mutant-cafe --list      # preview the mutants\nnpx mutant-cafe --jobs 4    # test them\n```\n\nIt mutates internal functions by default, including `Effect.fn` and `Effect.fnUntraced`, object-literal arrows, service methods inside Layers, and the inner function of a curried export. Layer values and static Layer properties are targets too. Names follow their path, such as `Greeter.layer.greet`, `policy.canEdit`, and `guardFor.\u003Cinner>`. With `--exported-only`, targets must be reachable through an exported binding path: exported top-level functions, methods and functions in exported values, returned curried functions, and exported Layers with their returned service methods. Local declarations and arrows inside other function bodies are internal, even if their owner is exported. This keeps local helpers out without dropping exported object or service APIs.\n\nValue synthesis includes branded strings and numbers, empty sets and maps, anonymous objects with cycled literal fields, and every assignable parameter as an identity replacement, named by the parameter. Boolean and literal unions with up to eight members are exhaustive, excluding an obvious original constant. Swallow mutants enumerate recoveries only for genuinely finite success types with at most four members, including both booleans. Numbers, strings, structs, Json and larger finite sets use one representative per error tag. Larger or recursive shapes have at most six synthesized representatives per function and genre, plus `undefined` when present. For `Schema.Json`, these are `null`, `\"\"`, `0`, `false`, `[]` and `{}`. Capped tagged unions keep the original body's discriminant first, with fields emptied, then other variants in declaration order. Synthesis stops beyond depth four or 2 KiB of printed value text and records the bound. Assignable-parameter identities are separate from the literal cap. Values differing only by `as const` or redundant parentheses generate one mutant. Naked type-parameter returns get no fabricated values, but a same-typed parameter can still supply an identity mutant. Context-only generic types that cannot be named in the body are skipped with a reason. Literal leaves keep their type without making mutable arrays readonly. Generator mutants use the body's type before `Effect.fn` pipeables such as `Effect.scoped` or `Effect.map`.\n\nRun it from the package whose tests you want to check. In a monorepo that resolves workspace packages through built output, build the package's dependencies first.\n\n| Flag | Meaning |\n| --- | --- |\n| `--list` | print mutants, per-file counts, the total and the not-mutated count, then exit |\n| `--exported-only` | only exported binding paths, curried returns and Layer service methods; exclude local helpers |\n| `--in-diff \u003Cfile>` | only mutants on lines a unified diff adds or changes |\n| `--in-diff-range \u003CA...B or A..B>` | select from `git diff` run at the repository root; exclusive with `--in-diff` |\n| `--max-mutants \u003Cn>` | keep the first n selected mutants in repository path, line, column, id order |\n| `--format \u003Ctext or json or github>` | text by default; JSON for `--list`; Markdown for GitHub |\n| `--summary-md \u003Cfile>` | write the Markdown summary to a file |\n| `--summary-marker \u003Ctext>` | override the first-line `\u003C!-- mutant.cafe -->` marker |\n| `--advisory` | exit 0 for outcomes and baseline failure; usage and internal errors still fail |\n| `--file \u003Cglob>`, `--exclude \u003Cglob>` | choose source files (repeatable) |\n| `--jobs \u003Cn>` | scratch copies tested in parallel |\n| `--timeout \u003Cs>` | per-mutant test timeout; default 5× the baseline run, at least 20 s |\n| `--timeout-multiplier \u003Cx>`, `--minimum-test-timeout \u003Cs>` | tune that default |\n| `--output \u003Cdir>` | results directory, default `mutants.out` |\n| `--tsconfig \u003Cpath>` | default `tsconfig.json` |\n\n## CI\n\nUse a git range to check changed bodies and a mutant budget to cap the work. The budget applies after file, diff and function selection. Ordering uses repository-relative file path (lexical, not locale-dependent), start line, column, then id. `--max-mutants 0` keeps none. Budget-skipped mutants are not outcomes.\n\nThis advisory GitHub Actions job writes a step summary and updates one sticky PR comment. Install mutant-cafe as a dev dependency first. Replace `npm ci` with your package manager's install command if needed; run the mutation command from the package you want to test.\n\n```yaml\nname: Mutation advisory\non: pull_request\npermissions:\n  contents: read\n  pull-requests: write\njobs:\n  mutants:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v4\n        with:\n          fetch-depth: 0\n      - uses: actions\u002Fsetup-node@v4\n        with:\n          node-version: 24\n      - run: npm ci\n      - name: Check changed bodies\n        run: >-\n          npx --no-install mutant-cafe\n          --in-diff-range \"origin\u002F${{ github.base_ref }}...HEAD\"\n          --max-mutants 40 --format github --advisory\n          --summary-md mutant-summary.md\n      - name: Update sticky comment\n        if: github.event.pull_request.head.repo.full_name == github.repository\n        uses: actions\u002Fgithub-script@v7\n        with:\n          script: |\n            const fs = require('node:fs');\n            const body = fs.readFileSync('mutant-summary.md', 'utf8');\n            const marker = '\u003C!-- mutant.cafe -->';\n            const { owner, repo } = context.repo;\n            const issue_number = context.issue.number;\n            const comments = await github.paginate(github.rest.issues.listComments, {\n              owner, repo, issue_number\n            });\n            const previous = comments.find(comment =>\n              comment.user.type === 'Bot' && comment.body?.startsWith(marker)\n            );\n            if (previous) {\n              await github.rest.issues.updateComment({\n                owner, repo, comment_id: previous.id, body\n              });\n            } else {\n              await github.rest.issues.createComment({ owner, repo, issue_number, body });\n            }\n```\n\nFork PRs still get the step summary; the example only posts comments on same-repository PRs. Do not switch this job to `pull_request_target` to grant untrusted PR code a write token. If a job or matrix tests multiple packages, give each summary a distinct `--summary-marker` and match that marker in the comment step.\n\n`--format github` prints Markdown and writes the same content to `GITHUB_STEP_SUMMARY` when set. `--summary-md` also works with the default text output. The first line is `\u003C!-- mutant.cafe -->` unless overridden. The summary counts all outcomes, lists up to 50 missed, timeout, untested and unreliable mutants with repository-root-relative paths, and says what would have failed without `--advisory`. Advisory mode does not hide bad arguments, bad refs, source errors or internal errors.\n\nFor automation without running tests, `--list --format json` prints one JSON document: `schemaVersion`, `tool`, `mutants` (the same `Mutant` shape used by report results), `notMutated`, and `counts` with `selected`, `run` and `budgetSkipped`. `selected` is the count before the budget; `run` is zero for a list and the number of recorded outcomes for an execution. The published `MutantList` and `RunReport` schemas are exported by `@mutant-cafe\u002Fcore` in this workspace. Reports keep schema version 2: `selected`, `run` and `budgetSkipped` are additive optional fields, so older v2 reports still decode.\n\n## Outputs\n\nMutant ids are stable within a version and may change between versions before 1.0. An import-adding mutant hashes its logical edit, not the retained file prefix, so edits above its binding do not change its id.\n\nResults land in `mutants.out\u002F`: `missed.txt`, `caught.txt`, `timeout.txt`, `unviable.txt`, `untested.txt`, `unreliable.txt`, `not-mutated.txt`, a context diff and a log per mutant, and `outcomes.json`. Every result line includes the mutant id used by `diff\u002F\u003Cid>.diff` and `logs\u002F\u003Cid>.log`. Lines show the declared return type when available, or an abbreviated inferred type; JSON keeps full types and uses report `schemaVersion: 2`. Add `mutants.out*` to `.gitignore`. Your source tree is never edited: each mutant runs in a scratch copy. Workspace dependency links back into the copied source tree, including package self-links, point at the scratch packages rather than the originals. Mutation imports are added when the file has no usable value import for an Effect API.\n\n`not-mutated.txt` gives one located line per considered function or Layer value with omitted mutations: `file:line:column`, target path and reason. Layer values use their initializer location; unavailable locations print `?:?`. It reports unsupported return fields, generic returns, explicit exclusions, capped values with an omitted count, and error classes whose constructors are unavailable. A constructor failure does not suppress recoveries or defects. Callbacks in arguments and arrays have their own locations; schema and brand constants are not functions. When a return cannot be synthesized but inner functions are mutated, the reason says so. The summary includes the line count. A target that the compiler cannot analyse gets a located `analysis failed` reason without aborting the remaining targets. Faults discovered during viability checks join the same skip report rather than becoming unviable outcomes. Config and program-load failures still stop the run. With `--in-diff`, only skips from files touched by the diff are reported. An empty selection, including a zero budget or a diff outside function bodies, skips the baseline, prints the selection count and cause to stderr, and writes a report with zero run and no baseline command. An empty actionable summary says “No actionable mutants.” The baseline command prints before execution when there are selected mutants. A failed baseline still writes `outcomes.json`, including its command and output tail; TypeScript load errors print the tsconfig path and diagnostics.\n\nAn include glob that matches no source file is a usage error, including a path outside the package root. Diff paths resolve from the Git toplevel, with support for `git diff --relative`; outside Git they resolve from the working directory.\n\n| Exit code | Meaning |\n| --- | --- |\n| 0 | no missed, unreliable, untested or timed-out mutants |\n| 1 | usage, source or tsconfig error |\n| 2 | some mutants were missed, or untested with no unreliable results |\n| 3 | baseline deadline exceeded, or some mutants timed out with no missed, unreliable or untested results |\n| 4 | baseline tests fail |\n| 5 | the `--in-diff` diff does not match the tree |\n| 6 | the diff cannot be parsed |\n| 7 | some results are unreliable, with none missed |\n| 70 | internal error |\n\nPrecedence is **missed (2), unreliable (7), untested (2), then timeout (3)**. A real miss wins over unreliable results; unreliable wins over an empty selection or timeout.\n\n## Outcomes\n\n| Outcome | Meaning |\n| --- | --- |\n| caught | a test failed, or a collected test run hung on `Effect.never` past its measured budget |\n| missed | the selected tests passed |\n| unviable | the mutant does not type-check |\n| timeout | the tests ran past the per-mutant budget without a reported failure or evidence of a caught `Effect.never` |\n| untested | related selection found no test files and the full-suite fallback did not fail |\n| unreliable | an unsupported runner, an omitted importing test, or a selected test reading a built self-entry instead of the affected source |\n\nFor built-in Node pools, mutant.cafe checks an empty related selection once per source file with a temporary module-load poison. The full suite must pass, its control hook must run, and no module-load signal may appear before any mutants in that file can be returned as untested without execution. A caught dynamic import still emits the signal, so it keeps per-mutant fallback. Probes and their durations appear in `reachabilityProbes` in the report. Unsupported pools and unreliable selections keep the existing fallback. This optimization applies to both cold and warm modes.\n\nVitest first runs tests related to the mutated file. When that selects no test files, mutant.cafe reruns the package's full suite within the remaining budget. A failing fallback counts as caught, including dynamic-import consumers. A passing fallback is untested, not missed: unrelated passing tests do not prove they reached the mutant.\n\nBefore the baseline, mutant.cafe checks `package.json`'s test script and asks the installed Vitest for its resolved test files. It warns when another runner owns the test script or a test importing a target is omitted. Test support imported by selected tests is not an omitted suite. Affected viable mutants are unreliable and are not scored as missed; their diagnostics name the script or omitted test. Common wrappers (`pnpm exec vitest`, `npx vitest`, `cross-env … vitest`, chained commands and `vitest --project`) count as Vitest scripts. Delegated scripts such as `turbo run test` or `pnpm -r test` are unverified, not declared non-Vitest.\n\nOnly an explicit non-Vitest runner skips the baseline and makes all results unreliable. Delegated or unknown scripts and failed selection probes warn but do not disable the Vitest baseline.\n\nSelf-imports that resolve to built JavaScript are scoped: the export's `types` condition or explicit tsconfig `rootDir`\u002F`outDir` maps the entry back to source and its import closure. A mutant in that closure is unreliable only if its actual selected tests include a test that imports the built entry. If mapping is unavailable, only that selected-test condition applies. Selection comes from the running Vitest reporter, including a full-suite fallback. Other mutants run normally; a built self-import never disables the baseline. Remapping a package link cannot rebuild its output.\n\nThis does not add `node:test` support. Literal relative imports are traced transitively; computed imports remain subject to the full-suite fallback.\n\nSelection and partial failures come from Vitest's reporter hooks, not its human-readable messages. A reported failure still counts as caught if another test file hangs.\n\n### Warm and cold runs\n\nThe baseline has a 30-minute overall hang guard, including selection and process startup. Set `--baseline-timeout 2400` (seconds), or `baselineTimeoutMs` in `mutants.config.json`, for a longer suite. Expiry reports `BaselineTimedOut`, names the limit and flag, and exits 3 rather than calling the original tests failed. Each paired calibration run uses that same baseline budget independently, across all scratch copies. Each cold execution also includes startup in its existing per-run budget. Cold runs launch the installed project's Vitest bin through Node, without an npm wrapper or shell lookup; the printed command names the actual generated launcher. Cleanup runs after deadline expiry before the next execution.\n\nSet `MUTANT_CAFE_PROCESS_TRACE=\u002Fabsolute\u002Fpath\u002Ftrace.jsonl` to opt into timestamped startup and cleanup stages: parent spawn, preload, birth inspection, child spawn, Vitest resolution\u002Fstart, test-module start and cwd inspection. Traces append process IDs, times and stage details, not arguments, environment contents or test output. No trace file is written by default.\n\nBy default, mutant.cafe first verifies a clean cold baseline and stops if it fails. It then excludes unviable and probe-cached mutants from calibration. Small runs stay cold without more baselines. Other runs measure warm and cold after the successful primer, so both use warmed filesystem inputs. Warm must select the same files, pass, and be at least 10% faster. At decision time the samples and opened copies are already paid for. Projected savings must cover only startup for copies not yet opened; sample costs remain in the report but do not bias the choice. Reports include the decision, measured costs and testable-mutant count. Use a forcing flag to avoid calibration.\n\nA warm scratch copy keeps one instance of the project's installed Vitest. Mutations and restores invalidate the changed module and its importers before the next run. Vitest's normal per-file isolation resets module-level state. Both modes use the project's configured worker count, or Vitest's default. `--jobs N` uses N scratch copies.\n\nUse `--cold` to start a fresh Vitest process for each mutant that needs tests, or `--warm` to force a persistent instance. The flags are mutually exclusive. Warm execution supports isolated built-in `forks` and `threads` pools on Vitest major 5, verified against 5.1.0. Other majors, VM pools, browser mode, custom pools, `globalSetup`, `isolate: false`, `poolOptions.*.isolate: false` and `--no-isolate` use cold execution. Auto falls back silently; `--warm` warns once with the reason. `baseline.runnerModeReason` records the reason in either mode. Selection-only hosts can inspect refused configurations but cannot execute tests; quiet logging never relaxes execution checks. The adapter also checks the private fields and transform\u002Finvalidation interfaces it uses. Falling back for `globalSetup` ensures each mutant initializes from its own source, just as cold execution does.\n\nAfter every warm execution, mutant.cafe closes the disposable worker pool and reaps test-created descendants before the next mutant. The Vitest\u002FVite host and its startup services remain alive. Test and hook timeouts, parallel bail and ordinary unhandled errors do not restart a healthy host. An unhandled error is a caught failure unless the project ignores it. Real worker death gets one pool retry; a second death switches the remaining run to cold mode. Only an unhealthy host is replaced. Reports and summaries include host restarts and unexpected pool resets from crashes, outer-deadline recovery or cancellation. Routine pool disposal is not counted. A host health check performs a trivial Vite transform as well as an IPC round trip. Worker-budget telemetry comes from Vitest's resolved config and is omitted when unavailable. Invalid telemetry never changes a verdict or triggers a pool retry: outcomes are written first, then the reporter warns with the bad field and value.\n\nEach Vitest instance has an ownership ledger. Child spawns inherit a unique label. Cleanup checks recorded PID identities, parent chains and escaped process groups with POSIX `ps`, then stops, kills and verifies the owned tree. Cleanup runs before reuse and on exit. Inspection or ownership failures warn with tracked PIDs, keep the ledger and let the run continue; an unhealthy host is not reused. Each ownership sweep shares a 10-second deadline across discovery, signalling and retries. Inspector calls allow two seconds, discovery seven seconds and signalling three seconds, all clamped to that shared deadline. These are hang guards, not clean-run speed targets. PPID descendants in the snapshot are claimed before fallible label inspection, so degraded cleanup claims unlabelled children before signalling their known parents. Inspector subprocesses receive cancellation signals; a stalled inspection cannot turn interruption into minutes of serial retries. If inspection fails or the budget expires, cleanup still attempts SIGKILL for PIDs already birth-matched in that sweep, then warns about unconfirmed exits and unverified ledger PIDs. A stale ledger entry alone never authorizes a signal. Zombies do not count as live survivors, and unverifiable PIDs are never signalled. Explicit child environments are left unchanged. The preload is appended only for implicit children using the current Node executable. Inspector environment output is never logged or included in reports. A minimal-env grandchild that daemonizes after its parent exits can escape cleanup. After each run, a scratch-path scan warns with the PIDs of unowned survivors; it never kills a process on a path match alone. The warning scan recognizes birth-validated PIDs from every live mutant.cafe ledger, including selector hosts. It reuses the latest PID\u002Fbirth\u002Fargv snapshot and checks cwd only for unknown processes born since the scratch session opened. Darwin restricts `lsof` to those candidate PIDs, drops exited or inaccessible PIDs and preserves partial output when another candidate exits during inspection. This warning-only filter never changes ownership or kill permissions. Each executed result records `backstopMs`, the total scratch-path scan time during that mutant. Summaries show its per-mutant p50\u002Fp90; baseline and selector-only scans are not samples. A source entry that vanishes during scratch copying is skipped with a debug note; permission errors, dangling source symlinks and missing destinations still fail the copy. Scratch removal allows 30 seconds for large workspaces and sends failures to stderr, never into GitHub Markdown output.\n\nOrdinary mutants use the configured timeout. For `Effect.never`, the reporter measures each passing test in the clean baseline. The budget uses the slowest test among the related files, including any full-suite fallback. A related-file probe selects those files. Comparing each task's original and probe timeouts distinguishes explicit options from inherited defaults; the probe's imposed timeout is not an original limit. The test and hook timeout is that duration × the timeout multiplier, with a 2 s floor, rather than the duration of the whole suite. Explicit per-test timeout options remain in effect, including larger values. Vitest does not expose a configuration API to raise a smaller explicit per-test timeout; those tests still use their own value. Reports record the computed timeout on each mutant result. The report also records the baseline test duration used as the budget base and the separate outer deadline. An inherited config timeout does not raise the outer deadline. That deadline allows the original startup time and the selected baseline files' collection, environment, hook and test durations, not the duration of the whole package. Cold and warm modes use the same per-test budget policy, so switching modes alone does not shorten a hanging test's timeout. A process killed before test collection is not credited as caught. Other mutants keep the existing per-test timeout of half their run budget. Both modes stop after the first reported failure.\n\n## Prior art\n\n[StrykerJS](https:\u002F\u002Fstryker-mutator.io) and its Effect 4 fork [stryker-js-effect](https:\u002F\u002Fgithub.com\u002Fsystemfsoftware\u002Fstryker-js-effect) mutate syntax (operators, literals, blocks, and some Effect concurrency faults) and use the type checker to discard mutants that don't compile. mutant.cafe uses the checker to generate mutants from types instead. Use both if you like; they find different gaps.\n\n## License\n\nMIT. Part of [rat-stack](https:\u002F\u002Fratstack.sh).\n","mutant-cafe 是一个面向 Effect TypeScript 生态的变异测试（mutation testing）工具，用于评估单元测试对代码逻辑缺陷的检测能力。它通过系统性地修改函数体（如替换为 Effect.succeed\u002Ffail\u002Fdie、翻转布尔值、篡改错误标签等），生成仍能通过类型检查的‘变异体’，再运行测试验证是否被捕获；特别支持 Effect 的类型化错误（E）、Option、Stream 和 Layer 等核心抽象的语义化变异。适用于使用 Effect 框架构建的高可靠性 TypeScript 项目，尤其适合在 Vitest 测试套件中集成，以量化测试覆盖质量并识别逻辑盲区。",2,"2026-11-24 04:33:01","CREATED_QUERY"]