mirror of
https://github.com/tiennm99/noitu.git
synced 2026-10-05 22:14:27 +00:00
Create a room and share a six-character code or an invite link; join by either. The waiting room shows the code until an opponent arrives. During a game the opponent's disconnection raises a banner with the grace countdown, and their return clears it. When the game ends, the rematch prompt appears only while an offer is actually open, so there is never a button that can only produce an error. The board is now one component both modes render, which is what makes online play the same screen as the bot game rather than a second implementation of it. Room codes are normalized by stripping separators and reading the code out of a pasted invite link, and nothing else. Filtering out every character outside the alphabet would turn any sentence into six plausible letters and send the player to a room that was never theirs. The socket now opens when the player asks for a room, not on arrival: the handshake carries the nickname once, and a socket opened before they typed it introduced them under whatever was stored beforehand. A tab that already holds a session reconnects immediately instead, so refreshing mid-game returns to the game. A resume the server cannot honour is dropped quietly rather than opening the lobby with an error the player did nothing to cause. The client also notices a socket that fails without closing. Nothing did before, so the page kept showing a live connection and a running countdown over a socket nothing could reach. A tick that fired late is ignored, because a backgrounded tab has its timers throttled and would otherwise close a healthy connection every time the player switched away.
47 lines
1.8 KiB
JavaScript
47 lines
1.8 KiB
JavaScript
// The upstream dictionary is pinned in two places: the Makefile, which builds
|
|
// it for a developer, and the Dockerfile, which builds it for the image. They
|
|
// have to agree, or the container ships a wordlist nobody tested against.
|
|
//
|
|
// This lives in the JavaScript suite for no better reason than that it is the
|
|
// suite that already reads other files in the repository. It is checking two
|
|
// build files, not the frontend.
|
|
|
|
import { readFileSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const makefile = readFileSync(fileURLToPath(new URL('../../Makefile', import.meta.url)), 'utf8');
|
|
const dockerfile = readFileSync(fileURLToPath(new URL('../../Dockerfile', import.meta.url)), 'utf8');
|
|
|
|
/**
|
|
* @param {string} source
|
|
* @param {RegExp} pattern
|
|
* @param {string} what
|
|
*/
|
|
function pin(source, pattern, what) {
|
|
const match = source.match(pattern);
|
|
expect(match, `${what} not found`).not.toBeNull();
|
|
return match?.[1].trim();
|
|
}
|
|
|
|
describe('the pinned upstream dictionary', () => {
|
|
const makeUrl = pin(makefile, /DICT_URL\s*:?=\s*(\S+)/, 'DICT_URL in the Makefile');
|
|
const makeSha = pin(makefile, /DICT_SHA256\s*:?=\s*(\S+)/, 'DICT_SHA256 in the Makefile');
|
|
const dockerUrl = pin(dockerfile, /ARG DICT_URL=(\S+)/, 'DICT_URL in the Dockerfile');
|
|
const dockerSha = pin(dockerfile, /ARG DICT_SHA256=(\S+)/, 'DICT_SHA256 in the Dockerfile');
|
|
|
|
it('is the same release in both build files', () => {
|
|
expect(dockerUrl).toBe(makeUrl);
|
|
});
|
|
|
|
it('is pinned to the same checksum in both build files', () => {
|
|
expect(dockerSha).toBe(makeSha);
|
|
});
|
|
|
|
it('is a checksum, not a placeholder', () => {
|
|
// A guard that only compared the two would pass happily if both were
|
|
// blanked, which is the one way this pin can silently stop pinning.
|
|
expect(makeSha).toMatch(/^[0-9a-f]{64}$/);
|
|
});
|
|
});
|