Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

requirements.authoring.refresh

Requirements index · View definition

evidence Valid

Requirement

Every habeas author form MUST accept --missing and --force, which are mutually exclusive; --missing MUST be the default. Under --missing, the command MUST assess only the selected subjects whose evidence is missing, stale, or invalid, and MUST preserve every current record without invoking a model, including accepted FIXME judgments and current false judgments; a current false judgment is reassessed only when its subject or inputs change or --force is given. Under --force, the command MUST assess every selected subject. --stdout MUST imply --force, because it writes no evidence. The command MUST report the number of selected subjects it skipped as current. When no assessment is needed, the command MUST succeed without resolving model configuration or credentials.

Rationale

The reviewed tests cover each obligation of requirements.authoring.refresh.

author is one clap command, enum[Command] in src/main.rs. Its subject/--all target group is shared by every form. The --missing and --force flags are declared once, with --missing conflicting with --force and --stdout. So the flags apply to every form, and tests across the forms are enough to exercise them.

  • Flags accepted, --missing the default.
    • missing_keeps_current_records_and_force_reassesses_every_selected_subject runs a named requirement, the author-evidence alias on an example, and --all. Each runs with no flag and with --missing, and the two give identical results.
    • batch_authors_citation_reviews_and_preserves_current_ones and site_reviews_are_authored_by_requirement_and_orphans_deleted_by_all do the same for citations: and sites: subjects.
  • Mutual exclusion. missing_keeps_current_records_and_force_reassesses_every_selected_subject asserts failure with “cannot be used with” for these argument sets:
    • --missing --force with a named requirement.
    • --missing --force with --all.
    • --stdout --missing.
  • Assess only missing, stale, or invalid subjects.
    • Missing: the first --all run assesses all six subjects.
    • Stale: a_single_missing_or_stale_subject_is_assessed_under_default_or_explicit_missing changes the requirement text. That reassesses under both the default and explicit --missing, and the next run skips.
    • Stale in a batch: batch_fills_evidence_preserves_current_records_and_reauthors_only_changed_inputs edits a read test and gets exactly “1 authored; 5 skipped as current”. An edit to an unread item causes no reassessment.
    • Invalid: missing_keeps_current_records_and_force_reassesses_every_selected_subject writes {invalid into a record. --all --missing then reassesses it and the record becomes valid again.
  • Preserve current records without invoking a model.
    • The tests assert that the server’s subject count is unchanged and that the usage record count is unchanged.
    • They assert that evidence is byte-identical or equal after the run.
    • The Rust unit test default_authoring_apis_preserve_current_records_without_configuration checks the same for the API entry points author_all, author_evidence and author_evidence_with_output. It checks that the evidence file and usage log are untouched and that no new usage record starts.
  • Accepted FIXME judgments. batch_fills_evidence_preserves_current_records_and_reauthors_only_changed_inputs rewrites beta’s record to a FIXME determination. It then asserts the record is unchanged after later runs.
  • Current false judgments.
    • batch_preserves_current_false_judgments_and_reauthors_stale_ones asserts the false record stays byte-identical and “0 authored; 6 skipped as current”.
    • Changing the subject’s inputs reassesses it, and --force reassesses it too.
    • batch_reauthors_a_false_judgment_when_its_reference_set_changes covers a changed reference set.
  • --force assesses every selected subject. Single subject and --all --force runs increase the server’s subject count as expected (“6 authored; 0 skipped as current”). Forced site and citation reviews overwrite a sentinel in the record.
  • --stdout implies --force. missing_keeps_current_records_and_force_reassesses_every_selected_subject runs --stdout on a current subject and asserts the model was invoked and the record printed. --stdout --missing is rejected.
  • Report the skipped count. Batch runs assert “N skipped as current”. Single-subject runs assert “evidence is current; 1 skipped as current (use –force to reassess)”. policy_comes_from_the_flag_then_the_configuration_then_defaults_to_confirm asserts “0 skipped as current” for forced runs.
  • No configuration or credentials when nothing needs assessment. The tests make the config invalid TOML (“invalid TOML [” or “not toml [”) or remove it. Current named, --all, site, and citation runs still succeed with no model call. In the Rust unit test, an unusable backend selection would fail if configuration were resolved, and it does not fail.

I found no unaddressed obligation or boundary.

Inputs

Tests

Input 2: outline src/authoring/mod.rs mod[tests]/fn[default_authoring_apis_preserve_current_records_without_configuration]
  • File: src/authoring/mod.rs
  • Selector: mod[tests]/fn[default_authoring_apis_preserve_current_records_without_configuration]
  • Kind: fn
  • src/authoring/mod.rs:1629–1679
    // {test}`requirements.authoring.refresh`
    #[tokio::test]
    async fn default_authoring_apis_preserve_current_records_without_configuration() {
        let project = inputs::tests::project();
        let state = tempfile::tempdir().unwrap();
        let subject = "requirements.ready";
        let mut sources = AssessmentSources::prepare(project.path(), subject).unwrap();
        let mut usage = UsageLog::start(state.path(), project.path(), subject).unwrap();
        let (_, record) = assess(&JudgmentProvider(json!(true)), &mut sources, &mut usage)
            .await
            .unwrap();
        let path = project.path().join("evidence/requirements.ready.json");
        let bytes = serde_json::to_vec_pretty(&record).unwrap();
        fs::create_dir(path.parent().unwrap()).unwrap();
        fs::write(&path, &bytes).unwrap();
        let before_usage = fs::read(&usage.path).unwrap();
        // An invalid selection would fail if any API resolved model configuration.
        let selection = Some("unconfigured-fixture-backend");
        let outcome = author_all(project.path(), selection).await.unwrap();
        assert_eq!(outcome.unchanged, 1);
        assert!(outcome.completed.is_empty());
        assert!(outcome.failures.is_empty());
        assert!(outcome.deleted.is_empty());
        assert!(outcome.policy.is_none());
        assert!(!outcome.cancelled);
        assert!(
            author_evidence(project.path(), subject, selection)
                .await
                .unwrap()
                .is_none()
        );
        assert!(
            author_evidence_with_output(project.path(), subject, selection, EvidenceOutput::File)
                .await
                .unwrap()
                .is_none()
        );
        assert_eq!(
            fs::read(path).unwrap(),
            bytes,
            "current evidence is preserved byte for byte"
        );
        assert_eq!(fs::read(&usage.path).unwrap(), before_usage);
        assert_eq!(
            fs::read_dir(state.path().join("authoring/usage"))
                .unwrap()
                .count(),
            1,
            "skipped assessments start no usage records"
        );
    }
Input 3: outline tests/authoring_batch.rs fn[batch_fills_evidence_preserves_current_records_and_reauthors_only_changed_inputs]
  • File: tests/authoring_batch.rs
  • Selector: fn[batch_fills_evidence_preserves_current_records_and_reauthors_only_changed_inputs]
  • Kind: fn
  • tests/authoring_batch.rs:531–686
// {test}`requirements.authoring.batch`
// {test}`requirements.authoring.concurrency`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.ci.determination`
// {test}`requirements.authoring.progress`
// {test}`requirements.configuration.loading`
// {test}`requirements.authoring.configuration`
// {test}`requirements.authoring.refresh`
// {test}`requirements.authoring.persistence`
#[test]
fn batch_fills_evidence_preserves_current_records_and_reauthors_only_changed_inputs() {
    let server = Server::start(true, None);
    let fixture = Fixture::new(&server.endpoint, Some(2));
    let source = fixture.project.join("src/lib.rs");
    fs::write(
        &source,
        format!(
            "{}\n// {{test}}`requirements.alpha`\n#[test]\nfn alpha_requirement() {{ assert_eq!(alpha(), 1); }}\n",
            fs::read_to_string(&source).unwrap().replace(
                "pub fn beta()",
                "// :::{fixme} requirements.beta\n// :github: example/app#123\n// Beta has no test yet.\n// :::\npub fn beta()",
            )
        ),
    )
    .unwrap();
    let output = fixture.run(&["author", "--all", "--config", "mock"]);
    assert!(
        output.status.success(),
        "{}",
        String::from_utf8_lossy(&output.stderr)
    );
    assert_eq!(server.subjects().len(), 6);
    let report = habeas::validate_repository(&fixture.project).unwrap();
    assert!(report.errors.is_empty(), "{:?}", report.errors);
    assert!(!fixture.project.join("evidence/rust").exists());
    let mut beta = fixture.evidence("requirements.beta");
    beta["determination"] = json!({"FIXME":["example/app#123"]});
    beta["rationale"] = "The source explicitly acknowledges the missing beta test.".into();
    fs::write(
        fixture.project.join("evidence/requirements.beta.json"),
        serde_json::to_vec_pretty(&beta).unwrap(),
    )
    .unwrap();
    let example = fixture.evidence("requirements.alpha_case");
    let gamma = fixture.evidence("requirements.gamma");
    let gamma_case = fixture.evidence("requirements.gamma_case");
    for (record, name) in [(&example, "alpha_case"), (&gamma_case, "gamma_case")] {
        assert!(record.get("requirement").is_none(), "{record}");
        assert!(
            record["example"]
                .as_str()
                .unwrap()
                .contains(name.split('_').next().unwrap()),
            "{record}"
        );
    }
    let usage = fixture.usage();
    assert_eq!(usage.len(), 6);
    assert!(
        usage
            .iter()
            .all(|run| run["outcome"] == "completed" && run["evidence_written"] == true)
    );
    {
        let requests = server.requests.0.lock().unwrap();
        assert_eq!(
            requests.peak, 2,
            "the configured concurrency bounds in-flight requests"
        );
        assert!(
            requests.first_pair_overlapped,
            "a second assessment must start before the first model response"
        );
    }

    fs::write(&fixture.config, "invalid TOML [").unwrap();
    let no_op = fixture.run(&["author", "--all"]);
    assert!(
        no_op.status.success(),
        "{}",
        String::from_utf8_lossy(&no_op.stderr)
    );
    fs::remove_file(&fixture.config).unwrap();
    let no_config = fixture.run(&["author", "--all"]);
    assert!(
        no_config.status.success(),
        "{}",
        String::from_utf8_lossy(&no_config.stderr)
    );
    #[cfg(unix)]
    {
        let no_op_terminal = fixture.run_in_pty(false, "xterm-256color");
        assert!(
            no_op_terminal.status.success(),
            "{}",
            String::from_utf8_lossy(&no_op_terminal.stderr)
        );
        assert_eq!(
            String::from_utf8_lossy(&no_op_terminal.stdout).trim(),
            "0 authored; 6 skipped as current; 0 failed"
        );
        assert!(!String::from_utf8_lossy(&no_op_terminal.stderr).contains("0/0 finished"));
    }
    assert_eq!(server.subjects().len(), 6);
    assert_eq!(fixture.usage().len(), 6);

    fs::write(&fixture.config, &fixture.config_text).unwrap();
    let changed = fs::read_to_string(&source)
        .unwrap()
        .replace("-> u8 { 1 }", "-> u8 { 1_u8 }");
    fs::write(&source, changed).unwrap();
    let unread_change = fixture.run(&["author", "--all"]);
    assert!(unread_change.status.success(), "{unread_change:?}");
    assert_eq!(server.subjects().len(), 6);
    fs::write(
        &source,
        fs::read_to_string(&source).unwrap().replace(
            "fn alpha_requirement() { assert_eq!(alpha(), 1); }",
            "fn alpha_requirement() { assert_eq!(alpha(), 1_u8); }",
        ),
    )
    .unwrap();
    #[cfg(unix)]
    let updated = fixture.run_in_pty(false, "xterm-256color");
    #[cfg(not(unix))]
    let updated = fixture.run(&["author", "--all"]);
    #[cfg(unix)]
    {
        let escape = regex::Regex::new(r"\x1b\[[0-?]*[ -/]*[@-~]").unwrap();
        let raw = String::from_utf8_lossy(&updated.stderr);
        let plain = escape.replace_all(&raw, "");
        assert!(plain.contains("1/1 finished"), "{plain}");
        assert!(!plain.contains("6/6 finished"), "{plain}");
    }
    assert!(
        updated.status.success(),
        "{}",
        String::from_utf8_lossy(&updated.stderr)
    );
    assert_eq!(server.subjects().len(), 7);
    assert_eq!(
        server.subjects().last().unwrap(),
        "requirement requirements.alpha"
    );
    assert_eq!(fixture.usage().len(), 7);
    assert_eq!(
        String::from_utf8_lossy(&updated.stdout).trim(),
        "1 authored; 5 skipped as current; 0 failed; policy once"
    );
    assert_eq!(fixture.evidence("requirements.beta"), beta);
    assert_eq!(fixture.evidence("requirements.alpha_case"), example);
    assert_eq!(fixture.evidence("requirements.gamma"), gamma);
    assert_eq!(fixture.evidence("requirements.gamma_case"), gamma_case);
    let report = habeas::validate_repository(&fixture.project).unwrap();
    assert!(report.errors.is_empty(), "{:?}", report.errors);
}
Input 4: outline tests/authoring_batch.rs fn[batch_preserves_current_false_judgments_and_reauthors_stale_ones]
// {test}`requirements.authoring.batch`
// {test}`requirements.ci.determination`
// {test}`requirements.authoring.refresh`
#[test]
fn batch_preserves_current_false_judgments_and_reauthors_stale_ones() {
    let server = Server::start(false, None);
    let fixture = Fixture::new(&server.endpoint, Some(2));
    let source = fixture.project.join("src/lib.rs");
    let original = fs::read_to_string(&source).unwrap();
    fs::write(
        &source,
        format!(
            "{original}\n// {{test}}`requirements.gamma`\n#[test]\nfn gamma_requirement() {{ assert_eq!(gamma(), 3); }}\n"
        ),
    )
    .unwrap();
    let output = fixture.run(&["author", "--all"]);
    assert!(
        output.status.success(),
        "{}",
        String::from_utf8_lossy(&output.stderr)
    );
    assert_eq!(server.subjects().len(), 6);
    let mark_false = |name: &str| {
        let path = fixture.project.join(format!("evidence/{name}.json"));
        let mut record = fixture.evidence(name);
        record["determination"] = json!(false);
        record["rationale"] = json!("The tests omit a boundary case.");
        fs::write(&path, serde_json::to_vec_pretty(&record).unwrap()).unwrap();
        fs::read(path).unwrap()
    };
    let alpha = mark_false("requirements.alpha");
    mark_false("requirements.gamma");

    let current = fixture.run(&["author", "--all"]);
    assert!(
        current.status.success(),
        "{}",
        String::from_utf8_lossy(&current.stderr)
    );
    assert_eq!(server.subjects().len(), 6, "{:?}", server.subjects());
    assert_eq!(
        String::from_utf8_lossy(&current.stdout).trim(),
        "0 authored; 6 skipped as current; 0 failed"
    );
    assert_eq!(
        fs::read(fixture.project.join("evidence/requirements.alpha.json")).unwrap(),
        alpha
    );
    assert_eq!(
        fixture.evidence("requirements.gamma")["determination"],
        false
    );

    fs::write(
        &source,
        fs::read_to_string(&source).unwrap().replace(
            "fn gamma_requirement() { assert_eq!(gamma(), 3); }",
            "fn gamma_requirement() { assert_eq!(gamma(), 3_u8); }",
        ),
    )
    .unwrap();
    let stale = fixture.run(&["author", "--all"]);
    assert!(
        stale.status.success(),
        "{}",
        String::from_utf8_lossy(&stale.stderr)
    );
    let subjects = server.subjects();
    assert_eq!(subjects.len(), 7, "{subjects:?}");
    assert_eq!(subjects[6], "requirement requirements.gamma");
    assert_eq!(
        String::from_utf8_lossy(&stale.stdout).trim(),
        "1 authored; 5 skipped as current; 0 failed; policy once"
    );
    assert_eq!(
        fixture.evidence("requirements.gamma")["determination"],
        true
    );
    assert_eq!(
        fs::read(fixture.project.join("evidence/requirements.alpha.json")).unwrap(),
        alpha
    );
    let forced = fixture.run(&["author", "requirements.alpha", "--force"]);
    assert!(forced.status.success(), "{forced:?}");
    assert_eq!(server.subjects().len(), 8);
    assert_eq!(
        fixture.evidence("requirements.alpha")["determination"],
        true
    );
}
Input 5: outline tests/authoring_batch.rs fn[batch_reauthors_a_false_judgment_when_its_reference_set_changes]
/// A new test reference changes the reference set and requires its source
/// to be supplied on reassessment, even when the old assessment read no code.
// {test}`requirements.authoring.batch`
// {test}`requirements.ci.reference_set`
// {test}`requirements.authoring.refresh`
#[test]
fn batch_reauthors_a_false_judgment_when_its_reference_set_changes() {
    let server = Server::start(false, None);
    let fixture = Fixture::new(&server.endpoint, Some(2));
    let output = fixture.run(&["author", "--all"]);
    assert!(
        output.status.success(),
        "{}",
        String::from_utf8_lossy(&output.stderr)
    );
    assert_eq!(server.subjects().len(), 6);
    for name in ["requirements.alpha", "requirements.delta"] {
        assert_eq!(
            fixture.evidence(name)["references"],
            habeas::reference_set_digest_for(&fixture.project, name).unwrap()
        );
    }
    let path = fixture.project.join("evidence/requirements.delta.json");
    let mut record = fixture.evidence("requirements.delta");
    record["determination"] = json!(false);
    record["rationale"] = json!("The behavior has no {test} reference.");
    fs::write(&path, serde_json::to_vec_pretty(&record).unwrap()).unwrap();

    let source = fixture.project.join("src/lib.rs");
    fs::write(
        &source,
        fs::read_to_string(&source).unwrap().replace(
            "pub fn delta() -> u8 { 4 }",
            "pub fn delta() -> u8 {\n    // {test}`requirements.delta`\n    4\n}",
        ),
    )
    .unwrap();
    let errors = habeas::validate_repository(&fixture.project)
        .unwrap()
        .errors;
    assert_eq!(errors.len(), 3, "{errors:?}");
    assert!(
        errors[0].starts_with("evidence/requirements.delta.json: determination is false")
            && errors[1].starts_with("evidence/requirements.delta.json: reference set changed"),
        "{errors:?}"
    );
    assert!(errors[2].contains("no input covers {test}"), "{errors:?}");

    let stale = fixture.run(&["author", "--all"]);
    assert!(
        stale.status.success(),
        "{}",
        String::from_utf8_lossy(&stale.stderr)
    );
    let subjects = server.subjects();
    assert_eq!(subjects.len(), 7, "{subjects:?}");
    assert_eq!(subjects[6], "requirement requirements.delta");
    assert_eq!(
        String::from_utf8_lossy(&stale.stdout).trim(),
        "1 authored; 5 skipped as current; 0 failed; policy once"
    );
    assert_eq!(
        fixture.evidence("requirements.delta")["references"],
        habeas::reference_set_digest_for(&fixture.project, "requirements.delta").unwrap()
    );
    let report = habeas::validate_repository(&fixture.project).unwrap();
    assert!(report.errors.is_empty(), "{:?}", report.errors);
}
Input 6: outline tests/authoring_batch.rs fn[site_reviews_are_authored_by_requirement_and_orphans_deleted_by_all]
// {test}`requirements.references.site_review`
// {test}`requirements.authoring.batch`
// {test}`requirements.authoring.refresh`
#[test]
fn site_reviews_are_authored_by_requirement_and_orphans_deleted_by_all() {
    let server = Server::start(false, None);
    let fixture = Fixture::new(&server.endpoint, None);
    let chapter = fs::read_to_string(fixture.project.join("md/requirements.md")).unwrap();
    fs::write(
        fixture.project.join("md/requirements.md"),
        format!(
            "{chapter}\n:::::{{req}} spread\nEach public function MUST return a constant.\n\n::::{{sites}} public\n```yaml\nlanguage: rust\nrule: {{ kind: function_item, regex: \"^pub fn (alpha|beta)\" }}\nmatch: [\"pub fn alpha() {{}}\"]\nno_match: [\"fn alpha() {{}}\"]\n```\n::::\n:::::\n"
        ),
    )
    .unwrap();
    let output = fixture.run(&["author", "sites:requirements.spread"]);
    assert!(
        output.status.success(),
        "{}",
        String::from_utf8_lossy(&output.stderr)
    );
    let mut subjects = server.subjects();
    subjects.sort();
    assert_eq!(subjects, ["src/lib.rs fn[alpha]", "src/lib.rs fn[beta]"]);
    let review = fixture
        .project
        .join("evidence/sites/requirements.spread/src/lib.rs/fn[alpha].json");
    let record: Value = serde_json::from_str(&fs::read_to_string(&review).unwrap()).unwrap();
    assert_eq!(record["applies"], true);
    assert_eq!(record["queries"], json!(["public"]));
    // Current reviews are kept; an unknown requirement is an error.
    let output = fixture.run(&["author", "sites:requirements.spread"]);
    assert!(output.status.success());
    assert_eq!(server.subjects().len(), 2);
    // A single named site review that is current is kept under `--missing`,
    // the default, without a model or configuration.
    fs::write(&fixture.config, "not toml [").unwrap();
    let site = "sites:requirements.spread/src/lib.rs#fn[alpha]";
    for args in [&["author", site][..], &["author", site, "--missing"]] {
        let output = fixture.run(args);
        assert!(
            output.status.success(),
            "{args:?}: {}",
            String::from_utf8_lossy(&output.stderr)
        );
        assert_eq!(
            String::from_utf8_lossy(&output.stdout).trim(),
            format!("{site}: evidence is current; 1 skipped as current (use --force to reassess)")
        );
    }
    assert_eq!(server.subjects().len(), 2, "no model was invoked");
    fs::write(&fixture.config, &fixture.config_text).unwrap();
    let mut before: Value = serde_json::from_slice(&fs::read(&review).unwrap()).unwrap();
    before["rationale"] = json!("CURRENT_RECORD_BEFORE_FORCE");
    fs::write(&review, before.to_string()).unwrap();
    let output = fixture.run(&["author", site, "--force"]);
    assert!(output.status.success(), "{output:?}");
    assert_eq!(server.subjects().len(), 3);
    assert!(review.exists());
    assert_eq!(
        serde_json::from_slice::<Value>(&fs::read(&review).unwrap()).unwrap()["item"],
        "fn[alpha]"
    );
    assert!(
        !fs::read_to_string(&review)
            .unwrap()
            .contains("CURRENT_RECORD_BEFORE_FORCE")
    );
    let output = fixture.run(&["author", "--all", "--force"]);
    assert!(output.status.success(), "{output:?}");
    assert_eq!(server.subjects().len(), 12);
    assert_eq!(
        server
            .subjects()
            .iter()
            .filter(|s| *s == "src/lib.rs fn[alpha]")
            .count(),
        3
    );
    assert_eq!(
        server
            .subjects()
            .iter()
            .filter(|s| *s == "src/lib.rs fn[beta]")
            .count(),
        2
    );
    let output = fixture.run(&["author", "sites:requirements.alpha"]);
    assert!(!output.status.success());
    assert!(
        String::from_utf8_lossy(&output.stderr).contains("no distributed requirement"),
        "{}",
        String::from_utf8_lossy(&output.stderr)
    );

    // `--all` deletes a review whose site is gone, without configuration.
    let orphan = fixture
        .project
        .join("evidence/sites/requirements.spread/src/lib.rs/fn[gone].json");
    fs::write(&orphan, "{}").unwrap();
    fs::remove_file(&fixture.config).unwrap();
    let output = fixture.run(&["author", "--all"]);
    assert!(!orphan.exists());
    assert!(
        String::from_utf8_lossy(&output.stderr).contains(
            "Deleted orphaned review evidence/sites/requirements.spread/src/lib.rs/fn[gone].json"
        ),
        "{}",
        String::from_utf8_lossy(&output.stderr)
    );
    assert!(review.exists());
}
Input 7: outline tests/authoring_batch.rs fn[batch_authors_citation_reviews_and_preserves_current_ones]
// {test}`requirements.references.citation_review`
// {test}`requirements.authoring.batch`
// {test}`requirements.authoring.refresh`
// {test}`requirements.references.coverage.report`
#[test]
fn batch_authors_citation_reviews_and_preserves_current_ones() {
    let server = Server::start(false, None);
    let fixture = Fixture::new(&server.endpoint, None);
    let source = fixture.project.join("src/lib.rs");
    let cite = "// {cite}`requirements.alpha`\n".to_owned();
    fs::write(
        &source,
        format!(
            "{}{cite}pub fn helper() {{}}\n",
            fs::read_to_string(&source).unwrap()
        ),
    )
    .unwrap();
    let output = fixture.run(&["author", "--all"]);
    assert!(
        output.status.success(),
        "{}",
        String::from_utf8_lossy(&output.stderr)
    );
    let subjects = server.subjects();
    assert_eq!(subjects.len(), 7, "{subjects:?}");
    assert!(
        subjects.contains(&"src/lib.rs fn[helper]".to_owned()),
        "{subjects:?}"
    );
    let review: Value = serde_json::from_slice(
        &fs::read(
            fixture
                .project
                .join("evidence/citations/src/lib.rs/fn[helper].json"),
        )
        .unwrap(),
    )
    .unwrap();
    assert_eq!(
        review["citations"],
        json!([{"role": "cite", "name": "requirements.alpha", "commentary": ""}])
    );
    let report = habeas::validate_repository(&fixture.project).unwrap();
    assert!(report.errors.is_empty(), "{:?}", report.errors);

    let again = fixture.run(&["author", "--all"]);
    assert_eq!(
        String::from_utf8_lossy(&again.stdout).trim(),
        "0 authored; 7 skipped as current; 0 failed"
    );
    // A single named citation review that is current is kept under
    // `--missing`, the default, without a model or configuration.
    fs::write(&fixture.config, "not toml [").unwrap();
    let citation = "citations:src/lib.rs#fn[helper]";
    for args in [
        &["author", citation][..],
        &["author", citation, "--missing"],
    ] {
        let output = fixture.run(args);
        assert!(
            output.status.success(),
            "{args:?}: {}",
            String::from_utf8_lossy(&output.stderr)
        );
        assert_eq!(
            String::from_utf8_lossy(&output.stdout).trim(),
            format!(
                "{citation}: evidence is current; 1 skipped as current (use --force to reassess)"
            )
        );
    }
    assert_eq!(server.subjects().len(), 7, "no model was invoked");
    fs::write(&fixture.config, &fixture.config_text).unwrap();
    let path = fixture
        .project
        .join("evidence/citations/src/lib.rs/fn[helper].json");
    let mut before: Value = serde_json::from_slice(&fs::read(&path).unwrap()).unwrap();
    before["rationale"] = json!("CURRENT_RECORD_BEFORE_FORCE");
    fs::write(&path, before.to_string()).unwrap();
    let output = fixture.run(&["author", citation, "--force"]);
    assert!(output.status.success(), "{output:?}");
    assert_eq!(server.subjects().len(), 8);
    assert_eq!(
        serde_json::from_slice::<Value>(&fs::read(&path).unwrap()).unwrap()["item"],
        "fn[helper]"
    );
    assert!(
        !fs::read_to_string(&path)
            .unwrap()
            .contains("CURRENT_RECORD_BEFORE_FORCE")
    );
    let output = fixture.run(&["author", "--all", "--force"]);
    assert!(output.status.success(), "{output:?}");
    assert_eq!(server.subjects().len(), 15);
    assert_eq!(
        server
            .subjects()
            .iter()
            .filter(|s| *s == "src/lib.rs fn[helper]")
            .count(),
        3
    );
    // A citation review can also be named on its own.
    let single = fixture.run(&["author", "citations:src/lib.rs#fn[helper]", "--stdout"]);
    assert!(
        single.status.success(),
        "{}",
        String::from_utf8_lossy(&single.stderr)
    );
    let printed: Value = serde_json::from_slice(&single.stdout).unwrap();
    assert_eq!(printed["item"], "fn[helper]");
    // The coverage summary stays on stderr; stdout holds only the record.
    let stderr = String::from_utf8_lossy(&single.stderr);
    assert!(
        stderr.contains("nodes have coverage warnings. Use `status --coverage` to see them."),
        "{stderr}"
    );
    assert!(
        !stderr.contains("coverage history is incomplete"),
        "{stderr}"
    );
    assert_eq!(server.subjects().len(), 16);
}
Input 8: outline tests/authoring_batch.rs fn[a_single_missing_or_stale_subject_is_assessed_under_default_or_explicit_missing]
// {test}`requirements.authoring.refresh`
#[test]
fn a_single_missing_or_stale_subject_is_assessed_under_default_or_explicit_missing() {
    let server = Server::start(false, None);
    let fixture = Fixture::new(&server.endpoint, None);
    let output = fixture.run(&["author", "requirements.alpha"]);
    assert!(
        output.status.success(),
        "{}",
        String::from_utf8_lossy(&output.stderr)
    );
    assert_eq!(server.subjects(), ["requirement requirements.alpha"]);
    let before = fixture.evidence("requirements.alpha");
    // Changing the supplied subject text makes its assessment stale.
    let source = fixture.project.join("md/requirements.md");
    let changed = fs::read_to_string(&source)
        .unwrap()
        .replace("alpha MUST return one.", "alpha MUST return exactly one.");
    fs::write(source, changed).unwrap();
    let output = fixture.run(&["author", "requirements.alpha", "--missing"]);
    assert!(
        output.status.success(),
        "{}",
        String::from_utf8_lossy(&output.stderr)
    );
    assert_eq!(
        server.subjects(),
        [
            "requirement requirements.alpha",
            "requirement requirements.alpha"
        ]
    );
    assert_ne!(
        fixture.evidence("requirements.alpha")["inputs"],
        before["inputs"]
    );
    let output = fixture.run(&["author", "requirements.alpha"]);
    assert!(
        output.status.success(),
        "{}",
        String::from_utf8_lossy(&output.stderr)
    );
    assert_eq!(
        server.subjects().len(),
        2,
        "the refreshed subject is skipped"
    );
}
Input 9: outline tests/authoring_batch.rs fn[missing_keeps_current_records_and_force_reassesses_every_selected_subject]
/// Under `--missing`, the default, a named subject or `--all` keeps current
/// records without a model or configuration; `--force` reassesses them, and
/// `--stdout` implies it.
// {test}`requirements.authoring.refresh`
// {test}`requirements.authoring.invocation`
// {test}`requirements.authoring.batch`
// {test}`requirements.references.coverage.report`
#[test]
fn missing_keeps_current_records_and_force_reassesses_every_selected_subject() {
    let server = Server::start(false, None);
    let fixture = Fixture::new(&server.endpoint, None);
    let first = fixture.run(&["author", "--all"]);
    assert!(
        first.status.success(),
        "{}",
        String::from_utf8_lossy(&first.stderr)
    );
    assert_eq!(server.subjects().len(), 6);
    let alpha = fixture.evidence("requirements.alpha");

    // Without a usable configuration, current records are still kept: no
    // configuration is resolved when nothing needs assessment.
    fs::write(&fixture.config, "not toml [").unwrap();
    // An item nothing reads is warned about even when nothing is assessed.
    fs::write(fixture.project.join("src/extra.rs"), "pub fn orphan() {}\n").unwrap();
    for args in [
        &["author", "requirements.alpha"][..],
        &["author", "requirements.alpha", "--missing"],
        &["author-evidence", "requirements.alpha_case"],
    ] {
        let output = fixture.run(args);
        assert!(
            output.status.success(),
            "{args:?}: {}",
            String::from_utf8_lossy(&output.stderr)
        );
        assert_eq!(
            String::from_utf8_lossy(&output.stdout).trim(),
            format!(
                "{}: evidence is current; 1 skipped as current (use --force to reassess)",
                args[1]
            )
        );
        let stderr = String::from_utf8_lossy(&output.stderr);
        assert!(
            stderr.contains("nodes have coverage warnings. Use `status --coverage` to see them."),
            "{args:?}: {stderr}"
        );
        assert!(
            !stderr.contains("function orphan has no recent coverage"),
            "{stderr}"
        );
    }
    for args in [&["author", "--all"][..], &["author", "--all", "--missing"]] {
        let output = fixture.run(args);
        assert!(
            output.status.success(),
            "{args:?}: {}",
            String::from_utf8_lossy(&output.stderr)
        );
        assert_eq!(
            String::from_utf8_lossy(&output.stdout).trim(),
            "0 authored; 6 skipped as current; 0 failed"
        );
    }
    assert_eq!(server.subjects().len(), 6, "no model was invoked");
    assert_eq!(fixture.usage().len(), 6);
    assert_eq!(fixture.evidence("requirements.alpha"), alpha);

    // `--missing` and `--force` are mutually exclusive, and `--stdout`
    // already implies `--force`.
    for args in [
        &["author", "requirements.alpha", "--missing", "--force"][..],
        &["author", "--all", "--missing", "--force"],
        &["author", "requirements.alpha", "--stdout", "--missing"],
    ] {
        let output = fixture.run(args);
        assert!(!output.status.success(), "{args:?}");
        assert!(
            String::from_utf8_lossy(&output.stderr).contains("cannot be used with"),
            "{args:?}: {}",
            String::from_utf8_lossy(&output.stderr)
        );
    }
    assert_eq!(server.subjects().len(), 6);

    fs::write(&fixture.config, &fixture.config_text).unwrap();
    let forced = fixture.run(&["author", "requirements.alpha", "--force"]);
    assert!(
        forced.status.success(),
        "{}",
        String::from_utf8_lossy(&forced.stderr)
    );
    assert_eq!(
        server.subjects().last().unwrap(),
        "requirement requirements.alpha"
    );
    assert_eq!(server.subjects().len(), 7);
    let stdout = fixture.run(&["author", "requirements.alpha", "--stdout"]);
    assert!(
        stdout.status.success(),
        "{}",
        String::from_utf8_lossy(&stdout.stderr)
    );
    let printed: Value = serde_json::from_slice(&stdout.stdout).unwrap();
    assert_eq!(printed["requirement"], alpha["requirement"]);
    assert_eq!(server.subjects().len(), 8, "--stdout implies --force");
    let all = fixture.run(&["author", "--all", "--force"]);
    assert!(
        all.status.success(),
        "{}",
        String::from_utf8_lossy(&all.stderr)
    );
    assert_eq!(
        String::from_utf8_lossy(&all.stdout).trim(),
        "6 authored; 0 skipped as current; 0 failed; policy once"
    );
    assert_eq!(server.subjects().len(), 14);
    fs::write(
        fixture.project.join("evidence/requirements.alpha.json"),
        "{invalid",
    )
    .unwrap();
    let repaired = fixture.run(&["author", "--all", "--missing"]);
    assert!(repaired.status.success(), "{repaired:?}");
    assert_eq!(server.subjects().len(), 15);
    assert_eq!(
        fixture.evidence("requirements.alpha")["determination"],
        true
    );

    let report = habeas::validate_repository(&fixture.project).unwrap();
    assert!(report.errors.is_empty(), "{:?}", report.errors);
}
Input 10: outline tests/authoring_batch.rs fn[policy_comes_from_the_flag_then_the_configuration_then_defaults_to_confirm]
/// The policy comes from `--policy`, then the configuration's `policy`,
/// then defaults to `confirm`; the report and every usage record name it,
/// and an unknown name is rejected before any model request.
// {test}`requirements.authoring.policy`
// {test}`requirements.authoring.configuration_structure`
// {test}`requirements.authoring.confirmation`
#[test]
// {test}`requirements.authoring.refresh`
fn policy_comes_from_the_flag_then_the_configuration_then_defaults_to_confirm() {
    let server = Server::start(false, None);
    let fixture = Fixture::new(&server.endpoint, None);
    let unconfigured = fixture.config_text.replace("policy = 'once'\n", "");
    let cases: [(&str, &[&str], &str, usize); 4] = [
        (&unconfigured, &[], "confirm", 2),
        (&unconfigured, &["--policy", "once"], "once", 1),
        (
            &fixture.config_text.replace("'once'", "'confirm'"),
            &["--policy", "once"],
            "once",
            1,
        ),
        (&fixture.config_text, &[], "once", 1),
    ];
    let run_ids = || {
        if fixture.state.exists() {
            fixture
                .usage()
                .into_iter()
                .map(|run| run["run_id"].as_str().unwrap().to_owned())
                .collect::<Vec<_>>()
        } else {
            Vec::new()
        }
    };
    for (config, policy, expected, conversations) in cases {
        fs::write(&fixture.config, config).unwrap();
        let before = server.subjects().len();
        let earlier = run_ids();
        let mut args = vec!["author", "requirements.alpha", "--force"];
        args.extend_from_slice(policy);
        let output = fixture.run(&args);
        assert!(
            output.status.success(),
            "{args:?}: {}",
            String::from_utf8_lossy(&output.stderr)
        );
        assert!(
            String::from_utf8_lossy(&output.stdout).contains(&format!("; policy {expected}")),
            "{args:?}: {}",
            String::from_utf8_lossy(&output.stdout)
        );
        assert!(String::from_utf8_lossy(&output.stdout).contains("0 skipped as current"));
        assert_eq!(server.subjects().len() - before, conversations, "{args:?}");
        // Each conversation's usage record identifies the policy.
        let usage = fixture
            .usage()
            .into_iter()
            .filter(|run| !earlier.contains(&run["run_id"].as_str().unwrap().to_owned()))
            .collect::<Vec<_>>();
        assert_eq!(usage.len(), conversations, "{args:?}");
        assert!(
            usage.iter().all(|run| run["policy"] == expected),
            "{args:?}: {usage:?}"
        );
    }
    let stdout = fixture.run(&[
        "author",
        "requirements.alpha",
        "--stdout",
        "--policy",
        "once",
    ]);
    assert!(stdout.status.success(), "{stdout:?}");
    assert!(String::from_utf8_lossy(&stdout.stderr).contains("policy once"));
    assert!(String::from_utf8_lossy(&stdout.stderr).contains("0 skipped as current"));
    let printed: Value = serde_json::from_slice(&stdout.stdout).unwrap();
    assert_eq!(printed["determination"], true);
    // The batch summary names the policy too.
    fs::write(&fixture.config, &unconfigured).unwrap();
    let batch = fixture.run(&["author", "--all", "--force", "--policy", "once"]);
    assert_eq!(
        String::from_utf8_lossy(&batch.stdout).trim(),
        "6 authored; 0 skipped as current; 0 failed; policy once"
    );

    let before = server.subjects().len();
    let flag = fixture.run(&[
        "author",
        "requirements.alpha",
        "--force",
        "--policy",
        "twice",
    ]);
    assert!(!flag.status.success());
    let stderr = String::from_utf8_lossy(&flag.stderr);
    assert!(
        stderr.contains("unknown assessment policy \"twice\""),
        "{stderr}"
    );
    fs::write(
        &fixture.config,
        fixture.config_text.replace("'once'", "'twice'"),
    )
    .unwrap();
    for args in [
        &["author", "requirements.alpha", "--force"][..],
        &["author", "--all", "--force"],
    ] {
        let output = fixture.run(args);
        assert!(!output.status.success(), "{args:?}");
        let stderr = String::from_utf8_lossy(&output.stderr);
        assert!(
            stderr.contains(&fixture.config.display().to_string()) && stderr.contains("policy"),
            "{args:?}: {stderr}"
        );
    }
    assert_eq!(
        server.subjects().len(),
        before,
        "rejected before any request"
    );
}

Other sources

Input 1: requirements selection requirements.authoring.refresh
:::{req} refresh
Every `habeas author` form MUST accept `--missing` and `--force`, which are
mutually exclusive; `--missing` MUST be the default. Under `--missing`, the
command MUST assess only the selected subjects whose evidence is missing, stale,
or invalid, and MUST preserve every current record without invoking a model,
including accepted FIXME judgments and current false judgments; a current false
judgment is reassessed only when its subject or inputs change or `--force` is
given. Under `--force`, the command MUST assess every selected subject. `--stdout`
MUST imply `--force`, because it writes no evidence. The command MUST report the
number of selected subjects it skipped as current. When no assessment is needed,
the command MUST succeed without resolving model configuration or credentials.
:::
Input 11: outline src/main.rs enum[Command]
#[derive(Subcommand)]
// {impl}`requirements.authoring.reporting`
enum Command {
    /// Run nextest with independent LLVM coverage for each test process.
    Coverage {
        #[arg(last = true)]
        args: Vec<String>,
    },
    /// Check saved file and function coverage, without running tests or a model.
    // {impl}`requirements.test-coverage.check`
    CoverageCheck,
    /// Collect coverage for the full workspace, then check its coverage policy.
    // {impl}`requirements.test-coverage.test`
    Test,
    #[command(hide = true)]
    CoverageProcess {
        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
        args: Vec<std::ffi::OsString>,
    },
    Mdbook {
        #[command(subcommand)]
        command: Option<MdbookCommand>,
    },
    Setup {
        #[arg(long, value_name = "crate-dir")]
        path: Option<PathBuf>,
    },
    Status {
        #[arg(long)]
        all: bool,
        /// List the judgments and original FIXME entries within each issue group.
        #[arg(long)]
        verbose: bool,
        /// Show individual evidence-coverage warnings and history details.
        #[arg(long)]
        coverage: bool,
        /// A full requirement or example name, or a definition glob.
        selection: Option<String>,
    },
    Info {
        /// A full requirement or example name, or a definition glob.
        selection: String,
    },
    // The single-subject syntax, its alias, and the `--all` exclusions.
    // {impl}`requirements.authoring.invocation`
    // `--config <name>` selects a configuration for this invocation.
    // `--missing` and `--force` choose which selected subjects are assessed;
    // `--stdout` implies `--force`, so it excludes `--missing`.
    // `--policy <name>` selects the assessment policy for every form.
    // {impl}`requirements.authoring.policy`
    #[command(alias = "author-evidence", group(ArgGroup::new("author_target").required(true).multiple(false).args(["subject", "all"])))]
    Author {
        subject: Option<String>,
        /// Author all requirement and example evidence needing attention.
        #[arg(long, conflicts_with = "stdout")]
        all: bool,
        #[arg(long)]
        config: Option<String>,
        /// Write evidence JSON to stdout instead of updating its file.
        #[arg(long)]
        stdout: bool,
        /// Show the stored rationale for false judgments.
        #[arg(short, long)]
        verbose: bool,
        /// Assess only subjects whose evidence is missing, stale, or invalid
        /// (the default).
        #[arg(long, conflicts_with_all = ["force", "stdout"])]
        missing: bool,
        /// Assess every selected subject, including those with current evidence.
        #[arg(long)]
        force: bool,
        /// The assessment policy: `confirm` checks each true or
        /// FIXME result in further independent conversations; `once` records a
        /// single assessment.
        #[arg(long, value_name = "name")]
        policy: Option<habeas::config::AssessmentPolicy>,
    },
    /// Update evidence after moving files, outline nodes, or definitions.
    Refactor {
        /// `<old>=<new>`: a file or directory path, a `<file>#<selector>`
        /// node, or a definition name.
        #[arg(long = "map", value_name = "old=new", required = true)]
        mappings: Vec<String>,
        /// Report what would change without writing anything.
        #[arg(long)]
        dry_run: bool,
    },
    #[command(hide = true)]
    Hook {
        #[command(subcommand)]
        command: HookCommand,
    },
}