// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0 // The mariadb and mongodb compositions (profiles//README.md): the migrate job applies exactly // the list the web shell's readiness probe expects, the job adapter's own table among them, and the // worker serves every module job on BullMQ. `kit template:prune --profile postgres` removes this folder. import { expectedDialectMigrations } from "@app/config" import { appModules } from "@app/modules" import { buildRegistry } from "@conusai-kit/core" import { describe, expect, it } from "vitest" import { mariadbJobsMigration } from "../../apps/worker/src/dialect/mariadb/index.js" import { mongodbJobsCommands } from "../../apps/worker/src/dialect/mongodb/index.js" import { bullmqJobs, dialectMigrations, queueSlug } from "../../apps/worker/src/dialect/runtime.js" import { dialectSchedules } from "../../apps/worker/src/dialect/schedules.js" const registry = buildRegistry([...appModules]) describe("the dialect profiles' migrations", () => { for (const profile of ["mariadb", "mongodb"] as const) { it(`${profile}: the migrate job applies what readiness expects, kernel, jobs table and modules`, async () => { const expected = await expectedDialectMigrations(registry, profile) const applied = (await dialectMigrations(registry, profile)).map((migration) => migration.name) expect([...applied].sort()).toEqual([...expected].sort()) expect(expected).toEqual( expect.arrayContaining([ "0001_kernel", "0007_kit-jobs", "notes/0001_notes", // kit:notes "account/0001_account", ]), ) }) } it("builds the outbox relay's ledger table in each dialect", () => { expect(mariadbJobsMigration().statements.join("\n")).toContain("create table `kit_processed_events`") expect(mongodbJobsCommands()).toContainEqual(expect.objectContaining({ createCollection: "kit_processed_events" })) }) }) describe("the dialect profiles' worker", () => { it("serves every module job of the registry, with its own payload schema", () => { const jobs = bullmqJobs(registry) expect(Object.keys(jobs).sort()).toEqual(Object.keys(registry.jobs).sort()) for (const [name, def] of Object.entries(jobs)) expect(def.payload).toBe(registry.jobs[name]?.def.payload) }) it("schedules on each dialect worker only the module jobs of modules installed on its profile", () => { for (const profile of ["mariadb", "mongodb"] as const) { const jobs = dialectSchedules(registry, profile) .map((schedule) => schedule.job) .sort() // The account, file and inbox sweeps run on both; the agent module ships Postgres only. expect(jobs).toEqual([ "account.deletion.sweep", "account.sessions.revoke", "files.recover", "notifications.retention.sweep", ]) } }) it("keys the queue by the platform's project, in the alphabet BullMQ prefixes take", () => { const env = (id: string) => ({ deployment: { CONUSAI_PROJECT_ID: id } }) as Parameters[0] expect(queueSlug(env("42"))).toBe("p-42") expect(queueSlug(env("Proj_ID.9"))).toMatch(/^[a-z0-9][a-z0-9-]*$/) }) })