diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..bd43241 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,13 @@ +## Why + +## What changed + +## How to verify + +--- + +## 背景 + +## 改动 + +## 怎么验证 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a5377e6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +name: CI +on: [pull_request] +permissions: + contents: read +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +jobs: + check: + runs-on: ubuntu-latest + timeout-minutes: 25 + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + - run: npm install -g pnpm@10.20.0 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: + node-version-file: .nvmrc + cache: pnpm + - run: pnpm install --frozen-lockfile + - run: pnpm lint + - run: pnpm typecheck + - run: pnpm test + - run: pnpm build + - run: pnpm exec playwright install --with-deps chromium + - name: Browser test with fake gates + run: | + PORT=28080 DEVICE_PORT=7600 node bridge/dist/server.js & + bridge_pid=$! + node scripts/fake-gates.mjs & + gates_pid=$! + trap 'kill $bridge_pid $gates_pid || true' EXIT + pnpm exec playwright test e2e/entrance.spec.ts + - run: docker build -t gatepost-sim:ci . + - uses: anchore/sbom-action@f8bdd1d8ac5e901a77a92f111440fdb1b593736b # v0.20.6 + with: + image: gatepost-sim:ci + artifact-name: gatepost-sim.spdx.json + - uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 + with: + image-ref: gatepost-sim:ci + format: table + exit-code: '1' + severity: CRITICAL,HIGH diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..05435bd --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,18 @@ +* @mateo-rossi @fatima-zahra +/bridge/ @mateo-rossi @fatima-zahra +/web/ @mateo-rossi @fatima-zahra +/scripts/ @mateo-rossi @fatima-zahra +/data/ @mateo-rossi @fatima-zahra +/compose.*.yaml @mateo-rossi @fatima-zahra +/compose.lab.yaml @yuki-tanaka @noah-williams +/bridge/test/ @noah-williams +/web/test/ @noah-williams +/e2e/ @noah-williams +/playwright.config.ts @noah-williams +/scripts/e2e-gatepost.sh @noah-williams +/scripts/real-controls.mjs @noah-williams +/scripts/screenshots.sh @noah-williams +/docs/screenshots/ @noah-williams +/.github/ @ingrid-larsen +/renovate.json @ingrid-larsen +/CODEOWNERS @ingrid-larsen diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..f557092 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,54 @@ +English | [简体中文](CONTRIBUTING.zh-CN.md) + +# Contributing + +Keep each pull request focused on one change. Include its tests and documentation, and update English and Chinese guides together. + +## Branches and commits + +Name branches `/`, using a short, hyphenated topic, for example `fix/gate-controls`. + +Use commit subjects of the form `type(scope): summary`. Use `feat`, `fix`, `test`, `docs`, `style`, `chore`, `ci`, `perf`, `refactor` or `revert` for the type. Name the affected area in the scope, such as `bridge`, `web`, `sim` or `repo`. Write the summary in the imperative, for example `fix(bridge): report failed power actions`. + +## Before opening a pull request + +Use the Node version in `.nvmrc` and pnpm 10.20.0, as specified by `package.json`. Run these commands from the repository root: + +```sh +pnpm install --frozen-lockfile +pnpm lint +pnpm typecheck +pnpm test +pnpm build +pnpm exec playwright install --with-deps chromium +``` + +Run the browser checks with a bridge and four fake gates. Keep ports 28080 and 7600 free, and stop any existing simulator first. Run this block in Bash after the build: + +```sh +( + set -e + PORT=28080 DEVICE_PORT=7600 node bridge/dist/server.js & + bridge_pid=$! + node scripts/fake-gates.mjs & + gates_pid=$! + trap 'kill "$bridge_pid" "$gates_pid" 2>/dev/null || true' EXIT + pnpm test:e2e +) +``` + +`pnpm test:e2e` runs `e2e/entrance.spec.ts`. The fake gates reconnect while the bridge starts. These checks cover the browser and simulated device connections. Changes to Docker controls, Compose files or Gatepost integration also need checks against a running entrance with Docker and a compatible Gatepost checkout. Include the exact revisions, commands and results in the pull request. + +With Docker installed, check the image build: + +```sh +docker build -t gatepost-sim:local . +``` + +Fix any failures and rerun the affected checks. Explain the reason for the change, what changed and how it was verified. + +## Review and merge + +Follow `CODEOWNERS` when requesting reviews. Mateo Rossi and Fatima Zahra own the simulator and device behaviour; Noah Williams owns tests and browser checks; Yuki Tanaka reviews routed lab changes; Ingrid Larsen owns CI. Obtain at least one approval from an owner of each touched area. Include the relevant security, network or operations owner when the change affects those responsibilities. + +All required CI checks must be green before merge. CI runs on pull requests. Local checks are required before opening the pull request. CI also builds the container image, generates its SBOM and scans for high and critical vulnerabilities. diff --git a/CONTRIBUTING.zh-CN.md b/CONTRIBUTING.zh-CN.md new file mode 100644 index 0000000..09b17dc --- /dev/null +++ b/CONTRIBUTING.zh-CN.md @@ -0,0 +1,54 @@ +[English](CONTRIBUTING.md) | 简体中文 + +# 贡献指南 + +每个拉取请求只处理一项改动,并附上相应的测试和文档。中英文指南应同步更新。 + +## 分支和提交 + +分支名采用 `/`,主题要简短,单词之间用连字符连接,例如 `fix/gate-controls`。 + +提交标题采用 `type(scope): summary`。类型使用 `feat`、`fix`、`test`、`docs`、`style`、`chore`、`ci`、`perf`、`refactor` 或 `revert`。括号内写受影响的范围,例如 `bridge`、`web`、`sim` 或 `repo`。摘要使用祈使句,以动词原形说明要做的事,例如 `fix(bridge): report failed power actions`。 + +## 发起拉取请求前 + +使用 `.nvmrc` 指定的 Node 版本,以及 `package.json` 指定的 pnpm 10.20.0。在仓库根目录运行: + +```sh +pnpm install --frozen-lockfile +pnpm lint +pnpm typecheck +pnpm test +pnpm build +pnpm exec playwright install --with-deps chromium +``` + +浏览器检查需要一个 bridge 和四台假设备。确保端口 28080 和 7600 空闲,并先停止已有的模拟器。构建完成后,在 Bash 中运行以下代码块: + +```sh +( + set -e + PORT=28080 DEVICE_PORT=7600 node bridge/dist/server.js & + bridge_pid=$! + node scripts/fake-gates.mjs & + gates_pid=$! + trap 'kill "$bridge_pid" "$gates_pid" 2>/dev/null || true' EXIT + pnpm test:e2e +) +``` + +`pnpm test:e2e` 执行 `e2e/entrance.spec.ts`。bridge 启动期间,假设备会自动重连。这些检查覆盖浏览器和模拟设备连接。修改 Docker 控制、Compose 文件或 Gatepost 集成时,还须安装 Docker,准备兼容的 Gatepost 检出目录,并对运行中的入口进行检查。在拉取请求中写明准确的版本引用、命令和结果。 + +安装 Docker 后,检查镜像能否构建: + +```sh +docker build -t gatepost-sim:local . +``` + +如有检查失败,修复后重新运行相关检查。在拉取请求中说明改动原因、具体改动和验证方式。 + +## 评审与合并 + +按照 `CODEOWNERS` 邀请评审。Mateo Rossi 和 Fatima Zahra 负责模拟器与设备行为;Noah Williams 负责测试和浏览器检查;Yuki Tanaka 评审路由实验环境的改动;Ingrid Larsen 负责 CI。每个受影响的领域都须至少有一名负责人批准。涉及安全、网络或运营职责时,也应邀请对应负责人参与。 + +合并前,所有必需的 CI 检查都必须通过。CI 在拉取请求上运行,发起拉取请求前须完成本地检查。CI 还会构建容器镜像、生成 SBOM,并扫描高危和严重漏洞。 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b36ffa6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM node:26.12.1-bookworm-slim@sha256:88e480776c6149ff1d098cd304f44bf18057fb5d284a3329b78162d29821e28c AS build +WORKDIR /app +RUN npm install -g pnpm@10.20.0 +COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ +COPY bridge/package.json bridge/package.json +COPY web/package.json web/package.json +RUN pnpm install --frozen-lockfile +COPY bridge bridge +COPY web web +RUN pnpm build +FROM node:26.12.1-bookworm-slim@sha256:88e480776c6149ff1d098cd304f44bf18057fb5d284a3329b78162d29821e28c +LABEL org.opencontainers.image.title="Gatepost entrance simulator" org.opencontainers.image.licenses="MIT" +ENV NODE_ENV=production PORT=8080 DEVICE_PORT=7600 WEB_ROOT=/app/web/dist +WORKDIR /app +COPY --from=build /app/bridge/dist /app/bridge/dist +COPY --from=build /app/web/dist /app/web/dist +COPY --from=build /app/node_modules /app/node_modules +COPY --from=build /app/bridge/node_modules /app/bridge/node_modules +COPY --from=build /app/bridge/package.json /app/bridge/package.json +USER node +EXPOSE 8080 7600 +HEALTHCHECK --interval=15s --timeout=3s CMD node -e "fetch('http://127.0.0.1:8080/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))" +CMD ["node","bridge/dist/server.js"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..2fa0866 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +English | [简体中文](README.zh-CN.md) + +# Gatepost simulator + +This local entrance simulator gives device developers and venue staff a browser view of four synthetic gates. It models barcode scans, turnstile motion, lights, device connections, power and the venue network. It implements Gatepost's [device simulator protocol](../gatepost/docs/device/simulator-protocol.md). + +## Run + +Install Docker, then run from this repository: + +```sh +scripts/venue.sh up --gatepost ../gatepost --ref 2b4843b --mode devices +scripts/venue.sh status +scripts/venue.sh down +``` + +The script builds `gated` in a detached temporary worktree, starts the standalone entrance at http://127.0.0.1:28080, and removes the worktree with `down`. For the Gate 3 crash scenario, build the revision before the fix in a separate detached worktree and pass `--gate3-crash DIR`; `down` includes `compose.gate3-crash.yaml` in cleanup. `scripts/e2e-gatepost.sh` runs the Playwright checks against an active entrance. The ticket file contains only synthetic barcodes. + +`SIM_PORT` changes the local page port. `DOCKER_GID` defaults to the socket group. The bridge listens for the page on port 8080 inside its container, publishes only to host loopback, and accepts device TCP on the private `devices` network. `AUTO_PASS_MS` enables automatic passage after a relay opens. The bridge runs as the `node` user; it needs access to the Docker socket, usually via the socket's group ID. + +## Browser messages + +The browser WebSocket is `/ws`. The bridge sends `{ "type": "snapshot", "gates": [], "events": [], "tickets": [] }` and `{ "type": "error", "message": "..." }`. The browser sends `scan` (`gate`, `barcode`), `simultaneous` (`gates`, `barcode`), `burst` (`count`, `intervalMs`), `pass` (`gate`), `power` (`gate`, `on`), or `network` (`gate`, `on`). Gate IDs must be configured services. The event log records the wire lines and directions. The bridge does not decide ticket validity; `gated` does. + +## Development + +Use Node 26.12.1 and pnpm 10.20.0. Run `pnpm install --frozen-lockfile`, then `pnpm lint`, `pnpm typecheck`, `pnpm test`, and `pnpm build`. `pnpm test:e2e` runs browser checks against a running bridge and fake gates. CI also builds the image, produces an SBOM, and scans it. + +The bridge has the Docker Engine socket mounted. Anyone who can use that socket can manage every container on the host. This local development service publishes its page only on 127.0.0.1 and checks the configured Compose project and service allow-list before power or network actions. The network control disconnects and reconnects only the venue network, saving its address, MAC and aliases; the private device network stays connected. The simulator models hardware commands, not radio, power-supply behavior, or scanner optics. diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 0000000..595db35 --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,29 @@ +[English](README.md) | 简体中文 + +# Gatepost 模拟器 + +本地入口模拟器在浏览器中展示四个使用合成票据的闸机,供设备开发与场馆演示使用。它模拟扫码、转闸、指示灯、设备连接、电源和场馆网络,并实现 Gatepost 的[设备模拟协议](../gatepost/docs/device/simulator-protocol.zh-CN.md)。 + +## 运行 + +安装 Docker,在本仓库执行: + +```sh +scripts/venue.sh up --gatepost ../gatepost --ref 2b4843b --mode devices +scripts/venue.sh status +scripts/venue.sh down +``` + +脚本在独立的临时 worktree 中构建 `gated`,在 http://127.0.0.1:28080 启动入口;`down` 清理 Compose 项目和 worktree。要运行重现 Gate 3 崩溃的场景,在另一个独立 worktree 中构建崩溃修复前的提交,并以 `--gate3-crash DIR` 传入;`down` 会同时纳入 `compose.gate3-crash.yaml`。`scripts/e2e-gatepost.sh` 检查正在运行的入口。票据文件只含合成条码。 + +`SIM_PORT` 控制本地页面端口;`DOCKER_GID` 默认取 Docker socket 的组 ID。容器内页面端口为 8080,仅发布到主机回环地址;设备 TCP 只在私有 `devices` 网络监听。`AUTO_PASS_MS` 可配置转闸打开后的自动通行。bridge 以 `node` 用户运行,需要通过 socket 的组权限访问 Docker。 + +## 浏览器消息 + +WebSocket 路径是 `/ws`。bridge 发送 `snapshot`(含 `gates`、`events`、`tickets`)或 `error`(含 `message`)。浏览器发送 `scan`(`gate`、`barcode`)、`simultaneous`(`gates`、`barcode`)、`burst`(`count`、`intervalMs`)、`pass`(`gate`)、`power` 或 `network`(`gate`、`on`)。闸机 ID 必须属于配置的服务。事件日志记录协议行与方向。票据是否有效由 `gated` 决定。 + +## 开发与限制 + +使用 Node 26.12.1 与 pnpm 10.20.0。运行 `pnpm install --frozen-lockfile`,再运行 `pnpm lint`、`pnpm typecheck`、`pnpm test`、`pnpm build`。`pnpm test:e2e` 在 bridge 与假闸机运行时检查页面。CI 还构建镜像、生成 SBOM 并扫描漏洞。 + +bridge 挂载了 Docker Engine socket。能够使用该 socket 的进程可以管理主机上的所有容器。因此本工具仅用于本地开发,页面只发布到 127.0.0.1;电源和网络操作会检查 Compose 项目与服务白名单。网络操作只断开并重新连接场馆网络,同时保存地址、MAC 与别名;私有设备网络保持连接。模拟器不模拟无线电、电源供电细节或扫码器光学特性。 diff --git a/bridge/package.json b/bridge/package.json index e21fae3..bbce9f4 100644 --- a/bridge/package.json +++ b/bridge/package.json @@ -1,11 +1,11 @@ { "name": "@gatepost-sim/bridge", - "version": "0.1.0-dev", + "version": "0.1.0", "private": true, "type": "module", "scripts": { "build": "tsc", - "test": "vitest run --passWithNoTests", + "test": "vitest run", "typecheck": "tsc --noEmit" }, "dependencies": { diff --git a/bridge/test/docker.test.ts b/bridge/test/docker.test.ts new file mode 100644 index 0000000..8faa5e2 --- /dev/null +++ b/bridge/test/docker.test.ts @@ -0,0 +1,66 @@ +import { afterEach, expect, it, vi } from 'vitest'; +import http from 'node:http'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import { allowed } from '../src/docker.js'; + +const servers: http.Server[] = []; +const directories: string[] = []; +afterEach(async () => { + await Promise.all( + servers.splice(0).map((server) => new Promise((done) => server.close(() => done()))), + ); + for (const directory of directories.splice(0)) + fs.rmSync(directory, { recursive: true, force: true }); + delete process.env.DOCKER_SOCKET; + vi.resetModules(); +}); + +it('guards project, service and requested gate', () => { + const labels = { + 'com.docker.compose.project': 'gatepost-sim-devices', + 'com.docker.compose.service': 'gate1', + }; + expect(allowed(labels, 'gate1')).toBe(true); + expect(allowed(labels, 'gate2')).toBe(false); + expect(allowed({ ...labels, 'com.docker.compose.project': 'foreign' }, 'gate1')).toBe(false); +}); + +it('checks inspected labels before a Docker action on a Unix socket', async () => { + const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'gatepost-docker-test-')); + directories.push(directory); + const socket = path.join(directory, 'docker.sock'); + process.env.DOCKER_SOCKET = socket; + const calls: string[] = []; + let projectLabel = 'foreign'; + const server = http.createServer((req, res) => { + calls.push(`${req.method} ${req.url}`); + res.setHeader('Content-Type', 'application/json'); + if (req.url?.startsWith('/containers/json')) res.end(JSON.stringify([{ Id: 'container-1' }])); + else if (req.url === '/containers/container-1/json') + res.end( + JSON.stringify({ + Id: 'container-1', + Config: { + Labels: { + 'com.docker.compose.project': projectLabel, + 'com.docker.compose.service': 'gate1', + }, + }, + NetworkSettings: { Networks: {} }, + }), + ); + else res.writeHead(204).end(); + }); + servers.push(server); + await new Promise((done) => server.listen(socket, done)); + vi.resetModules(); + const { action } = await import('../src/docker.js'); + await expect(action('gate1', 'power', false)).rejects.toThrow('Container labels refused'); + await expect(action('foreign-gate', 'power', false)).rejects.toThrow('Service not allowed'); + expect(calls.some((call) => call.includes('/kill'))).toBe(false); + projectLabel = 'gatepost-sim-devices'; + await action('gate1', 'power', false); + expect(calls.some((call) => call === 'POST /containers/container-1/kill')).toBe(true); +}); diff --git a/bridge/test/protocol.test.ts b/bridge/test/protocol.test.ts new file mode 100644 index 0000000..dc7d207 --- /dev/null +++ b/bridge/test/protocol.test.ts @@ -0,0 +1,43 @@ +import { describe, it, expect } from 'vitest'; +import { hello, output, Lines, scanLine } from '../src/protocol.js'; +describe('wire protocol', () => { + it('recognizes both HELLO roles and rejects malformed lines', () => { + expect(hello('HELLO gate1 scanner 1')).toEqual({ gate: 'gate1', role: 'scanner' }); + expect(hello('HELLO gate1 outputs 1')).toEqual({ gate: 'gate1', role: 'outputs' }); + expect(hello('HELLO gate1 scanner 2')).toBeNull(); + expect(hello('HELLO bad gate scanner 1')).toBeNull(); + }); + it('parses output commands and rejects unknown lines', () => { + expect(output('LIGHT GREEN')).toEqual({ kind: 'light', value: 'GREEN' }); + expect(output('RELAY OPEN 2000')).toEqual({ kind: 'relay', ms: 2000 }); + expect(output('LED NET OFF')).toEqual({ kind: 'net', value: 'OFF' }); + expect(output('RELAY OPEN -2')).toBeNull(); + expect(output('BOGUS')).toBeNull(); + }); + it('discards overlong and non-ASCII lines through LF', () => { + const lines: string[] = [], + bad: string[] = []; + const parser = new Lines(); + parser.feed( + Buffer.from('A'.repeat(256)), + (l) => lines.push(l), + (r) => bad.push(r), + ); + parser.feed( + Buffer.from('\nLIGHT GREEN\n'), + (l) => lines.push(l), + (r) => bad.push(r), + ); + parser.feed( + Buffer.from([0xff, 10]), + (l) => lines.push(l), + (r) => bad.push(r), + ); + expect(lines).toEqual(['LIGHT GREEN']); + expect(bad).toHaveLength(2); + }); + it('bounds outgoing scans', () => { + expect(scanLine('GP-1')).toBe('SCAN GP-1\n'); + expect(() => scanLine('a'.repeat(64))).toThrow(); + }); +}); diff --git a/bridge/test/state.test.ts b/bridge/test/state.test.ts new file mode 100644 index 0000000..010f4b0 --- /dev/null +++ b/bridge/test/state.test.ts @@ -0,0 +1,23 @@ +import { it, expect, vi } from 'vitest'; +import { Socket } from 'node:net'; +import { Model } from '../src/state.js'; +it('separates streams, resets outputs on disconnect and does not resend scans after reconnect', () => { + const model = new Model(() => {}); + const first = new Socket(), + next = new Socket(); + const write = vi.spyOn(first, 'write').mockReturnValue(true); + model.attach('gate1', 'scanner', first); + model.scan('gate1', 'GP-1'); + expect(write).toHaveBeenCalledWith('SCAN GP-1\n'); + model.attach('gate1', 'scanner', next); + expect(() => model.scan('gate2', 'GP-1')).toThrow(); + model.detach('gate1', 'scanner', first); + expect(model.gate('gate1').scanner).toBe(true); + model.attach('gate1', 'outputs', first); + model.receive('gate1', 'LIGHT GREEN'); + model.detach('gate1', 'outputs', first); + expect(model.gate('gate1').light).toBe('OFF'); + expect(model.gate('gate1').outputs).toBe(false); + next.destroy(); + first.destroy(); +}); diff --git a/compose.devices.yaml b/compose.devices.yaml new file mode 100644 index 0000000..931495f --- /dev/null +++ b/compose.devices.yaml @@ -0,0 +1,86 @@ +name: gatepost-sim-devices +x-gate: &gate + image: gatepost-build:local + restart: 'no' + volumes: + - ${GATEPOST_DIR:?set GATEPOST_DIR}:/src:ro + - ./data/tickets.txt:/data/tickets.txt:ro + networks: [devices, venue] + environment: + GATEPOST_SCANNER: sim:bridge:7600 + GATEPOST_OUTPUTS: sim:bridge:7600 + GATEPOST_HOLD_MS: '2000' +services: + bridge: + build: . + image: gatepost-sim:local + group_add: ['${DOCKER_GID:-0}'] + ports: ['127.0.0.1:${SIM_PORT:-28080}:8080'] + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ./data/tickets.txt:/data/tickets.txt:ro + environment: + COMPOSE_PROJECT_NAME: gatepost-sim-devices + GATE_SERVICES: gate1,gate2,gate3,gate4 + VENUE_NETWORK: gatepost-sim-devices_venue + TICKET_FILE: /data/tickets.txt + networks: [devices] + gate-hub: + image: gatepost-build:local + volumes: + [ + '${GATEPOST_DIR:?set GATEPOST_DIR}:/src:ro', + './data/tickets.txt:/data/tickets.txt:ro', + './scripts/hub-proxy.py:/sim/hub-proxy.py:ro', + ] + command: + [ + 'sh', + '-c', + '/src/build/debug/gate-hub /data/tickets.txt 7000 per-connection & exec python3 /sim/hub-proxy.py', + ] + networks: [venue] + profiles: [hub] + gate1: + <<: *gate + environment: + { + GATEPOST_SCANNER: 'sim:bridge:7600', + GATEPOST_OUTPUTS: 'sim:bridge:7600', + GATEPOST_GATE_ID: gate1, + GATEPOST_HUB: 'gate-hub:7001', + } + command: ['/src/build/debug/gated', '/data/tickets.txt'] + gate2: + <<: *gate + environment: + { + GATEPOST_SCANNER: 'sim:bridge:7600', + GATEPOST_OUTPUTS: 'sim:bridge:7600', + GATEPOST_GATE_ID: gate2, + GATEPOST_HUB: 'gate-hub:7001', + } + command: ['/src/build/debug/gated', '/data/tickets.txt'] + gate3: + <<: *gate + environment: + { + GATEPOST_SCANNER: 'sim:bridge:7600', + GATEPOST_OUTPUTS: 'sim:bridge:7600', + GATEPOST_GATE_ID: gate3, + GATEPOST_HUB: 'gate-hub:7001', + } + command: ['/src/build/debug/gated', '/data/tickets.txt'] + gate4: + <<: *gate + environment: + { + GATEPOST_SCANNER: 'sim:bridge:7600', + GATEPOST_OUTPUTS: 'sim:bridge:7600', + GATEPOST_GATE_ID: gate4, + GATEPOST_HUB: 'gate-hub:7001', + } + command: ['/src/build/debug/gated', '/data/tickets.txt'] +networks: + devices: {} + venue: {} diff --git a/compose.gate3-crash.yaml b/compose.gate3-crash.yaml new file mode 100644 index 0000000..4d02a28 --- /dev/null +++ b/compose.gate3-crash.yaml @@ -0,0 +1,13 @@ +services: + gate3: + image: gatepost-build:local + volumes: + - ${GATE3_CRASH_DIR:-${GATEPOST_DIR:?set GATEPOST_DIR}}:/gate3-crash:ro + - ./scripts/gate3-crash-adapter.py:/sim/gate3-crash-adapter.py:ro + command: + [ + 'python3', + '/sim/gate3-crash-adapter.py', + '/gate3-crash/build/debug/gated', + '/data/tickets.txt', + ] diff --git a/data/tickets.txt b/data/tickets.txt new file mode 100644 index 0000000..ab5561f --- /dev/null +++ b/data/tickets.txt @@ -0,0 +1,1000 @@ +GP-000000000000 +GP-000000000001 +GP-000000000002 +GP-000000000003 +GP-000000000004 +GP-000000000005 +GP-000000000006 +GP-000000000007 +GP-000000000008 +GP-000000000009 +GP-000000000010 +GP-000000000011 +GP-000000000012 +GP-000000000013 +GP-000000000014 +GP-000000000015 +GP-000000000016 +GP-000000000017 +GP-000000000018 +GP-000000000019 +GP-000000000020 +GP-000000000021 +GP-000000000022 +GP-000000000023 +GP-000000000024 +GP-000000000025 +GP-000000000026 +GP-000000000027 +GP-000000000028 +GP-000000000029 +GP-000000000030 +GP-000000000031 +GP-000000000032 +GP-000000000033 +GP-000000000034 +GP-000000000035 +GP-000000000036 +GP-000000000037 +GP-000000000038 +GP-000000000039 +GP-000000000040 +GP-000000000041 +GP-000000000042 +GP-000000000043 +GP-000000000044 +GP-000000000045 +GP-000000000046 +GP-000000000047 +GP-000000000048 +GP-000000000049 +GP-000000000050 +GP-000000000051 +GP-000000000052 +GP-000000000053 +GP-000000000054 +GP-000000000055 +GP-000000000056 +GP-000000000057 +GP-000000000058 +GP-000000000059 +GP-000000000060 +GP-000000000061 +GP-000000000062 +GP-000000000063 +GP-000000000064 +GP-000000000065 +GP-000000000066 +GP-000000000067 +GP-000000000068 +GP-000000000069 +GP-000000000070 +GP-000000000071 +GP-000000000072 +GP-000000000073 +GP-000000000074 +GP-000000000075 +GP-000000000076 +GP-000000000077 +GP-000000000078 +GP-000000000079 +GP-000000000080 +GP-000000000081 +GP-000000000082 +GP-000000000083 +GP-000000000084 +GP-000000000085 +GP-000000000086 +GP-000000000087 +GP-000000000088 +GP-000000000089 +GP-000000000090 +GP-000000000091 +GP-000000000092 +GP-000000000093 +GP-000000000094 +GP-000000000095 +GP-000000000096 +GP-000000000097 +GP-000000000098 +GP-000000000099 +GP-000000000100 +GP-000000000101 +GP-000000000102 +GP-000000000103 +GP-000000000104 +GP-000000000105 +GP-000000000106 +GP-000000000107 +GP-000000000108 +GP-000000000109 +GP-000000000110 +GP-000000000111 +GP-000000000112 +GP-000000000113 +GP-000000000114 +GP-000000000115 +GP-000000000116 +GP-000000000117 +GP-000000000118 +GP-000000000119 +GP-000000000120 +GP-000000000121 +GP-000000000122 +GP-000000000123 +GP-000000000124 +GP-000000000125 +GP-000000000126 +GP-000000000127 +GP-000000000128 +GP-000000000129 +GP-000000000130 +GP-000000000131 +GP-000000000132 +GP-000000000133 +GP-000000000134 +GP-000000000135 +GP-000000000136 +GP-000000000137 +GP-000000000138 +GP-000000000139 +GP-000000000140 +GP-000000000141 +GP-000000000142 +GP-000000000143 +GP-000000000144 +GP-000000000145 +GP-000000000146 +GP-000000000147 +GP-000000000148 +GP-000000000149 +GP-000000000150 +GP-000000000151 +GP-000000000152 +GP-000000000153 +GP-000000000154 +GP-000000000155 +GP-000000000156 +GP-000000000157 +GP-000000000158 +GP-000000000159 +GP-000000000160 +GP-000000000161 +GP-000000000162 +GP-000000000163 +GP-000000000164 +GP-000000000165 +GP-000000000166 +GP-000000000167 +GP-000000000168 +GP-000000000169 +GP-000000000170 +GP-000000000171 +GP-000000000172 +GP-000000000173 +GP-000000000174 +GP-000000000175 +GP-000000000176 +GP-000000000177 +GP-000000000178 +GP-000000000179 +GP-000000000180 +GP-000000000181 +GP-000000000182 +GP-000000000183 +GP-000000000184 +GP-000000000185 +GP-000000000186 +GP-000000000187 +GP-000000000188 +GP-000000000189 +GP-000000000190 +GP-000000000191 +GP-000000000192 +GP-000000000193 +GP-000000000194 +GP-000000000195 +GP-000000000196 +GP-000000000197 +GP-000000000198 +GP-000000000199 +GP-000000000200 +GP-000000000201 +GP-000000000202 +GP-000000000203 +GP-000000000204 +GP-000000000205 +GP-000000000206 +GP-000000000207 +GP-000000000208 +GP-000000000209 +GP-000000000210 +GP-000000000211 +GP-000000000212 +GP-000000000213 +GP-000000000214 +GP-000000000215 +GP-000000000216 +GP-000000000217 +GP-000000000218 +GP-000000000219 +GP-000000000220 +GP-000000000221 +GP-000000000222 +GP-000000000223 +GP-000000000224 +GP-000000000225 +GP-000000000226 +GP-000000000227 +GP-000000000228 +GP-000000000229 +GP-000000000230 +GP-000000000231 +GP-000000000232 +GP-000000000233 +GP-000000000234 +GP-000000000235 +GP-000000000236 +GP-000000000237 +GP-000000000238 +GP-000000000239 +GP-000000000240 +GP-000000000241 +GP-000000000242 +GP-000000000243 +GP-000000000244 +GP-000000000245 +GP-000000000246 +GP-000000000247 +GP-000000000248 +GP-000000000249 +GP-000000000250 +GP-000000000251 +GP-000000000252 +GP-000000000253 +GP-000000000254 +GP-000000000255 +GP-000000000256 +GP-000000000257 +GP-000000000258 +GP-000000000259 +GP-000000000260 +GP-000000000261 +GP-000000000262 +GP-000000000263 +GP-000000000264 +GP-000000000265 +GP-000000000266 +GP-000000000267 +GP-000000000268 +GP-000000000269 +GP-000000000270 +GP-000000000271 +GP-000000000272 +GP-000000000273 +GP-000000000274 +GP-000000000275 +GP-000000000276 +GP-000000000277 +GP-000000000278 +GP-000000000279 +GP-000000000280 +GP-000000000281 +GP-000000000282 +GP-000000000283 +GP-000000000284 +GP-000000000285 +GP-000000000286 +GP-000000000287 +GP-000000000288 +GP-000000000289 +GP-000000000290 +GP-000000000291 +GP-000000000292 +GP-000000000293 +GP-000000000294 +GP-000000000295 +GP-000000000296 +GP-000000000297 +GP-000000000298 +GP-000000000299 +GP-000000000300 +GP-000000000301 +GP-000000000302 +GP-000000000303 +GP-000000000304 +GP-000000000305 +GP-000000000306 +GP-000000000307 +GP-000000000308 +GP-000000000309 +GP-000000000310 +GP-000000000311 +GP-000000000312 +GP-000000000313 +GP-000000000314 +GP-000000000315 +GP-000000000316 +GP-000000000317 +GP-000000000318 +GP-000000000319 +GP-000000000320 +GP-000000000321 +GP-000000000322 +GP-000000000323 +GP-000000000324 +GP-000000000325 +GP-000000000326 +GP-000000000327 +GP-000000000328 +GP-000000000329 +GP-000000000330 +GP-000000000331 +GP-000000000332 +GP-000000000333 +GP-000000000334 +GP-000000000335 +GP-000000000336 +GP-000000000337 +GP-000000000338 +GP-000000000339 +GP-000000000340 +GP-000000000341 +GP-000000000342 +GP-000000000343 +GP-000000000344 +GP-000000000345 +GP-000000000346 +GP-000000000347 +GP-000000000348 +GP-000000000349 +GP-000000000350 +GP-000000000351 +GP-000000000352 +GP-000000000353 +GP-000000000354 +GP-000000000355 +GP-000000000356 +GP-000000000357 +GP-000000000358 +GP-000000000359 +GP-000000000360 +GP-000000000361 +GP-000000000362 +GP-000000000363 +GP-000000000364 +GP-000000000365 +GP-000000000366 +GP-000000000367 +GP-000000000368 +GP-000000000369 +GP-000000000370 +GP-000000000371 +GP-000000000372 +GP-000000000373 +GP-000000000374 +GP-000000000375 +GP-000000000376 +GP-000000000377 +GP-000000000378 +GP-000000000379 +GP-000000000380 +GP-000000000381 +GP-000000000382 +GP-000000000383 +GP-000000000384 +GP-000000000385 +GP-000000000386 +GP-000000000387 +GP-000000000388 +GP-000000000389 +GP-000000000390 +GP-000000000391 +GP-000000000392 +GP-000000000393 +GP-000000000394 +GP-000000000395 +GP-000000000396 +GP-000000000397 +GP-000000000398 +GP-000000000399 +GP-000000000400 +GP-000000000401 +GP-000000000402 +GP-000000000403 +GP-000000000404 +GP-000000000405 +GP-000000000406 +GP-000000000407 +GP-000000000408 +GP-000000000409 +GP-000000000410 +GP-000000000411 +GP-000000000412 +GP-000000000413 +GP-000000000414 +GP-000000000415 +GP-000000000416 +GP-000000000417 +GP-000000000418 +GP-000000000419 +GP-000000000420 +GP-000000000421 +GP-000000000422 +GP-000000000423 +GP-000000000424 +GP-000000000425 +GP-000000000426 +GP-000000000427 +GP-000000000428 +GP-000000000429 +GP-000000000430 +GP-000000000431 +GP-000000000432 +GP-000000000433 +GP-000000000434 +GP-000000000435 +GP-000000000436 +GP-000000000437 +GP-000000000438 +GP-000000000439 +GP-000000000440 +GP-000000000441 +GP-000000000442 +GP-000000000443 +GP-000000000444 +GP-000000000445 +GP-000000000446 +GP-000000000447 +GP-000000000448 +GP-000000000449 +GP-000000000450 +GP-000000000451 +GP-000000000452 +GP-000000000453 +GP-000000000454 +GP-000000000455 +GP-000000000456 +GP-000000000457 +GP-000000000458 +GP-000000000459 +GP-000000000460 +GP-000000000461 +GP-000000000462 +GP-000000000463 +GP-000000000464 +GP-000000000465 +GP-000000000466 +GP-000000000467 +GP-000000000468 +GP-000000000469 +GP-000000000470 +GP-000000000471 +GP-000000000472 +GP-000000000473 +GP-000000000474 +GP-000000000475 +GP-000000000476 +GP-000000000477 +GP-000000000478 +GP-000000000479 +GP-000000000480 +GP-000000000481 +GP-000000000482 +GP-000000000483 +GP-000000000484 +GP-000000000485 +GP-000000000486 +GP-000000000487 +GP-000000000488 +GP-000000000489 +GP-000000000490 +GP-000000000491 +GP-000000000492 +GP-000000000493 +GP-000000000494 +GP-000000000495 +GP-000000000496 +GP-000000000497 +GP-000000000498 +GP-000000000499 +GP-000000000500 +GP-000000000501 +GP-000000000502 +GP-000000000503 +GP-000000000504 +GP-000000000505 +GP-000000000506 +GP-000000000507 +GP-000000000508 +GP-000000000509 +GP-000000000510 +GP-000000000511 +GP-000000000512 +GP-000000000513 +GP-000000000514 +GP-000000000515 +GP-000000000516 +GP-000000000517 +GP-000000000518 +GP-000000000519 +GP-000000000520 +GP-000000000521 +GP-000000000522 +GP-000000000523 +GP-000000000524 +GP-000000000525 +GP-000000000526 +GP-000000000527 +GP-000000000528 +GP-000000000529 +GP-000000000530 +GP-000000000531 +GP-000000000532 +GP-000000000533 +GP-000000000534 +GP-000000000535 +GP-000000000536 +GP-000000000537 +GP-000000000538 +GP-000000000539 +GP-000000000540 +GP-000000000541 +GP-000000000542 +GP-000000000543 +GP-000000000544 +GP-000000000545 +GP-000000000546 +GP-000000000547 +GP-000000000548 +GP-000000000549 +GP-000000000550 +GP-000000000551 +GP-000000000552 +GP-000000000553 +GP-000000000554 +GP-000000000555 +GP-000000000556 +GP-000000000557 +GP-000000000558 +GP-000000000559 +GP-000000000560 +GP-000000000561 +GP-000000000562 +GP-000000000563 +GP-000000000564 +GP-000000000565 +GP-000000000566 +GP-000000000567 +GP-000000000568 +GP-000000000569 +GP-000000000570 +GP-000000000571 +GP-000000000572 +GP-000000000573 +GP-000000000574 +GP-000000000575 +GP-000000000576 +GP-000000000577 +GP-000000000578 +GP-000000000579 +GP-000000000580 +GP-000000000581 +GP-000000000582 +GP-000000000583 +GP-000000000584 +GP-000000000585 +GP-000000000586 +GP-000000000587 +GP-000000000588 +GP-000000000589 +GP-000000000590 +GP-000000000591 +GP-000000000592 +GP-000000000593 +GP-000000000594 +GP-000000000595 +GP-000000000596 +GP-000000000597 +GP-000000000598 +GP-000000000599 +GP-000000000600 +GP-000000000601 +GP-000000000602 +GP-000000000603 +GP-000000000604 +GP-000000000605 +GP-000000000606 +GP-000000000607 +GP-000000000608 +GP-000000000609 +GP-000000000610 +GP-000000000611 +GP-000000000612 +GP-000000000613 +GP-000000000614 +GP-000000000615 +GP-000000000616 +GP-000000000617 +GP-000000000618 +GP-000000000619 +GP-000000000620 +GP-000000000621 +GP-000000000622 +GP-000000000623 +GP-000000000624 +GP-000000000625 +GP-000000000626 +GP-000000000627 +GP-000000000628 +GP-000000000629 +GP-000000000630 +GP-000000000631 +GP-000000000632 +GP-000000000633 +GP-000000000634 +GP-000000000635 +GP-000000000636 +GP-000000000637 +GP-000000000638 +GP-000000000639 +GP-000000000640 +GP-000000000641 +GP-000000000642 +GP-000000000643 +GP-000000000644 +GP-000000000645 +GP-000000000646 +GP-000000000647 +GP-000000000648 +GP-000000000649 +GP-000000000650 +GP-000000000651 +GP-000000000652 +GP-000000000653 +GP-000000000654 +GP-000000000655 +GP-000000000656 +GP-000000000657 +GP-000000000658 +GP-000000000659 +GP-000000000660 +GP-000000000661 +GP-000000000662 +GP-000000000663 +GP-000000000664 +GP-000000000665 +GP-000000000666 +GP-000000000667 +GP-000000000668 +GP-000000000669 +GP-000000000670 +GP-000000000671 +GP-000000000672 +GP-000000000673 +GP-000000000674 +GP-000000000675 +GP-000000000676 +GP-000000000677 +GP-000000000678 +GP-000000000679 +GP-000000000680 +GP-000000000681 +GP-000000000682 +GP-000000000683 +GP-000000000684 +GP-000000000685 +GP-000000000686 +GP-000000000687 +GP-000000000688 +GP-000000000689 +GP-000000000690 +GP-000000000691 +GP-000000000692 +GP-000000000693 +GP-000000000694 +GP-000000000695 +GP-000000000696 +GP-000000000697 +GP-000000000698 +GP-000000000699 +GP-000000000700 +GP-000000000701 +GP-000000000702 +GP-000000000703 +GP-000000000704 +GP-000000000705 +GP-000000000706 +GP-000000000707 +GP-000000000708 +GP-000000000709 +GP-000000000710 +GP-000000000711 +GP-000000000712 +GP-000000000713 +GP-000000000714 +GP-000000000715 +GP-000000000716 +GP-000000000717 +GP-000000000718 +GP-000000000719 +GP-000000000720 +GP-000000000721 +GP-000000000722 +GP-000000000723 +GP-000000000724 +GP-000000000725 +GP-000000000726 +GP-000000000727 +GP-000000000728 +GP-000000000729 +GP-000000000730 +GP-000000000731 +GP-000000000732 +GP-000000000733 +GP-000000000734 +GP-000000000735 +GP-000000000736 +GP-000000000737 +GP-000000000738 +GP-000000000739 +GP-000000000740 +GP-000000000741 +GP-000000000742 +GP-000000000743 +GP-000000000744 +GP-000000000745 +GP-000000000746 +GP-000000000747 +GP-000000000748 +GP-000000000749 +GP-000000000750 +GP-000000000751 +GP-000000000752 +GP-000000000753 +GP-000000000754 +GP-000000000755 +GP-000000000756 +GP-000000000757 +GP-000000000758 +GP-000000000759 +GP-000000000760 +GP-000000000761 +GP-000000000762 +GP-000000000763 +GP-000000000764 +GP-000000000765 +GP-000000000766 +GP-000000000767 +GP-000000000768 +GP-000000000769 +GP-000000000770 +GP-000000000771 +GP-000000000772 +GP-000000000773 +GP-000000000774 +GP-000000000775 +GP-000000000776 +GP-000000000777 +GP-000000000778 +GP-000000000779 +GP-000000000780 +GP-000000000781 +GP-000000000782 +GP-000000000783 +GP-000000000784 +GP-000000000785 +GP-000000000786 +GP-000000000787 +GP-000000000788 +GP-000000000789 +GP-000000000790 +GP-000000000791 +GP-000000000792 +GP-000000000793 +GP-000000000794 +GP-000000000795 +GP-000000000796 +GP-000000000797 +GP-000000000798 +GP-000000000799 +GP-000000000800 +GP-000000000801 +GP-000000000802 +GP-000000000803 +GP-000000000804 +GP-000000000805 +GP-000000000806 +GP-000000000807 +GP-000000000808 +GP-000000000809 +GP-000000000810 +GP-000000000811 +GP-000000000812 +GP-000000000813 +GP-000000000814 +GP-000000000815 +GP-000000000816 +GP-000000000817 +GP-000000000818 +GP-000000000819 +GP-000000000820 +GP-000000000821 +GP-000000000822 +GP-000000000823 +GP-000000000824 +GP-000000000825 +GP-000000000826 +GP-000000000827 +GP-000000000828 +GP-000000000829 +GP-000000000830 +GP-000000000831 +GP-000000000832 +GP-000000000833 +GP-000000000834 +GP-000000000835 +GP-000000000836 +GP-000000000837 +GP-000000000838 +GP-000000000839 +GP-000000000840 +GP-000000000841 +GP-000000000842 +GP-000000000843 +GP-000000000844 +GP-000000000845 +GP-000000000846 +GP-000000000847 +GP-000000000848 +GP-000000000849 +GP-000000000850 +GP-000000000851 +GP-000000000852 +GP-000000000853 +GP-000000000854 +GP-000000000855 +GP-000000000856 +GP-000000000857 +GP-000000000858 +GP-000000000859 +GP-000000000860 +GP-000000000861 +GP-000000000862 +GP-000000000863 +GP-000000000864 +GP-000000000865 +GP-000000000866 +GP-000000000867 +GP-000000000868 +GP-000000000869 +GP-000000000870 +GP-000000000871 +GP-000000000872 +GP-000000000873 +GP-000000000874 +GP-000000000875 +GP-000000000876 +GP-000000000877 +GP-000000000878 +GP-000000000879 +GP-000000000880 +GP-000000000881 +GP-000000000882 +GP-000000000883 +GP-000000000884 +GP-000000000885 +GP-000000000886 +GP-000000000887 +GP-000000000888 +GP-000000000889 +GP-000000000890 +GP-000000000891 +GP-000000000892 +GP-000000000893 +GP-000000000894 +GP-000000000895 +GP-000000000896 +GP-000000000897 +GP-000000000898 +GP-000000000899 +GP-000000000900 +GP-000000000901 +GP-000000000902 +GP-000000000903 +GP-000000000904 +GP-000000000905 +GP-000000000906 +GP-000000000907 +GP-000000000908 +GP-000000000909 +GP-000000000910 +GP-000000000911 +GP-000000000912 +GP-000000000913 +GP-000000000914 +GP-000000000915 +GP-000000000916 +GP-000000000917 +GP-000000000918 +GP-000000000919 +GP-000000000920 +GP-000000000921 +GP-000000000922 +GP-000000000923 +GP-000000000924 +GP-000000000925 +GP-000000000926 +GP-000000000927 +GP-000000000928 +GP-000000000929 +GP-000000000930 +GP-000000000931 +GP-000000000932 +GP-000000000933 +GP-000000000934 +GP-000000000935 +GP-000000000936 +GP-000000000937 +GP-000000000938 +GP-000000000939 +GP-000000000940 +GP-000000000941 +GP-000000000942 +GP-000000000943 +GP-000000000944 +GP-000000000945 +GP-000000000946 +GP-000000000947 +GP-000000000948 +GP-000000000949 +GP-000000000950 +GP-000000000951 +GP-000000000952 +GP-000000000953 +GP-000000000954 +GP-000000000955 +GP-000000000956 +GP-000000000957 +GP-000000000958 +GP-000000000959 +GP-000000000960 +GP-000000000961 +GP-000000000962 +GP-000000000963 +GP-000000000964 +GP-000000000965 +GP-000000000966 +GP-000000000967 +GP-000000000968 +GP-000000000969 +GP-000000000970 +GP-000000000971 +GP-000000000972 +GP-000000000973 +GP-000000000974 +GP-000000000975 +GP-000000000976 +GP-000000000977 +GP-000000000978 +GP-000000000979 +GP-000000000980 +GP-000000000981 +GP-000000000982 +GP-000000000983 +GP-000000000984 +GP-000000000985 +GP-000000000986 +GP-000000000987 +GP-000000000988 +GP-000000000989 +GP-000000000990 +GP-000000000991 +GP-000000000992 +GP-000000000993 +GP-000000000994 +GP-000000000995 +GP-000000000996 +GP-000000000997 +GP-000000000998 +GP-000000000999 diff --git a/docs/screenshots/README.md b/docs/screenshots/README.md new file mode 100644 index 0000000..c7c95ec --- /dev/null +++ b/docs/screenshots/README.md @@ -0,0 +1,9 @@ +English | [简体中文](README.zh-CN.md) + +# Demonstration screenshots + +All screenshots use a 1440 × 900 light-theme Playwright viewport. + +| File | State and code ref | Command | +| ------------------- | ----------------------------------------------------------------------------- | ---------------------------------------------------------- | +| `gate3-stopped.png` | Gate 3 crash scenario, `2b4843b` plus Gate 3 crash revision `a058409` adapter | `pnpm exec playwright test e2e/real-gate3-stopped.spec.ts` | diff --git a/docs/screenshots/README.zh-CN.md b/docs/screenshots/README.zh-CN.md new file mode 100644 index 0000000..6927310 --- /dev/null +++ b/docs/screenshots/README.zh-CN.md @@ -0,0 +1,9 @@ +[English](README.md) | 简体中文 + +# 演示截图 + +所有截图均使用 Playwright 的 1440 × 900 浅色视口。 + +| 文件 | 状态与代码版本 | 命令 | +| ------------------- | ----------------------------------------------------------------------------- | ---------------------------------------------------------- | +| `gate3-stopped.png` | 重现 Gate 3 崩溃的场景,`2b4843b` 加 Gate 3 崩溃修复前的提交 `a058409` 适配器 | `pnpm exec playwright test e2e/real-gate3-stopped.spec.ts` | diff --git a/docs/screenshots/gate3-stopped.png b/docs/screenshots/gate3-stopped.png new file mode 100644 index 0000000..dd2bd2d Binary files /dev/null and b/docs/screenshots/gate3-stopped.png differ diff --git a/e2e/entrance.spec.ts b/e2e/entrance.spec.ts new file mode 100644 index 0000000..fa3f9c2 --- /dev/null +++ b/e2e/entrance.spec.ts @@ -0,0 +1,13 @@ +import { test, expect } from '@playwright/test'; +import AxeBuilder from '@axe-core/playwright'; +test('fake gates scan through the page and meet axe checks', async ({ page }) => { + await page.goto('/'); + await expect(page.getByRole('heading', { name: 'Entrance control' })).toBeVisible(); + const lane = page.getByRole('region', { name: 'gate1 lane' }); + await expect(lane.getByText('Scanner: connected')).toBeVisible(); + await lane.getByLabel('Barcode').fill('GP-000000000000'); + await lane.getByRole('button', { name: 'Scan' }).click(); + await expect(lane.getByLabel('Green light on')).toBeVisible(); + const results = await new AxeBuilder({ page }).analyze(); + expect(results.violations).toEqual([]); +}); diff --git a/e2e/real-gate3-stopped.spec.ts b/e2e/real-gate3-stopped.spec.ts new file mode 100644 index 0000000..6e26006 --- /dev/null +++ b/e2e/real-gate3-stopped.spec.ts @@ -0,0 +1,74 @@ +type Gate = { id: string; scanner: boolean; outputs: boolean; netLed: string }; +type Event = { seq: number; gate: string; line: string }; +type Snapshot = { gates: Gate[]; events: Event[] }; +import { test, expect } from '@playwright/test'; +test('Gate 3 crash scenario', async ({ page }) => { + const snapshots: Snapshot[] = []; + page.on('websocket', (socket) => + socket.on('framereceived', (frame) => { + try { + const msg = JSON.parse(String(frame.payload)); + if (msg.type === 'snapshot') snapshots.push(msg); + } catch {} + }), + ); + await page.goto('/'); + await expect + .poll(() => snapshots.at(-1)?.gates.filter((g: Gate) => g.scanner && g.outputs).length) + .toBe(4); + for (let i = 1; i <= 4; i++) { + const lane = page.getByRole('region', { name: `gate${i} lane` }); + await lane.getByLabel('Barcode').fill(`GP-${String(i).padStart(12, '0')}`); + await lane.getByRole('button', { name: 'Scan' }).click(); + await expect + .poll(() => + snapshots + .at(-1) + ?.events.some((e: Event) => e.gate === `gate${i}` && e.line === 'LIGHT GREEN'), + ) + .toBe(true); + } + await page + .getByRole('region', { name: 'gate1 lane' }) + .getByLabel('Barcode') + .fill('GP-000000000001'); + await page + .getByRole('region', { name: 'gate1 lane' }) + .getByRole('button', { name: 'Scan' }) + .click(); + await expect + .poll(() => + snapshots.at(-1)?.events.some((e: Event) => e.gate === 'gate1' && e.line === 'LIGHT RED'), + ) + .toBe(true); + await page.getByRole('region', { name: 'gate3 lane' }).getByLabel('Barcode').fill('UNKNOWN'); + await page + .getByRole('region', { name: 'gate3 lane' }) + .getByRole('button', { name: 'Scan' }) + .click(); + await expect + .poll(() => snapshots.at(-1)?.gates.find((g: Gate) => g.id === 'gate3')?.scanner) + .toBe(false); + await expect + .poll(() => snapshots.at(-1)?.gates.find((g: Gate) => g.id === 'gate3')?.outputs) + .toBe(false); + await page + .getByRole('region', { name: 'gate4 lane' }) + .getByLabel('Barcode') + .fill('GP-000000000005'); + await page + .getByRole('region', { name: 'gate4 lane' }) + .getByRole('button', { name: 'Scan' }) + .click(); + await expect + .poll(() => + snapshots + .at(-1) + ?.events.some((e: Event) => e.gate === 'gate4' && e.line === 'SCAN GP-000000000005'), + ) + .toBe(true); + await page.screenshot({ path: 'docs/screenshots/gate3-stopped.png' }); + console.log( + 'gate3-stopped: four accepted; repeat rejected; Gate 3 down after UNKNOWN; Gate 4 still scanned', + ); +}); diff --git a/package.json b/package.json index 596c0bd..a9da6c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gatepost-sim", - "version": "0.1.0-dev", + "version": "0.1.0", "private": true, "type": "module", "engines": { diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..6d76fb4 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from '@playwright/test'; +export default defineConfig({ + testDir: 'e2e', + use: { + baseURL: 'http://127.0.0.1:28080', + viewport: { width: 1440, height: 900 }, + colorScheme: 'light', + }, + retries: 0, +}); diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..6dc7957 --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["config:recommended"], + "labels": ["dependencies"] +} diff --git a/scripts/e2e-gatepost.sh b/scripts/e2e-gatepost.sh new file mode 100755 index 0000000..03091d3 --- /dev/null +++ b/scripts/e2e-gatepost.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")/.." +case ${1:-} in + gate3-stopped) pnpm exec playwright test e2e/real-gate3-stopped.spec.ts ;; + *) echo 'Usage: e2e-gatepost.sh gate3-stopped (with the corresponding venue running)' >&2; exit 2 ;; +esac diff --git a/scripts/fake-gates.mjs b/scripts/fake-gates.mjs new file mode 100644 index 0000000..d44417c --- /dev/null +++ b/scripts/fake-gates.mjs @@ -0,0 +1,44 @@ +import net from 'node:net'; + +for (let i = 1; i <= 4; i++) { + const gate = `gate${i}`; + function connect() { + let pending = ''; + let retrying = false; + const retry = () => { + if (retrying) return; + retrying = true; + scanner.destroy(); + outputs.destroy(); + setTimeout(connect, 1000); + }; + const scanner = net.connect(7600, '127.0.0.1', () => + scanner.write(`HELLO ${gate} scanner 1\n`), + ); + const outputs = net.connect(7600, '127.0.0.1', () => + outputs.write(`HELLO ${gate} outputs 1\nLED NET ON\n`), + ); + scanner.on('error', retry); + outputs.on('error', retry); + scanner.on('close', retry); + outputs.on('close', retry); + scanner.on('data', (chunk) => { + pending += chunk; + let index; + while ((index = pending.indexOf('\n')) >= 0) { + const line = pending.slice(0, index); + pending = pending.slice(index + 1); + if (!line.startsWith('SCAN ')) continue; + const accepted = line.slice(5).startsWith('GP-'); + outputs.write(accepted ? 'LIGHT GREEN\nRELAY OPEN 2000\n' : 'LIGHT RED\n'); + setTimeout( + () => { + if (!outputs.destroyed) outputs.write('LIGHT OFF\n'); + }, + accepted ? 2000 : 1000, + ); + } + }); + } + connect(); +} diff --git a/scripts/gate3-crash-adapter.py b/scripts/gate3-crash-adapter.py new file mode 100644 index 0000000..cc4fe9b --- /dev/null +++ b/scripts/gate3-crash-adapter.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +"""Connect a pre-device-layer gate binary to the simulator for the historical crash demo.""" +import socket +import subprocess +import sys +import threading + +binary, tickets = sys.argv[1:] +scanner = socket.create_connection(('bridge', 7600)) +outputs = socket.create_connection(('bridge', 7600)) +scanner.sendall(b'HELLO gate3 scanner 1\n') +outputs.sendall(b'HELLO gate3 outputs 1\nLED NET OFF\n') +child = subprocess.Popen([binary, tickets], stdin=subprocess.PIPE, stdout=subprocess.PIPE) + +def dark(): + try: + outputs.sendall(b'LIGHT OFF\n') + except OSError: + pass + +with scanner.makefile('rb') as stream: + for line in stream: + if not line.startswith(b'SCAN '): + continue + child.stdin.write(line[5:]) + child.stdin.flush() + decision = child.stdout.readline() + if not decision: + break + if decision == b'ACCEPT\n': + outputs.sendall(b'LIGHT GREEN\nRELAY OPEN 2000\n') + threading.Timer(2, dark).start() + elif decision == b'REJECT\n': + outputs.sendall(b'LIGHT RED\n') + threading.Timer(1, dark).start() +child.wait() +print(f"Gate 3 crash scenario gated returncode={child.returncode}", file=sys.stderr, flush=True) +scanner.close() +outputs.close() +sys.exit(child.returncode) diff --git a/scripts/hub-proxy.py b/scripts/hub-proxy.py new file mode 100644 index 0000000..ea13adb --- /dev/null +++ b/scripts/hub-proxy.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +"""Expose the historical loopback-only hub to the standalone venue network.""" +import socket +import socketserver + +class Forward(socketserver.BaseRequestHandler): + def handle(self): + try: + with socket.create_connection(('127.0.0.1', 7000), timeout=1) as hub: + hub.settimeout(1) + data = b'' + while not data.endswith(b'\n') and len(data) <= 256: + part = self.request.recv(1) + if not part: + return + data += part + hub.sendall(data) + response = b'' + while not response.endswith(b'\n') and len(response) <= 256: + part = hub.recv(1) + if not part: + return + response += part + self.request.sendall(response) + except OSError as error: + print(f'hub proxy: {error}', flush=True) + +class Server(socketserver.ThreadingTCPServer): + allow_reuse_address = True + daemon_threads = True + +with Server(('0.0.0.0', 7001), Forward) as server: + server.serve_forever() diff --git a/scripts/venue.sh b/scripts/venue.sh new file mode 100755 index 0000000..ae5d118 --- /dev/null +++ b/scripts/venue.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")/.." +export SIM_DIR=$(pwd) +export DOCKER_CONFIG=${DOCKER_CONFIG:-${TMPDIR:-/tmp}/gatepost-sim-docker-cli} +export DOCKER_HOST=${DOCKER_HOST:-unix:///var/run/docker.sock} +mkdir -p "$DOCKER_CONFIG" +[[ -f "$DOCKER_CONFIG/config.json" ]] || printf "{}\n" > "$DOCKER_CONFIG/config.json" +action=${1:-status}; shift || true +mode=devices; ref=; gate3_crash_dir=; source_dir=${GATEPOST_DIR:-../gatepost} +while (($#)); do + case "$1" in + --gatepost) source_dir=$2; shift 2;; + --ref) ref=$2; shift 2;; + --gate3-crash) gate3_crash_dir=$2; shift 2;; + --mode) mode=$2; shift 2;; + *) echo "Unknown option: $1" >&2; exit 2;; + esac +done +state=.venue-state +if [[ $action == up ]]; then + [[ $mode == devices ]] || { echo 'Invalid mode' >&2; exit 2; } + [[ ! -e $state ]] || { echo 'Run down first' >&2; exit 1; } + source_dir=$(cd "$source_dir" && pwd) + worktree= + if [[ -n $ref ]]; then + worktree=$(mktemp -d "${TMPDIR:-/tmp}/gatepost-sim.XXXXXXXX") + git -C "$source_dir" worktree add --detach "$worktree" "$ref" + gatepost_dir=$worktree + else gatepost_dir=$source_dir; fi + export GATEPOST_DIR=$gatepost_dir DOCKER_GID=$(stat -f %g /var/run/docker.sock 2>/dev/null || stat -c %g /var/run/docker.sock) SIM_PORT=${SIM_PORT:-28080} + project=gatepost-sim-devices + if [[ -n $gate3_crash_dir ]]; then gate3_crash_dir=$(cd "$gate3_crash_dir" && pwd); fi + printf '%s\n%s\n%s\n%s\n%s\n%s\n' "$source_dir" "$worktree" "$gatepost_dir" "$mode" "$SIM_PORT" "$gate3_crash_dir" > "$state" + docker build -t gatepost-build:local -f "$gatepost_dir/Dockerfile.build" "$gatepost_dir" + docker run --rm -v "$gatepost_dir:/src" gatepost-build:local sh -c 'cmake --preset debug && cmake --build --preset debug -j 4' + hub_args=(); [[ -x "$gatepost_dir/build/debug/gate-hub" ]] && hub_args=(--profile hub) + files=(-f compose.devices.yaml) + if [[ -n $gate3_crash_dir ]]; then export GATE3_CRASH_DIR=$gate3_crash_dir; files+=(-f compose.gate3-crash.yaml); fi + docker compose -p "$project" "${files[@]}" "${hub_args[@]}" up -d --build + echo "Simulator: http://127.0.0.1:$SIM_PORT" +elif [[ $action == down || $action == status ]]; then + [[ -e $state ]] || { echo 'No venue state'; exit 0; } + source_dir=$(sed -n "1p" "$state");worktree=$(sed -n "2p" "$state");gatepost_dir=$(sed -n "3p" "$state");mode=$(sed -n "4p" "$state");SIM_PORT=$(sed -n "5p" "$state");gate3_crash_dir=$(sed -n "6p" "$state") + export GATEPOST_DIR=$gatepost_dir SIM_PORT DOCKER_GID=$(stat -f %g /var/run/docker.sock 2>/dev/null || stat -c %g /var/run/docker.sock) + project=gatepost-sim-devices + files=(-f compose.devices.yaml);if [[ -n $gate3_crash_dir ]];then export GATE3_CRASH_DIR=$gate3_crash_dir;files+=(-f compose.gate3-crash.yaml);fi + if [[ $action == down ]]; then + docker compose -p "$project" "${files[@]}" --profile hub down -v + if [[ -n $worktree ]];then git -C "$source_dir" worktree remove --force "$worktree";fi + rm "$state" + else docker compose -p "$project" "${files[@]}" ps; fi +else echo 'Usage: venue.sh up|down|status [--gatepost DIR] [--ref REF] [--mode devices] [--gate3-crash DIR]' >&2; exit 2;fi diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..bf7c1d9 --- /dev/null +++ b/web/index.html @@ -0,0 +1,12 @@ + + + + + + Gatepost entrance simulator + + +
+ + + diff --git a/web/package.json b/web/package.json new file mode 100644 index 0000000..b78393d --- /dev/null +++ b/web/package.json @@ -0,0 +1,25 @@ +{ + "name": "@gatepost-sim/web", + "version": "0.1.0", + "private": true, + "type": "module", + "scripts": { + "build": "tsc -b && vite build", + "test": "vitest run", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "react": "19.3.1", + "react-dom": "19.3.1" + }, + "devDependencies": { + "@vitejs/plugin-react": "6.1.2", + "@testing-library/react": "16.3.3", + "@testing-library/jest-dom": "7.0.1", + "@types/react": "19.3.0", + "@types/react-dom": "19.3.0", + "jsdom": "30.1.3", + "vite": "8.3.5", + "vitest": "5.0.5" + } +} diff --git a/web/src/main.tsx b/web/src/main.tsx new file mode 100644 index 0000000..7826eba --- /dev/null +++ b/web/src/main.tsx @@ -0,0 +1,268 @@ +import React, { useEffect, useState } from 'react'; +import { createRoot } from 'react-dom/client'; +import './style.css'; +type Gate = { + id: string; + scanner: boolean; + outputs: boolean; + powered: boolean; + network: boolean; + light: 'GREEN' | 'RED' | 'OFF'; + netLed: 'ON' | 'OFF'; + relayUntil: number; +}; +type Entry = { at: string; gate: string; direction: string; line: string }; +type Snapshot = { gates: Gate[]; events: Entry[]; tickets: string[] }; +export function Lane({ gate, send }: { gate: Gate; send: (message: object) => void }) { + const [barcode, setBarcode] = useState(''); + const open = gate.relayUntil > Date.now(); + return ( +
+
+

{gate.id.toUpperCase()}

+ + {gate.powered ? (gate.scanner || gate.outputs ? 'Powered' : 'Stopped') : 'Power off'} + +
+
+ Scanner: {gate.scanner ? 'connected' : 'down'} + Outputs: {gate.outputs ? 'connected' : 'down'} +
+
+
+ + + +
+ +
+
{ + e.preventDefault(); + send({ type: 'scan', gate: gate.id, barcode }); + setBarcode(''); + }} + > + +
+ setBarcode(e.target.value)} + placeholder="GP-000000000000" + /> + +
+
+
+ + +
+
+ ); +} +export function App() { + const [state, setState] = useState({ gates: [], events: [], tickets: [] }); + const [connected, setConnected] = useState(false); + const [filter, setFilter] = useState('all'); + const [barcode, setBarcode] = useState(''); + const [count, setCount] = useState(10); + const [rate, setRate] = useState(5); + const [error, setError] = useState(''); + const [socket, setSocket] = useState(null); + useEffect(() => { + let active = true; + let ws: WebSocket; + function connect() { + ws = new WebSocket(`ws://${location.host}/ws`); + ws.onopen = () => { + setSocket(ws); + setConnected(true); + }; + ws.onclose = () => { + setConnected(false); + if (active) setTimeout(connect, 1000); + }; + ws.onmessage = (e) => { + const message = JSON.parse(e.data); + if (message.type === 'snapshot') setState(message); + if (message.type === 'error') setError(message.message); + }; + } + connect(); + return () => { + active = false; + ws?.close(); + }; + }, []); + const send = (message: object) => { + setError(''); + socket?.send(JSON.stringify(message)); + }; + return ( +
+
+
+

ELSWORNE · VENUE LAB

+

Entrance control

+

+ A live view of the scanner, turnstile, lights and network at each gate. +

+
+ + Bridge {connected ? 'connected' : 'disconnected'} + +
+
+
+
+

Gate lanes

+ + {state.gates.filter((g) => g.scanner && g.outputs).length} / {state.gates.length}{' '} + devices connected + +
+
+ {state.gates.map((g) => ( + + ))} +
+
+

Scenario controls

+
+ + setBarcode(e.target.value)} + placeholder="GP-000000000001" + /> + + + +
+
+ + setCount(Number(e.target.value))} + /> + + setRate(Number(e.target.value))} + /> + +
+ {error && ( +

+ {error} +

+ )} +
+
+ +
+
+ ); +} +if (document.getElementById('root')) + createRoot(document.getElementById('root')!).render( + + + , + ); diff --git a/web/src/style.css b/web/src/style.css new file mode 100644 index 0000000..651dae3 --- /dev/null +++ b/web/src/style.css @@ -0,0 +1,336 @@ +:root { + font-family: Inter, ui-sans-serif, system-ui, sans-serif; + color: #173041; + background: #f5f8f9; +} +* { + box-sizing: border-box; +} +body { + margin: 0; +} +button, +input, +select { + font: inherit; +} +button { + cursor: pointer; + border: 1px solid #acc5ce; + background: #fff; + color: #153b4c; + border-radius: 7px; + padding: 9px 12px; + font-weight: 600; +} +button:hover:not(:disabled) { + background: #e8f5f5; +} +button:disabled { + opacity: 0.52; + cursor: not-allowed; +} +:focus-visible { + outline: 3px solid #0866a2; + outline-offset: 3px; +} +main { + max-width: 1500px; + margin: auto; + padding: 30px 32px; +} +.top { + display: flex; + align-items: center; + justify-content: space-between; + margin-bottom: 34px; +} +.eyebrow { + font-size: 12px; + font-weight: 800; + letter-spacing: 0.16em; + color: #08777d; +} +.top h1 { + font-size: 38px; + margin: 4px 0; +} +.intro { + color: #506875; + margin: 0; +} +.bridge-state { + background: #fce6e0; + color: #8a2417; + border-radius: 100px; + padding: 10px 16px; + font-weight: 700; +} +.bridge-state.online { + background: #d9f3e9; + color: #086447; +} +.layout { + display: grid; + grid-template-columns: minmax(0, 1fr) 330px; + gap: 24px; +} +.section-head { + display: flex; + justify-content: space-between; + align-items: center; +} +.section-head h2 { + font-size: 20px; +} +.section-head span { + color: #516c78; +} +.lanes { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 16px; +} +.lane, +.panel { + background: #fff; + border: 1px solid #d8e4e8; + border-radius: 14px; + box-shadow: 0 2px 10px #193b4a0a; +} +.lane { + padding: 17px; +} +.lane header { + display: flex; + justify-content: space-between; + align-items: center; +} +.lane h2 { + font-size: 17px; + letter-spacing: 0.07em; + margin: 0; +} +.status { + font-size: 12px; + color: #376779; + background: #eaf3f5; + padding: 5px 9px; + border-radius: 50px; +} +.device-status { + display: flex; + gap: 15px; + font-size: 12px; + color: #526a75; + margin: 13px 0; +} +.scene { + height: 139px; + border: 1px solid #dfebed; + border-radius: 10px; + background: linear-gradient(#eaf3f5, #f5f8f8); + display: flex; + align-items: center; + justify-content: space-around; + margin-bottom: 15px; +} +.lights { + display: flex; + flex-direction: column; + gap: 9px; + background: #244254; + padding: 10px; + border-radius: 13px; +} +.bulb { + height: 19px; + width: 19px; + border-radius: 50%; + display: block; + opacity: 0.25; +} +.green { + background: #1eca68; +} +.red { + background: #ff5547; +} +.blue { + background: #42b4f6; +} +.bulb.lit { + opacity: 1; + box-shadow: 0 0 14px currentColor; +} +.turnstile { + height: 92px; + width: 150px; + border: 2px solid #8aa9b8; + background: #e9f0f3; + position: relative; + overflow: hidden; +} +.turnstile.open { + border-color: #16a579; + background: #e2f8ee; +} +.arm { + display: block; + height: 5px; + width: 85px; + background: #607d8c; + position: absolute; + top: 25px; + left: 30px; + transform: rotate(-27deg); + transition: transform 0.3s; +} +.turnstile.open .arm { + transform: rotate(50deg); +} +.lane label { + font-size: 13px; + font-weight: 700; + display: block; + margin-bottom: 5px; +} +.scan-field { + display: flex; + gap: 7px; +} +.scan-field input { + min-width: 0; + flex: 1; +} +.lane input, +.scenarios input, +select { + border: 1px solid #b8cdd5; + border-radius: 7px; + padding: 9px; + background: #fff; + color: #173041; +} +.controls { + display: flex; + gap: 8px; + margin-top: 12px; +} +.controls button { + font-size: 12px; + flex: 1; +} +.panel { + padding: 19px; + margin-top: 16px; +} +.panel h2 { + font-size: 17px; + margin: 0 0 11px; +} +.tickets { + margin-top: 0; +} +.tickets p { + font-size: 13px; + color: #596e78; +} +.ticket-list { + display: grid; + gap: 7px; +} +.ticket-list button { + text-align: left; + font-size: 12px; + font-family: ui-monospace, monospace; + padding: 7px; +} +.event-head { + display: flex; + align-items: center; + gap: 8px; +} +.event-head h2 { + margin-right: auto; +} +.event-head label { + font-size: 12px; +} +.event-head select { + max-width: 100px; +} +.events { + list-style: none; + padding: 0; + margin: 8px 0; + max-height: 410px; + overflow: auto; +} +.events li { + border-bottom: 1px solid #e7eff1; + padding: 7px 0; + display: flex; + flex-wrap: wrap; + gap: 5px; + font-size: 11px; +} +.events time { + color: #5d7580; +} +.events code { + width: 100%; + color: #233e4b; +} +.scenario-row { + display: flex; + align-items: center; + gap: 8px; + flex-wrap: wrap; + margin-top: 10px; +} +.scenario-row label { + font-size: 13px; + font-weight: 700; +} +.scenario-row input { + width: 160px; +} +.scenario-row input[type='number'] { + width: 75px; +} +.scenario-row button { + font-size: 12px; +} +.error { + color: #a12820; +} +@media (max-width: 1100px) { + .layout { + grid-template-columns: 1fr; + } + aside { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 16px; + } + .event-panel { + margin-top: 0; + } +} +@media (max-width: 650px) { + main { + padding: 18px; + } + .lanes, + aside { + grid-template-columns: 1fr; + } + .top { + align-items: flex-start; + gap: 10px; + } + .top h1 { + font-size: 29px; + } +} diff --git a/web/test/lane.test.tsx b/web/test/lane.test.tsx new file mode 100644 index 0000000..f8eace9 --- /dev/null +++ b/web/test/lane.test.tsx @@ -0,0 +1,25 @@ +import { it, expect, vi } from 'vitest'; +import { render, screen, fireEvent } from '@testing-library/react'; +import { Lane } from '../src/main'; +it('scans with Enter and shows device state', () => { + const send = vi.fn(); + render( + , + ); + expect(screen.getByLabelText('Green light on')).toBeTruthy(); + fireEvent.change(screen.getByLabelText('Barcode'), { target: { value: 'GP-000000000000' } }); + fireEvent.submit(screen.getByLabelText('Barcode').closest('form')!); + expect(send).toHaveBeenCalledWith({ type: 'scan', gate: 'gate1', barcode: 'GP-000000000000' }); +}); diff --git a/web/tsconfig.json b/web/tsconfig.json new file mode 100644 index 0000000..3d659a7 --- /dev/null +++ b/web/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "target": "ES2022", + "useDefineForClassFields": true, + "lib": ["ES2022", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true + }, + "include": ["src", "test"] +} diff --git a/web/vite.config.ts b/web/vite.config.ts new file mode 100644 index 0000000..5825d65 --- /dev/null +++ b/web/vite.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react'; +export default defineConfig({ + plugins: [react()], + server: { + host: '127.0.0.1', + port: 28082, + proxy: { '/ws': { target: 'http://127.0.0.1:28080', ws: true } }, + }, +}); diff --git a/web/vitest.config.ts b/web/vitest.config.ts new file mode 100644 index 0000000..939595a --- /dev/null +++ b/web/vitest.config.ts @@ -0,0 +1,2 @@ +import { defineConfig } from 'vitest/config'; +export default defineConfig({ test: { environment: 'jsdom' } });