Repository navigation
feat: generate docs explorer site from C# and Python ports - #672
Merged
Merged
Conversation
…nd Python manifests
After a write run, the hash manifest entry of a per-object file now names its
generator and the node's resolution key ({hash, generatedBy, sourceNode}, after
the JVM's generator/outputDir), as TypeScript already did, so a docs view built
from any of these ports lists each node's generated files. A whole-model file
keeps the plain hash. A shared 'provenance' vector in
fixtures/codegen-skip-conformance/manifests.json holds TypeScript, C#, Java and
Python to the same entries.
…ated on branch; one wording fix.
…VM, with no Node The JVM builds the port-neutral docs view from its loaded model (DocsView), byte for byte what TypeScript builds for every fixtures/explorer-conformance case, gated in the metadata suite. A docs-site generator (DocsSiteGenerator, registered in the Java and Kotlin registries, eject-exempt like TypeScript's) writes explorer.json, the shared explorer app, explorer-model.js and explorer-stamp.js, and lists each node's generated files from the hash manifest's provenance. Kotlin runs the same class, and its suite gates every corpus case through its own registry. MetaEndpoint gains the /_meta/docs helpers (body, ETag, If-None-Match), mounted by the host as /_meta is. Needs the HashManifest.loadProvenance API from #669.
…fm/mo-130-docs-view-jvm # Conflicts: # docs/features/explorer-site.md
…h dry-run cargo publish --workspace unpacks its overlay-registry dependencies into a per-checkout directory and never re-unpacks while the version is unchanged, so the self-hosted runner verified metaobjects-codegen against a metaobjects-1.3.0 unpacked before metamodel_docs existed. Main has been red on the rust lane since #670 for this reason; the crate itself packages correctly.
…t, and hold docs-site to the inert line The model and stamp scripts move beside the docs view serializer (com.metaobjects.docsview.ExplorerModelScript), so codegen-base types no line breaks (LayoutRatchetTest). The codegen-noop inert tests hold docs-site to the line TypeScript's rules-inert test draws: the explorer documents every node, so only its data payload may differ, and only by the new nodes and members.
…uild explorer.json
Each port builds the port-neutral docs view from its loaded model (MetaObjects.DocsView, metaobjects.docs_view), byte-identical to TypeScript for every fixtures/explorer-conformance case and gated in each suite. A docs-site generator in both registries writes explorer.json, the shared explorer app, explorer-model.js and explorer-stamp.js; it runs after every other generator and lists this run's files over the committed manifest's, so verify --codegen renders what gen wrote. MetaEndpoint.MetaDocs (C#) and meta_docs (Python) serve the same view at /_meta/docs with a strong ETag. C# and Python provenance now records the generator's registry name.
…s-py # Conflicts: # docs/features/explorer-data.md # docs/features/explorer-site.md # docs/features/metadata-api.md # fixtures/generator-registry-conformance/registry.json # server/csharp/MetaObjects.Codegen.Tests/HashManifestPerPackageTests.cs # server/csharp/MetaObjects.Codegen/CodegenRunner.cs # server/csharp/MetaObjects.Codegen/HashManifest.cs # server/python/src/metaobjects/codegen/runner.py # server/python/tests/codegen/test_manifest_store.py
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.
Validated in 1 no-mistakes run (5 review fix rounds, then test, document and lint passed).
What Changed
docs-sitegenerator to the C# and Python ports. It writesexplorer.json, the stamp file, the model script and the shared explorer app files, so a C# or Python project gets the docs explorer without Node. The explorer app is embedded inMetaObjects.Codegenand as package data in Python.DocsViewmodules in both ports (server/csharp/MetaObjects/DocsView/,server/python/src/metaobjects/docs_view.py) that build the port-neutral docs view in memory from the loaded model.MetaEndpoint(C#) andmeta_endpoint.py(Python) serve it beside/_metawith ETag/304 support, behind the same opt-in mount.docs-siteafter the other generators. Manifest provenance now recordsgeneratedByas the stable registry name (entity,filter-allowlist,routes) in both ports, matching TypeScript and Java.Validation
Risk Assessment
✅ Low: The round-5 fix makes C# and Python treat an empty file list inside a run as a known, empty list, which matches TypeScript's runDocsView and Java; the corpus test now drives the generator outside a run with the case's committed manifest (crm/model-alone expect files:false, shop expects true), and the drift cases assert the TS-oracle value.
Testing
Baseline configured test command passed and was not re-run. Drove three live scenarios with the real Python
metaobjectsCLI and the real C#dotnetCLI against a disposable copy of the shop fixture: fresh gen plus verify (both ports pass, files in sync); hand-edited explorer.json refused by gen and flagged by verify (both ports fail closed as designed). Byte-identity of explorer.json against the TypeScript reference and the /_meta-style docs-view endpoint ETag/304 were not driven live here; they are covered by the corpus and endpoint tests in the baseline. Overall: pass on driven scenarios.metaobjects genwith a docs-site target writes explorer.json and site files; freshverify --codegen --fullis in sync (shop model, local CLI)dotnetgen with a docs-site entry writes explorer.json; fresh verify --codegen --full is in sync (local CLI, in-repo codegen project)Evidence: C# fresh gen transcript
Evidence: C# fresh verify transcript
Evidence: C# gen after hand edit (refused)
Evidence: C# verify after hand edit (drift)
Evidence: Python-generated explorer.json from shop model
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
server/python/src/metaobjects/codegen/generators/docs_site_generator.py:199- Pythonverify --codegendoes not render whatgenwrote for docs-site, so a freshmetaobjects genfollowed bymetaobjects verify --codegenreports drift. The CLI's in-memory verify render calls_run_gen_targetswith noproject_rootand nogen_state_dir(cli.py:2649 and 2659).genpasses both (cli.py:2210-2213). For docs-site this has five effects. (1)knownis False, so the title is "Metadata" instead of the project directory's name, and explorer-model.js and explorer-stamp.js differ on every project that sets notitle. (2) runner.py_manifest_key(line 78) keys emitted files relative to the virtual out_dir (models/x.py), while gen keys them relative to the project (gen/models/x.py). The explorer.jsonfilespaths therefore differ. (3) Withgen_state_dirNone,_run_provenancecarries no manifest entries, so files from other targets or generators that gen listed are missing. (4) The owned theme and templates under codegen/docs-site/ are skipped (lines 212-213) andtemplates/is not searched for prompts (line 247). (5)verifyFileandroutesFileresolve against the process cwd instead of the project. The C# port fixes this withCodegenRunner.CaptureKeys(CodegenDrift.cs:151), which keys captured files by the real output directory and reads the real manifest. The intent states this as a decision ("in the drift gate (capture mode) files are keyed by the real output directory so verify --codegen renders what gen wrote"), and the changelog claims it for both ports. Sibling defect in the same path: in a multi-target Python project, every target runs its ownrun_genand the shared session saves the manifest only after the whole plan (cli.py ~1856)._run_provenancereads the manifest from disk (_read_union), so a docs-site in target B does not see the files target A wrote in this run. Two identicalgenruns on a fresh project then write different explorer.json files. The fix: give the verify render the real project root, gen-state dir and real-out-dir keying (the Python equivalent of CaptureKeys), and read carried provenance from the in-memory session (config.manifest) instead of disk. Add a Python test that runs gen and then verify --codegen with docs-site plus another generator, as C#'sThe_drift_gate_renders_what_gen_wrotedoes.server/csharp/MetaObjects.Codegen/CodegenRunner.cs:174-CarriedFilesbuilds the run's suite fromg.Name(entity-generator,routes-generator,filter-allowlist-generator, ...). The manifest'sgeneratedByis now the stable name (entity,routes,filter-allowlist; line 196 and line 223).!suite.Contains(prov.GeneratedBy)is therefore true for every file from those generators, even when they are in this run. The intent's rule is "Committed-manifest provenance is carried for generators not in this run", and that rule fails here. Effect: a file that a run generator no longer emits stays in explorer.json, because this run's entries overwrite only the keys they share. Concrete sequence: change an entity's output path or a generator's OutDir, then rundotnet meta gen. The orphan sweep deletes the old files and drops their manifest entries, but the docs site written in that run still lists the old paths under the object. The nextdotnet meta verify --codegencarries from the pruned manifest and reports explorer.json as drift. Python does this correctly (runner.py:256,_stable_name(g.name)). Fix:generators.Select(GeneratorRegistry.StableNameOf).server/python/tests/test_meta_endpoint.py- Intest_docs_etag_and_if_none_match, the assertionmeta_docs_etag("\u{0001}f600") == meta_docs_etag("😀".encode("utf-16", "surrogatepass").decode("utf-16"))compares the function with itself on the same string, because the encode/decode round-trip returns the input. It has no independent oracle and would still pass if Python hashed code points instead of UTF-16 code units, which would give a different ETag from the other ports. Replace it with the cross-port values C# pins from TypeScript and Java (MetaEndpointTests:"hello"gives"5-4f9f2cab","héllo ✓"gives"7-0579d2da"), plus a pinned value for a surrogate-pair string taken from the TypeScriptmetaDocsEtag.🔧 Fix applied.
1 error still open:
server/python/src/metaobjects/cli.py:1886- Round 1's fix (py-verify-codegen-docs-site-drift) closed the gen/verify mismatch only when the docs-site target is declared AFTER the code targets. It left two sibling paths in place. The Python runner runs areads_run_outputgenerator last only inside onerun_gencall (runner.py:244)._run_plan(cli.py:1886) still runs targets in declared order. A docs-site target therefore sees only what earlier targets wrote this run, plus the manifest as committed BEFORE this run (HashManifest.recorded_provenance, overwrite_policy.py:488).verify --codegenhas no session, so it reads the manifest from disk asgenleft it (runner.py:103).(1) Docs target declared first. Use
targets: {docs: {outDir: docs, generators: [docs-site]}, app: {outDir: gen, generators: [entity]}}on a fresh project. The firstgenruns docs before app, so explorer.json lists no entity files. Then app writesgen/...and saves provenance.verify --codegen --fullreads that manifest from disk and lists the entity files, so it reports explorer.json as drift. A secondgen --forcewrites a different explorer.json. Round 1 used exactly this symptom ("two identical gen runs on a fresh project then write different explorer.json"). The intent requires that the runner lists the run's files "whatever the declared order".(2) Docs target declared after the code target, and a code-target generator stops emitting a file for a node that still exists (for example, the app target's
outputLayoutchanges). The session still holds the old committed entry, because the orphan sweep runs only after the whole plan (cli.py:2236). The entry is carried because its generator is not in the docs target'ssuite, sogenlists the deleted path.verifythen reads the swept manifest and reports drift. The ADR-0064 skip can also keep the next plaingenfrom repairing explorer.json.The new parametrized test (test_docs_site_generator.py:153) covers only app-before-docs with no removed files, so it passes with both paths broken.
Fix at the plan level: run every target whose suite holds a
reads_run_outputgenerator after all other targets. Also exclude committed entries from generators that already ran in this plan unless this run re-noted them. Verify must apply the same rule, so give it an equivalent in-memory record of the captured provenance from earlier targets. Adddocs-firstandremoved-filecases to the parametrized test.🔧 Fix applied.
1 error still open:
server/python/src/metaobjects/codegen/runner.py:102- The docs site still lists files that the same run deletes. Round 2 (py-cross-target-docs-site-order) chose which committed files to carry by generator name:prov[0] not in ran. It did not use the orphan sweep's scope, so a sibling of round 2's path (2) remains.Path A, a generator removed from the list. This is routine. Remove
queriesfrom a target'sgeneratorsand rungen.queriesran nowhere in the plan, so_run_provenancecarries every committedqueriesentry, and docs-site writes explorer.json listing those paths. The orphan sweep runs after the whole plan (cli.py_sweep_orphans_after_gen). It deletes those files and drops their manifest entries.verify --codegen --fullthen reads the swept manifest, does not list the files, and reports explorer.json as drift. CI runs--fulland goes red. The local ADR-0064 skip may also answer "in sync" and keep the next plaingenfrom repairing the file.C# has the same defect: CodegenRunner.cs:262
CarriedFilescarries!suite.Contains(prov.GeneratedBy), and the sweep at CodegenRunner.cs:~226 runs after docs-site in the sameRun.Path B, the same generator in two targets (Python only). Use app1 {outDir gen1, [entity, docs-site], entities [A]} and app2 {outDir gen2, [entity], entities [B]}.
gen --target app1treatsentityas ran. Every committedentityentry is excluded, including app2's gen2 files, which this run neither renders nor sweeps. explorer.json loses B's files until a fullgen, and a fullverify --codegenreports drift in the meantime.Remedy: carry a committed entry only when this run's orphan sweep leaves it alone. That means the entry lies outside every outDir the run sweeps, or
--entitiesnarrows the run. Java does this (committedFilesBeside/OrphanSweep.isCandidate, commit 7a75c99). Entries inside a swept outDir are either re-emitted, and so already inplan.filesoremitted, or about to be deleted. Apply the rule in Python_run_provenance(runner.py:99-104), which gen and verify share, and in C#CarriedFiles(CodegenRunner.cs:257-264).Add a
removed-generatorcase to test_docs_site_generator.py's parametrized drift test and a C# counterpart. Each runs gen with [entity, queries, docs-site], dropsqueries, runs gen again, then asserts every listed path exists and thatverify --codegen --fullis clean. The currentremoved-filecase passes only becauseentitystill runs.🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
server/python/src/metaobjects/codegen/generators/docs_site_generator.py:215-DocsSiteGenerator._provenancetestsif ctx.run_provenance:. An empty dict is falsy, so the method falls back to reading the whole committed manifest with no filter. Round 3 (carry-deleted-orphans) made an empty list a normal result:_run_provenancenow drops every committed entry inside the sweep scope, which can leave nothing. Round 3 moved the 'never list a file the run removes' defect here and left this sibling in place.Concrete sequence:
gen. The manifest records gen/... entity files with their source nodes.gen. Nothing else is emitted, and every committed gen/ entry is in the sweep scope and excluded, so run_provenance == {}._provenancereads the raw manifest and lists the entity files in explorer.json._sweep_orphans_after_gendeletes those entity files and their manifest entries.verify --codegen --fullreads the swept manifest, also gets {}, falls back to it, lists nothing, and reports explorer.json as drift. The site also names files that no longer exist.C# does not have this bug:
ctx.GeneratedFiles ?? manifestfalls back only on null (DocsSiteGenerator.cs:69-70).Fix: change the test to
if ctx.run_provenance is not None:. Keep the manifest fallback only for a caller outside a run (None). Update the docstring, which still says 'with an empty list ... what the committed hash manifest records'. Add a case to test_the_drift_gate_renders_what_gen_wrote: [entity, docs-site] then [docs-site]. Assert that every listed path exists and thatverify --codegen --fullexits 0. The oracle is the existence of the files on disk after the sweep. The current code fails that check.docs/ports/csharp.md:1293- Applied inline. Three docs still described the round-2 carry rule: committed provenance carried 'for generators the run does not include'. Round 3 replaced it with 'outside the directories the run's orphan sweep clears'. I reworded docs/ports/csharp.md:1293, docs/features/explorer-site.md:76 and changelog.d/explorer-csharp-python.md:7-8 to match the code (CarriedFiles / _run_provenance using OrphanSweep.InScope / in_sweep_scope).🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
docs/ports/csharp.md:1293- Applied inline. Three docs still described the round-2 carry rule: committed provenance carried 'for generators the run does not include'. Round 3 replaced it with 'outside the directories the run's orphan sweep clears'. I reworded docs/ports/csharp.md:1293, docs/features/explorer-site.md:76 and changelog.d/explorer-csharp-python.md:7-8 to match the code (CarriedFiles / _run_provenance using OrphanSweep.InScope / in_sweep_scope).server/csharp/MetaObjects.Codegen/Generators/DocsSiteGenerator.cs:69- Round 5 (py-empty-run-provenance) went beyond the driver instruction and made the C# and Python ports disagree with the TypeScript reference. Both ports now return no file list (sources.files: false) whenever the run's file list is empty, even when a committed manifest exists. The instruction asked for that only when the list is empty AND the project has no committed manifest.The reference treats an empty run differently. In TypeScript,
runDocsView(server/typescript/packages/codegen-ts/src/docs-view-run.ts:37-56) passesmanifest: {}wheneverrunOutputis defined, sosources.filesis true. Java does the same:runFiles != null ? provenanceJson(runFiles)(DocsSiteGenerator.java:102-104), and Kotlin uses Java's generator.Concrete sequence: run
genwith [entity, docs-site], then rungenwith [docs-site]. TS, Java and Kotlin writesources.files: trueand list no files, so the explorer says "Nothing generated is traced to it." C# and Python writesources.files: false, so the explorer says "No generation manifest was read." That label is wrong, because the run's output was read.Round 5 also broke C#, which was correct before:
ctx.GeneratedFiles ?? manifestalready kept an empty list. Round 4's finding said so explicitly ("C# does not have this bug").The new tests assert the diverging value. They copy the implementation's rule and have no independent oracle:
A_site_generated_alone_lists_no_files_and_says_soassertsfilesis False.docs-alonecase, assertsview["sources"]["files"] is False.Other sites that must hold the same rule:
if not ctx.run_provenance: return None) and its docstring at :222-225.The Python corpus harness
_run(test_docs_site_generator.py:94-110) explains why the exception exists. It drives the crm and model-alone cases throughrun_gen, and those cases expectfiles: false. Under TypeScript semantics, a run is never 'no manifest read'.Fix:
files: truewith nothing listed. The oracle is TypeScript'srunDocsViewfor the same project.The [entity, docs-site] then [docs-site] drift case stays clean under this fix, because gen and verify share the rule.
🔧 Fix applied.
📝 1 wording or comment-placement note left for the author (no fix round spent):
docs/ports/csharp.md:1293- Applied inline. Three docs still described the round-2 carry rule: committed provenance carried 'for generators the run does not include'. Round 3 replaced it with 'outside the directories the run's orphan sweep clears'. I reworded docs/ports/csharp.md:1293, docs/features/explorer-site.md:76 and changelog.d/explorer-csharp-python.md:7-8 to match the code (CarriedFiles / _run_provenance using OrphanSweep.InScope / in_sweep_scope).✅ **Test** - passed
✅ No issues found.
metaobjects genwith a docs-site target writes explorer.json and site files; freshverify --codegen --fullis in sync (shop model, local CLI)dotnetgen with a docs-site entry writes explorer.json; fresh verify --codegen --full is in sync (local CLI, in-repo codegen project)scripts/ci-local.sh --affected --strict-toolchainsBaseline:scripts/ci-local.sh --affected --strict-toolchains(already passed at target commit; not re-run)Python: scratch project copied from fixtures/explorer-conformance/shop/project/metaobjects with targets app[entity] + docs[docs-site];metaobjects gen(exit 0, 17 files),metaobjects verify --codegen --full(exit 0, docs in sync 9 files)Python: appended line to docs/site/explorer.json;metaobjects genrefused it (exit 1, 'Refused to overwrite site/explorer.json');metaobjects verify --codegen --fullexit 1 with '[docs] generated code is out of sync'C#:dotnet buildof server/csharp/MetaObjects.Cli (exit 0); scratch codegen project scaffolded bydotnet MetaObjects.Cli.dll init, pointed at in-repo server/csharp/MetaObjects.Codegen via ProjectReference, with DocsSiteGenerator { OutDir = "docs" } and EntityGenerator added;dotnet run --project codegen -- gen metaobjects --out generated(exit 0, 17 files);verify ... --codegen --fullexit 0C#: appended line to docs/site/explorer.json; gen exit 1 with 'refused: docs/site/explorer.json'; verify exit 1 with '~ docs/site/explorer.json (committed content differs from a fresh regen)'Compared C# and Python explorer.json from their own projects: differences limited to per-language entity file names and generatedBy entries; not a byte-identity oracle, so not used as a passScratch projects under $DEV_SCRATCH removed; worktree git status clean✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.