'use strict'; /** * DC-058 share preview page static-analysis test. * * Validates the static contract of status/share/index.html: * 1. parses cleanly (no malformed HTML/CSS/JS) * 2. exposes the expected public endpoints (preview fetch + subscribe POST) * 3. does NOT call the redeem-tailscale endpoint from the client (the * redemption flow lives on Caddy, not the browser — see the * server-side handler at routes/share.js) * 4. extracts the share token from the URL path * 5. shows the right CTA copy for public vs Tailscale shares * * This is a regression guard for the "fake Tailscale redemption" bug codex * flagged in the first review pass: an earlier version of the page POSTed * a random deviceId to /redeem-tailscale, which silently consumed the * one-shot share and broke the legitimate Tailscale join. * * Source path resolution: the standard location is `status/share/index.html`. * The judge-artifact.sh wrapper sometimes copies the file into a flat * worktree with a numeric prefix (e.g. `3_index.html`), so we fall back * to a directory scan. */ const fs = require('fs'); const path = require('path'); const vm = require('vm'); const test = require('node:test'); const assert = require('node:assert/strict'); function findTarget(name) { const candidates = [ path.join(__dirname, '..', 'share', 'index.html'), path.join(__dirname, 'share', 'index.html'), path.join(__dirname, 'index.html'), ]; for (const p of candidates) { try { if (fs.statSync(p).isFile()) return p; } catch (_) { /* keep looking */ } } const dir = __dirname; let entries = []; try { entries = fs.readdirSync(dir); } catch (_) { return null; } const match = entries.find(e => e === name || e.endsWith('_' + name) || e.endsWith('-' + name)); return match ? path.join(dir, match) : null; } const SHARE_PAGE_PATH = findTarget('index.html'); if (!SHARE_PAGE_PATH) { throw new Error( 'Cannot find share/index.html. Searched standard paths + directory scan of ' + __dirname + '. If running under judge-artifact.sh, ensure the wrapper ' + 'passed the file via --files.' ); } let pageHtml; let pageSource; function loadPage() { pageHtml = fs.readFileSync(SHARE_PAGE_PATH, 'utf8'); const scriptMatch = pageHtml.match(/