requirements.configuration.loading
Requirements index · View definition
Requirement
An operation MUST load user configuration only when its requirements call for user settings. A missing user file MUST represent absent user configuration; whether the operation can proceed MUST be defined by the feature. Loading MUST NOT create a file, repair malformed input, or supply an undocumented selection.
When loading configuration, Habeas MUST report unreadable files, invalid TOML, unsupported user-file versions, unknown common keys, and invalid common field types. It MUST validate the feature sections used by that operation and report invalid feature settings with the file and setting identified. Unknown keys in an explicitly documented provider-owned options map MUST follow that feature’s validation rules.
An operation MUST NOT require or semantically validate configuration for a feature it does not use. This isolation MUST NOT suppress TOML syntax errors in a shared file that the operation otherwise needs to parse. In particular, ordinary validation still requires a parseable
book.tomlwhile remaining independent of authoring settings and the user configuration file. It MUST apply the selected workspace’s evidence path policy without loading its model clients or credentials.
Rationale
I read the supplied tests and mapped each obligation in requirements.configuration.loading to scenarios and assertions. I found no unacknowledged gap.
Load user configuration only when needed
tests/authoring_cli.rs#fn[ordinary_status_ignores_invalid_user_authoring_configuration]writes invalid TOML to the user config. It asserts thatstatussucceeds and that no state is created.tests/authoring_batch.rs#fn[batch_fills_evidence_preserves_current_records_and_reauthors_only_changed_inputs]runsauthor --allas a no-op with an invalid user config and again with the config removed. Both runs succeed and make no new model calls.tests/configuration.rs#fn[commands_without_evidence_inputs_ignore_an_invalid_workspace_file]shows thathook,setupandmdbook supportsdo not read an invalid workspace file.
A missing user file means absent configuration, and the feature decides whether to proceed
tests/configuration.rs#fn[absent_and_minimal_configuration_are_distinct_and_read_only]asserts that a missing file givesNoneand is not created.tests/configuration.rs#fn[explicit_project_and_default_selections_choose_whole_configs]asserts that authoring reports “no authoring configuration” with the file path when the config is absent.
Loading must not create files, repair input or supply an undocumented selection
- The file is not created.
absent_and_minimal_configuration_are_distinct_and_read_onlyasserts!path.exists(), andunreadable_configuration_files_are_reported_instead_of_skippedasserts the directory stays empty. - Malformed input is not repaired. Malformed and minimal user files are asserted unchanged, and
workspace_discovery_uses_nearest_file_without_merging_or_rewriting_itasserts the malformed workspace file is unchanged. - No selection is supplied.
configurations_without_any_selection_report_how_to_choose_oneasserts an error when configs exist but none is selected.
Reporting load failures
- Unreadable files:
unreadable_configuration_files_are_reported_instead_of_skippedcovers a directory in place of a file and non-UTF-8 content. It covers the user and workspace loaders and asserts the path appears in each error. - Invalid TOML:
absent_and_minimal_configuration_are_distinct_and_read_onlyandworkspace_diagnostics_identify_the_file_and_settingassert the syntax error with the file and position. - Unsupported versions, unknown common keys and wrong common field types:
invalid_schema_and_feature_values_report_the_configuration_pathandworkspace_diagnostics_identify_the_file_and_settingcoverversion = 2,version = '1'andunknown = truefor the user and workspace parsers. They assert the file and the setting appear in the message.
Feature validation with file and setting
storage_rules_reject_each_invalid_field_with_its_settingasserts both the file and the setting for many invalid authoring fields.workspace_diagnostics_identify_the_file_and_settingasserts that the error starts withfile: settingfor the authoring, evidence and coverage tables.authoring_concurrency_defaults_overrides_and_invalid_valuescovers invalid concurrency values.
Provider-owned options map
- Unknown arbitrary keys, such as
custom, are accepted inbackend_configuration_round_trips_without_materializing_defaults. - Reserved keys, such as
model,promptandtools, and non-finite floats are rejected instorage_rules_reject_each_invalid_field_with_its_setting.
Isolation
- Unused authoring settings are ignored by validation.
validation_checks_workspace_common_config_without_loading_unused_authoring_settingsandstatus_loads_nearest_workspace_file_without_validating_authoringassert this. - Unused authoring settings do not break the evidence loader.
evidence_configuration_ignores_unused_authoring_settings_and_detects_credentialsshows this, including an unknown backend and credentials, and asserts the credential text is not printed. - Authoring ignores an invalid
[coverage]table, while validation reports it. This is covered byan_invalid_coverage_table_is_a_validation_finding_but_authoring_proceedsandthe_window_follows_the_workspace_setting. - TOML syntax errors in a shared file are still reported.
validation_checks_workspace_common_config_without_loading_unused_authoring_settingswritesversion = [and asserts the error.status_loads_nearest_workspace_file_without_validating_authoringcovers a malformed nestedhabeas.toml.
Ordinary validation and book.toml
src/evidence.rs#mod[tests]/fn[book_source_defaults_only_when_absent_and_reports_invalid_configuration]covers a missingbook.toml, invalid TOML and wrong types. It also covers defaults when settings are absent.- Independence from user configuration is shown by the status test with an invalid user config.
Evidence path policy
configured_external_inputs_validate_and_remain_subject_to_freshness_and_disallowapplies the selected workspace’sallowanddisallowpolicy invalidate_repository.workspace_discovery_uses_nearest_file_without_merging_or_rewriting_itcovers nearest-file selection.- Credentials are not loaded.
evidence_configuration_ignores_unused_authoring_settings_and_detects_credentialsshows the evidence loader only flags that credentials are present.
Inputs
Tests
Input 2: outline src/evidence.rs mod[tests]/fn[book_source_defaults_only_when_absent_and_reports_invalid_configuration]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[book_source_defaults_only_when_absent_and_reports_invalid_configuration] - Kind:
fn src/evidence.rs:2479–2531
// {test}`requirements.ci.book_source`
// {test}`requirements.configuration.loading`
#[test]
fn book_source_defaults_only_when_absent_and_reports_invalid_configuration() {
let temp = TempDir::new().unwrap();
let root = temp.path();
let path = root.join("book.toml");
for (configuration, expected) in [
("", "src"),
("[book]\ntitle = 'Example'\n", "src"),
("[book]\nsrc = 'docs'\n", "docs"),
("book = { src = 'docs' }\n", "docs"),
] {
fs::write(&path, configuration).unwrap();
let mut errors = Vec::new();
assert_eq!(
super::book_source_dir(root, &mut errors),
root.join(expected)
);
assert!(errors.is_empty(), "{errors:?}");
}
fs::remove_file(&path).unwrap();
let mut errors = Vec::new();
super::book_source_dir(root, &mut errors);
assert!(
errors
.iter()
.any(|error| error.contains("book.toml: cannot read book configuration"))
);
for (configuration, expected) in [
("[book", "invalid TOML"),
("book = 'wrong'", "book must be a table"),
("[book]\nsrc = 7", "book.src must be a string"),
("[book]\nsrc = false", "book.src must be a string"),
("[book]\nsrc = []", "book.src must be a string"),
("[book.src]", "book.src must be a string"),
("[book]\nsrc = ''", "book.src must be a directory"),
("[book]\nsrc = '/outside'", "book.src must be a directory"),
("[book]\nsrc = '../outside'", "book.src must be a directory"),
(
"[book]\nsrc = 'md/../outside'",
"book.src must be a directory",
),
] {
fs::write(&path, configuration).unwrap();
let mut errors = Vec::new();
super::book_source_dir(root, &mut errors);
assert!(
errors.iter().any(|error| error.contains(expected)),
"{configuration:?}: {errors:?}"
);
}
}
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_cli.rs fn[ordinary_status_ignores_invalid_user_authoring_configuration]
- File:
tests/authoring_cli.rs - Selector:
fn[ordinary_status_ignores_invalid_user_authoring_configuration] - Kind:
fn tests/authoring_cli.rs:1622–1644
// {test}`requirements.authoring.deterministic_validation`
// {test}`requirements.configuration.loading`
#[test]
fn ordinary_status_ignores_invalid_user_authoring_configuration() {
let fixture = Fixture::new("http://127.0.0.1:1");
fs::write(
fixture.config.join("habeas/config.toml"),
"this is not TOML [",
)
.unwrap();
let output = fixture.run(&["status", SUBJECT, "--all"]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(String::from_utf8_lossy(&output.stdout).contains(SUBJECT));
assert!(!fixture.state.exists());
assert_eq!(
fs::read_to_string(&fixture.evidence).unwrap(),
fixture.original
);
}
Input 5: outline tests/commands.rs fn[status_loads_nearest_workspace_file_without_validating_authoring]
- File:
tests/commands.rs - Selector:
fn[status_loads_nearest_workspace_file_without_validating_authoring] - Kind:
fn tests/commands.rs:223–269
// {test}`requirements.configuration.workspace_location`
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.configuration.workspace_structure`
// {test}`requirements.configuration.loading`
// {test}`requirements.authoring.deterministic_validation`
// {test}`requirements.cli.status`
// {test}`requirements.ci.errors`
#[test]
fn status_loads_nearest_workspace_file_without_validating_authoring() {
let temp = fixture();
let nested = temp.path().join("src/nested");
fs::write(temp.path().join("habeas.toml"), "version = 99\n").unwrap();
fs::write(
nested.join("habeas.toml"),
"version = 1\n[authoring]\nconfigs = 'invalid but unused'\n",
)
.unwrap();
let output = habeas(&nested, &["status"]);
assert!(output.status.success(), "{output:?}");
// An invalid workspace file is one validation finding: `status` and
// `info` still run and report the checks that do not depend on it.
for args in [["status"].as_slice(), ["info", "requirements.*"].as_slice()] {
let output = habeas(temp.path(), args);
assert!(output.status.success(), "{args:?}: {output:?}");
let text = String::from_utf8(output.stdout).unwrap();
assert!(
text.contains("habeas.toml: version: expected version = 1"),
"{args:?}: {text}"
);
assert!(
text.contains("evidence/requirements.malformed.json: invalid JSON"),
"{args:?}: {text}"
);
}
fs::write(temp.path().join("habeas.toml"), "version = 1\n").unwrap();
fs::write(nested.join("habeas.toml"), "version = [\n").unwrap();
let output = habeas(&nested, &["status"]);
assert!(output.status.success(), "{output:?}");
let text = String::from_utf8(output.stdout).unwrap();
assert!(
text.contains(&nested.join("habeas.toml").display().to_string())
&& text.contains("evidence/requirements.malformed.json: invalid JSON"),
"{text}"
);
}
Input 6: outline tests/configuration.rs fn[absent_and_minimal_configuration_are_distinct_and_read_only]
- File:
tests/configuration.rs - Selector:
fn[absent_and_minimal_configuration_are_distinct_and_read_only] - Kind:
fn tests/configuration.rs:69–106
// {test}`requirements.configuration.structure`
// {test}`requirements.configuration.loading`
// {test}`requirements.configuration.serialization`
// {test}`requirements.configuration.workspace_structure`
#[test]
// {test}`requirements.configuration.documentation`
fn absent_and_minimal_configuration_are_distinct_and_read_only() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("user.toml");
assert!(load_user_config(&path).unwrap().is_none());
assert!(!path.exists());
let original = "# keep this comment\nversion = 1\n";
fs::write(&path, original).unwrap();
let config = load_user_config(&path).unwrap().unwrap();
assert!(config.authoring.is_none());
assert_eq!(fs::read_to_string(&path).unwrap(), original);
assert_eq!(
UserConfig::parse(&config.to_toml().unwrap(), &path).unwrap(),
config
);
let book = "[book]\nsrc = 'docs'\n";
assert!(
ProjectConfig::from_book_toml(book, &path)
.unwrap()
.is_none()
);
assert_eq!(
ProjectConfig::from_book_toml(&format!("{book}\n[habeas]\n"), &path).unwrap(),
Some(ProjectConfig {})
);
assert!(ProjectConfig::from_book_toml("[habeas]\nversion = 1\n", &path).is_err());
let malformed = "version = [\n";
fs::write(&path, malformed).unwrap();
let error = load_user_config(&path).unwrap_err().to_string();
assert!(error.contains("invalid TOML syntax"), "{error}");
assert!(error.contains(path.to_str().unwrap()), "{error}");
assert_eq!(fs::read_to_string(&path).unwrap(), malformed);
}
Input 7: outline tests/configuration.rs fn[backend_configuration_round_trips_without_materializing_defaults]
- File:
tests/configuration.rs - Selector:
fn[backend_configuration_round_trips_without_materializing_defaults] - Kind:
fn tests/configuration.rs:108–158
// {test}`requirements.authoring.configuration_structure`
// {test}`requirements.authoring.configuration_serialization`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.authoring.concurrency`
// {test}`requirements.configuration.serialization`
#[test]
// {test}`requirements.configuration.loading`
fn backend_configuration_round_trips_without_materializing_defaults() {
let source = r#"
version = 1
[authoring]
default = "Cloud"
[authoring.configs.Cloud]
backend = "bedrock"
model = "arn:aws:bedrock:us-west-2:123:inference-profile/exact-id"
aws_profile = "research"
region = "us-west-2"
[authoring.configs.Cloud.options]
temperature = 0.2
max_tokens = 777
enabled = true
labels = ["a", "b"]
[authoring.configs.Cloud.options.custom]
arbitrary = "provider-defined"
[authoring.configs.local]
backend = "ollama"
model = "tiny:latest"
"#;
let path = Path::new("settings.toml");
let config = UserConfig::parse(source, path).unwrap();
let authoring = config.authoring.as_ref().unwrap();
assert!(authoring.projects.is_empty());
let local = &authoring.configs["local"].backend;
let BackendConfig::Ollama(ollama) = local else {
panic!("wrong backend")
};
assert_eq!(ollama.endpoint(), "http://localhost:11434");
assert_eq!(ollama.endpoint, None);
assert!(ollama.options.is_empty());
assert_eq!(local.model_ref().model, "tiny:latest");
assert_eq!(local.model_ref().backend, BackendKind::Ollama);
let json = authoring.configs["Cloud"].backend.options_json().unwrap();
assert_eq!(json["custom"]["arbitrary"], "provider-defined");
assert_eq!(json["max_tokens"], 777);
let serialized = config.to_toml().unwrap();
assert!(!serialized.contains("endpoint"));
assert!(!serialized.contains("http://localhost"));
assert!(!serialized.contains("concurrency"));
assert_eq!(UserConfig::parse(&serialized, path).unwrap(), config);
}
Input 8: outline tests/configuration.rs fn[authoring_concurrency_defaults_overrides_and_invalid_values]
- File:
tests/configuration.rs - Selector:
fn[authoring_concurrency_defaults_overrides_and_invalid_values] - Kind:
fn tests/configuration.rs:160–206
// {test}`requirements.authoring.concurrency`
// {test}`requirements.authoring.configuration_structure`
// {test}`requirements.authoring.configuration_serialization`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.configuration.loading`
// {test}`requirements.configuration.serialization`
#[test]
fn authoring_concurrency_defaults_overrides_and_invalid_values() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("config.toml");
for backend in ["bedrock", "ollama", "openai"] {
let base =
format!("version = 1\n[authoring.configs.model]\nbackend = '{backend}'\nmodel = 'm'\n");
let defaults = UserConfig::parse(&base, &path).unwrap();
let resolved =
resolve_authoring_from(&path, Some(&defaults), dir.path(), Some("model")).unwrap();
assert_eq!(resolved.concurrency, None);
let expected = if backend != "ollama" {
std::thread::available_parallelism()
.map(|n| n.get())
.unwrap_or(1)
} else {
1
};
assert_eq!(resolved.effective_concurrency(), expected);
assert!(!defaults.to_toml().unwrap().contains("concurrency"));
let configured = UserConfig::parse(&format!("{base}concurrency = 7\n"), &path).unwrap();
let resolved =
resolve_authoring_from(&path, Some(&configured), dir.path(), Some("model")).unwrap();
assert_eq!(resolved.concurrency.unwrap().get(), 7);
assert_eq!(resolved.effective_concurrency(), 7);
let serialized = configured.to_toml().unwrap();
assert!(serialized.contains("concurrency = 7"));
assert_eq!(UserConfig::parse(&serialized, &path).unwrap(), configured);
assert!(resolved.backend.options().is_empty());
for invalid in ["0", "-1", "1.5", "'2'"] {
let error = UserConfig::parse(&format!("{base}concurrency = {invalid}\n"), &path)
.unwrap_err()
.to_string();
assert!(error.contains(&path.display().to_string()), "{error}");
assert!(error.contains("concurrency"), "{error}");
}
}
}
Input 9: outline tests/configuration.rs fn[explicit_project_and_default_selections_choose_whole_configs]
- File:
tests/configuration.rs - Selector:
fn[explicit_project_and_default_selections_choose_whole_configs] - Kind:
fn tests/configuration.rs:261–336
// {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 10: outline tests/configuration.rs fn[configurations_without_any_selection_report_how_to_choose_one]
- File:
tests/configuration.rs - Selector:
fn[configurations_without_any_selection_report_how_to_choose_one] - Kind:
fn tests/configuration.rs:338–356
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.configuration.loading`
#[test]
fn configurations_without_any_selection_report_how_to_choose_one() {
let dir = tempfile::tempdir().unwrap();
let root = dir.path().canonicalize().unwrap();
let config_path = root.join("config.toml");
// Configurations exist, but no name, project entry, or default selects one.
let unselected = UserConfig::parse(
"version = 1\n[authoring.configs.only]\nbackend = 'ollama'\nmodel = 'm:tag'\n",
&config_path,
)
.unwrap();
let error = resolve_authoring_from(&config_path, Some(&unselected), &root, None)
.unwrap_err()
.to_string();
assert!(error.contains("no configuration selected"), "{error}");
assert!(error.contains("editing-the-file"), "{error}");
}
Input 11: outline tests/configuration.rs fn[invalid_schema_and_feature_values_report_the_configuration_path]
- File:
tests/configuration.rs - Selector:
fn[invalid_schema_and_feature_values_report_the_configuration_path] - Kind:
fn tests/configuration.rs:358–386
// {test}`requirements.configuration.structure`
// {test}`requirements.configuration.loading`
// {test}`requirements.authoring.configuration_serialization`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.configuration.feature_sections`
#[test]
fn invalid_schema_and_feature_values_report_the_configuration_path() {
let path = Path::new("/settings/habeas/config.toml");
for source in [
"version = 2",
"version = '1'",
"",
"version = 1\nunknown = true",
"version = 1\n[authoring]",
"version = 1\n[authoring]\nconfigs = {}\ndefault = '_bad'",
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = ''",
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\nunknown = true",
"version = 1\n[authoring.configs.local]\nbackend = 'unsupported'\nmodel = 'm'",
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\napi_key_env = 'BAD=KEY'",
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\n[authoring.configs.local.options]\nvalue = nan",
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\n[authoring.configs.local.options]\nmodel = 'override'",
"version = 1\n[authoring]\nconfigs = {}\n[authoring.projects.relative]\nconfig = 'local'",
] {
let error = UserConfig::parse(source, path).unwrap_err().to_string();
assert!(error.contains("/settings/habeas/config.toml"), "{error}");
}
let valid = UserConfig::parse("version = 1\n[authoring]\nconfigs = {}", path).unwrap();
assert!(valid.authoring.unwrap().configs.is_empty());
}
Input 12: outline tests/configuration.rs fn[workspace_discovery_uses_nearest_file_without_merging_or_rewriting_it]
- File:
tests/configuration.rs - Selector:
fn[workspace_discovery_uses_nearest_file_without_merging_or_rewriting_it] - Kind:
fn tests/configuration.rs:416–474
// {test}`requirements.configuration.workspace_location`
// {test}`requirements.authoring.configuration_serialization`
// {test}`requirements.authoring.configuration_structure`
// {test}`requirements.configuration.workspace_structure`
// {test}`requirements.configuration.loading`
// {test}`requirements.configuration.serialization`
#[test]
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.configuration.documentation`
fn workspace_discovery_uses_nearest_file_without_merging_or_rewriting_it() {
let temp = tempfile::tempdir().unwrap();
let project = temp.path().join("project");
let nested = project.join("nested/deep");
fs::create_dir_all(&nested).unwrap();
let outer = temp.path().join("habeas.toml");
fs::write(&outer, "version = 1\n[evidence]\nallow = ['outer']\n").unwrap();
let inherited = load_workspace_config(&project).unwrap().unwrap();
assert_eq!(inherited.path, outer);
assert_eq!(inherited.root, temp.path().canonicalize().unwrap());
let path = project.join("nested/habeas.toml");
let text = "# preserved\nversion = 1\n[authoring]\ndefault = 'cloud'\n[evidence]\ndisallow = ['private']\n";
fs::write(&path, text).unwrap();
let closest = load_workspace_config(&nested).unwrap().unwrap();
assert_eq!(closest.path, path);
assert_eq!(closest.root, path.parent().unwrap());
assert!(
closest
.config
.authoring
.as_ref()
.unwrap()
.configs
.is_empty()
);
assert!(closest.config.evidence.as_ref().unwrap().allow.is_empty());
assert_eq!(
closest.config.evidence.as_ref().unwrap().disallow,
vec![Path::new("private")]
);
assert_eq!(fs::read_to_string(&path).unwrap(), text);
let serialized = closest.config.to_toml().unwrap();
assert!(!serialized.contains("configs"));
assert_eq!(
WorkspaceConfig::parse(&serialized, &path).unwrap(),
closest.config
);
fs::write(&path, "version = 1\n[evidence\n").unwrap();
let error = load_workspace_config(&nested).unwrap_err().to_string();
assert!(error.contains(path.to_str().unwrap()), "{error}");
assert!(error.contains("invalid TOML"), "{error}");
assert_eq!(
fs::read_to_string(&path).unwrap(),
"version = 1\n[evidence\n"
);
fs::remove_file(path).unwrap();
fs::remove_file(outer).unwrap();
assert!(load_workspace_config(&nested).unwrap().is_none());
}
Input 13: outline tests/configuration.rs fn[evidence_configuration_ignores_unused_authoring_settings_and_detects_credentials]
- File:
tests/configuration.rs - Selector:
fn[evidence_configuration_ignores_unused_authoring_settings_and_detects_credentials] - Kind:
fn tests/configuration.rs:476–517
// {test}`requirements.configuration.workspace_structure`
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.configuration.loading`
// {test}`requirements.authoring.credentials`
#[test]
fn evidence_configuration_ignores_unused_authoring_settings_and_detects_credentials() {
let temp = tempfile::tempdir().unwrap();
let path = temp.path().join("habeas.toml");
fs::write(&path, "version = 1\n[evidence]\nallow = ['generated', '../shared']\ndisallow = ['generated/private']\n[authoring.configs.cloud]\nbackend = 'unknown'\ncredentials = 'DO_NOT_PRINT_THIS_CREDENTIAL'\n").unwrap();
let policy = load_workspace_evidence(temp.path()).unwrap().unwrap();
assert_eq!(policy.path, path);
assert_eq!(policy.root, temp.path().canonicalize().unwrap());
assert_eq!(
policy.evidence.allow,
vec![Path::new("generated"), Path::new("../shared")]
);
assert!(policy.contains_credentials);
let error = load_workspace_config(temp.path()).unwrap_err().to_string();
assert!(!error.contains("DO_NOT_PRINT_THIS_CREDENTIAL"), "{error}");
fs::write(&path, "version = 1\n[authoring]\ndefault = 123\n").unwrap();
assert!(
!load_workspace_evidence(temp.path())
.unwrap()
.unwrap()
.contains_credentials
);
assert!(load_workspace_config(temp.path()).is_err());
for source in [
"version = 2",
"version = 1\nunknown = true",
"version = 1\n[evidence]\nallow = ['']",
"version = 1\n[evidence]\ndisallow = [42]",
"version = 1\n[evidence]\nunknown = []",
] {
fs::write(&path, source).unwrap();
let error = load_workspace_evidence(temp.path())
.unwrap_err()
.to_string();
assert!(error.contains(path.to_str().unwrap()), "{error}");
}
}
Input 14: outline tests/configuration.rs fn[explicit_credentials_round_trip_but_diagnostics_and_debug_redact_them]
- File:
tests/configuration.rs - Selector:
fn[explicit_credentials_round_trip_but_diagnostics_and_debug_redact_them] - Kind:
fn tests/configuration.rs:700–767
// {test}`requirements.authoring.credentials`
// {test}`requirements.authoring.configuration_serialization`
// {test}`requirements.configuration.serialization`
// {test}`requirements.configuration.loading`
// {test}`requirements.authoring.configuration_structure`
#[test]
fn explicit_credentials_round_trip_but_diagnostics_and_debug_redact_them() {
let path = Path::new("habeas.toml");
let source = "version = 1\n[authoring.configs.cloud]\nbackend = 'bedrock'\nmodel = 'm'\n[authoring.configs.cloud.credentials]\naccess_key_id = 'PRIVATE_ACCESS_KEY'\nsecret_access_key = 'PRIVATE_SECRET_KEY'\nsession_token = 'PRIVATE_SESSION'\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\napi_key = 'PRIVATE_OLLAMA_KEY'\n[authoring.configs.openai]\nbackend = 'openai'\napi_key = 'PRIVATE_OPENAI_KEY'\n";
let config = WorkspaceConfig::parse(source, path).unwrap();
let debug = format!("{config:?}");
for secret in [
"PRIVATE_ACCESS_KEY",
"PRIVATE_SECRET_KEY",
"PRIVATE_SESSION",
"PRIVATE_OLLAMA_KEY",
"PRIVATE_OPENAI_KEY",
] {
assert!(!debug.contains(secret), "{debug}");
}
assert_eq!(
WorkspaceConfig::parse(&config.to_toml().unwrap(), path).unwrap(),
config
);
let BackendConfig::Ollama(local) = &config.authoring.as_ref().unwrap().configs["local"].backend
else {
panic!("wrong backend");
};
assert_eq!(
local.api_key_from(|_| None).unwrap().as_deref(),
Some("PRIVATE_OLLAMA_KEY")
);
for invalid_source in [
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\napi_key = ['PRIVATE_OLLAMA_KEY']\n",
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\napi_key = 'PRIVATE_OLLAMA_KEY' unexpected\n",
"version = 1\n[authoring.configs.cloud]\nbackend = 'bedrock'\nmodel = 'm'\ncredentials = 'PRIVATE_SECRET_KEY'\n",
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\napi_key = 123456789\n",
] {
for error in [
WorkspaceConfig::parse(invalid_source, path).unwrap_err(),
UserConfig::parse(invalid_source, path).unwrap_err(),
] {
let error = error.to_string();
assert!(error.contains("habeas.toml"), "{error}");
assert!(!error.contains("PRIVATE_"), "{error}");
assert!(!error.contains("123456789"), "{error}");
}
}
for invalid_source in [
source.replace(
"model = 'm'\n[authoring.configs.cloud.credentials]",
"model = 'm'\naws_profile = 'p'\n[authoring.configs.cloud.credentials]",
),
source.replace(
"api_key = 'PRIVATE_OLLAMA_KEY'",
"api_key = 'PRIVATE_OLLAMA_KEY'\napi_key_env = 'KEY'",
),
source.replace(
"secret_access_key = 'PRIVATE_SECRET_KEY'",
"secret_access_key = ''",
),
source.replace("access_key_id = 'PRIVATE_ACCESS_KEY'", "access_key_id = ''"),
source.replace("session_token = 'PRIVATE_SESSION'", "session_token = ''"),
source.replace("api_key = 'PRIVATE_OLLAMA_KEY'", "api_key = ''"),
] {
assert!(WorkspaceConfig::parse(&invalid_source, path).is_err());
}
}
Input 15: outline tests/configuration.rs fn[storage_rules_reject_each_invalid_field_with_its_setting]
- File:
tests/configuration.rs - Selector:
fn[storage_rules_reject_each_invalid_field_with_its_setting] - Kind:
fn tests/configuration.rs:857–1012
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.authoring.configuration_structure`
// {test}`requirements.configuration.loading`
#[test]
fn storage_rules_reject_each_invalid_field_with_its_setting() {
let temp = tempfile::tempdir().unwrap();
let root = temp.path().canonicalize().unwrap();
let path = root.join("config.toml");
let named = |name: &str| {
format!("version = 1\n[authoring.configs.{name}]\nbackend = 'ollama'\nmodel = 'm'\n")
};
let ollama = |extra: &str| format!("{}{extra}", named("local"));
let project = |key: &str, config: &str| {
format!(
"version = 1\n[authoring]\nconfigs = {{}}\n[authoring.projects.{key:?}]\nconfig = '{config}'\n"
)
};
let root_text = root.display().to_string();
let base = root.file_name().unwrap().to_string_lossy().into_owned();
let mut cases = vec![
// Configuration names.
(named("\"\""), "authoring.configs."),
(named("\"a.b\""), "authoring.configs.a.b"),
(named("\"a b\""), "authoring.configs.a b"),
(named("\"é\""), "authoring.configs.é"),
(named("\"-x\""), "authoring.configs.-x"),
(named("_x"), "authoring.configs._x"),
(
"version = 1\n[authoring]\nconfigs = {}\ndefault = 'a.b'\n".to_owned(),
"authoring.default",
),
(project(&root_text, "bad name"), ".config"),
// Project-selection keys must be canonical absolute paths.
(project("relative", "local"), "authoring.projects.relative"),
(
project(&format!("{root_text}/../{base}"), "local"),
"authoring.projects.",
),
(
project(&format!("{root_text}/./"), "local"),
"authoring.projects.",
),
(
project(&format!("{root_text}/"), "local"),
"authoring.projects.",
),
// Model IDs.
(
"version = 1\n[authoring.configs.c]\nbackend = 'bedrock'\nmodel = ''\n".to_owned(),
"authoring.configs.c.model",
),
// `api_key_env` names.
(
ollama("api_key_env = ''\n"),
"authoring.configs.local.api_key_env",
),
(
ollama("api_key_env = 'A=B'\n"),
"authoring.configs.local.api_key_env",
),
(
ollama("api_key_env = \"A\\u0000B\"\n"),
"authoring.configs.local.api_key_env",
),
// Non-finite floats, including nested ones.
(
ollama("[authoring.configs.local.options]\nvalue = nan\n"),
"authoring.configs.local.options.value",
),
(
ollama("[authoring.configs.local.options]\nvalue = inf\n"),
"authoring.configs.local.options.value",
),
(
ollama("[authoring.configs.local.options]\nvalue = [1.0, -inf]\n"),
"authoring.configs.local.options.value",
),
(
ollama("[authoring.configs.local.options.value]\ninner = nan\n"),
"authoring.configs.local.options.value",
),
];
#[cfg(unix)]
{
let link = root.join("link");
std::os::unix::fs::symlink(&root, &link).unwrap();
cases.push((
project(&link.display().to_string(), "local"),
"authoring.projects.",
));
}
// Options may not replace the model, prompt, or tools.
for key in [
"model",
"modelId",
"model_id",
"prompt",
"messages",
"system",
"tools",
"tool_choice",
"toolChoice",
"toolConfig",
] {
for backend in ["ollama", "bedrock"] {
cases.push((
format!("version = 1\n[authoring.configs.c]\nbackend = '{backend}'\nmodel = 'm'\n[authoring.configs.c.options]\n{key} = 'x'\n"),
"authoring.configs.c.options.",
));
}
}
for (source, setting) in &cases {
let error = UserConfig::parse(source, &path).unwrap_err().to_string();
assert!(error.contains(path.to_str().unwrap()), "{source}: {error}");
assert!(error.contains(setting), "{source}: {error}");
}
// Workspace files apply the same name and field rules.
let workspace_path = root.join("habeas.toml");
for (source, setting) in [
(
"version = 1\n[authoring]\ndefault = '_bad'\n".to_owned(),
"authoring.default",
),
(named("\"a.b\""), "authoring.configs.a.b"),
(
ollama("api_key_env = ''\n"),
"authoring.configs.local.api_key_env",
),
] {
let error = WorkspaceConfig::parse(&source, &workspace_path)
.unwrap_err()
.to_string();
assert!(error.contains("habeas.toml"), "{source}: {error}");
assert!(error.contains(setting), "{source}: {error}");
}
// Accepted values: case-sensitive distinct names, opaque model IDs with
// tags, a canonical existing root, and a canonical root that does not exist.
let missing = root.join("not-yet-created");
let accepted = UserConfig::parse(
&format!(
"version = 1\n[authoring]\n[authoring.configs.Local]\nbackend = 'ollama'\nmodel = 'name:tag@sha256:abc'\napi_key_env = 'MODEL_KEY_1'\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\n[authoring.configs.A-1_b]\nbackend = 'bedrock'\nmodel = 'arn:aws:bedrock:us-east-1:1:x/y'\n[authoring.projects.{root_text:?}]\nconfig = 'Local'\n[authoring.projects.{:?}]\nconfig = 'A-1_b'\n",
missing.display().to_string()
),
&path,
)
.unwrap();
let authoring = accepted.authoring.unwrap();
assert_eq!(authoring.configs.len(), 3);
assert_eq!(
authoring.configs["Local"].backend.model_ref().model,
"name:tag@sha256:abc"
);
assert_eq!(authoring.projects.len(), 2);
}
Input 16: outline tests/configuration.rs fn[workspace_diagnostics_identify_the_file_and_setting]
- File:
tests/configuration.rs - Selector:
fn[workspace_diagnostics_identify_the_file_and_setting] - Kind:
fn tests/configuration.rs:1077–1164
// {test}`requirements.configuration.workspace_structure`
// {test}`requirements.configuration.loading`
#[test]
fn workspace_diagnostics_identify_the_file_and_setting() {
let temp = tempfile::tempdir().unwrap();
let path = temp.path().join("habeas.toml");
let file = path.to_str().unwrap();
for (source, setting) in [
("version = '1'", "version"),
("version = 2", "version"),
("version = 1\nunknown = true", "unknown"),
(
"version = 1\n[authoring]\ndefault = 123",
"authoring.default",
),
("version = 1\n[authoring]\nbogus = 1", "authoring.bogus"),
(
"version = 1\n[authoring.configs.cloud]\nbackend = 'bedrock'\nmodel = 3",
"authoring.configs.cloud",
),
(
"version = 1\n[evidence]\ndisallow = [42]",
"evidence.disallow",
),
("version = 1\n[evidence]\nunknown = []", "evidence.unknown"),
("version = 1\n[evidence]\nallow = ['']", "evidence.allow[0]"),
] {
fs::write(&path, source).unwrap();
let errors = [
load_workspace_config(temp.path()).map(|_| ()),
WorkspaceConfig::parse(source, &path).map(|_| ()),
];
for error in errors {
let error = error.unwrap_err().to_string();
assert!(error.starts_with(&format!("{file}: {setting}")), "{error}");
}
}
// Only the coverage report decodes `[coverage]`; authoring ignores it.
for (source, setting) in [
(
"version = 1\n[coverage]\nreauthorings = 'many'",
"coverage.reauthorings",
),
("version = 1\n[coverage]\nbogus = 1", "coverage.bogus"),
] {
fs::write(&path, source).unwrap();
let errors = [
load_coverage_reauthorings(temp.path()).map(|_| ()),
WorkspaceConfig::parse(source, &path).map(|_| ()),
];
for error in errors {
let error = error.unwrap_err().to_string();
assert!(error.starts_with(&format!("{file}: {setting}")), "{error}");
}
load_workspace_config(temp.path()).unwrap().unwrap();
}
// The evidence loader decodes only the `[evidence]` table it uses.
for (source, setting) in [
(
"version = 1\n[evidence]\ndisallow = [42]",
"evidence.disallow",
),
("version = 1\n[evidence]\nunknown = []", "evidence.unknown"),
] {
fs::write(&path, source).unwrap();
let error = load_workspace_evidence(temp.path())
.unwrap_err()
.to_string();
assert!(error.starts_with(&format!("{file}: {setting}")), "{error}");
}
fs::write(&path, b"version = 1\n# \xff\n").unwrap();
let error = load_workspace_config(temp.path()).unwrap_err().to_string();
assert!(error.contains(file), "{error}");
fs::write(&path, "version = 1\n[evidence\n").unwrap();
let error = load_workspace_config(temp.path()).unwrap_err().to_string();
assert!(error.starts_with(file), "{error}");
assert!(
error.contains("invalid TOML syntax at line 2, column"),
"{error}"
);
let error = UserConfig::parse("version = 1\n[authoring]\ndefault = 123", &path)
.unwrap_err()
.to_string();
assert!(
error.starts_with(&format!("{file}: authoring.default")),
"{error}"
);
}
Input 17: outline tests/configuration.rs fn[unreadable_configuration_files_are_reported_instead_of_skipped]
- File:
tests/configuration.rs - Selector:
fn[unreadable_configuration_files_are_reported_instead_of_skipped] - Kind:
fn tests/configuration.rs:1166–1201
// {test}`requirements.configuration.workspace_location`
// {test}`requirements.configuration.loading`
// {test}`requirements.configuration.structure`
#[test]
fn unreadable_configuration_files_are_reported_instead_of_skipped() {
let temp = tempfile::tempdir().unwrap();
let outer = temp.path().join("habeas.toml");
fs::write(&outer, "version = 1\n").unwrap();
let project = temp.path().join("project");
fs::create_dir_all(project.join("habeas.toml")).unwrap();
for error in [
load_workspace_config(&project).map(|_| ()),
load_workspace_evidence(&project).map(|_| ()),
] {
let error = error.unwrap_err().to_string();
assert!(
error.contains(project.join("habeas.toml").to_str().unwrap()),
"{error}"
);
}
let user = temp.path().join("config.toml");
fs::create_dir(&user).unwrap();
let error = load_user_config(&user).unwrap_err().to_string();
assert!(error.contains(user.to_str().unwrap()), "{error}");
let binary = temp.path().join("binary.toml");
fs::write(&binary, b"version = 1\n# \xff\n").unwrap();
let error = load_user_config(&binary).unwrap_err().to_string();
assert!(error.contains(binary.to_str().unwrap()), "{error}");
// Loading an absent workspace file leaves the directory unchanged.
let empty = tempfile::tempdir().unwrap();
assert!(load_workspace_config(empty.path()).unwrap().is_none());
assert!(load_workspace_evidence(empty.path()).unwrap().is_none());
assert!(!empty.path().join("habeas.toml").exists());
assert_eq!(fs::read_dir(empty.path()).unwrap().count(), 0);
}
Input 18: outline tests/configuration.rs fn[commands_without_evidence_inputs_ignore_an_invalid_workspace_file]
- File:
tests/configuration.rs - Selector:
fn[commands_without_evidence_inputs_ignore_an_invalid_workspace_file] - Kind:
fn tests/configuration.rs:1556–1581
// {test}`requirements.configuration.loading`
#[test]
fn commands_without_evidence_inputs_ignore_an_invalid_workspace_file() {
let temp = tempfile::tempdir().unwrap();
let project = temp.path();
fs::write(
project.join("habeas.toml"),
"version = 1\n[evidence]\nallow = [1]\n",
)
.unwrap();
let run = |args: &[&str]| {
std::process::Command::new(env!("CARGO_BIN_EXE_habeas"))
.current_dir(project)
.args(args)
.stdin(std::process::Stdio::null())
.output()
.unwrap()
};
let hook = run(&["hook", "session-start"]);
assert!(hook.status.success(), "{hook:?}");
let setup = run(&["setup"]);
let stderr = String::from_utf8_lossy(&setup.stderr);
assert!(stderr.contains("cannot find a project"), "{stderr}");
assert!(!stderr.contains("habeas.toml"), "{stderr}");
assert!(run(&["mdbook", "supports", "html"]).status.success());
}
Input 19: outline tests/coverage.rs fn[the_window_follows_the_workspace_setting]
- File:
tests/coverage.rs - Selector:
fn[the_window_follows_the_workspace_setting] - Kind:
fn tests/coverage.rs:201–229
// {test}`requirements.references.coverage.history`
// {test}`requirements.configuration.loading`
#[test]
fn the_window_follows_the_workspace_setting() {
let temp = project();
let root = temp.path();
fs::write(
root.join("habeas.toml"),
"version = 1\n\n[coverage]\nreauthorings = 1\n",
)
.unwrap();
record(
root,
"rules.check",
&["fn[parse]", "fn[render]", "fn[helper]"],
);
commit(root, "first");
assert!(warned(root).is_empty());
record(root, "rules.check", &["fn[render]", "fn[helper]"]);
commit(root, "second");
assert_eq!(warned(root), ["parse"]);
fs::write(
root.join("habeas.toml"),
"version = 1\n\n[coverage]\nreauthorings = 0\n",
)
.unwrap();
let error = habeas::coverage_warnings(root).unwrap_err().to_string();
assert!(error.contains("coverage.reauthorings"), "{error}");
}
Input 20: outline tests/coverage.rs fn[an_invalid_coverage_table_is_a_validation_finding_but_authoring_proceeds]
- File:
tests/coverage.rs - Selector:
fn[an_invalid_coverage_table_is_a_validation_finding_but_authoring_proceeds] - Kind:
fn tests/coverage.rs:598–633
// {test}`requirements.configuration.workspace_structure`
// {test}`requirements.configuration.loading`
// {test}`requirements.references.coverage.history`
#[test]
fn an_invalid_coverage_table_is_a_validation_finding_but_authoring_proceeds() {
let temp = project();
let root = temp.path();
fs::write(root.join("md/rules.md"), "# Rules\n").unwrap();
commit(root, "first");
for (table, setting) in [
("[coverage]\nreauthorings = 0\n", "coverage.reauthorings"),
("[coverage]\nreauthorings = 'x'\n", "coverage.reauthorings"),
("[coverage]\nwindow = 2\n", "coverage.window"),
] {
fs::write(root.join("habeas.toml"), format!("version = 1\n\n{table}")).unwrap();
let errors = habeas::validate_repository(root).unwrap().errors;
assert!(
errors
.iter()
.any(|error| error.contains("habeas.toml") && error.contains(setting)),
"{table}: {errors:#?}"
);
// Authoring does not use `[coverage]`.
let output = Command::new(env!("CARGO_BIN_EXE_habeas"))
.args(["author", "--all"])
.current_dir(root)
.output()
.unwrap();
assert!(output.status.success(), "{table}: {output:?}");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("cannot compute coverage warnings"),
"{stderr}"
);
}
}
Input 21: outline tests/evidence_boundaries.rs fn[configured_external_inputs_validate_and_remain_subject_to_freshness_and_disallow]
- File:
tests/evidence_boundaries.rs - Selector:
fn[configured_external_inputs_validate_and_remain_subject_to_freshness_and_disallow] - Kind:
fn tests/evidence_boundaries.rs:410–461
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.ci.input_containment`
// {test}`requirements.ci.outline_inputs`
// {test}`requirements.configuration.loading`
#[test]
fn configured_external_inputs_validate_and_remain_subject_to_freshness_and_disallow() {
let temp = fixture();
let root = temp.path().join("project");
let external = temp.path().join("generated");
fs::create_dir(&external).unwrap();
let source = external.join("generated.rs");
fs::write(&source, "pub fn generated() {}\n").unwrap();
let external_toml = toml::Value::String(external.display().to_string());
let config = format!("version = 1\n[evidence]\nallow = [{external_toml}]\n");
fs::write(root.join("habeas.toml"), &config).unwrap();
{
let input = outline(&root, source.to_str().unwrap(), "fn[generated]");
write_inputs(&root, vec![input]);
fs::write(root.join("habeas.toml"), "version = 1\n").unwrap();
assert!(
validate_repository(&root)
.unwrap()
.errors
.join("\n")
.contains("outside the repository")
);
fs::write(root.join("habeas.toml"), &config).unwrap();
let report = validate_repository(&root).unwrap();
assert!(report.errors.is_empty(), "{:?}", report.errors);
fs::write(&source, "pub fn generated() { changed(); }\n").unwrap();
assert!(
validate_repository(&root)
.unwrap()
.errors
.join("\n")
.contains("outline input changed")
);
fs::write(&source, "pub fn generated() {}\n").unwrap();
fs::write(
root.join("habeas.toml"),
format!("{config}disallow = [{external_toml}]\n"),
)
.unwrap();
assert!(
validate_repository(&root)
.unwrap()
.errors
.join("\n")
.contains("disallowed")
);
}
}
Input 22: outline tests/evidence_boundaries.rs fn[validation_checks_workspace_common_config_without_loading_unused_authoring_settings]
- File:
tests/evidence_boundaries.rs - Selector:
fn[validation_checks_workspace_common_config_without_loading_unused_authoring_settings] - Kind:
fn tests/evidence_boundaries.rs:508–533
// {test}`requirements.configuration.workspace_location`
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.configuration.workspace_structure`
// {test}`requirements.configuration.loading`
// {test}`requirements.authoring.deterministic_validation`
#[test]
fn validation_checks_workspace_common_config_without_loading_unused_authoring_settings() {
let temp = fixture();
let root = temp.path().join("project");
for text in [
"version = 2\n",
"version = 1\nunknown = true\n",
"version = [\n",
] {
fs::write(root.join("habeas.toml"), text).unwrap();
let errors = validate_repository(&root).unwrap().errors.join("\n");
assert!(errors.contains("habeas.toml"), "{text:?}: {errors}");
}
fs::write(
root.join("habeas.toml"),
"version = 1\n[authoring]\nconfigs = 'invalid unused authoring settings'\n",
)
.unwrap();
let report = validate_repository(&root).unwrap();
assert!(report.errors.is_empty(), "{:?}", report.errors);
}
Other sources
Input 1: requirements selection requirements.configuration.loading
requirements.configuration.loading:md/requirements/configuration.md:217–237
:::{req} loading
An operation MUST load user configuration only when its requirements call for
user settings. A missing user file MUST represent absent user configuration;
whether the operation can proceed MUST be defined by the feature. Loading MUST
NOT create a file, repair malformed input, or supply an undocumented selection.
When loading configuration, Habeas MUST report unreadable files, invalid TOML,
unsupported user-file versions, unknown common keys, and invalid common field
types. It MUST validate the feature sections used by that operation and report
invalid feature settings with the file and setting identified. Unknown keys in
an explicitly documented provider-owned options map MUST follow that feature's
validation rules.
An operation MUST NOT require or semantically validate configuration for a
feature it does not use. This isolation MUST NOT suppress TOML syntax errors in
a shared file that the operation otherwise needs to parse. In particular,
ordinary validation still requires a parseable `book.toml` while remaining
independent of authoring settings and the user configuration file. It MUST apply
the selected workspace's evidence path policy without loading its model clients
or credentials.
:::