feat(world-builder): register uploaded graphics and extend palette schemas (#6) - #111
Conversation
…rena reset functions (Bitcoindefi#26)
| export async function validatePaletteEntry( | ||
| entry: PaletteEntry, | ||
| ): Promise<{ valid: boolean; reason?: string }> { | ||
| for (const grhIndex of entry.graphics) { | ||
| if (grhIndex >= UPLOADED_GRAPHIC_INDEX_START) { | ||
| const exists = await pool.query( | ||
| `SELECT 1 FROM game_uploaded_graphics WHERE grh_index = $1 LIMIT 1`, | ||
| [grhIndex], | ||
| ); | ||
| if (exists.rowCount === 0) { | ||
| return { | ||
| valid: false, | ||
| reason: `El grafico ${grhIndex} no existe en el motor ni en assets subidos.`, | ||
| }; | ||
| } |
There was a problem hiding this comment.
⚠️ Quality: validatePaletteEntry is never called and untested
The PR's stated goal is to validate multi-layer palette definitions, but validatePaletteEntry is not imported or invoked by any route or caller in the codebase (only its definition exists), and the new test file only exercises paletteEntrySchema, never validatePaletteEntry. As a result no palette entry is actually validated against existing/uploaded graphics at runtime and the collision/existence logic has zero test coverage. Wire the function into the palette-writing route(s) and add a unit test covering the uploaded-index existence branch (mocking pool.query).
Was this helpful? React with 👍 / 👎
| for (const grhIndex of entry.graphics) { | ||
| if (grhIndex >= UPLOADED_GRAPHIC_INDEX_START) { | ||
| const exists = await pool.query( | ||
| `SELECT 1 FROM game_uploaded_graphics WHERE grh_index = $1 LIMIT 1`, | ||
| [grhIndex], | ||
| ); | ||
| if (exists.rowCount === 0) { | ||
| return { | ||
| valid: false, | ||
| reason: `El grafico ${grhIndex} no existe en el motor ni en assets subidos.`, | ||
| }; | ||
| } | ||
| } else if (grhIndex <= 0) { | ||
| return { | ||
| valid: false, |
There was a problem hiding this comment.
💡 Bug: Engine graphic indices are accepted without existence check
The function's docstring claims it verifies graphics exist "originales o subidos", but for any positive index below UPLOADED_GRAPHIC_INDEX_START (1,000,000) it performs no validation at all — including indices between the real engine max (320151) and 1,000,000, which are non-existent yet accepted as valid. This lets invalid engine indices pass validation. Either validate engine indices against the known upper bound (e.g. reject grhIndex > MAX_ENGINE_GRAPHIC_INDEX) or correct the docstring to reflect that only uploaded indices are checked.
Reject engine indices outside the valid original range instead of accepting them blindly.:
} else if (grhIndex <= 0 || grhIndex > 320151) {
return {
valid: false,
reason: `Indice de grafico invalido: ${grhIndex}.`,
};
}
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
Code Review
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar
Summary
Resolves #6 by implementing
paletteEntrySchemaandvalidatePaletteEntryto validate multi-layer palette definitions, enforce non-colliding graphic index allocations (UPLOADED_GRAPHIC_INDEX_START = 1_000_000), and verify graphic existence across engine and uploaded assets.Changes
paletteEntrySchemaandvalidatePaletteEntryinapi/src/repositories/worldBuilder.ts.api/src/repositories/__tests__/paletteValidation.test.ts.Closes #6
Summary by Gitar
canAccountEditMapinapi/src/server.ts.gracefulShutdownlogic with client closure and connection reset hooks inserver/src/gracefulShutdown.tsandserver/src/server.ts.This will update automatically on new commits.