Skip to content

test: move the writeOnly/required schema guard into pkg/registry - #162

Merged
naxty merged 1 commit into
mainfrom
naxty/move-schema-invariants-test
Sep 4, 2026
Merged

test: move the writeOnly/required schema guard into pkg/registry#162
naxty merged 1 commit into
mainfrom
naxty/move-schema-invariants-test

Conversation

@naxty

@naxty naxty commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Repo tidy-up. schema_invariants_test.go sat in the repository root in
package main — the only schema-shape guard living there. Its two siblings are
already inside packages:

  • pkg/registry/nested_fieldhint_test.go — walks schema/pkl, guards nested @FieldHint wiring
  • pkg/resources/listparam_contract_test.go — guards the listParam contract

Moved to pkg/registry/, and renamed to writeonly_required_test.go so it names
its invariant the way its neighbour does.

The part that mattered

The test did filepath.WalkDir("schema/pkl", ...), which only worked because it
ran from the repo root. Go tests run with the working directory set to the
package directory, so after the move that path resolves to nothing — and a
walk that finds zero files still passes
. The move could have silently disabled
the guard while looking green.

It now uses the same idiom nested_fieldhint_test.go already uses
(filepath.Abs(filepath.Join("..", "..", "schema", "pkl"))), and offender paths
are re-relativized so failure text reads exactly as before.

Proven, not assumed — reintroducing required = true beside the existing
writeOnly = true on storageAccountKey in
schema/pkl/operationalinsights/loganalyticsstorageinsightconfig.pkl:

--- FAIL: TestNoFieldIsBothWriteOnlyAndRequired
    Error: Should be empty, but was
      [schema/pkl/operationalinsights/loganalyticsstorageinsightconfig.pkl: storageAccountKey]
    Messages: these fields are both writeOnly and required, so discovery will
              drop the resource; drop `required` and make the property nullable

Reverting the schema file returns it to green. I ran that break/fix cycle
independently of the change itself.

What the guard is for

writeOnly means the provider never returns the value; required makes core
reject anything lacking it. Together, discovery finds the resource and then
throws it away — surfacing as a bare [Discover] timeout with nothing pointing
at the cause. That combination cost a full diagnosis cycle during wave 3. The doc
comment recording it is preserved verbatim.

Verification

make build, make test-unit, go test -tags=integration ./pkg/resources/,
make verify-schema, make verify-fixtures (593/593), go vet,
golangci-lint, REUSE lint — all pass.

No behaviour change; the assertions are untouched.

schema_invariants_test.go sat alone in the repo root under package main,
even though its two sibling schema-shape guards both live inside packages
(pkg/registry/nested_fieldhint_test.go and
pkg/resources/listparam_contract_test.go). pkg/registry already owns the
other test that walks schema/pkl, so this test belongs there too.

Moved with `git mv` to keep history, renamed to
pkg/registry/writeonly_required_test.go (a name that describes the
invariant being checked, since "schema_invariants" reads oddly sitting
next to nested_fieldhint_test.go), switched `package main` to `package
registry`, and matched the 2025 copyright year already used by the other
files in pkg/registry.

Go tests run with the working directory set to the package directory, so
the old relative `filepath.WalkDir("schema/pkl", ...)` would silently walk
nothing after the move and the test would pass vacuously. Replaced it with
the same `filepath.Abs(filepath.Join("..", "..", "schema", "pkl"))`
approach nested_fieldhint_test.go already uses, and reported offenders
with a path relative to schema/pkl again so failure output still reads the
same as before the move.

Proved the fix isn't neutered: with `required = true` temporarily added
next to `writeOnly = true` on `storageAccountKey` in
schema/pkl/operationalinsights/loganalyticsstorageinsightconfig.pkl, the
test fails and names that exact file and field
(schema/pkl/operationalinsights/loganalyticsstorageinsightconfig.pkl:
storageAccountKey); reverting the schema file makes it pass again. Doc
comment explaining why writeOnly+required is fatal to discovery is
preserved unchanged.
@naxty
naxty merged commit 48d3a48 into main Sep 4, 2026
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