Каркас monorepo: scheduler, data_collector, khbuild_assistant_prep, khb_common; миграции; CI/CD
Some checks failed
ci / test (push) Failing after 20s
ci / deploy (push) Has been skipped

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 09:44:50 +03:00
commit ebb1cb7950
101 changed files with 4971 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { createTestDb, testDatabaseUrl, type TestDb } from "./testing/index.js";
const url = testDatabaseUrl();
const d = url ? describe : describe.skip;
d("миграции (временная БД)", () => {
let db: TestDb;
beforeAll(async () => {
db = await createTestDb(url!);
});
afterAll(async () => {
await db?.drop();
});
it("создают все таблицы, двойники _hist и представление", async () => {
const { rows } = await db.pool.query("select table_name from information_schema.tables where table_schema = 'public'");
const names = new Set(rows.map((r) => r.table_name as string));
for (const t of [
"jt_job", "jt_job_hist", "jt_task", "jt_task_hist", "jt_task_dependency_hist", "jt_task_assignment_hist",
"sync_source", "sync_snapshot", "sync_table_status", "purchase_task_ref", "calendar_day", "person",
"construction_manager", "assistant_project", "reminder_history", "sched_run", "ap_input_package",
"ap_input_package_item", "ap_agent_invocation", "active_task_list", "active_task", "v_agent_input",
])
expect(names.has(t), t).toBe(true);
});
it("справочник закупок засеян 9 реальными названиями", async () => {
const { rows } = await db.pool.query("select count(*)::int as n from purchase_task_ref");
expect(rows[0].n).toBe(9);
});
it("у всех таблиц включён RLS", async () => {
const { rows } = await db.pool.query(
"select relname from pg_class c join pg_namespace n on n.oid = c.relnamespace where n.nspname = 'public' and c.relkind = 'r' and not c.relrowsecurity and relname <> 'schema_migrations'",
);
expect(rows).toEqual([]);
});
it("sched_run: повторный старт в ту же минуту невозможен", async () => {
const q = "insert into sched_run (job_name, scheduled_minute, status) values ('j', '2026-10-11T10:00:00Z', 'started')";
await db.pool.query(q);
await expect(db.pool.query(q)).rejects.toThrow(/duplicate key/);
});
});