requirements.configuration.workspace_location
Requirements index · View definition
Requirement
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.
Rationale
I found no gap against requirements.configuration.workspace_location.
Code
- Nearest file, searched upward.
src/config.rs#fn[workspace_document]starts at the current directory when it is inside the canonical root. Otherwise it starts at the root. It then walksancestors()and takes the firsthabeas.toml. That covers both the invocation-directory search and the library rule for a given project root.src/main.rs#fn[main]/use@118842506675callsload_workspace_evidence(¤t_dir)for the commands that load settings up front. - Single file, no merging.
workspace_documentreturns the first match immediately, and the loaders decode only that table. - Base for relative paths.
LoadedWorkspaceConfigandWorkspaceEvidenceConfigsetrootto the selected file’s parent.src/authoring/access.rs#impl[PathPolicy]/fn[load]joins evidence paths onto thatconfig.root.src/evidence.rs#fn[inspect_repository_with_progress]keeps its own project root for the book and evidence directories, so the workspace file does not replace it. - Missing file.
NotFoundis skipped, and if no candidate exists the function returnsNone, which callers treat as absent settings. - Unreadable candidates. Any
symlink_metadataerror other thanNotFound, or a read or parse failure, returns an error that names the path. It never falls through to an ancestor. - No creation. The loader only reads and never writes.
Tests
- Nearest file and no merging.
tests/configuration.rs#fn[workspace_discovery_uses_nearest_file_without_merging_or_rewriting_it]covers inheriting an outer file, selecting the nested file, not merging the two, leaving the file unchanged, an invalid-TOML error, andNonewhen all files are removed. It also exercises the library-root case with the current directory outside the project. - Current directory inside the project.
tests/commands.rs#fn[status_loads_nearest_workspace_file_without_validating_authoring]runsstatusfrom a nested directory with an invalid nested file and a valid outer file. The output names the nested path, so the search started at the current directory.tests/authoring_cli.rs#fn[authoring_uses_nearest_workspace_configuration_without_a_user_file]runsauthorfrom a nested directory. The nested file’s model is used, and the parent’s invalid default is ignored. - Relative-path base.
src/authoring/access.rs#mod[tests]/fn[evidence_rules_are_relative_to_the_selected_workspace_file]puts the file in the parent of the project root. It shows that evidence rules resolve against the file’s directory, not the project root. - Unreadable candidates and no creation.
tests/configuration.rs#fn[unreadable_configuration_files_are_reported_instead_of_skipped]makeshabeas.tomla directory with a valid ancestor file present. Both loaders return an error naming that path. It also loads from an empty directory, getsNone, and checks that no file was created. - Validation and project root.
tests/evidence_boundaries.rs#fn[validation_checks_workspace_common_config_without_loading_unused_authoring_settings]covers validation with a project-root workspace file.
The extra behavior in the loaders (the credentials flag and dropping [coverage]) is specified by other requirements that the same code marks with {impl}.
Inputs
Implementation
Input 2: outline src/authoring/access.rs impl[PathPolicy]/fn[load]
- File:
src/authoring/access.rs - Selector:
impl[PathPolicy]/fn[load] - Kind:
fn src/authoring/access.rs:17–38
// {impl}`requirements.configuration.evidence_paths`
// {impl}`requirements.configuration.workspace_location`
// {impl}`requirements.configuration.loading`
pub(crate) fn load(root: &Path) -> io::Result<Self> {
let Some(config) = crate::config::load_workspace_evidence(root)? else {
return Ok(Self::default());
};
Ok(Self {
allow: config
.evidence
.allow
.iter()
.map(|path| config.root.join(path))
.collect(),
disallow: config
.evidence
.disallow
.iter()
.map(|path| config.root.join(path))
.collect(),
})
}
Input 4: outline src/config.rs struct[LoadedWorkspaceConfig]
- File:
src/config.rs - Selector:
struct[LoadedWorkspaceConfig] - Kind:
struct src/config.rs:86–92
// {impl}`requirements.configuration.workspace_location`
#[derive(Clone, Debug)]
pub struct LoadedWorkspaceConfig {
pub path: PathBuf,
pub root: PathBuf,
pub config: WorkspaceConfig,
}
Input 5: outline src/config.rs fn[load_workspace_config]
- File:
src/config.rs - Selector:
fn[load_workspace_config] - Kind:
fn src/config.rs:891–915
// {impl}`requirements.configuration.workspace_location`
// {impl}`requirements.configuration.loading`
// {impl}`requirements.configuration.workspace_structure`
// {impl}`requirements.configuration.serialization`
// {impl}`requirements.authoring.configuration_serialization`
pub fn load_workspace_config(root: &Path) -> io::Result<Option<LoadedWorkspaceConfig>> {
let Some((path, mut table)) = workspace_document(root)? else {
return Ok(None);
};
// Authoring does not use `[coverage]`, so it must not fail on an invalid
// table (requirements.configuration.loading): the table is dropped
// before decoding, and only the coverage report decodes and validates it,
// through `load_coverage_reauthorings` and `CoverageConfig::validate`.
table.remove("coverage");
let config: WorkspaceConfig = decode(toml::Value::Table(table), &path, "")?;
config.validate(&path)?;
Ok(Some(LoadedWorkspaceConfig {
root: path
.parent()
.expect("configuration has a parent")
.to_owned(),
path,
config,
}))
}
Input 6: outline src/config.rs fn[load_workspace_evidence]
- File:
src/config.rs - Selector:
fn[load_workspace_evidence] - Kind:
fn src/config.rs:917–951
// {impl}`requirements.configuration.workspace_location`
// {impl}`requirements.configuration.workspace_structure`
// {impl}`requirements.configuration.evidence_paths`
// {impl}`requirements.configuration.loading`
// {impl}`requirements.authoring.deterministic_validation`
// {impl}`requirements.configuration.feature_sections`
pub fn load_workspace_evidence(root: &Path) -> io::Result<Option<WorkspaceEvidenceConfig>> {
let Some((path, table)) = workspace_document(root)? else {
return Ok(None);
};
let evidence: EvidenceConfig = table
.get("evidence")
.map(|value| decode(value.clone(), &path, "evidence"))
.transpose()?
.unwrap_or_default();
evidence.validate(&path)?;
let contains_credentials = table
.get("authoring")
.and_then(|value| value.get("configs"))
.and_then(toml::Value::as_table)
.is_some_and(|configs| {
configs.values().any(|config| {
config.get("credentials").is_some() || config.get("api_key").is_some()
})
});
Ok(Some(WorkspaceEvidenceConfig {
root: path
.parent()
.expect("configuration has a parent")
.to_owned(),
path,
evidence,
contains_credentials,
}))
}
Input 7: outline src/config.rs fn[workspace_document]
- File:
src/config.rs - Selector:
fn[workspace_document] - Kind:
fn src/config.rs:988–1019
// {impl}`requirements.configuration.workspace_location`
// {impl}`requirements.configuration.loading`
// {impl}`requirements.configuration.workspace_structure`
fn workspace_document(root: &Path) -> io::Result<Option<(PathBuf, toml::Table)>> {
let root = fs::canonicalize(root)?;
let start = std::env::current_dir()
.and_then(fs::canonicalize)
.ok()
.filter(|cwd| cwd.starts_with(&root))
.unwrap_or(root);
for directory in start.ancestors() {
let path = directory.join("habeas.toml");
match fs::symlink_metadata(&path) {
Ok(_) => {
let text = fs::read_to_string(&path).map_err(|error| {
io::Error::new(error.kind(), format!("{}: {error}", path.display()))
})?;
let table = parse_document(&text, &path)?;
validate_workspace_common(&table, &path)?;
return Ok(Some((path, table)));
}
Err(error) if error.kind() == io::ErrorKind::NotFound => {}
Err(error) => {
return Err(io::Error::new(
error.kind(),
format!("{}: {error}", path.display()),
));
}
}
}
Ok(None)
}
Input 8: outline src/evidence.rs fn[inspect_repository]
- File:
src/evidence.rs - Selector:
fn[inspect_repository] - Kind:
fn src/evidence.rs:175–183
// {impl}`requirements.ci.errors`
// {impl}`requirements.ci.diagnostics`
// {impl}`requirements.examples.evidence`
// {impl}`requirements.configuration.workspace_location`
// {impl}`requirements.configuration.workspace_structure`
// {impl}`requirements.configuration.loading`
pub(crate) fn inspect_repository(root: &Path) -> io::Result<RepositoryInspection> {
inspect_repository_with_progress(root, |_| {})
}
Input 9: outline src/evidence.rs fn[inspect_repository_with_progress]
- File:
src/evidence.rs - Selector:
fn[inspect_repository_with_progress] - Kind:
fn src/evidence.rs:185–386
// {impl}`requirements.ci.errors`
// {impl}`requirements.examples.evidence`
// {impl}`requirements.configuration.workspace_location`
// {impl}`requirements.configuration.workspace_structure`
// {impl}`requirements.configuration.loading`
// {impl}`requirements.ci.book_source`
// {impl}`requirements.definitions.declaration`
// {impl}`requirements.references.builtin_definitions`
// {impl}`requirements.ci.determination`
pub(crate) fn inspect_repository_with_progress(
root: &Path,
mut progress: impl FnMut(InspectionProgress),
) -> io::Result<RepositoryInspection> {
let root = fs::canonicalize(root)?;
progress(InspectionProgress {
stage: "discovering requirements",
completed: 0,
total: None,
});
let mut errors = Vec::new();
if let Err(error) = crate::config::load_workspace_evidence(&root) {
errors.push(error.to_string());
}
let md_root = book_source_dir(&root, &mut errors);
let definitions = collect_definitions(&root, &md_root, &mut errors);
let mut discovery_errors = errors.clone();
// {impl}`requirements.test-coverage.setup.validation`
// {impl}`requirements.test-coverage.setup.validation.static`
if let Err(error) = crate::execution_coverage::validate_setup(&root) {
errors.push(error.to_string());
}
// Only the coverage report uses `[coverage]`, so an invalid table is a
// finding but not a discovery failure, and authoring still proceeds.
if let Some(error) = crate::config::coverage_error(&root) {
errors.push(error.to_string());
}
let evidence_root = root.join("evidence");
let listing_errors = errors.len();
let evidence_files = if evidence_root.is_dir() {
files_with_extension(&root, &evidence_root, "json", &mut errors)
} else {
Vec::new()
};
let evidence_listed = errors.len() == listing_errors;
let mut present = BTreeSet::new();
let outlines = OutlineCache::default();
// Citation reviews are validated against their source items below.
let (review_files, ordinary_files): (Vec<_>, Vec<_>) = evidence_files
.iter()
.partition(|file| crate::citations::is_review_path(&evidence_root, file));
let review_files: Vec<PathBuf> = review_files.into_iter().cloned().collect();
// Site reviews are validated against the sites of their requirements.
// {impl}`requirements.ci.orphans`
let (site_files, ordinary_files): (Vec<_>, Vec<_>) = ordinary_files
.into_iter()
.partition(|file| crate::sites::is_review_path(&evidence_root, file));
let site_files: Vec<PathBuf> = site_files.into_iter().cloned().collect();
// {impl}`requirements.ci.orphans`
for (completed, file) in ordinary_files.iter().enumerate() {
progress(InspectionProgress {
stage: "evidence files",
completed,
total: Some(ordinary_files.len()),
});
let relative = file
.strip_prefix(&evidence_root)
.expect("evidence file is inside evidence directory");
let label = display_path(&root, file);
let name = if relative.components().count() == 1 {
relative
.file_name()
.and_then(|part| part.to_str())
.and_then(|part| part.strip_suffix(".json"))
} else {
None
};
let expected = name
.and_then(|name| definitions.get(name))
.filter(|d| d.kind != DefinitionKind::Term);
if let Some(name) = name.filter(|_| expected.is_some()) {
present.insert(name.to_owned());
} else {
errors.push(format!("{label}: no matching requirement or example"));
}
validate_evidence_file(&root, file, expected, &definitions, &outlines, &mut errors);
}
progress(InspectionProgress {
stage: "evidence files",
completed: ordinary_files.len(),
total: Some(ordinary_files.len()),
});
// {impl}`requirements.ci.coverage`
// Missing evidence is reported as a validation error; inspection never
// starts authoring.
// {impl}`requirements.authoring.deterministic_validation`
for (name, definition) in &definitions {
if definition.kind != DefinitionKind::Term && !present.contains(name) {
errors.push(format!(
"evidence/{name}.json: missing for {} at {}",
definition.kind.noun(),
definition.source
));
}
}
// Unreadable reference sources are discovery failures: a batch must not
// treat a partial scan as complete.
let scanned = errors.len();
progress(InspectionProgress {
stage: "discovering source references",
completed: 0,
total: None,
});
let files = discovered_files(&root, &mut errors);
let references = collect_references_with_progress(&root, &files, &mut errors, &mut progress);
discovery_errors.extend(errors[scanned..].iter().cloned());
validate_committed_credentials(&root, &mut errors);
// {impl}`requirements.references.distributed`
let sites = crate::sites::discover(
&root,
&definitions,
&files,
&outlines,
&mut errors,
&mut discovery_errors,
);
validate_references(
&root,
&definitions,
&references,
&sites,
&outlines,
&mut errors,
&mut progress,
);
crate::citations::validate(
&root,
&definitions,
&references,
&outlines,
&review_files,
&mut errors,
&mut progress,
);
crate::sites::validate(
&root,
&definitions,
&references,
&sites,
&outlines,
&site_files,
&mut errors,
&mut progress,
);
crate::rust_coverage::validate_cargo_examples(
&root,
&files,
&definitions,
&references,
&mut errors,
);
// An item an evidence record or review read is covered.
// {impl}`requirements.references.rust_item_coverage`
let reads = crate::rust_coverage::EvidenceReads::load(&evidence_files);
let uncovered = crate::rust_coverage::validate_rust_functions(
&root,
&files,
&definitions,
&reads,
&mut errors,
&mut discovery_errors,
&mut progress,
);
let examples = definitions
.values()
.filter(|definition| definition.kind == DefinitionKind::Example)
.count();
let requirements = definitions
.values()
.filter(|definition| definition.kind == DefinitionKind::Requirement)
.count();
Ok(RepositoryInspection {
root: root.clone(),
report: EvidenceReport {
requirements,
examples,
evidence_files: evidence_files.len(),
errors,
},
definitions,
references,
sites,
uncovered,
evidence_files,
evidence_listed,
discovery_errors,
})
}
Input 10: outline src/main.rs fn[main]/use@118842506675
- File:
src/main.rs - Selector:
fn[main]/use@118842506675 - Kind:
use src/main.rs:133–235
// {impl}`requirements.cli.clap`
let cli = Cli::parse();
// {impl}`requirements.configuration.workspace_location`
// {impl}`requirements.configuration.workspace_structure`
// {impl}`requirements.configuration.loading`
// Commands other than `author` load only the evidence settings, so status
// and book rendering never need authoring configuration or credentials.
// {impl}`requirements.authoring.deterministic_validation`
// Only commands that resolve evidence inputs use the workspace evidence
// path policy; setup, the session-start hook, and support queries do not.
// `status` and `info` render the validation report, which records an
// invalid workspace file as one finding and still runs the other checks,
// so they must not stop here.
// {impl}`requirements.ci.errors`
if !matches!(
cli.command,
Command::Mdbook {
command: Some(MdbookCommand::Supports { .. })
} | Command::Setup { .. }
| Command::Coverage { .. }
| Command::CoverageCheck
| Command::Test
| Command::CoverageProcess { .. }
| Command::Hook { .. }
| Command::Status { .. }
| Command::Info { .. }
) {
habeas::config::load_workspace_evidence(&std::env::current_dir()?)?;
}
match cli.command {
Command::Coverage { args } => {
std::process::exit(habeas::execution_coverage::run(
&setup::project_root()?,
&args,
)?);
}
// {impl}`requirements.test-coverage.check`
Command::CoverageCheck => {
let report = habeas::execution_coverage::check(&setup::project_root()?)?;
print!("{}", report.text);
std::process::exit(i32::from(!report.passed));
}
// {impl}`requirements.test-coverage.test`
Command::Test => {
std::process::exit(habeas::execution_coverage::test(&setup::project_root()?)?);
}
Command::CoverageProcess { args } => {
std::process::exit(habeas::execution_coverage::collect_process(&args)?);
}
// {impl}`requirements.cli.mdbook`
Command::Mdbook { command: None } => {
let (context, mut book) = mdbook_preprocessor::parse_input(io::stdin())?;
habeas::preprocess_book(&mut book, &context.root)?;
serde_json::to_writer(io::stdout().lock(), &book)?;
Ok(())
}
// {impl}`requirements.cli.invocation`
Command::Mdbook {
command: Some(MdbookCommand::Supports { renderer }),
} => {
if renderer == "html" {
Ok(())
} else {
std::process::exit(1)
}
}
// {impl}`requirements.cli.setup`
// {impl}`requirements.cli.setup_local_path`
Command::Setup { path } => setup::run(path.as_deref()),
// {impl}`requirements.cli.status`
// {impl}`requirements.cli.fixme_summary`
// {impl}`requirements.cli.fixme_issues`
Command::Status {
all,
selection,
verbose,
coverage,
} => {
let root = setup::project_root()?;
io::stdout().lock().write_all(
habeas::status_markdown_with_coverage(
&root,
all,
selection.as_deref(),
verbose,
coverage,
&habeas::GithubIssues::from_env(&root),
)?
.as_bytes(),
)?;
Ok(())
}
// {impl}`requirements.refactor.command`
// {impl}`requirements.refactor.invalid_mappings`
Command::Refactor { mappings, dry_run } => {
let root = setup::project_root()?;
match habeas::refactor(&root, &mappings, dry_run) {
Ok(report) => {
io::stdout().lock().write_all(report.as_bytes())?;
Ok(())
}
Err(habeas::RefactorError::Usage(message)) => {
use clap::CommandFactory;
Tests
Input 3: outline src/authoring/access.rs mod[tests]/fn[evidence_rules_are_relative_to_the_selected_workspace_file]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[evidence_rules_are_relative_to_the_selected_workspace_file] - Kind:
fn src/authoring/access.rs:724–747
// {test}`requirements.configuration.workspace_location`
#[test]
fn evidence_rules_are_relative_to_the_selected_workspace_file() {
let workspace = tempfile::tempdir().unwrap();
let base = workspace.path().canonicalize().unwrap();
let root = base.join("project");
fs::create_dir(&root).unwrap();
fs::write(base.join("allowed.txt"), "outside project").unwrap();
fs::write(root.join("denied.txt"), "inside project").unwrap();
fs::write(root.join("allowed.txt"), "unrelated local file").unwrap();
fs::write(
base.join("habeas.toml"),
"version = 1\n[evidence]\nallow = ['allowed.txt']\ndisallow = ['project/denied.txt']\n",
)
.unwrap();
let access = SourceAccess::load(&root).unwrap();
assert_eq!(
access.file(&root, Path::new("../allowed.txt")).unwrap(),
base.join("allowed.txt")
);
let error = access.file(&root, Path::new("denied.txt")).unwrap_err();
assert!(error.to_string().contains("disallowed"), "{error}");
assert!(access.file(&root, Path::new("allowed.txt")).is_ok());
}
Input 11: outline tests/authoring_cli.rs fn[authoring_uses_nearest_workspace_configuration_without_a_user_file]
- File:
tests/authoring_cli.rs - Selector:
fn[authoring_uses_nearest_workspace_configuration_without_a_user_file] - Kind:
fn tests/authoring_cli.rs:724–797
// {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 12: 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 13: 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 14: 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 15: 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.workspace_location
requirements.configuration.workspace_location:md/requirements/configuration.md:30–39
:::{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.
:::