Repository navigation
fix(cli): read a section of a docs-tree namespace from the guide that has it - #7212
Conversation
… has it `astryx docs layout side-panels` worked in 0.6.6 and has failed since the layout split, because a section argument on a namespace always failed. A section read on a namespace now finds the one guide below it, at any depth, that has the section (by key, then by title, as a topic's section read does) and returns that guide's own section read. When no guide or more than one has it, the read fails with ERR_UNKNOWN_SECTION and names the guides. The choice between several matching guides lives in one function, oneGuide.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Visual Regression23 of 442 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 3 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Thanks — this restores a read that the layout split broke, and the shape of
the fix looks right: astryx docs layout side-panels answers from the guide
that has the section again, in the same payload shape as reading the guide
directly, and the ambiguity and language cases are covered by tests.
Approval needs a maintainer spec decision first. On main, AST-046 is still a
draft and its FR6 says a section argument on a namespace must fail; the
contract this change implements — return the section when exactly one guide
below the namespace has it, and fail naming the guides when none or several
do — currently lives only in the in-review spec update (#7210). A maintainer
needs to land that governing claim on main (including whether an exact-key
match in one guide outranks a title match in another) before this can be
approved; nothing about the implementation needs to be removed or split for
that.
Two smaller fixes are worth taking along whenever that lands:
- The namespace read can pick a different section than the guide's own read
for the same query when a title-derived key matches a later section while
an earlier section's title contains the query ("Shell contract" before
"Shell" in one guide). That sits awkwardly with the changeset's "returns
the same section the guide's own read returns", and the key-preference test
doesn't currently pit a key against a competing title match. Aligning the
per-guide candidate with the guide's own search result — or spelling out a
namespace-only rule in the spec — plus a competing fixture would close it. - On namespaces with no guides below them (
cli/api,cli/commands,
unorganized), a section miss now returns no suggestions while saying
"Open one of its guides instead"; restoring the previous children
suggestions for that case keeps the error actionable.
[Automated review]
…n read Each guide now answers with the section its own section read returns for the query, so 'astryx docs <namespace> <section>' returns exactly what the guide read does, even when a later section's title-derived key matches while an earlier section's title contains the query. A namespace with no guide below it (cli/api) names its children again on a section miss.
There was a problem hiding this comment.
Approving. This stands on its own against current main, restores the 0.6.6 reads, and both Changesets pass the coverage gate.
- Run from this head against the
layoutnamespace that is already onmain:astryx docs layout side-panelsfails onmainwith"layout" has no sectionsand prints the Side panels section here;--jsonis byte-identical toastryx docs layout/side-panels side-panels; the title form,--denseand--zhreturn the samedocs.detail.section. All 14 section keys of the v0.6.6 flatlayoutdoc resolve. A miss names the guides,cli/api(no guides) still names its children,astryx docs theme quick-startis unchanged. Nothing here needs the pending topic split; it applies to any namespace. - Tests: the three named files pass 58/58; routing the namespace case back to the old failure fails 8 of the 10 new tests. The CLI README check passes.
- Changesets:
node scripts/release/changeset-coverage.mjs pr✓ (@astryxdesign/clinamed; released CLI JSON ids intact); rewording the unreleased #7125 note so it no longer says section reads stop resolving is the right correction. The ambiguity rule (several guides match → an error naming them rather than the first match) is the AST-046 owner's choice; AST-046 is still a draft record, so that choice is recorded for its amendment in #7210 and does not hold this restoration.
[Automated review]
There was a problem hiding this comment.
Thanks — the two fixes from the last round look right: a namespace read now returns exactly what the chosen guide's own section read returns (the "Shell contract" before "Shell" case included), and namespaces with no guides below them name their children again on a section miss. With those in, the implementation matches the proposed contract end to end — exactly-one guide answers in the guide's own payload shape by key and by title, in --dense and --zh too, and a query that matches several guides asks instead of guessing.
Approval still needs the maintainer spec decision. On main, AST-046 is a draft whose FR6 says a section argument on a namespace must fail; the contract this implements lives in the in-review spec update (#7210). A maintainer needs to land that governing claim on main — including the rule that an exact-key match in one guide outranks a title match in another — before this can be approved. Nothing needs to be removed or split for that, and no code changes are being requested in the meantime.
[Automated review]
User impact
Restored:
astryx docs layout side-panels, and every otherastryx docs layout <section>read, worked in 0.6.6 and have failed withERR_UNKNOWN_SECTIONsincelayoutbecame a docs-tree namespace. With this change, a section read on a namespace returns the section when exactly one guide below the namespace has it, so those reads work again. The same holds for any later topic split.New behavior, for a decision: when a section query matches sections in more than one guide (for example a title fragment two guides share), the read used to guess and now asks. A flat topic's section read returns its first title match; across guides, this read fails with
ERR_UNKNOWN_SECTIONand names each guide that matches, so the reader picks one. The choice lives in one function (oneGuide) with its own test, so returning the first match in tree order instead is a one-line change.Problem and solution fit
The fix reads the section from the guide that holds it, so the command keeps its meaning without the reader knowing the topic was split.
Expected behavior and authority
The docs-tree spec amendment in review (the change to AST-046 FR6) states the contract. A section read on a namespace returns the section when exactly one guide below it, at any depth, has it, found by key (its
id, else the key its title derives) or by title. The response is the guide's own section read (docs.detail.section). When no guide or several have it, the read fails withERR_UNKNOWN_SECTION, naming the guides that have it, or every guide when none does. A section read on a typed doc still fails, naming the doc.Smallest restoration
api/docs/docs.mjs: a section argument on a namespace goes to the new read; a typed doc still fails.api/docs/detail/section/section.mjs:namespaceSectionwalks the guides below the namespace in tree order. Each guide answers with the section its own section read returns for the query, so the namespace read returns exactly whatastryx docs <guide> <section>returns. When that section's key is the query in some guides, those guides answer first. A namespace with no guide below it (such ascli/api) names its children on a section read, as before. The response is built by the same code as a topic's section read, so the JSON shape, links,--denseand--zhall match.astryx docs layout <section>stops resolving.Evidence
astryx docs layout side-panelsfails with"layout" has no sections.--jsonreturns the samedocs.detail.sectionasastryx docs layout/side-panels side-panels, by key and by title, in--denseand--zhtoo.astryx docs theme quick-start) and the section read on a typed doc.api/docs/namespace-section.test.mjscovers layout reads by key and title, dense and zh, the guide's own answer when an earlier section's title contains the query and a later section's derived key equals it, a key match in one guide beating a title match in another, a miss naming every guide at any depth, a namespace with no guides naming its children, an ambiguous query naming each matching guide, andoneGuideon its own.Scope
Testing
npx vitest run packages/cli/api/docs/namespace-section.test.mjs packages/cli/api/docs/docs.test.mjs packages/cli/clients/cli/commands/docs.test.mjsvitest run --project node packages/cli) against bare main on the same machine: no failure specific to this change. Tests that differed between the two concurrent runs (theme build watch, theme doctor and provenance, search CLI) pass when rerun alone.node scripts/release/changeset-coverage.mjs pr: passes. The docs tree builds with 0 diagnostics.