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.cli.distributed_guidance.when

Requirements index · View definition

evidence Valid

Requirement

The bundled skills MUST direct agents to make a requirement distributed only when its obligation applies on its own at each of many sites, such as a convention every validation function follows; to use {impl} instead when particular code carries out the requirement as a whole; and to mark with {impl} the code that carries out any obligation of a distributed requirement that its sites do not uphold.

Rationale

The requirement has three directive clauses for the bundled skills. Skills are text assets, so a test adequately checks them by asserting that the guidance is present in the right place. The single test tests/authoring_cli.rs#fn[bundled_skills_make_a_requirement_distributed_only_for_per_site_obligations] does that.

It takes the ## Do section of the habeas skill’s distributed-requirements reference. It gets that through distributed_reference() and section(...), which cuts the section out and collapses its whitespace. It then uses assert_text, which panics if a phrase is missing. It asserts two sentences:

  1. “Make a requirement distributed only when its obligation applies on its own at each site; when particular code carries out the requirement as a whole, use {impl} there.” This covers clause 1 (distribute only for per-site obligations) and clause 2 (use {impl} instead when particular code carries out the requirement as a whole).
  2. “Separate obligations each site upholds from obligations particular code carries out, and mark that code {impl}.” This covers clause 3 (mark with {impl} the code that carries out obligations the sites do not uphold).

I read assets/skills/habeas/references/distributed-requirements.md. Both bullets are in its Do section, and the intro there gives the “many sites, such as a convention every validation function follows” framing. That is the implementation named by the :impl: anchor in md/requirements/cli.md. The test fails if either directive is removed or weakened, because every phrase must be present in that section.

Two minor points do not amount to gaps:

  • The “many sites” and “convention every validation function follows” wording sits in the intro, which this test does not assert. Both are illustrative (“such as”) context, and the operative directive is the Do bullet that the test does check.
  • The test covers only the habeas skill’s reference. The implementation anchor and my search found the guidance only in that reference, so no other skill carries these directives.

No fixme acknowledgments apply, and none are needed.

Inputs

Implementation

Input 3: outline assets/skills/habeas/references/distributed-requirements.md section[Distributed%20requirements]
# Distributed requirements

Some obligations apply on their own at each of many sites, such as a convention
every validation function follows. Marking every site `{impl}` spreads the
requirement across the codebase and asks one review to judge them all. A
distributed requirement instead declares queries that find its sites, and
Habeas reviews each site separately.

## Queries

A requirement becomes distributed by containing query directives, each with one
fenced `yaml` block and a name unique within the requirement:

- `:::{sites} <name>` selects the places the obligation applies.
- `:::{violations} <name>` selects constructs likely to break it, such as `?`,
  `return`, `continue`, or `break` in a function that must keep going after a
  failed check. Each needs `within: <site query>`, naming a site query of the same
  requirement; only matches inside that query's sites count. Violation queries
  point site reviews at likely problems; each site's review still judges the
  whole site, and a violation query that misses a construct does not by itself
  make the requirement false.

Query directives belong inside a requirement. Each name is a single identifier
(ASCII letters, digits, underscores, or hyphens), unique across both query kinds in
that requirement. Validation reports missing or extra YAML blocks, invalid YAML,
unknown query keys, unsupported languages, and rules that cannot compile. A
violation query naming a nonexistent site query in `within` is also invalid;
`within` belongs only to violation queries.
Validation also rejects empty `match` or `no_match` lists, snippets that fail to
parse or have the wrong match result, and violation queries without a site query.

Each body has these keys: `language` (`rust`, `python`, `typescript`, `tsx`,
`css`, `markdown`, `toml`, or `yaml`); optional `paths` and `exclude`, lists of
project-relative files or directories; an ast-grep `rule`, with optional `utils`
and `constraints`; `within`, required for violation queries; and `match` and
`no_match` snippet lists. Give the requirement a longer outer fence:

````text
::::{req} errors
A validation function that collects validation errors MUST hold them in a
parameter or local variable named `errors`, and a function with such a variable
is a site. After one of its checks fails, a site MUST still run every later check
that does not depend on the failed check's result.

:::{sites} error_accumulators
```yaml
language: rust
paths: [src]
rule:
  kind: function_item
  has:
    stopBy: { kind: function_item }
    any:
      - kind: parameter
        has: { field: pattern, regex: "^errors$" }
      - kind: let_declaration
        has: { field: pattern, regex: "^errors$" }
match:
  - "fn check(value: &str, errors: &mut Vec<String>) {}"
  - |
    fn run() {
        let mut errors = Vec::new();
        check("", &mut errors);
    }
no_match:
  - "fn check(value: &str, problems: &mut Vec<String>) {}"
  - |
    fn run() {
        let mut problems = Vec::new();
        check("", &mut problems);
    }
```
:::

:::{violations} early_exits
```yaml
language: rust
paths: [src]
within: error_accumulators
rule:
  any:
    - kind: try_expression
    - kind: return_expression
match:
  - |
    fn check(v: &Value, errors: &mut Vec<String>) -> Option<u8> {
        let n = v.as_u64()?;
        if v.is_null() { errors.push("null".into()); }
        Some(n as u8)
    }
  - |
    fn check(v: &Value, errors: &mut Vec<String>) {
        if !v.is_object() { errors.push("object".into()); return; }
        if v.is_null() { errors.push("null".into()); }
    }
no_match:
  - |
    fn parse(v: &Value) -> Option<u8> {
        let n = v.as_u64()?;
        Some(n as u8)
    }
  - |
    fn check(v: &Value, errors: &mut Vec<String>) {
        if v.is_null() { errors.push("null".into()); }
    }
```
:::
::::
````

Each site-query match makes a site: the innermost outline node containing the
match, such as the enclosing function. A violation match is reported to the site
that contains it.

## Do

- Make a requirement distributed only when its obligation applies on its own at
  each site; when particular code carries out the requirement as a whole, use
  `{impl}` there.
- Describe sites exactly as the site queries select them. When a query relies on
  a convention, such as how a variable is named, state the convention as an
  obligation, so code that breaks it is a real gap you fix in the code.
- Separate obligations each site upholds from obligations particular code
  carries out, and mark that code `{impl}`.
- State the requirement's scope in its text, and use `paths` and `exclude` for
  scope a rule cannot see, such as authoring code outside validation.
- Give every query `match` and `no_match` snippets that test its conditions the
  way you would test code: `match` snippets for what it selects, and `no_match`
  snippets for nearby code it must not select, such as the right type with the
  wrong name. A condition needs no snippet of its own. This applies to violation
  queries too.
- Write a violation query, with `within` naming the site query, for every kind
  of construct that could break the obligation, such as each early exit in a
  function that must keep going.
- Before the habeas-requirements review (its step 3), check that the site
  queries select every place the obligation
  applies and no others: think about places they could miss, such as a list
  held in a local variable or under another name, and places they select that
  the obligation does not cover. Widen or narrow the query, or state the
  convention as an obligation so a miss becomes a code gap. The requirement's
  review searches for both.
- Present the queries and snippets with the requirement text when reviewing it
  with the user.
- Check with `habeas info <full-name>` that the sites are the ones you expect.
- Let `habeas author --all` author the site reviews.

## Don't

- Don't describe sites more broadly than the queries select, as in "however it is
  named".
- Don't state a per-site obligation that a reviewer cannot check from the site
  and the helpers it calls, such as "not reported by another check", which needs
  reading other sites; narrow it to the site, such as "does not report one
  failure twice".
- Don't reference the distributed requirement from a site just because it is a
  site; sites need none. A site review reads its site, which covers it for Rust
  item coverage, but a site that is a root of another requirement gets
  `{impl}` of that one, and a site that carries out one of this requirement's
  other obligations, such as the function that reports the collected errors,
  gets `{impl}` of this one like any other root.
- Don't re-run a false site review for a different result; fix the site, or
  tighten the queries or the text, as the habeas-evidence skill's
  `references/reviews.md` describes.

## Gotchas

- Patterns parse as standalone code, so a type or parameter fragment needs
  ast-grep's `context` and `selector` form, such as
  `{ context: "fn f(x: &mut Vec<String>) {}", selector: reference_type }`. A plain
  pattern that parses differently silently matches nothing; the snippets catch
  this.
- Each snippet parses as a whole file, so a Rust snippet must be complete items,
  not a bare expression.
- `habeas coverage` runs every snippet and reports a wrong result, and a
  site query that matches nothing in the project.

## Review

`habeas author --all` authors a site review for each site, judging the per-site
obligations and each violation match in it. The requirement's own review checks
the Do list above.

Tests

Input 2: outline tests/authoring_cli.rs fn[bundled_skills_make_a_requirement_distributed_only_for_per_site_obligations]
// {test}`requirements.cli.distributed_guidance.when`
#[test]
fn bundled_skills_make_a_requirement_distributed_only_for_per_site_obligations() {
    assert_text(
        "Do list",
        &section(distributed_reference(), "## Do"),
        &[
            "Make a requirement distributed only when its obligation applies on its own at each site; when particular code carries out the requirement as a whole, use `{impl}` there.",
            "Separate obligations each site upholds from obligations particular code carries out, and mark that code `{impl}`.",
        ],
    );
}

Other sources

Input 1: requirements selection requirements.cli.distributed_guidance.when
:::{req} distributed_guidance.when
The bundled skills MUST direct agents to make a requirement distributed only when its obligation applies on its own at each of many sites, such as a convention every validation function follows; to use `{impl}` instead when particular code carries out the requirement as a whole; and to mark with `{impl}` the code that carries out any obligation of a distributed requirement that its sites do not uphold.
:::