Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

requirements.authoring.not_listed

Requirements index · View definition

evidence Valid

Requirement

A list_files, ripgrep, or ast_grep result MUST include not_listed, an array of {path, reason} with reason untracked, naming each untracked file inside the project that the listing would otherwise include or that contains a match, so the model can tell that sources exist which it cannot read. It MUST be omitted when there are none, and for a paged result it MUST appear on the first page, continuing across subsequent pages when needed to obey the page size limit. Page counts MUST include these entries as well as the ordinary result entries, and each array MUST retain its order. It MUST NOT give those files’ contents, and they MUST NOT become evidence inputs. Files excluded for another reason, such as a workspace disallow rule or generated evidence/ output, MUST NOT be read to find matches and MUST NOT be listed.

Rationale

I judged this from the three supplied tests only, and I didn’t request any implementation source. Together they cover each obligation in requirements.authoring.not_listed.

Content and format

  • src/authoring/tools.rs#mod[tests]/fn[listings_and_searches_name_untracked_files_without_their_contents] runs list_files, ripgrep and ast_grep on a repo with untracked files.
  • It asserts not_listed names exactly the expected paths: ["drafts","untracked.rs"] for list_files, ["drafts/plan.txt","untracked.rs"] for ripgrep, and ["untracked.rs"] for ast_grep.
  • For ast_grep, the untracked drafts/plan.txt is not a Rust file and secret.rs is disallowed, so naming only untracked.rs shows that only files that actually match are listed.
  • Every entry has reason == "untracked", and the test asserts the entries carry no tag.
  • Result order is checked, because the expected arrays are sorted lists compared with assert_eq!.

No contents, no evidence

  • The same test asserts the serialized result does not contain the untracked file text, either “fn needle” or “a needle here”.
  • It asserts inputs is empty for every tool.
  • The paging test also asserts page.inputs.is_empty() on every page.

Omission when there are none

  • A ripgrep query with no untracked matches has no not_listed key.
  • A list_files call on src, which has no untracked files at that point, also has no not_listed key.

Scope: “inside the project … would otherwise include”

  • Untracked files outside the listed or searched path are not named. This is shown by the list_files on src, which does not name untracked.rs or drafts.
  • After src/draft.rs is added, the path forms ./src, src/../src and an absolute path each name only src/draft.rs, for all three tools.

Exclusions

  • A disallowed secret.rs (which contains the match) and evidence/note.txt are never named, in list_files, ripgrep or ast_grep. The exact-equality assertions on the named lists enforce this.
  • Whether the excluded files are actually read is not directly observable. A match in them that stayed hidden is the observable consequence, and it is asserted.

Paging

  • src/authoring/pages.rs#mod[tests]/fn[not_listed_comes_on_the_first_page_within_the_page_limit] uses 800 tracked files and 40 untracked ones through list_files.
  • It asserts the first page has all 40 not_listed entries, every page serializes within PAGE_LIMIT, and later pages have no not_listed.
  • src/authoring/pages.rs#mod[tests]/fn[untracked_entries_page_without_tracked_entries_or_oversized_overhead] uses 1000 untracked entries with 0, 1 and 500 tracked entries, so not_listed must continue across pages.
  • It asserts the first page has a non-empty not_listed, and every page is within PAGE_LIMIT and has no evidence inputs.
  • It asserts total_entries equals tracked plus untracked, and returned_entries equals entries plus not_listed on each page.
  • The concatenated tracked and untracked arrays equal the originals in order.

I found no unmet obligation or missing boundary case that the text names.

Inputs

Tests

Input 2: outline src/authoring/pages.rs mod[tests]/fn[not_listed_comes_on_the_first_page_within_the_page_limit]
    // {test}`requirements.authoring.result_pages`
    // {test}`requirements.authoring.not_listed`
    #[test]
    fn not_listed_comes_on_the_first_page_within_the_page_limit() {
        let root = project();
        for index in 0..800 {
            fs::write(
                root.path()
                    .join(format!("src/file_with_a_rather_long_name_{index:04}.rs")),
                "fn f() {}\n",
            )
            .unwrap();
        }
        let git = |args: &[&str]| {
            let output = std::process::Command::new("git")
                .current_dir(root.path())
                .args(args)
                .output()
                .unwrap();
            assert!(output.status.success(), "{output:?}");
        };
        git(&["init", "--quiet"]);
        git(&["add", "."]);
        for index in 0..40 {
            fs::write(
                root.path().join(format!(
                    "src/untracked_draft_with_a_long_name_{index:02}.rs"
                )),
                "fn f() {}\n",
            )
            .unwrap();
        }
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let mut pages = ResultPages::default();
        let first =
            dispatch_paged(&sources, &mut pages, "list_files", &json!({"path":"src"})).unwrap();
        let delivered = all_pages(&mut pages, first);
        assert_eq!(
            delivered[0].result["not_listed"].as_array().unwrap().len(),
            40,
            "{}",
            delivered[0].result
        );
        for (number, page) in delivered.iter().enumerate() {
            assert!(page.result.to_string().len() <= PAGE_LIMIT, "page {number}");
            if number > 0 {
                assert!(page.result.get("not_listed").is_none(), "page {number}");
            }
        }
    }
Input 3: outline src/authoring/pages.rs mod[tests]/fn[untracked_entries_page_without_tracked_entries_or_oversized_overhead]
  • File: src/authoring/pages.rs
  • Selector: mod[tests]/fn[untracked_entries_page_without_tracked_entries_or_oversized_overhead]
  • Kind: fn
  • src/authoring/pages.rs:564–616
    // {test}`requirements.authoring.result_pages`
    // {test}`requirements.authoring.not_listed`
    #[test]
    fn untracked_entries_page_without_tracked_entries_or_oversized_overhead() {
        let root = project();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let untracked: Vec<Value> = (0..1000)
            .map(|i| json!({"path":format!("src/{i:04}_{}.rs", "x".repeat(70)), "reason":"untracked"}))
            .collect();
        for count in [0, 1, 500] {
            let tracked: Vec<Value> = (0..count)
                .map(|i| json!({"path":format!("src/tracked_{i:04}.rs"),"kind":"file"}))
                .collect();
            let mut pages = ResultPages::default();
            let first = pages
                .deliver(
                    &sources,
                    Listing::array(tracked.clone()).with_not_listed(untracked.clone()),
                )
                .unwrap();
            assert!(
                first.result["not_listed"]
                    .as_array()
                    .is_some_and(|v| !v.is_empty())
            );
            let delivered = all_pages(&mut pages, first);
            let mut actual_tracked = Vec::new();
            let mut actual_untracked = Vec::new();
            for page in delivered {
                assert!(page.result.to_string().len() <= PAGE_LIMIT);
                assert!(page.inputs.is_empty(), "untracked paths are never evidence");
                let entries = page.result["entries"].as_array().unwrap();
                let omitted = page
                    .result
                    .get("not_listed")
                    .and_then(Value::as_array)
                    .cloned()
                    .unwrap_or_default();
                assert_eq!(
                    page.result["page"]["total_entries"],
                    count + untracked.len()
                );
                assert_eq!(
                    page.result["page"]["returned_entries"],
                    entries.len() + omitted.len()
                );
                actual_tracked.extend(entries.iter().cloned());
                actual_untracked.extend(omitted);
            }
            assert_eq!(actual_tracked, tracked);
            assert_eq!(actual_untracked, untracked);
        }
    }
Input 4: outline src/authoring/tools.rs mod[tests]/fn[listings_and_searches_name_untracked_files_without_their_contents]
    // {test}`requirements.authoring.not_listed`
    // {test}`requirements.authoring.search_accounting.entry_tags`
    #[test]
    // {test}`requirements.authoring.read_denial`
    fn listings_and_searches_name_untracked_files_without_their_contents() {
        let root = project();
        fs::write(root.path().join("src/lib.rs"), "fn tracked() {}\n").unwrap();
        fs::write(
            root.path().join("habeas.toml"),
            "version = 1\n[evidence]\ndisallow = ['secret.rs']\n",
        )
        .unwrap();
        git(root.path(), &["init", "--quiet"]);
        git(root.path(), &["add", "."]);
        fs::write(root.path().join("untracked.rs"), "fn needle() {}\n").unwrap();
        fs::create_dir(root.path().join("drafts")).unwrap();
        fs::write(root.path().join("drafts/plan.txt"), "a needle here\n").unwrap();
        fs::write(root.path().join("secret.rs"), "fn needle() {}\n").unwrap();
        fs::create_dir_all(root.path().join("evidence")).unwrap();
        fs::write(root.path().join("evidence/note.txt"), "needle\n").unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let named = |result: &Value| {
            result["not_listed"]
                .as_array()
                .map(|entries| {
                    entries
                        .iter()
                        .map(|entry| {
                            assert_eq!(entry["reason"], "untracked");
                            assert!(entry.get("tag").is_none());
                            entry["path"].as_str().unwrap().to_owned()
                        })
                        .collect::<Vec<_>>()
                })
                .unwrap_or_default()
        };
        let listing = dispatch(&sources, "list_files", &json!({})).unwrap();
        assert_eq!(named(&listing.result), ["drafts", "untracked.rs"]);
        assert!(
            listing.result["entries"]
                .as_array()
                .unwrap()
                .iter()
                .any(|entry| entry["path"] == "src")
        );
        let search = dispatch(&sources, "ripgrep", &json!({"pattern": "needle"})).unwrap();
        assert_eq!(named(&search.result), ["drafts/plan.txt", "untracked.rs"]);
        let text = search.result.to_string();
        assert!(
            !text.contains("a needle here") && !text.contains("fn needle"),
            "{text}"
        );
        assert!(search.inputs.is_empty());
        let rust = dispatch(
            &sources,
            "ast_grep",
            &json!({"language": "rust", "rule": {"rule": {"pattern": "fn needle() {}"}}}),
        )
        .unwrap();
        assert_eq!(named(&rust.result), ["untracked.rs"]);
        for delivery in [&listing, &rust] {
            assert!(delivery.inputs.is_empty());
            let text = delivery.result.to_string();
            assert!(
                !text.contains("fn needle") && !text.contains("a needle here"),
                "{text}"
            );
        }

        // Nothing untracked matches: no not_listed.
        let none = dispatch(&sources, "ripgrep", &json!({"pattern": "tracked\\(\\)"})).unwrap();
        assert!(none.result.get("not_listed").is_none(), "{}", none.result);
        let inside = dispatch(&sources, "list_files", &json!({"path": "src"})).unwrap();
        assert!(
            inside.result.get("not_listed").is_none(),
            "{}",
            inside.result
        );
        fs::write(root.path().join("src/draft.rs"), "fn needle() {}\n").unwrap();
        for path in [
            "./src".to_owned(),
            "src/../src".to_owned(),
            root.path().join("src").to_string_lossy().into_owned(),
        ] {
            for (tool, arguments) in [
                ("list_files", json!({"path":path})),
                ("ripgrep", json!({"path":path,"pattern":"needle"})),
                (
                    "ast_grep",
                    json!({"path":path,"language":"rust","rule":{"rule":{"pattern":"fn needle() {}"}}}),
                ),
            ] {
                let delivery = dispatch(&sources, tool, &arguments).unwrap();
                assert_eq!(named(&delivery.result), ["src/draft.rs"], "{tool}: {path}");
                assert!(delivery.inputs.is_empty());
            }
        }
    }

Other sources

Input 1: requirements selection requirements.authoring.not_listed
:::{req} not_listed
A `list_files`, `ripgrep`, or `ast_grep` result MUST include `not_listed`, an
array of `{path, reason}` with reason `untracked`, naming each untracked file
inside the project that the listing would otherwise include or that contains a
match, so the model can tell that sources exist which it cannot read. It MUST
be omitted when there are none, and for a paged result it MUST appear on the
first page, continuing across subsequent pages when needed to obey the page
size limit. Page counts MUST include these entries as well as the ordinary
result entries, and each array MUST retain its order. It MUST NOT give those
files' contents, and they MUST NOT become
evidence inputs. Files excluded for another reason, such as a workspace disallow
rule or generated `evidence/` output, MUST NOT be read to find matches and MUST
NOT be listed.
:::