Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
@@ -0,0 +1,102 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { queueNames } from "@toolctrl/queue";
|
||||
import {
|
||||
DEFAULT_GROUP_CONCURRENCY,
|
||||
InvalidWorkerQueueGroupError,
|
||||
bootstrapWorkerGroup,
|
||||
resolveGroupConcurrency,
|
||||
resolveQueueNamesForGroup,
|
||||
resolveWorkerQueueGroup,
|
||||
} from "./group-runtime.js";
|
||||
|
||||
describe("resolveWorkerQueueGroup", () => {
|
||||
test("returns the validated group when env is set", () => {
|
||||
expect(resolveWorkerQueueGroup({ WORKER_QUEUE_GROUP: "mail" })).toBe("mail");
|
||||
});
|
||||
|
||||
test("throws when env is missing", () => {
|
||||
expect(() => resolveWorkerQueueGroup({})).toThrow(InvalidWorkerQueueGroupError);
|
||||
});
|
||||
|
||||
test("throws when env is unknown", () => {
|
||||
expect(() => resolveWorkerQueueGroup({ WORKER_QUEUE_GROUP: "all" })).toThrow(InvalidWorkerQueueGroupError);
|
||||
});
|
||||
|
||||
test("error message lists every valid group", () => {
|
||||
try {
|
||||
resolveWorkerQueueGroup({ WORKER_QUEUE_GROUP: "bogus" });
|
||||
throw new Error("should have thrown");
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(InvalidWorkerQueueGroupError);
|
||||
const message = (error as Error).message;
|
||||
for (const group of ["general", "mail", "import", "webhook", "plugin"]) {
|
||||
expect(message).toContain(group);
|
||||
}
|
||||
expect(message).toContain("docs/ops/worker-queues.md");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveQueueNamesForGroup", () => {
|
||||
test("mail group resolves to email queue", () => {
|
||||
expect(resolveQueueNamesForGroup("mail")).toEqual([queueNames.email]);
|
||||
});
|
||||
|
||||
test("general group includes notifications + maintenance + fileScan", () => {
|
||||
expect(resolveQueueNamesForGroup("general")).toEqual([queueNames.notifications, queueNames.maintenance, queueNames.fileScan]);
|
||||
});
|
||||
|
||||
test("import group includes imports + exports", () => {
|
||||
expect(resolveQueueNamesForGroup("import")).toEqual([queueNames.imports, queueNames.exports]);
|
||||
});
|
||||
|
||||
test("webhook group covers AI + browser automation", () => {
|
||||
expect(resolveQueueNamesForGroup("webhook")).toEqual([queueNames.aiChatbot, queueNames.browserAutomation]);
|
||||
});
|
||||
|
||||
test("plugin group resolves to plugin-invoke queue", () => {
|
||||
expect(resolveQueueNamesForGroup("plugin")).toEqual([queueNames.pluginInvoke]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveGroupConcurrency", () => {
|
||||
test("falls back to documented defaults when env is unset", () => {
|
||||
expect(resolveGroupConcurrency("general", {})).toBe(DEFAULT_GROUP_CONCURRENCY.general);
|
||||
expect(resolveGroupConcurrency("mail", {})).toBe(DEFAULT_GROUP_CONCURRENCY.mail);
|
||||
expect(resolveGroupConcurrency("import", {})).toBe(DEFAULT_GROUP_CONCURRENCY.import);
|
||||
expect(resolveGroupConcurrency("webhook", {})).toBe(DEFAULT_GROUP_CONCURRENCY.webhook);
|
||||
expect(resolveGroupConcurrency("plugin", {})).toBe(DEFAULT_GROUP_CONCURRENCY.plugin);
|
||||
});
|
||||
|
||||
test("honours WORKER_CONCURRENCY_PLUGIN override", () => {
|
||||
expect(resolveGroupConcurrency("plugin", { WORKER_CONCURRENCY_PLUGIN: "12" })).toBe(12);
|
||||
});
|
||||
|
||||
test("honours explicit WORKER_CONCURRENCY_<GROUP> override", () => {
|
||||
expect(resolveGroupConcurrency("webhook", { WORKER_CONCURRENCY_WEBHOOK: "40" })).toBe(40);
|
||||
expect(resolveGroupConcurrency("mail", { WORKER_CONCURRENCY_MAIL: "8" })).toBe(8);
|
||||
});
|
||||
|
||||
test("ignores non-numeric or zero/negative overrides and uses default", () => {
|
||||
expect(resolveGroupConcurrency("mail", { WORKER_CONCURRENCY_MAIL: "abc" })).toBe(DEFAULT_GROUP_CONCURRENCY.mail);
|
||||
expect(resolveGroupConcurrency("mail", { WORKER_CONCURRENCY_MAIL: "0" })).toBe(DEFAULT_GROUP_CONCURRENCY.mail);
|
||||
expect(resolveGroupConcurrency("mail", { WORKER_CONCURRENCY_MAIL: "-5" })).toBe(DEFAULT_GROUP_CONCURRENCY.mail);
|
||||
});
|
||||
});
|
||||
|
||||
describe("bootstrapWorkerGroup", () => {
|
||||
test("returns a fully-resolved record for valid env", () => {
|
||||
expect(
|
||||
bootstrapWorkerGroup({ WORKER_QUEUE_GROUP: "import", WORKER_CONCURRENCY_IMPORT: "2" })
|
||||
).toEqual({
|
||||
group: "import",
|
||||
queueNames: [queueNames.imports, queueNames.exports],
|
||||
concurrency: 2,
|
||||
concurrencyEnvVar: "WORKER_CONCURRENCY_IMPORT",
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects invalid group", () => {
|
||||
expect(() => bootstrapWorkerGroup({ WORKER_QUEUE_GROUP: "" })).toThrow(InvalidWorkerQueueGroupError);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user