feat: initialize sunrise with 100-player shared rooms

This commit is contained in:
2026-10-30 16:36:35 +09:00
commit 31d6eac4c2
257 changed files with 66063 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
import assert from 'node:assert/strict';
import { randomUUID } from 'node:crypto';
import { MongoClient } from 'mongodb';
import { MongoVisitStore } from '../server/visits.ts';
// Isolated disposable database: never uses the application's MONGODB_DATABASE.
const database = `sunrise_verify_${randomUUID().replaceAll('-', '')}`;
const uri = process.env.MONGODB_URI ?? 'mongodb://172.16.0.7:27017';
const reader = new MongoClient(uri, { serverSelectionTimeoutMS: 5000 });
let store: MongoVisitStore | undefined;
try {
store = await MongoVisitStore.connect(uri, database);
const id = randomUUID(), now = new Date();
await store.insert({ _id: id, visitorId: randomUUID(), nickname: '연결 검증', locationId: 'gwanaksan',
roomId: 'gwanaksan-001', joinedAt: now, lastSeenAt: now, leftAt: null, endReason: null, serverInstanceId: randomUUID() });
await store.heartbeat([id], new Date(+now + 1000));
// A second connection must not rewrite an existing open visit.
const second = await MongoVisitStore.connect(uri, database);
await second.close();
await reader.connect();
const open = await reader.db(database).collection<{ _id: string; endReason: string | null }>('visitSessions').findOne({ _id: id });
assert.equal(open?.endReason, null, 'startup must not rewrite existing open visits');
await store.finish(id, new Date(+now + 2000), 'disconnect');
await reader.connect();
const record = await reader.db(database).collection<{ _id: string; lastSeenAt: Date; leftAt: Date; endReason: string }>('visitSessions').findOne({ _id: id });
assert.equal(record?.endReason, 'disconnect');
assert.equal(record?.leftAt.getTime(), +now + 2000);
assert.equal(record?.lastSeenAt.getTime(), +now + 2000);
assert.ok(!('equipment' in record!) && !('x' in record!), 'no transient player state in visit log');
console.log(JSON.stringify({ ok: true, tested: ['insert', 'heartbeat', 'finish', 'read'], isolatedDatabase: database }));
} finally {
await store?.close();
// This exact random database was created by this verification run alone.
if (store) await reader.db(database).dropDatabase();
await reader.close();
}