feat(16.3-01): admin:token CLI, party.Activated, READMEs and docs
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -26,7 +26,7 @@ Use cases:
|
||||
- A process-wide, concurrency-safe registry filled by `party.Register` (nil plugins are ignored).
|
||||
- `party.Activate` selects plugins by manifest ID and fails on an empty ID, a duplicate ID, an unregistered plugin, a missing requirement or a dependency cycle.
|
||||
- Stable topological ordering: plugins without a dependency relation keep their manifest order.
|
||||
- Activation sequence: records the ordered IDs on the `backpack.App`, merges each `pact.HasConfig` tree into the app config under the plugin ID, runs every Register, publishes the translator ([phrasebook](../phrasebook/README.md)) and mailer ([postcard](../postcard/README.md)), then registers each plugin's mail templates and runs its Boot.
|
||||
- Activation sequence: records the ordered IDs on the `backpack.App`, publishes `party.Activated` (the ordered plugin list for commands that need plugin scopes at Run time), merges each `pact.HasConfig` tree into the app config under the plugin ID, runs every Register, publishes the translator ([phrasebook](../phrasebook/README.md)) and mailer ([postcard](../postcard/README.md)), then registers each plugin's mail templates and runs its Boot.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -73,6 +73,7 @@ if err != nil {
|
||||
| `party.Plugin` | Interface every compiled plugin implements: ID, required plugin IDs, Register and Boot. |
|
||||
| `party.Register` | Adds a plugin to the process-wide registry; called from the plugin's `init`. |
|
||||
| `party.Activate` | Selects registered plugins by ID, orders them by `party.Plugin.Requires` and runs the config, Register, translation, mail and Boot steps; returns the ordered plugins. |
|
||||
| `party.Activated` | The ordered `[]party.Plugin` published by `party.Activate`; commands look it up at Run time with `app.Lookup[party.Activated]()`. |
|
||||
|
||||
## Dependencies
|
||||
|
||||
|
||||
@@ -19,6 +19,10 @@ type Plugin interface {
|
||||
Boot(app *backpack.App) error
|
||||
}
|
||||
|
||||
// Activated is the ordered plugin list published by Activate. Commands look
|
||||
// it up at Run time with app.Lookup[Activated]().
|
||||
type Activated []Plugin
|
||||
|
||||
var (
|
||||
mu sync.Mutex
|
||||
plugins []Plugin
|
||||
@@ -105,6 +109,9 @@ func activate(registered []Plugin, app *backpack.App, ids []string) ([]Plugin, e
|
||||
orderedIDs[i] = p.ID()
|
||||
}
|
||||
app.SetPlugins(orderedIDs)
|
||||
if err := app.Publish(Activated(ordered)); err != nil {
|
||||
return nil, fmt.Errorf("party: %w", err)
|
||||
}
|
||||
|
||||
for _, p := range ordered {
|
||||
if hc, ok := p.(pact.HasConfig); ok && app.Config != nil {
|
||||
|
||||
@@ -305,6 +305,26 @@ func TestActivateNilAppRejected(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActivatePublishesPlugins(t *testing.T) {
|
||||
var log []string
|
||||
a := &tracePlugin{id: "golem15.a", log: &log}
|
||||
b := &tracePlugin{id: "golem15.b", req: []string{"golem15.a"}, log: &log}
|
||||
app := backpack.New(&compass.Config{})
|
||||
if _, err := activate([]Plugin{b, a}, app, []string{"golem15.b", "golem15.a"}); err != nil {
|
||||
t.Fatalf("activate: %v", err)
|
||||
}
|
||||
activated, ok := app.Lookup[Activated]()
|
||||
if !ok || activated == nil {
|
||||
t.Fatal("Activate did not publish Activated")
|
||||
}
|
||||
if len(activated) != 2 {
|
||||
t.Fatalf("Activated has %d plugins, want 2", len(activated))
|
||||
}
|
||||
if activated[0].ID() != "golem15.a" || activated[1].ID() != "golem15.b" {
|
||||
t.Fatalf("Activated order = %q, %q; want golem15.a then golem15.b", activated[0].ID(), activated[1].ID())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterNilIsNoop(t *testing.T) {
|
||||
Register(nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user