requirements.cli.setup
Requirements index · View definition
Requirement
Running
habeas setupin an existing Cargo and mdBook project MUST add Habeas as a dev dependency, configurehabeas mdbookas its preprocessor, add the badge stylesheet, enable sidebar folding withoutput.html.fold.enableunless the book already sets it, and createtests/habeas.rsthat callshabeas::validate(). Repeating setup MUST avoid duplicate configuration and MUST NOT overwrite a differing test or stylesheet. Setup MUST NOT install or modify agent skills.
Rationale
I judged this from the supplied test source only and did not request implementation source or the fixture() helper. The marked tests cover every obligation in requirements.cli.setup.
- Dev dependency:
tests/setup.rs#fn[setup_is_repeatable]runs setup twice. It asserts thatCargo.tomlhas[dev-dependencies],habeas, and apath =entry. - Preprocessor: the same test asserts that
book.tomlcontainscommand = "habeas mdbook". - Badge stylesheet: the same test asserts that
md/habeas.cssexists as a file and thatbook.tomllists it. It also asserts that the existingmd/custom.cssentry is still there. tests/habeas.rs: the same test asserts the exact file content, which includeshabeas::validate();.- Fold setting:
setup_is_repeatablechecks thatoutput.html.fold.enableends up true on a fresh book.setup_keeps_an_existing_fold_settingcovers the “unless the book already sets it” clause. It tests an explicitenable = falsein a table, a table with onlylevel(which must getenable = true, andlevel = 1is kept), and an inlinefold = { enable = false }.setup_rejects_invalid_book_configurationcovers a non-tablefold.
- Repeating setup:
setup_is_repeatableruns setup twice. It then asserts thatmd/habeas.cssappears once inbook.toml, thatenableappears once, that the TOML still parses, and thattests/habeas.rscontent is unchanged. No test asserts that the preprocessor entry or the dev-dependency is not duplicated. TOML keys cannot repeat in a table, and the successful parse after the second run would catch a repeated key. - No overwrite:
setup_does_not_overwrite_a_differing_test_or_stylesheetpre-creates a differingtests/habeas.rsand, separately, a differingmd/habeas.css. In each case it asserts that setup fails with “already exists with different content” naming the file, and that the file is unchanged. It also asserts thatbook.tomlandCargo.tomlare unchanged. - Agent skills:
setup_is_repeatableasserts that.agents/skillsis absent after each run.setup_preserves_existing_agent_skillsasserts that an existing skill file keeps its content.
Related tests also cite the requirement: setup_uses_src_when_book_table_or_source_setting_is_absent and setup_rejects_invalid_book_configuration. They cover the book.src fallback and invalid-configuration failures. I found no obligation in the requirement text that lacks a test with an assertion on the outcome.
Inputs
Tests
Input 2: outline tests/setup.rs fn[setup_is_repeatable]
- File:
tests/setup.rs - Selector:
fn[setup_is_repeatable] - Kind:
fn tests/setup.rs:335–371
// {test}`requirements.cli.setup`
// {test}`requirements.cli.setup_css`
// {test}`requirements.cli.setup_local_path`
// {test}`requirements.cli.mdbook`
// {test}`requirements.index.detail_pages`
#[test]
fn setup_is_repeatable() {
let temp = fixture();
let project = temp.path();
let local_crate = env!("CARGO_MANIFEST_DIR");
run(project, &["setup", "--path", local_crate]);
assert!(!project.join(".agents/skills").exists());
run(project, &["setup", "--path", local_crate]);
let cargo = fs::read_to_string(project.join("Cargo.toml")).unwrap();
assert!(cargo.contains("[dev-dependencies]"));
assert!(cargo.contains("habeas"));
assert!(cargo.contains("path = "));
let book = fs::read_to_string(project.join("book.toml")).unwrap();
assert!(book.contains("command = \"habeas mdbook\""));
assert!(book.contains("md/habeas.css"));
assert!(book.contains("md/custom.css"));
assert_eq!(book.matches("md/habeas.css").count(), 1);
assert_eq!(
fs::read_to_string(project.join("tests/habeas.rs")).unwrap(),
"#[test]\nfn habeas() {\n habeas::validate();\n}\n"
);
assert!(project.join("md/habeas.css").is_file());
assert!(!project.join(".agents/skills").exists());
let book: toml_edit::DocumentMut = book.parse().unwrap();
assert_eq!(
book["output"]["html"]["fold"]["enable"].as_bool(),
Some(true)
);
assert_eq!(book.to_string().matches("enable").count(), 1, "{book}");
}
Input 3: outline tests/setup.rs fn[setup_keeps_an_existing_fold_setting]
- File:
tests/setup.rs - Selector:
fn[setup_keeps_an_existing_fold_setting] - Kind:
fn tests/setup.rs:373–409
// {test}`requirements.cli.setup`
// {test}`requirements.index.detail_pages`
#[test]
fn setup_keeps_an_existing_fold_setting() {
for (configuration, expected) in [
(
"[output.html.fold]\nenable = false\nlevel = 1\n",
Some(false),
),
("[output.html.fold]\nlevel = 1\n", Some(true)),
("[output.html]\nfold = { enable = false }\n", Some(false)),
] {
let temp = fixture();
let project = temp.path();
fs::write(
project.join("book.toml"),
format!("[book]\nsrc = \"md\"\n\n{configuration}"),
)
.unwrap();
run(project, &["setup", "--path", env!("CARGO_MANIFEST_DIR")]);
let book: toml_edit::DocumentMut = fs::read_to_string(project.join("book.toml"))
.unwrap()
.parse()
.unwrap();
assert_eq!(
book["output"]["html"]["fold"]["enable"].as_bool(),
expected,
"{configuration}"
);
if configuration.contains("level") {
assert_eq!(
book["output"]["html"]["fold"]["level"].as_integer(),
Some(1)
);
}
}
}
Input 4: outline tests/setup.rs fn[setup_preserves_existing_agent_skills]
- File:
tests/setup.rs - Selector:
fn[setup_preserves_existing_agent_skills] - Kind:
fn tests/setup.rs:411–423
// {test}`requirements.cli.setup`
#[test]
fn setup_preserves_existing_agent_skills() {
let temp = fixture();
let project = temp.path();
let skill = project.join(".agents/skills/habeas-requirements/SKILL.md");
fs::create_dir_all(skill.parent().unwrap()).unwrap();
fs::write(&skill, "custom skill\n").unwrap();
run(project, &["setup", "--path", env!("CARGO_MANIFEST_DIR")]);
assert_eq!(fs::read_to_string(skill).unwrap(), "custom skill\n");
}
Input 5: outline tests/setup.rs fn[setup_uses_src_when_book_table_or_source_setting_is_absent]
- File:
tests/setup.rs - Selector:
fn[setup_uses_src_when_book_table_or_source_setting_is_absent] - Kind:
fn tests/setup.rs:425–446
// {test}`requirements.cli.setup_project`
// {test}`requirements.integration.symposium_setup_hook`
// {test}`requirements.cli.setup`
#[test]
fn setup_uses_src_when_book_table_or_source_setting_is_absent() {
for configuration in ["", "[book]\ntitle = 'Example'\n"] {
let temp = fixture();
let project = temp.path();
fs::write(project.join("book.toml"), configuration).unwrap();
fs::write(project.join("src/SUMMARY.md"), "# Summary\n").unwrap();
run(project, &["setup", "--path", env!("CARGO_MANIFEST_DIR")]);
assert!(project.join("src/habeas.css").is_file());
assert_eq!(session_start(project, project), skill_sentence_only());
let mut book: toml_edit::DocumentMut = fs::read_to_string(project.join("book.toml"))
.unwrap()
.parse()
.unwrap();
book["book"]["src"] = toml_edit::value(7);
fs::write(project.join("book.toml"), book.to_string()).unwrap();
assert!(advises_setup(&session_start(project, project)));
}
}
Input 6: outline tests/setup.rs fn[setup_rejects_invalid_book_configuration]
- File:
tests/setup.rs - Selector:
fn[setup_rejects_invalid_book_configuration] - Kind:
fn tests/setup.rs:448–505
// {test}`requirements.cli.setup_project`
// {test}`requirements.cli.setup_css`
// {test}`requirements.cli.setup`
#[test]
fn setup_rejects_invalid_book_configuration() {
let temp = fixture();
let project = temp.path();
let binary = env!("CARGO_BIN_EXE_habeas");
for (book, expected) in [
("book = 'wrong'\n", "book must be a table"),
("[book]\nsrc = 7\n", "book.src must be a string"),
("[book]\nsrc = ''\n", "book.src must be a directory"),
("[book]\nsrc = '/outside'\n", "book.src must be a directory"),
(
"[book]\nsrc = \"../outside\"\n",
"book.src must be a directory",
),
(
"[book]\nsrc = 'md/../outside'\n",
"book.src must be a directory",
),
(
"[book]\nsrc = \"md\"\n\n[output.html]\nadditional-css = \"wrong\"\n",
"output.html.additional-css must be an array",
),
(
"[book]\nsrc = \"md\"\n\n[output.html]\nfold = true\n",
"output.html.fold must be a table",
),
] {
fs::write(project.join("book.toml"), book).unwrap();
let output = Command::new(binary)
.args(["setup", "--path", env!("CARGO_MANIFEST_DIR")])
.current_dir(project)
.env("CARGO_NET_OFFLINE", "true")
.output()
.unwrap();
assert!(!output.status.success());
assert!(
String::from_utf8_lossy(&output.stderr).contains(expected),
"{:?}: {}",
book,
String::from_utf8_lossy(&output.stderr)
);
}
fs::write(project.join("book.toml"), "[book]\nsrc = \"md\"\n").unwrap();
fs::remove_file(project.join("md/SUMMARY.md")).unwrap();
let output = Command::new(binary)
.args(["setup", "--path", env!("CARGO_MANIFEST_DIR")])
.current_dir(project)
.env("CARGO_NET_OFFLINE", "true")
.output()
.unwrap();
assert!(!output.status.success());
assert!(String::from_utf8_lossy(&output.stderr).contains("cannot find mdBook SUMMARY.md"));
}
Input 7: outline tests/setup.rs fn[setup_does_not_overwrite_a_differing_test_or_stylesheet]
- File:
tests/setup.rs - Selector:
fn[setup_does_not_overwrite_a_differing_test_or_stylesheet] - Kind:
fn tests/setup.rs:723–754
// {test}`requirements.cli.setup`
#[test]
fn setup_does_not_overwrite_a_differing_test_or_stylesheet() {
for existing in ["tests/habeas.rs", "md/habeas.css"] {
let temp = fixture();
let project = temp.path();
let path = project.join(existing);
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(&path, "user content\n").unwrap();
let book = fs::read_to_string(project.join("book.toml")).unwrap();
let cargo = fs::read_to_string(project.join("Cargo.toml")).unwrap();
let output = Command::new(env!("CARGO_BIN_EXE_habeas"))
.args(["setup", "--path", env!("CARGO_MANIFEST_DIR")])
.current_dir(project)
.env("CARGO_NET_OFFLINE", "true")
.output()
.unwrap();
assert!(!output.status.success(), "{existing}");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("already exists with different content") && stderr.contains(existing),
"{existing}: {stderr}"
);
assert_eq!(fs::read_to_string(&path).unwrap(), "user content\n");
assert_eq!(fs::read_to_string(project.join("book.toml")).unwrap(), book);
assert_eq!(
fs::read_to_string(project.join("Cargo.toml")).unwrap(),
cargo
);
}
}
Other sources
Input 1: requirements selection requirements.cli.setup
requirements.cli.setup:md/requirements/cli.md:11–13
:::{req} setup
Running `habeas setup` in an existing Cargo and mdBook project MUST add Habeas as a dev dependency, configure `habeas mdbook` as its preprocessor, add the badge stylesheet, enable sidebar folding with `output.html.fold.enable` unless the book already sets it, and create `tests/habeas.rs` that calls `habeas::validate()`. Repeating setup MUST avoid duplicate configuration and MUST NOT overwrite a differing test or stylesheet. Setup MUST NOT install or modify agent skills.
:::