test: bring the test suite up to date, and let it run on Windows

The smoke, features, account and qol tests had fallen behind the server
and failed before reaching their end. Each now checks what the server
does on purpose today:

- harness: the chat filter messages the server sends unasked ("xfl"
  after every login, "xfa" on the first room) are set aside like "zs".
- smoke: a banned account's sign-in is refused with "account_banned", so
  the login-choices check uses a fresh account instead of the banned Carol.
- features: a shop's name comes from its room file, read the first time
  anyone goes in (the first visitor sees a name made from the path). A
  scout goes in first until the file is read, so the check no longer
  depends on what an earlier run left in cache/.
- account: a deleted account's name is held for NAME_HELD_DAYS, so taking
  it again right away is "username_taken".
- qol: the commands page sets what to type in italics.

And on Windows: withServer waits for the server process to exit before
removing its data directory, and retries; the database stays locked until
the process is gone, and the cleanup's EPERM hid the test's own result.

All seven test files pass (smoke, features, account, qol, buddygames,
restored, and staff in the next commit).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
SnipzilandClaude Opus 5.5 committed 2026-10-16 22:42:36 -04:00
1 parent edca7bf790
commit 63dc43ebb3
5 files changed
+46 -9

No files matched your search

+3 -1
View File
@@ -219,7 +219,9 @@ const run = async () => {
assert.strictEqual((await mine("me", undefined, ben)).status, 401);
assert.strictEqual((await authenticate("Ben", "Password01")).status, 401);
assert.ok(!(await panel("accounts", undefined, admin)).data.accounts.some(account => account.username === "Ben"));
assert.strictEqual((await register("Ben", 5)).status, 200); // the name is free again
// the name is held for a while (lib/accounts.js, NAME_HELD_DAYS): the
// players Ben met still know him by it.
assert.deepStrictEqual(await (await register("Ben", 5)).json(), {error: "username_taken"});
b2.socket.destroy();
a.socket.destroy();
b.socket.destroy();
+25 -1
View File
@@ -45,7 +45,7 @@ const wall = async body => (await postJson(`${BASE}/wall`, body)).json();
const run = async () => {
const registerJson = body => fetch(`${BASE}/api/register`, {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({avatarType: 1, agreed: true, ...body})});
for (const username of ["Ann", "Ben", "Cat"]) {
for (const username of ["Ann", "Ben", "Cat", "Scout"]) {
assert.strictEqual((await registerJson({username, password: "Password01"})).status, 200);
}
@@ -85,6 +85,30 @@ const run = async () => {
await a.untilXt("ac");
await a.nextXt("il");
// the shop's name and stalls come from its room file (lib/roominfo.js),
// read the first time anyone goes in; until then the name is made from its
// path. a scout goes in first and comes back until the file has been read,
// so that what follows does not depend on what an earlier run left in the
// cache. (the scout never enters the township, so a and b see nothing.)
const scoutAuth = await (await postJson(`${BASE}/authenticate`, {username: "Scout", password: "Password01"})).json();
const scout = new harness.GameClient(GAME_PORT);
await scout.connect();
assert.strictEqual((await scout.logIn("Scout", scoutAuth.auth_token)).status, "1");
let scoutRoom = 1;
for (let tries = 0; ; tries++) {
scout.xt("rj", scoutRoom, "jamaa_township.clothes_shop#1", 1, 0, 0);
const there = await scout.untilXt("rj");
if (there[14] === "Jam Mart Clothing") {
break;
}
assert.ok(tries < 40, `the shop's room file was never read (still "${there[14]}")`);
await new Promise(resolve => setTimeout(resolve, 500));
scout.xt("rj", there[4], "sarepia.room_main#1", 1, 0, 0);
scoutRoom = (await scout.untilXt("rj"))[4];
}
scout.socket.destroy();
await new Promise(resolve => setTimeout(resolve, 300)); // gone before Ben walks in
// --- a shop's title is its room's name, as the id of the string that says so
b.xt("rj", roomId, "jamaa_township.clothes_shop#1", 1, 0, 0);
const shopRoom = await b.untilXt("rj");
+10 -1
View File
@@ -100,6 +100,11 @@ class GameClient {
this.varUpdates.push(fields);
continue;
}
// the chat filter settings ("xfl", after every login) and the one-time
// question which filter to use ("xfa", on the first room) come unasked.
if ((fields[0] === "xfl" || fields[0] === "xfa") && cmd !== fields[0]) {
continue;
}
if (this.unasked(fields)) {
continue;
}
@@ -165,8 +170,12 @@ const withServer = async (name, httpPort, gamePort, run) => {
throw err;
}
finally {
// on Windows the database stays locked until the process has gone, so
// wait for it before throwing its files away.
const exited = server.exitCode !== null ? Promise.resolve() : new Promise(resolve => server.once("exit", resolve));
server.kill();
fs.rmSync(dataDir, {recursive: true, force: true});
await exited;
fs.rmSync(dataDir, {recursive: true, force: true, maxRetries: 10, retryDelay: 200});
}
};
+1 -1
View File
@@ -149,7 +149,7 @@ const run = async () => {
assert.strictEqual(await owned(), before + 3);
say(a, roomId, "!help"); // gone: the list is at /commands
assert.strictEqual((await a.untilXt("uc"))[3], "!help");
assert.match(await (await fetch(`${BASE}/commands`)).text(), /!outfit save NAME/);
assert.match(await (await fetch(`${BASE}/commands`)).text(), /!outfit save <i>NAME<\/i>/); // the page sets what to type in italics
// --- den undo, mail, music
say(a, roomId, "!den undo");
+7 -5
View File
@@ -621,14 +621,16 @@ const run = async () => {
// --- the custom client's login choices: honoured for that session only
assert.strictEqual((await (await fetch(`${BASE}/flashvars`)).json()).loginChoices, true);
const chosen = await (await postJson(`${BASE}/authenticate`, {username: "Carol", password: "Password03",
// (a fresh account: Carol is banned by now, and a banned account's
// sign-in is refused with "account_banned", so it gets no token.)
assert.strictEqual((await registerJson({username: "Erin", password: "Password05"})).status, 200);
const chosen = await (await postJson(`${BASE}/authenticate`, {username: "Erin", password: "Password05",
login_choices: {accountType: 0, isGuide: true, membershipDays: 12, isModerator: "yes"}})).json();
// (Carol is banned from the game by now, so only the web side is checked.)
assert.strictEqual((await (await fetch(`${BASE}/player`, {headers: {Authorization: `Bearer ${chosen.auth_token}`}})).json()).game_account_type, 0);
a.xt("ag", denId, "Carol", 0);
a.xt("ag", denId, "Erin", 0);
assert.deepStrictEqual((await a.untilXt("ag")).slice(5, 7), ["0", "1"]); // account type, guide
await postJson(`${BASE}/authenticate`, {username: "Carol", password: "Password03"}); // and back to normal
a.xt("ag", denId, "Carol", 0);
await postJson(`${BASE}/authenticate`, {username: "Erin", password: "Password05"}); // and back to normal
a.xt("ag", denId, "Erin", 0);
assert.deepStrictEqual((await a.untilXt("ag")).slice(5, 7), ["2", "0"]);
// --- custom colours: an id for four RGB values, announced to everyone