eb37f8319f
La suite era allineata a una vecchia forma dello stato (sp.punt/sp.set/ sp.servHome) e a una vecchia architettura e2e (controller su :3001). Baseline iniziale: 77/170 test Vitest falliti. Vitest (ora 212/212 verdi): - gameState.test.js: riscritto con helper che derivano punteggio/set/ servizio dalla striscia; aggiunto blocco formInizio - server-utils.js: getNetworkIPs accetta interfacce iniettabili e printServerInfo accetta gli IP iniettabili (deterministico anche su WSL); filtro LAN unificato (esclude 127./169.254./172.) - websocket + stress: punteggio letto via punteggio(striscia) - ControllerPage/DisplayPage: forzato layout mobile (viewport portrait), punteggi impostati via striscia; aggiunto test bottone REFERTO - nuovi: referto.test.js, persist.test.js (mock fs), wsMixin.test.js, integration/server.test.js (routing) Refactor di supporto: - referto.js: estratta buildRefertoHtml(state, now) pura; generaReferto resta wrapper con window.open/print - server.js: estratti createApp()/startServer(); avvio solo se entrypoint e2e (migrazione parziale, NON ancora verificata verde): - tutti i riferimenti controller :3001 -> :3000/controller - forzato viewport portrait sul controller prima del goto - reset helper: chiude il dialog di configurazione che doReset apre - game-simulation: gestione del dialog SET VINTO automatico a 25
71 lines
2.2 KiB
JavaScript
71 lines
2.2 KiB
JavaScript
import { networkInterfaces } from 'os'
|
|
import { readFileSync, existsSync } from 'fs'
|
|
import { execSync } from 'child_process'
|
|
|
|
function isWSL() {
|
|
try {
|
|
return existsSync('/proc/sys/kernel/osrelease') &&
|
|
readFileSync('/proc/sys/kernel/osrelease', 'utf8').toLowerCase().includes('microsoft')
|
|
} catch { return false }
|
|
}
|
|
|
|
// Un IPv4 è "pubblicabile" in LAN se non è loopback, link-local o bridge Docker.
|
|
function isLanIPv4(address) {
|
|
return !!address
|
|
&& !address.startsWith('127.')
|
|
&& !address.startsWith('169.254.')
|
|
&& !address.startsWith('172.')
|
|
}
|
|
|
|
// Estrae gli IP LAN da un oggetto in stile os.networkInterfaces().
|
|
// Esportata per poter essere testata in isolamento, senza dipendere dalla piattaforma.
|
|
export function collectIPs(nets) {
|
|
const out = []
|
|
for (const name of Object.keys(nets || {})) {
|
|
for (const net of nets[name]) {
|
|
if (net.family === 'IPv4' && !net.internal && isLanIPv4(net.address)) {
|
|
out.push(net.address)
|
|
}
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// Restituisce gli IP di rete della macchina.
|
|
// Passando `nets` (oggetto in stile os.networkInterfaces) si forza il percorso
|
|
// deterministico, scavalcando il rilevamento WSL/PowerShell: utile nei test.
|
|
export function getNetworkIPs(nets) {
|
|
if (nets) return collectIPs(nets)
|
|
|
|
if (isWSL()) {
|
|
try {
|
|
const out = execSync(
|
|
'powershell.exe -NoProfile -Command "Get-NetIPAddress -AddressFamily IPv4 | Select-Object -ExpandProperty IPAddress"',
|
|
{ timeout: 3000 }
|
|
)
|
|
return out.toString().trim().split('\n')
|
|
.map(s => s.trim())
|
|
.filter(isLanIPv4)
|
|
} catch { return [] }
|
|
}
|
|
|
|
return collectIPs(networkInterfaces())
|
|
}
|
|
|
|
// `networkIPs` è iniettabile per rendere la stampa testabile in modo deterministico.
|
|
export function printServerInfo(port = 3000, networkIPs = getNetworkIPs()) {
|
|
console.log(`\nSegnapunti Server`)
|
|
console.log(` Display: http://127.0.0.1:${port}/display`)
|
|
console.log(` Controller: http://127.0.0.1:${port}/controller`)
|
|
|
|
if (networkIPs.length > 0) {
|
|
console.log(`\n Da dispositivi remoti:`)
|
|
networkIPs.forEach(ip => {
|
|
console.log(` Display: http://${ip}:${port}/display`)
|
|
console.log(` Controller: http://${ip}:${port}/controller`)
|
|
})
|
|
}
|
|
|
|
console.log()
|
|
}
|