Skip to content

Inventory documented examples with the structured extractor - #4587

Open
evanchooly wants to merge 1 commit into
audits-section-rolesfrom
audits-structured-inventory
Open

evanchooly wants to merge 1 commit into
audits-section-rolesfrom
audits-structured-inventory

Conversation

@evanchooly

Copy link
Copy Markdown
Member

Step 2 of retiring the legacy RST extractor. Stacked on #4586.

Problem

The example inventory, documented-examples.json, came from the line-based RST extractor (FormMigration.pageExamples) over pages that fetch.py copied out of a docs checkout. That extractor reads one example per section and matches owners largely by title, and that hid several problems:

  • Stale owners. The docs rewrote many examples against the sample datasets. The $group page's "Pivot Data" now groups db.movies, but the inventory still recorded the old db.books fixture as its owner, because the title survived. 16 owners were stale this way.
  • Sections with several examples were read as one. $project's "Exclude Fields from Embedded Documents" shows the same exclusion with dot notation and with an embedded document. $regexFind shows each option form. Only one of each was in the inventory.
  • The weekly job depended on the old extractor. discover.sh ran fetch.py and the RST extractor, so it couldn't retire.

Change

  • GenerateMainKt plan drafts audits/catalog/scenario-plan.json from the parsed operator pages. It's reviewed policy, now committed. Each page that declares one operator (.. expression:: $add, read from the parser's target node) and has an examples section gets a rule:
    • the examples section, whose own code becomes shared setup when subsections follow it;
    • the page's non-driver tabs as scenario variants;
    • its bash highlighting as shell;
    • unlabeled code read as JavaScript.
  • GenerateMainKt inventory takes a source bundle and the parsed pages (DocumentsMainKt). It extracts the planned pages with the structured extractor (Classify section blocks by the shell grammar #4586) and keeps the existing owner matching:
    • titles follow the legacy spelling (main, <section> :: <tab>);
    • a new status, UNSUPPORTED, records why an example has no program.
  • discover.sh pins the manual into a bundle, parses the operator pages, inventories them under the committed plan, and reports a freshly drafted plan's plan.diff next to inventory.diff. fetch.py no longer runs.

Extraction fixes this needed

  • Sibling setup. A section that inserts in plain code and queries in an input/output block gives its inserts to that block; $graphLookup lost its data before.
  • Earlier inserts. A query on a collection an earlier section inserted runs against those inserts. $elemMatch's later sections query "the survey collection" from the section before.
  • Reads after writes. A read that follows a write in the same section (an update, $merge, $out, or a bulkWrite the page shows but no scenario runs) reports AFTER_EARLIER_WRITE instead of asserting the write's effect without running it.
  • Results after updates. What a page prints after an update goes to generation as that update's printed result, the convention the converted cases use. Option (c) replaces this in step 4.
  • Identical repeats. An identical example a page repeats (the same title, source and state), such as $setIntersection's query run for two users, is listed once.
  • Unreadable setup. An insert the grammar can't read makes the examples after it UNSUPPORTED_SETUP instead of running them without data. Inherited data never crosses such an insert, and inherited copies count against the extraction budgets.
  • Discovery keys. Discovery identifies a new example by its reviewed name, or else its title, plus a digest of its own source when it isn't unowned. Named siblings no longer collide, and a sibling added later doesn't re-report an example.
  • sql counts as a foreign language (pages show SQL equivalents).
  • Projection key order. The generator declares PROJECT_ID_FIRST when a projection's _id isn't its first key, since Morphia writes suppressId() first.

Result at docs e4b0c153

Legacy inventory Structured inventory
Pages 297 (3 skipped) 290 (7 without an examples section)
Owned 320 307
Unowned (generation candidates) 262 281
Unsupported (no program, with the reason) — 112

Generation produces 25 new cases. Three generated cases are replaced by better-named ones: $project's embedded-field and array examples, and $group's "Calculate Count, Sum, and Average", which the docs split into "Group by Year" and "Group by null".

Decisions for review

  • 60 proposed names in example-names.json. They're for examples that share a section's title, for example "Exclude an Embedded Field with Dot Notation" and "Exclude an Embedded Field with a Nested Document". A shared title names no owner. Please read through them.
  • 19 reviews dropped. Their examples no longer produce an action: the Queryable Encryption, change stream, diagnostic and Atlas pages, plus two owner reviews for examples the docs rewrote. 17 other reviews were re-keyed to the new action text. The $bucketAuto owner review is kept with the same digest.
  • One exclusion for a page error. $reduce's "Probability" inserts into events but aggregates probability. Two other page errors don't need exclusions: $mod's "Negative Dividend" and the positional "Update Documents in an Array" pass an array to insertOne, and the extractor now reports them as UNSUPPORTED_SETUP by itself.
  • Inherited inserts. The rule that a query inherits the most recent inserts into its collection, from any earlier section, is new. It assumes the page's examples share their data unless a section inserts its own.
  • Titles from heading text. Titles now come from the parsed heading text, so Bitwise OR with Two Integers reads "Bitwise OR with Two Integers". Stems don't change, but one display name does.

Verification

  • The audits suite passes, including new tests for plan drafting, sibling names, the structured inventory (GeneratorTest now builds parsed pages through ParsedPages), setup inheritance, native group setup, skipped writes and reads across groups.
  • The candidate integrated under Critter and reflection: 452 tests each, no failures. It is promoted, and a second candidate of the tree changes nothing.
  • Three local Codex rounds found 14 issues, all fixed with regression tests:
    • native groups getting later or unreadable setup;
    • inherited inserts losing their declarations, missing setup-only sections, crossing an unreadable insert, and escaping the budgets;
    • writes detected from strings;
    • deduplication dropping examples with different data;
    • declaration order in the generation handoff;
    • a data-less generated case;
    • discovery keys and the summary lookup.
  • Copilot CLI was out of quota.

Self-reviewed only: the independent reviewers are out of quota until 2026-11-26.

The example inventory came from the line-based RST extractor over pages
fetch.py copied out of a docs checkout. It read one example per section
and matched owners largely by title, so rewritten examples kept stale
owners and sections that show several examples lost all but one.

GenerateMainKt plan drafts the committed scenario-plan.json from the
parsed operator pages, and inventory extracts the planned pages with the
structured extractor, keeping the owner matching. discover.sh parses the
operator pages instead of running fetch.py, and reports plan drift.

The extractor gives a section's inserts to its input/output groups,
lets a query inherit the inserts into its collection from an earlier
section, and marks reads that follow a write. Sibling examples that
share a title get reviewed names; three page errors are excluded with
their evidence. Generation adds 27 cases, integrated under both mappers.

This branch has not been deployed

No deployments
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.

1 participant