| name | write-tests |
| description | Write tests for Syncpack using the TestBuilder pattern. Use when adding tests for commands, validation logic, or any new functionality. Covers TestBuilder API, assertion patterns, and common test scenarios. |
Write Tests
Golden rules
- Use
TestBuilder — never construct Context manually.
- Assert with
expect(&ctx).to_have_instances(vec![...]) — never index ctx.instances.
- Async-first:
#[tokio::test] + .run().await is the canonical entry.
TDD
- Read 2-3 tests in the same
*_test.rs and copy the pattern
- Write failing test →
just test → confirm RED
- Ask before implementing
- Implement minimal code → GREEN →
just format
Quick start
use {
crate::{
instance::{FixableInstance::*, InstanceState, SuspectInstance::*, UnfixableInstance::*, ValidInstance::*},
test::{
builder::TestBuilder,
expect::{expect, ExpectedInstance},
},
},
serde_json::json,
};
#[tokio::test]
async fn pinned_version_replaces_anything_different() {
let ctx = TestBuilder::new()
.with_package(json!({
"name": "package-a",
"version": "1.0.0",
: {: }
}))
.(json!({
: [],
:
}))
.()
.;
(&ctx).([
ExpectedInstance {
state: InstanceState::(IsLocalAndValid),
dependency_name: ,
id: ,
actual: ,
expected: (),
overridden: ,
},
ExpectedInstance {
state: InstanceState::(DiffersToPin),
dependency_name: ,
id: ,
actual: ,
expected: (),
overridden: ,
},
]);
}