Skip to content

Put data rules widgets rely on in their contracts, and leave malformed input to the agent - #2487

Merged
max-sixty merged 6 commits into
mainfrom
contract-owned-data-rules
Oct 12, 2026
Merged

max-sixty merged 6 commits into
mainfrom
contract-owned-data-rules

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Some widgets enforced rules their data contracts did not state, so leaf data set stored values the page then failed on. Each such rule now lives in the contract, checked at the boundary, and producers stop diagnosing malformed input the consuming agent can see fail on its own.

Rules moved into contracts

  • visual-review: the visual-run contract declares records: {items: "cases", key: "id"}, so data set refuses a run that repeats a case id. The widget's own "visual run repeats a case id" throw is gone, and with it test_visual_review_recovers_from_rejected_cases, which reached the failure view only through that guard.
  • format: uri was never checked. jsonschema checks uri only with the optional rfc3987 package, so the uri fields in visual-run and playwright-trace accepted anything; http://a.test:99999/ reached lf-visual-review's new URL and threw. registry/schema.py now checks uri with the new runtime dependency ada-url (Ada, the WHATWG URL parser Node uses), so data set accepts exactly the URLs the browser parses. A new check_schema refuses any format Leaf has no checker for, at every registry schema check.
  • Which language a filename means: the file editor reads langForPath instead of its own /\.(md|markdown)$/ regex, and $languages.paths maps markdown, so lf-diff and lf-code colour .markdown too.
  • references/packages.md tells package authors to state such rules in the contract.

One table for lf-diff's two readers. The widget (Pierre) and patch_manifest.py (unidiff) both decide what lf-diff can present; #1082 keeps patch parsing out of core, so both stay. tests/diff_patch_cases.json is the table both are tested against, replacing each reader's own refusal list. The browser test draws every accepted row as text and as its manifest and compares file names.

Malformed input is left to the agent. A new /developing-leaf section, "Let the agent correct its own input": code reads the input its contract describes and lets anything else fail where it fails, handling a malformed case only where it would otherwise pass silently into state the user relies on. Applied here:

  • patch_manifest.py goes from 302 to about 100 lines. unidiff supplies paths and counts; the script keeps only the contract's exclusions (copies, and hunkless entries other than Git's exact path-only rename, binary renames included).
  • lf-diff's path-only rename check now counts exact rename blocks against Pierre's hunkless renames, so a rename with missing hunk headers still fails rather than showing as a clean rename; its path decoding and header comparison are gone.
  • import_trace.py drops the type and shape checks the playwright-trace contract repeats at data set, and the archive-name, duplicate-call, parent-agreement, image-format and capture-consistency refusals. It keeps the format-9 refusal and the parentId cycle guard, which would otherwise loop forever.

Behavior changes: data set refuses repeated visual-run case ids and URLs the browser cannot parse; package check and page init refuse a schema naming an unchecked format; the diff and playwright producers no longer diagnose malformed patches or traces.

The ~45 registry entries restating the element-id pattern are left alone: each tag entry is one complete schema (AGENTS.md), and the creates-child check pins the canonical form where it is a cross-widget contract.

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

max-sixty and others added 6 commits October 10, 2026 21:29
…tracts declare

Some widgets enforced rules their data contracts did not state, so `leaf data set`
stored values the page then failed on. Each rule now has one home at the boundary.

- **visual-review.** The `visual-run` contract declares `records: {items: "cases",
  key: "id"}`, so `data set` refuses a run that repeats a case id. The widget's own
  "visual run repeats a case id" throw is deleted.
- **`format: uri` was never checked.** jsonschema checks `uri` only when the optional
  rfc3987 package is installed, so the `uri` formats in `visual-run` and
  `playwright-trace` accepted anything; `http://a.test:99999/` reached
  lf-visual-review's `new URL` and threw. `registry/schema.py` now checks `uri` with
  ada-url (a new runtime dependency binding Ada, the WHATWG URL parser Node uses), so
  `data set` accepts exactly the absolute URLs the browser parses. A new `check_schema`
  refuses any `format` Leaf has no checker for, at every registry schema check, so a
  declared format can no longer be silently ignored.
- **Which language a filename means.** The file editor chose Markdown mode by its own
  `/\.(md|markdown)$/` regex; it now reads `langForPath`, and `$languages.paths` maps
  `markdown`. A `.markdown` file is now coloured as Markdown by lf-diff and lf-code too.
- **lf-diff patch rules in two languages.** The widget (Pierre) and
  `patch_manifest.py` (unidiff) both decide what lf-diff can present; #1082 keeps patch
  parsing out of core, so both stay. `tests/diff_patch_cases.json` is now the one table
  both are tested against, replacing each reader's own refusal list; the browser test
  draws every accepted row as text and as its manifest and compares file names. The
  table found that both Git path decoders accepted one- and two-digit octal escapes Git
  never writes; the manifest decoded `bad\1.py` while Pierre kept the quoted spelling,
  so the page refused a manifest `data set` had stored. Both now accept only Git's
  three-digit form.
- `references/packages.md` tells package authors to state such rules in the contract.

Behavior changes: `data set` refuses repeated visual-run case ids and URLs the browser
cannot parse; `package check` and page init refuse a schema naming an unchecked format;
short octal escapes in quoted diff paths are refused.

The diff contract's `key: path` and rename `previousPath` rules already landed in #2319.
The ~45 registry entries restating the element-id pattern are left: each tag entry is
one complete schema (AGENTS.md), and the creates-child check pins the canonical form
where it is a cross-widget contract.

Tests: test_interact_contract, _layer, _document and test_product_page pass (798), as
do the diff table browser test, the visual-review projection and journey tests, and
the file-editor typography test, which now edits a `.markdown` file and fails when the
registry loses that entry.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A new /developing-leaf section: code handles the input its contract describes and
lets anything else fail through the parser or check already in its path, since the
agent reads that failure and fixes its input. Handling a malformed variant is reserved
for one that would otherwise pass silently into state the user relies on.

It records the decision not to make lf-diff refuse malformed inline patches (headerless
patches, contradictory headers, invalid quoted paths), which the patch table showed it
draws leniently.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Conflicts: developing-leaf's new section sits after main's paragraph on checks; the
$languages description takes main's build/vendor.mjs; lf-visual-review's Lit rewrite
keeps its repeated-case-id guard out, since the visual-run contract now refuses one.
Main's test_visual_review_recovers_from_rejected_cases is deleted: it reached the
widget's failure view through that guard, and data set now refuses the duplicate run
it set (test_data_set_refuses_a_visual_run_the_widget_cannot_show).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Per developing-leaf's "Let the agent correct its own input", code reads the input its
contract describes and leaves a malformed one to fail where it fails.

- patch_manifest.py: 302 to ~100 lines. unidiff now supplies each file's paths and
  counts; the script keeps only the contract's exclusions (copies, and hunkless
  entries other than Git's exact path-only rename, which covers binary renames).
  Gone: header/marker agreement, rename-block agreement, quoted-path escape
  validation, hunk line recounting, unmarked empty lines, no-prefix detection, and
  the repeated-path and empty-patch refusals `data set` already makes.
- lf-diff: the path-only rename check counts exact rename blocks against Pierre's
  hunkless renames, so a rename with missing hunk headers still fails rather than
  showing as a clean rename; its path decoding and header comparison are gone.
- import_trace.py: drops the type and shape checks the playwright-trace contract
  repeats at `data set`, and the archive-name, duplicate-call, parent-agreement,
  image-format and capture-consistency refusals. It keeps the format-9 refusal and
  the parentId cycle guard, which would otherwise loop forever.

Behavior change: malformed patches and traces are no longer diagnosed by the
producers; a damaged input may now be stored and read leniently. The diff patch
table keeps the well-formed rows and the contract exclusions; rows that pinned
removed diagnoses are deleted, as are the playwright tests of removed refusals.

Tests: the trace, playwright, diff and manifest selections pass (224).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit f616816 into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the contract-owned-data-rules branch October 12, 2026 05:00
max-sixty added a commit that referenced this pull request Oct 12, 2026
…ts by ref, and repaint only the pairs on an inspection choice (#2527)

Follow-up to the Lit conversion of `lf-visual-review` (#2374), covering
item #35 of the Lit-survey review (that review's numbering, not GitHub
issues) and the part of item #41 that touches this widget's tests.

**#35: cuts left by the conversion.**
- The inspector's radios declare their Enter/Space command with
`commandsOn` in the template, replacing the widget's own path: a cache
of ref callbacks, a `dataset` re-entry check and `commands(radio, …)`.
The radios no longer carry `data-mode`/`data-scope`/`data-scale`; the
one control archetype that selected on `data-mode` now selects on the
radio's `value`.
- Each case entry holds its `lf-shot` and article through the `ref`s the
template binds, so the post-render `querySelector` loop, the six
`shotHost.querySelector("lf-shot")` lookups and the unobserve-on-removal
loop are gone.
- Only the selected case's head, toolbar slot and stage are
size-observed, since hidden cases measure zero; observation moves with
the selection.
- An opacity tick repaints only the inspector and the pairs. A mode,
scope or size choice repaints the inspector, the pairs and the selected
pair's allocation, without re-rendering every case. `#remaining()` runs
once per render rather than once per case (it was quadratic in case
count), and the selected pair gets its allocation alone after the shared
choices instead of a second full inspection.
- A failed source (the `failSoft` view in `#show`) now discards its
cases, and the next good commit rebuilds them with the selection kept.
With entries held by ref, a failure left each entry's article null, and
the next-remaining control threw inside every page-wide key reflection.
- The focus-crop availability test has one home, `#focusAvailable()`,
and `type="button"` is dropped where `offered` already writes it.
- The `data-lf-gen="1" data-lf-said` markers stay as static attributes.
Lit cannot interpolate attribute names without a directive, and #2504
removed `said` so that the static markers are the one documented form.

Behaviour changed: none a reader sees. Enter on an inspector radio now
has a test; that test fails when the command's `run` is emptied.

**#41 (this widget's part).**
`test_visual_review_recovers_from_rejected_cases` no longer exists:
#2487 deleted it when the `visual-run` contract began refusing repeated
case ids, so no data reaches the failure view now. The reorder test
replaces its `node === old` check with what that identity gives the
user: after the reorder, Cmd/Ctrl+Z still undoes the typed draft (the
assertion fails when the editor is swapped for a copy with the same
value). `test_visual_review_ignores_a_late_load_from_detached_evidence`
now replaces the evidence through `data set`, as a new run would,
instead of swapping the `lf-shot` by hand behind Lit, and it now asserts
that the shown pair's box does not move when the detached evidence
finally loads. Its old assertion read the new shot's own image width,
which the old shot could never change; the new one fails when the layout
reads the detached shot's geometry.

**Line deltas**
- Hand-written source: `lf-visual-review.js` 940 → 917 (−23; +93/−116).
- Tests: +23/−27 (−4).

> _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