Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Train T2 fix for #7349: a plain delete of a bot's shared skill copy no longer takes it off all bots

milind-soni2f4d2eb0e7f9
diff --git a/server/cloud-team-skills-all-bots.e2e.test.ts b/server/cloud-team-skills-all-bots.e2e.test.ts
index 6ddcc04399..bf32d33e2a 100644
--- a/server/cloud-team-skills-all-bots.e2e.test.ts
+++ b/server/cloud-team-skills-all-bots.e2e.test.ts
@@ -67,14 +67,17 @@ it("reaches only the person's own bots, and only that person can put it on or ta
expect((await team.as(ada, "DELETE", `/api/bots/${adasKeeper.id}/skills/client-onboarding`)).status).toBe(200);
expect(await skillsOf(adasKeeper)).toEqual([expect.objectContaining({ allBots: true })]);
- expect((await team.as(olive, "DELETE", `/api/bots/${adasResearcher.id}/skills/client-onboarding`)).status).toBe(403);
+ expect((await team.as(olive, "DELETE", `/api/bots/${adasResearcher.id}/skills/client-onboarding/all-bots`)).status).toBe(403);
expect(await skillsOf(adasResearcher)).toHaveLength(1);
+ // A plain delete of one bot's shared copy, as a send, a move or a team file replaces a skill with, takes it off no bot.
+ expect((await team.as(ada, "DELETE", `/api/bots/${adasResearcher.id}/skills/client-onboarding`)).status).toBe(409);
+ for (const bot of [adasWriter, adasResearcher, later, adasKeeper]) expect(await skillsOf(bot)).toEqual([expect.objectContaining({ allBots: true })]);
expect((await team.as(ada, "PATCH", `/api/bots/${adasResearcher.id}/skills/client-onboarding`, { enabled: false })).status).toBe(200);
expect(await skillsOf(adasResearcher)).toEqual([expect.objectContaining({ enabled: false })]);
expect(await skillsOf(adasWriter)).toEqual([expect.objectContaining({ enabled: true })]);
- expect((await team.as(ada, "DELETE", `/api/bots/${adasWriter.id}/skills/client-onboarding`)).status).toBe(200);
+ expect((await team.as(ada, "DELETE", `/api/bots/${adasWriter.id}/skills/client-onboarding/all-bots`)).status).toBe(200);
for (const bot of [adasResearcher, later, adasKeeper]) expect(await skillsOf(bot)).toEqual([]);
// The bot whose own skill it was keeps it.
expect(await skillsOf(adasWriter)).toEqual([expect.not.objectContaining({ allBots: true })]);
diff --git a/server/routes/skills-for-all-bots.ts b/server/routes/skills-for-all-bots.ts
index b03069b173..b120feda95 100644
--- a/server/routes/skills-for-all-bots.ts
+++ b/server/routes/skills-for-all-bots.ts
@@ -44,15 +44,16 @@ export function createSkillsForAllBotsRoutes(deps: SkillsForAllBotsRouteDeps): R
const bot = deps.store.bot(m[1]!);
if (!bot) return PASS;
const name = m[2]!;
- if (m[3]) {
- if (method !== "POST") return PASS;
+ if (m[3] && method === "POST") {
const allowed = requesterScope(bot, auth);
if ("error" in allowed) return json(res, allowed.status, { error: allowed.error });
const done = deps.host.fromSkillsPage(bot, name, allowed.scope);
return json(res, done.status, done.body);
}
- // Remove on a shared skill takes it off every bot of the person's; the rest is the per-bot routes'.
- if (method !== "DELETE" || !listSkills(bot.id).some((skill) => skill.name === name && skill.allBots)) return PASS;
+ if (method !== "DELETE" || !listSkills(bot.id).some((skill) => skill.name === name && skill.allBots)) return m[3] ? json(res, 404, { error: `no skill named "${name}" is on all your bots` }) : PASS;
+ // Only Remove on the Skills page (…/all-bots) takes a shared skill off every bot of the person's. A plain delete of a
+ // bot's shared copy is what a send, a move or a team file does to replace one bot's skill, so it is refused.
+ if (!m[3]) return json(res, 409, { error: `"${name}" is on all your bots. Remove it from all of them on this bot's Skills page, or turn it off for this bot.` });
const allowed = requesterScope(bot, auth);
if ("error" in allowed) return json(res, allowed.status, { error: allowed.error });
const removed = removeFromAllBots(allowed.scope, name);
diff --git a/src/components/SkillsSection.behavior.test.ts b/src/components/SkillsSection.behavior.test.ts
index d5fd378db5..e40298cb79 100644
--- a/src/components/SkillsSection.behavior.test.ts
+++ b/src/components/SkillsSection.behavior.test.ts
@@ -155,6 +155,11 @@ describe("Skills library review and assignment controls", () => {
vi.stubGlobal("window", { confirm });
named(render(true), "Remove client-onboarding").props.onClick!();
expect(confirm).toHaveBeenCalledWith("Remove “client-onboarding” from all your bots?");
+ expect(fixture.request).not.toHaveBeenCalledWith("/api/bots/bot/skills/client-onboarding", expect.objectContaining({ method: "DELETE" }));
+ vi.stubGlobal("window", { confirm: vi.fn(() => true) });
+ named(render(true), "Remove client-onboarding").props.onClick!();
+ await flush();
+ expect(fixture.request).toHaveBeenCalledWith("/api/bots/bot/skills/client-onboarding/all-bots", { method: "DELETE" });
vi.unstubAllGlobals();
});
});
diff --git a/src/components/bot-panel/pages.tsx b/src/components/bot-panel/pages.tsx
index 3bfa9892ab..c98b32a060 100644
--- a/src/components/bot-panel/pages.tsx
+++ b/src/components/bot-panel/pages.tsx
@@ -255,7 +255,7 @@ export function SkillsPage({ bot }: PageContext) {
skills.setWorking(skill.name);
skills.setError("");
try {
- await api(`/api/bots/${bot.id}/skills/${encodeURIComponent(skill.name)}`, { method: "DELETE" });
+ await api(`/api/bots/${bot.id}/skills/${encodeURIComponent(skill.name)}${skill.allBots ? "/all-bots" : ""}`, { method: "DELETE" });
await skills.refresh();
} catch (cause) {
skills.setError(errorText(cause, t("botPanel.skills.removeFailed")));
diff --git a/src/components/bot-settings/SkillsSection.tsx b/src/components/bot-settings/SkillsSection.tsx
index 9483082d37..4062e859c3 100644
--- a/src/components/bot-settings/SkillsSection.tsx
+++ b/src/components/bot-settings/SkillsSection.tsx
@@ -388,7 +388,7 @@ export function SkillsSection({ bot }: { bot: Bot }) {
setWorking(skill.name);
setError("");
try {
- await api(`/api/bots/${bot.id}/skills/${encodeURIComponent(skill.name)}`, { method: "DELETE" });
+ await api(`/api/bots/${bot.id}/skills/${encodeURIComponent(skill.name)}${skill.allBots ? "/all-bots" : ""}`, { method: "DELETE" });
await refresh();
} catch (cause) {
setError(cause instanceof Error ? cause.message : t("skills.error.remove"));