requirements.authoring.mandatory_inputs
Requirements index · View definition
Requirement
The harness MUST construct each assessment’s mandatory input set by combining the contributions specified by the requirements applicable to that subject and its inputs. A requirement that contributes inputs MUST cite this requirement and define which sources it contributes and when. The harness MUST include every applicable contribution, deduplicate identical selections, and report unresolvable mandatory inputs before inference. The complete set MUST be supplied in the initial model request. Generated output under project-root
evidence/, including symlink aliases, MUST be omitted from mandatory inputs when the default exclusion applies. An explicit workspace allow MUST permit those selections; an explicit disallow MUST abort under.
Rationale
The reviewed tests adequately cover each obligation of requirements.authoring.mandatory_inputs. I did not run them.
Combining contributions and including every applicable one
bundle_combines_direct_references_terms_and_current_existing_selectorsbuilds a requirement subject. It asserts the declaration,{test}item nodes, cited requirements, example declarations, and the definition inputs. It also asserts that distant, uncited, and{impl}-only items are not included.- It checks an example subject too.
only_edges_leaving_the_subject_contribute_inputs,references_contribute_their_owning_outline_nodes,anchored_files_contribute_root_node_inputsandtest_anchors_supply_only_the_selected_nodecover the other contribution kinds. These are:impl:/:test:anchors, docs sections, plain-text files, and acknowledgment metadata.- The citation flow is covered by
citation_review_inputs_combine_item_declarations_terms_and_built_ins_once. - The site flow is covered by
site_reviews_use_their_prompt_and_record_applies_and_the_site.
Deduplicating identical selections
citation_review_inputs_combine_item_declarations_terms_and_built_ins_oncehas duplicate{cite}references, a term shared by two declarations, and a built-in cited twice. It asserts each appears exactly once and that the total is 5.- In the subject flow, the bundle test asserts exactly 2 definition inputs for two mutually referencing terms.
anchored_files_contribute_root_node_inputsnames the same file as both:impl:and:test:anchor, and asserts the exact input list with that file once.
Reporting unresolvable inputs before inference
- These tests assert an abort with
PermissionDenied, or a “cannot read … anchor” error, naming the path:disallowed_mandatory_inputs_abort_preparationunreadable_or_denied_anchors_fail_before_inferencemandatory_inputs_outside_the_project_still_abortmandatory_git_inputs_require_staging_declarations_sources_and_terms
unresolvable_mandatory_inputs_fail_before_any_model_requestintests/authoring_cli.rsruns the real CLI. It asserts a nonzero exit and that stderr names the path. It also asserts that the listener never receives a connection and that the evidence file is unchanged.unresolvable_earlier_inputs_do_not_block_reassessmentchecks that stale earlier inputs are not treated as mandatory.
Complete set supplied in the initial request
citation_reviews_use_their_prompt_and_record_the_item_and_citationschecks that the initial prompt contains the mandatory item hash, the requirement text, and the built-in text.test_anchors_supply_only_the_selected_nodechecks the prompt contents.- The CLI tests (
ollama_cli_delivers_sources_records_fixme_and_keeps_usage_content_freeandimplementation_discovery_has_no_text_or_evidence_until_the_model_requests_a_read) check that the first request carries the requirement, definition, and test text.
Generated evidence/ output
generated_evidence_anchors_are_omitted_unless_allowed_and_abort_when_disallowedcovers four cases:- The default exclusion omits the anchor.
- A symlink alias into
evidence/is omitted, on unix. - An explicit allow includes it.
- An explicit disallow aborts with
PermissionDeniednaming the file.
generated_evidence_references_are_omitted_by_defaultandearlier_evidence_inputs_and_judgments_are_not_carried_forwardcover the default omission of evidence-derived references and earlier judgments.
Obligations not assessed here
- The clause that a contributing requirement must cite this requirement and define its sources is a documentation obligation on other requirements. Those requirements’ own reviews carry it.
- The abort-reporting details under
requirements.authoring.read_denial.mandatoryare cited context. I did not reassess them.
I found no requirement-violating behavior that these tests would accept.
Inputs
Tests
Input 3: outline src/authoring/inputs.rs mod[tests]/fn[role]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[role] - Kind:
fn src/authoring/inputs.rs:853–856
// {test}`requirements.authoring.mandatory_inputs`
pub(crate) fn role(kind: &str, name: &str) -> String {
format!("{{{kind}}}`{name}`")
}
Input 4: outline src/authoring/inputs.rs mod[tests]/fn[project]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[project] - Kind:
fn src/authoring/inputs.rs:858–875
// {test}`requirements.authoring.mandatory_inputs`
pub(crate) fn project() -> tempfile::TempDir {
let root = tempfile::tempdir().unwrap();
fs::create_dir_all(root.path().join("md")).unwrap();
fs::create_dir_all(root.path().join("src")).unwrap();
fs::write(
root.path().join("Cargo.toml"),
"[package]\nname='fixture'\nversion='0.1.0'\n",
)
.unwrap();
fs::write(root.path().join("book.toml"), "[book]\nsrc='md'\n").unwrap();
fs::write(
root.path().join("md/requirements.md"),
":::{req} ready\nThe project MUST be ready.\n:::\n",
)
.unwrap();
root
}
Input 5: outline src/authoring/inputs.rs mod[tests]/fn[bundle_combines_direct_references_terms_and_current_existing_selectors]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[bundle_combines_direct_references_terms_and_current_existing_selectors] - Kind:
fn src/authoring/inputs.rs:955–1058
// {test}`requirements.authoring.complete_initial_bundle`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring_input`
// {test}`requirements.examples.authoring_inputs`
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.definitions.authoring_inputs`
// {test}`requirements.ci.authoring_inputs`
// {test}`requirements.ci.reference_set`
#[test]
fn bundle_combines_direct_references_terms_and_current_existing_selectors() {
let root = project();
let terms = format!(
":::{{definition}} unit\n:phrase: unit\nA {}.\n:::\n\n:::{{definition}} value\n:phrase: value\nA {}.\n:::\n",
role("term", "terms.value"),
role("term", "terms.unit")
);
fs::write(root.path().join("md/terms.md"), terms).unwrap();
let declarations = format!(
":::{{req}} ready\nReady uses {} and {}.\n:::\n\n:::{{req}} base\nBase cites {}.\n:::\n\n:::{{req}} distant\nDistant MUST work.\n:::\n\n:::{{example}} case\nReady example. {} {}\n:::\n",
role("cite", "requirements.base"),
role("term", "terms.unit"),
role("cite", "requirements.distant"),
role("cite", "requirements.ready"),
role("test", "requirements.ready")
);
fs::write(root.path().join("md/requirements.md"), declarations).unwrap();
fs::write(root.path().join("src/lib.rs"), format!("struct Thing;\nimpl Thing {{\n // {}\n fn run(&self) {{}}\n fn unrelated(&self) {{}}\n}}\n// {}\nfn test_ready() {{}}\n", role("impl", "requirements.ready"), role("test", "requirements.ready"))).unwrap();
fs::write(root.path().join("notes.txt"), "new source text\n").unwrap();
fs::create_dir(root.path().join("evidence")).unwrap();
fs::write(
root.path().join("evidence/requirements.ready.json"),
json!({
"determination": false, "rationale": "old secret judgment",
"inputs": [{"file":"notes.txt", "line_start":1, "line_end":1, "text":["old text"]}]
})
.to_string(),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
// The recorded digest covers the same `{impl}` and `{test}` edges.
assert_eq!(
sources.reference_set,
crate::evidence::reference_set_digest_for(root.path(), "requirements.ready").unwrap()
);
let inputs = sources.mandatory_inputs();
assert!(sources.recorded_inputs().is_empty());
assert!(
!inputs
.iter()
.any(|input| input["item"] == "impl[Thing]/fn[run]")
);
assert!(inputs.iter().any(|input| input["item"] == "fn[test_ready]"));
assert!(!inputs.iter().any(|input| input["item"] == "impl[Thing]"));
assert!(
inputs
.iter()
.any(|input| input["requirements"] == "requirements.case")
);
assert!(
inputs
.iter()
.any(|input| input["requirements"] == "requirements.base")
);
assert!(
!inputs
.iter()
.any(|input| input["requirements"] == "requirements.distant")
);
assert_eq!(
inputs
.iter()
.filter(|input| input.get("definition").is_some())
.count(),
2
);
// Earlier evidence inputs are not carried forward.
assert!(!inputs.iter().any(|input| input["file"] == "notes.txt"));
assert!(
!serde_json::to_string(inputs)
.unwrap()
.contains("old secret judgment")
);
let example = AssessmentSources::prepare(root.path(), "requirements.case").unwrap();
assert!(matches!(
example.subject_kind,
AssessmentKind::Definition(DefinitionKind::Example, false)
));
assert_eq!(
example.mandatory_inputs()[0]["requirements"],
"requirements.case"
);
assert_eq!(
example.mandatory_inputs()[0]["text"],
json!([
":::{example} case",
format!(
"Ready example. {} {}",
role("cite", "requirements.ready"),
role("test", "requirements.ready")
),
":::"
])
);
}
Input 6: outline src/authoring/inputs.rs mod[tests]/fn[unresolvable_earlier_inputs_do_not_block_reassessment]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[unresolvable_earlier_inputs_do_not_block_reassessment] - Kind:
fn src/authoring/inputs.rs:1060–1089
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.ci.authoring_inputs`
// {test}`requirements.authoring_input`
#[test]
fn unresolvable_earlier_inputs_do_not_block_reassessment() {
let root = project();
fs::create_dir(root.path().join("evidence")).unwrap();
fs::write(
root.path().join("evidence/requirements.ready.json"),
json!({
"inputs": [
{"file":"missing.txt", "line_start":1, "line_end":1},
{"rust_file":"src/lib.rs", "rust_item":"fn[removed]", "text":["fn removed() {}"]},
{"requirements":"requirements.removed", "matches":["requirements.removed"], "text":["gone"]}
]
})
.to_string(),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert_eq!(
sources.mandatory_inputs(),
&[json!({
"requirements": "requirements.ready",
"matches": ["requirements.ready"],
"text": [":::{req} ready", "The project MUST be ready.", ":::"]
})]
);
assert!(AssessmentSources::prepare(root.path(), "missing").is_err());
}
Input 7: outline src/authoring/inputs.rs mod[tests]/fn[earlier_evidence_inputs_and_judgments_are_not_carried_forward]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[earlier_evidence_inputs_and_judgments_are_not_carried_forward] - Kind:
fn src/authoring/inputs.rs:1091–1118
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.ci.authoring_inputs`
#[test]
fn earlier_evidence_inputs_and_judgments_are_not_carried_forward() {
let root = project();
fs::write(root.path().join("notes.txt"), "current source\n").unwrap();
fs::create_dir_all(root.path().join("evidence")).unwrap();
let old = json!({
"requirement": "The project MUST be ready.",
"determination": false,
"rationale": "old secret judgment",
"inputs": [
{"file":"evidence/requirements.ready.json", "line_start":1, "line_end":1, "text":["old judgment"]},
{"file":"notes.txt", "line_start":1, "line_end":1, "text":["old source"]},
]
});
let path = root.path().join("evidence/requirements.ready.json");
fs::write(&path, old.to_string()).unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let supplied = serde_json::to_string(sources.mandatory_inputs()).unwrap();
assert!(!supplied.contains("notes.txt"), "{supplied}");
assert!(!supplied.contains("evidence/"), "{supplied}");
assert!(!supplied.contains("old secret judgment"), "{supplied}");
assert_eq!(
serde_json::from_str::<Value>(&fs::read_to_string(path).unwrap()).unwrap(),
old
);
}
Input 8: outline src/authoring/inputs.rs mod[tests]/fn[mandatory_git_inputs_require_staging_declarations_sources_and_terms]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[mandatory_git_inputs_require_staging_declarations_sources_and_terms] - Kind:
fn src/authoring/inputs.rs:1120–1187
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.definitions.authoring_inputs`
// {test}`requirements.authoring_input`
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.authoring.read_denial`
// {test}`requirements.references.discovery`
#[test]
fn mandatory_git_inputs_require_staging_declarations_sources_and_terms() {
let root = project();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "Cargo.toml", "book.toml"]);
let error = AssessmentSources::prepare(root.path(), "requirements.ready")
.err()
.unwrap();
assert!(
error.to_string().contains("md/requirements.md")
&& error.to_string().contains("git add"),
"{error}"
);
git(root.path(), &["add", "md"]);
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {}\nfn ready() {{}}\n",
role("test", "requirements.ready")
),
)
.unwrap();
// Discovery does not consider an untracked source, so its reference is
// not yet an input; staging it makes the source mandatory.
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let supplied = serde_json::to_string(sources.mandatory_inputs()).unwrap();
assert!(!supplied.contains("src/lib.rs"), "{supplied}");
git(root.path(), &["add", "src"]);
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let supplied = serde_json::to_string(sources.mandatory_inputs()).unwrap();
assert!(supplied.contains("src/lib.rs"), "{supplied}");
fs::write(
root.path().join("md/terms.md"),
":::{definition} ready\n:phrase: ready\nReady to proceed.\n:::\n",
)
.unwrap();
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {} {}\nfn ready() {{}}\n",
role("test", "requirements.ready"),
role("term", "terms.ready")
),
)
.unwrap();
let error = AssessmentSources::prepare(root.path(), "requirements.ready")
.err()
.unwrap();
assert!(
error.to_string().contains("md/terms.md") && error.to_string().contains("git add"),
"{error}"
);
git(root.path(), &["add", "md/terms.md"]);
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert!(
sources
.mandatory_inputs()
.iter()
.any(|input| input["definition"] == "terms.ready")
);
}
Input 9: outline src/authoring/inputs.rs mod[tests]/fn[disallowed_mandatory_inputs_abort_preparation]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[disallowed_mandatory_inputs_abort_preparation] - Kind:
fn src/authoring/inputs.rs:1215–1231
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.read_denial`
#[test]
fn disallowed_mandatory_inputs_abort_preparation() {
let root = project();
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\ndisallow = ['md/requirements.md']\n",
)
.unwrap();
let error = AssessmentSources::prepare(root.path(), "requirements.ready")
.err()
.unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(error.to_string().contains("md/requirements.md"), "{error}");
}
Input 10: outline src/authoring/inputs.rs mod[tests]/fn[citation_review_inputs_combine_item_declarations_terms_and_built_ins_once]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[citation_review_inputs_combine_item_declarations_terms_and_built_ins_once] - Kind:
fn src/authoring/inputs.rs:1233–1296
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.references.citation_review`
#[test]
fn citation_review_inputs_combine_item_declarations_terms_and_built_ins_once() {
let root = project();
fs::write(
root.path().join("md/terms.md"),
":::{definition} unit\n:phrase: unit\nA unit.\n:::\n",
)
.unwrap();
fs::write(
root.path().join("md/requirements.md"),
format!(
":::{{req}} ready\nReady uses {}.\n:::\n\n:::{{req}} other\nOther uses {}.\n:::\n",
role("term", "terms.unit"),
role("term", "terms.unit")
),
)
.unwrap();
let util = "// :::{cite} habeas:util\n// Glue.\n// :::\n".to_owned();
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {}\n// {}\n// {}\n{util}{util}fn helper() {{}}\n",
role("cite", "requirements.ready"),
role("cite", "requirements.ready"),
role("cite", "requirements.other"),
),
)
.unwrap();
let sources =
AssessmentSources::prepare_citation(root.path(), "src/lib.rs", "fn[helper]").unwrap();
let inputs = sources.mandatory_inputs();
// The item, each cited declaration once, the shared term once, and the
// built-in text once.
assert_eq!(inputs[0]["item"], "fn[helper]");
let count =
|key: &str, value: &str| inputs.iter().filter(|input| input[key] == value).count();
assert_eq!(
count("requirements", "requirements.ready"),
1,
"{inputs:#?}"
);
assert_eq!(
count("requirements", "requirements.other"),
1,
"{inputs:#?}"
);
assert_eq!(count("definition", "terms.unit"), 1, "{inputs:#?}");
assert_eq!(count("builtin", "habeas:util"), 1, "{inputs:#?}");
assert_eq!(inputs.len(), 5, "{inputs:#?}");
// An unresolvable mandatory input aborts preparation.
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\ndisallow = ['md/terms.md']\n",
)
.unwrap();
let error = AssessmentSources::prepare_citation(root.path(), "src/lib.rs", "fn[helper]")
.err()
.unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(error.to_string().contains("md/terms.md"), "{error}");
}
Input 11: outline src/authoring/inputs.rs mod[tests]/fn[only_edges_leaving_the_subject_contribute_inputs]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[only_edges_leaving_the_subject_contribute_inputs] - Kind:
fn src/authoring/inputs.rs:1298–1362
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.references.roles`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.examples.definition`
#[test]
fn only_edges_leaving_the_subject_contribute_inputs() {
let root = project();
let declarations = format!(
":::{{req}} ready\nReady relies on {} and refines {}.\n:::\n\n:::{{req}} base\nBase MUST hold.\n:::\n\n:::{{req}} parent\nParent MUST hold.\n:::\n\n:::{{example}} citer\nA case relying on ready. {}\n:::\n\n:::{{example}} tester\nA ready case. {} {}\n:::\n",
role("cite", "requirements.base"),
role("impl", "requirements.parent"),
role("cite", "requirements.ready"),
role("cite", "requirements.base"),
role("test", "requirements.ready")
);
fs::write(root.path().join("md/requirements.md"), declarations).unwrap();
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {}\nfn run() {{}}\n// {}\nfn helper() {{}}\n// {}\nfn check() {{}}\n",
role("impl", "requirements.ready"),
role("cite", "requirements.ready"),
role("test", "requirements.ready")
),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let inputs = sources.mandatory_inputs();
let has_requirements =
|name: &str| inputs.iter().any(|input| input["requirements"] == name);
let has_item = |item: &str| inputs.iter().any(|input| input["item"] == item);
assert!(has_requirements("requirements.ready"));
assert!(has_requirements("requirements.base"), "{inputs:#?}");
assert!(has_requirements("requirements.tester"), "{inputs:#?}");
assert!(!has_item("fn[run]"), "{inputs:#?}");
assert!(has_item("fn[check]"), "{inputs:#?}");
assert!(!has_item("fn[helper]"), "{inputs:#?}");
assert!(!has_requirements("requirements.citer"), "{inputs:#?}");
assert!(!has_requirements("requirements.parent"), "{inputs:#?}");
let example = AssessmentSources::prepare(root.path(), "requirements.citer").unwrap();
assert!(
example
.mandatory_inputs()
.iter()
.any(|input| input["requirements"] == "requirements.ready"),
"{:#?}",
example.mandatory_inputs()
);
let parent = AssessmentSources::prepare(root.path(), "requirements.parent").unwrap();
let inputs = parent.mandatory_inputs();
assert!(
inputs
.iter()
.any(|input| input["requirements"] == "requirements.ready"),
"{inputs:#?}"
);
assert!(
!inputs
.iter()
.any(|input| input["requirements"] == "requirements.base"),
"{inputs:#?}"
);
}
Input 12: outline src/authoring/inputs.rs mod[tests]/fn[anchored_files_contribute_root_node_inputs]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[anchored_files_contribute_root_node_inputs] - Kind:
fn src/authoring/inputs.rs:1364–1405
// {test}`requirements.references.anchors`
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring_input`
// {test}`requirements.authoring.no_line_numbers`
#[test]
fn anchored_files_contribute_root_node_inputs() {
let root = project();
fs::create_dir_all(root.path().join("skills")).unwrap();
fs::write(root.path().join("skills/ready.md"), "# Skill\nBe ready.\n").unwrap();
fs::write(
root.path().join("md/requirements.md"),
":::{req} ready\n:impl: skills/ready.md\n:test: skills/ready.md\nThe project MUST be ready.\n\nKeep the whole body.\n:impl: this is body text\n:::\n",
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let inputs = sources.mandatory_inputs();
let hash =
crate::inputs::outline_input(root.path(), "skills/ready.md", "").unwrap()["hash"]
.clone();
assert_eq!(
inputs,
&[
json!({
"requirements": "requirements.ready",
"matches": ["requirements.ready"],
"text": [":::{req} ready", "The project MUST be ready.", "", "Keep the whole body.", ":impl: this is body text", ":::"]
}),
json!({
"file": "skills/ready.md",
"item": "",
"hash": hash,
"kind": "file",
"text": ["# Skill", "Be ready."]
}),
]
);
assert_eq!(
sources.subject_text,
"The project MUST be ready.\n\nKeep the whole body.\n:impl: this is body text"
);
}
Input 13: outline src/authoring/inputs.rs mod[tests]/fn[test_anchors_supply_only_the_selected_node]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[test_anchors_supply_only_the_selected_node] - Kind:
fn src/authoring/inputs.rs:1407–1440
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.references.anchors`
// {test}`requirements.authoring.mandatory_inputs`
#[test]
fn test_anchors_supply_only_the_selected_node() {
let root = project();
fs::write(
root.path().join("src/lib.rs"),
"fn target() { assert_eq!(1, 1); }\nfn sibling() { panic!(\"UNRELATED_SOURCE\"); }\n",
)
.unwrap();
fs::write(
root.path().join("md/requirements.md"),
":::{req} ready\n:test: src/lib.rs#fn[target]\nThe project MUST be ready.\n:::\n",
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let inputs = sources.mandatory_inputs();
assert_eq!(inputs.len(), 2, "{inputs:?}");
let expected =
crate::inputs::outline_input(root.path(), "src/lib.rs", "fn[target]").unwrap();
for key in ["file", "item", "hash"] {
assert_eq!(inputs[1][key], expected[key]);
}
assert_eq!(inputs[1]["kind"], "fn");
assert_eq!(
inputs[1]["text"],
json!(["fn target() { assert_eq!(1, 1); }"])
);
let prompt = super::super::initial_prompt(&sources).unwrap().joined();
assert!(prompt.contains("assert_eq!(1, 1)"), "{prompt}");
assert!(!prompt.contains("UNRELATED_SOURCE"), "{prompt}");
assert!(!prompt.contains("fn sibling"), "{prompt}");
}
Input 14: outline src/authoring/inputs.rs mod[tests]/fn[unreadable_or_denied_anchors_fail_before_inference]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[unreadable_or_denied_anchors_fail_before_inference] - Kind:
fn src/authoring/inputs.rs:1568–1624
// {test}`requirements.references.anchors`
// {test}`requirements.authoring.read_denial`
// {test}`requirements.authoring.read_denial.mandatory`
#[test]
// {test}`requirements.authoring.mandatory_inputs`
fn unreadable_or_denied_anchors_fail_before_inference() {
let root = project();
fs::write(
root.path().join("md/requirements.md"),
":::{req} ready\n:impl: skills/missing.md\nThe project MUST be ready.\n:::\n",
)
.unwrap();
let error = AssessmentSources::prepare(root.path(), "requirements.ready")
.err()
.unwrap();
assert!(
error
.to_string()
.contains("requirements.ready: cannot read :impl: anchor skills/missing.md"),
"{error}"
);
// An anchor naming a node its existing file lacks fails the same way.
fs::write(root.path().join("src/lib.rs"), "fn present() {}\n").unwrap();
fs::write(
root.path().join("md/requirements.md"),
":::{req} ready\n:impl: src/lib.rs#fn[missing]\nThe project MUST be ready.\n:::\n",
)
.unwrap();
let error = AssessmentSources::prepare(root.path(), "requirements.ready")
.err()
.unwrap();
assert!(
error
.to_string()
.contains("cannot read :impl: anchor src/lib.rs#fn[missing]"),
"{error}"
);
fs::create_dir_all(root.path().join("private")).unwrap();
fs::write(root.path().join("private/skill.md"), "secret\n").unwrap();
fs::write(
root.path().join("md/requirements.md"),
":::{req} ready\n:impl: private/skill.md\nThe project MUST be ready.\n:::\n",
)
.unwrap();
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\ndisallow = ['private']\n",
)
.unwrap();
let error = AssessmentSources::prepare(root.path(), "requirements.ready")
.err()
.unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(error.to_string().contains("private/skill.md"), "{error}");
}
Input 15: outline src/authoring/inputs.rs mod[tests]/fn[references_contribute_their_owning_outline_nodes]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[references_contribute_their_owning_outline_nodes] - Kind:
fn src/authoring/inputs.rs:1706–1766
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.references.outline_comments`
// {test}`requirements.references.anchors`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.fixme_inputs`
// {test}`requirements.references.roles`
#[test]
fn references_contribute_their_owning_outline_nodes() {
let root = project();
fs::create_dir_all(root.path().join("docs")).unwrap();
fs::write(
root.path().join("md/requirements.md"),
":::{req} ready\n:impl: src/lib.rs#mod[inner]\nThe project MUST be ready.\n:::\n",
)
.unwrap();
// A `{fixme}` contributes metadata for the node its comment belongs to;
// an unnamed one is not an acknowledgment edge.
fs::write(
root.path().join("src/lib.rs"),
"mod inner {\n fn unrelated() {}\n}\n\n// :::{fixme} requirements.ready\n// The gap.\n// :::\nfn gap() {}\n\n// :::{fixme}\n// :github: example/app#1\n// :::\nfn tracked() {}\n",
)
.unwrap();
fs::write(
root.path().join("docs/guide.md"),
format!(
"# Intro\n\nText.\n\n# Usage\n\nSee {}.\n",
role("test", "requirements.ready")
),
)
.unwrap();
fs::write(
root.path().join("notes.txt"),
format!("first\n{}\n", role("test", "requirements.ready")),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let items = sources
.mandatory_inputs()
.iter()
.filter(|input| input.get("item").is_some())
.map(|input| {
(
input["file"].as_str().unwrap(),
input["item"].as_str().unwrap(),
)
})
.collect::<Vec<_>>();
assert_eq!(
items,
[
("docs/guide.md", "section[Usage]"),
// A plain-text file contributes the complete file.
("notes.txt", ""),
]
);
let acknowledgments = sources.model_acknowledgments();
assert_eq!(acknowledgments.len(), 1, "{acknowledgments:#?}");
assert_eq!(acknowledgments[0]["file"], "src/lib.rs");
assert_eq!(acknowledgments[0]["item"], "fn[gap]");
assert_eq!(acknowledgments[0]["body"], "The gap.");
}
Input 16: outline src/authoring/inputs.rs mod[tests]/fn[generated_evidence_anchors_are_omitted_unless_allowed_and_abort_when_disallowed]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[generated_evidence_anchors_are_omitted_unless_allowed_and_abort_when_disallowed] - Kind:
fn src/authoring/inputs.rs:1798–1869
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.read_denial`
#[test]
fn generated_evidence_anchors_are_omitted_unless_allowed_and_abort_when_disallowed() {
let root = project();
fs::create_dir_all(root.path().join("evidence")).unwrap();
fs::write(root.path().join("evidence/report.md"), "# Report\n").unwrap();
#[cfg(unix)]
std::os::unix::fs::symlink("evidence", root.path().join("alias")).unwrap();
let declaration = |anchor: &str| {
fs::write(
root.path().join("md/requirements.md"),
format!(":::{{req}} ready\n:test: {anchor}\nThe project MUST be ready.\n:::\n"),
)
.unwrap();
};
let has_file = |sources: &AssessmentSources, file: &str| {
sources
.mandatory_inputs()
.iter()
.any(|input| input["file"] == file)
};
// Default exclusion omits the anchor instead of aborting.
declaration("evidence/report.md");
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert!(
!has_file(&sources, "evidence/report.md"),
"{:#?}",
sources.mandatory_inputs()
);
assert_eq!(sources.mandatory_inputs().len(), 1);
// A symlink alias into `evidence/` is omitted too.
#[cfg(unix)]
{
declaration("alias/report.md");
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert!(
!has_file(&sources, "alias/report.md"),
"{:#?}",
sources.mandatory_inputs()
);
assert_eq!(sources.mandatory_inputs().len(), 1);
}
// An explicit allow permits the selection.
declaration("evidence/report.md");
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\nallow = ['evidence/report.md']\n",
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert!(
has_file(&sources, "evidence/report.md"),
"{:#?}",
sources.mandatory_inputs()
);
// An explicit disallow aborts before inference.
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\ndisallow = ['evidence']\n",
)
.unwrap();
let error = AssessmentSources::prepare(root.path(), "requirements.ready")
.err()
.unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(error.to_string().contains("evidence/report.md"), "{error}");
}
Input 17: outline src/authoring/inputs.rs mod[tests]/fn[generated_evidence_references_are_omitted_by_default]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[generated_evidence_references_are_omitted_by_default] - Kind:
fn src/authoring/inputs.rs:1871–1943
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.references.authoring_inputs`
#[test]
fn generated_evidence_references_are_omitted_by_default() {
let root = project();
fs::create_dir_all(root.path().join("evidence")).unwrap();
fs::write(
root.path().join("evidence/notes.md"),
format!("# Notes\n\n{}\n", role("test", "requirements.ready")),
)
.unwrap();
fs::write(
root.path().join("src/literal.rs"),
format!(
"const REFERENCE: &str = {:?};\n",
role("test", "requirements.ready")
),
)
.unwrap();
fs::write(
root.path().join("evidence/copy.json"),
json!({"rationale":role("test", "requirements.ready")}).to_string(),
)
.unwrap();
fs::write(
root.path().join("notes.txt"),
role("test", "requirements.ready"),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert!(
sources
.mandatory_inputs()
.iter()
.any(|input| input["file"] == "notes.txt")
);
assert!(
!sources
.mandatory_inputs()
.iter()
.any(|input| input["file"] == "evidence/notes.md"),
"{:#?}",
sources.mandatory_inputs()
);
for excluded in ["src/literal.rs", "evidence/copy.json"] {
assert!(
!sources
.mandatory_inputs()
.iter()
.any(|input| input["file"] == excluded)
);
}
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\nallow = ['evidence/notes.md']\n",
)
.unwrap();
let allowed = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
// Reference discovery has fixed exclusions under references.discovery.
// Explicit allowances permit an anchor or requested read into evidence/,
// as the anchor test checks; they do not discover references there.
assert!(
!allowed
.mandatory_inputs()
.iter()
.any(|input| input["file"] == "evidence/notes.md"),
"{:#?}",
allowed.mandatory_inputs()
);
assert!(!allowed.mandatory_inputs().iter().any(|input| input["file"]
== "evidence/copy.json"
|| input["file"] == "src/literal.rs"));
}
Input 18: outline src/authoring/mod.rs mod[tests]/fn[citation_reviews_use_their_prompt_and_record_the_item_and_citations]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[citation_reviews_use_their_prompt_and_record_the_item_and_citations] - Kind:
fn src/authoring/mod.rs:4261–4416
// {test}`requirements.authoring.citation_prompt`
// {test}`requirements.references.citation_review`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.habeas_background`
// {test}`requirements.authoring.judgment_rules`
// {test}`requirements.authoring.adaptive`
#[tokio::test]
async fn citation_reviews_use_their_prompt_and_record_the_item_and_citations() {
let project = inputs::tests::project();
let cite = "{cite}`requirements.ready`";
fs::write(
project.path().join("src/lib.rs"),
format!(
"// {cite}\n// :::{{cite}} habeas:util\n// Formats output for the caller.\n// :::\nfn helper() {{}}\n"
),
)
.unwrap();
let subject = AuthoringSubject::parse("citations:src/lib.rs#fn[helper]");
assert_eq!(
subject.evidence_path(project.path()),
project
.path()
.join("evidence/citations/src/lib.rs/fn[helper].json")
);
let mut sources = subject.sources(project.path()).unwrap();
assert!(!sources.has_applicable_fixme);
let mandatory = sources.mandatory_inputs().to_vec();
assert_eq!(mandatory[0]["file"], "src/lib.rs");
assert_eq!(mandatory[0]["item"], "fn[helper]");
assert_eq!(mandatory[1]["requirements"], "requirements.ready");
assert_eq!(mandatory[2]["builtin"], "habeas:util");
assert!(
mandatory[2]["text"][0]
.as_str()
.unwrap()
.starts_with("Cite this on an item that serves")
);
let state = tempfile::tempdir().unwrap();
let mut usage = UsageLog::start(state.path(), project.path(), &subject.label()).unwrap();
let provider = RecordingProvider::new(vec![judgment(json!(true), "Both are sensible.")]);
let (_, record) = assess(&provider, &mut sources, &mut usage).await.unwrap();
let prompts = provider.prompts();
let expected: Vec<_> = tool_definitions_with("submit_judgment", false)
.unwrap()
.into_iter()
.map(|tool| tool.name)
.collect();
assert_eq!(prompts[0].1, expected);
let duplicate = json!({"determination":true,"rationale":"Both are sensible."});
let duplicate_provider = ScriptedProvider {
turns: vec![vec![
("submit_judgment", duplicate.clone()),
("submit_judgment", duplicate),
]],
requests: RefCell::default(),
};
let mut duplicate_sources = subject.sources(project.path()).unwrap();
assert!(
assess(&duplicate_provider, &mut duplicate_sources, &mut usage)
.await
.unwrap_err()
.to_string()
.contains("exactly once")
);
let prompt = &prompts[0].0;
assert!(
prompt.contains("Review one source item's citations."),
"{prompt}"
);
assert!(
prompt.contains("Item under review: src/lib.rs fn[helper]"),
"{prompt}"
);
assert!(
prompt.contains("Formats output for the caller."),
"{prompt}"
);
// The initial request carries the complete mandatory set.
assert!(
prompt.contains(mandatory[0]["hash"].as_str().unwrap()),
"{prompt}"
);
assert!(prompt.contains("The project MUST be ready."), "{prompt}");
assert!(
prompt.contains("Cite this on an item that serves"),
"{prompt}"
);
// Prompts are recorded as serialized requests.
for background in [
approved_text("habeas_background", 0),
approved_text("habeas_background", 1),
approved_text("judgment_rules", 0),
] {
let background = serde_json::to_string(background).unwrap();
assert!(prompt.contains(background.trim_matches('"')), "{prompt}");
}
assert!(!prompt.contains("{{"), "{prompt}");
let citations = json!([
{"role": "cite", "name": "requirements.ready", "commentary": ""},
{"role": "cite", "name": "habeas:util", "commentary": "Formats output for the caller."}
]);
let request: Value = serde_json::from_str(prompt).unwrap();
// Compare the actual placeholder payload, rather than text which
// could also appear independently in the mandatory source inputs.
let user = request["chat_history"]
.as_array()
.unwrap()
.iter()
.find(|message| message["role"] == "user")
.unwrap();
let subject_text = user["content"][0]["text"].as_str().unwrap();
let payload = subject_text
.lines()
.find_map(|line| line.strip_prefix("Citations to check: "))
.unwrap();
assert_eq!(serde_json::from_str::<Value>(payload).unwrap(), citations);
assert_eq!(record["file"], "src/lib.rs");
assert_eq!(record["item"], "fn[helper]");
assert_eq!(record["citations"], citations);
assert_eq!(record["determination"], true);
let inputs = record["inputs"].as_array().unwrap();
assert!(inputs.iter().all(|input| input.get("builtin").is_none()));
assert_eq!(inputs.len(), 2, "{inputs:#?}");
// The recorded review satisfies validation for its item.
let path = subject.evidence_path(project.path());
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(&path, record.to_string()).unwrap();
let errors = crate::validate_repository(project.path()).unwrap().errors;
assert!(
!errors
.iter()
.any(|error| error.starts_with("evidence/citations/")),
"{errors:#?}"
);
// A name without a selector reviews the file's root node.
assert!(matches!(
AuthoringSubject::parse("citations:notes.txt"),
AuthoringSubject::Citation { file, item } if file == "notes.txt" && item.is_empty()
));
// The root node's selector is shown as `<root>` in the prompt.
fs::write(project.path().join("notes.txt"), format!("Notes. {cite}\n")).unwrap();
let sources = AuthoringSubject::parse("citations:notes.txt")
.sources(project.path())
.unwrap();
let prompt = initial_prompt(&sources).unwrap().joined();
assert!(
prompt.contains("Item under review: notes.txt <root>"),
"{prompt}"
);
assert!(!prompt.contains("{{"), "{prompt}");
}
Input 19: outline src/authoring/mod.rs mod[tests]/fn[site_reviews_use_their_prompt_and_record_applies_and_the_site]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[site_reviews_use_their_prompt_and_record_applies_and_the_site] - Kind:
fn src/authoring/mod.rs:4783–4960
// {test}`requirements.authoring.site_prompt`
// {test}`requirements.authoring.habeas_background`
// {test}`requirements.references.site_review`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.judgment_rules`
// {test}`requirements.authoring.no_line_numbers`
#[tokio::test]
async fn site_reviews_use_their_prompt_and_record_applies_and_the_site() {
let project = crate::sites::tests::project(
crate::sites::tests::RULE,
&crate::sites::tests::SOURCE.replace(
"fn check_two() {}",
"fn check_two() {\n // :::{fixme} requirements.rule\n // Panics.\n // :::\n}",
),
);
let root = project.path();
let declaration = crate::sites::tests::RULE.replace("Each checker MUST report problems instead of panicking.", "Each checker MUST report problems instead of panicking. {cite}`requirements.other` {term}`terms.value`");
fs::write(
root.join("md/requirements.md"),
format!("{declaration}\n:::{{req}} other\nOther MUST hold.\n:::\n"),
)
.unwrap();
fs::write(
root.join("md/terms.md"),
":::{definition} value\n:phrase: value\nA useful value.\n:::\n",
)
.unwrap();
let subject = AuthoringSubject::parse("sites:requirements.rule/src/lib.rs#fn[check_two]");
assert_eq!(
subject.evidence_path(root),
root.join("evidence/sites/requirements.rule/src/lib.rs/fn[check_two].json")
);
let mut sources = subject.sources(root).unwrap();
let mandatory = sources.mandatory_inputs().to_vec();
assert_eq!(mandatory[0]["file"], "src/lib.rs");
assert_eq!(mandatory[0]["item"], "fn[check_two]");
assert_eq!(mandatory[1]["requirements"], "requirements.rule");
assert_eq!(mandatory.len(), 4, "{mandatory:#?}");
assert!(
mandatory
.iter()
.any(|input| input["requirements"] == "requirements.other")
);
assert!(
mandatory
.iter()
.any(|input| input["definition"] == "terms.value")
);
// The subject message names the requirement, the site's file and
// selector, and each query match with its kind, name and lines.
let matches =
json!([{"kind": "sites", "query": "checkers", "item": "fn[check_two]"}]).to_string();
let mandatory_inputs =
serde_json::to_string_pretty(&sources.model_mandatory_inputs()).unwrap();
let expected_subject = fill(
approved_text("site_prompt", 1),
&[
("requirement_name", "requirements.rule"),
("site_file", "src/lib.rs"),
("site_selector", "fn[check_two]"),
("matches", &matches),
("mandatory_inputs", &mandatory_inputs),
],
);
let initial = initial_prompt(&sources).unwrap();
assert_eq!(initial.subject, expected_subject);
assert!(
initial
.subject
.starts_with(&format!(
"# Subject\n\nSite under review: src/lib.rs fn[check_two]\nRequirement: requirements.rule\nMatches: {matches}\n"
)),
"{}",
initial.subject
);
let state = tempfile::tempdir().unwrap();
let mut usage = UsageLog::start(state.path(), root, &subject.label()).unwrap();
let provider = RecordingProvider::new(vec![(
"submit_judgment",
json!({"applies": true, "determination": {"FIXME": ["Panics."]}, "rationale": "Acknowledged."}),
)]);
let (_, record) = assess(&provider, &mut sources, &mut usage).await.unwrap();
let prompts = provider.prompts();
let (prompt, tools) = &prompts[0];
let prompt = serde_json::from_str::<Value>(prompt).unwrap();
let text = prompt.to_string();
assert!(
text.contains(
serde_json::to_string(&initial.subject)
.unwrap()
.trim_matches('"')
),
"the subject message reaches the model"
);
let heading = approved_text("site_prompt", 0)
.split("\n\n# Background")
.next()
.unwrap();
assert!(
text.contains(serde_json::to_string(heading).unwrap().trim_matches('"')),
"{heading}\n{text}"
);
for block in [
approved_text("habeas_background", 0),
distributed_background(),
approved_text("judgment_rules", 0),
] {
assert!(
text.contains(serde_json::to_string(block).unwrap().trim_matches('"')),
"{block}"
);
}
assert!(
!text.contains(
serde_json::to_string(approved_text("habeas_background", 1))
.unwrap()
.trim_matches('"')
),
"the site prompt has no reference roles"
);
assert!(!text.contains("{{"), "{text}");
assert!(tools.contains(&"submit_judgment".to_owned()));
let expected: Vec<_> = tool_definitions_with("submit_judgment", false)
.unwrap()
.into_iter()
.map(|tool| tool.name)
.collect();
assert_eq!(*tools, expected);
let duplicate = json!({"applies":true,"determination":true,"rationale":"Covered."});
let duplicate_provider = ScriptedProvider {
turns: vec![vec![
("submit_judgment", duplicate.clone()),
("submit_judgment", duplicate),
]],
requests: RefCell::default(),
};
let mut duplicate_sources = subject.sources(root).unwrap();
assert!(
assess(&duplicate_provider, &mut duplicate_sources, &mut usage)
.await
.unwrap_err()
.to_string()
.contains("exactly once")
);
let submit = provider.requests.borrow()[0]["tools"]
.as_array()
.unwrap()
.iter()
.find(|tool| tool["name"] == "submit_judgment")
.unwrap()
.clone();
assert_eq!(
submit["parameters"]["required"],
json!(["determination", "rationale", "applies"])
);
assert_eq!(record["requirement"], "requirements.rule");
assert_eq!(record["file"], "src/lib.rs");
assert_eq!(record["item"], "fn[check_two]");
assert_eq!(record["queries"], json!(["checkers"]));
assert_eq!(record["applies"], true);
assert_eq!(
record["fixmes"],
json!([{"item": "fn[check_two]", "commentary": "Panics."}])
);
// The recorded review satisfies validation for its site.
let path = subject.evidence_path(root);
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(&path, record.to_string()).unwrap();
let errors = crate::validate_repository(root).unwrap().errors;
let prefix = crate::sites::review_path("requirements.rule", "src/lib.rs", "fn[check_two]");
assert!(
!errors.iter().any(|error| error.starts_with(&prefix)),
"{errors:#?}"
);
}
Input 20: outline src/authoring/tools.rs mod[tests]/fn[model_inputs_reads_searches_and_citation_prompts_are_redacted]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[model_inputs_reads_searches_and_citation_prompts_are_redacted] - Kind:
fn src/authoring/tools.rs:1696–1774
// {test}`requirements.authoring.redaction`
// {test}`requirements.authoring.credentials`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.citation_prompt`
// {test}`requirements.authoring.fixme_inputs`
#[test]
fn model_inputs_reads_searches_and_citation_prompts_are_redacted() {
let root = project();
let token = crate::redaction::tests::github_token();
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\napi_key = 'plain ollama key'\n",
)
.unwrap();
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {}\nfn client() -> &'static str {{\n \"{token}\"\n}}\n\n// :::{} requirements.ready\n// Defaults to {token}.\n// :::\nfn helper() {{}}\n\n// :::{{fixme}} requirements.ready\n// Missing check for {token}.\n// :::\nfn gap() {{}}\n",
role("test", "requirements.ready"),
"{cite}"
),
)
.unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
let leaks = |value: &Value| {
let text = value.to_string();
text.contains(&token) || text.contains("plain ollama key")
};
// Mandatory inputs, and so the initial and verification prompts.
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let mandatory = Value::Array(sources.mandatory_inputs().to_vec());
assert!(!leaks(&mandatory), "{mandatory:#}");
assert!(mandatory.to_string().contains("[REDACTED:GitHub Token]"));
let prompt = super::super::initial_prompt(&sources).unwrap().joined();
assert!(!prompt.contains(&token), "{prompt}");
assert!(
prompt.contains("Missing check for [REDACTED:GitHub Token]."),
"{prompt}"
);
assert!(!prompt.contains("fn gap()"), "{prompt}");
// A habeas read of the configuration file and a line range.
let read = dispatch(&sources, "habeas", &json!({"file":"habeas.toml","item":""})).unwrap();
assert!(!leaks(&read.result), "{:#}", read.result);
assert!(
read.result["input"]["text"]
.as_array()
.unwrap()
.contains(&json!("api_key = '[REDACTED:api_key]'"))
);
let lines = dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","line_start":1}),
)
.unwrap();
assert!(!leaks(&lines.result), "{:#}", lines.result);
// Search results, even for a pattern matching the credential itself.
for pattern in ["ollama", "gh[p]_", "Defaults"] {
let search = dispatch(&sources, "ripgrep", &json!({"pattern": pattern})).unwrap();
assert!(
!search.result["matches"].as_array().unwrap().is_empty(),
"{pattern}"
);
assert!(!leaks(&search.result), "{pattern}: {:#}", search.result);
}
// A citation review's inputs and its commentary in the prompt.
let citation =
AssessmentSources::prepare_citation(root.path(), "src/lib.rs", "fn[helper]").unwrap();
assert!(!leaks(&Value::Array(citation.mandatory_inputs().to_vec())));
let prompt = super::super::initial_prompt(&citation).unwrap().joined();
assert!(!prompt.contains(&token), "{prompt}");
assert!(
prompt.contains("Defaults to [REDACTED:GitHub Token]."),
"{prompt}"
);
}
Input 21: outline src/authoring/tools.rs mod[tests]/fn[mandatory_inputs_outside_the_project_still_abort]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[mandatory_inputs_outside_the_project_still_abort] - Kind:
fn src/authoring/tools.rs:3205–3225
// {test}`requirements.authoring.read_denial`
// {test}`requirements.authoring.mandatory_inputs`
#[test]
fn mandatory_inputs_outside_the_project_still_abort() {
let root = project();
let external = tempfile::tempdir().unwrap();
fs::write(external.path().join("skill.md"), "# Skill\n").unwrap();
fs::write(
root.path().join("md/requirements.md"),
format!(
":::{{req}} ready\n:impl: {}\nThe project MUST be ready.\n:::\n",
external.path().join("skill.md").display()
),
)
.unwrap();
let error = AssessmentSources::prepare(root.path(), "requirements.ready")
.err()
.unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(error.to_string().contains("outside the project"), "{error}");
}
Input 22: outline tests/authoring_cli.rs fn[implementation_discovery_has_no_text_or_evidence_until_the_model_requests_a_read]
- File:
tests/authoring_cli.rs - Selector:
fn[implementation_discovery_has_no_text_or_evidence_until_the_model_requests_a_read] - Kind:
fn tests/authoring_cli.rs:292–364
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.reference_index`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.authoring.fixme_inputs`
// {test}`requirements.authoring.complete_initial_bundle`
#[test]
fn implementation_discovery_has_no_text_or_evidence_until_the_model_requests_a_read() {
let server = Server::start(vec![
reply(vec![call(
"locate",
"references",
json!({"selection": SUBJECT, "roles": ["impl"]}),
)]),
reply(vec![call(
"read",
"habeas",
json!({"file": "src/lib.rs", "item": "fn[ready]"}),
)]),
reply(vec![call(
"submit",
"submit_judgment",
json!({"determination": true, "rationale": "The tests check the requirement."}),
)]),
]);
let fixture = Fixture::new(&server.endpoint);
let output = fixture.run(&["author", SUBJECT]);
assert!(output.status.success(), "{output:?}");
let requests = server.finish();
assert_eq!(requests.len(), 3);
let prompt = prompt_text(&requests[0].body);
assert!(prompt.contains("fn ready_test()"));
assert!(prompt.contains("One acknowledged gap."));
assert!(!prompt.contains("pub fn ready()"));
let tool_result = |request: &Request| -> Value {
let message = request.body["messages"]
.as_array()
.unwrap()
.iter()
.rev()
.find(|message| message["role"] == "tool")
.unwrap();
serde_json::from_str(message["content"].as_str().unwrap()).unwrap()
};
let locations = tool_result(&requests[1]);
assert!(locations.to_string().contains("fn[ready]"), "{locations:#}");
for text in [
REQUIREMENT,
"One acknowledged gap.",
"pub fn ready()",
"\"input\"",
"\"inputs\"",
] {
assert!(!locations.to_string().contains(text), "{locations:#}");
}
let read = tool_result(&requests[2]);
assert!(read["input"]["text"].to_string().contains("pub fn ready()"));
assert_eq!(read["input"]["file"], "src/lib.rs");
assert_eq!(read["input"]["item"], "fn[ready]");
assert_eq!(
read["input"]["hash"],
habeas::outline_input(&fixture.project, "src/lib.rs", "fn[ready]").unwrap()["hash"]
);
let record: Value = serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
let inputs = record["inputs"].as_array().unwrap();
assert_eq!(
inputs
.iter()
.filter(|input| input["file"] == "src/lib.rs" && input["item"] == "fn[ready]")
.count(),
1
);
assert!(!fixture.usage()["inputs"].to_string().contains("references"));
}
Input 23: outline tests/authoring_cli.rs fn[ollama_cli_delivers_sources_records_fixme_and_keeps_usage_content_free]
- File:
tests/authoring_cli.rs - Selector:
fn[ollama_cli_delivers_sources_records_fixme_and_keeps_usage_content_free] - Kind:
fn tests/authoring_cli.rs:366–676
// {test}`requirements.authoring.complete_initial_bundle`
// {test}`requirements.authoring.invocation`
// {test}`requirements.authoring.additional_read`
// {test}`requirements.authoring.acknowledged_gap`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.rig_configuration_mapping`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.authoring.initial_prompt`
// {test}`requirements.ci.review_criteria`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.authoring.usage_inputs`
// {test}`requirements.authoring.usage_requests`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.github_reads`
// {test}`requirements.authoring.invocation`
// {test}`requirements.configuration.serialization`
// {test}`requirements.ci.fixme_implementation_gap`
// {test}`requirements.authoring.finish_search.empty`
// {test}`requirements.authoring.finish_search.completion`
#[test]
// {test}`requirements.authoring.persistence`
// {test}`requirements.authoring.reporting`
fn ollama_cli_delivers_sources_records_fixme_and_keeps_usage_content_free() {
let server = Server::start(vec![
reply(vec![
call("list", "list_files", json!({})),
call(
"search",
"ripgrep",
json!({"path":"extra.txt","pattern":"needle"}),
),
call(
"read",
"habeas",
json!({"file":"extra.txt","line_start":10}),
),
call(
"repeat",
"habeas",
json!({"file":"extra.txt","line_start":10}),
),
call(
"missing",
"habeas",
json!({"file":"absent.txt","line_start":1}),
),
]),
json!({"__finish_latest_search":true}),
reply(vec![call(
"submit",
"submit_judgment",
json!({
"determination":{"FIXME":["example/app#125"]},"rationale":"SECRET_RATIONALE: `src/lib.rs#fn[ready]` documents the gap."}),
)]),
]);
let fixture = Fixture::new(&server.endpoint);
let user_config = fixture.config.join("habeas/config.toml");
let configured = fs::read(&user_config).unwrap();
let output = fixture.run(&["author-evidence", SUBJECT]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
// The user configuration, with its environment-resolved key, is not
// rewritten.
assert_eq!(fs::read(&user_config).unwrap(), configured);
let requests = server.finish();
assert_eq!(requests.len(), 3);
for request in &requests {
assert!(request.headers.starts_with("POST /api/chat HTTP/1.1\r\n"));
assert!(request.headers.to_ascii_lowercase().contains(&format!(
"authorization: bearer {}",
AUTH.to_ascii_lowercase()
)));
assert_eq!(request.body["model"], MODEL);
assert_eq!(request.body["options"]["temperature"], 0.25);
assert_eq!(request.body["options"]["num_ctx"], 4096);
assert_eq!(request.body["think"], false);
assert_eq!(request.body["stream"], false);
}
let prompt = prompt_text(&requests[0].body);
for text in [
"Assess whether a project's tests adequately check one requirement.",
REQUIREMENT,
"SECRET_DEFINITION_TEXT",
"fn ready_test()",
"You MUST end by calling submit_judgment",
] {
assert!(prompt.contains(text), "prompt missing {text}");
}
assert!(!prompt.contains("pub fn ready()"), "{prompt}");
assert!(!prompt.contains("OLD_RATIONALE_MUST_NOT_REACH_MODEL"));
let mut tools = requests[0].body["tools"]
.as_array()
.unwrap()
.iter()
.map(|tool| tool["function"]["name"].as_str().unwrap())
.collect::<Vec<_>>();
tools.sort();
assert_eq!(
tools,
[
"ast_grep",
"finish_search",
"github",
"habeas",
"list_files",
"next_page",
"outline",
"references",
"ripgrep",
"submit_judgment"
]
);
let results = requests[1].body["messages"]
.as_array()
.unwrap()
.iter()
.filter(|message| message["role"] == "tool")
.collect::<Vec<_>>();
assert_eq!(results.len(), 5);
assert!(results.iter().any(|message| {
message["content"]
.as_str()
.unwrap()
.contains("SECRET_SOURCE_PAYLOAD")
}));
assert!(
results
.iter()
.any(|message| message["content"].as_str().unwrap().contains("absent.txt"))
);
let evidence: Value = serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
assert_eq!(
evidence["determination"],
json!({"FIXME":["example/app#125"]})
);
assert_eq!(
evidence["rationale"],
"SECRET_RATIONALE: `src/lib.rs#fn[ready]` documents the gap."
);
assert_eq!(evidence["requirement"], REQUIREMENT);
let inputs = evidence["inputs"].as_array().unwrap();
assert!(
inputs
.iter()
.any(|input| input["file"] == "src/lib.rs" && input["item"] == "fn[ready_test]"),
"{inputs:#?}"
);
// The acknowledgment reaches the model as metadata, without the
// containing implementation. Its body is protected by the reference set.
assert!(prompt.contains(":github: example/app#125"));
assert!(prompt.contains("One acknowledged gap."));
// GitHub is unreachable, so the issue is supplied as open, but the state
// is not recorded.
assert!(
prompt.contains("\"reference\": \"example/app#125\"")
&& prompt.contains("\"state\": \"open\""),
"{prompt}"
);
assert!(!evidence.to_string().contains("github_issues"));
assert!(!fixture.usage().to_string().contains("github_issues"));
assert!(
!inputs
.iter()
.any(|input| input["file"] == "src/lib.rs" && input["item"] == "fn[ready]"),
"{inputs:#?}"
);
// CI accepts the FIXME judgment: its evidence has no validation error.
let report = habeas::validate_repository(&fixture.project).unwrap();
let label = format!("evidence/{SUBJECT}.json");
assert!(
!report.errors.iter().any(|error| error.contains(&label)),
"{:#?}",
report.errors
);
// The same record with a false determination is rejected.
let mut rejected = evidence.clone();
rejected["determination"] = json!(false);
let accepted = fs::read(&fixture.evidence).unwrap();
fs::write(&fixture.evidence, rejected.to_string()).unwrap();
let report = habeas::validate_repository(&fixture.project).unwrap();
assert!(
report.errors.iter().any(|error| error.contains(&label)),
"{:#?}",
report.errors
);
fs::write(&fixture.evidence, accepted).unwrap();
assert!(
inputs
.iter()
.any(|input| input["definition"] == "terms.readiness")
);
let extra = inputs
.iter()
.filter(|input| input["file"] == "extra.txt")
.collect::<Vec<_>>();
// The search only locates lines and records nothing; the reads cover
// lines 10-12, one plain-text line node each, and the repeated delivery
// is recorded once, by selector and hash only.
assert_eq!(
extra,
habeas::outline_inputs_for_lines(&fixture.project, "extra.txt", 10, 12)
.unwrap()
.iter()
.collect::<Vec<_>>(),
"repeated delivery is deduplicated in evidence"
);
assert!(
!evidence["inputs"]
.to_string()
.contains("SECRET_SOURCE_PAYLOAD")
);
assert!(
!inputs
.iter()
.any(|input| input["file"] == "absent.txt" || input["file"] == ".")
);
let usage = fixture.usage();
assert_eq!(usage["outcome"], "completed");
assert_eq!(usage["determination"], "FIXME");
assert_eq!(usage["evidence_written"], true);
assert_eq!(usage["request_count"], 3);
assert_eq!(usage["tool_call_count"], 7);
assert_eq!(usage["tool_calls"]["habeas"], 3);
assert_eq!(usage["tool_failures"]["habeas"], 1);
// The directory listing counts as a tool call but is not an input.
assert_eq!(usage["tool_calls"]["list_files"], 1);
assert_eq!(usage["tool_calls"]["ripgrep"], 1);
assert_eq!(usage["tool_calls"]["finish_search"], 1);
let usage_inputs = usage["inputs"].as_array().unwrap();
assert!(
!usage_inputs
.iter()
.any(|input| input["origin"] == "list_files"),
"{usage_inputs:?}"
);
// Search snippets count toward usage, without becoming evidence inputs.
assert!(
usage_inputs.iter().any(|input| input["origin"] == "ripgrep"
&& input["kind"] == "search"
&& input["bytes"].as_u64().unwrap() > 0
&& input["lines"].as_u64().unwrap() > 0),
"{usage_inputs:?}"
);
assert!(
usage_inputs
.iter()
.any(|input| input["origin"] == "habeas" && input["unique"] == true),
"{usage_inputs:?}"
);
assert_eq!(usage["tokens"]["input"], 33);
assert_eq!(usage["tokens"]["output"], 21);
assert_eq!(usage["tokens"]["complete"], true);
assert!(
usage["inputs"]
.as_array()
.unwrap()
.iter()
.any(|input| input["origin"] == "habeas"
&& input["unique"] == false
&& input["sent_in_request"] == 1)
);
assert!(
usage["inputs"]
.as_array()
.unwrap()
.iter()
.any(|input| input["origin"] == "mandatory"
&& input["kind"] == "definition"
&& input["bytes"].as_u64().unwrap() > 0)
);
let serialized = usage.to_string();
for secret in [
"SECRET_REQUIREMENT_TEXT",
"SECRET_DEFINITION_TEXT",
"SECRET_SOURCE_PAYLOAD",
"SECRET_RATIONALE",
AUTH,
"#125",
] {
assert!(
!serialized.contains(secret),
"usage contains source or credential content: {secret}"
);
}
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(stdout.contains(MODEL) && stdout.contains("Evidence:") && stdout.contains("Usage:"));
// By default the report names the subject and backend and identifies the
// evidence file it wrote.
assert!(
stdout.starts_with(&format!("{SUBJECT}: ollama / {MODEL}")),
"{stdout}"
);
let evidence = stdout
.lines()
.find_map(|line| line.strip_prefix("Evidence: "))
.unwrap();
assert!(
evidence.ends_with(&format!("evidence/{SUBJECT}.json")),
"{stdout}"
);
assert_eq!(
fs::canonicalize(evidence).unwrap(),
fs::canonicalize(fixture.project.join(format!("evidence/{SUBJECT}.json"))).unwrap()
);
}
Input 24: outline tests/authoring_cli.rs fn[unresolvable_mandatory_inputs_fail_before_any_model_request]
- File:
tests/authoring_cli.rs - Selector:
fn[unresolvable_mandatory_inputs_fail_before_any_model_request] - Kind:
fn tests/authoring_cli.rs:2791–2815
// {test}`requirements.authoring.mandatory_inputs`
#[test]
fn unresolvable_mandatory_inputs_fail_before_any_model_request() {
let listener = TcpListener::bind(("127.0.0.1", 0)).unwrap();
listener.set_nonblocking(true).unwrap();
let fixture = Fixture::new(&format!("http://{}", listener.local_addr().unwrap()));
// The subject's own declaration is a mandatory input that cannot be read.
fs::write(
fixture.project.join("habeas.toml"),
"version = 1\n[evidence]\ndisallow = ['md/requirements.md']\n",
)
.unwrap();
let output = fixture.run(&["author", SUBJECT]);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(!output.status.success(), "{stderr}");
assert!(stderr.contains("md/requirements.md"), "{stderr}");
assert!(
matches!(listener.accept(), Err(error) if error.kind() == std::io::ErrorKind::WouldBlock),
"the model endpoint was contacted"
);
assert_eq!(
fs::read_to_string(&fixture.evidence).unwrap(),
fixture.original
);
}
Referenced definitions
Input 2: requirements selection requirements.authoring.read_denial.mandatory
requirements.authoring.read_denial.mandatory:md/requirements/authoring.md:725–734
:::{req} read_denial.mandatory
When source-access policy denies a mandatory input, the assessment MUST abort
before any model request and report the denied path and reason to its caller;
for an untracked file, the report MUST say what {cite}`requirements.authoring.read_denial.untracked`
says. The aborted assessment MUST NOT write evidence or emit evidence JSON, and
its usage record MUST identify the failure. In a batch, other assessments MUST
continue, including queued assessments, and their successful writes MUST be
retained; the command MUST return a nonzero exit status after the batch
finishes.
:::
Other sources
Input 1: requirements selection requirements.authoring.mandatory_inputs
requirements.authoring.mandatory_inputs:md/requirements/authoring.md:1285–1297
:::{req} mandatory_inputs
The harness MUST construct each assessment's mandatory input set by combining
the contributions specified by the requirements applicable to that subject and
its inputs. A requirement that contributes inputs MUST cite this requirement and
define which sources it contributes and when. The harness MUST include every
applicable contribution, deduplicate identical selections, and report
unresolvable mandatory inputs before inference. The complete set MUST be supplied
in the initial model request.
Generated output under project-root `evidence/`, including symlink aliases, MUST
be omitted from mandatory inputs when the default exclusion applies. An explicit
workspace allow MUST permit those selections; an explicit disallow MUST abort
under {cite}`requirements.authoring.read_denial.mandatory`.
:::