Repository navigation
docs(design): cite code and docs by name in trust_boundaries.md, and check the names - #888
Merged
Merged
Conversation
…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 <noreply@anthropic.com>
A JavaScript name now counts only outside every named definition or directly in the body of the name before it, so a local of the same name no longer stands in for a renamed helper. Code spans follow CommonMark, more ways of writing a line number are refused, Rust impl headers with lifetimes, a semicolon, or an arrow are read correctly, and headings in HTML comments no longer count. Two converted references are corrected and one row no longer repeats a reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ence check A TypeScript return type, an object type in a parameter or a type alias, and a class field holding an arrow function no longer move a name to the wrong level. A body search stops at the end of a value, control keywords are not definitions, Rust items count only at the top of the file, and a line number after a symbol reference is refused. The doc's format rules describe what the check looks through. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mes by pattern The trust-boundary reference check read JavaScript, TypeScript, and Rust with hand-written readers (comment and string masking, bracket pairing, nesting levels, TypeScript return types, Rust impl extents) to check 36 references, and a new syntax form in a cited file could make it fail on an unrelated pull request. For these languages it now checks that each part of a name (a.b.c, or Type::method) is defined somewhere in the file, with a few patterns that match a definition at the start of a line. Python is still read with ast and Markdown anchors are still exact. The check misses a rename when another definition with the same name is left in the file, which the doc's "Keeping this doc accurate" section says. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…by reference About 20 places named a docs section by a quoted heading next to its path, and about 30 named a function or class next to a file path written alone. The validator checked the file but not the heading or the name. Each is now `path#anchor` or `path:Symbol`, so the check covers it. The validator also rejects the common forms of both old shapes (a quoted heading after a Markdown path, and a bare name beside a code path). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…rn form
A review found that a call whose line did not end in `;` counted as a
method definition (`own(x) || own(y)) {`, `foo(a, () => {`), so moving a
function to another module while its callers stayed kept the reference
passing. A method now needs its parameters to close before a `{` on the
same line, or to run on to the next line, and a `name(): Type;` signature
counts for TypeScript interfaces.
The tests now cover each form the patterns read (modifiers, generics,
optional and definite markers, generators, enums, namespaces, signatures,
`.mjs`, Rust `async`, `const` and `unsafe` items, multi-line and `unsafe`
`impl` headers). Both old-shape rules also catch a heading in backticks,
a typographic quote, and a bare name that is not a file name. Comments
and the doc say what the patterns still count.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Opus 5.5)
The follow-up commits (the looser check for JavaScript, TypeScript, Rust, and Pest, and the conversion of the last quoted headings and bare names) are by Sonnet 5.5.
docs/design/trust_boundaries.mdcited code and docs by line number, so its references went stale every time the code moved: #887 had to correct 202 of them, anddispatcher.pyalone changed 36 times this month. This pull request makes each reference name the function, class, or docs heading instead, and adds a validator that fails the gate when a named thing is gone.What changes
path:Symbol, such ascitry/attrs.py:validate_html_attr_name, and every docs reference ispath#anchor, such asdocs/security.md#authorize-every-event. The 76 references written as a bare:N(meaning the file named earlier in the row) now name their file, so each one stands alone.scripts/validators/trust_boundary_refs.pychecks every code span in the doc that is a file path, alone or followed by:Symbolor#anchor. It fails when the file does not exist, when the symbol is not defined in it, when no heading in a Markdown file has the anchor, on a line number written in a reference or right after one, and on the common wordings of the two old shapes: a quoted heading after a Markdown path, and a bare name beside a code path.scripts/validate.pyfinds it on its own, like every other validator.ast: a name must sit where the reference puts it.a.b.c) or of a RustType::methodonly has to be defined somewhere in the file.{ #id }when it sets one, otherwise GitHub's slug.packages/py/citry/tests/test_trust_boundary_refs_validator.pytests the validator on small made-up files, one case per rule, following the existing validator tests.No row's statement about trust changed. Two rows changed wording beyond their references:
window,document, and form members listed five function names followed by one line range. The five names are now the five references._render_inputsfunction said_complete_call(:1641, the call at:1697). Both lines are in_complete_call, so ", the call at ..." would have repeated the same reference, and it is gone.In the follow-up, the Citry UI tag-inputs row said
CCard,CRowandCColwere "incflow.py";CCardis inccard.py, so the row now gives each class its own reference.Format rules
path:namefor a module-level function, class, or constant;path:Class.namefor a method or class attribute. A definition inside another one is named from the outermost definition down, joined with dots:citry/components/dynamic.py:make_dynamic_element.DynamicElement.on_render. The check follows that nesting.constandletvalues, object properties, and class fields (citry/_vue/client.js:startPreparedOwned.host.preflightResult). The outermost name is one defined outside every named function, class, or object; inclient.jsthat includes the functions inside the anonymous function that wraps the whole file. A property set withObject.definePropertyat the top is cited by its name alone, whatever object it is set on (citry/_vue/client.js:pageNonce). The check does not follow the nesting: it requires each part to be defined somewhere in the file.fn,struct,enum, ortraitby its name; a method in animplortraitblock asType::method, using Rust's own path separator (vc/server_render.rs:StaticWriter::element). A method fromimpl Display for WriterisWriter::fmt. The check requiresTypeto be defined or to appear in animplheader in the file, andmethodto be defined in the file.tp/grammar.pest:html_attribute).path#anchor. When a heading sets its own anchor with{ #id }, the anchor is that id; otherwise it is GitHub's slug of the heading text. For text that covered several sections, the reference names the heading above them all, or each section.ui/components/cavatar/api.yml, is now a path; the row already names thesrcinput.citry/,ui/,js/,tp/,vc/,docs/). The validator reads them from the list under "How to read a row", so the doc and the check cannot disagree; any other path is read from the repository root.What the patterns match in JavaScript, TypeScript, Rust, and Pest
Each pattern starts at the beginning of a line, after indentation and keywords such as
export,pub,asyncandstatic. That keeps a name after//or in the middle of a line from counting, so the check needs no reader of comments and strings. "Known limits" lists what still counts.function name,function* name,class,interface,enum,namespace,type,const,letandvarfollowed by a name;(or<T>(whose parameters close on the same line before a{(a method) or before: Type;(a signature), or run on to the next line; a call such asfoo(a, () => {does not count;:,?:or!:(an object property or a typed class field), or=(a class field);Object.defineProperty(target, "name".fn,struct,enum,trait,type,union,mod,constorstaticfollowed by a name (afterpub(...),async,const,unsafe); for theTypeofType::method, an item of that name or animplline whose header names it.name =at the start of a line.How the conversion was done
A throwaway script read each cited line or range at
origin/main(06ced07) and found the innermost definition holding it (Python withast, JavaScript with acorn) or the heading above it. I mapped the 19 Rust, 3 Pest, and 2 TypeScript references by hand, and checked by hand every other case the script could not map cleanly.client.jsnames above)Where two neighboring references became the same one (for example
docs/security.md:1462-1465and:1466-1510, both in "What is blocked"), they were merged into one.The 49 references mapped by hand
mainvc/server_render.rs:4376vc/server_render.rs:escape_texttp/grammar.pest:81-83tp/grammar.pest:html_comment_contentdocs/syntax/expressions.md:135-148docs/syntax/expressions.md#how-values-rendertp/grammar.pest:182-204tp/grammar.pest:html_script_content,tp/grammar.pest:html_style_contenttp/compiler.rs:262-274tp/compiler.rs:compile_template_body_with_modetp/compiler.rs:398-441tp/compiler.rs:compile_template_body_with_modedocs/syntax/raw.md:25-30docs/syntax/raw.md#literal-texttp/compiler.rs:733-756tp/compiler.rs:compile_html_nodevc/server_render.rs:4391vc/server_render.rs:escape_attributetp/grammar.pest:306tp/grammar.pest:html_attribute:273-309(indocs/advanced/html-attributes.md)docs/advanced/html-attributes.md#invalid-names,docs/advanced/html-attributes.md#names-citry-reservescitry/attrs.py:140-153citry/attrs.py:is_vue_code_attr_namedocs/advanced/dynamic-components.md:175-223docs/advanced/dynamic-components.md#valid-tag-names,docs/advanced/dynamic-components.md#refused-tagsdocs/concepts/slots.md:60-111docs/concepts/slots.md#c-fill-in-templates,docs/concepts/slots.md#c-slot-fallbackcrates/citry_html_transform/src/marker.rs:520crates/citry_html_transform/src/marker.rs:mark_htmltp/compiler.rs:150tp/compiler.rs:compile_template:161(intp/compiler.rs)tp/compiler.rs:compile_prepared_templatecitry/component.py:724-729citry/component.py:Component.templatetemplateclass attributedocs/security.md:1437-1613docs/security.md#sandbox-python-template-expressionsdocs/security.md:1677-1986docs/security.md#apply-a-request-csp-nonce-centrallycitry/_vue/client.js:6190citry/_vue/client.js:pageNoncecrates/citry_core_py/src/vue.rs:13crates/citry_core_py/src/vue.rs:compile_vuevc/server_render.rs:3509-3510vc/server_render.rs:Writer::record_form_names:4151(invc/server_render.rs)vc/server_render.rs:StaticWriter::elementvc/server_render.rs:1576vc/server_render.rs:dom_answervc/hydration.rs:1430vc/hydration.rs:component_attributescrates/citry_native_render/src/json.rs:14crates/citry_native_render/src/json.rs:write_json_strcrates/citry_i18n/src/compiler.rs:3955crates/citry_i18n/src/compiler.rs:validate_tagged_argjs/citry-i18n-runtime.ts:426js/citry-i18n-runtime.ts:createI18nWireRuntime.argumentValuecreateI18nWireRuntimedocs/events/actions.md:27-128docs/events/actions.md#re-render-the-component,docs/events/actions.md#keep-list-items-matched-to-their-records,docs/events/actions.md#swap-in-a-different-component,docs/events/actions.md#update-one-part-of-the-pagedocs/security.md:483-748docs/security.md#protect-event-posts-from-csrfcitry/ext/preview/host.py:57-87citry/ext/preview/host.py:_is_loopback_authority,citry/ext/preview/host.py:_is_local_requestcitry/extension.py:1462-1479citry/extension.py:_as_str,citry/extension.py:_as_node_listcitry/extension.py:952-966citry/extension.py:Extension.on_component_input,citry/extension.py:Extension.on_component_data:1031-1051(incitry/ext/cache/replay.py)citry/ext/cache/replay.py:_require_authored_span,citry/ext/cache/replay.py:_require_produced_binding,citry/ext/cache/replay.py:_require_authored_values_expressioncrates/citry_html_transform/src/output_policy.rs:188crates/citry_html_transform/src/output_policy.rs:check_output_htmloutput_policy.rs:298-336crates/citry_html_transform/src/output_policy.rs:for_each_reading:1497-1743(incrates/citry_html_transform/src/output_policy.rs)crates/citry_html_transform/src/output_policy.rs:tags_require_javascript:1862(incrates/citry_html_transform/src/output_policy.rs)crates/citry_html_transform/src/output_policy.rs:encoding_dependent_spandocs/security.md:2088-2374docs/security.md#choose-how-much-javascript-citry-may-delivercitry/settings.py:728-735citry/settings.py:CitrySettings.security_script_integritydocs/security.md:2376-2435docs/security.md#pin-citry-managed-scripts-with-sriui/components/cavatar/api.yml:13ui/components/cavatar/api.ymlsrcinput:1733-1776(incitry/_vue/client.js)citry/_vue/client.js:requireEventHandler,citry/_vue/client.js:writableStateFieldsjs/citry-i18n-runtime.ts:1107js/citry-i18n-runtime.ts:createI18nWireRuntime.requirementRecordcreateI18nWireRuntime:3231(incitry/_vue/client.js)citry/_vue/client.js:styleNamesApp:3255(incitry/_vue/client.js)citry/_vue/client.js:removeStyleElement:6208(incitry/_vue/client.js)citry/_vue/client.js:startDocumentclient.js:6166citry/_vue/client.js:checkBlockWithoutNonceConverting the headings and bare names
After the maintainer's review, the follow-up commits converted the references the first pass left outside the check, and the validator catches the common wordings of the old shapes:
docs/security.md, "Nonces in fragments", and one in backticks) becamepath#anchor, heredocs/security.md#html-fragments, the heading's own id. Where a row cited a page asdocs_site/content/..., it now uses thedocs/short form.combine_assets(citry/citry_render.py), becamepath:Symbol. A nested Python function takes its full name (citry/_vue/direct_capture.py:assemble_typed_render.transform_component.transform_parts.write_static_html_run); the TypeScript ones follow the same rule (js/citry-fragments.ts:installFragmentManager.loadOnce).docs/reference/browser-apis.mdis an HTML<h3>, which no anchor check reads, so the row cites the section it sits in,#fragments.Left as they are: a path written alone with no name next to it (a file cited as a whole, such as
citry/_vue/events.py, or "docstrings incitry/extension.py"), and the heading "Do not compile rendered values as source" in the design docvue.md, which is linked with a relative Markdown link that the validator does not read.A reference that may not match its row
The row for a stored render-cache entry (section 11) says names are "checked against this process's live templates on replay" and cited
citry/ext/cache/replay.py:937. Line 937 is in_export_typed_leaf, the check that runs when a render is stored; the checks that run on replay are in_replay_typed_leaf, which calls the three_require_*helpers the row also cites. The conversion kept the line's own function,citry/ext/cache/replay.py:_export_typed_leaf, so the row says what it said before. Whether that reference should be_replay_typed_leaf, and whether a dynamic tag is checked again on replay, is a question about the row's trust statement, so I left it for you.Decisions
The maintainer answered the questions the first version raised.
{ #id }are cited by that id, not by GitHub's slug. Kept. For about 350 of the roughly 1,470 headings underdocs_site/content/, GitHub's slug includes the id text and changes whenever the heading is reworded; the id is whatdocs/best-practices/writing-docs.mdtells writers to keep. When a reference uses the slug of a heading that has its own id, the validator says which id to use.citry/_vue/direct_capture.py:assemble_typed_render.transform_component.transform_parts. Kept.Type::method. Kept.Not changed: the
docs/short form meansdocs_site/content/, so a design doc in the repository's owndocs/folder cannot be cited with a short path. The doc links those with relative Markdown links (for example[vue.md](vue.md)), which the validator does not read.Cost of the new check
validatorsphase ofscripts/check.py, in both the fast and the full profile, so locally and in CI with no new job.implextents) to about 100 lines of patterns. The readers served 75 of the 512 references, three reviews kept finding holes in them, and a new syntax form in a cited file could have made the check fail on an unrelated pull request.Checks
python scripts/validate.py: all 18 validators pass.pytest packages/py/citry/tests/test_trust_boundary_refs_validator.py packages/py/citry/tests/test_trust_boundary_rows_validator.py --noconftest: 70 passed. (The citry conftest needs a freshcitry_corebuild, which these tests do not use.)ruff check,ruff format --check,mypy, andmypy --platform linuxon the changed files: clean.Type::methodwith a misspelled method, a misspelled Pest rule, an unknown anchor, GitHub's slug where the heading has its own id, a line number, a quoted heading beside a path, and a bare name beside a path.=>guard, the rule that a call is not a method, the: Type;signature,Object.definePropertyat the start of a line, Rustasync,const,unsafe,static,union,modandpub(crate)items, multi-line andunsafeimplheaders, a type that only animplline names, the Rust method check, a Pest rule anywhere in a line, checking only the first part of a dotted name, the.mjschecker, and each part of the two old-shape rules.Review
Four independent reviews checked this pull request: three before it was opened and one of the follow-up commits.
astand@babel/parser. It found two references to correct (a Pest range that held two rules, and an anchor broader than the cited lines), the row whose text repeated a reference, and the possibly mismatched reference above. All of these are folded in or listed above.ownhelper inclient.jsstill passed;implheaders with lifetimes or a;) concerned the nesting readers that the follow-up deleted. Theowncase is now an accepted limit (see "Known limits").implextents concerned readers that are now deleted. The others, a line number written after a symbol reference and the false alarm onexample.com:8000, are fixed with tests.;counted as a method (own(x) || own(y)) {), so moving a function to another module while its callers stayed kept the reference passing. A method now needs its parameters to close before a{on the same line, or to run on to the next line, and the commitaa6b06a17has the test. It also found 15 changes to the patterns that no test noticed, which now have tests (see "Checks"), claims in the comments and commit message about the old-shape rule that were stronger than the rule, stale text in this section about the deleted readers, and a few sentences in the doc and the validator's comments that said more than the patterns do. All are fixed. The fixes were checked with the tests and the mutation run above, not by a second review round.Known limits
For JavaScript, TypeScript, Rust, and Pest the check is looser on purpose:
Type::method, each part is checked on its own, so a part that moved to another object orimplstill passes.if (x) {), a parameter line (callback: Cb,), a plain reassignment (state = next;), a call whose line ends at its(, and afninside amacro_rules!body.implheader counts as a type, includingforand generic parameters, soDisplay::fmtpasses when the file hasimpl Display for Writer.const { a, b } = ..., by the second name ofconst a = 1, b = 2, by a quoted property name ("name": value), by a shorthand property, or by a member assignment such asexports.name = ...is not found; cite the enclosing name.a plain `str`, `citry/util/html.py` escapes it) is a false alarm.Versioning and changelog
This changes a design doc, a repository validator, and a test; no code in a published package changes. Nothing the 1.x promise covers is affected, no contract version changes, and no changelog entry is needed.
Security
No value reaches the browser through this change, so the Mechanism 7 security pass and the Mechanism 8 advisory check do not apply.
docs/security/reviews/records keep their line numbers, since they record a point in time.🤖 Generated with Claude Code