Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog.d/explorer-app-stable-bundle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- **The explorer app's bundle builds the same bytes every time.** `explorer-app/assets/explorer-app.js`
is now minified for whitespace and syntax only, and keeps its identifiers' names. Bun's choice of
short names was not stable between builds of unchanged sources, so the check that the committed
bundle is what the sources build failed at random. The bundle grows from about 95 KB to about
120 KB. Every port's copy is refreshed, so the docs site's `assets/explorer-app.js` changes and
nothing else does. Generated-output change — regenerate to pick it up; three-way merge preserves
hand edits.
10 changes: 10 additions & 0 deletions changelog.d/generated-file-provenance-all-ports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- **C#, Java and Python codegen record which node each generated file came from.** After a write
run, the hash manifest entry of a per-object file names its generator and the node's resolution
key, `{ "hash", "generatedBy", "sourceNode" }` (after the JVM's `generator` and `outputDir`),
exactly as TypeScript already wrote it. A docs view built from any of these ports' manifests now
lists each node's generated files, so the explorer's "generated files" panel is filled. A file
rendered from the whole model or a package keeps the plain hash. The shared `provenance` vector in
`fixtures/codegen-skip-conformance/manifests.json` holds all four ports to the same entries.

Upgrading: the next `gen` rewrites the committed `.metaobjects/.gen-state/.hashes/` files once,
adding the two fields to each per-object entry. Commit them; generated source files do not change.
21 changes: 13 additions & 8 deletions docs/features/explorer-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ comes from the `node` field. The structured payload is TypeScript-only, as the r

### Node provenance in the manifest

Each generated file now records the metadata node it was rendered from. A generator built with
`perEntity` sets this automatically. An `EmittedFile` can also name its node directly with
`sourceNode`, which is a node resolution key such as `acme::shop::Order`. `meta gen` then
writes that file's manifest entry in object form:
Each generated file now records the metadata node it was rendered from, in TypeScript, C#,
Java and Python. A per-object generator sets this automatically (TypeScript `perEntity`, C#
`PerEntityGenerator`, Python `per_entity`, and the shared writer the Java generators use). A
generated file can also name its node directly (`sourceNode` on a TypeScript `EmittedFile`,
`SourceNode` in C#, `source_node` in Python), as a node resolution key such as
`acme::shop::Order`. A write run then writes that file's manifest entry in object form:

```json
{
Expand All @@ -116,8 +118,11 @@ manifest reader takes `hash` from either form.

The provenance field is named `generatedBy`, not `generator`. In a Java or Kotlin module's
manifest, `generator` means that generator owns the file (ADR-0060), and the orphan sweep acts
on that ownership. TypeScript does not make that claim. TypeScript is the only port that writes
provenance today, and the JVM rewrites its manifest without these fields.
on that ownership, so a JVM entry carries both: `{ "hash", "generator", "outputDir",
"generatedBy", "sourceNode" }`. The four ports that write provenance write the same entry for the
same records; the shared vector `provenance` in
[`fixtures/codegen-skip-conformance/manifests.json`](../../fixtures/codegen-skip-conformance/manifests.json)
holds TypeScript, C#, Java and Python to it. Kotlin and Rust write no provenance yet.

## Building it by hand

Expand Down Expand Up @@ -151,8 +156,8 @@ malformed leaves its part of the view empty.

- **`usage`**: which hand-written modules import a generated module. The design marks it
optional, and nothing builds it yet.
- **Provenance from the JVM, Python and C# generators.** Their manifests have no `sourceNode`
yet, so for those ports a node lists no files.
- **Provenance from the Kotlin and Rust generators.** Their manifest entries have no
`sourceNode` yet, so for those ports a node lists no files.
- **The docs view in the other ports.** TypeScript builds it today; the corpus is what the
other ports will be held to.

Expand Down
2 changes: 1 addition & 1 deletion docs/features/explorer-site.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ a dangling link. `createExplorer` (the page table both outputs draw from) and
`explorer-app/README.md`), and each port's docs-site generator is still to write them.
- "Hand-written code that imports it": the site reads no import graph, so the object pages say
it was not scanned.
- Generated-file provenance from the JVM, Python and C# generators (see
- Generated-file provenance from the Kotlin and Rust generators (see
[explorer-data.md](explorer-data.md)), so for those ports the generated-file lists are empty.

## Verified by
Expand Down
5 changes: 3 additions & 2 deletions docs/features/own-your-codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,9 @@ overwritten; an edited one is refused by name (`<handEdits>keep</handEdits>`, th
replaced (`<handEdits>overwrite</handEdits>`). There is **no three-way merge**
(TypeScript-only). **Commit the manifest.**

A TypeScript entry can also carry the node the file was rendered from,
`{ "hash", "generatedBy", "sourceNode" }`. That is provenance, not ownership, which is why it
An entry can also carry the node the file was rendered from,
`{ "hash", "generatedBy", "sourceNode" }`; the TypeScript, C#, Java and Python runs write it
(on the JVM after `generator` and `outputDir`). That is provenance, not ownership, which is why it
does not use the JVM's `generator` field. Every reader takes `hash` from either form. See
[explorer-data.md](explorer-data.md#node-provenance-in-the-manifest).

Expand Down
3 changes: 2 additions & 1 deletion explorer-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ bash scripts/sync-explorer-app.sh # refres
The `explorer app copies` step of `scripts/ci-local.sh --only gates` fails when this directory is
stale or a port's copy differs from it.

The bundle is minified, and minified output depends on the Bun version, so `build-app.ts` runs
The bundle is minified for whitespace and syntax only. Identifiers keep their names, because
Bun's short names are not stable between builds. Minified output depends on the Bun version, so `build-app.ts` runs
only on the Bun the workflows pin (`EXPLORER_APP_BUN` in the script, currently 1.3.14). Any other
Bun stops with an error that names the required version.

Expand Down
16 changes: 8 additions & 8 deletions explorer-app/assets/explorer-app.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions fixtures/codegen-skip-conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ vectors in `manifests.json` are run by each port's manifest unit tests, beside t
is one file's bytes in full), the legacy file is removed, and a second identical write changes no
file. `gitignoreBefore` becomes `gitignoreAfter`; a file that already holds the new line, or has no
`.gen-state/*` rule, is left alone.
- `provenance`: which generator, and which node, each recorded path came from (the docs view's
generated files). Seed `beforeFiles` as the `.hashes/` directory, record `records` with `objects`
as the loaded model, and the directory must hold exactly `afterFiles` (`goldenText` is one file's
bytes in full). A record with a `sourceNode` makes the entry `{ "hash", <other fields kept>,
"generatedBy", "sourceNode" }`; one without returns it to the plain hash; a path with no recorded
hash is left out. Recording the same records again changes no file. TypeScript, C#, Java and
Python run it.

A port's tests also assert what the vectors cannot: two writes that change entries in two packages
change two files and no third, a save that changes nothing writes nothing, a package that loses its
Expand Down
108 changes: 107 additions & 1 deletion fixtures/codegen-skip-conformance/manifests.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$comment": "ADR-0064 Amendment 1. Every port with hash state runs these vectors against its own manifest store: fileNames (a package's manifest file name), placement (which manifest a path is filed under, given the loaded objects) and legacySplit (a legacy .hashes.json becomes these package files, byte for byte, and is removed). 'package': null is the root manifest (.root.json). A manifest file's text is the object with keys sorted, two-space indentation and a trailing newline ('goldenText' is one file in full).",
"$comment": "ADR-0064 Amendment 1. Every port with hash state runs these vectors against its own manifest store: fileNames (a package's manifest file name), placement (which manifest a path is filed under, given the loaded objects), legacySplit (a legacy .hashes.json becomes these package files, byte for byte, and is removed) and provenance (which generator and node each recorded path came from). 'package': null is the root manifest (.root.json). A manifest file's text is the object with keys sorted, two-space indentation and a trailing newline ('goldenText' is one file in full).",
"version": 1,
"objects": [
{
Expand Down Expand Up @@ -277,5 +277,111 @@
"goldenText": "{\n \"gen/Order.ts\": \"h1\",\n \"gen/OrderDto.java\": {\n \"hash\": \"h2\",\n \"generator\": \"java:dto\",\n \"outputDir\": \"gen\"\n }\n}\n",
"gitignoreBefore": ".gen-state/*\n!.gen-state/.hashes.json\n",
"gitignoreAfter": ".gen-state/*\n!.gen-state/.hashes/\n"
},
"provenance": {
"$comment": "Generated-file provenance (the docs view's 'files'): after a write run, each recorded path's entry names the generator that wrote it and, for a file rendered from one node, that node's resolution key. A port seeds 'beforeFiles' as its .hashes/ directory, records 'records' (with the vectors' 'objects' as the loaded model), and must then hold exactly 'afterFiles'. A record with a sourceNode makes the entry { hash, <other fields kept in order>, generatedBy, sourceNode }; one without returns the entry to the plain hash (or to { hash, <other fields> } when it has owner fields); a path with no recorded hash is left out; the sourceNode then places the entry. 'goldenText' is one file's bytes in full. Recording the same records a second time changes no file.",
"beforeFiles": {
"acme.shop.json": {
"gen/Order.ts": "h1",
"gen/OrderDto.java": {
"hash": "h2",
"generator": "java:dto",
"outputDir": "gen"
}
},
"acme.crm.json": {
"gen/Customer.ts": {
"hash": "h3",
"generatedBy": "entity",
"sourceNode": "acme::crm::Customer"
}
},
"acme.billing.json": {
"gen/Invoice.ts": "h5"
},
"gone.json": {
"gen/index.ts": {
"hash": "h4",
"generatedBy": "barrel",
"sourceNode": "gone::X"
}
},
".root.json": {
"gen/Item.ts": "h6"
}
},
"records": [
{
"path": "gen/Order.ts",
"generatedBy": "entity",
"sourceNode": "acme::shop::Order",
"why": "a per-object file gains its generator and node"
},
{
"path": "gen/OrderDto.java",
"generatedBy": "dto",
"sourceNode": "acme::shop::Order",
"why": "the JVM owner fields stay, before the provenance"
},
{
"path": "gen/index.ts",
"generatedBy": "barrel",
"why": "a whole-model file returns to the plain hash and is placed by its stem"
},
{
"path": "gen/Customer.ts",
"generatedBy": "entity",
"sourceNode": "acme::crm::Customer",
"why": "already recorded so: unchanged"
},
{
"path": "gen/Item.ts",
"generatedBy": "entity",
"sourceNode": "acme::crm::Item",
"why": "the sourceNode places a file the stem cannot"
},
{
"path": "gen/Missing.ts",
"generatedBy": "entity",
"sourceNode": "acme::shop::Missing",
"why": "no recorded hash: provenance never records a write"
}
],
"afterFiles": {
"acme.shop.json": {
"gen/Order.ts": {
"hash": "h1",
"generatedBy": "entity",
"sourceNode": "acme::shop::Order"
},
"gen/OrderDto.java": {
"hash": "h2",
"generator": "java:dto",
"outputDir": "gen",
"generatedBy": "dto",
"sourceNode": "acme::shop::Order"
}
},
"acme.crm.json": {
"gen/Customer.ts": {
"hash": "h3",
"generatedBy": "entity",
"sourceNode": "acme::crm::Customer"
},
"gen/Item.ts": {
"hash": "h6",
"generatedBy": "entity",
"sourceNode": "acme::crm::Item"
}
},
"acme.billing.json": {
"gen/Invoice.ts": "h5"
},
".root.json": {
"gen/index.ts": "h4"
}
},
"goldenFile": "acme.shop.json",
"goldenText": "{\n \"gen/Order.ts\": {\n \"hash\": \"h1\",\n \"generatedBy\": \"entity\",\n \"sourceNode\": \"acme::shop::Order\"\n },\n \"gen/OrderDto.java\": {\n \"hash\": \"h2\",\n \"generator\": \"java:dto\",\n \"outputDir\": \"gen\",\n \"generatedBy\": \"dto\",\n \"sourceNode\": \"acme::shop::Order\"\n }\n}\n"
}
}
Loading
Loading