Skip to content

Commit bd6bd55

Browse files
committed
addressing claude review
1 parent 8befc4b commit bd6bd55

2 files changed

Lines changed: 31 additions & 37 deletions

File tree

extensions/active-memory/index.test.ts

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -440,37 +440,33 @@ describe("active-memory plugin", () => {
440440
expect(runEmbeddedPiAgent).toHaveBeenCalledTimes(1);
441441
});
442442

443-
it("blocks write-scoped gateway callers from changing global active-memory config", async () => {
443+
it("blocks gateway callers without admin scope from changing global active-memory config", async () => {
444444
const command = registeredCommands["active-memory"];
445445

446-
const offResult = await command.handler({
447-
channel: "gateway",
448-
isAuthorizedSender: true,
449-
gatewayClientScopes: ["operator.write"],
450-
args: "off --global",
451-
commandBody: "/active-memory off --global",
452-
config: {},
453-
requestConversationBinding: async () => ({ status: "error", message: "unsupported" }),
454-
detachConversationBinding: async () => ({ removed: false }),
455-
getCurrentConversationBinding: async () => null,
456-
});
457-
458-
expect(offResult.text).toContain("requires operator.admin");
459-
expect(api.runtime.config.replaceConfigFile).not.toHaveBeenCalled();
446+
for (const { args, gatewayClientScopes } of [
447+
{ args: "off --global", gatewayClientScopes: ["operator.write"] },
448+
{ args: "on --global", gatewayClientScopes: ["operator.write"] },
449+
{ args: "disable --global", gatewayClientScopes: ["operator.write"] },
450+
{ args: "enable --global", gatewayClientScopes: ["operator.write"] },
451+
{ args: "disabled --global", gatewayClientScopes: ["operator.write"] },
452+
{ args: "enabled --global", gatewayClientScopes: ["operator.write"] },
453+
{ args: "off --global", gatewayClientScopes: [] },
454+
]) {
455+
const result = await command.handler({
456+
channel: "gateway",
457+
isAuthorizedSender: true,
458+
gatewayClientScopes,
459+
args,
460+
commandBody: `/active-memory ${args}`,
461+
config: {},
462+
requestConversationBinding: async () => ({ status: "error", message: "unsupported" }),
463+
detachConversationBinding: async () => ({ removed: false }),
464+
getCurrentConversationBinding: async () => null,
465+
});
460466

461-
const onResult = await command.handler({
462-
channel: "gateway",
463-
isAuthorizedSender: true,
464-
gatewayClientScopes: ["operator.write"],
465-
args: "on --global",
466-
commandBody: "/active-memory on --global",
467-
config: {},
468-
requestConversationBinding: async () => ({ status: "error", message: "unsupported" }),
469-
detachConversationBinding: async () => ({ removed: false }),
470-
getCurrentConversationBinding: async () => null,
471-
});
467+
expect(result.text).toContain("global enable/disable changes require operator.admin");
468+
}
472469

473-
expect(onResult.text).toContain("requires operator.admin");
474470
expect(api.runtime.config.replaceConfigFile).not.toHaveBeenCalled();
475471
});
476472

extensions/active-memory/index.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,9 @@ function requiresAdminToMutateActiveMemoryGlobal(gatewayClientScopes?: readonly
786786
return Array.isArray(gatewayClientScopes) && !gatewayClientScopes.includes("operator.admin");
787787
}
788788

789+
const ACTIVE_MEMORY_GLOBAL_MUTATION_ADMIN_REQUIRED_TEXT =
790+
"⚠️ /active-memory global enable/disable changes require operator.admin for gateway clients.";
791+
789792
function normalizePluginConfig(pluginConfig: unknown): ResolvedActiveRecallPluginConfig {
790793
const raw = (
791794
pluginConfig && typeof pluginConfig === "object" ? pluginConfig : {}
@@ -2823,12 +2826,12 @@ export default definePluginEntry({
28232826
text: `Active Memory: ${isActiveMemoryGloballyEnabled(currentConfig) ? "on" : "off"} globally.`,
28242827
};
28252828
}
2829+
if (requiresAdminToMutateActiveMemoryGlobal(ctx.gatewayClientScopes)) {
2830+
return {
2831+
text: ACTIVE_MEMORY_GLOBAL_MUTATION_ADMIN_REQUIRED_TEXT,
2832+
};
2833+
}
28262834
if (action === "on" || action === "enable" || action === "enabled") {
2827-
if (requiresAdminToMutateActiveMemoryGlobal(ctx.gatewayClientScopes)) {
2828-
return {
2829-
text: "⚠️ /active-memory on|off --global requires operator.admin for gateway clients.",
2830-
};
2831-
}
28322835
const nextConfig = updateActiveMemoryGlobalEnabledInConfig(currentConfig, true);
28332836
await api.runtime.config.replaceConfigFile({
28342837
nextConfig,
@@ -2838,11 +2841,6 @@ export default definePluginEntry({
28382841
return { text: "Active Memory: on globally." };
28392842
}
28402843
if (action === "off" || action === "disable" || action === "disabled") {
2841-
if (requiresAdminToMutateActiveMemoryGlobal(ctx.gatewayClientScopes)) {
2842-
return {
2843-
text: "⚠️ /active-memory on|off --global requires operator.admin for gateway clients.",
2844-
};
2845-
}
28462844
const nextConfig = updateActiveMemoryGlobalEnabledInConfig(currentConfig, false);
28472845
await api.runtime.config.replaceConfigFile({
28482846
nextConfig,

0 commit comments

Comments
 (0)