Sign panel sessions and isolate test runs
Some checks failed
Deploy to Production / test (push) Failing after 29s

- Replace in-memory auth sessions with signed cookies and signed OAuth state
- Add auth route coverage and update panel/web server wiring
- Switch test script to per-file Bun processes and clean up type checks
This commit is contained in:
syntaxbullet
2026-04-09 21:44:05 +02:00
parent 6abbd4652a
commit 25a0bd3431
25 changed files with 354 additions and 157 deletions

View File

@@ -22,7 +22,7 @@ function blackjackHand(cards: Card[]): PlayerHand {
}
function makeSeat(hands: PlayerHand[], activeHandIndex = 0, hasBet = true): PlayerSeat {
return { hands, activeHandIndex, hasBet };
return { hands, activeHandIndex, hasBet, cumulativePnl: 0 };
}
/** Create a rigged state for deterministic testing. */

View File

@@ -435,7 +435,7 @@ export const blackjackPlugin: GamePlugin<BlackjackState, BlackjackAction> = {
const isMyTurn = activeId === playerId && state.phase === "player_turns";
const mySeat = state.seats[playerId];
const myActiveHand = mySeat && mySeat.activeHandIndex >= 0
? mySeat.hands[mySeat.activeHandIndex]
? mySeat.hands[mySeat.activeHandIndex] ?? null
: null;
// Determine active hand index for the view
@@ -454,7 +454,7 @@ export const blackjackPlugin: GamePlugin<BlackjackState, BlackjackAction> = {
myPlayerId: playerId,
phase: state.phase,
canAct: isMyTurn,
canSplit: isMyTurn && myActiveHand !== null && canSplitHand(myActiveHand, mySeat!.hands.length),
canSplit: isMyTurn && myActiveHand !== null && mySeat !== undefined && canSplitHand(myActiveHand, mySeat.hands.length),
canDoubleDown: isMyTurn && myActiveHand !== null && canDoubleHand(myActiveHand),
roundNumber: state.roundNumber,
myCumulativePnl: mySeat?.cumulativePnl ?? 0,

View File

@@ -43,10 +43,12 @@ export const chessPlugin: GamePlugin<ChessState, ChessAction> = {
createInitialState(players: string[], options?: Record<string, unknown>): ChessState {
const game = new Chess();
const timeControlKey = (options?.timeControl as string) ?? "blitz_5_3";
const tc = TIME_CONTROLS[timeControlKey] ?? TIME_CONTROLS.blitz_5_3;
const tc = TIME_CONTROLS[timeControlKey] ?? TIME_CONTROLS["blitz_5_3"]!;
// Randomly assign colors
const shuffled = Math.random() < 0.5 ? [players[0], players[1]] : [players[1], players[0]];
const shuffled: [string, string] = Math.random() < 0.5
? [players[0]!, players[1]!]
: [players[1]!, players[0]!];
const clock: ChessClock | null = tc.time > 0
? { white: tc.time, black: tc.time, increment: tc.increment, lastMoveAt: Date.now() }
@@ -108,7 +110,7 @@ export const chessPlugin: GamePlugin<ChessState, ChessAction> = {
const moveEntry = {
from: action.from,
to: action.to,
san: game.history().slice(-1)[0],
san: game.history().slice(-1)[0]!,
color: turn === "white" ? "w" as const : "b" as const,
};

View File

@@ -16,7 +16,7 @@ const LogLevelNames = {
[LogLevel.ERROR]: "ERROR",
};
export type LogSource = "bot" | "web" | "shared" | "system";
export type LogSource = "auth" | "bot" | "web" | "shared" | "system";
export interface LogEntry {
timestamp: string;

View File

@@ -127,10 +127,10 @@ describe("questService", () => {
{ userId: 1n, questId: 1, completedAt: null },
{ userId: 1n, questId: 2, completedAt: new Date() },
]);
mockReturning.mockResolvedValue([{ userId: 1n, questId: 3 }]);
mockReturning.mockResolvedValue([{ userId: 1n, questId: 3 }] as any);
const result = await questService.assignQuest("1", 3);
expect(result).toEqual([{ userId: 1n, questId: 3 }]);
expect(result).toEqual([{ userId: 1n, questId: 3 }] as any);
mockGetSettings.mockRestore();
});

View File

@@ -69,9 +69,11 @@ mock.module("@shared/lib/config", () => ({
// Mock Events (trivia service emits domain events instead of calling dashboardService directly)
const mockEmit = mock(() => true);
const mockEmitAsync = mock(async () => true);
mock.module("@shared/lib/events", () => ({
systemEvents: {
emit: mockEmit,
emitAsync: mockEmitAsync,
},
EVENTS: {
DOMAIN: {
@@ -115,6 +117,7 @@ describe("TriviaService", () => {
mockWhere.mockClear();
mockOnConflictDoUpdate.mockClear();
mockEmit.mockClear();
mockEmitAsync.mockClear();
// Clear active sessions
(triviaService as any).activeSessions.clear();
});
@@ -224,7 +227,7 @@ describe("TriviaService", () => {
// Verify balance update
expect(mockUpdate).toHaveBeenCalledWith(users);
expect(mockInsert).toHaveBeenCalledWith(transactions);
expect(mockEmit).toHaveBeenCalled();
expect(mockEmitAsync).toHaveBeenCalled();
});
it("should not award prize for incorrect answer", async () => {

View File

@@ -92,7 +92,7 @@ if [ -n "$1" ]; then
EXIT_CODE=1
fi
else
if bash shared/scripts/test-sequential.sh --integration; then
if bash shared/scripts/test-isolated.sh --integration; then
echo "✅ CI Simulation Passed!"
EXIT_CODE=0
else

42
shared/scripts/test-isolated.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/bash
set -euo pipefail
INCLUDE_INTEGRATION=false
if [[ "${1:-}" == "--integration" ]]; then
INCLUDE_INTEGRATION=true
fi
JOBS="${AURORA_TEST_JOBS:-4}"
echo "🔍 Finding test files..."
if [ "$INCLUDE_INTEGRATION" = true ]; then
FIND_ARGS=( -name "*.test.ts" )
else
FIND_ARGS=( -name "*.test.ts" -not -name "*.integration.test.ts" )
fi
TEST_FILES=()
while IFS= read -r file; do
TEST_FILES+=("$file")
done < <(find . "${FIND_ARGS[@]}" -not -path "*/node_modules/*" | sort)
if [ "${#TEST_FILES[@]}" -eq 0 ]; then
echo "⚠️ No test files found!"
exit 0
fi
echo "🧪 Running ${#TEST_FILES[@]} test files with isolated Bun processes..."
echo " Workers: $JOBS"
if [ "$INCLUDE_INTEGRATION" = true ]; then
echo " (including integration tests)"
fi
if printf '%s\n' "${TEST_FILES[@]}" | xargs -n1 -P "$JOBS" bash -lc 'echo "---------------------------------------------------"; echo "running: $1"; bun test "$1"' _; then
echo "---------------------------------------------------"
echo "✅ All tests passed!"
exit 0
fi
echo "---------------------------------------------------"
echo "❌ Some tests failed."
exit 1

View File

@@ -1,49 +0,0 @@
#!/bin/bash
set -e
INCLUDE_INTEGRATION=false
if [[ "$1" == "--integration" ]]; then
INCLUDE_INTEGRATION=true
fi
echo "🔍 Finding test files..."
if [ "$INCLUDE_INTEGRATION" = true ]; then
TEST_FILES=$(find . -name "*.test.ts" -not -path "*/node_modules/*")
else
TEST_FILES=$(find . -name "*.test.ts" -not -name "*.integration.test.ts" -not -path "*/node_modules/*")
fi
if [ -z "$TEST_FILES" ]; then
echo "⚠️ No test files found!"
exit 0
fi
echo "🧪 Running tests sequentially..."
if [ "$INCLUDE_INTEGRATION" = true ]; then
echo " (including integration tests)"
fi
FAILED=0
for FILE in $TEST_FILES; do
echo "---------------------------------------------------"
echo "running: $FILE"
if bun test "$FILE"; then
echo "✅ passed: $FILE"
else
echo "❌ failed: $FILE"
FAILED=1
# Fail fast
exit 1
fi
done
if [ $FAILED -eq 0 ]; then
echo "---------------------------------------------------"
echo "✅ All tests passed!"
exit 0
else
echo "---------------------------------------------------"
echo "❌ Some tests failed."
exit 1
fi