Add bots files handling logic

This commit is contained in:
2026-10-21 17:56:09 +01:00
parent b0af4db1bf
commit d17a4a7bdd
97 changed files with 5843 additions and 41 deletions
+60
View File
@@ -0,0 +1,60 @@
import { describe, expect, test } from "bun:test";
import grabStorageScopes from "./storage-access";
describe("grabStorageScopes", () => {
test("a worker in its own chat reaches only its folder", () => {
expect(grabStorageScopes({ bot_id: 4, bot_kind: "worker" })).toEqual([
{ scope: "bot", owner_id: 4 },
]);
});
test("a worker in a workspace also reaches the workspace's folder", () => {
expect(
grabStorageScopes({ bot_id: 4, bot_kind: "worker", workspace_id: 9 }),
).toEqual([
{ scope: "bot", owner_id: 4 },
{ scope: "workspace", owner_id: 9 },
]);
});
test("the coordinator reaches every workspace, its own folder first", () => {
expect(
grabStorageScopes({
bot_id: 1,
bot_kind: "coordinator",
all_workspace_ids: [9, 3],
}),
).toEqual([
{ scope: "bot", owner_id: 1 },
{ scope: "workspace", owner_id: 9 },
{ scope: "workspace", owner_id: 3 },
]);
});
test("the coordinator in a workspace still reaches them all", () => {
const scopes = grabStorageScopes({
bot_id: 1,
bot_kind: "coordinator",
workspace_id: 9,
all_workspace_ids: [9],
});
expect(scopes).toEqual([
{ scope: "bot", owner_id: 1 },
{ scope: "workspace", owner_id: 9 },
]);
});
test("ignores invalid workspace ids", () => {
expect(
grabStorageScopes({
bot_id: 1,
bot_kind: "coordinator",
all_workspace_ids: [0, 2],
}),
).toEqual([
{ scope: "bot", owner_id: 1 },
{ scope: "workspace", owner_id: 2 },
]);
});
});