Skip to content

Report markup validation findings as records - #2686

Merged
max-sixty merged 1 commit into
mainfrom
markup-findings-records
Oct 12, 2026
Merged

max-sixty merged 1 commit into
mainfrom
markup-findings-records

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

The markup checks behind page check now report findings as records, as #2662 made the render gate do. Each check produces a Finding where it detects the problem. The record carries a stable code, the element it concerns as at, and the line and the offending and expected values in values. A new samples field names the live-sample document it was read in. The words for every code are written once, in the code table in findings.py. page check --json now carries these fields. Before, it wrapped each markup error as a markup record whose only value was the text.

What changed

  • One record type, in one place. findings.py moves from render_gate/ to leaf/, because validation, structure, styles and data_contracts now report through it too. Its code table gains the markup codes, about 75 of them, such as unknown-widget, attribute-schema, not-member, allocation-value, duplicate-ids, unpointable, contract-conflict and css-syntax.
  • Producers return records. These modules return records in place of list[str]: validation/markup.py, validation/instances.py, validation/source.py, validation/source_history.py, validation/admission.py, the parser's own errors in structure.py, styles.css_syntax_errors, and the binding conflicts and measurement lag in data_contracts.py. SourceCheck.errors and .advice are list[Finding]. Callers that join them into a refusal (page stamp, activation, a reply while the source is invalid, data writes) print str(finding).
  • Records are facts, not prose. An attribute schema failure carries the JSON Schema keyword and path. The text of a question context that asks nothing is now built from data: each framed widget and the x-awaits conditions it lacks (instances.unasked). A reference that breaks a relation carries the relation, its predicate and what the target declares. A sample's errors carry the template ids in samples instead of a sample 'x': prefix on the sentence.
  • Message markup refusals keep their records. check_markup and read_text_arg raise findings.Rejected, a Refused that holds findings. message_markup_errors, formerly message_markup_error, returns the first failing stage's findings.

Wording changes

Two wordings were inconsistent with the rest, and now match them:

  • An element named by its id reads <lf-suggestion id=sg>, the form the render findings use. Suggestion, question-context, measurement-lag and owned-twice findings used to write id='sg' or id="sg".
  • Every message markup refusal opens <kind> markup doesn't validate: and lists its findings. Duplicate ids, taken ids and a looping sample used to read <kind> markup: … on one line. Their findings read the same as before.

Human output: before and after

leaf page check printed byte-identical stdout, stderr and exit status at the merge base and on this branch for five shipped examples copied into fresh pages: triage-board, release-notes (missing media), alert-review, heat-loss and review-a-plan.

I ran it on two fixtures with known errors. The first has 44 errors across most of the codes. The second covers allocations, question contexts, unclosed tags and errors inside nested samples. The only differences are the id spellings above:

<   - <lf-suggestion id='sg'> (line 36): needs a <lf-old> (what it replaces), a <lf-new> (what it proposes), or both
>   - <lf-suggestion id=sg> (line 36): needs a <lf-old> (what it replaces), a <lf-new> (what it proposes), or both
<   - <lf-ask> (line 12): a Question context registers no Question: <lf-options id="o9"> (line 12) asks only where choose is present
>   - <lf-ask> (line 12): a Question context registers no Question: <lf-options id=o9> (line 12) asks only where choose is present

On a set of bad reply fragments, check_markup's refusals were identical, except for the duplicate-id refusal, which now has the shared heading:

< reply markup: duplicate ids (anchors need unique targets): ["dup"]
> reply markup doesn't validate:
>   - duplicate ids (anchors need unique targets): ["dup"]

page check --json for one finding, before and after:

{"code":"markup","severity":"error","values":{"text":"<div data-width=\"huge\"> (line 10) has an invalid value; expected one of wide, available"},"text":"…"}
{"code":"allocation-value","severity":"error","at":"<div>","values":{"line":10,"attr":"data-width","value":"huge","allowed":["wide","available"]},"text":"<div data-width=\"huge\"> (line 10) has an invalid value; expected one of wide, available"}
{"code":"unknown-widget","severity":"error","at":"<lf-bogus>","samples":["kid"],"values":{"line":16},"text":"sample 'kid': <lf-bogus> (line 16): unknown widget — not in the vendored registry.json"}

Tests

  • Tests that read producers directly now assert on codes and fields: fragment_errors, reference_errors, check_markup's refusal, and declared_data_bindings. They use two new interact_support helpers: check_findings, which runs page check --json in-process, and found, which selects findings by code, element and values.
  • I ran these model files: test_interact_product, test_interact_contract, test_interact_document, test_interact_anchors, test_interact_layer, test_render_gate, test_responses, test_receipts, test_wait, test_stop_guard, test_questions and test_delivery. I also ran the sample, markup, check and stamp tests in process/test_interact_server.py, and the touched journeys nodes.

Left for follow-ups

  • Tests that match page check text. About 200 check() calls still match the CLI's words. Their words did not change, so they pass. Cutting them over to check_findings comes next, by area.
  • Registry contract errors. RegistryError is raised from about 100 sites in registry/ and reaches page check as one invalid-registry finding whose value is the error's text. ArtifactError reaches it as capture-failed, and a sample's history as sample-history. Those exceptions are a separate producer family.
  • Event admission refusals. EventRefused is matched by text with pytest.raises(match=…) across the suite. It is larger than this change.

This was written by Claude Code on behalf of max-sixty

Every check behind `page check`'s markup half now produces a `Finding` record
where it detects the problem: a stable code, the element it concerns (`at`, with
the line in `values`), the offending and expected values, and the live sample
whose document it was read in (`samples`). The words are written once, in
`findings.py`'s code table, which moves from `render_gate/` to `leaf/` since
validation, structure, styles and data contracts all report through it now.
`page check --json` carries the real fields where it carried `markup` records
whose only value was the text.

Message markup refusals raise `Rejected`, a `Refused` that keeps its findings,
so a caller reads the records rather than the sentence.

User-visible changes, all wording:
- an element named by id reads `<lf-suggestion id=sg>`, as the render findings
  write it, where suggestion, question-context, measurement-lag and owned-twice
  findings wrote `id='sg'` or `id="sg"`;
- every message markup refusal opens "<kind> markup doesn't validate:" and lists
  its findings, where duplicate ids, taken ids and a looping sample read
  "<kind> markup: …" on one line.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 09d202c into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the markup-findings-records branch October 12, 2026 23:03
max-sixty added a commit that referenced this pull request Oct 12, 2026
#2686 made the markup checks report records. This PR switches the tests
that matched `page check`'s words for those findings to read the
records. `interact_support.check_findings` runs `page check --json` in
process and returns the exit status and the findings. `found` selects
them by code, by element, and by values.

The assertions now pin facts that the words only suggested:

- the reserved markers each element wears, which replaces a count of a
phrase and a hand-written negative check for `(note)`;
- the line and body of each split pane;
- the template ids a sample child's error was read in;
- the allowed values for an allocation;
- the layer's known words for an unknown tone;
- exactly which threads activation would move.

That last one now includes the reaction mark that follows its subject.
The text assertion it replaced never excluded it.

Some assertions still match words, because what they read is not a
record yet:

- a registry contract's `RegistryError` (the `invalid-registry`
finding's `error`);
- capture's `ArtifactError` (`capture-failed`);
- a sample history's event refusal (`sample-history`);
- a page that was never initialized, which `page check` refuses before
it checks anything;
- refusals at the `thread` and `comment` commands, which have no
`--json`.

No user-visible behaviour changed.

I ran the model files `test_interact_contract`,
`test_interact_document`, `test_interact_anchors` and
`test_interact_product` in full. I ran each changed journeys test by
node ID, in `journeys/test_interact_document.py`,
`test_interact_contract.py` and `test_interact_anchors.py`.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 13, 2026
Registry problems now reach `page check` and `package check` as records,
like the markup and render findings from #2662 and #2686. Before, each
one was a `RegistryError` sentence, and `page check --json` wrapped it
as one `invalid-registry` record whose only value was that text.

## What changed

- **One finding per registry problem.** Each of the ~100 raise sites
under `registry/`, plus the example and incoming-layer checks in
`validation/composition.py`, now raises `registry_error(code, registry,
tag, **values)`. The result is a `RegistryError` that carries one
`Finding`:
- `code`: one of 104 codes. Sites that raise the same kind of problem
share one, so `unknown-declarations` covers `x-owners` and `x-unique`
(`values.key`), and `predicate-*` covers `x-awaits` and `x-thread-seat`.
- `at`: the element declaration the problem concerns, such as
`<lf-local>`, or empty for a `$` fact.
  - `values.registry`: the file or composition it was read in.
- `values.revendor`: present when the fault is in a vendored layer that
re-vendoring fixes.
- The remaining `values` hold what the check read: the verb, the
attribute, the offending names or value. A JSON Schema complaint also
carries `keyword`, `path` and `reason`, from
`registry.schema.schema_reading`. The markup check's `attribute-schema`
now uses the same helper.
- **Words in one place.** The words for every code are in `findings.py`,
under `_declared`. That helper adds the file prefix and the re-vendor
suffix.
- **Commands report the record.** `page check` adds the refusal's
findings to its errors. When `package check --json` meets a refusal that
carries findings, it reports those findings in place of a `package`
record.
- **`findings.Rejected`** is now `Rejected(findings, heading=None)`.
With no heading, its text is the findings' own words. `RegistryError`
subclasses it.
- `layer_facts_error`, which returned a string, is replaced by
`check_layer_facts`, which raises. `reference_relation_error` is now
`reference_relation_problem` and returns a code and values. The
`invalid-registry` code now covers only the refusal #2658 added for a
layer this Leaf cannot serve (`layer.incompatible_layer`). That refusal
is still a sentence that the page servers, the event door and the
website also read.

## Human output: before and after

Human output is byte-identical. I ran `leaf page check` from the merge
base and from this branch on two broken pages and diffed stdout, stderr
and the exit status. The only difference was the base run's
`leaf-version` advice line, which comes from running an exported tree,
so I filtered it out.

A page whose own `page/registry.json` declares an `x-awaits` answering
verb it doesn't have:

```
Error: index.html has 1 validation issue
  - …/authored/page/registry.json: <lf-local> x-awaits answers with verbs ["submit"], which are not x-state verbs the user writes
```

A page whose vendored `registry.json` has `$languages.names: 3`:

```
Error: index.html has 1 validation issue
  - …/vendored/registry.json: $languages.names: 3 is not of type "array"; run `leaf page init …/vendored` to re-vendor it
```

I also compared the refusal text of about 100 broken registries between
the two trees. Each one mutated the shipped registry, a registry file,
an example, the incoming layer or a fixed `$events` member, and together
they reached nearly every code. All were identical.

`page check --json` for the second page:

```json
before: {"code": "invalid-registry", "severity": "error", "values": {"error": "…/vendored/registry.json: $languages.names: 3 is not of type \"array\"; run `leaf page init …/vendored` to re-vendor it"}, "text": "…"}
after:  {"code": "layer-facts", "severity": "error", "values": {"keyword": "type", "path": ["$languages", "names"], "reason": "3 is not of type \"array\"", "registry": "…/vendored/registry.json", "revendor": "…/vendored"}, "text": "…"}
```

For the first page:

```json
after:  {"code": "awaits-verbs", "severity": "error", "at": "<lf-local>", "values": {"verbs": ["submit"], "registry": "…/authored/page/registry.json"}, "text": "…"}
```

## Tests

- I cut the tests in `test_interact_layer.py`, `test_server_lifetime.py`
and `journeys/test_interact_contract.py` that matched registry words
over to codes and fields. They use two new `interact_support` helpers:
  - `registry_refusal(read)` returns the finding a refusal carries.
- `command_refusal(*args)` runs a leaf command in process and returns
its refusal's finding. It covers commands with no `--json`, such as
`page init` and `package init`.
- `test_package_check_requires_a_non_empty_widget_description` now
expects `no-description` where it expected a `package` record. That is
the user-visible change to `package check --json`.
- `test_interact_contract.py` still matches the words, which are
unchanged. A follow-up PR cuts it over.
- I ran `tests/model/test_interact_contract.py`,
`test_interact_layer.py` and `test_server_lifetime.py` in full, and the
changed journeys test by node ID. To check the cut-over, I replaced
every registry finding's words with a constant and reran those files and
seven other model files that write registries, with the follow-up's
conversion of `test_interact_contract.py` applied. All 876 tests passed,
so no other test in them reads registry words.

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 13, 2026
Every gate at the event log's append door now refuses on a `Finding`
record (#2662, #2686, #2692 built the type) instead of a sentence. Each
refusal has a stable code and the values the gate read: the refused
event's `kind`, the identity or field it concerns, and, where a value
was refused, what was offered and what would have been admitted. The
words for each code are written once, in `findings._TEXT`.

- **Gates** in `event_contracts`, `events.UndoReading`,
`tasks.task_error`, `work.widget_seat_error`, `read_state` and `layer`
return `Finding | None`. `EventRefused` and `AttemptConflict` carry that
one finding. A schema refusal (`invalid-event`, `invalid-detail`) names
the JSON pointer of its `field` and the schema `rule` it breaks
(`registry.schema.schema_complaint`).
- **Layer refusals**: `layer.incompatible_layer` and
`incompatible_revision` return findings too (`foreign-layer`,
`retired-layer`, `foreign-revision`, `retired-revision`), so serving,
admission and `page check --json` report the same record. `page check
--json` reports the layer's own code where it used `invalid-registry`.
- **User words**: `refusals.Refusal`, the string that carried separate
words for the browser, is gone. The two codes that have their own user
words (`stale-move`, `stale-edit`) get them from `findings._USER`,
through `Rejected.user`.
- **Transports**: the event door's 400/409 answer carries `findings`
beside `error`, which is still the text the browser shows.
`Refused.json()` is the one JSON shape of a refusal. A failed thread
title records the refusal's code.
- **Hook weight**: `findings` imports `registry.schema` only when it
writes words. The event log raises findings, and the Codex tool hook
reads a quiet page without importing jsonschema
(`test_codex_tool_hook_reads_a_quiet_page_without_the_page_model`).

No user-visible behaviour changed: every refusal reads as it did, in the
browser and on the command line.

Tests that matched admission refusal text in-process, or in the door's
answer, now read the code and fields through `refused_on`. A heuristic
count of test assertions that match the original refusal words fell from
63 to 31. Most of the 31 match the CLI's printed output, and a follow-up
PR moves them to a `--json` refusal shape. The rest assert the
user-facing words or text that does not come from the append door.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants