test: server 测试共用建库与假引擎,sse-pg 归入串行组
- 新增 apps/server/test/support/{pg,engine}.ts:测试库地址、可用性探测、schema 咨询锁、
建 schema + 加锁迁移 + 删除、可选去重的假引擎;6 份 harness 改用它(acquisition-organize 与
file-manager 原先迁移不加锁,并行下有冲突隐患,一并修正)
- sse-pg 起子进程,并行下子进程启动超时,归入 serial
- 修正 b61335e 挪动 / 改名测试后遗留的 import 排序与格式(当时 lint 检查经管道被吞掉退出码)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
7cc3742d31
commit
c9e8120fc6
25 files changed
+254
-328
No files matched your search
@@ -2,7 +2,7 @@ import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import type { FakeScript } from "@umt/agent";
|
||||
import { type DB, migrateToLatest } from "@umt/db";
|
||||
import type { DB } from "@umt/db";
|
||||
import {
|
||||
createMockQb,
|
||||
createMockTmdb,
|
||||
@@ -13,8 +13,7 @@ import {
|
||||
TMDB_FIXTURES,
|
||||
type TmdbFixture,
|
||||
} from "@umt/testkit";
|
||||
import { Kysely, PostgresDialect, sql } from "kysely";
|
||||
import pg from "pg";
|
||||
import { type Kysely, sql } from "kysely";
|
||||
import { ConfigSchema } from "../../src/config.ts";
|
||||
import { type Bootstrapped, bootstrap } from "../../src/context.ts";
|
||||
import { createApp } from "../../src/http/app.ts";
|
||||
@@ -26,30 +25,18 @@ import { setDefaultUpstream } from "../../src/modules/pi/store.ts";
|
||||
import type { ServerModule } from "../../src/modules/types.ts";
|
||||
import type { WebSearchModuleOptions } from "../../src/modules/websearch/index.ts";
|
||||
import { type RunningWorker, startWorker } from "../../src/worker/index.ts";
|
||||
import { withSchemaLock } from "../auth-settings/harness.ts";
|
||||
import { createTestSchema, dropSchemas, PG_URL, uniqueSchema } from "../support/pg.ts";
|
||||
import { buildModules } from "./fixtures/modules.ts";
|
||||
|
||||
// 端到端夹具:真实 PG(每个文件独立业务 schema + 独立引擎 schema)+ 真实四个模块 + OpenWorkflow 引擎/worker/outbox 中继
|
||||
// + testkit mock(qB / TMDB / RSS)+ 临时目录(缓存卷、媒体库、Agent 会话)。HTTP 走 createApp(DEV key = admin)。
|
||||
|
||||
export const PG_URL = process.env.DATABASE_URL ?? "postgres://umt:umt@localhost:55433/umt";
|
||||
export { PG_URL, pgAvailable } from "../support/pg.ts";
|
||||
export const DEV_KEY = "dev-admin-e2e-key";
|
||||
export const MASTER_KEY = "e2e-master-key-0123456789";
|
||||
/** mock TMDB 的 v3 key(32 位十六进制,经设置 metadata.tmdbApiKey 录入) */
|
||||
export const TMDB_KEY = "0123456789abcdef0123456789abcdef";
|
||||
|
||||
export async function pgAvailable(): Promise<boolean> {
|
||||
if (process.env.UMT_SKIP_DB_TESTS === "1") return false;
|
||||
const c = new pg.Client({ connectionString: PG_URL, connectionTimeoutMillis: 2000 });
|
||||
try {
|
||||
await c.connect();
|
||||
await c.end();
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: 测试断言直接读 JSON
|
||||
type Loose = any;
|
||||
|
||||
@@ -110,19 +97,10 @@ export async function waitFor<T>(
|
||||
}
|
||||
|
||||
export async function createE2E(name: string, opts: E2EOptions = {}): Promise<E2E> {
|
||||
const uniq = `${process.pid.toString(36)}${Math.random().toString(36).slice(2, 7)}`;
|
||||
const biz = `e2e_${name}_${uniq}`;
|
||||
const ts = await createTestSchema(uniqueSchema(`e2e_${name}`), { max: 10 });
|
||||
const { schema: biz } = ts;
|
||||
const db: Kysely<DB> = ts.db;
|
||||
const ow = `${biz}_ow`;
|
||||
const admin = new pg.Client({ connectionString: PG_URL });
|
||||
await admin.connect();
|
||||
await admin.query(`create schema ${biz}`);
|
||||
await admin.end();
|
||||
const db = new Kysely<DB>({
|
||||
dialect: new PostgresDialect({
|
||||
pool: new pg.Pool({ connectionString: PG_URL, max: 10, options: `-c search_path=${biz},public` }),
|
||||
}),
|
||||
});
|
||||
await withSchemaLock(() => migrateToLatest(db, { migrationTableSchema: biz }));
|
||||
|
||||
const qb = await createMockQb({ addVisibleAfterPolls: 0 });
|
||||
const tmdb = await createMockTmdb({ apiKey: TMDB_KEY, fixtures: opts.tmdbFixtures ?? TMDB_FIXTURES });
|
||||
@@ -225,13 +203,7 @@ export async function createE2E(name: string, opts: E2EOptions = {}): Promise<E2
|
||||
await lib.cleanup();
|
||||
await cache.cleanup();
|
||||
await rm(sessionDir, { recursive: true, force: true });
|
||||
await withSchemaLock(async () => {
|
||||
const c = new pg.Client({ connectionString: PG_URL });
|
||||
await c.connect();
|
||||
await c.query(`drop schema if exists ${biz} cascade`);
|
||||
await c.query(`drop schema if exists ${ow} cascade`);
|
||||
await c.end();
|
||||
});
|
||||
await dropSchemas(biz, ow);
|
||||
},
|
||||
};
|
||||
// 通用设置:fake 上游(脚本化假模型,设为默认)、TMDB 走设置里的 secret、结算快一点
|
||||
|
||||
Reference in new issue
Block a user