@@ -299,24 +299,6 @@ func TestDeleteRegistrationPackageLosesRaceToHandover(t *testing.T) {
299299 }
300300}
301301
302- func TestHasDefaultVariant (t * testing.T ) {
303- with := & cozyv1alpha1.PackageSource {Spec : cozyv1alpha1.PackageSourceSpec {
304- Variants : []cozyv1alpha1.Variant {{Name : "big" }, {Name : "default" }},
305- }}
306- if ! hasDefaultVariant (with ) {
307- t .Error ("expected a default variant to be detected" )
308- }
309- without := & cozyv1alpha1.PackageSource {Spec : cozyv1alpha1.PackageSourceSpec {
310- Variants : []cozyv1alpha1.Variant {{Name : "only" }, {Name : "second" }},
311- }}
312- if hasDefaultVariant (without ) {
313- t .Error ("expected no default variant" )
314- }
315- if hasDefaultVariant (& cozyv1alpha1.PackageSource {}) {
316- t .Error ("expected no default variant for an empty source" )
317- }
318- }
319-
320302func TestPrivilegedInstallComponents (t * testing.T ) {
321303 ps := & cozyv1alpha1.PackageSource {Spec : cozyv1alpha1.PackageSourceSpec {
322304 Variants : []cozyv1alpha1.Variant {{
@@ -337,18 +319,20 @@ func TestPrivilegedInstallComponents(t *testing.T) {
337319 }
338320}
339321
340- // TestReconcileRegistersApps asserts the happy path: a materialized tap creates
341- // a tap-managed registration Package so the repository's apps register in the
342- // catalog on connect, without a manual `cozypkg add`.
343- func TestReconcileRegistersApps (t * testing.T ) {
322+ // TestReconcileCreatesNoPackageOnConnect asserts that connecting a repository
323+ // materializes its PackageSource and nothing else: no Package (and so no
324+ // HelmRelease or ApplicationDefinition) is created on connect. Auto-registering
325+ // on connect ran a publisher's install chart under Flux's cluster-admin account
326+ // with no operator step (issue #4978); installing is now explicit via
327+ // `cozypkg add`.
328+ func TestReconcileCreatesNoPackageOnConnect (t * testing.T ) {
344329 scheme := tapScheme (t )
345330 data , digest := tarGz (t , map [string ]string {
346331 // samplePS declares PackageSource "example.hello" with a default variant.
347332 "packages/core/platform/sources/hello.yaml" : samplePS ,
348333 })
349- repo := tapRepo (true )
350334 cl := fake .NewClientBuilder ().WithScheme (scheme ).
351- WithObjects (repo ).
335+ WithObjects (tapRepo ( true ) ).
352336 WithStatusSubresource (& sourcev1.OCIRepository {}).
353337 Build ()
354338
@@ -374,25 +358,57 @@ func TestReconcileRegistersApps(t *testing.T) {
374358 if err := cl .Get (context .Background (), client.ObjectKey {Name : "example.hello" }, & cozyv1alpha1.PackageSource {}); err != nil {
375359 t .Fatalf ("PackageSource not materialized: %v" , err )
376360 }
377- // A tap-managed registration Package was created for it .
361+ // No Package is created: connect installs nothing .
378362 var pkg cozyv1alpha1.Package
379- if err := cl .Get (context .Background (), client.ObjectKey {Name : "example.hello" }, & pkg ); err != nil {
380- t .Fatalf ("registration Package not created: % v" , err )
363+ if err := cl .Get (context .Background (), client.ObjectKey {Name : "example.hello" }, & pkg ); ! apierrors . IsNotFound ( err ) {
364+ t .Fatalf ("connect must create no Package, got err=%v pkg=%+ v" , err , pkg )
381365 }
382- if pkg .GetLabels ()[tapconst .Label ] != "true" {
383- t .Errorf ("registration Package must be tap-managed (labelled), got %v" , pkg .GetLabels ())
366+ }
367+
368+ // TestReconcileDoesNotRecreateDeletedPackage asserts that a Package the admin
369+ // removed (e.g. with `cozypkg del`) stays removed across a new source revision.
370+ // Auto-registration used to re-create it on every revision (the second effect in
371+ // issue #4978); with it gone the materializer never creates a Package at all.
372+ func TestReconcileDoesNotRecreateDeletedPackage (t * testing.T ) {
373+ scheme := tapScheme (t )
374+ data , digest := tarGz (t , map [string ]string {
375+ "packages/core/platform/sources/hello.yaml" : samplePS ,
376+ })
377+ cur := data
378+ cl := fake .NewClientBuilder ().WithScheme (scheme ).
379+ WithObjects (tapRepo (true )).
380+ WithStatusSubresource (& sourcev1.OCIRepository {}).
381+ Build ()
382+ r := materializerFor (scheme , cl , record .NewFakeRecorder (10 ), & cur )
383+
384+ // Connect (rev1): materializes the PackageSource, creates no Package.
385+ setArtifact (t , cl , digest , "rev1" )
386+ if _ , err := r .Reconcile (context .Background (), req ()); err != nil {
387+ t .Fatalf ("reconcile rev1: %v" , err )
384388 }
385- if pkg .GetAnnotations ()[tapconst .SourceAnnotation ] != repo .Name {
386- t .Errorf ("registration Package must record its source, got %v" , pkg .GetAnnotations ())
389+
390+ // Admin installs then removes the app: a plain user Package appears and is
391+ // then deleted with `cozypkg del`.
392+ userPkg := & cozyv1alpha1.Package {ObjectMeta : metav1.ObjectMeta {Name : "example.hello" }}
393+ if err := cl .Create (context .Background (), userPkg ); err != nil {
394+ t .Fatalf ("create user Package: %v" , err )
387395 }
388- // Variant is left empty so the Package reconciler resolves it to "default"
389- // deterministically, rather than pinning whichever variant was listed first.
390- if pkg .Spec .Variant != "" {
391- t .Errorf ("registration Package must leave Variant empty, got %q" , pkg .Spec .Variant )
396+ if err := cl .Delete (context .Background (), userPkg ); err != nil {
397+ t .Fatalf ("delete user Package: %v" , err )
392398 }
393- // Owned by its PackageSource so a direct delete of the PackageSource GCs it.
394- if len (pkg .OwnerReferences ) != 1 || pkg .OwnerReferences [0 ].Kind != "PackageSource" || pkg .OwnerReferences [0 ].Name != "example.hello" {
395- t .Errorf ("registration Package must own-ref its PackageSource, got %+v" , pkg .OwnerReferences )
399+
400+ // A new revision must not resurrect the deleted Package.
401+ data2 , digest2 := tarGz (t , map [string ]string {
402+ "packages/core/platform/sources/hello.yaml" : samplePS ,
403+ })
404+ cur = data2
405+ setArtifact (t , cl , digest2 , "rev2" )
406+ if _ , err := r .Reconcile (context .Background (), req ()); err != nil {
407+ t .Fatalf ("reconcile rev2: %v" , err )
408+ }
409+ var pkg cozyv1alpha1.Package
410+ if err := cl .Get (context .Background (), client.ObjectKey {Name : "example.hello" }, & pkg ); ! apierrors .IsNotFound (err ) {
411+ t .Fatalf ("a removed Package must stay removed across revisions, got err=%v pkg=%+v" , err , pkg )
396412 }
397413}
398414
@@ -422,10 +438,10 @@ func setArtifact(t *testing.T, cl client.Client, digest, rev string) {
422438}
423439
424440// TestReconcileLeavesUnmarkedPackage: an unmarked Package of the same name (a
425- // user's `cozypkg add`, or one from before this version) means registration is
426- // already satisfied . The reconcile must NOT error (which would hot-loop the whole
427- // tap and re-pull the artifact every backoff), NOT adopt it, and NOT delete it;
428- // the revision is stamped so the loop does not recur.
441+ // user's `cozypkg add`, or one from before this version) must be left untouched
442+ // by materialization . The reconcile must NOT error (which would hot-loop the
443+ // whole tap and re-pull the artifact every backoff), NOT adopt it, and NOT delete
444+ // it; the revision is stamped so the loop does not recur.
429445func TestReconcileLeavesUnmarkedPackage (t * testing.T ) {
430446 scheme := tapScheme (t )
431447 data , digest := tarGz (t , map [string ]string {"packages/core/platform/sources/hello.yaml" : samplePS })
0 commit comments