Repository navigation
feat(op): a resource announces an interface and reflects on the struct behind it - #657
Conversation
|
Correction to this PR's body. It says "No generated file changed." That is false — - map[string][]string{
- "Equal": {"other"},
- "CanConvertFrom": {"source"},
- "ConvertFrom": {"value"},
- },
+ nil,What stayed true is the important half: the file still names Harmless here, and load-bearing later. For The rule it establishes for phases 2-5: a method that must be dispatchable has to be declared on the sealed interface, because the generator only sees what the exported type exposes. Worth noting the related status quo so the finding is not overstated: an announcement carrying Recorded on the plan and on #642. |
Phase 1 of #625. Closes #641.
The judgment scenario, red first
The forging test went in before the seal, and its failure is the argument for the whole feature:
Every identity field empty,
Namefilled from an author-supplied map.op.Convert's generic map-to-structhydration admits any target whose concrete kind is
reflect.Struct, so a dict where a resource is expectedreflectively minted one — and it reaches
sm.Disable(name.Name)against the host. Sealing removes the pathrather than policing it: the slot type becomes an interface, hydration declines, and conversion falls through
to the registered constructor. The test is green now.
The framework change
receiverTypecarried one type doing two jobs. Split:byTypekeytypeIDserves the twotypeIDOf(ProviderType()) == typeIDcomparisons that match an idlifted from a URI
NewMethodcannot consume an interface method at all —reflectgives one a nilFuncand aTypewith noreceiver, so
do.Type.In(0)returns the first parameter and panics outright for a no-arg method. Routingreflection back to the struct is what makes sealing possible; it is not an enumeration nicety.
No generated file changed. The announcement still names
provider.Resourceandprovider.DiscoverResource,both exported. The struct crosses the package boundary by registration instead —
op.RegisterResourceImplementation,called from the provider's own init. Ordering is guaranteed by the language: the generated package imports the
provider package, so Go initializes the provider first.
The receipt-retyping failure
Commitrecords whatcanonicalIDOfreports; restore resolves it through an index built from declared resulttypes. Two derivations of one identity, with nothing forcing agreement — they agreed only because the declared
return and the dynamic type were the same type. Sealing separates them.
The failure would have been silent:
retypeStampedResultisif !ok { return }, so a resumed run keeps theraw URI string instead of a resource. Fixed on both sides —
canonicalIDOfasks a resource for its announcedidentity, and the index is additionally keyed by that identity. Pinned in
pkg/op/inventory, which is where theregistry is populated, and the pin asserts resolution rather than asserting that a resume succeeded.
Serialization did not move
service's URI fragment is still…/provider/service.Resource, pinned byte-for-byte. Ruling 4 works exactlyas designed: the interface took the name the struct gave up, so
typeIDOfis unchanged.#649's deferral trigger, observed
op.Convertstep 7 no longer reachesConvertFromfor a resource slot —reflect.New(interface)yields apointer-to-interface with an empty method set, so the
TargetConverterprobe fails. Recorded as a test thatfails if it ever regains the ability to mint an identity-less resource. #649 can now be decided.
Four things phase 1 found that the plan had not predicted
bound to one is refused unless the interface names a claim type. Every later phase needs the same two lines.
op.Resourcedoes not expose everythingResourceBaseprovides —ReachabilityURI,Equal,Format,and the marshalers were reachable only because embedding leaked the base's surface. Every caller is
in-package, so the tests reach the struct rather than widening the exported contract. A later phase with an
out-of-package caller will have to decide differently.
test needing a populated registry belongs in
pkg/op/inventory. The first placement of the resolution pinwas wrong for exactly this reason.
RegisterResourceMint. That answers a differentquestion — what a bare authored string claims as — and the two coincide only for a single-implementation
interface.
filedesignates*file.AnyKindwhile having four implementations.All four are recorded in the plan, which now marks phase 1 complete.
Verification
make test103 ok / 0 fail ·make build·make vetdarwin/linux/windows ·make test-scenario·complexity·shell-lint·verify-ldflags·gofmt -l— all clean.