Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "msms",
"version": "0.3.0",
"description": "Minecraft Server Management System portable, bilingual (EN/TR) desktop control panel for Minecraft servers.",
"description": "Minecraft Server Management System \u2014 portable, bilingual (EN/TR) desktop control panel for Minecraft servers.",
"author": "CaYatur",
"license": "MIT",
"main": "./out/main/index.js",
Expand All @@ -14,6 +14,8 @@
"typecheck:web": "tsc --noEmit -p tsconfig.web.json --composite false",
"typecheck": "npm run typecheck:node && npm run typecheck:web",
"lint": "eslint . --ext .ts,.tsx || echo lint-skipped",
"gates": "node scripts/gates.mjs",
"gates:packaged": "node scripts/gates.mjs --packaged",
"dist": "electron-vite build && electron-builder",
"dist:portable": "electron-vite build && electron-builder --win portable",
"dist:dir": "electron-vite build && electron-builder --dir"
Expand Down
93 changes: 93 additions & 0 deletions scripts/gates.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Run every smoke gate, against the dev build or against a packaged binary.
*
* The packaged half is the point (#166). Gates had only ever been run with
* `npx electron .`, so nothing looked at the thing an operator downloads —
* and `MSMS_SMOKE_WORLDS` had been failing against every packaged build since
* at least v0.2.5 without anyone knowing, because a packaged app is built for
* the Windows GUI subsystem and its console output goes nowhere.
*
* node scripts/gates.mjs the dev build
* node scripts/gates.mjs --packaged the newest portable exe in release/
* node scripts/gates.mjs --packaged <path> a specific binary
*
* The verdict is the exit code, per this project's doctrine. The transcript of
* a failing gate is printed from `msms-data/logs/smoke.log`, which is where a
* packaged run writes it.
*/
import { spawnSync } from 'node:child_process'
import { existsSync, readdirSync, readFileSync, rmSync } from 'node:fs'
import { join, resolve } from 'node:path'

const GATES = [
'MSMS_SMOKE',
'MSMS_SMOKE_WORLDS',
'MSMS_SMOKE_WEB',
'MSMS_SMOKE_MODUPDATE',
'MSMS_SMOKE_ANALYSIS',
'MSMS_SMOKE_AUDIT',
'MSMS_SMOKE_ALERTS',
'MSMS_SMOKE_BRIDGE',
'MSMS_SMOKE_EVENTS',
'MSMS_SMOKE_METRICS',
'MSMS_SMOKE_JAVA'
]

const root = process.cwd()
const args = process.argv.slice(2)
const packaged = args.includes('--packaged')

function newestPortable() {
const dir = join(root, 'release')
if (!existsSync(dir)) return null
const hits = readdirSync(dir)
.filter((n) => n.endsWith('-portable.exe'))
.map((n) => join(dir, n))
if (!hits.length) return null
// Newest by name, which sorts by version for this project's naming.
return hits.sort()[hits.length - 1]
}

const explicit = args.find((a) => a !== '--packaged')
const exe = packaged ? (explicit ? resolve(explicit) : newestPortable()) : null
if (packaged && !exe) {
console.error('No packaged binary found. Build one with `npm run dist:portable` first.')
process.exit(2)
}
if (packaged && !existsSync(exe)) {
console.error('No such binary: ' + exe)
process.exit(2)
}

// The gates want the pre-seeded fixture, the same one the dev run uses.
const baseDir = join(root, 'dev-root')
const transcript = join(baseDir, 'msms-data', 'logs', 'smoke.log')

console.log(packaged ? 'Gates against ' + exe : 'Gates against the dev build')
console.log('')

let failed = 0
for (const gate of GATES) {
try {
rmSync(transcript, { force: true })
} catch {
/* no transcript yet */
}
const env = { ...process.env, [gate]: '1', MSMS_BASE_DIR: baseDir }
const r = packaged
? spawnSync(exe, [], { env, stdio: 'ignore' })
: spawnSync('npx', ['electron', '.'], { env, stdio: 'ignore', shell: true })
const code = r.status ?? 1
const ok = code === 0
if (!ok) failed++
console.log((ok ? 'PASS ' : 'FAIL ') + gate + (ok ? '' : ' (exit ' + code + ')'))
if (!ok && existsSync(transcript)) {
// The reason, from the file — a packaged run has no console to have printed it.
const lines = readFileSync(transcript, 'utf-8').split('\n').filter((l) => l.includes('FAIL'))
for (const l of lines.slice(-3)) console.log(' ' + l.trim())
}
}

console.log('')
console.log(failed ? failed + ' gate(s) failed' : 'all ' + GATES.length + ' gates passed')
process.exit(failed ? 1 : 0)
9 changes: 8 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { initBlockColours } from './core/clientAssets'
import { resolveBaseDir } from './paths'
import { log } from './logger'
import { startTileWarming } from './core/tileWarm'
import { teeSmokeOutput } from './smokeLog'
import {
runSmoke,
runWizardSmoke,
Expand Down Expand Up @@ -230,7 +231,9 @@ if (!gotLock) {
// worse than a failing test, because it looks like a working one.
if (Object.keys(process.env).some((k) => k.startsWith('MSMS_SMOKE'))) {
// eslint-disable-next-line no-console
console.log('SMOKE: FAIL - another instance holds the single-instance lock; nothing ran')
// Through the logger as well: a packaged app has no console, so a bare
// console.log here would make this the one failure nobody can see (#166).
log.error('SMOKE: FAIL - another instance holds the single-instance lock; nothing ran')
app.exit(1)
} else {
app.quit()
Expand All @@ -241,6 +244,10 @@ if (!gotLock) {
app.whenReady().then(async () => {
Menu.setApplicationMenu(null)
loadConfig()
// A packaged app has no console attached, so without this a gate can only
// ever report its exit code and nothing else (#166). Here rather than at
// module scope, which is where the logger itself is known to work.
if (Object.keys(process.env).some((k) => k.startsWith('MSMS_SMOKE'))) teeSmokeOutput()
log.info(`MSMS starting. Base dir: ${resolveBaseDir()}`)
handleImageProtocol()
registerIpc()
Expand Down
Loading
Loading