02 · Test Generation
A pure function without tests is the friendliest target for an AI-written test suite: inputs and outputs are observable, no mocks required. This case asks DSCC to read one file and create a table-driven test file that covers happy path, edge cases, and error cases.
Capability demonstrated
read_fileon the source.write_fileon a new path under the workspace.WorkspaceWritepermission — writes insidecwd, nothing else. See guides/permissions.md.
Setup
Inside a Rust project (e.g. a fresh
cargo new --lib util_demo), create a target function:
cat > src/utils.rs <<'RS'
use std::time::Duration;
pub fn parse_duration(s: &str) -> Option<Duration> {
let s = s.trim();
if s.is_empty() { return None; }
let (num, unit) = s.split_at(s.len() - 1);
let n: u64 = num.parse().ok()?;
match unit {
"s" => Some(Duration::from_secs(n)),
"m" => Some(Duration::from_secs(n * 60)),
"h" => Some(Duration::from_secs(n * 3600)),
_ => None,
}
}
RS
Then expose it from src/lib.rs:
echo 'pub mod utils;' >> src/lib.rs
Run command
dscc --model claude-sonnet-4-6 \
--permission-mode workspace-write \
prompt "$(cat docs/cookbook/02-test-generation/PROMPT.md)"
A live run against doubao-seed-2.0-code is captured at
report_dscc.md; the generated
test file is preserved at generated_utils_test.rs.
Note: when you run it unattended, use
--permission-mode danger-full-access(or install aPreToolUsehook that auto-approvescargo *), because the model will want to shell out tocargo testfor self-verification.
Expected behavior
The model should typically:
read_fileonsrc/utils.rs.- Possibly
glob_searchforCargo.toml/ existing tests. write_fileontests/utils_test.rswith a#[test]-based table.
No edits to src/utils.rs.
Verification
cargo testpasses.tests/utils_test.rsexists and contains at least 5 test cases (happy + edge + error).git diff src/utils.rsis empty.