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/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/bridge/package.json b/bridge/package.json new file mode 100644 index 0000000..f13c22e --- /dev/null +++ b/bridge/package.json @@ -0,0 +1,19 @@ +{ + "name": "@gatepost-sim/bridge", + "version": "0.1.0-dev", + "private": true, + "type": "module", + "scripts": { + "build": "tsc", + "test": "vitest run", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "ws": "8.18.3" + }, + "devDependencies": { + "@types/node": "26.6.6", + "@types/ws": "8.18.1", + "vitest": "5.0.5" + } +} diff --git a/bridge/src/docker.ts b/bridge/src/docker.ts new file mode 100644 index 0000000..966859b --- /dev/null +++ b/bridge/src/docker.ts @@ -0,0 +1,105 @@ +import http from 'node:http'; +const project = process.env.COMPOSE_PROJECT_NAME || 'gatepost-sim-devices'; +const services = (process.env.GATE_SERVICES || 'gate1,gate2,gate3,gate4').split(','); +const venueNetwork = process.env.VENUE_NETWORK || `${project}_venue`; +const socketPath = process.env.DOCKER_SOCKET || '/var/run/docker.sock'; +export function allowed(labels: Record, id: string) { + return ( + labels['com.docker.compose.project'] === project && + services.includes(labels['com.docker.compose.service']) && + labels['com.docker.compose.service'] === id + ); +} +export function request( + method: string, + path: string, + body?: unknown, +): Promise<{ status: number; data: unknown }> { + return new Promise((resolve, reject) => { + const payload = body === undefined ? undefined : JSON.stringify(body); + const req = http.request( + { + socketPath, + path, + method, + headers: payload + ? { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) } + : {}, + }, + (res) => { + let raw = ''; + res.on('data', (chunk) => (raw += chunk)); + res.on('end', () => { + let data: unknown = raw; + try { + data = JSON.parse(raw); + } catch {} + resolve({ status: res.statusCode || 0, data }); + }); + }, + ); + req.on('error', reject); + req.end(payload); + }); +} +async function checked(method: string, path: string, body?: unknown) { + const result = await request(method, path, body); + if (result.status >= 300) + throw new Error(`Docker ${method} ${path}: ${result.status} ${JSON.stringify(result.data)}`); + return result.data; +} +type Container = { + Id: string; + Config: { Labels: Record }; + NetworkSettings: { + Networks: Record< + string, + { + IPAMConfig?: { IPv4Address?: string; IPv6Address?: string } | null; + IPAddress?: string; + GlobalIPv6Address?: string; + MacAddress?: string; + Aliases?: string[]; + } + >; + }; +}; +export async function action(id: string, kind: 'power' | 'network', on: boolean) { + if (!services.includes(id)) throw new Error('Service not allowed'); + const list = (await checked( + 'GET', + `/containers/json?all=1&filters=${encodeURIComponent(JSON.stringify({ label: [`com.docker.compose.project=${project}`, `com.docker.compose.service=${id}`] }))}`, + )) as { Id: string }[]; + if (list.length !== 1) throw new Error(`Expected one container for ${id}, found ${list.length}`); + const container = (await checked('GET', `/containers/${list[0].Id}/json`)) as Container; + if (!allowed(container.Config.Labels || {}, id)) throw new Error('Container labels refused'); + const cid = container.Id; + if (kind === 'power') await checked('POST', `/containers/${cid}/${on ? 'start' : 'kill'}`); + else { + const network = container.NetworkSettings.Networks[venueNetwork]; + if (on) { + if (network) return; + const saved = networkSettings.get(cid); + if (!saved) throw new Error('Original network settings unavailable'); + await checked('POST', `/networks/${encodeURIComponent(venueNetwork)}/connect`, { + Container: cid, + EndpointConfig: saved, + }); + } else { + if (!network) return; + networkSettings.set(cid, { + IPAMConfig: network.IPAMConfig ?? { + IPv4Address: network.IPAddress, + IPv6Address: network.GlobalIPv6Address, + }, + MacAddress: network.MacAddress, + Aliases: network.Aliases, + }); + await checked('POST', `/networks/${encodeURIComponent(venueNetwork)}/disconnect`, { + Container: cid, + Force: false, + }); + } + } +} +const networkSettings = new Map(); diff --git a/bridge/src/protocol.ts b/bridge/src/protocol.ts new file mode 100644 index 0000000..e0dc803 --- /dev/null +++ b/bridge/src/protocol.ts @@ -0,0 +1,48 @@ +export type Role = 'scanner' | 'outputs'; +export type Output = + | { kind: 'light'; value: 'GREEN' | 'RED' | 'OFF' } + | { kind: 'relay'; ms: number } + | { kind: 'net'; value: 'ON' | 'OFF' }; +export function hello(line: string): { gate: string; role: Role } | null { + const match = /^HELLO ([!-~]{1,63}) (scanner|outputs) 1$/.exec(line); + return match && !/\s/.test(match[1]) ? { gate: match[1], role: match[2] as Role } : null; +} +export function output(line: string): Output | null { + if (line === 'LIGHT GREEN' || line === 'LIGHT RED' || line === 'LIGHT OFF') + return { kind: 'light', value: line.slice(6) as 'GREEN' | 'RED' | 'OFF' }; + if (line === 'LED NET ON' || line === 'LED NET OFF') + return { kind: 'net', value: line.slice(8) as 'ON' | 'OFF' }; + const relay = /^RELAY OPEN (0|[1-9][0-9]*)$/.exec(line); + if (relay && Number.isSafeInteger(Number(relay[1])) && Number(relay[1]) > 0) + return { kind: 'relay', ms: Number(relay[1]) }; + return null; +} +export class Lines { + private pending = ''; + private dropping = false; + feed(chunk: Buffer, onLine: (line: string) => void, onInvalid: (reason: string) => void) { + for (const byte of chunk) { + if (byte === 10) { + if (this.dropping) onInvalid('overlong line'); + else if (/^[\x20-\x7e]*$/.test(this.pending)) onLine(this.pending); + else onInvalid('non-ASCII or malformed line'); + this.pending = ''; + this.dropping = false; + } else if (!this.dropping) { + if (byte < 32 || byte > 126) { + this.dropping = true; + continue; + } + if (this.pending.length >= 255) { + this.dropping = true; + continue; + } + this.pending += String.fromCharCode(byte); + } + } + } +} +export function scanLine(barcode: string) { + if (!/^[!-~]{1,63}$/.test(barcode) || /\s/.test(barcode)) throw new Error('Invalid barcode'); + return `SCAN ${barcode}\n`; +} diff --git a/bridge/src/server.ts b/bridge/src/server.ts new file mode 100644 index 0000000..99aeaf0 --- /dev/null +++ b/bridge/src/server.ts @@ -0,0 +1,133 @@ +import net from 'node:net'; +import http from 'node:http'; +import fs from 'node:fs'; +import path from 'node:path'; +import { WebSocketServer, WebSocket } from 'ws'; +import { hello, Lines } from './protocol.js'; +import { Model } from './state.js'; +import { action } from './docker.js'; +const port = Number(process.env.PORT || 8080), + devicePort = Number(process.env.DEVICE_PORT || 7600); +const webRoot = process.env.WEB_ROOT || path.resolve('web/dist'); +const tickets = ( + process.env.TICKET_FILE && fs.existsSync(process.env.TICKET_FILE) + ? fs.readFileSync(process.env.TICKET_FILE, 'utf8') + : '' +) + .split(/\r?\n/) + .filter(Boolean); +const gateIds = (process.env.GATE_SERVICES || 'gate1,gate2,gate3,gate4').split(','); +const clients = new Set(); +const model = new Model( + () => { + const data = JSON.stringify({ type: 'snapshot', ...model.snapshot(), tickets }); + for (const ws of clients) if (ws.readyState === WebSocket.OPEN) ws.send(data); + }, + Number(process.env.AUTO_PASS_MS || 0), +); +for (const id of gateIds) model.gate(id); +net + .createServer((socket) => { + const lines = new Lines(); + let identity: ReturnType = null; + socket.on('data', (chunk) => + lines.feed( + Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk), + (line) => { + if (!identity) { + const parsed = hello(line); + if (!parsed || !gateIds.includes(parsed.gate)) { + model.log('?', 'ignored', line); + socket.destroy(); + return; + } + identity = parsed; + model.attach(parsed.gate, parsed.role, socket); + model.log(parsed.gate, 'received', line); + return; + } + if (identity.role === 'outputs') model.receive(identity.gate, line); + else model.log(identity.gate, 'ignored', line); + }, + (reason) => model.log(identity?.gate || '?', 'ignored', reason), + ), + ); + socket.on('close', () => { + if (identity) model.detach(identity.gate, identity.role, socket); + }); + }) + .listen(devicePort, '0.0.0.0'); +const types: Record = { + '.html': 'text/html', + '.js': 'text/javascript', + '.css': 'text/css', + '.svg': 'image/svg+xml', +}; +const server = http.createServer((req, res) => { + if (req.url === '/health') { + res.writeHead(200, { 'Content-Type': 'application/json' }).end(JSON.stringify({ ok: true })); + return; + } + const name = req.url === '/' ? '/index.html' : decodeURIComponent((req.url || '').split('?')[0]); + const file = path.resolve(webRoot, '.' + name); + if (!file.startsWith(path.resolve(webRoot) + path.sep)) { + res.writeHead(403).end(); + return; + } + fs.readFile(file, (error, data) => { + if (error) { + res.writeHead(404).end(); + return; + } + res + .writeHead(200, { 'Content-Type': types[path.extname(file)] || 'application/octet-stream' }) + .end(data); + }); +}); +const wss = new WebSocketServer({ server, path: '/ws' }); +wss.on('connection', (ws) => { + clients.add(ws); + ws.send(JSON.stringify({ type: 'snapshot', ...model.snapshot(), tickets })); + ws.on('close', () => clients.delete(ws)); + ws.on('message', async (raw) => { + try { + const msg = JSON.parse(raw.toString()); + if (msg.type === 'scan' && typeof msg.gate === 'string' && typeof msg.barcode === 'string') + model.scan(msg.gate, msg.barcode); + else if ( + msg.type === 'simultaneous' && + Array.isArray(msg.gates) && + typeof msg.barcode === 'string' + ) { + for (const id of msg.gates) model.scan(id, msg.barcode); + } else if ( + msg.type === 'burst' && + Number.isInteger(msg.count) && + msg.count > 0 && + msg.count <= 200 && + Number.isInteger(msg.intervalMs) && + msg.intervalMs >= 0 && + msg.intervalMs <= 5000 + ) { + for (let i = 0; i < msg.count; i++) + setTimeout(() => { + try { + model.scan(gateIds[i % gateIds.length], tickets[i % tickets.length]); + } catch {} + }, i * msg.intervalMs); + } else if (msg.type === 'pass' && typeof msg.gate === 'string') model.pass(msg.gate); + else if ( + (msg.type === 'power' || msg.type === 'network') && + typeof msg.gate === 'string' && + typeof msg.on === 'boolean' + ) { + await action(msg.gate, msg.type, msg.on); + if (msg.type === 'power') model.setPower(msg.gate, msg.on); + else model.setNetwork(msg.gate, msg.on); + } else throw new Error('Invalid message'); + } catch (error) { + ws.send(JSON.stringify({ type: 'error', message: String(error) })); + } + }); +}); +server.listen(port, '0.0.0.0'); diff --git a/bridge/src/state.ts b/bridge/src/state.ts new file mode 100644 index 0000000..8ff1965 --- /dev/null +++ b/bridge/src/state.ts @@ -0,0 +1,126 @@ +import type { Socket } from 'node:net'; +import { output, scanLine, type Role } from './protocol.js'; +export type Gate = { + id: string; + scanner: boolean; + outputs: boolean; + powered: boolean; + network: boolean; + light: 'GREEN' | 'RED' | 'OFF'; + netLed: 'ON' | 'OFF'; + relayUntil: number; +}; +export type Event = { seq: number; at: string; gate: string; direction: string; line: string }; +export class Model { + gates = new Map(); + sockets = new Map(); + events: Event[] = []; + private sequence = 0; + constructor( + public publish: () => void, + public autoPassMs: number = 0, + ) {} + gate(id: string) { + let g = this.gates.get(id); + if (!g) { + g = { + id, + scanner: false, + outputs: false, + powered: true, + network: true, + light: 'OFF', + netLed: 'OFF', + relayUntil: 0, + }; + this.gates.set(id, g); + } + return g; + } + log(gate: string, direction: string, line: string) { + this.events.push({ seq: ++this.sequence, at: new Date().toISOString(), gate, direction, line }); + if (this.events.length > 500) this.events.shift(); + this.publish(); + } + attach(id: string, role: Role, socket: Socket) { + const key = `${id}:${role}`; + this.sockets.get(key)?.destroy(); + this.sockets.set(key, socket); + const g = this.gate(id); + g[role] = true; + g.powered = true; + this.publish(); + } + detach(id: string, role: Role, socket: Socket) { + const key = `${id}:${role}`; + if (this.sockets.get(key) !== socket) return; + this.sockets.delete(key); + const g = this.gate(id); + g[role] = false; + if (role === 'outputs') { + g.light = 'OFF'; + g.netLed = 'OFF'; + g.relayUntil = 0; + } + this.publish(); + } + receive(id: string, line: string) { + const g = this.gate(id); + const parsed = output(line); + this.log(id, 'received', line); + if (!parsed) { + this.log(id, 'ignored', line); + return; + } + if (parsed.kind === 'light') g.light = parsed.value; + else if (parsed.kind === 'net') g.netLed = parsed.value; + else { + g.relayUntil = Date.now() + parsed.ms; + setTimeout(() => { + if (g.relayUntil <= Date.now()) { + g.relayUntil = 0; + this.publish(); + } + }, parsed.ms + 5); + if (this.autoPassMs > 0) + setTimeout(() => { + if (g.relayUntil > Date.now()) this.pass(id); + }, this.autoPassMs); + } + this.publish(); + } + scan(id: string, barcode: string) { + const socket = this.sockets.get(`${id}:scanner`); + if (!socket || socket.destroyed) throw new Error(`${id} scanner disconnected`); + const line = scanLine(barcode); + socket.write(line); + this.log(id, 'sent', line.trimEnd()); + } + pass(id: string) { + const g = this.gate(id); + if (g.relayUntil <= Date.now()) throw new Error('Turnstile locked'); + const socket = this.sockets.get(`${id}:outputs`); + if (!socket || socket.destroyed) throw new Error('Outputs disconnected'); + socket.write('PASSED\n'); + g.relayUntil = 0; + this.log(id, 'sent', 'PASSED'); + this.publish(); + } + snapshot() { + return { gates: [...this.gates.values()], events: this.events }; + } + setPower(id: string, powered: boolean) { + const g = this.gate(id); + g.powered = powered; + if (!powered) { + g.light = 'OFF'; + g.netLed = 'OFF'; + g.relayUntil = 0; + } + this.publish(); + } + setNetwork(id: string, network: boolean) { + this.gate(id).network = network; + this.publish(); + } +} 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/bridge/tsconfig.json b/bridge/tsconfig.json new file mode 100644 index 0000000..fcd4f2b --- /dev/null +++ b/bridge/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "strict": true, + "outDir": "dist", + "rootDir": "src", + "types": ["node"], + "esModuleInterop": true + }, + "include": ["src"] +} 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/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/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..4205450 --- /dev/null +++ b/web/package.json @@ -0,0 +1,25 @@ +{ + "name": "@gatepost-sim/web", + "version": "0.1.0-dev", + "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' } });