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.definitions.selection

Requirements index · View definition

evidence Valid

Requirement

A definition selection in a requirements input MUST continue to select requirements and named examples, excluding named definitions. Definitions referenced by selected texts MUST be captured as separate definition inputs, regardless of whether their names match the selection. Sharing a selection’s matching name prefix alone MUST NOT make a definition a dependency.

Rationale

The tests cover each obligation in requirements.definitions.selection. I did not request implementation or helper source. The judgment rests on the supplied test text.

Obligations derived from the text

  1. A definition selection MUST select requirements and named examples, and MUST exclude named definitions.
  2. Definitions referenced by selected texts MUST be captured as separate definition inputs, even when their names don’t match the selection.
  3. A shared name prefix alone MUST NOT make a definition a dependency.

Coverage

  • Obligation 1, glob case: tests/definitions.rs#fn[selections_match_requirements_and_examples_but_never_named_definitions] writes a requirement rules.ready, an example rules.case and a definition rules.used.
    • It records the selection rules.* as matching only rules.case and rules.ready, and asserts that validation raises no evidence/rules.ready.json error.
    • So the glob selects both the requirement and the example and leaves out the definition.
  • Obligation 1, exact-name case: the same test records the exact name rules.used. It asserts the error “matches no requirement or example”, so a named definition’s exact name selects nothing.
  • Obligation 1, CLI paths: the same test runs status rules.* and info rules.* through the CLI. Both outputs contain rules.ready and rules.case but not rules.used, and info rules.used fails.
  • Obligation 1, tool path: src/authoring/tools.rs#mod[tests]/fn[requirements_reads_select_requirements_and_examples_but_not_definitions] reads requirements.* through the habeas tool. It asserts that matches are exactly the example and the requirement and that definitions is empty. It also asserts that the exact name of the unused definition produces a “matches no requirement or example” error.
  • Obligation 2, referenced definition outside the glob: tests/definitions.rs#fn[globs_exclude_terms_but_capture_referenced_terms_outside_the_glob] references glossary.a, which the glob rules.* does not match. Omitting it produces an error containing “glossary.a, found 0”. So it is required as a separate input.
  • Obligation 2, referenced definition matching the glob: the same test references rules.used, which the glob does match. Omitting it produces “rules.used, found 0”, so it is required regardless of the match.
  • Obligation 3: in the same test, rules.unrelated shares the rules. prefix but is not referenced. The complete input set validates with no errors, and no error ever mentions rules.unrelated.
  • Stale selection: a recorded selection whose matches include the named definition rules.used triggers an evidence/rules.ready.json error. This rejects selections that include definitions.

Together these exercise the positive, negative and boundary cases the text names, and the assertions check the outcomes. I found no gap.

Inputs

Tests

Input 2: outline src/authoring/tools.rs mod[tests]/fn[requirements_reads_select_requirements_and_examples_but_not_definitions]
  • File: src/authoring/tools.rs
  • Selector: mod[tests]/fn[requirements_reads_select_requirements_and_examples_but_not_definitions]
  • Kind: fn
  • src/authoring/tools.rs:1651–1694
    // {test}`requirements.definitions.selection`
    // {test}`requirements.references.definition_globs`
    // {test}`requirements.authoring.source_tools`
    #[test]
    fn requirements_reads_select_requirements_and_examples_but_not_definitions() {
        let root = project();
        fs::write(
            root.path().join("md/requirements.md"),
            format!(
                ":::{{req}} ready\nThe project MUST be ready.\n:::\n\n\
                 :::{{example}} case\nA ready case. {}\n:::\n\n\
                 :::{{definition}} unused\n:phrase: unused\n\nNot referenced.\n:::\n",
                role("cite", "requirements.ready")
            ),
        )
        .unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let delivery = dispatch(
            &sources,
            "habeas",
            &json!({"requirements": "requirements.*"}),
        )
        .unwrap();
        assert_eq!(
            delivery.result["input"]["matches"],
            json!(["requirements.case", "requirements.ready"]),
            "{}",
            delivery.result
        );
        assert_eq!(delivery.result["definitions"], json!([]));
        let error = dispatch(
            &sources,
            "habeas",
            &json!({"requirements": "requirements.unused"}),
        )
        .err()
        .unwrap();
        assert!(
            error
                .to_string()
                .contains("matches no requirement or example"),
            "{error}"
        );
    }
Input 3: outline tests/definitions.rs fn[globs_exclude_terms_but_capture_referenced_terms_outside_the_glob]
// {test}`requirements.definitions.selection`
// {test}`requirements.definitions.glob_dependency`
#[test]
fn globs_exclude_terms_but_capture_referenced_terms_outside_the_glob() {
    let temp = fixture();
    // `rules.used` matches the glob and is referenced; `rules.unrelated`
    // matches the glob and shares its prefix but is not referenced.
    fs::write(
        temp.path().join("md/rules.md"),
        ":::{req} ready\nUse {term}`glossary.a` and {term}`rules.used`.\n:::\n\n:::{definition} used\n:phrase: used\n\nReferenced.\n:::\n\n:::{definition} unrelated\n:phrase: unrelated\n\nNot referenced.\n:::\n",
    )
    .unwrap();
    let root = temp.path();
    let selection = requirements(root, "rules.*", &["rules.ready"]);
    let path = record(
        root,
        "rules.ready",
        vec![
            selection.clone(),
            definition(root, "glossary.a"),
            definition(root, "glossary.b"),
            definition(root, "rules.used"),
        ],
    );
    approve(&path);
    // The glob selects only the requirement, and exactly the referenced
    // definitions are required as separate inputs.
    let errors = validate_repository(root).unwrap().errors;
    assert!(errors.is_empty(), "{errors:?}");

    // The referenced definition is required although the glob does not
    // select it; the unreferenced one is never required.
    record(
        root,
        "rules.ready",
        vec![
            selection,
            definition(root, "glossary.a"),
            definition(root, "glossary.b"),
        ],
    );
    approve(&path);
    let errors = validate_repository(root).unwrap().errors;
    assert!(
        errors
            .iter()
            .any(|error| error.contains("rules.used, found 0")),
        "{errors:?}"
    );
    assert!(
        errors
            .iter()
            .all(|error| !error.contains("rules.unrelated")),
        "{errors:?}"
    );

    // A directly referenced definition outside the glob is also mandatory.
    record(
        root,
        "rules.ready",
        vec![
            requirements(root, "rules.*", &["rules.ready"]),
            definition(root, "glossary.b"),
            definition(root, "rules.used"),
        ],
    );
    approve(&path);
    let errors = validate_repository(root).unwrap().errors;
    assert!(
        errors
            .iter()
            .any(|error| error.contains("glossary.a, found 0")),
        "{errors:?}"
    );

    // A selection whose recorded matches include named definitions is stale.
    let definitions = requirements(root, "rules.*", &["rules.ready", "rules.used"]);
    record(
        root,
        "rules.ready",
        vec![
            definitions,
            definition(root, "glossary.a"),
            definition(root, "glossary.b"),
            definition(root, "rules.used"),
        ],
    );
    approve(&path);
    let errors = validate_repository(root).unwrap().errors;
    assert!(
        errors
            .iter()
            .any(|error| error.starts_with("evidence/rules.ready.json")),
        "{errors:?}"
    );
}
Input 4: outline tests/definitions.rs fn[selections_match_requirements_and_examples_but_never_named_definitions]
  • File: tests/definitions.rs
  • Selector: fn[selections_match_requirements_and_examples_but_never_named_definitions]
  • Kind: fn
  • tests/definitions.rs:349–417
// {test}`requirements.definitions.selection`
// {test}`requirements.references.definition_globs`
#[test]
fn selections_match_requirements_and_examples_but_never_named_definitions() {
    let temp = fixture();
    let root = temp.path();
    fs::write(
        root.join("md/rules.md"),
        ":::{req} ready\nUse {term}`glossary.a`.\n:::\n\n\
         :::{example} case\nA ready case. {cite}`rules.ready`\n:::\n\n\
         :::{definition} used\n:phrase: used\n\nNot referenced by the selection.\n:::\n",
    )
    .unwrap();
    // The glob selects the requirement and the example, not the definition
    // whose name it also matches, and that definition is not a dependency.
    let selected = vec![
        requirements(root, "rules.*", &["rules.case", "rules.ready"]),
        definition(root, "glossary.a"),
        definition(root, "glossary.b"),
    ];
    let path = record(root, "rules.ready", selected.clone());
    approve(&path);
    let errors = validate_repository(root).unwrap().errors;
    assert!(
        errors
            .iter()
            .all(|error| !error.starts_with("evidence/rules.ready.json")),
        "{errors:?}"
    );

    // A named definition's exact name selects nothing.
    let exact = requirements(root, "rules.used", &["rules.used"]);
    record(
        root,
        "rules.ready",
        vec![
            exact,
            definition(root, "glossary.a"),
            definition(root, "glossary.b"),
        ],
    );
    let errors = validate_repository(root).unwrap().errors;
    assert!(
        errors
            .iter()
            .any(|error| error.contains("matches no requirement or example")),
        "{errors:?}"
    );
    record(root, "rules.ready", selected);

    // The CLI selection paths apply the same rule.
    for args in [["status", "rules.*"], ["info", "rules.*"]] {
        let output = std::process::Command::new(env!("CARGO_BIN_EXE_habeas"))
            .current_dir(root)
            .args(args)
            .output()
            .unwrap();
        let stdout = String::from_utf8_lossy(&output.stdout);
        assert!(stdout.contains("rules.ready"), "{args:?}: {stdout}");
        assert!(stdout.contains("rules.case"), "{args:?}: {stdout}");
        assert!(!stdout.contains("rules.used"), "{args:?}: {stdout}");
    }
    let output = std::process::Command::new(env!("CARGO_BIN_EXE_habeas"))
        .current_dir(root)
        .args(["info", "rules.used"])
        .output()
        .unwrap();
    assert!(!output.status.success(), "{output:?}");
}

Referenced definitions

Input 5: definition requirements.references.definition_selection
:::{definition} definition_selection
:phrase: definition selection

A full requirement or example name, or a definition glob, identifying the
requirements and named examples it matches under
{cite}`requirements.references.definition_globs`. A name without `*` selects
exactly that definition.
:::

Other sources

Input 1: requirements selection requirements.definitions.selection
:::{req} selection
A {term}`requirements.references.definition_selection` in a requirements input MUST continue to select requirements and named examples, excluding named definitions. Definitions referenced by selected texts MUST be captured as separate definition inputs, regardless of whether their names match the selection. Sharing a selection's matching name prefix alone MUST NOT make a definition a dependency.
:::