cscheck
Write and simplify C# property-based, model-based, and executable specification tests with CsCheck. Use for generators, shrinking, stateful command sequences, Spec guards and rules, implementation conformance, or replaying generated failures.
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- cscheck
- description
- Write and simplify C# property-based, model-based, and executable specification tests with CsCheck. Use for generators, shrinking, stateful command sequences, Spec guards and rules, implementation conformance, or replaying generated failures.
- user-invocable
- false
02 资源文件 4
- 参考文档references/failures.md5.1 KB
- 参考文档references/properties.md5.7 KB
- 参考文档references/specifications.md9.2 KB
- 参考文档references/stateful-and-async.md7.7 KB
03 SKILL.md 正文
CsCheck
Use CsCheck to explore inputs and action sequences; keep the application's contract visible in the test. Let the library generate, shrink, print, and replay counterexamples. Start with the smallest test that can falsify the claim, rather than building a testing framework around CsCheck.
Choose the test shape
| What needs checking | Start with | Read when needed |
|---|---|---|
| A function, round trip, algebraic law, or data transformation | Gen + Sample |
Properties and generators |
| An implementation with a simpler reference representation | SampleModelBased / SampleModelBasedAsync |
Stateful and async tests |
| A protocol or lifecycle with explicit state, guards, and requirements | Spec.From, then Exhaustive and Conform |
Executable specifications |
| Async resources or expectations that must incorporate observed outcomes | Generated command arrays + SampleAsync, with cleanup inside each case |
Stateful and async tests |
| A failing property, seed replay, or a before/after bug demonstration | Native sampling controls and a concrete regression | Failure discovery and replay |
Read only the references needed for the task. These examples use xUnit, but CsCheck itself is test-framework independent. Preserve the project's existing framework and package-management conventions.
Establish the contract first
Identify an observable requirement and a plausible wrong result it would reject. Separate generated inputs, expected behavior, and actual observations. A model may consume observations, but must validate them against prior expectations before accepting them as new state. Do not use the implementation's answer to manufacture its expected answer.
Generate individual operations and their arguments, allowing CsCheck to compose arbitrary sequences. Finite domains, weighted boundary values, and preconditions are legitimate modeling choices. Handwritten whole scenarios are useful regressions, but are not a substitute for exploring action orderings.
Keep rejected requests testable when rejection is part of the contract. A guard saying “only withdraw when funds exist” cannot test insufficient-funds rejection. Preconditions describe what can be attempted; postconditions describe the response, including allowed failures.
Keep the test machinery small
- Prefer composed
Genvalues toRandom, hand-chosen seed lists, custom shrinkers, or retries-until-green. - Construct a fresh mutable implementation and model for each generated case, including shrinking.
- Use ordinary records, direct calls, and meaningful comparisons.
equal:must compare behavior or state; cleanup belongs infinally/using, not an equality predicate that always returns true. - Keep seeds out of ordinary discovery runs. Replay a seed emitted by a failure, then pin concrete inputs when the regression must survive generator changes.
- Preserve domain coverage and historical counterexamples when simplifying. Fewer lines alone do not establish that the replacement checks the same behavior.
Verify the right thing
Spec.Exhaustive checks the model. Spec.Conform checks the real implementation through the adapter
and only for sampled traces and compared observations. Keep both claims explicit. Inspect unreachable
requirements, deadlocks, and search cutoffs; a green run can be vacuous.
When practical, show that the test rejects a known broken implementation or a small deliberate defect in an isolated copy. Compile and execute examples rather than assuming similarly named FsCheck APIs exist in CsCheck. Reuse native model-based APIs when their independent transitions and comparison fit; a custom async loop is a useful alternative, not a universal replacement.
API baseline
The linked examples were compiled and run with CsCheck 4.9.1 on .NET 8. Its package identifies
source revision 5050355.
Check the installed package before adapting signatures. For upgrades, verify the
NuGet package and upstream source; do not infer a major version
or native async Spec.Conform support from another library's API.
04 同仓库更多 Skills
writing-tunit-tests
Write tests in TUnit — the attributes, the async assertion model, data-driven cases, lifecycle hooks, and the parallelism rules. USE FOR writing or fixing a test in a TUnit project, translating a test idea into TUnit syntax, or reviewing TUnit test code for API mistakes. DO NOT USE FOR deciding what to test, judging whether a test is any good, or running tests.
dotnet-walls
Walls for a .NET change in a repository without its own quality gates — pinned, ephemeral analyzer, format, clone and scanner commands for the verify step, their identity ratchet, and the build traps. Use during a walls preflight, or when a worker's verify step needs .NET quality gates.
csharp-15
Write, review and modernize C# 15 (.NET 11) code correctly. Covers every C# 15 feature - collection expression arguments (`[with(...), ...]`), union types (`union`, `[Union]`, `IUnion`, custom unions), closed class hierarchies (`closed`), extension indexers, labeled `break`/`continue`, non-virtual static interface members on runtimes without default interface methods, and the preview memory-safety model (`unsafe(expr)`, `safe`, requires-unsafe members). Use when code targets net11.0 or LangVersion 15/preview, when the user mentions any of these features, when replacing marker interfaces, OneOf-style results, `goto`/flag loop exits or capacity/comparer boilerplate, or when the build reports CS8121, CS8509, CS8655, CS8510, CS0121/CS0411 on a `with(...)` element, CS9370, CS9380 or CS9363.
verified-waves
Run one task as verified multi-agent waves. Plans the fan-out, sends findings to fresh skeptics, keeps a ledger, and reports N of M done; small tasks stay solo.
harness
The bundled dispatch harness, which runs a task file on worker models through OpenCode or Codex, fences their writes, escalates their asks to the operator, settles each result from git and its verify commands, and records every step in a ledger. Its commands, task file, modes and write fence, configuration, runs and their recovery, ledger and exit codes.
delegating-to-worker-models
Use when you hand off implementation, a plan, research a decision will rely on, or a review, and you brief the worker and check what comes back. A subagent that searches, reads in parallel, or keeps your context small is ordinary tool use. Covers what stays with you, the mechanism, assigning work by strength, the walls preflight, prompts without contradictions, the worker contract and model profiles, evidence from your own run, review, and the fix-up loop.