// Сценарии спеки deploy (TPTIP-6): сервер стенда и отсутствие страницы-заглушки. const test = require('node:test'); const assert = require('node:assert'); const fs = require('node:fs'); const os = require('node:os'); const path = require('node:path'); const ROOT = path.join(__dirname, '..'); async function withServer(dir, fn) { process.env.APP_DIR = dir; delete require.cache[require.resolve('../server.js')]; const { createServer } = require('../server.js'); const srv = createServer().listen(0); await new Promise((r) => srv.once('listening', r)); try { await fn(`http://127.0.0.1:${srv.address().port}`); } finally { srv.close(); delete process.env.APP_DIR; } } function tmpDir(files) { const d = fs.mkdtempSync(path.join(os.tmpdir(), 'tptip6-')); for (const [name, body] of Object.entries(files)) fs.writeFileSync(path.join(d, name), body); return d; } test('Сервер жив: GET /healthz → 200 «ok»', () => withServer(ROOT, async (base) => { const r = await fetch(base + '/healthz'); assert.strictEqual(r.status, 200); assert.strictEqual(await r.text(), 'ok'); })); test('Неизвестный адрес: служебные файлы не отдаются (404)', () => withServer(ROOT, async (base) => { for (const p of ['/.peppa/project.json', '/server.js', '/../AGENTS.md']) { assert.strictEqual((await fetch(base + p)).status, 404, p); } })); test('Приложение есть: «/» отдаёт index.html', () => withServer(tmpDir({ 'index.html': '