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
6 changes: 6 additions & 0 deletions docs/test-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ Rewild changes world files, so its safety promises come first. "Acceptance" is `
**Skipped, with reasons:**
- How a reset area looks and blends in a real client: real client only, in the README's untested list.
- LanternGraves as a real keep provider: it doesn't register one yet; `keep.mjs` uses a stand-in with the same name.

## 2026-11-16: cleanup (D226)

- **Covered:** the harness records each server folder it creates and each Java process it starts. When the run ends (pass, fail, an uncaught error, Ctrl-C, SIGTERM or SIGHUP) it kills those processes and deletes those folders, and nothing else. A folder from an earlier run that's in the way stops the run; it isn't deleted. `KEEP_TEST_SERVERS=1` keeps the folders for debugging.
- **Checked by hand:** on MobShowdown, a full run (42/42) and a run interrupted after 45 seconds both left the work folder empty, with no Java left and the test port closed. The other harnesses use the same code.
- **Gap skipped:** the suite can't check its own leftovers, because cleanup runs as the process exits. A wrapper that checks after the suite exits would add more machinery than the check is worth here.
13 changes: 13 additions & 0 deletions test/harness.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,21 @@ export function report(file) {
return failed.length
}

// D226: a run removes everything it created, pass, fail or interrupted, and nothing else. Folders made by freshServer
// are recorded and deleted at exit, after any server still running is killed. KEEP_TEST_SERVERS=1 keeps them.
const created = new Set(), procs = new Set()
function cleanupAll() {
for (const p of procs) try { if (p.exitCode === null && p.signalCode === null) p.kill('SIGKILL') } catch {}
if (process.env.KEEP_TEST_SERVERS === '1') return
for (const d of created) try { rmSync(d, { recursive: true, force: true, maxRetries: 10, retryDelay: 300 }) } catch {}
}
process.on('exit', cleanupAll)
for (const sig of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.on(sig, () => { cleanupAll(); process.exit(128 + ({ SIGHUP: 1, SIGINT: 2, SIGTERM: 15 })[sig]) })

/** A fresh server folder. Paper's downloaded libraries are cloned from a primed folder to save time. */
export function freshServer(version, { seed = 424242, plugins = [], config = null, props = {} } = {}) {
const dir = mkdtempSync(path.join(os.tmpdir(), `rewild-test-${version}-`))
created.add(dir)
copyFileSync(path.join(CACHE, `paper-${version}.jar`), path.join(dir, 'paper.jar'))
const prime = path.join(CACHE, `prime-${version}`)
for (const f of ['libraries', 'versions', 'cache']) {
Expand Down Expand Up @@ -74,6 +86,7 @@ export class Server {
this.exit = new Promise(resolve => {
this.proc = spawn(JAVA, ['-Xms1G', '-Xmx3G', '-Dterminal.jline=false', '-Dterminal.ansi=false', ...jvm, '-jar', 'paper.jar', 'nogui'],
{ cwd: this.dir, stdio: ['pipe', 'pipe', 'pipe'] })
procs.add(this.proc)
const add = d => { this.log += d.toString() }
this.proc.stdout.on('data', add)
this.proc.stderr.on('data', add)
Expand Down
Loading