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.configuration

Requirements index · View definition

evidence Valid

Requirement

Authoring MUST use the [authoring] sections of the shared user configuration and the selected workspace’s habeas.toml, refining impl requirements.configuration.feature_sections for the authoring feature. cite requirements.configuration.user_location cite requirements.configuration.structure Assessing a subject with habeas author, singly or in a batch that needs at least one assessment, MUST require an [authoring] section in at least one of these files; either section MAY be absent. No other operation requires the section, including a batch with no assessments needed and the operations in cite requirements.authoring.deterministic_validation. It MUST support named configurations, workspace defaults, and a user-local selection for each project. Credential-source references SHOULD be used; explicit credentials MUST be supported under cite requirements.authoring.credentials. cite requirements.configuration.workspace_location cite requirements.configuration.workspace_structure

Rationale

I judge the tests adequate for requirements.authoring.configuration. I did not request any implementation source.

Obligations and the tests that cover them

  1. Assessing needs an [authoring] section in at least one file.

    • tests/authoring_cli.rs#fn[version_only_configurations_cannot_author_needed_evidence] writes version = 1 to both the user config and the workspace habeas.toml.
    • It runs both a single-subject author and author --all. Both must fail, with stderr containing “no authoring configuration”.
    • It also asserts that the evidence file is unchanged and that no connection reaches the provider.
    • tests/configuration.rs#fn[explicit_project_and_default_selections_choose_whole_configs] covers the missing-configuration error from the resolver. The error must name the config file and point to the documented examples.
  2. Either section MAY be absent.

    • Workspace-only: tests/authoring_cli.rs#fn[authoring_uses_nearest_workspace_configuration_without_a_user_file] deletes the user file and succeeds using only the nested habeas.toml.
      • The test also asserts that neither workspace file is rewritten and that no user config is created.
    • Workspace-only at the resolver level: tests/configuration.rs#fn[workspace_defaults_and_configs_combine_with_existing_user_selections] calls the resolver with None for the user config.
    • User-only: tests/authoring_cli.rs#fn[an_explicit_configuration_selects_the_nondefault_workspace_profile] and the batch test rely on a user config with no workspace section. The explicit-selection resolver test uses a user-only config.
      • Strictly, the profile test removes the user file, so it is workspace-only.
  3. No other operation requires the section.

    • tests/authoring_cli.rs#fn[missing_or_stale_evidence_fails_validation_without_contacting_the_provider] runs validate_repository, status --all, and the mdbook preprocessor.
      • It does this with both the full config and a version-only config, and with the credential environment variable removed.
      • It does so for missing and stale evidence. Validation reports the failure, status and rendering succeed, and the provider is never contacted.
      • No usage state is written and the evidence file is not authored.
    • tests/authoring_batch.rs#fn[batch_fills_evidence_preserves_current_records_and_reauthors_only_changed_inputs] runs author --all as a batch needing no assessments. It does so with invalid TOML in the user config, and again with the user config removed. Both runs succeed, make no new requests, and write no new usage records.
  4. Named configurations, workspace defaults, and a user-local selection per project.

    • tests/configuration.rs#fn[explicit_project_and_default_selections_choose_whole_configs] covers the user default, the per-project selection, explicit --config selection, and an unknown-name error.
    • tests/configuration.rs#fn[workspace_defaults_and_configs_combine_with_existing_user_selections] covers the workspace default, the user project selection overriding it, explicit selection, and a workspace default that names a user config. It also covers a workspace-only run and an error for a missing name that names the file.
    • an_explicit_configuration_selects_the_nondefault_workspace_profile is the CLI check that --config alternate beats the workspace default.
  5. Credentials. Explicit api_key support is exercised end to end in authoring_uses_nearest_workspace_configuration_without_a_user_file. The key reaches the provider request headers, and it appears nowhere in the request body, usage record, stdout, or stderr. The detailed credential rules are delegated to requirements.authoring.credentials, which is cited, so I did not reassess them here.

Unresolved question (not a gap): I found no test that pairs a version-only workspace habeas.toml with a user config that has [authoring]. Both sides are covered separately, and the text does not distinguish that combination, so I do not count it as a gap.

Inputs

Tests

Input 8: 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 9: outline tests/authoring_cli.rs fn[authoring_uses_nearest_workspace_configuration_without_a_user_file]
// {test}`requirements.configuration.workspace_location`
// {test}`requirements.authoring.configuration`
// {test}`requirements.configuration.workspace_structure`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.credentials`
// {test}`requirements.authoring.provider`
// {test}`requirements.authoring.rig_configuration_mapping`
// {test}`requirements.authoring.invocation`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.configuration.serialization`
#[test]
// {test}`requirements.configuration.documentation`
fn authoring_uses_nearest_workspace_configuration_without_a_user_file() {
    let server = Server::start(vec![reply(vec![call(
        "submit",
        "submit_judgment",
        json!({"determination":true,"rationale":"The supplied sources support the subject."}),
    )])]);
    let fixture = Fixture::new(&server.endpoint);
    fs::remove_file(fixture.config.join("habeas/config.toml")).unwrap();
    fs::write(
        fixture.project.join("habeas.toml"),
        "version = 1\n[authoring]\ndefault = 'missing-parent-choice'\n",
    )
    .unwrap();
    let nested = fixture.project.join("src/nested");
    fs::create_dir(&nested).unwrap();
    let workspace = nested.join("habeas.toml");
    fs::write(
        &workspace,
        format!(
            "version = 1\n[authoring]\ndefault = 'workspace'\n[authoring.configs.workspace]\npolicy = 'once'\nbackend = 'ollama'\nmodel = 'workspace-model'\nendpoint = '{}'\napi_key = 'WORKSPACE_LITERAL_KEY'\n",
            server.endpoint
        ),
    )
    .unwrap();
    let configurations = [fixture.project.join("habeas.toml"), workspace.clone()];
    let before = configurations
        .iter()
        .map(|path| fs::read(path).unwrap())
        .collect::<Vec<_>>();
    let output = fixture
        .command()
        .current_dir(&nested)
        .args(["author", SUBJECT])
        .output()
        .unwrap();
    assert!(output.status.success(), "{output:?}");
    // Running the configured feature rewrites neither configuration file,
    // and creates no user configuration.
    for (path, before) in configurations.iter().zip(&before) {
        assert_eq!(&fs::read(path).unwrap(), before, "{}", path.display());
    }
    assert!(!fixture.config.join("habeas/config.toml").exists());
    let requests = server.finish();
    assert_eq!(requests.len(), 1);
    assert_eq!(requests[0].body["model"], "workspace-model");
    assert!(requests[0].headers.contains("WORKSPACE_LITERAL_KEY"));
    assert!(
        !requests[0]
            .body
            .to_string()
            .contains("WORKSPACE_LITERAL_KEY")
    );
    let usage = fixture.usage();
    assert_eq!(usage["model"], "workspace-model");
    for text in [
        usage.to_string(),
        String::from_utf8_lossy(&output.stdout).into_owned(),
        String::from_utf8_lossy(&output.stderr).into_owned(),
    ] {
        assert!(!text.contains("WORKSPACE_LITERAL_KEY"), "{text}");
    }
}
Input 10: outline tests/authoring_cli.rs fn[an_explicit_configuration_selects_the_nondefault_workspace_profile]
// {test}`requirements.authoring.invocation`
// {test}`requirements.authoring.configuration`
#[test]
fn an_explicit_configuration_selects_the_nondefault_workspace_profile() {
    let server = Server::start(vec![reply(vec![call(
        "submit",
        "submit_judgment",
        json!({"determination":true,"rationale":"The supplied sources support the subject."}),
    )])]);
    let fixture = Fixture::new(&server.endpoint);
    fs::remove_file(fixture.config.join("habeas/config.toml")).unwrap();
    let nested = fixture.project.join("src/nested");
    fs::create_dir(&nested).unwrap();
    fs::write(nested.join("habeas.toml"), format!(
        "version = 1\n[authoring]\ndefault = 'default'\n[authoring.configs.default]\nbackend = 'ollama'\nmodel = 'WRONG_DEFAULT_MODEL'\nendpoint = 'http://127.0.0.1:9'\n[authoring.configs.alternate]\npolicy = 'once'\nbackend = 'ollama'\nmodel = 'alternate-model'\nendpoint = '{}'\napi_key = 'ALTERNATE_TEST_KEY'\n", server.endpoint
    )).unwrap();
    let output = fixture
        .command()
        .current_dir(&nested)
        .args(["author", SUBJECT, "--config", "alternate", "--force"])
        .output()
        .unwrap();
    assert!(output.status.success(), "{output:?}");
    let requests = server.finish();
    assert_eq!(requests.len(), 1);
    assert_eq!(requests[0].body["model"], "alternate-model");
    assert!(requests[0].headers.contains("ALTERNATE_TEST_KEY"));
    assert_eq!(fixture.usage()["model"], "alternate-model");
    assert_eq!(fixture.usage()["backend"], "ollama");
}
Input 11: outline tests/authoring_cli.rs fn[version_only_configurations_cannot_author_needed_evidence]
// {test}`requirements.authoring.configuration`
#[test]
fn version_only_configurations_cannot_author_needed_evidence() {
    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()));
    fs::write(fixture.config.join("habeas/config.toml"), "version = 1\n").unwrap();
    fs::write(fixture.project.join("habeas.toml"), "version = 1\n").unwrap();
    let before = fs::read(&fixture.evidence).unwrap();
    for args in [&["author", SUBJECT][..], &["author", "--all"]] {
        let output = fixture.run(args);
        assert!(!output.status.success(), "{args:?}: {output:?}");
        assert!(
            String::from_utf8_lossy(&output.stderr).contains("no authoring configuration"),
            "{output:?}"
        );
        assert_eq!(fs::read(&fixture.evidence).unwrap(), before);
        assert!(
            matches!(listener.accept(), Err(error) if error.kind() == std::io::ErrorKind::WouldBlock)
        );
    }
}
Input 12: outline tests/authoring_cli.rs fn[missing_or_stale_evidence_fails_validation_without_contacting_the_provider]
// {test}`requirements.authoring.deterministic_validation`
// {test}`requirements.authoring.configuration`
#[test]
fn missing_or_stale_evidence_fails_validation_without_contacting_the_provider() {
    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()));
    let changed = format!(":::{{req}} ready\n{REQUIREMENT} Changed.\n:::\n");
    let config_path = fixture.config.join("habeas/config.toml");
    let configured = fs::read_to_string(&config_path).unwrap();
    for config in [&configured[..], "version = 1\n"] {
        fs::write(&config_path, config).unwrap();
        for (case, expected) in [("missing", "missing for requirement"), ("stale", "changed")] {
            if case == "missing" {
                fs::remove_file(&fixture.evidence).unwrap();
            } else {
                fs::write(&fixture.evidence, &fixture.original).unwrap();
                fs::write(fixture.project.join("md/requirements.md"), &changed).unwrap();
            }
            let report = habeas::validate_repository(&fixture.project).unwrap();
            assert!(
                report
                    .errors
                    .iter()
                    .any(|error| error.contains(SUBJECT) && error.contains(expected)),
                "{case}: {:?}",
                report.errors
            );
            // Status and book rendering need no authoring credentials.
            let status = fixture
                .command()
                .env_remove("HABEAS_TEST_MODEL_KEY")
                .args(["status", "--all"])
                .output()
                .unwrap();
            assert!(status.status.success(), "{case}: {status:?}");
            assert!(
                String::from_utf8_lossy(&status.stdout).contains(SUBJECT),
                "{case}: {status:?}"
            );

            let mut book = mdbook_preprocessor::book::Book::new();
            book.push_item(mdbook_preprocessor::book::Chapter::new(
                "Requirements",
                fs::read_to_string(fixture.project.join("md/requirements.md")).unwrap(),
                "requirements.md",
                Vec::new(),
            ));
            let context = mdbook_preprocessor::PreprocessorContext::new(
                fixture.project.clone(),
                mdbook_preprocessor::config::Config::default(),
                "html".to_owned(),
            );
            let mut render = fixture
                .command()
                .env_remove("HABEAS_TEST_MODEL_KEY")
                .arg("mdbook")
                .stdin(std::process::Stdio::piped())
                .stdout(std::process::Stdio::piped())
                .stderr(std::process::Stdio::piped())
                .spawn()
                .unwrap();
            serde_json::to_writer(render.stdin.take().unwrap(), &(&context, &book)).unwrap();
            let rendered = render.wait_with_output().unwrap();
            assert!(rendered.status.success(), "{case}: {rendered:?}");
            let rendered: Value = serde_json::from_slice(&rendered.stdout).unwrap();
            assert!(rendered.to_string().contains(SUBJECT), "{case}");
        }
    }
    assert!(
        matches!(listener.accept(), Err(error) if error.kind() == std::io::ErrorKind::WouldBlock),
        "validation, status, or rendering contacted the provider"
    );
    assert!(!fixture.state.exists(), "no authoring usage was recorded");
    assert_eq!(
        fs::read_to_string(&fixture.evidence).unwrap(),
        fixture.original,
        "validation did not author evidence"
    );
}
Input 13: outline tests/configuration.rs fn[explicit_project_and_default_selections_choose_whole_configs]
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.authoring.rig_configuration_mapping`
// {test}`requirements.authoring.configuration`
// {test}`requirements.configuration.loading`
// {test}`requirements.configuration.structure`
#[test]
// {test}`requirements.authoring.configuration_structure`
fn explicit_project_and_default_selections_choose_whole_configs() {
    let dir = tempfile::tempdir().unwrap();
    let root = dir.path().canonicalize().unwrap();
    let config_path = root.join("config.toml");
    let mut config = UserConfig::parse(
        r#"
version = 1
[authoring]
default = "default"
[authoring.configs.default]
backend = "bedrock"
model = "cloud-id"
aws_profile = "named"
[authoring.configs.project]
backend = "ollama"
model = "project:tag"
endpoint = "http://server:11434"
[authoring.configs.explicit]
backend = "ollama"
model = "explicit:tag"
"#,
        &config_path,
    )
    .unwrap();
    assert_eq!(
        resolve_authoring_from(&config_path, Some(&config), &root, None)
            .unwrap()
            .name,
        "default"
    );
    config.authoring.as_mut().unwrap().projects.insert(
        root.clone(),
        habeas::config::ProjectSelection {
            config: "project".to_owned(),
        },
    );
    let project =
        resolve_authoring_from(&config_path, Some(&config), &root.join("."), None).unwrap();
    assert_eq!(project.name, "project");
    assert_eq!(project.project_root, root);
    let BackendConfig::Ollama(ollama) = project.backend else {
        panic!("wrong backend")
    };
    assert_eq!(ollama.endpoint(), "http://server:11434");
    let explicit =
        resolve_authoring_from(&config_path, Some(&config), &root, Some("explicit")).unwrap();
    let BackendConfig::Ollama(ollama) = explicit.backend else {
        panic!("wrong backend")
    };
    assert_eq!(ollama.model, "explicit:tag");
    assert_eq!(ollama.endpoint, None);
    let error = resolve_authoring_from(&config_path, Some(&config), &root, Some("DEFAULT"))
        .unwrap_err()
        .to_string();
    assert!(error.contains("DEFAULT"));
    assert!(error.contains("config.toml"));
    assert!(error.contains("editing-the-file"));
    // Missing configuration names the file and points to documented examples.
    let missing = resolve_authoring_from(&config_path, None, &root, None)
        .unwrap_err()
        .to_string();
    assert!(missing.contains("no authoring configuration"), "{missing}");
    assert!(
        missing.contains(&config_path.display().to_string()),
        "{missing}"
    );
    assert!(missing.contains("editing-the-file"), "{missing}");
}
Input 14: outline tests/configuration.rs fn[workspace_defaults_and_configs_combine_with_existing_user_selections]
// {test}`requirements.configuration.workspace_structure`
// {test}`requirements.authoring.configuration`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.configuration.serialization`
#[test]
fn workspace_defaults_and_configs_combine_with_existing_user_selections() {
    let temp = tempfile::tempdir().unwrap();
    let root = temp.path().canonicalize().unwrap();
    let user_path = root.join("user.toml");
    let mut user = UserConfig::parse("version = 1\n[authoring]\ndefault = 'user'\n[authoring.configs.user]\nbackend = 'bedrock'\nmodel = 'user-model'\naws_profile = 'user-profile'\n[authoring.configs.shared]\nbackend = 'bedrock'\nmodel = 'old-model'\nregion = 'us-west-2'\nconcurrency = 7\noptions = { temperature = 0.25, top_p = 0.5 }\n", &user_path).unwrap();
    let path = root.join("habeas.toml");
    fs::write(&path, "version = 1\n[authoring]\ndefault = 'workspace'\n[authoring.configs.workspace]\nbackend = 'ollama'\nmodel = 'workspace-model'\n[authoring.configs.shared]\nbackend = 'ollama'\nmodel = 'replacement'\noptions = { temperature = 0.8 }\n").unwrap();
    let mut workspace = load_workspace_config(&root).unwrap().unwrap();
    let selected = resolve_authoring_with_workspace_from(
        &user_path,
        Some(&user),
        Some(&workspace),
        &root,
        None,
    )
    .unwrap();
    assert_eq!(selected.name, "workspace");
    assert_eq!(selected.config_path, path);
    let replaced = resolve_authoring_with_workspace_from(
        &user_path,
        Some(&user),
        Some(&workspace),
        &root,
        Some("shared"),
    )
    .unwrap();
    assert_eq!(replaced.config_path, path);
    assert_eq!(replaced.concurrency, None);
    assert_eq!(
        replaced.backend.options_json().unwrap(),
        serde_json::json!({"temperature":0.8})
    );
    assert!(
        matches!(&replaced.backend, BackendConfig::Ollama(config) if config.model == "replacement" && config.endpoint.is_none())
    );

    user.authoring.as_mut().unwrap().projects.insert(
        root.clone(),
        habeas::config::ProjectSelection {
            config: "user".into(),
        },
    );
    let project = resolve_authoring_with_workspace_from(
        &user_path,
        Some(&user),
        Some(&workspace),
        &root,
        None,
    )
    .unwrap();
    assert_eq!(project.name, "user");
    assert_eq!(project.config_path, user_path);
    let explicit = resolve_authoring_with_workspace_from(
        &user_path,
        Some(&user),
        Some(&workspace),
        &root,
        Some("workspace"),
    )
    .unwrap();
    assert_eq!(explicit.name, "workspace");
    user.authoring.as_mut().unwrap().projects.clear();
    workspace.config.authoring.as_mut().unwrap().default = Some("user".into());
    let user_reference = resolve_authoring_with_workspace_from(
        &user_path,
        Some(&user),
        Some(&workspace),
        &root,
        None,
    )
    .unwrap();
    assert_eq!(user_reference.name, "user");
    assert_eq!(user_reference.config_path, user_path);
    workspace.config.authoring.as_mut().unwrap().default = None;
    assert_eq!(
        resolve_authoring_with_workspace_from(
            &user_path,
            Some(&user),
            Some(&workspace),
            &root,
            None
        )
        .unwrap()
        .name,
        "user"
    );
    workspace.config.authoring.as_mut().unwrap().default = Some("workspace".into());
    let workspace_only =
        resolve_authoring_with_workspace_from(&user_path, None, Some(&workspace), &root, None)
            .unwrap();
    assert_eq!(workspace_only.name, "workspace");
    let error = resolve_authoring_with_workspace_from(
        &user_path,
        Some(&user),
        Some(&workspace),
        &root,
        Some("missing"),
    )
    .unwrap_err()
    .to_string();
    assert!(
        error.contains(path.to_str().unwrap()) && error.contains("missing"),
        "{error}"
    );
}

Referenced definitions

Input 2: requirements selection requirements.configuration.user_location
:::{req} user_location
Habeas MUST locate its per-user configuration at
`$XDG_CONFIG_HOME/habeas/config.toml` on Unix when XDG_CONFIG_HOME is an absolute,
nonempty path, otherwise at `$HOME/.config/habeas/config.toml`. On Windows it MUST
use `%APPDATA%/habeas/config.toml`. `HOME` and `APPDATA` MUST likewise be
absolute, nonempty paths to be used. If no usable base directory can be
determined, an operation requiring user configuration MUST fail with an
explanatory diagnostic naming the variable.

The same user configuration MUST be usable across projects. Its location MUST
NOT be selected relative to the current project or changed by project settings.
User-local preferences for a project MAY remain in the user configuration;
workspace settings MUST use `habeas.toml` under
{cite}`requirements.configuration.workspace_location`.
:::
Input 3: requirements selection requirements.configuration.structure
:::{req} structure
The user configuration file MUST be UTF-8 TOML serializing UserConfig. It MUST
contain `version = 1` and MAY contain the documented feature tables. The common
root MUST contain only the schema version and those feature tables; feature
settings MUST NOT occupy unscoped root keys. A user file containing only
`version = 1` MUST be valid common configuration.

Workspace configuration MUST follow {cite}`requirements.configuration.workspace_structure`.
The absence of an optional feature section MUST be distinguishable
from that feature's explicit settings and interpreted according to its own
requirements.
:::
Input 4: requirements selection requirements.authoring.deterministic_validation
:::{req} deterministic_validation
Ordinary evidence validation, status inspection, and book rendering MUST continue
to check evidence using the existing rules without invoking models, contacting
providers, or requiring authoring configuration or credentials. Missing or stale
evidence MUST remain a validation failure rather than trigger authoring.
:::
Input 5: requirements selection requirements.authoring.credentials
:::{req} credentials
Bedrock configurations MAY supply `credentials` containing nonempty
`access_key_id`, `secret_access_key`, and optional nonempty `session_token`.
Ollama and OpenAI configurations MAY supply a nonempty `api_key`. Habeas MUST reject a
Bedrock record combining explicit credentials with `aws_profile`, and an Ollama or OpenAI
record combining `api_key` with `api_key_env`.

Explicit credentials MUST be passed directly to the selected provider without
changing process environment variables or writing credential files. Saved
explicit values MUST round-trip; credentials resolved from profiles or the
environment MUST NOT be serialized back. Debug output, configuration diagnostics,
usage records, and initial prompts MUST NOT include credential values. TOML
diagnostics MUST NOT echo credential-containing source lines. A configuration
file containing explicit credentials MAY be read as source; its credential
values MUST be redacted under {cite}`requirements.authoring.redaction`.
Validation MUST report a workspace `habeas.toml` present in the Git index that
contains explicit credentials, naming the file and the credential fields and
recommending credential-source references, because committed credentials leak.

Documentation MUST discourage literal credentials in workspace files and
recommend AWS profiles or environment-variable references. Examples MUST use
placeholders and explain that workspace files may be committed or read as source
when explicitly allowed.
:::
Input 6: requirements selection requirements.configuration.workspace_location
:::{req} workspace_location
Habeas MUST search from its invocation directory upward for the nearest enclosing
`habeas.toml`. It MUST use that file alone, without merging ancestor workspace
files. A library operation given a project root MUST search from that root unless
its current directory is inside the project, in which case it MUST start there.
The directory containing the selected file defines the base for its relative
paths; it does not replace the Cargo and mdBook project root. A missing file MUST
mean absent workspace settings. Discovery MUST report unreadable candidate files
rather than silently selecting an ancestor. Loading MUST NOT create the file.
:::
Input 7: requirements selection requirements.configuration.workspace_structure
:::{req} workspace_structure
{impl}`requirements.configuration.feature_sections`
`habeas.toml` MUST serialize WorkspaceConfig as UTF-8 TOML with `version = 1`.
Its supported feature tables are `[authoring]`, `[coverage]`, and
`[evidence]`; each MAY be absent. `[coverage]` has one optional key,
`reauthorings`, under {cite}`requirements.references.coverage.history`; it has
no user-file counterpart or invocation option, and no operation requires it. Unknown keys, unsupported versions, and invalid field types MUST produce
a diagnostic identifying the file and setting. Invalid TOML, including content
that is not UTF-8, MUST produce a diagnostic identifying the file, with the line
and column of a syntax error.
Features MUST define their own data structures and loading rules under
{cite}`requirements.configuration.feature_sections`. A file containing only
`version = 1` MUST be valid. Habeas settings MUST NOT require a `[habeas]` table
inside `book.toml`.
:::

Other sources

Input 1: requirements selection requirements.authoring.configuration
:::{req} configuration
Authoring MUST use the `[authoring]` sections of the shared user configuration
and the selected workspace's `habeas.toml`, refining
{impl}`requirements.configuration.feature_sections` for the authoring feature.
{cite}`requirements.configuration.user_location`
{cite}`requirements.configuration.structure`
Assessing a subject with `habeas author`, singly or in a batch that needs at
least one assessment, MUST require an `[authoring]` section in at least one of
these files; either section MAY be absent. No other operation requires the
section, including a batch with no assessments needed and the operations in
{cite}`requirements.authoring.deterministic_validation`.
It MUST support named configurations, workspace defaults, and a user-local
selection for each project. Credential-source references SHOULD be used;
explicit credentials MUST be supported under {cite}`requirements.authoring.credentials`.
{cite}`requirements.configuration.workspace_location`
{cite}`requirements.configuration.workspace_structure`
:::