test: move the writeOnly/required schema guard into pkg/registry - #162
Merged
Conversation
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.
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.
Repo tidy-up.
schema_invariants_test.gosat in the repository root inpackage main— the only schema-shape guard living there. Its two siblings arealready inside packages:
pkg/registry/nested_fieldhint_test.go— walksschema/pkl, guards nested@FieldHintwiringpkg/resources/listparam_contract_test.go— guards the listParam contractMoved to
pkg/registry/, and renamed towriteonly_required_test.goso it namesits invariant the way its neighbour does.
The part that mattered
The test did
filepath.WalkDir("schema/pkl", ...), which only worked because itran 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.goalready uses(
filepath.Abs(filepath.Join("..", "..", "schema", "pkl"))), and offender pathsare re-relativized so failure text reads exactly as before.
Proven, not assumed — reintroducing
required = truebeside the existingwriteOnly = trueonstorageAccountKeyinschema/pkl/operationalinsights/loganalyticsstorageinsightconfig.pkl:Reverting the schema file returns it to green. I ran that break/fix cycle
independently of the change itself.
What the guard is for
writeOnlymeans the provider never returns the value;requiredmakes corereject anything lacking it. Together, discovery finds the resource and then
throws it away — surfacing as a bare
[Discover] timeoutwith nothing pointingat 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.