52 lines
2.1 KiB
TypeScript
52 lines
2.1 KiB
TypeScript
import fs from 'node:fs/promises';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
|
|
import { readReleaseManifest } from '../src/orchestrator/releaseManifest.js';
|
|
|
|
const temporaryDirectories: string[] = [];
|
|
|
|
const createWorkspace = async (gatewayHead: string, gameHead: string): Promise<string> => {
|
|
const workspace = await fs.mkdtemp(path.join(os.tmpdir(), 'sammo-release-manifest-'));
|
|
temporaryDirectories.push(workspace);
|
|
await fs.mkdir(path.join(workspace, 'packages/infra/prisma/gateway-migrations', gatewayHead), {
|
|
recursive: true,
|
|
});
|
|
await fs.mkdir(path.join(workspace, 'packages/infra/prisma/migrations', gameHead), { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(workspace, 'release-manifest.json'),
|
|
JSON.stringify({
|
|
formatVersion: 1,
|
|
controllerProtocol: 1,
|
|
gatewaySchemaHead: gatewayHead,
|
|
gameSchemaHead: gameHead,
|
|
components: ['gateway-api', 'gateway-frontend', 'game-api', 'game-engine', 'game-frontend'],
|
|
})
|
|
);
|
|
return workspace;
|
|
};
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(temporaryDirectories.splice(0).map((directory) => fs.rm(directory, { recursive: true })));
|
|
});
|
|
|
|
describe('readReleaseManifest', () => {
|
|
it('accepts a manifest whose schema heads match the selected workspace', async () => {
|
|
const workspace = await createWorkspace('20260801000000_gateway', '20260801000000_game');
|
|
|
|
await expect(readReleaseManifest(workspace)).resolves.toMatchObject({
|
|
gatewaySchemaHead: '20260801000000_gateway',
|
|
gameSchemaHead: '20260801000000_game',
|
|
});
|
|
});
|
|
|
|
it('rejects a stale schema head before any deployment command runs', async () => {
|
|
const workspace = await createWorkspace('20260801000000_gateway', '20260801000000_game');
|
|
await fs.mkdir(path.join(workspace, 'packages/infra/prisma/migrations/20260802000000_newer'));
|
|
|
|
await expect(readReleaseManifest(workspace)).rejects.toThrow('does not match workspace head');
|
|
});
|
|
});
|