forked from dcatanzaro/aoweb
-
Notifications
You must be signed in to change notification settings - Fork 34
feat(world-builder): register uploaded graphics and extend palette schemas (#6) #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Rodrigoue9
wants to merge
12
commits into
Bitcoindefi:main
Choose a base branch
from
Rodrigoue9:feat/registered-graphics-palette-extension
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ec22f9c
fix(server): implement graceful shutdown on SIGINT and SIGTERM (#26)
Rodrigoue9 cf09ac9
test(shutdown): exercise real resetAllCharactersConnectedStatus and a…
Rodrigoue9 e78070f
test(shutdown): isolate reset helpers from PostgreSQL
Rodrigoue9 f4f523a
test(shutdown): exercise graceful shutdown path
Rodrigoue9 ac00742
feat(world-builder): permissions and protected map restrictions for m…
Rodrigoue9 77fc6fc
feat(world-builder): register uploaded graphics and extend palette sc…
Rodrigoue9 3a4137b
fix(world-builder): enforce palette graphic validation
Rodrigoue9 beda37d
test(world-builder): include palette validation in Vitest
Rodrigoue9 43078b1
chore(merge): sync with main and resolve worldBuilder & gracefulShutd…
Rodrigoue9 9c259bd
chore(merge): sync PR 111 with origin/main
Rodrigoue9 3ecc497
chore(world-builder): scope palette bounty to issue 6
Rodrigoue9 09c069b
fix(server): exclude keepalive ping from AFK idle liveness reference
Rodrigoue9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| import { | ||
| MAX_ENGINE_GRAPHIC_INDEX, | ||
| paletteEntrySchema, | ||
| UPLOADED_GRAPHIC_INDEX_START, | ||
| validatePaletteEntry, | ||
| } from "../repositories/worldBuilder"; | ||
| import pool from "../db"; | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| describe("Palette Entry Schema and Validation (#6)", () => { | ||
| it("should accept valid multi-layer palette entries with blocking flag", () => { | ||
| const valid = paletteEntrySchema.safeParse({ | ||
| graphics: [5500, 581], | ||
| blocked: true, | ||
| }); | ||
| expect(valid.success).toBe(true); | ||
| if (valid.success) { | ||
| expect(valid.data.graphics).toEqual([5500, 581]); | ||
| expect(valid.data.blocked).toBe(true); | ||
| } | ||
| }); | ||
|
|
||
| it("should reject palette entries with empty graphics array", () => { | ||
| const invalid = paletteEntrySchema.safeParse({ | ||
| graphics: [], | ||
| blocked: false, | ||
| }); | ||
| expect(invalid.success).toBe(false); | ||
| }); | ||
|
|
||
| it("should reject palette entries exceeding maximum layers (4)", () => { | ||
| const invalid = paletteEntrySchema.safeParse({ | ||
| graphics: [1, 2, 3, 4, 5], | ||
| }); | ||
| expect(invalid.success).toBe(false); | ||
| }); | ||
|
|
||
| it("should enforce non-colliding reserved range for uploaded graphics", () => { | ||
| expect(UPLOADED_GRAPHIC_INDEX_START).toBe(1_000_000); | ||
| // Original game graphics reach up to 320151, well below 1_000_000 | ||
| expect(UPLOADED_GRAPHIC_INDEX_START).toBeGreaterThan( | ||
| MAX_ENGINE_GRAPHIC_INDEX, | ||
| ); | ||
| }); | ||
|
|
||
| it("should accept an original engine graphic without a database lookup", async () => { | ||
| const query = vi.spyOn(pool, "query"); | ||
| const result = await validatePaletteEntry({ | ||
| graphics: [MAX_ENGINE_GRAPHIC_INDEX], | ||
| }); | ||
|
|
||
| expect(result).toEqual({ valid: true }); | ||
| expect(query).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("should reject graphic indices outside the original engine range", async () => { | ||
| const query = vi.spyOn(pool, "query"); | ||
| const result = await validatePaletteEntry({ | ||
| graphics: [MAX_ENGINE_GRAPHIC_INDEX + 1], | ||
| }); | ||
|
|
||
| expect(result.valid).toBe(false); | ||
| expect(result.reason).toContain("Indice de grafico invalido"); | ||
| expect(query).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("should validate uploaded graphics against the database", async () => { | ||
| const query = vi | ||
| .spyOn(pool, "query") | ||
| .mockResolvedValue({ rowCount: 1 } as never); | ||
|
|
||
| const result = await validatePaletteEntry({ | ||
| graphics: [UPLOADED_GRAPHIC_INDEX_START], | ||
| }); | ||
|
|
||
| expect(result).toEqual({ valid: true }); | ||
| expect(query).toHaveBeenCalledWith( | ||
| expect.stringContaining("game_uploaded_graphics"), | ||
| [UPLOADED_GRAPHIC_INDEX_START], | ||
| ); | ||
| }); | ||
|
|
||
| it("should reject an uploaded graphic that is not registered", async () => { | ||
| vi.spyOn(pool, "query").mockResolvedValue({ rowCount: 0 } as never); | ||
|
|
||
| const result = await validatePaletteEntry({ | ||
| graphics: [UPLOADED_GRAPHIC_INDEX_START + 1], | ||
| }); | ||
|
|
||
| expect(result.valid).toBe(false); | ||
| expect(result.reason).toContain("no existe"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.