requirements.authoring.read_denial.build_output
Requirements index · View definition
Requirement
A tool error for a path inside the book’s build directory,
bookunlessbook.tomlsets[build] build-dir, or inside the project-roottargetdirectory, that no workspace allow rule or generated-output rule permits MUST say that the path holds build output and that the sources it is built from are elsewhere in the project.
Rationale
The tests adequately cover requirements.authoring.read_denial.build_output.
Obligations derived from the text
- A tool error for a path inside the build directory must say the path holds build output and that its sources are elsewhere in the project.
- The build directory is
bookby default, or the[build] build-dirvalue frombook.toml. - The same applies to the project-root
targetdirectory. - The message applies only when no workspace allow rule and no generated-output rule permits the path.
How the tests cover them
src/authoring/tools.rs#mod[tests]/fn[requests_for_book_or_target_output_are_ordinary_read_failures]:- It runs two configurations. One has the default
bookbuild directory. The other setsbuild-dir = 'site'. - In each, it requests a nested file under the build directory and under
targetthroughhabeas(line-range and item forms),outline,list_filesandripgrep. - Every error must not be
PermissionDenied. Every message must contain both “holds build output” and “the sources it is built from are elsewhere in the project”. This checks both required statements. - A negative case shows that when
build-diris set,book/source.txtis read normally. That fixes the build directory as the configured one.
- It runs two configurations. One has the default
src/authoring/access.rs#mod[tests]/fn[explicit_allow_overrides_the_build_output_refusal]:- With no
book.toml, so the defaultbook, it checks thattarget/doc/page.htmlandbook/page.htmlfail with “holds build output”. - After
habeas.tomladds allow rules fortarget/docandbook/page.html, both files read successfully. This covers the carve-out for workspace allow rules.
- With no
src/authoring/tools.rs#mod[tests]/fn[cargo_output_is_discovered_and_read_without_building_or_allowing_other_target_files]:- The generated-output location (
target/debug/build/.../out) is listed, searched, and read throughhabeasandast_grep. This covers the generated-output carve-out. - A sibling file under
targetstill fails with “holds build output” and is notPermissionDenied. - After an explicit disallow rule, the error is the separate
PermissionDenied“disallowed” error. This distinguishes the build-output message from the disallow message.
- The generated-output location (
Gaps
I found no established gap. A path like sub/target is not named by the text as build output, so it needs no test. All three tests carry the {test} reference to the requirement, so there are no marking gaps. The acknowledgments list is empty and none is needed.
Inputs
Tests
Input 2: outline src/authoring/access.rs mod[tests]/fn[explicit_allow_overrides_the_build_output_refusal]
- File:
src/authoring/access.rs - Selector:
mod[tests]/fn[explicit_allow_overrides_the_build_output_refusal] - Kind:
fn src/authoring/access.rs:908–935
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.authoring.generated_inputs`
// {test}`requirements.authoring.read_denial.build_output`
#[test]
fn explicit_allow_overrides_the_build_output_refusal() {
let root = tempfile::tempdir().unwrap();
for directory in ["target/doc", "book"] {
fs::create_dir_all(root.path().join(directory)).unwrap();
fs::write(root.path().join(directory).join("page.html"), "built\n").unwrap();
}
let root = fs::canonicalize(root.path()).unwrap();
for file in ["target/doc/page.html", "book/page.html"] {
let error = SourceAccess::load(&root)
.unwrap()
.file(&root, Path::new(file))
.unwrap_err();
assert!(error.to_string().contains("holds build output"), "{error}");
}
fs::write(
root.join("habeas.toml"),
"version = 1\n[evidence]\nallow = ['target/doc', 'book/page.html']\n",
)
.unwrap();
let access = SourceAccess::load(&root).unwrap();
for file in ["target/doc/page.html", "book/page.html"] {
assert!(access.file(&root, Path::new(file)).is_ok(), "{file}");
}
}
Input 3: outline src/authoring/tools.rs mod[tests]/fn[cargo_output_is_discovered_and_read_without_building_or_allowing_other_target_files]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[cargo_output_is_discovered_and_read_without_building_or_allowing_other_target_files] - Kind:
fn src/authoring/tools.rs:2568–2703
// {test}`requirements.authoring.generated_inputs`
// {test}`requirements.authoring.file_discovery`
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.configuration.evidence_paths`
// {test}`requirements.authoring.read_denial`
// {test}`requirements.authoring.read_denial.build_output`
// {test}`requirements.authoring.structural_search`
#[test]
fn cargo_output_is_discovered_and_read_without_building_or_allowing_other_target_files() {
let root = project();
fs::write(root.path().join("src/lib.rs"), "pub fn ready() {}\n").unwrap();
fs::write(
root.path().join("Cargo.lock"),
"version = 4\n\n[[package]]\nname = 'fixture'\nversion = '0.1.0'\n",
)
.unwrap();
fs::write(root.path().join(".gitignore"), "target/\n").unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
let unbuilt = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert!(
dispatch(
&unbuilt,
"habeas",
&json!({"file":"src/lib.rs", "line_start":1})
)
.is_ok()
);
assert!(!root.path().join("target").exists());
let out = root.path().join("target/debug/build/fixture-hash/out");
fs::create_dir_all(&out).unwrap();
fs::write(out.join("generated.rs"), "pub fn generated_needle() {}\n").unwrap();
fs::write(
out.parent().unwrap().join("root-output"),
out.to_str().unwrap(),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let listing = dispatch(&sources, "list_files", &json!({})).unwrap();
assert!(
listing
.result
.get("entries")
.unwrap_or(&listing.result)
.as_array()
.unwrap()
.iter()
.any(|entry| entry["path"] == "target/debug/build/fixture-hash/out")
);
let search = dispatch(&sources, "ripgrep", &json!({"pattern":"generated_needle"})).unwrap();
let generated = dispatch(
&sources,
"list_files",
&json!({"path":"target/debug/build/fixture-hash/out"}),
)
.unwrap();
assert_eq!(
generated.result,
json!([{"path":"target/debug/build/fixture-hash/out/generated.rs","kind":"file"}])
);
assert!(generated.inputs.is_empty());
assert_eq!(matched(&search).len(), 1);
let structural_arguments =
json!({"language":"rust","rule":{"rule":{"pattern":"pub fn generated_needle() {}"}}});
let structural = dispatch(&sources, "ast_grep", &structural_arguments).unwrap();
assert_eq!(
found(&structural),
["target/debug/build/fixture-hash/out/generated.rs#fn[generated_needle]"]
);
assert!(structural.inputs.is_empty());
let read = dispatch(&sources, "habeas", &json!({"file":"target/debug/build/fixture-hash/out/generated.rs", "item":"fn[generated_needle]"})).unwrap();
assert_eq!(
read.result["input"]["text"],
json!(["pub fn generated_needle() {}"])
);
// Other build output under target is an ordinary read failure.
let error = dispatch(
&sources,
"habeas",
&json!({"file":"target/debug/build/fixture-hash/root-output", "line_start":1}),
)
.err()
.unwrap();
assert_ne!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(error.to_string().contains("holds build output"), "{error}");
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[evidence]\ndisallow = ['target/debug/build/fixture-hash/out']\n",
)
.unwrap();
let denied = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let listing = dispatch(&denied, "list_files", &json!({})).unwrap();
assert!(
!listing
.result
.get("entries")
.unwrap_or(&listing.result)
.as_array()
.unwrap()
.iter()
.any(|entry| entry["path"] == "target/debug/build/fixture-hash/out")
);
assert!(
matched(&dispatch(&denied, "ripgrep", &json!({"pattern":"generated_needle"})).unwrap())
.is_empty()
);
assert!(matched(&dispatch(&denied, "ast_grep", &structural_arguments).unwrap()).is_empty());
for (name, arguments) in [
(
"habeas",
json!({"file":"target/debug/build/fixture-hash/out/generated.rs", "line_start":1}),
),
(
"list_files",
json!({"path":"target/debug/build/fixture-hash/out"}),
),
(
"ripgrep",
json!({"path":"target/debug/build/fixture-hash/out", "pattern":"generated_needle"}),
),
(
"ast_grep",
json!({"path":"target/debug/build/fixture-hash/out","language":"rust","rule":{"rule":{"kind":"function_item"}}}),
),
] {
let error = dispatch(&denied, name, &arguments).err().unwrap();
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(error.to_string().contains("disallowed"), "{error}");
let path = arguments["file"]
.as_str()
.or_else(|| arguments["path"].as_str())
.unwrap();
assert!(error.to_string().contains(path), "{error}");
}
}
Input 4: outline src/authoring/tools.rs mod[tests]/fn[requests_for_book_or_target_output_are_ordinary_read_failures]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[requests_for_book_or_target_output_are_ordinary_read_failures] - Kind:
fn src/authoring/tools.rs:3146–3203
// {test}`requirements.authoring.read_denial`
// {test}`requirements.authoring.read_denial.build_output`
// {test}`requirements.authoring.tool_descriptions.special_cases`
#[test]
fn requests_for_book_or_target_output_are_ordinary_read_failures() {
let root = project();
for (book, built) in [("", "book"), ("[build]\nbuild-dir = 'site'\n", "site")] {
fs::write(
root.path().join("book.toml"),
format!("[book]\nsrc = 'md'\n{book}"),
)
.unwrap();
for directory in [built, "target"] {
fs::create_dir_all(root.path().join(directory).join("nested")).unwrap();
fs::write(
root.path().join(directory).join("nested/page.html"),
"fn built_needle() {}\n",
)
.unwrap();
}
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
for directory in [built, "target"] {
let file = format!("{directory}/nested/page.html");
for (name, arguments) in [
("habeas", json!({"file": file, "line_start": 1})),
("habeas", json!({"file": file, "item": ""})),
("outline", json!({"file": file})),
("list_files", json!({"path": directory})),
("ripgrep", json!({"pattern": "needle", "path": directory})),
] {
let error = dispatch(&sources, name, &arguments).err().unwrap();
assert_ne!(
error.kind(),
io::ErrorKind::PermissionDenied,
"{name} {arguments}: {error}"
);
assert!(
error.to_string().contains("holds build output")
&& error.to_string().contains(
"the sources it is built from are elsewhere in the project"
),
"{name} {arguments}: {error}"
);
}
}
}
// With a build-dir set, `book` is an ordinary project directory.
fs::write(root.path().join("book/source.txt"), "plain\n").unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
assert!(
dispatch(
&sources,
"habeas",
&json!({"file":"book/source.txt","line_start":1})
)
.is_ok()
);
}
Other sources
Input 1: requirements selection requirements.authoring.read_denial.build_output
requirements.authoring.read_denial.build_output:md/requirements/authoring.md:717–723
:::{req} read_denial.build_output
A tool error for a path inside the book's build directory, `book` unless
`book.toml` sets `[build] build-dir`, or inside the project-root `target`
directory, that no workspace allow rule or generated-output rule permits MUST say
that the path holds build output and that the sources it is built from are
elsewhere in the project.
:::