diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f6d083c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,22 @@ +# Monthly updates, grouped into one pull request per ecosystem. +# Actions are pinned to commit SHAs: Dependabot bumps the SHA and the version comment together. +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: monthly + groups: + actions: + patterns: ["*"] + commit-message: + prefix: ci + - package-ecosystem: npm + directory: / + schedule: + interval: monthly + groups: + npm: + patterns: ["*"] + commit-message: + prefix: deps diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a35cd36 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +jobs: + smoke: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: + node-version: 22 + cache: npm + - run: npm ci + - run: npx playwright install --with-deps chromium + - run: npm test diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..53fb424 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,34 @@ +# Advanced CodeQL setup: the game's code is inline in index.html, so GitHub's default setup sees no +# JavaScript and only scans the workflows. The JavaScript extractor reads scripts inside HTML files. +name: CodeQL + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: "17 4 * * 1" + +permissions: + contents: read + +jobs: + analyze: + runs-on: ubuntu-latest + permissions: + security-events: write + actions: read + strategy: + fail-fast: false + matrix: + language: [actions, javascript-typescript] + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + - uses: github/codeql-action/init@4bfa242aa49c5f7c6770b98670d354a7dfac05f8 # v3.39.1 + with: + languages: ${{ matrix.language }} + build-mode: none + - uses: github/codeql-action/analyze@4bfa242aa49c5f7c6770b98670d354a7dfac05f8 # v3.39.1 + with: + category: /language:${{ matrix.language }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7baf96c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,20 @@ +# Changelog + +All notable changes to The Locked World. The game is served from `main` at https://solidgeeks.github.io/lockedworld/: every change merged there is live, so entries are dated rather than versioned. + +## 2026-10-25 — Solid standard + +### Added +- Smoke test (`npm test`): the game loads, and each of the 10 levels starts and runs without a JavaScript error. CI runs it on every push and pull request. +- CodeQL now scans the game's code (inline in `index.html`), not only the workflows. +- README in English, with the level names as they appear in the game; AGPL-3.0 license, `SECURITY.md`, first-merge card for new contributors. + +### Fixed +- Brand colour: Volt is `#C8FF2E`, as in the logo kit (was `#c8f520`). +- The GitHub link points at github.com/SolidGeeks. + +## 2026-10-25 — first release + +### Added +- Ten levels, each with its own mechanic and a teammate to win: fog and rescue, wave arena, escort, stealth, defence and boss, newcomers to protect, license ammo, packet routing, vertical scrolling, chase. +- Keyboard and mouse controls, two-thumb touch controls, sound synthesized with Web Audio, progress saved in the browser. diff --git a/README.md b/README.md index 0099101..0774df5 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,16 @@ One `index.html` file, no build step, no dependencies: Canvas 2D, sound synthesi To try it locally: open `index.html` in a browser, or run `python3 -m http.server` in this folder and go to http://localhost:8000. +To run the tests (Node.js 22 or later; the game itself needs nothing, Playwright is only for the tests): + +```bash +npm install +npx playwright install chromium # once +npm test # the game loads, and each of the 10 levels starts and runs without an error +``` + +Changes are listed in [CHANGELOG.md](CHANGELOG.md). + ## Contributing Contributions follow the [Solid standard](https://github.com/SolidGeeks/.github/blob/main/CONTRIBUTING.md): sign off every commit with `git commit -s` (DCO), no CLA. The code is licensed [AGPL-3.0-or-later](LICENSE). To report a vulnerability, see [SECURITY.md](SECURITY.md). diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..abbb340 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,45 @@ +{ + "name": "lockedworld", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "lockedworld", + "version": "1.0.0", + "license": "AGPL-3.0-or-later", + "devDependencies": { + "playwright": "^1.49.0" + } + }, + "node_modules/playwright": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.64.1.tgz", + "integrity": "sha512-HCrVhHr5QQuwYoswEUGTb7gGp522yflbv/ST8nF4sFWGuLjQCt17Q/EubpGGSNKYn1tsTCPZxqHhHCfVURu7UA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.64.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/playwright-core": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.1.tgz", + "integrity": "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..97cdeb1 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "lockedworld", + "version": "1.0.0", + "private": true, + "description": "The Locked World: a ten-level top-down shooter that runs in the browser.", + "license": "AGPL-3.0-or-later", + "repository": "github:SolidGeeks/lockedworld", + "type": "module", + "scripts": { + "test": "node --test tests/smoke.test.mjs" + }, + "devDependencies": { + "playwright": "^1.49.0" + } +} diff --git a/tests/smoke.test.mjs b/tests/smoke.test.mjs new file mode 100644 index 0000000..69598d0 --- /dev/null +++ b/tests/smoke.test.mjs @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +// Smoke test: the game loads, and each of the 10 levels starts and runs for a few seconds without a JavaScript error. +// Run with: npm test (needs a browser once: npx playwright install chromium) +import { test, before, after } from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import { join, dirname } from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; +import { chromium } from 'playwright'; + +const root = join(dirname(fileURLToPath(import.meta.url)), '..'); +const page_url = pathToFileURL(join(root, 'index.html')).href; +// The game runs inside an IIFE. Serve it with one extra line that exposes its state to the test; index.html is not changed. +const html = readFileSync(join(root, 'index.html'), 'utf8'); +const end = html.lastIndexOf('})();'); +assert.ok(end > 0, 'the game script ends with })();'); +const served = html.slice(0, end) + 'window.__LW = { game, LEVELS, startLevel };\n' + html.slice(end); + +let browser, page; +const errors = []; + +before(async () => { + browser = await chromium.launch(); + page = await browser.newPage({ viewport: { width: 1280, height: 800 } }); + page.on('pageerror', e => errors.push(e.message)); + await page.route(page_url, r => r.fulfill({ body: served, contentType: 'text/html; charset=utf-8' })); + await page.goto(page_url); + await page.waitForFunction(() => window.__LW); +}); +after(async () => { await browser?.close(); }); + +test('the game loads on its title screen, without errors', async () => { + assert.equal(await page.evaluate(() => window.__LW.game.state), 'title'); + assert.equal(await page.evaluate(() => window.__LW.LEVELS.length), 10); + assert.match(await page.title(), /The Locked World/); + assert.deepEqual(errors, []); +}); + +for (let i = 0; i < 10; i++) { + test(`level ${i + 1} starts and runs`, async () => { + errors.length = 0; + const name = await page.evaluate(n => { window.__LW.startLevel(n); return window.__LW.LEVELS[n].name; }, i); + // Play a little: move and hold fire, so the level's update and drawing code actually run + await page.mouse.move(900, 300); + await page.mouse.down(); + await page.keyboard.down('d'); + await page.waitForTimeout(2500); + await page.keyboard.up('d'); + await page.mouse.up(); + const s = await page.evaluate(() => ({ state: window.__LW.game.state, idx: window.__LW.game.idx, lt: window.__LW.game.lt })); + assert.deepEqual(errors, [], `${name}: JavaScript error`); + assert.equal(s.idx, i, `${name}: wrong level`); + assert.ok(['intro', 'play', 'clear', 'dead'].includes(s.state), `${name}: unexpected state ${s.state}`); + assert.ok(s.lt > 0, `${name}: the level clock does not advance`); + }); +}