test: isolate conditional integration runner

This commit is contained in:
2026-07-31 07:59:48 +00:00
parent 425c258bf5
commit 2378bfee92
5 changed files with 419 additions and 70 deletions
@@ -19,7 +19,8 @@ import { createGameApiServer } from '../src/server.js';
const databaseUrl = process.env.INPUT_EVENT_DATABASE_URL;
const integration = describe.skipIf(!databaseUrl || !process.env.REDIS_URL);
const profileId = process.env.POSTGRES_SCHEMA ?? 'conditional_integration';
const profileName = `che:nation-html-${process.pid}`;
const runId = process.env.CONDITIONAL_INTEGRATION_RUN_ID ?? String(process.pid);
const profileName = `che:nation-html-${runId}`;
const userId = `nation-html-user-${process.pid}`;
const fixtureId = 900_000 + (process.pid % 50_000);
const secret = 'nation-html-http-secret';
@@ -57,6 +58,18 @@ const restoreEnv = (): void => {
}
};
const deleteProfileRedisKeys = async (): Promise<void> => {
if (!redis) {
return;
}
for await (const key of redis.client.scanIterator({
MATCH: `sammo:game:*:${profileName}:*`,
COUNT: 100,
})) {
await redis.client.del(key);
}
};
integration('nation HTML purification over HTTP transport', () => {
beforeAll(async () => {
uploadDir = await fs.mkdtemp(path.join(os.tmpdir(), 'sammo-nation-html-http-'));
@@ -150,6 +163,7 @@ integration('nation HTML purification over HTTP transport', () => {
await db?.nation.deleteMany({ where: { id: fixtureId } });
await db?.worldState.deleteMany({ where: { id: fixtureId } });
await disconnectDb?.();
await deleteProfileRedisKeys();
await redis?.disconnect();
if (uploadDir) {
await fs.rm(uploadDir, { recursive: true, force: true });
@@ -19,7 +19,8 @@ import { createGameApiServer } from '../src/server.js';
const databaseUrl = process.env.INPUT_EVENT_DATABASE_URL;
const integration = describe.skipIf(!databaseUrl || !process.env.REDIS_HOST || !process.env.REDIS_PORT);
const profileId = process.env.POSTGRES_SCHEMA ?? 'conditional_integration';
const profileName = `che:security-http-${process.pid}`;
const runId = process.env.CONDITIONAL_INTEGRATION_RUN_ID ?? String(process.pid);
const profileName = `che:security-http-${runId}`;
const userId = `security-http-user-${process.pid}`;
const generalId = 990_001;
const secret = 'security-http-e2e-secret';
@@ -56,6 +57,18 @@ const restoreEnv = (): void => {
}
};
const deleteProfileRedisKeys = async (): Promise<void> => {
if (!redis) {
return;
}
for await (const key of redis.client.scanIterator({
MATCH: `sammo:game:*:${profileName}:*`,
COUNT: 100,
})) {
await redis.client.del(key);
}
};
const buildPayload = (suffix: string, sanctions: GameSessionTokenPayload['sanctions']): GameSessionTokenPayload => ({
version: 1,
profile: profileName,
@@ -144,6 +157,7 @@ integration('game API security over HTTP transport', () => {
await server?.app.close();
await db?.general.deleteMany({ where: { id: generalId } });
await disconnectDb?.();
await deleteProfileRedisKeys();
await redis?.disconnect();
if (uploadDir) {
await fs.rm(uploadDir, { recursive: true, force: true });