Repository navigation
feat(schema): compose a plugin's served schema as a CUE module instance - #491
Merged
Merged
Conversation
sdk#490's first unit: a plugin's served schema is composed as ONE CUE module
instance instead of being compiled as package-less text in a context with no
module in scope. That text compile is why a plugin could not import
github.com/opencharly/spec/schema: it refused the import at the first clause
("package imported but not defined"), so no consumer could retire its local copy.
The composer (schema_compose.go) composes the concatenated schema body of the
plugin's embedded FS under a CUE module: the plugin's OWN cue.mod/module.cue when its
FS ships one, otherwise a derived declaration that pins the language version the spec
module declares and names github.com/opencharly/spec (with its major suffix) as the
one dependency. A modconfig.Registry serves that dependency from the embedded CUE
module the spec Go module already carries, so the compose is offline: no network, no
module cache, no cue.mod/pkg vendoring, and no local replace (the pinned modfile
schema has no such field). That dependency's source FS must implement
module.OSRootFS, so spec's module is materialized once at a content-named directory
under the system temp root — never the host tree — and every compose shares it.
ComposeServedText composes the package-less body that travels on
Capabilities.schema_cue. It runs the SAME compose under the derived declaration,
because the wire carries no module declaration: that is what makes the serve side and
the host agree byte for byte on the same schema, and it is asserted, not assumed.
BuildCapabilitiesWithRequires uses the composer. A schema that imports the spec
package now serves; a schema that imports nothing composes to the same value the
deleted text compile produced, which the tests assert twice — the canonical rendering
of both values is identical, and the two values judge the same document corpus the
same way.
The spec require moves to v0.2026313.48: the module declaration the composer reads is
exported by the spec module's root package, which the pinned version does not carry.
Item 3 of the issue (the param generator keeps a module) and item 4 (the
per-consumer units) are out of scope here; a plugin that imports spec still needs
those before its Go params can be generated from the same source.
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
Review — PASSHead SHA: Security screen: PASS Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
github-actions Bot
pushed a commit
to opencharly/spec
that referenced
this pull request
Nov 9, 2026
…ed schema (#297) * feat(schemacompose): the one module-aware compose for a plugin's served schema opencharly/sdk#490's composer lives here, in the contract module, and the placement is decided by a rule rather than by taste: charly core may import github.com/opencharly/spec and may NOT import github.com/opencharly/sdk (charly's import-purity gate: "the sdk mechanism kits + the sdk root plugin-authoring package are for PLUGINS to import, never the host"), while the sdk and every plugin import this module. Both halves of the contract — the serve side and the host gate — must judge the same schema with the same code, so the ONE composer has to live where both of them may reach it. This module also already owns the family it belongs to: schemaconcat, schemaparams, cuetoolchain, and the embedded schema source plus the module declaration. ServedSchema composes a plugin's concatenated schema body as ONE CUE module instance: the plugin's own cue.mod/module.cue when its FS ships one, otherwise a declaration derived from this module's pinned language.version and naming github.com/opencharly/spec@v0 as its one dependency. ServedText composes the package-less body that travels on Capabilities.schema_cue — the same compose under the derived declaration, because the wire carries no module declaration, so the declaration must be one both sides derive. A modconfig.Registry serves the dependency from the embedded CUE module this Go module already carries, so the compose is offline: no network, no module cache, no cue.mod/pkg vendoring, and no local replace (the pinned modfile schema has no path field). The loader requires that dependency's source FS to implement module.OSRootFS, so the module is materialized ONCE at a content-named directory under the system temp root — never the host tree — and every compose shares it. The registry matches on the base path, since the loader asks with the major-suffixed path. The tests assert the four properties the cutover rests on: an importing schema composes and the imported definition is ENFORCED (a violating document fails with its own constraint error, a conforming one passes); a non-importing schema composes to the SAME value the text compile produced (canonical rendering identical, and the same verdicts over a document corpus); the two entry points agree byte for byte; and the compose is deterministic, refuses an unservable dependency and a foreign language.version, and is safe under concurrent use. opencharly/sdk#491 landed a first copy of this composer in the sdk (tag v0.2026313.433); the sdk's next unit makes its public entry points delegate here and deletes that copy, so there is ONE implementation. The host gate follows it. Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated) * docs(schemacompose): the acceptance header names the failure direction correctly The file header said the arms would PASS without the fix — the opposite of what it documents three lines later, of the PR body, and of R7 (coverage must FAIL without the change). It is the copied opening from the sdk's first draft, where the sentence was a typo from the start; the validator read it against its own surroundings and was right. The three arms it introduces are unchanged: the import arm FAILS on the pre-fix path at the first import clause, the equality arm is the regression guard, and the agreement arm is the byte-for-byte half. Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
github-actions Bot
pushed a commit
that referenced
this pull request
Nov 9, 2026
…sdk delegates (#492) #491 put the module-aware compose for a plugin's served schema in this module. It cannot stay here: `charly/charly/import_purity_test.go` states the boundary as a tested invariant ("github.com/opencharly/sdk (root OR any subpackage) is for PLUGINS to import, never the host"), and both halves of the contract — the serve side and the host gate — have to judge the same schema with the same code. The ONE module both may import is github.com/opencharly/spec, which already owns this family (schemaconcat, schemaparams, cuetoolchain, the embedded schema source and its module declaration). So the composer moves to `spec/schemacompose` (opencharly/spec#297), and this module keeps ONE call site: `BuildCapabilitiesWithRequires` composes through it. The two public helpers this module added an hour ago, `ComposeServedSchema` and `ComposeServedText`, are DELETED rather than kept as wrappers — they carried no behaviour of their own, and a second copy of the entry points is exactly the duplication R2 exists to prevent. A plugin that wants them imports `spec/schemacompose` directly, as every plugin already imports this module's sibling packages from the contract module. The spec require moves to the release that carries the package. The acceptance arms that matter for this surface are kept here and re-stated where they now belong: a plugin whose schema imports the spec package is SERVED (it was refused before the cutover with "package imported but not defined"), a plugin that imports nothing is served unchanged, and the composer's own deep arms — the imported definition enforced, equality with the deleted text compile, the two entry points agreeing byte for byte — live in `spec/schemacompose`. Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
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.
Summary
Closes the composer half of #490 (its ordered roots 1 and 2 live in two repos because of the
module pin; this is the producer, and the host half follows it).
Every site that judged a plugin's served schema compiled it as package-less text in a context
with no CUE module in scope. So a plugin could not
import "github.com/opencharly/spec/schema":the compile refused the import at its first clause, and adding a
cue.modon the consumer sidechanged nothing — the module was never in scope — while a second failure waited behind it, because
N units concatenated into one file put N import clauses in one compilation unit, which is not CUE
at all.
This lands the composer in the sdk, which is where it belongs: both halves of the contract must
judge the same schema with the same code.
schema_compose.gocomposes the plugin's concatenatedschema body as one CUE module instance, and
BuildCapabilitiesWithRequiresuses it instead ofCompileString.What the compose does:
cue.mod/module.cuewhen its embedded FS ships one,otherwise a derived declaration that pins the language version the spec module declares and
names
github.com/opencharly/spec@v0as its one dependency. A plugin's own declaration is usedverbatim after ONE check: its
language.versionmust be the spec module's. The check existsbecause the host composes the same body under the derived declaration (the wire carries no module
declaration), so a plugin evaluated under different semantics on the two sides would be judged
twice, differently.
modconfig.Registryfrom the embedded CUE module the spec Go modulealready carries — offline: no network, no module cache, no
cue.mod/pkgvendoring, and no localreplace(the pinned modfile schema admitssource!: kind!: "self" | "git"and no path field).The loader requires that dependency's source FS to implement
module.OSRootFS, because it mapsan imported package to an absolute directory, so spec's module is materialized ONCE at a
content-named directory under the system temp root — never the host tree — and every compose
shares it. The registry matches on the base path, since the loader asks with the major-suffixed
path.
ComposeServedTextcomposes the package-less body that travels onCapabilities.schema_cue, using the SAME compose under the derived declaration. That is whatlets the serve side and the host agree byte for byte, and it is asserted, not assumed.
Equality with today's behaviour. A plugin that imports nothing composes to the value the
deleted text compile produced. Asserted twice: the canonical rendering of both values is
identical, and both judge the same corpus of documents (conforming and violating) identically.
go.modmoves the spec require tov0.2026313.48— the version that exports the moduledeclaration the composer reads.
Out of scope, stated plainly. #490's ordered roots 3 (the param generator keeps a module) and
4 (the per-consumer units) are not here; a plugin that imports spec still needs those before its
Go params can be generated from the same source. The host gate —
compileBasePlusServedmust stopjoining unit sources — is in
opencharly/charly, which pins this module: it is the next unit, itcalls this composer, and it needs this tag first.
Files
schema_compose.goschema_compose_test.goschema.goBuildCapabilitiesWithRequirescomposes instead ofCompileString; the doc comment says what the contract is nowmeta.gogo.modgithub.com/opencharly/specmoves tov0.2026313.48(the root package that exports the module declaration), plus the indirect requires it declaresgo.sumHow tested
The sdk's change gate is its CI (
.github/workflows/ci.yml), run here on the committed treebdb44cb5fad88cde846f30ecfa68e4b3d10d8d9b:go test ./...covers every package of the module (okon all 19).The imported definition is enforced (the arm that matters):
No regression for a plugin that does not import — the guard, on a restating plugin:
The two halves agree (serve side from the schema FS, host side from the wire body):
R7 — the arm fails without the change. Restoring
origin/main'sschema.go(the text compile)and keeping the new tests:
The same text compile is what the host's gate ran, and the joined-units shape it fed —
expected label or ':', found 'STRING'— is the second, independent failure #490 measured; the host unitthat replaces it is the next one.
Rulebook compliance
golangci-lintwhose own Go build could not read the host toolchain's export data) was traced toa toolchain mismatch and re-run under the
go.modtoolchain (1.26.8), which is what the workflowpins. It is not a finding about this diff.
than kept beside the new path, and both entry points run
composeServedBody, so there is nosecond implementation to drift.
dependency the offline registry does not serve is a hard error naming the module.
grep -rn 'cuecontext.New().CompileString' --include=*.go . | grep -v _test.goreturns nothing(
rc=1). Two deliberate survivors, both named so the grep is not read as wider than it is: theequality guard in
schema_compose_test.gocalls it ON PURPOSE, as the baseline it compares thecomposed value against, and
loaderkit/cue_schema.gokeepscueSchemaCtx().CompileStringforthe config loader's OWN base schema — a different mechanism, no import, not one of a plugin schema cannot cite spec: all four compile sites are text, so a cue.mod plus an import makes the plugin fail to start #490's four
sites.
golangci-lintv2.13.2, four-arch cross-compile), all run on the committed tree.
Change classification
Library change in the plugin contract module; the sdk ships no binary and no image, so there is no
disposable bed in this repo's gate.
imports the spec schema now serves instead of failing at start-up; its Go params are still
generated by the text pipeline until a plugin schema cannot cite spec: all four compile sites are text, so a cue.mod plus an import makes the plugin fail to start #490's root 3 lands, so this change enables nothing on its
own and is the producer for the host unit.
and its acceptance for every schema shape that composed before, so nothing has to change on the
consumer side.
consumer where it was.
Filed issues
None.
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)