Files
wownerogue/test/releaseIdentity.test.js
jwinterm fad2a695bd Wownerogue
A browser-based roguelike synchronized with crypto block timing. A run is a race
against the next block: reach the exit before the block lands, or the house wins.
The same codebase runs the solo dungeon, the social Tavern, and operator-selected
PvP and race rulesets, with separate free and paid leaderboards.

Self-hostable under the MIT License. See README.md to run it, docs/ARCHITECTURE.md
for the design, and docs/DEPLOY.md to operate an instance.
2026-07-27 08:23:01 -04:00

65 lines
2.3 KiB
JavaScript

const fs = require('fs');
const os = require('os');
const path = require('path');
const {
loadReleaseIdentity,
readBoundedRegularFile
} = require('../src/config/releaseIdentity');
describe('immutable release identity', () => {
let root;
beforeEach(() => {
root = fs.mkdtempSync(path.join(os.tmpdir(), 'wowngeon-release-identity-'));
});
afterEach(() => {
fs.rmSync(root, { recursive: true, force: true });
});
function writeIdentity(commit = 'a'.repeat(40), id = `git-${commit.slice(0, 12)}`) {
fs.writeFileSync(path.join(root, '.release-id'), `${id}\n`, { mode: 0o444 });
fs.writeFileSync(path.join(root, '.release-commit'), `${commit}\n`, { mode: 0o444 });
}
test('returns the matching artifact release ID and commit', () => {
writeIdentity();
expect(loadReleaseIdentity({ releaseRoot: root, production: true })).toEqual({
verified: true,
id: `git-${'a'.repeat(12)}`,
commit: 'a'.repeat(40)
});
});
test('fails production closed when identity files disagree', () => {
writeIdentity('b'.repeat(40), `git-${'c'.repeat(12)}`);
expect(() => loadReleaseIdentity({ releaseRoot: root, production: true }))
.toThrow('production release identity is absent or invalid');
});
test('fails production closed when either identity file is absent', () => {
expect(() => loadReleaseIdentity({ releaseRoot: root, production: true }))
.toThrow('production release identity is absent or invalid');
});
test('returns an explicit unverified identity outside production', () => {
expect(loadReleaseIdentity({ releaseRoot: root, production: false })).toEqual({
verified: false,
id: null,
commit: null
});
});
test('refuses symlinks and oversized identity files', () => {
const target = path.join(root, 'target');
fs.writeFileSync(target, 'a'.repeat(40));
const linked = path.join(root, 'linked');
fs.symlinkSync(target, linked);
expect(() => readBoundedRegularFile(linked)).toThrow();
const oversized = path.join(root, 'oversized');
fs.writeFileSync(oversized, 'x'.repeat(129));
expect(() => readBoundedRegularFile(oversized)).toThrow('unsafe shape');
});
});