Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pluginkit/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Releases of this module are tagged `pluginkit/vX.Y.Z`. Releases up to
- `pluginstoretest.Run` checks any `PluginStore` against the contract, and `pluginstoretest.NewMemory` is a store in memory that keeps it.
- `Installed` lists one `InstalledPlugin` per installed plugin, with the JSON names `id`, `name`, `description`, `version`, `status`, `paused_step` and `paused_reason`, sorted by name without regard to case, then by id. It leaves out a plugin the records hold as not installed and a record with no manifest, and lists a manifest with no record as active. The step and the reason are empty unless the plugin is paused.
- `wire.Manifest` reads `description`, which no longer sits in `Extra`, a breaking change.
- `wire.Manifest` reads `graphql` as `GraphQL`, which no longer sits in `Extra`, a breaking change.
- `wire` rejects a manifest that spells a key it reads in another case, such as `Name`, repeats a name in one object, or holds text that is not valid UTF-8, as bytes or as an escaped surrogate with no pair, a breaking change.
- `RegisterEach` and `Register` take only plugins with an `ID() string` method, and fail at `StepRegister` a plugin whose `ID` is not its entry's id, or a `Register` that answers no plugin, a breaking change.
- `Protect` takes the plugin's id and a `RouteSettings`, which holds the middleware as `Wrap`, a breaking change.
Expand Down
6 changes: 4 additions & 2 deletions pluginkit/wire/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Manifest struct {
Name string `json:"name"`
Backend string `json:"backend,omitempty"`
Frontend string `json:"frontend,omitempty"`
// GraphQL marks a plugin whose backend extends the application's GraphQL API.
GraphQL bool `json:"graphql,omitempty"`

Description string `json:"description,omitempty"`
Version string `json:"version,omitempty"`
Expand Down Expand Up @@ -120,8 +122,8 @@ type manifest Manifest

// typedKeys are the manifest keys Manifest has a field for.
var typedKeys = []string{
"id", "name", "backend", "frontend", "description", "version", "license", "did", "requires", "tested", "engines",
"uninstall", "hooks", "defines", "jobs", "settings", "menu", "screens", "screen_capabilities",
"id", "name", "backend", "frontend", "graphql", "description", "version", "license", "did", "requires", "tested",
"engines", "uninstall", "hooks", "defines", "jobs", "settings", "menu", "screens", "screen_capabilities",
}

// isTypedKey reports whether key is the json name of a field of Manifest.
Expand Down
3 changes: 2 additions & 1 deletion pluginkit/wire/manifest_identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
)

// everyNewKey is every key a manifest may name beside the ones wire has always read.
const everyNewKey = `"description": "Sells seats for the events a site holds.",
const everyNewKey = `"graphql": true,
"description": "Sells seats for the events a site holds.",
"version": "2.0.0",
"license": "Apache-2.0",
"did": "did:plc:example",
Expand Down
7 changes: 4 additions & 3 deletions pluginkit/wire/manifest_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const fullIndex = `[
"name": "Events",
"backend": "example.com/myapp/plugins/events",
"frontend": "@myapp/plugin-events",
"graphql": true,
"description": "Sells seats for the events a site holds.",
"version": "2.0.0",
"license": "Apache-2.0",
Expand Down Expand Up @@ -115,7 +116,7 @@ const fullIndex = `[
"screen_capabilities": {
"seats": "events.manage"
},
"graphql": true
"myapp_featured": true
},
{
"id": "feed",
Expand Down Expand Up @@ -169,8 +170,8 @@ func TestManifestIndexLeavesOutAnAbsentOrEmptyOptionalKey(t *testing.T) {
t.Parallel()

got := runForIndex(t, map[string]string{
"feed": withKeys(feedManifest,
`"uninstall": false, "engines": [], "requires": {}, "settings": [{"key": "seats", "type": "count"}]`),
"feed": withKeys(feedManifest, `"graphql": false, "uninstall": false, "engines": [], "requires": {}, `+
`"settings": [{"key": "seats", "type": "count"}]`),
})

want := `[
Expand Down
5 changes: 3 additions & 2 deletions pluginkit/wire/manifest_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func wrongCaseKeys() map[string]wrongShape {
`"DESCRIPTION": "Sells seats"`, `the key "DESCRIPTION" must be spelled "description"`,
},
"a top level key in mixed case": {`"Version": "2.0.0"`, `the key "Version" must be spelled "version"`},
"graphql spelled as its Go field": {`"GraphQL": true`, `the key "GraphQL" must be spelled "graphql"`},
"a top level key beside its own spelling": {`"Name": "Other"`, `the key "Name" must be spelled "name"`},
"a top level key with an underscore": {
`"Screen_Capabilities": {"seats": "a"}`, `the key "Screen_Capabilities" must be spelled "screen_capabilities"`,
Expand Down Expand Up @@ -84,15 +85,15 @@ func repeatedKeys() map[string]wrongShape {
func TestLoadReadsAKeyOfDataAsWritten(t *testing.T) {
t.Parallel()

got := feedWith(t, `"GraphQL": true, "note": 1, "Note": 2, "ver-sion": "a", "ver_sion": "b", `+
got := feedWith(t, `"Featured": true, "note": 1, "Note": 2, "ver-sion": "a", "ver_sion": "b", `+
`"pages": [{"Word": "forums", "word": "topics"}], "requires": {"App": ">=1", "app": ">=2"}, `+
`"screen_capabilities": {"Seats": "events.manage"}, "settings": [{"key": "a", "type": "b", "Note": 1}]`)

assertSame(t, got.Requires, map[string]string{"App": ">=1", "app": ">=2"})
assertSame(t, got.ScreenCapabilities, map[string]string{"Seats": "events.manage"})
assertSame(t, got.Settings, []Setting{{Key: "a", Type: "b"}})
assertSame(t, got.Extra, map[string]json.RawMessage{
"GraphQL": json.RawMessage(`true`),
"Featured": json.RawMessage(`true`),
"note": json.RawMessage(`1`),
"Note": json.RawMessage(`2`),
"ver-sion": json.RawMessage(`"a"`),
Expand Down
47 changes: 38 additions & 9 deletions pluginkit/wire/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const fullManifest = `{
"name": "Events",
"backend": "example.com/myapp/plugins/events",
"frontend": "@myapp/plugin-events",
"graphql": true,
"description": "Sells seats for the events a site holds.",
"version": "2.0.0",
"license": "Apache-2.0",
Expand All @@ -43,7 +44,7 @@ const fullManifest = `{
],
"screens": "@myapp/plugin-events/screens",
"screen_capabilities": {"seats": "events.manage"},
"graphql": true
"myapp_featured": true
}`

// number returns a pointer to value, as a setting's limits hold it.
Expand All @@ -63,6 +64,7 @@ func fullManifestRead() Manifest {
Name: "Events",
Backend: "example.com/myapp/plugins/events",
Frontend: "@myapp/plugin-events",
GraphQL: true,
Description: "Sells seats for the events a site holds.",
Version: "2.0.0",
License: "Apache-2.0",
Expand Down Expand Up @@ -94,7 +96,7 @@ func fullManifestRead() Manifest {
},
Screens: "@myapp/plugin-events/screens",
ScreenCapabilities: map[string]string{"seats": "events.manage"},
Extra: map[string]json.RawMessage{"graphql": json.RawMessage(`true`)},
Extra: map[string]json.RawMessage{"myapp_featured": json.RawMessage(`true`)},
}
}

Expand Down Expand Up @@ -297,24 +299,48 @@ func TestADescriptionReachesTheIndexAndReadsBack(t *testing.T) {
assertSame(t, read, written)
}

func TestLoadReadsTheGraphqlKeyIntoItsOwnFieldAndNotIntoExtra(t *testing.T) {
t.Parallel()

got := feedWith(t, `"graphql": true`)

assertSame(t, got.GraphQL, true)
assertSame(t, got.Extra, map[string]json.RawMessage(nil))
}

func TestTheGraphqlKeyReachesTheIndexBesideTheFrontendAndReadsBack(t *testing.T) {
t.Parallel()

written := Manifest{ID: "feed", Name: "Feed", Frontend: "@myapp/plugin-feed", GraphQL: true, Version: "1.0.0"}

data, err := json.Marshal(written)

assertErrorFree(t, err)
assertSame(t, string(data),
`{"id":"feed","name":"Feed","frontend":"@myapp/plugin-feed","graphql":true,"version":"1.0.0"}`)
var read Manifest
assertErrorFree(t, json.Unmarshal(data, &read))
assertSame(t, read, written)
}

func TestLoadKeepsAnUnknownKeyInExtra(t *testing.T) {
t.Parallel()

got := feedWith(t, `"graphql": true, "pages": [{"word": "forums"}], "note": null`)
got := feedWith(t, `"myapp_featured": true, "pages": [{"word": "forums"}], "note": null`)

assertSame(t, got.Extra, map[string]json.RawMessage{
"graphql": json.RawMessage(`true`),
"pages": json.RawMessage(`[{"word": "forums"}]`),
"note": json.RawMessage(`null`),
"myapp_featured": json.RawMessage(`true`),
"pages": json.RawMessage(`[{"word": "forums"}]`),
"note": json.RawMessage(`null`),
})
}

func TestLoadReadsANullAsAnAbsentKey(t *testing.T) {
t.Parallel()

got := feedWith(t, `"description": null, "version": null, "requires": null, "engines": null, "uninstall": null, `+
`"hooks": null, "defines": null, "jobs": null, "settings": null, "menu": null, "screens": null, `+
`"screen_capabilities": null`)
got := feedWith(t, `"graphql": null, "description": null, "version": null, "requires": null, "engines": null, `+
`"uninstall": null, "hooks": null, "defines": null, "jobs": null, "settings": null, "menu": null, `+
`"screens": null, "screen_capabilities": null`)

want, err := loadOne(t, "feed", feedManifest)
assertErrorFree(t, err)
Expand Down Expand Up @@ -423,6 +449,9 @@ type wrongShape struct{ keys, want string }
// wrongTypes lists keys of the wrong JSON type, and what the decoder says of each.
func wrongTypes() map[string]wrongShape {
return map[string]wrongShape{
"a string for graphql": {
`"graphql": "yes"`, "json: cannot unmarshal string into Go struct field manifest.graphql of type bool",
},
"a number for description": {
`"description": 5`,
"json: cannot unmarshal number into Go struct field manifest.description of type string",
Expand Down