← back to Dw Domain Fleet

scripts/fixtures/grid-fixture.js

32 lines

#!/usr/bin/env node
/**
 * grid-fixture.js — a deliberately broken (or deliberately healthy) stand-in for
 * a fleet site, so scripts/test-assert-grids.sh can prove the deploy grid gate
 * actually goes red. TEST-ONLY. Never referenced by server.js or any deploy path.
 *
 * MODE=empty-pool  | /health serving:0, /catalog with 0 cards  (the TK-11463 outage)
 * MODE=empty-grid  | /health serving:11242, /catalog with 0 cards
 * MODE=no-contract | /health 200 but no `serving` field
 * MODE=healthy     | /health serving:11242, /catalog with 60 cards
 */
const http = require('http');
const MODE = process.env.MODE || 'healthy';
const PORT = Number(process.env.PORT || 0);

const CARD = '<div class="card" data-handle="x" data-sku="DW-1" data-price="10.00"></div>';
const shell = (n) => `<!doctype html><html><body><div class="grid" id="grid">${CARD.repeat(n)}</div></body></html>`;

const cfg = {
  'empty-pool':  { health: { ok: true, site: 'fixture', serving: 0,     niche: 0 },     cards: 0  },
  'empty-grid':  { health: { ok: true, site: 'fixture', serving: 11242, niche: 11242 }, cards: 0  },
  'no-contract': { health: { ok: true, site: 'fixture' },                                cards: 60 },
  'healthy':     { health: { ok: true, site: 'fixture', serving: 11242, niche: 11242 }, cards: 60 },
}[MODE];
if (!cfg) { console.error('unknown MODE ' + MODE); process.exit(2); }

http.createServer((req, res) => {
  if (req.url.startsWith('/health'))  { res.writeHead(200, { 'Content-Type': 'application/json' }); return res.end(JSON.stringify(cfg.health)); }
  if (req.url.startsWith('/catalog')) { res.writeHead(200, { 'Content-Type': 'text/html' });        return res.end(shell(cfg.cards)); }
  res.writeHead(404); res.end();
}).listen(PORT, '127.0.0.1', () => process.stderr.write('fixture ' + MODE + ' on ' + PORT + '\n'));