mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-17 14:25:27 +09:00
Construct plugins with a static fromContext (#487)
Each plugin class now has a private constructor and a static async fromContext(context) that loads its datastores, constructs the instance and attaches its handlers and hooks. This replaces the public constructor followed by init(), and AutoRestart's start(). Datastores are loaded before construction and passed to the constructor, so the definite assignment assertions on them are gone. Tests build the plugins through fromContext and pass a wrapped logger in the context instead of overwriting plugin.logger before init(). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
757a36fc03
commit
ea9bf1fb78
17 files changed
+236
-241
No files matched your search
@@ -44,8 +44,7 @@ async function startPlugin(t2, { roles = [] } = {}) {
|
||||
permissionsUpdated(user);
|
||||
};
|
||||
|
||||
const plugin = new ControllerPlugin({ plugin: { name: "exp_roles" }, controller, logger });
|
||||
await plugin.init();
|
||||
const plugin = await ControllerPlugin.fromContext({ plugin: { name: "exp_roles" }, controller, logger });
|
||||
return { plugin, controller, state };
|
||||
}
|
||||
|
||||
@@ -62,7 +61,7 @@ t.test("entrypoint", async t2 => {
|
||||
});
|
||||
|
||||
t.test("class ControllerPlugin", t2 => {
|
||||
t2.test(".init() and .sweepRoleMeta() manage the role properties", async t3 => {
|
||||
t2.test(".fromContext() and .sweepRoleMeta() manage the role properties", async t3 => {
|
||||
const { plugin } = await startPlugin(t3, { roles: [role(0, "Cluster Admin"), role(5, "Moderator")] });
|
||||
|
||||
t3.strictSame(plugin.roleMeta.get(0).order, 1, "the first role is ordered first");
|
||||
|
||||
Reference in new issue
Block a user