From faed2c6757eff28f1f9e29d3524b0dcce1d0118d Mon Sep 17 00:00:00 2001 From: Juro Oravec Date: Wed, 25 Nov 2026 14:33:57 +0100 Subject: [PATCH 1/6] docs(design): cite code and docs by name in trust_boundaries.md, and check the names Every code reference in docs/design/trust_boundaries.md is now path:Symbol and every docs reference path#anchor, so a reference stays right while lines move. The new validator scripts/validators/trust_boundary_refs.py fails the gate when a cited file, symbol, or heading no longer exists, or when a reference cites a line number. Co-Authored-By: Claude Opus 5.5 --- docs/design/trust_boundaries.md | 350 +++++---- .../test_trust_boundary_refs_validator.py | 218 ++++++ scripts/validators/trust_boundary_refs.py | 733 ++++++++++++++++++ 3 files changed, 1154 insertions(+), 147 deletions(-) create mode 100644 packages/py/citry/tests/test_trust_boundary_refs_validator.py create mode 100644 scripts/validators/trust_boundary_refs.py diff --git a/docs/design/trust_boundaries.md b/docs/design/trust_boundaries.md index 3555cf921..2654228ec 100644 --- a/docs/design/trust_boundaries.md +++ b/docs/design/trust_boundaries.md @@ -1,9 +1,11 @@ # Who may supply each input that reaches the page -**Status (2026-11-25): line numbers checked against `main` after the -citry 1.3.0 release.** Every row names the function that does the -work; when that function changes, the row changes in the same pull request -(see [Keeping this doc accurate](#keeping-this-doc-accurate)). +**Status (2026-11-25): references checked against `main` after the +citry 1.3.0 release.** Every row names the function that does the work, +by name rather than by line, and a validator fails the gate when a named +function, class, or docs heading no longer exists. When that function +changes, the row changes in the same pull request (see +[Keeping this doc accurate](#keeping-this-doc-accurate)). Citry turns Python values, template source, and HTTP requests into HTML, CSS, and JavaScript. For each value that ends up in the page, an app @@ -46,11 +48,13 @@ Each row answers four questions. 2. **What the browser does with it**: shows it as text, parses it as markup, applies it as CSS, runs it, navigates to it, or uses it as a key. 3. **What Citry does, and where**: the one function that escapes, checks, - or passes the value through, as `file:line`, and the render paths that + or passes the value through, as `path:Symbol` (such as + `citry/attrs.py:validate_html_attr_name`), and the render paths that reach it. 4. **What the docs say**: the public page or docstring that states the - rule. "Missing" means the code makes the input author only or app code - but no public page says so yet. + rule, with a page section cited as `path#anchor` (such as + `docs/security.md#authorize-every-event`). "Missing" means the code + makes the input author only or app code but no public page says so yet. Paths are repo-relative, with these short forms: @@ -68,12 +72,12 @@ says which paths it covers. These are the paths: - **Capture.** Every ordinary render first records its output as a list of parts: text values, trusted HTML, and element start tags with their - attributes (`citry/component_render.py:1069-1076`, `citry/_vue/capture.py`). + attributes (`citry/component_render.py:render_impl`, `citry/_vue/capture.py`). The next two paths, static HTML and Vue, each turn that list into the page, so a check made while recording applies to both. - **Static HTML.** A page or subtree without Vue. `citry/serialize.py` - writes text values with `escape_to_str` (`citry/serialize.py:1423`) and - trusted HTML as it is (`:1426`). + writes text values with `escape_to_str` (`citry/serialize.py:_append_frame_parts`) and + trusted HTML as it is (`citry/serialize.py:_append_frame_parts`). - **Vue.** A component with `js`, Vue syntax, or Events bindings. No Python value becomes Vue template source: the template gets a reference such as `$citryPrepared.citryText3`, and the value travels as JSON in the page's @@ -87,7 +91,7 @@ says which paths it covers. These are the paths: repeat the attribute-name checks of capture. - **Node path.** The older node classes in `citry/nodes/__init__.py`. Only a component render sets the context variable that selects capture - (`citry/_vue/capture.py:51`), so a template renders on the node path in + (`citry/_vue/capture.py:_PREPARED_RENDER`), so a template renders on the node path in these cases: - It embeds spans of another template language, such as Django template syntax, through the experimental `on_template_foreign_spans` hook @@ -97,11 +101,11 @@ says which paths it covers. These are the paths: spans). - A fill slot renders outside a component render: `str(slot)` (or `Markup(slot)`) on a slot kept after the render - (`citry/slots.py:337-352`), or a slot rendered in a worker thread that + (`citry/slots.py:Slot.__str__`), or a slot rendered in a worker thread that does not copy context variables. Then a component class that has not rendered yet compiles on the node path, and a nested template always does, even when its class has rendered - (`citry/nodes/__init__.py:1105-1122`), so an attribute on an element + (`citry/nodes/__init__.py:TemplateHtmlAttr._compiled_body`), so an attribute on an element inside markup passed as a component input uses the node path every time. After `Component.reset_template()` or a code reload, a class compiles again as if it had not rendered. A slot rendered in a thread @@ -112,7 +116,7 @@ says which paths it covers. These are the paths: On the node path, `ElementAttrsNode._format` writes every attribute value, and `ElementKeyNode` writes the `#c-key` attribute - (`data-citry-key`) on its own (`citry/nodes/__init__.py:1571`). + (`data-citry-key`) on its own (`citry/nodes/__init__.py:ElementKeyNode.render`). - **Events `Render`.** An event handler that returns `Render(element=...)` re-renders through the same capture and writers. - **Cached render.** `citry/ext/cache/replay.py` replays a stored capture @@ -122,20 +126,20 @@ says which paths it covers. These are the paths: The shared escaping functions live in `citry/util/html.py`: -- `escape` (`:84`) and `escape_to_str` (`:100`) escape HTML text +- `escape` (`citry/util/html.py:escape`) and `escape_to_str` (`citry/util/html.py:escape_to_str`) escape HTML text (`& < > ' "` and ESC). A value with `__html__` passes through unchanged. -- `exact_str` (`:125`) copies a `str` subclass into a plain `str`. `str()` +- `exact_str` (`citry/util/html.py:exact_str`) copies a `str` subclass into a plain `str`. `str()` of a `Markup` value is already plain, but a Django `SafeString` returns itself and keeps its `__html__`, so text that must be escaped, such as the `#c-key` value that `ElementKeyNode` writes, goes through `exact_str(str(value))` before `escape`. -- `escape_attribute_value` (`:576`) escapes a double-quoted attribute value. +- `escape_attribute_value` (`citry/util/html.py:escape_attribute_value`) escapes a double-quoted attribute value. A value with `__html__` is first decoded to the text a browser reads - (`decode_attribute_entities`, `:555`) and then escaped, so a `Markup` + (`decode_attribute_entities`, `citry/util/html.py:decode_attribute_entities`) and then escaped, so a `Markup` value cannot end the attribute. The decoded text is always a plain `str`, so a Django `SafeString` is escaped too. A carriage return is written as ` `, because the browser reads a raw one as a line feed. -- `script_json` (`:614`) writes JSON for a ``, but it can leave a JavaScript string or add CSS rules. Under a data-chosen `svg` the browser decodes the escaped value inside ``, but it can leave a JavaScript string or add CSS rules. Under a data-chosen `svg` the browser decodes the escaped value inside ``, but it can leave a JavaScript string or add CSS rules. Under a data-chosen `svg` the browser decodes the escaped value inside ``, but it can leave a JavaScript string or add CSS rules. Under a data-chosen `svg` the browser decodes the escaped value inside `