Skip to content

openapi: two schema composition tests assert less than their names claim #742

Description

@OmarAlJarrah

Problem

Two tests in compilers/openapi/internal/schema/compose_test.go cannot fail for the reason they were written.

  • TestUnionCombinators_CoDeclaredKeepsTheBoundsWrittenBesideIt declares a wantDiag column and, after its other assertions, checks that the openapi/degraded-construct diagnostic at /components/schemas/A contains it. No case sets wantDiag, so every case returns before that check. The last case that set it ("kept minimum as the tighter of the two", added in fix(compilers/openapi): keep bounds beside a preserved union #363) was removed in feat(ir)!: land the IR 0.4.0 stack #464, which left the column and the branch in place.
  • TestAllOf_BoolBranchSkippedInCompositionRequired exercises the bs == nil guard in compositionRequired (compose.go), which skips an allOf branch that is a bare boolean schema. The guard has no observable effect: GetRequired is nil-safe, so without it the loop appends nothing for that branch either. Deleting the guard leaves the package green.

Reproduction

$ git grep -n 'wantDiag' -- compilers/openapi/internal/schema/compose_test.go

prints the field, the if tc.wantDiag == "" early return and the assert.Contains, and no case literal.

For the guard, delete the three lines of if bs == nil { continue } in compositionRequired and run:

$ go test ./compilers/openapi/internal/schema/ -count=1
ok  	github.com/dexpace/morphic/compilers/openapi/internal/schema

Why it matters

The wantDiag column reads as coverage of what reading the co-declared bounds reports, and nothing checks it. A change that stops reporting, or reports the wrong thing, passes.

The guard is harmless, but it is the only reason the bool-branch test's name points at compositionRequired: the test pins the lowered result, which holds with or without it.

Options

  • Give the union-combinators table a case that sets wantDiag to what the bounds reading reports today, or drop the column and the branch if it reports nothing worth pinning.
  • Delete the guard, since the code reads the same without it, or keep it and name the test for the behaviour it pins.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:P4Off the first emitter's path

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions