Skip to content

test(service): fix E0283 in list_games mock tests to unbreak Backend CI - #947

Open
abdulwaarith0 wants to merge 4 commits into
OpenKnight-Foundation:mainfrom
abdulwaarith0:fix/games-rs-e0283-mockrow
Open

test(service): fix E0283 in list_games mock tests to unbreak Backend CI#947
abdulwaarith0 wants to merge 4 commits into
OpenKnight-Foundation:mainfrom
abdulwaarith0:fix/games-rs-e0283-mockrow

Conversation

@abdulwaarith0

Copy link
Copy Markdown
Contributor

Summary

cargo test for the service module currently fails to compile, turning Backend CI red on main and on every open PR. The error:

error[E0283]: type annotations needed
  --> modules/service/src/games.rs:616 and :678
     .append_query_results(vec![ vec![] ])
      ^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T`
                                 declared on the method `append_query_results`

Root cause

In test_list_games_query_structure and test_list_games_with_cursor, the count query's mock result set is an untyped empty vec![]. Under sea-orm 1.1.20 the additional IntoMockRow impls make the element type of an empty vec ambiguous, so append_query_results::<T, _, _> can no longer infer T. (Introduced when the count query result set was added in the pagination work — the data-query set compiles fine because game::Model pins its type.)

Fix

Type the empty count set as Vec::<game::Model>::new() so T: IntoMockRow is inferable. No behavior changecount() on an empty mock result resolves to 0 and execution continues to the data query, so both queries still run and transaction_log.len() == 2 still holds.

Verification

Built in isolation against sea-orm 1.1.20 (the workspace can't build the full service crate locally due to an unrelated OpenSSL dev-dep). A minimal entity reproducing the exact flow confirms:

count on empty mock = 0
data rows           = 1
transaction_log.len() = 2

i.e. the typed empty set compiles, count() returns 0 without error, and both the count and data queries execute — matching each test's assertions.

The count result set in test_list_games_query_structure and
test_list_games_with_cursor was an untyped empty `vec![]`. Under sea-orm
1.1.20 the added IntoMockRow impls make the element type ambiguous, so
`append_query_results` fails to compile with E0283 (type annotations
needed) — breaking `cargo test` for the whole service module and turning
Backend CI red on main and every PR.

Type the empty count set as `Vec::<game::Model>::new()` so `T: IntoMockRow`
is inferable. Behavior is unchanged: count() on an empty mock result
resolves to 0 and execution continues to the data query, so both queries
still run (transaction_log.len() == 2). Verified against sea-orm 1.1.20 in
isolation.
The ws_integration_test built its target URL as
  format!("{}/v1/ws/game/{}", srv.url(""), game_id)
but srv.url("") returns a trailing slash, so the path became
'//v1/ws/game/...' with a double slash, which actix routes to 404. The
four connect-and-expect tests failed the handshake with
InvalidResponseStatus(404); the two negative tests only passed because a
404 still satisfies their is_err() assertion.

Pass the path into srv.url() (which handles the leading slash) instead of
concatenating onto srv.url(""), producing a correct single-slash URL.
Verified against actix-test in isolation: srv.url("") + concat -> 404,
srv.url("/v1/ws/game/x") -> 200. Production route is unaffected; this was
a test-only URL bug that (with the E0283 fix in this PR) unblocks Backend CI.
@abdulwaarith0

Copy link
Copy Markdown
Contributor Author

Added a second commit. The E0283 fix (first commit) makes the service module compile again — but that unmasked a separate pre-existing failure it had been hiding: 4 tests in api/tests/ws_integration_test.rs failed the WS handshake with InvalidResponseStatus(404).

Root cause (test-only, not production): the tests built their URL as format!("{}/v1/ws/game/{}", srv.url(""), game_id), but srv.url("") returns a trailing slash → the path became //v1/ws/game/... (double slash) → actix 404. Only the 4 positive tests failed; the 2 negative tests passed for the wrong reason (a 404 still satisfies their is_err() check).

Fix: pass the path into srv.url() (which handles the leading slash) instead of concatenating onto srv.url(""). Verified against actix-test in isolation: concat form → 404, srv.url("/v1/ws/game/x") → 200. Together the two commits should fully green Backend CI.

… assertion)

The final failing ws_integration_test asserted that a client-sent Move
produces no response, based on a since-outdated no-op in WsSession's Text
handler. That handler now parses the message and broadcasts it to the game
(ws.rs), and because the sender is in the game's broadcast set it receives
its own move back (version-stamped). The original author anticipated this:
'if this ever starts failing because a response does arrive ... update this
test to assert the new behavior.'

Rewrite the test to send a Move and assert the version-stamped WsMessage::Move
is broadcast back, using the same frame-reading pattern as the other tests.
Completes the Backend CI repair in this PR (ws_integration_test now 6/6).
…count query

test_list_games_query_structure and test_list_games_with_cursor inspected
transaction_log[0], but since the pagination refactor added a COUNT query
that runs first, index 0 is the count query — which carries neither the
ORDER BY / LIMIT nor the keyset cursor predicate (those are on the data
query at index 1). The assertions therefore failed once the E0283 fix in
this PR let these tests compile and run.

Point both at transaction_log[1]. Verified against sea-orm 1.1.20 in
isolation that the data query contains exactly the asserted fragments
(WHERE white_player=$1 OR black_player=$2, ORDER BY created_at DESC id DESC,
LIMIT $3; and the cursor keyset created_at<$1 OR (created_at=$2 AND id<$3)).
@abdulwaarith0

Copy link
Copy Markdown
Contributor Author

Test Backend is green ✅ — the four test-only fixes in this PR (sea-orm mock E0283, WS integration-test URLs, the stale WS no-op assertion, and the list_games SQL query-index) fully repair cargo test for the backend, which had been red on main and every PR.

The remaining red is a separate Security Scan check, and it's not caused by this PR — my diff is test-only (no Cargo.toml/lockfile changes). It's cargo audit tripping on a newly-published advisory that isn't in the workflow's ignore-list yet:

RUSTSEC-2026-0221 — event-listener (transitive)
error: 1 vulnerability found!

This fails on main too, so it's independent of the Backend CI repair here. Fixing it is a maintainer call (bump the dependency pulling the vulnerable event-listener, or add --ignore RUSTSEC-2026-0221 to the audit step) and I'm happy to open a separate PR for it if that's the preferred route. This PR is ready to merge on the Backend CI side — landing it also greens the companion PRs #944 and #946.

@abdulwaarith0

Copy link
Copy Markdown
Contributor Author

Friendly bump on this one 🙏 — it's been green on Test Backend and mergeable for several days now. Since landing it also unblocks the companion PRs #944 and #946 (they only inherit the old E0283 failure from main), it'd be great to get a review when a maintainer has a moment.

Small correction to my note above for the record: the single cargo audit error is actually rkyv 0.7.46RUSTSEC-2026-0235 (pulled in transitively via rust_decimal), not event-listener — that one's just one of the 8 allowed warnings. Still a maintainer call and unrelated to this test-only diff; happy to open a separate PR adding --ignore RUSTSEC-2026-0235 to the audit step (matching the existing ignores) if that's the preferred route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant