package resolution import ( "os" "path/filepath" "strings" "testing" mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) func l2Moved(t *testing.T, parts ...string) string { t.Helper() raw, err := os.ReadFile(filepath.Join(append([]string{"testdata", "l2-moved"}, parts...)...)) if err != nil { t.Fatal(err) } return string(raw) } func TestTheCollectorsL2MovedComposeAsBeforeWhereNothingIsHanded(t *testing.T) { // Each moved contributor, its items read back from its templates archive as the mesh holds them. items := map[string][]string{ "asus-zephyrus-g14": {"shell:after-wake:normal", "contribution:node-hotkeys:trigger"}, "claude-code": {"shell:zsh:normal"}, "mesh-cli": {"shell:zsh:normal"}, "powerlevel10k": {"shell:zsh:normal"}, "zsh-autosuggestions": {"shell:zsh:normal"}, "zsh-syntax-highlighting": {"shell:zsh:last"}, } var modules []mcat.Manifest for _, module := range sortedKeys(items) { m := mcat.Manifest{Module: module, Moved: true} for _, collection := range items[module] { m.Items = append(m.Items, mcat.Item{Collection: collection, Content: l2Moved(t, "items", module+"."+strings.ReplaceAll(collection, ":", "-"))}) } modules = append(modules, m) } for _, c := range []struct{ module, seat string }{{"zsh", mcat.LoginShellSeat}, {"triggerhappy", mcat.HotkeysSeat}, {"power", mcat.PowerSeat}} { holder := mcat.Manifest{Module: c.module, Moved: true, Claims: []mcat.Claim{{Name: c.seat}}} resource := map[string]any{"id": "file", "type": "file", "path": "/etc/" + c.module, "content": l2Moved(t, "templates", c.module)} var unplaced []string if err := contributionsInto(resource, holder, append([]mcat.Manifest{holder}, modules...), map[string]string{"name": "g14"}, mcat.Rendering{}, map[string]bool{}, &unplaced); err != nil { t.Fatalf("%s: %v", c.module, err) } if got, want := resource["content"], l2Moved(t, "want", c.module); got != want { t.Errorf("%s's file is not what the old forms made:\n%s\nwant:\n%s", c.module, got, want) } if len(unplaced) != 0 { t.Errorf("%s: unplaced %v", c.module, unplaced) } } }