입찰 장수가 사라진 유니크 경매를 복구하고 시스템 공지를 지원한다
This commit is contained in:
1 parent
0ae14d5ee0
commit
3f51bec90a
6 files changed
+344
-23
No files matched your search
@@ -13,6 +13,8 @@ import type { AppRouter as GameAppRouter } from '@sammo-ts/game-api';
|
||||
import {
|
||||
createGameApiServer,
|
||||
buildAuctionTimerKeys,
|
||||
buildAuctionFinalizeRequestId,
|
||||
processDueAuctionId,
|
||||
seedAuctionTimers,
|
||||
DatabaseTurnDaemonTransport,
|
||||
} from '@sammo-ts/game-api';
|
||||
@@ -412,6 +414,33 @@ describe('auction integration flow', () => {
|
||||
}
|
||||
}, 30_000);
|
||||
|
||||
it('restricts public system messages to superusers and publishes a notice once', async () => {
|
||||
if (!gameServer || !gameClient || !gameConnector || !userSessions[0]) {
|
||||
throw new Error('runtime not ready');
|
||||
}
|
||||
const notice = {
|
||||
noticeId: 'auction-system-notice-test',
|
||||
text: '[Codex] 유니크 경매 정산 오류를 수정했습니다.',
|
||||
};
|
||||
const anonymous = createGameClient(gameUrl, gameServer.config.trpcPath, {});
|
||||
const player = createGameClient(gameUrl, gameServer.config.trpcPath, { value: userSessions[0].accessToken });
|
||||
await expect(anonymous.messages.sendSystem.mutate(notice)).rejects.toMatchObject({
|
||||
data: { code: 'UNAUTHORIZED' },
|
||||
});
|
||||
await expect(player.messages.sendSystem.mutate(notice)).rejects.toMatchObject({ data: { code: 'FORBIDDEN' } });
|
||||
await expect(gameClient.messages.sendSystem.mutate({ ...notice, text: ' ' })).rejects.toMatchObject({
|
||||
data: { code: 'BAD_REQUEST' },
|
||||
});
|
||||
const sent = await gameClient.messages.sendSystem.mutate(notice);
|
||||
await expect(gameClient.messages.sendSystem.mutate(notice)).resolves.toEqual(sent);
|
||||
await expect(gameConnector.prisma.message.findUnique({ where: { id: sent.msgId } })).resolves.toMatchObject({
|
||||
type: 'public',
|
||||
mailbox: 9999,
|
||||
src: 0,
|
||||
message: { text: notice.text, src: { generalName: '시스템' } },
|
||||
});
|
||||
});
|
||||
|
||||
it('handles resource auction flow with bidding, extension, and finalization', async () => {
|
||||
if (!gameConnector || !redisConnector || !gameServer) {
|
||||
throw new Error('runtime not ready');
|
||||
@@ -1085,14 +1114,14 @@ describe('auction integration flow', () => {
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
it('starts from inheritance, accepts another user bid, and awards a default-pool unique', async () => {
|
||||
it('awards a default-pool unique and recovers a later auction whose highest bidder disappears', async () => {
|
||||
if (!gameConnector || !redisConnector || !gameServer) {
|
||||
throw new Error('runtime not ready');
|
||||
}
|
||||
const prisma = gameConnector.prisma;
|
||||
const redis = redisConnector.client;
|
||||
const [host, bidder] = userSessions;
|
||||
if (!host || !bidder) {
|
||||
const [host, bidder, laterBidder] = userSessions;
|
||||
if (!host || !bidder || !laterBidder) {
|
||||
throw new Error('not enough bidders');
|
||||
}
|
||||
|
||||
@@ -1102,11 +1131,7 @@ describe('auction integration flow', () => {
|
||||
await turnDaemonLoop;
|
||||
}
|
||||
|
||||
const uniquePair = await findUniqueItemPair();
|
||||
const slotField = resolveSlotField(uniquePair.slot);
|
||||
if (!slotField) {
|
||||
throw new Error('unsupported item slot');
|
||||
}
|
||||
const itemKey = 'che_무기_07_맥궁';
|
||||
const state = await prisma.worldState.findFirstOrThrow();
|
||||
const config =
|
||||
state.config && typeof state.config === 'object' && !Array.isArray(state.config) ? state.config : {};
|
||||
@@ -1133,7 +1158,7 @@ describe('auction integration flow', () => {
|
||||
data: { status: 'CANCELED', finishedAt: new Date() },
|
||||
});
|
||||
|
||||
for (const session of [host, bidder]) {
|
||||
for (const session of [host, bidder, laterBidder]) {
|
||||
const row = await prisma.general.findUniqueOrThrow({
|
||||
where: { id: session.generalId },
|
||||
select: { meta: true },
|
||||
@@ -1161,8 +1186,8 @@ describe('auction integration flow', () => {
|
||||
});
|
||||
}
|
||||
await prisma.general.updateMany({
|
||||
where: { [slotField]: uniquePair.keyA } as GamePrisma.GeneralWhereInput,
|
||||
data: { [slotField]: 'None' } as GamePrisma.GeneralUpdateManyMutationInput,
|
||||
where: { weaponCode: itemKey },
|
||||
data: { weaponCode: 'None' },
|
||||
});
|
||||
|
||||
const gameDatabaseUrl = resolvePostgresConfigFromEnv({ schema: 'che' }).url;
|
||||
@@ -1181,17 +1206,17 @@ describe('auction integration flow', () => {
|
||||
const inheritStatus = await hostClient.inherit.getStatus.query();
|
||||
expect(inheritStatus.availableUnique.length).toBeGreaterThan(80);
|
||||
expect(inheritStatus.availableUnique).toEqual(
|
||||
expect.arrayContaining([expect.objectContaining({ key: uniquePair.keyA })])
|
||||
expect.arrayContaining([expect.objectContaining({ key: itemKey })])
|
||||
);
|
||||
|
||||
const opened = await hostClient.inherit.openUniqueAuction.mutate({
|
||||
itemId: uniquePair.keyA,
|
||||
itemId: itemKey,
|
||||
amount: 5_000,
|
||||
});
|
||||
const auction = await prisma.auction.findUniqueOrThrow({ where: { id: opened.auctionId } });
|
||||
expect(auction).toMatchObject({
|
||||
type: 'UNIQUE_ITEM',
|
||||
targetCode: uniquePair.keyA,
|
||||
targetCode: itemKey,
|
||||
hostGeneralId: host.generalId,
|
||||
status: 'OPEN',
|
||||
});
|
||||
@@ -1230,11 +1255,99 @@ describe('auction integration flow', () => {
|
||||
where: { id: bidder.generalId },
|
||||
select: { weaponCode: true, bookCode: true, horseCode: true, itemCode: true },
|
||||
});
|
||||
expect(Object.values(winner)).toContain(uniquePair.keyA);
|
||||
expect(Object.values(winner)).toContain(itemKey);
|
||||
await expect(
|
||||
prisma.inheritancePoint.findUniqueOrThrow({
|
||||
where: { userId_key: { userId: bidder.userId, key: 'previous' } },
|
||||
})
|
||||
).resolves.toMatchObject({ value: 94_900 });
|
||||
|
||||
const stuck = await hostClient.inherit.openUniqueAuction.mutate({ itemId: itemKey, amount: 5_000 });
|
||||
const laterBidderClient = createGameClient(gameUrl, gameServer.config.trpcPath, {
|
||||
value: laterBidder.accessToken,
|
||||
});
|
||||
await laterBidderClient.auction.bidUnique.mutate({ auctionId: stuck.auctionId, amount: 5_100 });
|
||||
const pointsOf = (userId: string) =>
|
||||
prisma.inheritancePoint.findUniqueOrThrow({
|
||||
where: { userId_key: { userId, key: 'previous' } },
|
||||
});
|
||||
await expect(pointsOf(laterBidder.userId)).resolves.toMatchObject({ value: 94_900 });
|
||||
await expect(pointsOf(host.userId)).resolves.toMatchObject({ value: 100_000 });
|
||||
|
||||
await turnDaemon.lifecycle.stop('simulate-missing-auction-bidder');
|
||||
await turnDaemon.close();
|
||||
await turnDaemonLoop;
|
||||
await prisma.general.delete({ where: { id: laterBidder.generalId } });
|
||||
await prisma.auction.update({
|
||||
where: { id: stuck.auctionId },
|
||||
data: {
|
||||
closeAt: finalizeAt,
|
||||
closeTick: BigInt(finalizeTick),
|
||||
status: 'FINALIZING',
|
||||
finalizingAt: new Date(),
|
||||
},
|
||||
});
|
||||
const deadline = { closeAt: finalizeAt, closeTick: BigInt(finalizeTick) };
|
||||
const legacyFailure = {
|
||||
type: 'auctionFinalize',
|
||||
auctionId: stuck.auctionId,
|
||||
ok: false,
|
||||
reason: '입찰자를 찾을 수 없습니다.',
|
||||
};
|
||||
for (const retry of [0, 1]) {
|
||||
const requestId = buildAuctionFinalizeRequestId(stuck.auctionId, deadline, retry);
|
||||
await prisma.inputEvent.create({
|
||||
data: {
|
||||
requestId,
|
||||
target: 'ENGINE',
|
||||
eventType: 'auctionFinalize',
|
||||
status: 'SUCCEEDED',
|
||||
result: legacyFailure,
|
||||
payload: {
|
||||
requestId,
|
||||
type: 'auctionFinalize',
|
||||
auctionId: stuck.auctionId,
|
||||
expectedCloseTick: finalizeTick,
|
||||
expectedCloseAt: finalizeAt.toISOString(),
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
await expect(
|
||||
processDueAuctionId({ db: prisma, redis, ...timerKeys, id: String(stuck.auctionId), nowMs: Date.now() })
|
||||
).resolves.toBe('PENDING');
|
||||
|
||||
turnDaemon = await createTurnDaemonRuntime({
|
||||
profile: 'che',
|
||||
profileName: 'che:908',
|
||||
databaseUrl: gameDatabaseUrl,
|
||||
gatewayDatabaseUrl,
|
||||
});
|
||||
turnDaemonLoop = turnDaemon.lifecycle.start();
|
||||
const recoveredRequestId = buildAuctionFinalizeRequestId(stuck.auctionId, deadline, 2);
|
||||
await expect
|
||||
.poll(async () => prisma.inputEvent.findUnique({ where: { requestId: recoveredRequestId } }), {
|
||||
timeout: 10_000,
|
||||
})
|
||||
.toMatchObject({ status: 'SUCCEEDED', result: { ok: true } });
|
||||
await expect(prisma.auction.findUniqueOrThrow({ where: { id: stuck.auctionId } })).resolves.toMatchObject({
|
||||
status: 'CANCELED',
|
||||
});
|
||||
await expect(
|
||||
transport.requestCommand(
|
||||
{ type: 'auctionFinalize', auctionId: stuck.auctionId, expectedCloseTick: finalizeTick },
|
||||
30_000
|
||||
)
|
||||
).resolves.toMatchObject({ ok: true });
|
||||
await expect(pointsOf(laterBidder.userId)).resolves.toMatchObject({ value: 100_000 });
|
||||
await expect(pointsOf(host.userId)).resolves.toMatchObject({ value: 100_000 });
|
||||
await expect(
|
||||
prisma.inheritanceLog.count({
|
||||
where: { userId: laterBidder.userId, text: `경매 ${stuck.auctionId}번 취소로 유산 5100포인트 환불` },
|
||||
})
|
||||
).resolves.toBe(1);
|
||||
await expect(
|
||||
hostClient.inherit.openUniqueAuction.mutate({ itemId: itemKey, amount: 5_000 })
|
||||
).resolves.toMatchObject({ ok: true });
|
||||
}, 60_000);
|
||||
});
|
||||
Reference in new issue
Block a user