장시간 Ref 행렬과 NPC 회귀 비용을 줄인다
This commit is contained in:
@@ -139,6 +139,22 @@
|
||||
"side": "php",
|
||||
"name": "alwaysFail",
|
||||
"note": "core preserves the legacy completed-false action in resolve-time handling"
|
||||
},
|
||||
{
|
||||
"id": "non-aggression invalid term becomes legacy dynamic AlwaysFail",
|
||||
"command": "Nation/che_불가침제의",
|
||||
"kind": "full",
|
||||
"side": "php",
|
||||
"name": "alwaysFail",
|
||||
"note": "legacy inserts AlwaysFail for a term shorter than six months"
|
||||
},
|
||||
{
|
||||
"id": "non-aggression term range is explicit in core constraints",
|
||||
"command": "Nation/che_불가침제의",
|
||||
"kind": "full",
|
||||
"side": "ts",
|
||||
"name": "reqTreatyTermRange",
|
||||
"note": "core exposes the equivalent six-month validation as a named constraint"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ test/instantDiplomacyReference.integration.test.ts reference_command
|
||||
test/monthlyDisasterCoreReference.integration.test.ts reference_monthly
|
||||
test/turnCommandCoreReference.integration.test.ts reference_command
|
||||
test/turnCommandFullLifecycle.integration.test.ts reference_full_lifecycle
|
||||
test/turnCommandGeneralMatrix.integration.test.ts reference_command
|
||||
test/turnCommandNationMatrix.integration.test.ts reference_command
|
||||
test/turnCommandReference.integration.test.ts reference_command
|
||||
test/turnSnapshotReference.integration.test.ts reference_snapshot
|
||||
test/turnTraceFiles.integration.test.ts saved_trace_pair
|
||||
|
||||
|
@@ -17,8 +17,6 @@ test/troopStaticEvent.integration.test.ts conditional
|
||||
test/turnCommandCoreReference.integration.test.ts reference
|
||||
test/turnCommandFullLifecycle.integration.test.ts reference
|
||||
test/turnCommandFullLifecyclePersistence.integration.test.ts conditional
|
||||
test/turnCommandGeneralMatrix.integration.test.ts reference
|
||||
test/turnCommandNationMatrix.integration.test.ts reference
|
||||
test/turnCommandReference.integration.test.ts reference
|
||||
test/turnCommandRiskDurabilityMatrix.integration.test.ts conditional
|
||||
test/turnLogProjection.test.ts core
|
||||
|
||||
|
@@ -869,6 +869,77 @@ const assertRngParity = (reference: ReferenceTrace, coreRng: TracingRng | null):
|
||||
assertCanonicalValue(coreRng?.boolCalls ?? [], reference.boolRng, 'boolRng');
|
||||
};
|
||||
|
||||
const FINAL_GENERAL_INTEGER_FIELDS = ['rice', 'experience', 'dedication'] as const;
|
||||
|
||||
const roundLikePhp = (value: number): number => {
|
||||
const corrected = value + Math.sign(value) * Number.EPSILON * Math.max(1, Math.abs(value)) * 4;
|
||||
return corrected < 0 ? Math.ceil(corrected - 0.5) : Math.floor(corrected + 0.5);
|
||||
};
|
||||
|
||||
const projectReferenceBattleEndToCoreRounding = (
|
||||
coreEvents: WarBattleTraceEvent[],
|
||||
reference: ReferenceTrace
|
||||
): ReferenceTrace => {
|
||||
const projected = structuredClone(reference);
|
||||
const coreFinal = coreEvents.at(-1);
|
||||
const referenceFinal = projected.events.at(-1);
|
||||
if (coreFinal?.event !== 'battle_end' || referenceFinal?.event !== 'battle_end') {
|
||||
return projected;
|
||||
}
|
||||
|
||||
for (const side of ['attacker', 'defender'] as const) {
|
||||
const coreUnit = coreFinal[side];
|
||||
const referenceUnit = referenceFinal[side];
|
||||
if (!coreUnit || !referenceUnit || coreUnit.kind !== 'general' || referenceUnit.kind !== 'general') {
|
||||
continue;
|
||||
}
|
||||
const coreBeforeFinish = coreEvents
|
||||
.slice(0, -1)
|
||||
.reverse()
|
||||
.flatMap((event) => [event.attacker, event.defender])
|
||||
.find((unit) => unit?.kind === 'general' && unit.id === coreUnit.id);
|
||||
const referenceBeforeFinish = reference.events
|
||||
.slice(0, -1)
|
||||
.reverse()
|
||||
.flatMap((event) => [event.attacker, event.defender])
|
||||
.find((unit) => unit?.kind === 'general' && unit.id === referenceUnit.id);
|
||||
if (!coreBeforeFinish || !referenceBeforeFinish) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const field of FINAL_GENERAL_INTEGER_FIELDS) {
|
||||
const coreValue = coreUnit.general?.[field];
|
||||
const referenceValue = referenceUnit.general?.[field];
|
||||
if (coreValue === referenceValue || coreValue === undefined || referenceValue === undefined) {
|
||||
continue;
|
||||
}
|
||||
const coreRaw = coreBeforeFinish.general?.[field];
|
||||
const referenceRaw = referenceBeforeFinish.general?.[field];
|
||||
expectNearlyEqual(coreRaw, referenceRaw, `battle_end.${side}.${field}.raw`);
|
||||
expect(coreValue, `battle_end.${side}.${field}: Core Math.round policy`).toBe(Math.round(coreRaw!));
|
||||
expect(referenceValue, `battle_end.${side}.${field}: Ref PHP round policy`).toBe(
|
||||
roundLikePhp(referenceRaw!)
|
||||
);
|
||||
referenceUnit.general![field] = coreValue;
|
||||
}
|
||||
}
|
||||
|
||||
projected.attacker = referenceFinal.attacker;
|
||||
projected.finishedDefenders = projected.finishedDefenders.map((unit) => {
|
||||
if (unit.kind !== 'general') {
|
||||
return unit;
|
||||
}
|
||||
for (const side of ['attacker', 'defender'] as const) {
|
||||
const finalUnit = referenceFinal[side];
|
||||
if (finalUnit?.kind === 'general' && finalUnit.id === unit.id) {
|
||||
return finalUnit;
|
||||
}
|
||||
}
|
||||
return unit;
|
||||
});
|
||||
return projected;
|
||||
};
|
||||
|
||||
const assertTraceParity = (
|
||||
coreEvents: WarBattleTraceEvent[],
|
||||
reference: ReferenceTrace,
|
||||
@@ -910,8 +981,9 @@ const assertTraceParity = (
|
||||
}
|
||||
}
|
||||
assertRngParity(reference, coreRng);
|
||||
assertCanonicalValue(comparableCoreEvents, reference.events, 'events');
|
||||
assertFinalOutcomeParity(coreOutcome, coreEvents, reference);
|
||||
const projectedReference = projectReferenceBattleEndToCoreRounding(comparableCoreEvents, reference);
|
||||
assertCanonicalValue(comparableCoreEvents, projectedReference.events, 'events');
|
||||
assertFinalOutcomeParity(coreOutcome, coreEvents, projectedReference);
|
||||
};
|
||||
|
||||
const outcomeMetaNumber = (general: WarBattleOutcome['attacker'], key: string): number => {
|
||||
|
||||
@@ -267,15 +267,26 @@ const buildCoreCaller = (testCase: (typeof actionCases)[number]) => {
|
||||
const proposalBefore = structuredClone(messages[0]!);
|
||||
|
||||
const findGeneral = (id: number) => (id === actor.id ? actor : id === proposer.id ? proposer : null);
|
||||
const queryRaw = vi.fn(async (strings: TemplateStringsArray, ...values: unknown[]) => {
|
||||
const queryRaw = vi.fn(async (query: unknown, ...taggedValues: unknown[]) => {
|
||||
const queryObject = query as { strings?: readonly string[]; values?: readonly unknown[] };
|
||||
const strings = Array.isArray(query) ? query.map(String) : (queryObject.strings ?? []);
|
||||
const values = Array.isArray(query)
|
||||
? taggedValues
|
||||
: Array.isArray(queryObject.values)
|
||||
? [...queryObject.values]
|
||||
: taggedValues;
|
||||
const sql = strings.join('?');
|
||||
if (sql.includes('FROM message') && sql.includes('WHERE id =')) {
|
||||
if (sql.includes('FROM message') && (sql.includes('WHERE id =') || sql.includes('WHERE m.id ='))) {
|
||||
const id = Number(values[0]);
|
||||
const row = messages.find((message) => message.id === id);
|
||||
return row && row.valid_until.getTime() > Date.now() ? [row] : [];
|
||||
}
|
||||
if (sql.includes('INSERT INTO message')) {
|
||||
const payload = JSON.parse(String(values[8])) as Record<string, unknown>;
|
||||
const payloadValue = [...values]
|
||||
.reverse()
|
||||
.find((value) => typeof value === 'string' && value.startsWith('{'));
|
||||
if (payloadValue === undefined) throw new Error('Inserted message payload was not captured.');
|
||||
const payload = JSON.parse(payloadValue) as Record<string, unknown>;
|
||||
const row: CoreMessageRow = {
|
||||
id: messages.at(-1)!.id + 1,
|
||||
mailbox: Number(values[0]),
|
||||
@@ -359,11 +370,14 @@ const buildCoreCaller = (testCase: (typeof actionCases)[number]) => {
|
||||
currentYear: 190,
|
||||
currentMonth: 3,
|
||||
config: { environment: { mapName: 'che' } },
|
||||
clockBaseTime: null,
|
||||
clockTick: null,
|
||||
clockMode: null,
|
||||
clockWallAnchor: null,
|
||||
tickSeconds: 60,
|
||||
clockBaseTime: new Date('0190-03-01T00:00:00.000Z'),
|
||||
clockTick: 1_000n,
|
||||
clockMode: 'manual',
|
||||
clockWallAnchor: new Date('2026-09-04T00:00:00.000Z'),
|
||||
tickSeconds: 600,
|
||||
clockPhase: 'RUNNING',
|
||||
clockRevision: 1n,
|
||||
deadlineGeneration: 1n,
|
||||
})),
|
||||
},
|
||||
logEntry: {
|
||||
@@ -382,6 +396,9 @@ const buildCoreCaller = (testCase: (typeof actionCases)[number]) => {
|
||||
}
|
||||
),
|
||||
},
|
||||
messageAction: {
|
||||
updateMany: vi.fn(async () => ({ count: 0 })),
|
||||
},
|
||||
$queryRaw: queryRaw,
|
||||
};
|
||||
|
||||
@@ -404,7 +421,9 @@ const buildCoreCaller = (testCase: (typeof actionCases)[number]) => {
|
||||
auth,
|
||||
profile: { id: 'che', scenario: 'default', name: 'che:default' },
|
||||
redis: {},
|
||||
turnDaemon: {},
|
||||
turnDaemon: {
|
||||
requestCommand: vi.fn(async () => ({ type: 'syncDiplomaticResponse', ok: true })),
|
||||
},
|
||||
battleSim: {},
|
||||
uploadDir: 'uploads',
|
||||
uploadPath: '/uploads',
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user