Skip to content

Add automated smoke test and cleanup script initialization#14

Open
DaKongOlta wants to merge 1 commit into
mainfrom
codex/add-automated-smoke-test-script
Open

Add automated smoke test and cleanup script initialization#14
DaKongOlta wants to merge 1 commit into
mainfrom
codex/add-automated-smoke-test-script

Conversation

@DaKongOlta

@DaKongOlta DaKongOlta commented Oct 30, 2025

Copy link
Copy Markdown
Owner

Summary

  • add a Puppeteer-based smoke test that loads the prototype, runs a quick race, advances the Grand Prix, and simulates a manager week while asserting UI state via window.spacerxDiagnostics
  • wire the smoke test into npm (Node 18+) and document prerequisites plus fallback manual steps
  • deduplicate script.js DOM bindings and initialization blocks so diagnostics and initialization run without redeclaration errors

Testing

  • npm run smoke

https://chatgpt.com/codex/tasks/task_e_68d0f71a83188324a2e0c8d5a7b5397c

Summary by Sourcery

Add automated end-to-end smoke testing and streamline application initialization to support reliable UI state diagnostics

New Features:

  • Introduce a Puppeteer-based smoke test (tests/full_smoke.mjs) that runs a quick race, advances a Grand Prix event, and simulates a manager week with UI assertions
  • Expose window.spacerxDiagnostics.getControlState for capturing UI and application state during tests
  • Add an npm "smoke" script and Node.js (>=18) engine requirement to package.json

Enhancements:

  • Refactor script.js to remove duplicate DOM bindings and consolidate all UI setup into an initializeAppState function
  • Add utility functions (isElementVisible, getButtonDiagnostics) to aid in diagnostics and test assertions

Documentation:

  • Document automated smoke test setup, prerequisites, and manual fallback steps in README.md and tests/MANUAL_CHECKLIST.md

Tests:

  • Update MANUAL_CHECKLIST.md with automated coverage section and manual fallback checklist

@sourcery-ai

sourcery-ai Bot commented Oct 30, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR introduces a full end-to-end smoke test powered by Puppeteer, wires it into npm with documentation updates, and significantly refactors script.js by deduplicating DOM initialization, consolidating startup into a single initializeAppState routine, and exposing a diagnostics API for test assertions.

Sequence diagram for automated smoke test flow

sequenceDiagram
  actor Tester
  participant Puppeteer
  participant SpacerXApp as "Spacer-X App"
  Tester->>Puppeteer: Run `npm run smoke`
  Puppeteer->>SpacerXApp: Launch in headless Chromium
  Puppeteer->>SpacerXApp: Disable broadcast intros
  Puppeteer->>SpacerXApp: Start quick race
  Puppeteer->>SpacerXApp: Advance Grand Prix
  Puppeteer->>SpacerXApp: Simulate manager week
  Puppeteer->>SpacerXApp: Query window.spacerxDiagnostics.getControlState()
  SpacerXApp-->>Puppeteer: Return UI state
  Puppeteer-->>Tester: Report test results
Loading

Class diagram for diagnostics API and initialization refactor

classDiagram
  class SpacerXDiagnostics {
    +getPhaseTimeline()
    +getControlState()
    +reset()
  }
  class AppState {
    +uiSettings
    +raceSettings
    +currentTrackType
    +totalLaps
    +aiLevel
    +currentWeather
    +startProcedureMode
    +activeTrackTraits
    +currentVisualTheme
    +lastTelemetryOrder
    +initializeAppState()
  }
  SpacerXDiagnostics <.. AppState: uses
  class DOMBindings {
    +mainMenu
    +raceScreen
    +teamsScreen
    +managerScreen
    +bettingScreen
    +codexScreen
    +settingsScreen
    +newRaceBtn
    +grandPrixBtn
    +resumeGrandPrixBtn
    +gpStatusCard
    +... (other elements)
  }
  AppState <.. DOMBindings: uses
Loading

File-Level Changes

Change Details Files
Add a Puppeteer-based automated smoke test and npm integration
  • Create tests/full_smoke.mjs with a static server and test flows for quick race, GP round, and manager week
  • Add “smoke” script entry and Puppeteer dependency to package.json
  • Document prerequisites and fallback steps in README.md and tests/MANUAL_CHECKLIST.md
tests/full_smoke.mjs
package.json
README.md
tests/MANUAL_CHECKLIST.md
Refactor script.js startup and DOM bindings into a unified initializer
  • Remove duplicated blocks of document.getElementById calls
  • Introduce initializeAppState() to load settings, sync controls, update UI and reset state in one place
  • Replace ad-hoc resets with a single call to initializeAppState()
script.js
Expose window.spacerxDiagnostics API for control-state assertions
  • Implement isElementVisible() and getButtonDiagnostics() helpers
  • Attach spacerxDiagnostics.getControlState() and getPhaseTimeline() to window
  • Use diagnostics API in smoke test to drive assertions
script.js
tests/full_smoke.mjs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • script.js has grown quite large with intertwined initialization and diagnostics logic—consider splitting it into smaller modules or files to improve readability and maintainability.
  • The initializeAppState routine now rebinds event listeners and timers; make sure you clear any existing handlers or intervals so that calling it repeatedly won’t leak or duplicate behavior.
  • In full_smoke.mjs the waitForControlState calls are very repetitive—extracting a higher‐level helper or configuration object for common checks could reduce duplication and make the flow clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- script.js has grown quite large with intertwined initialization and diagnostics logic—consider splitting it into smaller modules or files to improve readability and maintainability.
- The initializeAppState routine now rebinds event listeners and timers; make sure you clear any existing handlers or intervals so that calling it repeatedly won’t leak or duplicate behavior.
- In full_smoke.mjs the waitForControlState calls are very repetitive—extracting a higher‐level helper or configuration object for common checks could reduce duplication and make the flow clearer.

## Individual Comments

### Comment 1
<location> `tests/full_smoke.mjs:125-134` </location>
<code_context>
+async function runQuickRace(page) {
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding assertions for error states and UI failures during race flow.

Add assertions to verify that error overlays do not appear and that race controls maintain their expected enabled/disabled state throughout the test.
</issue_to_address>

### Comment 2
<location> `script.js:884-894` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Avoid function declarations, favouring function assignment expressions, inside blocks. ([`avoid-function-declarations-in-blocks`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/JavaScript/Default-Rules/avoid-function-declarations-in-blocks))

<details><summary>Explanation</summary>Function declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers.
Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you
should use function expressions, which create functions in-scope.
</details>
</issue_to_address>

### Comment 3
<location> `script.js:6913-6922` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Avoid function declarations, favouring function assignment expressions, inside blocks. ([`avoid-function-declarations-in-blocks`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/JavaScript/Default-Rules/avoid-function-declarations-in-blocks))

<details><summary>Explanation</summary>Function declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers.
Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you
should use function expressions, which create functions in-scope.
</details>
</issue_to_address>

### Comment 4
<location> `script.js:6924-6934` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Avoid function declarations, favouring function assignment expressions, inside blocks. ([`avoid-function-declarations-in-blocks`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/JavaScript/Default-Rules/avoid-function-declarations-in-blocks))

<details><summary>Explanation</summary>Function declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers.
Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you
should use function expressions, which create functions in-scope.
</details>
</issue_to_address>

### Comment 5
<location> `script.js:6936-6960` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Avoid function declarations, favouring function assignment expressions, inside blocks. ([`avoid-function-declarations-in-blocks`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/JavaScript/Default-Rules/avoid-function-declarations-in-blocks))

<details><summary>Explanation</summary>Function declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers.
Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you
should use function expressions, which create functions in-scope.
</details>
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/full_smoke.mjs
Comment on lines +125 to +134
async function runQuickRace(page) {
console.log('▶ Running quick race…');
await waitForControlState(page, 'main menu', () => {
const diagnostics = window.spacerxDiagnostics?.getControlState?.();
return diagnostics?.screen === 'mainMenu';
});

const initialState = await getControlState(page);
assert(initialState.buttons?.newRace?.enabled, 'Expected "Schnelles Rennen" to be enabled on load');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider adding assertions for error states and UI failures during race flow.

Add assertions to verify that error overlays do not appear and that race controls maintain their expected enabled/disabled state throughout the test.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant