Separate runtime profile identity from scenario
This commit is contained in:
@@ -25,7 +25,7 @@ export interface GameApiConfig {
|
|||||||
export const resolveGameApiConfigFromEnv = (env: NodeJS.ProcessEnv = process.env): GameApiConfig => {
|
export const resolveGameApiConfigFromEnv = (env: NodeJS.ProcessEnv = process.env): GameApiConfig => {
|
||||||
const profile = env.PROFILE ?? env.SERVER_PROFILE ?? 'hwe';
|
const profile = env.PROFILE ?? env.SERVER_PROFILE ?? 'hwe';
|
||||||
const scenario = env.SCENARIO ?? 'default';
|
const scenario = env.SCENARIO ?? 'default';
|
||||||
const profileName = `${profile}:${scenario}`;
|
const profileName = env.GAME_PROFILE_NAME ?? `${profile}:${scenario}`;
|
||||||
const secret = env.GAME_TOKEN_SECRET ?? env.GATEWAY_TOKEN_SECRET ?? '';
|
const secret = env.GAME_TOKEN_SECRET ?? env.GATEWAY_TOKEN_SECRET ?? '';
|
||||||
if (!secret) {
|
if (!secret) {
|
||||||
throw new Error('GAME_TOKEN_SECRET is required for game token verification.');
|
throw new Error('GAME_TOKEN_SECRET is required for game token verification.');
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
import { resolveGameApiConfigFromEnv } from '../src/config.js';
|
||||||
|
|
||||||
|
describe('resolveGameApiConfigFromEnv', () => {
|
||||||
|
it('keeps the deployment profile identity separate from the scenario id', () => {
|
||||||
|
const config = resolveGameApiConfigFromEnv({
|
||||||
|
PROFILE: 'hwe',
|
||||||
|
SCENARIO: '1010',
|
||||||
|
GAME_PROFILE_NAME: 'hwe:2',
|
||||||
|
GAME_TOKEN_SECRET: 'test-secret',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(config.profile).toBe('hwe');
|
||||||
|
expect(config.scenario).toBe('1010');
|
||||||
|
expect(config.profileName).toBe('hwe:2');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('falls back to the legacy profile and scenario pair', () => {
|
||||||
|
const config = resolveGameApiConfigFromEnv({
|
||||||
|
PROFILE: 'hwe',
|
||||||
|
SCENARIO: '2',
|
||||||
|
GAME_TOKEN_SECRET: 'test-secret',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(config.profileName).toBe('hwe:2');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -300,6 +300,7 @@ export const buildProcessDefinitions = (
|
|||||||
...baseEnv,
|
...baseEnv,
|
||||||
PROFILE: profile.profile,
|
PROFILE: profile.profile,
|
||||||
SCENARIO: profile.scenario,
|
SCENARIO: profile.scenario,
|
||||||
|
GAME_PROFILE_NAME: profile.profileName,
|
||||||
GAME_API_PORT: String(profile.apiPort),
|
GAME_API_PORT: String(profile.apiPort),
|
||||||
GAME_TRPC_PATH: `/${profile.profile}/api/trpc`,
|
GAME_TRPC_PATH: `/${profile.profile}/api/trpc`,
|
||||||
GAME_API_EVENTS_PATH: `/${profile.profile}/api/events`,
|
GAME_API_EVENTS_PATH: `/${profile.profile}/api/events`,
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ describe('buildProcessDefinitions', () => {
|
|||||||
expect(definitions.api.cwd).toBe(path.join(buildWorkspace, 'app', 'game-api'));
|
expect(definitions.api.cwd).toBe(path.join(buildWorkspace, 'app', 'game-api'));
|
||||||
expect(definitions.api.script).toBe(path.join(buildWorkspace, 'app', 'game-api', 'dist', 'index.js'));
|
expect(definitions.api.script).toBe(path.join(buildWorkspace, 'app', 'game-api', 'dist', 'index.js'));
|
||||||
expect(definitions.api.env).toMatchObject({
|
expect(definitions.api.env).toMatchObject({
|
||||||
|
GAME_PROFILE_NAME: 'che:2',
|
||||||
GAME_TRPC_PATH: '/che/api/trpc',
|
GAME_TRPC_PATH: '/che/api/trpc',
|
||||||
GAME_API_EVENTS_PATH: '/che/api/events',
|
GAME_API_EVENTS_PATH: '/che/api/events',
|
||||||
GAME_UPLOAD_PATH: '/che/api/uploads',
|
GAME_UPLOAD_PATH: '/che/api/uploads',
|
||||||
|
|||||||
@@ -55,6 +55,18 @@ const resetScenario = async (page: Page, scenarioId: string, sourceCommit: strin
|
|||||||
timeout: 30_000,
|
timeout: 30_000,
|
||||||
});
|
});
|
||||||
await expect(profileStatus.locator('..').locator('.text-red-400')).toHaveCount(0);
|
await expect(profileStatus.locator('..').locator('.text-red-400')).toHaveCount(0);
|
||||||
|
await expect
|
||||||
|
.poll(
|
||||||
|
() =>
|
||||||
|
page.evaluate(async () => {
|
||||||
|
const response = await fetch(
|
||||||
|
'/hwe/api/trpc/lobby.info,public.getMapLayout,public.getCachedMap?batch=1&input=%7B%7D'
|
||||||
|
);
|
||||||
|
return response.status;
|
||||||
|
}),
|
||||||
|
{ timeout: 60_000 }
|
||||||
|
)
|
||||||
|
.toBe(200);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createGeneralAndInspectIcons = async (
|
const createGeneralAndInspectIcons = async (
|
||||||
|
|||||||
Reference in New Issue
Block a user