Skip to content

feat(schema): compose a plugin's served schema as a CUE module instance - #491

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/schema-compose-module
Nov 9, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/schema-compose-module

Conversation

@aitrawog

@aitrawog aitrawog commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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.mod on the consumer side
changed 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.go composes the plugin's concatenated
schema body as one CUE module instance, and BuildCapabilitiesWithRequires uses it instead of
CompileString.

What the compose does:

  • Module declaration. The plugin's own cue.mod/module.cue when its embedded FS ships one,
    otherwise a derived declaration that pins the language version the spec module declares and
    names github.com/opencharly/spec@v0 as its one dependency. A plugin's own declaration is used
    verbatim after ONE check: its language.version must be the spec module's. The check exists
    because 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.
  • Dependency. Served by a modconfig.Registry from the embedded CUE module the spec Go module
    already carries — offline: no network, no module cache, no cue.mod/pkg vendoring, and no local
    replace (the pinned modfile schema admits source!: kind!: "self" | "git" and no path field).
    The loader requires that dependency's source FS to implement module.OSRootFS, because it maps
    an 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.
  • Agreement. ComposeServedText composes the package-less body that travels on
    Capabilities.schema_cue, using the SAME compose under the derived declaration. That is what
    lets 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.mod moves the spec require to v0.2026313.48 — the version that exports the module
declaration 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 — compileBasePlusServed must stop
joining unit sources — is in opencharly/charly, which pins this module: it is the next unit, it
calls this composer, and it needs this tag first.

Files

File Change
schema_compose.go the composer: one compose, two entry points, offline spec module registry, materialization, derived and own module declaration
schema_compose_test.go accepts the import and enforces the imported definition, equality with the deleted text compile, serve/host agreement, own-module, foreign-language-version refusal, determinism, unservable dependency, concurrency
schema.go BuildCapabilitiesWithRequires composes instead of CompileString; the doc comment says what the contract is now
meta.go the shared meta doc comment follows the same contract
go.mod github.com/opencharly/spec moves to v0.2026313.48 (the root package that exports the module declaration), plus the indirect requires it declares
go.sum the hashes for that version

How tested

The sdk's change gate is its CI (.github/workflows/ci.yml), run here on the committed tree
bdb44cb5fad88cde846f30ecfa68e4b3d10d8d9b:

$ test -z "$(gofmt -l .)";                                   echo "gofmt rc=$?"
gofmt rc=0
$ go vet ./...   > /tmp/sdk-vet-head.log 2>&1;                echo "vet rc=$?"
vet rc=0
$ go test ./...  > /tmp/sdk-test-head.log 2>&1;               echo "test rc=$?"
test rc=0
$ golangci-lint run ./...   # v2.13.2, the pin in that workflow
0 issues.
$ for a in amd64 arm64 arm 386; do GOOS=linux GOARCH=$a CGO_ENABLED=0 go build ./...; done
amd64 rc=0
arm64 rc=0
arm rc=0
386 rc=0

go test ./... covers every package of the module (ok on all 19).

The imported definition is enforced (the arm that matters):

$ go test -run TestComposeServedSchemaEnforcesAnImportedSpecDefinition -v .
    schema_compose_test.go:130: violating spec.#TunnelConfig ->
        #TunnelInput.provider: conflicting values 5 and string (mismatched types int and string)
    schema_compose_test.go:138: violating spec.#TunnelPort ->
        #TunnelInput.ports.0.port: conflicting values "eighty" and int (mismatched types string and int)
    schema_compose_test.go:145: conforming spec.#TunnelConfig -> err = <nil>
--- PASS

No regression for a plugin that does not import — the guard, on a restating plugin:

$ go test -run TestComposeServedSchemaMatchesTheLegacyTextCompile -v .
--- PASS   # canonical rendering identical, and five documents judged identically by both values

The two halves agree (serve side from the schema FS, host side from the wire body):

$ go test -run TestComposeServedTextMatchesComposeServedSchema -v .
    --- PASS: TestComposeServedTextMatchesComposeServedSchema/restating
    --- PASS: TestComposeServedTextMatchesComposeServedSchema/importing

R7 — the arm fails without the change. Restoring origin/main's schema.go (the text compile)
and keeping the new tests:

$ git show origin/main:schema.go > schema.go
$ go test -run TestBuildCapabilitiesServesAnImportingSchema -v .
    schema_compose_test.go:236: BuildCapabilities must accept a plugin schema that imports spec:
        plugin schema does not compile: package "github.com/opencharly/spec/schema"
        imported but not defined in  (and 1 more errors)
--- FAIL
test rc=1

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 unit
that replaces it is the next one.

Rulebook compliance

  • R1 — no finding: every gate above is green, and the one environmental anomaly (a local
    golangci-lint whose own Go build could not read the host toolchain's export data) was traced to
    a toolchain mismatch and re-run under the go.mod toolchain (1.26.8), which is what the workflow
    pins. It is not a finding about this diff.
  • R2 — one compose, two entry points; the text compile is DELETED from the serve surface rather
    than kept beside the new path, and both entry points run composeServedBody, so there is no
    second implementation to drift.
  • R3 — no sleep, retry or fallback: a schema that does not compose is a hard error; a
    dependency the offline registry does not serve is a hard error naming the module.
  • R5 — the retired production call site is gone, claim-keyed:
    grep -rn 'cuecontext.New().CompileString' --include=*.go . | grep -v _test.go returns nothing
    (rc=1). Two deliberate survivors, both named so the grep is not read as wider than it is: the
    equality guard in schema_compose_test.go calls it ON PURPOSE, as the baseline it compares the
    composed value against, and loaderkit/cue_schema.go keeps cueSchemaCtx().CompileString for
    the 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.
  • R7 — pasted above: the import arm fails on the pre-change tree with exit code 1.
  • R10 — the change's own gate for this repo is its CI matrix (gofmt, vet, unit tests, golangci-lint
    v2.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.

  • Consumers: a plugin that imports nothing is unaffected — proved, not asserted. A plugin that
    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.
  • The public Go surface only gains two functions; the existing entry point keeps its signature
    and its acceptance for every schema shape that composed before, so nothing has to change on the
    consumer side.
  • Reversing it: the commit is additive; moving the spec require back is enough to leave every
    consumer where it was.

Filed issues

None.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

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)
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Review — PASS

Head SHA: bdb44cb5fad88cde846f30ecfa68e4b3d10d8d9b (branch: feat/schema-compose-module)

Security screen: PASS
Checklist: All applicable rules PASS or NA. (Change class: library code + go.mod bump; gate is the repo's CI — sdk ships no binary/bed. Tool-limited cross-checks: pasted CI output is internally consistent with the diff; the R7 fail-without-change arm is shown; comment thread is empty.)

Verdict: PASS


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) November 9, 2026 04:33
@github-actions
github-actions Bot merged commit 34c6b58 into main Nov 9, 2026
8 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Nov 9, 2026
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)
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