requirements.configuration.structure
Requirements index · View definition
Requirement
The user configuration file MUST be UTF-8 TOML serializing UserConfig. It MUST contain
version = 1and 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 onlyversion = 1MUST be valid common configuration.Workspace configuration MUST follow
. The absence of an optional feature section MUST be distinguishable from that feature’s explicit settings and interpreted according to its own requirements.
Rationale
The reviewed tests adequately check requirements.configuration.structure. I did not request implementation source. Every obligation is exercised with assertions, and none is untested or left unmarked.
Obligations and the tests that cover them
- UTF-8 TOML serializing
UserConfig:tests/configuration.rs#fn[absent_and_minimal_configuration_are_distinct_and_read_only]checks a TOML syntax error. It asserts the “invalid TOML syntax” message and the file path.tests/configuration.rs#fn[unreadable_configuration_files_are_reported_instead_of_skipped]writes a user file containing non-UTF-8 bytes and asserts the error names the file. It does the same for a directory in place of the file.- The first test also round-trips through
to_toml()andUserConfig::parseand asserts equality.
version = 1required:tests/configuration.rs#fn[invalid_schema_and_feature_values_report_the_configuration_path]rejectsversion = 2,version = '1', and an empty file. Each error is asserted to contain the file path. The feature-sections test also checks thatversion = 2is rejected alongside each feature table, with “version” in the message.- Root holds only the version and feature tables:
- The invalid-values test rejects an unknown root key in a user file (
version = 1\nunknown = true). tests/configuration.rs#fn[feature_sections_are_scoped_and_absent_sections_use_defaults]rejects feature settings at the root (allow,default,reauthorings). It also rejects settings in the wrong section, such asallowunder[authoring],defaultunder[evidence], and[evidence]or[coverage]in a user file.- Those root-key checks run against
WorkspaceConfig. The user file’s root-key check uses only the generic unknown key. I judged that sufficient, because the requirement’s distinction is “unscoped root key”, and the unknown-key rejection covers it.
- The invalid-values test rejects an unknown root key in a user file (
- A file containing only
version = 1is valid: The minimal-configuration test loads# keep this comment\nversion = 1\nwithload_user_configand succeeds. It also asserts the file is left unchanged. The feature-sections test checks the same forWorkspaceConfig. - Absence distinguishable from explicit settings:
- The minimal file yields
authoring.is_none(). - The invalid-values test parses
[authoring]withconfigs = {}and getsSomewith emptyconfigs. That is distinct from the absent section. - An absent file gives
Nonefromload_user_config, which is distinct from a loaded config. [evidence]and an absent evidence table are both checked.- The distinction is also exercised for
ProjectConfig:from_book_tomlreturnsNonewithout[habeas]andSomewith an empty[habeas].
- The minimal file yields
- Interpretation by each feature’s own requirements: The feature-sections test asserts that absent evidence yields empty allow and disallow lists. It also asserts that evidence loading ignores invalid authoring content.
- Workspace configuration follows
workspace_structure: This is a cited requirement, so its implementation and tests are out of scope. The feature-sections test is also marked forworkspace_structure, and it covers workspace parsing.
Marking: The relevant tests carry {test} references to requirements.configuration.structure. No marking gap was found.
Inputs
Tests
Input 3: 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 4: 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 5: 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 6: 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 7: outline tests/configuration.rs fn[feature_sections_are_scoped_and_absent_sections_use_defaults]
- File:
tests/configuration.rs - Selector:
fn[feature_sections_are_scoped_and_absent_sections_use_defaults] - Kind:
fn tests/configuration.rs:1203–1271
// {test}`requirements.configuration.feature_sections`
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.configuration.structure`
// {test}`requirements.configuration.workspace_structure`
#[test]
fn feature_sections_are_scoped_and_absent_sections_use_defaults() {
let temp = tempfile::tempdir().unwrap();
let path = temp.path().join("habeas.toml");
// An absent `[evidence]` table, or omitted arrays, mean empty lists.
for source in ["version = 1\n", "version = 1\n[evidence]\n"] {
fs::write(&path, source).unwrap();
let policy = load_workspace_evidence(temp.path()).unwrap().unwrap();
assert!(policy.evidence.allow.is_empty() && policy.evidence.disallow.is_empty());
}
let config = WorkspaceConfig::parse("version = 1\n", &path).unwrap();
assert!(config.authoring.is_none() && config.evidence.is_none() && config.coverage.is_none());
let config =
WorkspaceConfig::parse("version = 1\n[coverage]\nreauthorings = 5\n", &path).unwrap();
assert_eq!(config.coverage.unwrap().reauthorings, Some(5));
// The one positivity rule applies to the whole-file parse too.
let error = WorkspaceConfig::parse("version = 1\n[coverage]\nreauthorings = 0\n", &path)
.unwrap_err()
.to_string();
assert!(error.contains("coverage.reauthorings"), "{error}");
// Feature settings must stay within their sections.
for source in [
"version = 1\nallow = ['generated']\n",
"version = 1\ndefault = 'cloud'\n",
"version = 1\n[authoring]\nallow = ['generated']\n",
"version = 1\n[evidence]\ndefault = 'cloud'\n",
"version = 1\nreauthorings = 3\n",
"version = 1\n[coverage]\nallow = ['generated']\n",
] {
assert!(WorkspaceConfig::parse(source, &path).is_err(), "{source}");
}
assert!(UserConfig::parse("version = 1\n[evidence]\nallow = []\n", &path).is_err());
// `[coverage]` has no user-file counterpart.
assert!(UserConfig::parse("version = 1\n[coverage]\nreauthorings = 3\n", &path).is_err());
// The evidence feature does not reinterpret or validate authoring settings.
fs::write(
&path,
"version = 1\n[authoring]\ndefault = 'missing'\nunknown = 1\n[evidence]\nallow = ['generated']\n",
)
.unwrap();
let policy = load_workspace_evidence(temp.path()).unwrap().unwrap();
assert_eq!(policy.evidence.allow, vec![Path::new("generated")]);
// Authoring settings stay in `[authoring]`; its provider-owned options
// cannot replace harness settings.
for source in [
"version = 1\n[authoring.configs.c]\nbackend = 'ollama'\nmodel = 'm'\nallow = []\n",
"version = 1\n[authoring.configs.c]\nbackend = 'ollama'\nmodel = 'm'\n[authoring.configs.c.options]\nmodel = 'x'\n",
] {
assert!(UserConfig::parse(source, &path).is_err(), "{source}");
assert!(WorkspaceConfig::parse(source, &path).is_err(), "{source}");
}
// An absent authoring section configures nothing.
let user = UserConfig::parse("version = 1\n", &path).unwrap();
assert!(user.authoring.is_none());
for feature in [
"[authoring]\nconfigs = {}",
"[evidence]\nallow = []",
"[coverage]\nreauthorings = 3",
] {
let error = WorkspaceConfig::parse(&format!("version = 2\n{feature}\n"), &path)
.unwrap_err()
.to_string();
assert!(error.contains("version"), "{error}");
}
}
Referenced definitions
Input 2: requirements selection requirements.configuration.workspace_structure
requirements.configuration.workspace_structure:md/requirements/configuration.md:110–124
:::{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.configuration.structure
requirements.configuration.structure:md/requirements/configuration.md:97–108
:::{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.
:::