@@ -42,14 +42,21 @@ var (
4242)
4343
4444// testPlugin implements Plugin plus whichever of Produces/Consumes the test
45- // populates, mirroring how real plugins opt into each role.
45+ // populates, mirroring how real plugins opt into each role. The scope registry
46+ // is keyed by typed name, so tests that must not see another test's spec set a
47+ // distinct name.
4648type testPlugin struct {
49+ name string
4750 produces map [fwkplugin.DataKey ]any
4851 consumes * fwkplugin.DataDependencies
4952}
5053
5154func (p * testPlugin ) TypedName () fwkplugin.TypedName {
52- return fwkplugin.TypedName {Type : "testPlugin" , Name : "mock" }
55+ name := p .name
56+ if name == "" {
57+ name = "mock"
58+ }
59+ return fwkplugin.TypedName {Type : "testPlugin" , Name : name }
5360}
5461
5562type producerPlugin struct { testPlugin }
@@ -79,6 +86,7 @@ func scopeProducerConsumer(t *testing.T, endpoint fwksched.Endpoint) (fwksched.E
7986 plug := & producerConsumerPlugin {}
8087 plug .produces = map [fwkplugin.DataKey ]any {producedKey : nil }
8188 plug .consumes = & fwkplugin.DataDependencies {Optional : map [fwkplugin.DataKey ]any {consumedKey : nil }}
89+ RegisterScopeSpecs ([]fwkplugin.Plugin {plug })
8290 scoped , violation := Scope (testLogger (), "test-extension-point" , plug , []fwksched.Endpoint {endpoint })
8391 require .Len (t , scoped , 1 )
8492 return scoped [0 ], violation
@@ -115,6 +123,7 @@ func TestScope_ViolationsAreSharedAndReportTheFirstWrite(t *testing.T) {
115123
116124 plug := & producerPlugin {}
117125 plug .produces = map [fwkplugin.DataKey ]any {producedKey : nil }
126+ RegisterScopeSpecs ([]fwkplugin.Plugin {plug })
118127 scoped , violations := Scope (testLogger (), "test-extension-point" , plug , endpoints )
119128
120129 first := fwkplugin .NewDataKey ("first-undeclared" , "otherPlugin" )
@@ -162,7 +171,9 @@ func TestScope_GetHonoursConsumesAndProduces(t *testing.T) {
162171// the case that previously fell through to unrestricted reads.
163172func TestScope_PluginDeclaringNothingReachesNothing (t * testing.T ) {
164173 endpoint := newEndpoint (t )
165- scoped , violation := Scope (testLogger (), "test-extension-point" , & testPlugin {}, []fwksched.Endpoint {endpoint })
174+ plug := & testPlugin {}
175+ RegisterScopeSpecs ([]fwkplugin.Plugin {plug })
176+ scoped , violation := Scope (testLogger (), "test-extension-point" , plug , []fwksched.Endpoint {endpoint })
166177 require .Len (t , scoped , 1 )
167178
168179 _ , ok := scoped [0 ].Get (consumedKey )
@@ -180,6 +191,7 @@ func TestScope_ProducerWithoutConsumesReadsOnlyItsOwnOutput(t *testing.T) {
180191 endpoint := newEndpoint (t )
181192 plug := & producerPlugin {}
182193 plug .produces = map [fwkplugin.DataKey ]any {producedKey : nil }
194+ RegisterScopeSpecs ([]fwkplugin.Plugin {plug })
183195
184196 scoped , _ := Scope (testLogger (), "test-extension-point" , plug , []fwksched.Endpoint {endpoint })
185197
@@ -248,24 +260,42 @@ func TestUnscope_LeavesUnwrappedEndpointsAlone(t *testing.T) {
248260 assert .Equal (t , endpoints , Unscope (endpoints ))
249261}
250262
251- func TestScope_AllowedKeySetsAreCachedPerPluginInstance (t * testing.T ) {
252- plugA := & producerConsumerPlugin {}
253- plugA .produces = map [fwkplugin.DataKey ]any {producedKey : nil }
254- plugA .consumes = & fwkplugin.DataDependencies {Optional : map [fwkplugin.DataKey ]any {consumedKey : nil }}
255- assert .Same (t , scopeSpecFor (plugA ), scopeSpecFor (plugA ), "same plugin instance must share one cached spec" )
263+ // Declarations grant nothing on their own: the allowed sets come from the
264+ // registry, and a plugin nobody registered is confined like one that declares
265+ // nothing.
266+ func TestScope_UnregisteredPluginIsConfinedToNothing (t * testing.T ) {
267+ plug := & producerConsumerPlugin {}
268+ plug .name = "never-registered"
269+ plug .produces = map [fwkplugin.DataKey ]any {producedKey : nil }
270+ plug .consumes = & fwkplugin.DataDependencies {Optional : map [fwkplugin.DataKey ]any {consumedKey : nil }}
256271
257- plugB := & producerConsumerPlugin {}
258- plugB .produces = map [fwkplugin.DataKey ]any {producedKey : nil }
259- plugB .consumes = & fwkplugin.DataDependencies {}
260- assert .NotSame (t , scopeSpecFor (plugA ), scopeSpecFor (plugB ), "distinct instances must not share a spec" )
272+ endpoint := newEndpoint (t )
273+ scoped , violations := Scope (testLogger (), "test-extension-point" , plug , []fwksched.Endpoint {endpoint })
274+ require .Len (t , scoped , 1 )
275+
276+ _ , ok := scoped [0 ].Get (consumedKey )
277+ assert .False (t , ok , "a declared read must not resolve without registration" )
278+ scoped [0 ].Put (producedKey , cloneableStr ("nope" ))
279+ _ , ok = endpoint .Get (producedKey )
280+ assert .False (t , ok , "a declared write must not reach the endpoint without registration" )
281+ assert .Error (t , violations .Write ())
282+ }
283+
284+ // The registry is keyed by typed name; registering a name again replaces its
285+ // spec rather than accumulating.
286+ func TestRegisterScopeSpecs_ReregistrationReplacesTheSpec (t * testing.T ) {
287+ declaring := & producerConsumerPlugin {}
288+ declaring .name = "replaced"
289+ declaring .produces = map [fwkplugin.DataKey ]any {producedKey : nil }
290+ declaring .consumes = & fwkplugin.DataDependencies {Optional : map [fwkplugin.DataKey ]any {consumedKey : nil }}
291+ RegisterScopeSpecs ([]fwkplugin.Plugin {declaring })
292+
293+ silent := & testPlugin {name : "replaced" }
294+ RegisterScopeSpecs ([]fwkplugin.Plugin {silent })
261295
262- // Confinement is unchanged when the spec comes from the cache.
263296 endpoint := newEndpoint (t )
264- scoped , _ := Scope (testLogger (), "test-extension-point" , plugA , []fwksched.Endpoint {endpoint })
297+ scoped , _ := Scope (testLogger (), "test-extension-point" , declaring , []fwksched.Endpoint {endpoint })
265298 require .Len (t , scoped , 1 )
266- _ , ok := scoped [0 ].Get (undeclaredKey )
267- assert .False (t , ok , "undeclared read must stay rejected on a cached spec" )
268- got , ok := scoped [0 ].Get (consumedKey )
269- assert .True (t , ok )
270- assert .Equal (t , cloneableStr ("consumed-value" ), got )
299+ _ , ok := scoped [0 ].Get (consumedKey )
300+ assert .False (t , ok , "the registry must serve the last spec registered for a typed name" )
271301}
0 commit comments