requirements.authoring.judgment_rules
Requirements index · View definition
Requirement
Every assessment prompt MUST replace
{{judgment_rules}}with this text, so all assessments judge by the same rules:- Derive obligations from the supplied subject and contextual text. Base conclusions about tests or other source behavior only on source code you have received: mandatory inputs, items read with the habeas tool, or snippets returned by ripgrep or ast_grep. Close every delivered search with finish_search, recording the tags whose snippets you relied on without an additional source read. Supplied acknowledgments establish what a {fixme} reference says and which issues it names; they do not establish that its claimed gap is real. outline, list_files, and references only locate items; read any item whose code your conclusion relies on unless a search snippet provides the information you need. Comments state intent; check behavior and assertions in the code itself. - Judge only against the text your task names. Report a gap only where your task or these rules define one, naming the obligation and the relevant sources you have reviewed. For a missing test, identify the obligation or scenario after looking where your task directs; do not invent a source item for absent code. Do not report other bugs or issues you notice; edge cases the text does not name are not gaps. - A SHOULD imposes an obligation unless the text or a source comment gives a reason it does not apply. In a test-adequacy assessment, apply the testing criteria to each applicable SHOULD, and explain any exception in your rationale. MAY imposes nothing to check. Examples and sample output inside the text illustrate the obligations its prose states; they bind their exact form only where the text says the output takes that form. - If the text admits two readings that its wording supports equally, not merely one it fails to exclude, and they lead to different conclusions, such as whether code conforms or which role a citation calls for, that ambiguity is a gap. Name the readings in your rationale. - These are not gaps: style, performance, logging, how helpers are factored, robustness the text does not require, and silently ignoring input the text does not mention. - A gap is acknowledged only by a {fixme} reference, in the supplied acknowledgments, in the inputs, or in a source you read, to the requirement or example your task judges against, or, in a site review, to the distributed requirement within the site, whose body describes that same gap, and whose named issues are open; a {fixme} naming a closed issue no longer acknowledges its gap. A plain FIXME or TODO comment is not an acknowledgment. Judge an acknowledgment only within your task's scope. An acknowledgment of an implementation bug alone does not establish a test-adequacy gap or acknowledge a different missing-test or assertion gap. Do not inspect implementation correctness merely to validate an out-of-scope acknowledgment. In a FIXME determination or an acknowledgments list, give each distinct issue its :github: option names once, such as "rust-lang/rust#123", and, for a {fixme} naming no issue, its body's words joined by single spaces. A {fixme} describing a gap that your review establishes no longer exists within its task's scope is itself a gap. - Explain your judgment in a Markdown rationale with source locations, including any acknowledged gaps. - Give a source location as its file and outline selector, the address the habeas and outline tools use, in backticks: `src/config.rs#fn[load]`, or `src/config.rs` for a whole file. Name requirements, examples, and definitions by full name in backticks. Name functions, types, and tests in backticks exactly as they are written. Do not give line numbers: they change whenever nearby code changes, while a selector stays correct.
Rationale
Obligation. The requirement has one testable obligation. Every assessment prompt must contain the judgment_rules text in place of the {{judgment_rules}} placeholder. The prompts in scope are the initial prompts for a requirement, an example, a citation review and a site review. The verifier prompts are also in scope. The substituted text must match the requirement text, and no placeholder may be left behind.
Implementation shape. I read src/authoring/mod.rs#fn[shared_blocks], fn[initial_prompt] and fn[verification_prompt]. All prompts take the block from approved_text("judgment_rules", 0), which extracts the block from md/requirements/authoring.md. That is the same text as the requirement. The test helper approved_text uses the same extraction, so the tests compare against the requirement’s own text rather than a copy.
Test coverage by prompt kind:
- Requirement initial prompt:
initial_prompt_carries_the_review_criteriaasserts that the prompt containsapproved_text("judgment_rules", 0). It also asserts that the prompt has no{{. - Citation initial prompt:
citation_reviews_use_their_prompt_and_record_the_item_and_citationschecks the serialized request forjudgment_rules, along with the two habeas background blocks. It also asserts that the prompt has no{{. - Site initial prompt:
site_reviews_use_their_prompt_and_record_applies_and_the_sitechecks the JSON-escaped text forjudgment_rules. It also asserts that the prompt has no{{. - Requirement verifier prompt:
disagreeing_assessments_verify_the_less_favorable_onechecks the third recorded prompt forjudgment_rulesand for no{{. - Example and citation verifier prompts:
verifier_prompts_name_examples_and_citation_reviewsasserts the presence ofjudgment_rulesin both the example and citation verifier prompts. It also asserts that neither has{{. - Site verifier prompt:
site_assessments_differing_only_in_applies_are_verifiedasserts the escapedjudgment_rulestext in every site verifier prompt. It also asserts that none has{{.
Example initial prompt. initial_prompt_carries_the_review_criteria builds an example prompt in its second half. There it asserts that the prompt has no {{, so an unreplaced placeholder would be caught. It does not repeat the positive judgment_rules check there. This is not a gap. The example prompt goes through the same initial_prompt code path as the requirement prompt. It uses the same shared_blocks values and the same template. Only the subject_task value differs. The requirement text does not distinguish prompt kinds in a way that needs a separate test. The example verifier test also verifies the rules text for the example subject.
Result. Each prompt kind that the code builds differently has a test that asserts the exact rules text and the absence of leftover placeholders. I found no adequacy gap, and the acknowledgments list is empty.
Inputs
Implementation
Input 8: outline src/authoring/mod.rs fn[initial_prompt]
- File:
src/authoring/mod.rs - Selector:
fn[initial_prompt] - Kind:
fn src/authoring/mod.rs:870–922
// {impl}`requirements.authoring.initial_prompt`
// {impl}`requirements.ci.review_criteria`
// {impl}`requirements.ci.outcomes`
// {impl}`requirements.examples.evidence`
// {impl}`requirements.examples.definition`
// {impl}`requirements.authoring.mandatory_inputs`
// {impl}`requirements.authoring.citation_prompt`
// {impl}`requirements.authoring.redaction`
// {impl}`requirements.authoring.github_reads`
// {impl}`requirements.authoring.site_prompt`
// {impl}`requirements.authoring.habeas_background`
// {impl}`requirements.authoring.judgment_rules`
// {impl}`requirements.authoring.credentials`
fn initial_prompt(sources: &AssessmentSources) -> io::Result<Prompt> {
let mandatory = serde_json::to_string_pretty(&sources.model_mandatory_inputs())?;
let mut values = shared_blocks().to_vec();
values.push(("mandatory_inputs", &mandatory));
Ok(match &sources.subject_kind {
AssessmentKind::Definition(kind, distributed) => {
let acknowledgments = serde_json::to_string_pretty(&sources.model_acknowledgments())?;
let task = subject_task(kind);
let distributed = distributed_task(kind, *distributed);
values.extend([
("subject_kind", sources.subject_kind.noun()),
("subject_name", &sources.subject_name),
("subject_task", &task),
("distributed_task", &distributed),
("acknowledgments", &acknowledgments),
]);
Prompt::filled("initial_prompt", &values)
}
AssessmentKind::Citation(item) => {
let citations = serde_json::to_string(&item.model_citations_value())?;
values.extend([
("item_file", item.file.as_str()),
("item_selector", item.selector_label()),
("citations", &citations),
]);
Prompt::filled("citation_prompt", &values)
}
AssessmentKind::Site(site, _) => {
let matches = serde_json::to_string(&site.matches_value())?;
values.extend([
("requirement_name", site.requirement.as_str()),
("site_file", site.file.as_str()),
("site_selector", site.selector_label()),
("matches", &matches),
("distributed_background", distributed_background()),
]);
Prompt::filled("site_prompt", &values)
}
})
}
Input 9: outline src/authoring/mod.rs fn[verification_prompt]
- File:
src/authoring/mod.rs - Selector:
fn[verification_prompt] - Kind:
fn src/authoring/mod.rs:956–986
/// The verifier's prompt for a determination and its rationale.
// {impl}`requirements.authoring.judgment_rules`
// {impl}`requirements.authoring.github_reads`
// {impl}`requirements.authoring.habeas_background`
// {impl}`requirements.authoring.prompt_parts`
fn verification_prompt(
sources: &AssessmentSources,
determination: &Judgment,
rationale: &str,
) -> io::Result<Prompt> {
let site = matches!(sources.subject_kind, AssessmentKind::Site(..));
let instructions = review_instructions(&initial_prompt(sources)?, site);
let mandatory = serde_json::to_string_pretty(&sources.model_mandatory_inputs())?;
let determination = determination.to_value().to_string();
let mut values = shared_blocks().to_vec();
if site {
// A site review's verifier gets no reference roles.
values.retain(|(name, _)| *name != "reference_roles");
values.push(("reference_roles", ""));
}
values.extend([
("subject_kind", sources.subject_kind.noun()),
("subject_name", sources.subject_name.as_str()),
("determination", &determination),
("rationale", rationale.trim()),
("review_instructions", &instructions),
("site_step", if site { SITE_STEP } else { "" }),
("mandatory_inputs", &mandatory),
]);
Ok(Prompt::filled("verifier_prompt", &values))
}
Input 10: outline src/authoring/mod.rs fn[shared_blocks]
- File:
src/authoring/mod.rs - Selector:
fn[shared_blocks] - Kind:
fn src/authoring/mod.rs:746–756
/// The shared blocks every assessment prompt fills: Habeas's terms, the
/// reference roles, and the judgment rules.
// {impl}`requirements.authoring.habeas_background`
// {impl}`requirements.authoring.judgment_rules`
fn shared_blocks() -> [(&'static str, &'static str); 3] {
[
("habeas_background", approved_text("habeas_background", 0)),
("reference_roles", approved_text("habeas_background", 1)),
("judgment_rules", approved_text("judgment_rules", 0)),
]
}
Tests
Input 2: outline src/authoring/mod.rs mod[tests]/fn[initial_prompt_carries_the_review_criteria]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[initial_prompt_carries_the_review_criteria] - Kind:
fn src/authoring/mod.rs:2138–2210
// {test}`requirements.ci.review_criteria`
// {test}`requirements.authoring.requirement_task`
// {test}`requirements.authoring.testing_bar`
// {test}`requirements.authoring.example_task`
// {test}`requirements.authoring.judgment_rules`
// {test}`requirements.authoring.habeas_background`
// {test}`requirements.examples.evidence`
// {test}`requirements.examples.definition`
#[test]
fn initial_prompt_carries_the_review_criteria() {
let project = inputs::tests::project();
let sources = AssessmentSources::prepare(project.path(), "requirements.ready").unwrap();
let prompt = initial_prompt(&sources).unwrap().joined();
for criterion in [
"Subject: requirement requirements.ready\nJudge against: the subject's text.",
approved_text("habeas_background", 0),
approved_text("habeas_background", 1),
approved_text("judgment_rules", 0),
approved_text("requirement_task", 0),
approved_text("testing_bar", 0),
"Derive testable obligations and expected outcomes from each MUST, MUST NOT,",
"Testing criteria:",
"The project MUST be ready.",
] {
assert!(
prompt.contains(criterion),
"missing {criterion:?} in:\n{prompt}"
);
}
// The testing criteria follow the requirement task.
assert!(prompt.contains(&format!(
"{}\n{}",
approved_text("requirement_task", 0),
approved_text("testing_bar", 0)
)));
assert!(!prompt.contains(approved_text("example_task", 0)));
assert!(!prompt.contains("This subject is a distributed requirement."));
assert!(!prompt.contains(distributed_background()));
assert!(!prompt.contains("{{"), "{prompt}");
// An example's task replaces the requirement task.
let requirements = project.path().join("md/requirements.md");
let mut book = fs::read_to_string(&requirements).unwrap();
let cite = "{cite}`requirements.ready`";
book.push_str(&format!(
"\n:::{{example}} case\nA ready case. {cite}\n:::\n"
));
fs::write(&requirements, book).unwrap();
let sources = AssessmentSources::prepare(project.path(), "requirements.case").unwrap();
let prompt = initial_prompt(&sources).unwrap().joined();
assert!(
prompt.contains("Subject: example requirements.case"),
"{prompt}"
);
assert!(
prompt.contains(approved_text("example_task", 0)),
"{prompt}"
);
assert!(
prompt.contains("First check that it describes a concrete case\nwith expected behavior; a missing concrete case or expected behavior is a gap."),
"{prompt}"
);
assert!(
!prompt.contains(approved_text("requirement_task", 0)),
"{prompt}"
);
assert!(
!prompt.contains(approved_text("testing_bar", 0)),
"{prompt}"
);
assert!(!prompt.contains("Testing criteria:"), "{prompt}");
assert!(!prompt.contains("{{"), "{prompt}");
}
Input 3: outline src/authoring/mod.rs mod[tests]/fn[disagreeing_assessments_verify_the_less_favorable_one]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[disagreeing_assessments_verify_the_less_favorable_one] - Kind:
fn src/authoring/mod.rs:3854–4030
// {test}`requirements.authoring.confirmation`
// {test}`requirements.authoring.verifier_prompt`
// {test}`requirements.authoring.verifier_outcome`
// {test}`requirements.authoring.habeas_background`
// {test}`requirements.authoring.judgment_rules`
#[tokio::test]
async fn disagreeing_assessments_verify_the_less_favorable_one() {
for (turns, recorded, kept, conclusion, less) in [
// A real, unacknowledged gap records false with the less favorable
// (second) assessment's rationale.
(
vec![
judgment(json!(true), "Looks complete."),
judgment(json!(false), "The empty case is unhandled."),
verdict(true, &[], "The empty case panics."),
],
Judgment::False,
1,
"found an unacknowledged real gap",
1,
),
// A false assessment ranks below an acknowledged gap.
(
vec![
judgment(json!({"FIXME": ["#7"]}), "Only the known gap."),
judgment(json!(false), "An additional unacknowledged gap."),
verdict(true, &[], "The additional gap is real."),
],
Judgment::False,
1,
"found an unacknowledged real gap",
1,
),
// A FIXME whose gap is real but unacknowledged also becomes false.
(
vec![
judgment(json!({"FIXME": ["#7"]}), "Issue 7 is open."),
judgment(json!(true), "Complete."),
verdict(true, &[], "Issue 7 is closed."),
],
Judgment::False,
0,
"found an unacknowledged real gap",
0,
),
// Real and acknowledged gaps record FIXME with the verifier's
// acknowledgments.
(
vec![
judgment(json!(true), "Looks complete."),
judgment(json!(false), "The empty case is unhandled."),
verdict(true, &["example/queue#9"], "A fixme tracks it."),
],
Judgment::Fixme(vec!["example/queue#9".into()]),
1,
"found its real gaps all acknowledged",
1,
),
// No real gap records the more favorable (second) assessment.
(
vec![
judgment(json!({"FIXME": ["#7"]}), "Issue 7 is open."),
judgment(json!(true), "Complete."),
verdict(false, &[], "Issue 7 does not affect this."),
],
Judgment::True,
1,
"found none of its claimed gaps real",
0,
),
(
vec![
judgment(json!({"FIXME": ["#7"]}), "Only the known gap."),
judgment(json!(false), "An additional unacknowledged gap."),
verdict(false, &[], "The additional gap is not real."),
],
Judgment::Fixme(vec!["#7".into()]),
0,
"found none of its claimed gaps real",
1,
),
(
vec![
judgment(json!(true), "Complete."),
judgment(json!({"FIXME":["#7"]}), "Issue 7 is open."),
verdict(true, &["#7"], "The known gap is real and acknowledged."),
],
Judgment::Fixme(vec!["#7".into()]),
1,
"found its real gaps all acknowledged",
1,
),
(
vec![
judgment(json!(true), "Complete."),
judgment(json!({"FIXME":["#7"]}), "Issue 7 is open."),
verdict(false, &[], "The known gap does not apply."),
],
Judgment::True,
0,
"found none of its claimed gaps real",
1,
),
] {
let (result, provider, logs) = confirmed(turns.clone(), true).await;
let (judgment, record) = result.unwrap();
assert_eq!(judgment, recorded);
assert_eq!(record["determination"], judgment.to_value());
let rationale = record["rationale"].as_str().unwrap();
assert!(
rationale.starts_with(turns[kept].1["rationale"].as_str().unwrap()),
"{rationale}"
);
assert!(
rationale.contains("the assessments disagreed"),
"{rationale}"
);
assert!(rationale.contains(conclusion), "{rationale}");
assert!(
rationale.contains(turns[2].1["rationale"].as_str().unwrap()),
"{rationale}"
);
// Prompts are recorded as serialized requests, so expected text is
// compared in its JSON-escaped form.
// The verifier receives the less favorable determination, its
// rationale, and the criteria it applied, with the source tools
// and submit_verification only.
let prompts = provider.prompts();
assert_eq!(prompts.len(), 3);
let determination = turns[less].1["determination"].to_string();
let less_rationale = turns[less].1["rationale"].as_str().unwrap();
let escaped = serde_json::to_string(&format!(
"The reviewer judged requirement requirements.ready as {determination}."
))
.unwrap();
let (text, tools) = &prompts[2];
assert!(text.contains(escaped.trim_matches('"')), "{text}");
assert!(text.contains(less_rationale), "{text}");
assert!(
text.contains("Judge against: the subject's text."),
"{text}"
);
assert!(text.contains("Derive testable obligations"), "{text}");
assert!(text.contains("# Mandatory inputs"), "{text}");
// The verifier of a requirement carries both background texts,
// the judgment rules, and the subject's mandatory input.
let text = serde_json::from_str::<Value>(text).unwrap().to_string();
for background in [
approved_text("habeas_background", 0),
approved_text("habeas_background", 1),
approved_text("judgment_rules", 0),
"\"requirements\": \"requirements.ready\"",
"The project MUST be ready.",
] {
let background = serde_json::to_string(background).unwrap();
assert!(text.contains(background.trim_matches('"')), "{text}");
}
assert!(!text.contains("{{"), "{text}");
assert!(tools.contains(&"submit_verification".to_owned()));
assert!(tools.contains(&"habeas".to_owned()));
assert!(!tools.contains(&"submit_judgment".to_owned()));
// The verifier has the assessments' source tools.
let source_tools = |tools: &[String]| {
tools
.iter()
.filter(|tool| !tool.starts_with("submit_"))
.cloned()
.collect::<Vec<_>>()
};
assert_eq!(source_tools(tools), source_tools(&prompts[0].1));
assert_eq!(logs.len(), 3);
assert_eq!(logs[2]["subject"], "requirements.ready (verification)");
assert_eq!(logs[2]["outcome"], "completed");
}
}
Input 4: outline src/authoring/mod.rs mod[tests]/fn[verifier_prompts_name_examples_and_citation_reviews]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[verifier_prompts_name_examples_and_citation_reviews] - Kind:
fn src/authoring/mod.rs:4032–4103
// {test}`requirements.authoring.verifier_prompt`
// {test}`requirements.authoring.habeas_background`
// {test}`requirements.authoring.judgment_rules`
#[test]
fn verifier_prompts_name_examples_and_citation_reviews() {
let project = inputs::tests::project();
let cite = "{cite}`requirements.ready`";
let requirements = project.path().join("md/requirements.md");
let mut book = fs::read_to_string(&requirements).unwrap();
book.push_str(&format!(
"\n:::{{example}} case\nA ready case. {cite}\n:::\n"
));
fs::write(&requirements, book).unwrap();
fs::write(
project.path().join("src/lib.rs"),
format!("// {cite}\n// :::{{cite}} habeas:util\n// Formats output.\n// :::\nfn helper() {{}}\n"),
)
.unwrap();
for (subject, header, named) in [
(
"requirements.case",
"The reviewer judged example requirements.case as false.",
"Subject: example requirements.case",
),
(
"citations:src/lib.rs#fn[helper]",
"The reviewer judged citation review citations:src/lib.rs#fn[helper] as false.",
"Item under review: src/lib.rs fn[helper]\nCitations to check:",
),
] {
let sources = AuthoringSubject::parse(subject)
.sources(project.path())
.unwrap();
let parts = verification_prompt(&sources, &Judgment::False, "A claimed gap.").unwrap();
let prompt = parts.joined();
let initial = initial_prompt(&sources).unwrap();
// The reviewer's criteria are its subject message between the
// "# Subject" and "# Mandatory inputs" headings, then its task.
let subject_section = prompt_section(&initial.subject, "Subject").trim();
let first = prompt_section(&initial.system, "Task");
assert!(
parts.subject.contains(&format!(
"The criteria the reviewer applied:\n\n{subject_section}\n\n{}",
prompt_section(&initial.system, "Your task")
)),
"{prompt}"
);
for expected in [
header,
named,
"A claimed gap.",
approved_text("habeas_background", 0),
approved_text("habeas_background", 1),
approved_text("judgment_rules", 0),
] {
assert!(
prompt.contains(expected),
"missing {expected:?} in:\n{prompt}"
);
}
// The rationale and subject stay out of the system prompt.
assert!(!parts.system.contains("A claimed gap."), "{prompt}");
assert!(!parts.system.contains(&sources.subject_name), "{prompt}");
assert!(!prompt.contains(first), "{prompt}");
assert!(!prompt.contains(SITE_STEP), "{prompt}");
// Every mandatory input is delivered.
let mandatory =
serde_json::to_string_pretty(&sources.model_mandatory_inputs()).unwrap();
assert!(prompt.contains(&mandatory), "{prompt}");
assert!(!prompt.contains("{{"), "{prompt}");
}
}
Input 5: 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 6: 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 7: outline src/authoring/mod.rs mod[tests]/fn[site_assessments_differing_only_in_applies_are_verified]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[site_assessments_differing_only_in_applies_are_verified] - Kind:
fn src/authoring/mod.rs:5053–5194
// {test}`requirements.authoring.confirmation`
// {test}`requirements.authoring.verifier_prompt`
// {test}`requirements.authoring.verifier_outcome`
// {test}`requirements.authoring.habeas_background`
#[tokio::test]
// {test}`requirements.authoring.judgment_rules`
async fn site_assessments_differing_only_in_applies_are_verified() {
let site = |applies: bool, determination: Value, rationale: &str| {
(
"submit_judgment",
json!({"applies": applies, "determination": determination, "rationale": rationale}),
)
};
let check = |applies: bool, real: bool, rationale: &str| {
(
"submit_verification",
json!({"real": real, "acknowledged": false, "acknowledgments": [],
"rationale": rationale, "applies": applies}),
)
};
// Agreement needs the same applies too.
let (result, provider) = site_confirmed(vec![
site(true, json!(true), "Reports problems."),
site(true, json!(true), "Also fine."),
])
.await;
assert_eq!(result.unwrap().1["rationale"], "Reports problems.");
assert_eq!(provider.requests.borrow().len(), 2);
for (turns, recorded, applies, kept) in [
// The verifier finds the requirement does not apply, unlike the
// more favorable assessment it keeps: true on its rationale.
(
vec![
site(false, json!(true), "Not a checker."),
site(true, json!(true), "Reports problems."),
check(true, false, "It is a checker after all."),
],
Judgment::True,
true,
"It is a checker after all.",
),
// The verifier agrees with the more favorable assessment.
(
vec![
site(true, json!(true), "Reports problems."),
site(false, json!(true), "Not a checker."),
check(false, false, "Only a helper."),
],
Judgment::True,
false,
"Not a checker.",
),
// A real gap in the applying assessment records false.
(
vec![
site(false, json!(true), "Not a checker."),
site(true, json!(false), "It panics."),
check(true, true, "It panics in `src/lib.rs#fn[check_one]`."),
],
Judgment::False,
true,
"It panics.",
),
(
vec![
site(false, json!(true), "Not a checker."),
site(true, json!(false), "It panics."),
(
"submit_verification",
json!({
"applies":true, "real":true, "acknowledged":true,
"acknowledgments":["o/r#1"], "rationale":"The site acknowledges its panic."
}),
),
],
Judgment::Fixme(vec!["o/r#1".into()]),
true,
"It panics.",
),
(
vec![
site(true, json!({"FIXME":["o/r#1"]}), "The known gap."),
site(true, json!(false), "Another gap."),
check(false, false, "Only a helper."),
],
Judgment::True,
false,
"Only a helper.",
),
] {
let (result, provider) = site_confirmed(turns.clone()).await;
let (judgment, record) = result.unwrap();
assert_eq!(judgment, recorded);
assert_eq!(record["determination"], judgment.to_value());
assert_eq!(record["applies"], applies, "{record}");
let rationale = record["rationale"].as_str().unwrap();
assert!(rationale.starts_with(kept), "{rationale}");
assert!(
rationale.contains("the assessments disagreed"),
"{rationale}"
);
let prompts = provider.prompts();
let (text, tools) = &prompts[2];
let text = serde_json::from_str::<Value>(text).unwrap().to_string();
let escaped = |value: &str| {
serde_json::to_string(value)
.unwrap()
.trim_matches('"')
.to_owned()
};
assert!(
text.contains(&escaped(
"The reviewer judged site review sites:requirements.rule/src/lib.rs#fn[check_one] as"
)),
"{text}"
);
assert!(
text.contains(&escaped(approved_text("judgment_rules", 0))),
"{text}"
);
assert!(text.contains(&escaped(SITE_STEP)), "{text}");
assert!(
text.contains(&escaped(approved_text("habeas_background", 0))),
"{text}"
);
assert!(
text.contains(&escaped(&format!(
"requirement states for each of its sites.\n\n{}\n\nThe mandatory inputs at the end contain the site",
distributed_background()
))),
"{text}"
);
assert!(
!text.contains(&escaped(approved_text("habeas_background", 1))),
"{text}"
);
assert!(!text.contains("{{"), "{text}");
assert!(tools.contains(&"submit_verification".to_owned()));
}
}
Other sources
Input 1: requirements selection requirements.authoring.judgment_rules
requirements.authoring.judgment_rules:md/requirements/authoring.md:269–328
:::{req} judgment_rules
Every assessment prompt MUST replace `{{judgment_rules}}` with this text, so all
assessments judge by the same rules:
```text
- Derive obligations from the supplied subject and contextual text. Base
conclusions about tests or other source behavior only on source code you have
received: mandatory inputs, items read with the habeas tool, or snippets
returned by ripgrep or ast_grep. Close every delivered search with
finish_search, recording the tags whose snippets you relied on without an
additional source read. Supplied acknowledgments establish what a {fixme}
reference says and which issues it names; they do not establish that its
claimed gap is real. outline, list_files, and references only locate items;
read any item whose code your conclusion relies on unless a search snippet
provides the information you need. Comments state intent; check behavior and
assertions in the code itself.
- Judge only against the text your task names. Report a gap only where your task
or these rules define one, naming the obligation and the relevant sources you
have reviewed. For a missing test, identify the obligation or scenario after
looking where your task directs; do not invent a source item for absent code.
Do not report other bugs or issues you notice; edge cases the text does not name are
not gaps.
- A SHOULD imposes an obligation unless the text or a source comment gives a
reason it does not apply. In a test-adequacy assessment, apply the testing
criteria to each applicable SHOULD, and explain any exception in your rationale.
MAY imposes nothing to check. Examples and sample output inside the text
illustrate the obligations its prose states; they bind their exact form only
where the text says the output takes that form.
- If the text admits two readings that its wording supports equally, not merely
one it fails to exclude, and they lead to different conclusions, such as
whether code conforms or which role a citation calls for, that ambiguity is a
gap. Name the readings in your rationale.
- These are not gaps: style, performance, logging, how helpers are factored,
robustness the text does not require, and silently ignoring input the text
does not mention.
- A gap is acknowledged only by a {fixme} reference, in the supplied
acknowledgments, in the inputs, or in a source you read, to the requirement
or example your task judges against, or,
in a site review, to the distributed requirement within the site, whose body
describes that same gap, and whose named issues are open; a {fixme} naming a
closed issue no longer acknowledges its gap. A plain FIXME or TODO comment is
not an acknowledgment. Judge an acknowledgment only within your task's scope.
An acknowledgment of an implementation bug alone does not establish a
test-adequacy gap or acknowledge a different missing-test or assertion gap.
Do not inspect implementation correctness merely to validate an out-of-scope
acknowledgment. In a FIXME determination or an acknowledgments list,
give each distinct issue its :github: option names once, such as
"rust-lang/rust#123", and, for a {fixme} naming no issue, its body's words
joined by single spaces. A {fixme} describing a gap that your review establishes
no longer exists within its task's scope is itself a gap.
- Explain your judgment in a Markdown rationale with source locations, including
any acknowledged gaps.
- Give a source location as its file and outline selector, the address the
habeas and outline tools use, in backticks: `src/config.rs#fn[load]`, or
`src/config.rs` for a whole file. Name requirements, examples, and
definitions by full name in backticks. Name functions, types, and tests in
backticks exactly as they are written. Do not give line numbers: they change
whenever nearby code changes, while a selector stays correct.
```
:::