fix: block stale default agent staging

This commit is contained in:
Shakker
2026-08-04 11:17:44 +01:00
committed by Shakker
parent 72b6aa478a
commit 7dbeb876f9
2 changed files with 42 additions and 0 deletions
+39
View File
@@ -404,6 +404,45 @@ describe("createRuntimeConfigCapability", () => {
runtimeConfig.dispose();
});
it("does not stage a default agent after access downgrades", async () => {
const request = vi.fn(async (method: string) => {
if (method === "config.get") {
return {
sourceConfig: {
agents: {
entries: {
main: {},
reviewer: { default: true },
},
},
},
hash: "hash-1",
valid: true,
issues: [],
};
}
return { hash: "hash-2" };
});
const client = { request } as unknown as GatewayBrowserClient;
const { gateway, publish } = createGatewayHarness(client);
const runtimeConfig = createRuntimeConfigCapability(gateway);
await runtimeConfig.ensureLoaded();
publish(true, client, {
type: "hello-ok",
protocol: 1,
auth: { role: "operator", scopes: ["operator.read"] },
features: { methods: ["config.get", "config.set"] },
} as GatewayHelloOk);
expect(runtimeConfig.stageDefaultAgent("main")).toBe(false);
expect(runtimeConfig.state.configFormDirty).toBe(false);
expect(runtimeConfig.state.configForm).toEqual({
agents: { entries: { main: {}, reviewer: { default: true } } },
});
runtimeConfig.dispose();
});
it("refuses to create blocked agent entry paths", async () => {
const request = vi.fn(async (method: string) =>
method === "config.get"
+3
View File
@@ -1999,6 +1999,9 @@ export function createRuntimeConfigCapability(
: Promise.resolve(),
agentEntry: (agentId, options) => agentConfigEntry(state, agentId, options),
stageDefaultAgent: (agentId) => {
if (!canCallConfigMethod("config.set")) {
return false;
}
const changed = stageDefaultAgentConfigEntry(state, agentId);
publish();
scheduleAutoSave();