Headers: - Every JavaScript file (sources, front, scripts, tests) starts with a /** @file … */ header, in the three levels used by sokko-g: a short description for simple files; Utilisé par / Attention / @see for shared modules; a full header (context, entry points, callers, dependencies, pitfalls) for index.js, the music queue, the web server, the storage manager and the jukebox page script. - No @author, @version or @since: git already knows. - test/fileHeaders.test.js fails `npm run check` when a header is missing or a central file's header is incomplete. Stylesheet (no visual change, checked by comparing every element's computed styles in Chromium at 1280, 800 and 400 px, hover included): - Role header and section comments. - Transparent shades derive from the colour variables with color-mix() instead of copied rgba() values; new tokens for repeated values (text, text on accent, accent gradient, white veils, shadow). - Native nesting for buttons, the live indicator, upload rows and home cards; drop the unused .hero__visual--large and redundant rules. - Utility classes move to the end so they win over components. The library list's u-mt-1, which never applied (.list reset it), is removed to keep the layout as it was. Docs: CONTRIBUTING.md describes the language, header and stylesheet conventions; CLAUDE.md points to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
2.5 KiB
JavaScript
66 lines
2.5 KiB
JavaScript
/**
|
|
* @file Vérifie le sondage TCP des serveurs de jeux, l'état saisi à la main et le message publié.
|
|
*/
|
|
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import net from "node:net";
|
|
|
|
Object.assign(process.env, {
|
|
NODE_ENV: "test",
|
|
DISCORD_GUILD_ID: "1",
|
|
SHINUWA_USER_ID: "1",
|
|
WEB_SERVER_PORT: "3000",
|
|
WEB_API_KEY: "test-key",
|
|
DISCORD_APPLICATION_ID: "1",
|
|
DISCORD_TOKEN: "test-token",
|
|
VOICE_CHANNEL_ID: "1",
|
|
TEXT_CHANNEL_ID: "1",
|
|
GAME_SERVERS_MESSAGE_ID: "1",
|
|
});
|
|
|
|
const { buildMessage, probeTcp, serverStatus } = await import(
|
|
"../src/features/showGameServers.js"
|
|
);
|
|
|
|
test("a listening TCP port is online, a closed one offline", async () => {
|
|
const server = net.createServer((socket) => socket.end());
|
|
server.listen(0, "127.0.0.1");
|
|
await new Promise((resolve) => server.once("listening", resolve));
|
|
const { port } = server.address();
|
|
try {
|
|
assert.equal(await probeTcp("127.0.0.1", port), true);
|
|
} finally {
|
|
await new Promise((resolve) => server.close(resolve));
|
|
}
|
|
assert.equal(await probeTcp("127.0.0.1", port), false);
|
|
});
|
|
|
|
test("servers without check keep their manual status", async () => {
|
|
const probe = () => assert.fail("must not probe");
|
|
assert.equal(await serverStatus({ active: true }, probe), true);
|
|
assert.equal(await serverStatus({ active: false }, probe), false);
|
|
});
|
|
|
|
test("checked servers are probed on checkPort, else on port", async () => {
|
|
const probed = [];
|
|
const probe = async (host, port) => probed.push(`${host}:${port}`) && true;
|
|
await serverStatus({ address: "games.example.com:8211", port: 8211, check: true, checkPort: 25575 }, probe);
|
|
await serverStatus({ address: "games.example.com:25566", port: 25566, check: true }, probe);
|
|
assert.deepEqual(probed, ["games.example.com:25575", "games.example.com:25566"]);
|
|
assert.equal(await serverStatus({ address: "x", check: true }, probe), false);
|
|
});
|
|
|
|
test("the status message is coloured and mentions the owner", () => {
|
|
const message = buildMessage({
|
|
servers: [
|
|
{ game: "Minecraft", address: "games.example.com:25565", active: true },
|
|
{ game: "Palworld", address: "games.example.com:8211", active: false },
|
|
],
|
|
});
|
|
// Les couleurs des blocs ansi de Discord demandent le caractère ESC lui-même.
|
|
assert.ok(message.includes("Minecraft : \u001b[2;32mOnline\u001b[0m"));
|
|
assert.ok(message.includes("Palworld : \u001b[2;31mOffline\u001b[0m"));
|
|
// OWNER_USER_ID absent : l'ancien nom SHINUWA_USER_ID est encore accepté.
|
|
assert.match(message, /<@1>/);
|
|
});
|