diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23dd5b1..dae9c40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -160,6 +160,7 @@ jobs: - name: Installer and control safety with mocked transports run: | python3 tools/test-setup-backend.py + node --test setup/test-controller.cjs node tools/test-installers.cjs node tools/test-loader-observer.cjs node tools/test-loader-restoration.cjs diff --git a/docs/BUILDING.md b/docs/BUILDING.md index b21a10a..77d2548 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -18,7 +18,7 @@ Existing optional files in `vendor/kaihen-mo/programs`, including Moader diagnos ## Build from a clean source checkout -The bundled SDK setup targets **Apple Silicon macOS and Linux x86_64**, including WSL2 x86_64. It provisions checksum-pinned, host-specific devkitA64 GCC 16.1.0, switch-tools 1.13.1 and ounce-devkit 20261114 into the checkout. Linux needs `zstd` to extract the packages. Intel macOS and Linux arm64 cross-builds are not configured by these scripts. Install Python 3.10+, Node 22+ and `make`; use native POSIX Node 24 for the later live installation. +The bundled SDK setup targets **Apple Silicon macOS and Linux x86_64**, including WSL2 x86_64. It provisions checksum-pinned, host-specific devkitA64 GCC 16.1.0, switch-tools 1.13.1 and ounce-devkit 20261114 into the checkout. Both hosts need `zstd` to extract the packages. Intel macOS and Linux arm64 cross-builds are not configured by these scripts. Install Python 3.10+, Node 22+ and `make`; use native POSIX Node 24 for the later live installation. If devkitPro's official endpoint returns HTTP 403 for the architecture-independent `dkp-toolchain-vars` 1.0.5 package, `setup-devkit.py` tries one [alternate host](https://wii.leseratte10.de/devkitPro/other-stuff/dkp-toolchain-vars-1.0.5-1-any.pkg.tar.zst). This exception applies only to that exact URL and SHA-256 `e6e26af3147061090572b61c576114ee9a45d5ed8c77c7d93cc5f5559198c288`; the downloaded bytes must match before extraction. diff --git a/docs/SEEDSOW.md b/docs/SEEDSOW.md index 86702b8..020f5a9 100644 --- a/docs/SEEDSOW.md +++ b/docs/SEEDSOW.md @@ -8,7 +8,7 @@ Download the [v4.0.0 backend ZIP](https://github.com/H644b/Moader/releases/downl - A Switch 2 with Seedsow Lullaby Demo or the full game and a working launcher save for **that edition**. The full game's save format differs from the Demo's; do not restore a Demo launcher save over a full-game save. Follow the [upstream Seedsow setup](https://github.com/Malev0/seedsow-fs-kaihen#setup-once) if you do not already have that entrypoint. This guide does not change or replace your save. - An Apple Silicon Mac or Linux x86_64 host, including WSL2, able to reach the Switch on the local network. The game's HTTP launcher must be reachable from that host after you press **Y**. -- Python 3.10 or newer, native POSIX Node.js **24**, Git, AArch64 capable `clang`, and room for the local SDK. Linux also needs `zstd` for the pinned packages. `tools/setup-devkit.py` installs the native SDK inside the kit without changing system packages. A source rebuild additionally needs `make`. +- Python 3.10 or newer, native POSIX Node.js **24**, Git, AArch64 capable `clang`, `zstd` for the pinned packages, and room for the local SDK. `tools/setup-devkit.py` installs the native SDK inside the kit without changing system packages. A source rebuild additionally needs `make`. - A native Switch 2 game you can use for the documented hold-R hbmenu entry after installation. Extract the backend ZIP and run the remaining commands from its outer folder, the one containing `START_HERE.txt` and `tools/`. Developers rebuilding from source can use the [repository](https://github.com/H644b/Moader) and [build guide](BUILDING.md). diff --git a/docs/SETUP_GUI.md b/docs/SETUP_GUI.md index 3d1e460..7e44498 100644 --- a/docs/SETUP_GUI.md +++ b/docs/SETUP_GUI.md @@ -14,7 +14,7 @@ The release files are packaged by [GitHub Actions](https://github.com/H644b/Moad Extract the ZIP for your computer. On macOS, open **Moader Setup.app**. On Linux, open **Moader Setup** in the file manager and choose Run if asked. On Windows, open **Moader Setup.exe** and choose a WSL2 Linux distribution in its picker. Keep the complete extracted kit together. Moader Setup opens its own desktop window. Its private local controller performs the computer work; the separate **Open Moader in browser** task opens the page hosted by the Switch. -Each prebuilt Setup app includes the matching console app, resident plugin, HEN, RO, bootstrap, a Node 24 controller runtime and a pinned Python preparation helper. You do not need the separate console app ZIP for a complete backend installation. The first host preparation fetches reviewed provider sources and, if needed, a Python distribution into the kit's state folder. Git is needed to fetch those sources. Seedsow preparation also needs clang and, on Linux, zstd. If an OS tool is missing, Setup names it. On macOS it opens the Command Line Tools installer. On Linux it can use a graphical software manager or, after an explicit click, the distribution's signed package manager with graphical administrator approval. In WSL2 it can install the named tools into the selected distribution through its signed package manager. A distribution without one of the supported package managers needs a supported desktop Linux or WSL2 environment before preparation can proceed. Nothing is installed globally by the Python helper. +Each prebuilt Setup app includes the matching console app, resident plugin, HEN, RO, bootstrap, a Node 24 controller runtime and a pinned Python preparation helper. You do not need the separate console app ZIP for a complete backend installation. The first host preparation fetches reviewed provider sources and, if needed, a Python distribution into the kit's state folder. Git is needed to fetch those sources. Seedsow preparation also needs clang and zstd to unpack the pinned SDK. On macOS, Setup finds zstd in standard Homebrew or MacPorts locations even when Finder does not put them on PATH. If it is absent, install zstd with your macOS package manager and reopen Setup. Setup names other missing OS tools and can open the Command Line Tools installer for Git and clang. On Linux it can use a graphical software manager or, after an explicit click, the distribution's signed package manager with graphical administrator approval. In WSL2 it can install the named tools into the selected distribution through its signed package manager. A distribution without one of the supported package managers needs a supported desktop Linux or WSL2 environment before preparation can proceed. Nothing is installed globally by the Python helper. ## Choose a task diff --git a/setup/controller.cjs b/setup/controller.cjs index 26fa019..f8c37a0 100644 --- a/setup/controller.cjs +++ b/setup/controller.cjs @@ -10,6 +10,22 @@ const crypto = require('node:crypto'); const {spawn, spawnSync} = require('node:child_process'); const hostPolicy = require('./host-policy.cjs'); const hostTools = require('./host-tools.cjs'); +const launcherStatus = require('./launcher-status.cjs'); + +// Finder-launched macOS apps receive a small system PATH. Homebrew and +// MacPorts install zstd outside it, although macOS tar needs that executable +// to unpack the pinned SDK archives. +if (process.platform === 'darwin') { + for (const folder of ['/opt/homebrew/bin', '/usr/local/bin', '/opt/local/bin']) { + const executable = path.join(folder, 'zstd'); + try { + fs.accessSync(executable, fs.constants.X_OK); + if (!(process.env.PATH || '').split(path.delimiter).includes(folder)) + process.env.PATH = folder + path.delimiter + (process.env.PATH || ''); + break; + } catch { /* Try the next standard package-manager path. */ } + } +} const root = path.resolve(__dirname, '..'); // The desktop window uses the same local identity assets as the paired browser. @@ -106,8 +122,9 @@ function checkHostDependencies(method) { requireTrue(cmdVersion('git'), 'Git is needed to fetch the pinned provider. Open the operating system installer from Setup, then click Prepare and verify kit again.'); if (method === 'seedsow') { requireTrue(cmdVersion('clang'), 'AArch64 source preparation needs clang. Open the operating system installer from Setup, then click Prepare and verify kit again.'); - if (process.platform === 'linux') - requireTrue(cmdVersion('zstd'), 'The kit-scoped SDK needs zstd. Open your Linux software manager from Setup, then click Prepare and verify kit again.'); + requireTrue(cmdVersion('zstd'), process.platform === 'darwin' + ? 'The kit-scoped SDK needs zstd to unpack its pinned archives. Install zstd with your macOS package manager, reopen Setup, then click Prepare and verify kit again.' + : 'The kit-scoped SDK needs zstd. Open your Linux software manager from Setup, then click Prepare and verify kit again.'); } } function executableInPath(name) { @@ -121,7 +138,7 @@ function executableInPath(name) { function missingHostTools(method) { return [!cmdVersion('git') && 'git', method === 'seedsow' && !cmdVersion('clang') && 'clang', method === 'seedsow' && - process.platform === 'linux' && !cmdVersion('zstd') && 'zstd'].filter(Boolean); + !cmdVersion('zstd') && 'zstd'].filter(Boolean); } async function installHostTools(method) { requireTrue(process.platform === 'linux' && supported(method), @@ -450,7 +467,7 @@ function checkLauncher(address) { data += bytes.toString('utf8'); if (data.length > 8192) request.destroy(Error('Launcher status reply was too large.')); }); - response.on('end', () => response.statusCode === 200 && /^status: ok(?:\r?\n|$)/.test(data) + response.on('end', () => launcherStatus(response.statusCode, data) ? resolve({online: true, message: 'Seedsow launcher answered on this address. FS access is not verified yet.'}) : reject(Error('Seedsow launcher did not return its expected status. Open the matching edition and press Y.'))); }); diff --git a/setup/launcher-status.cjs b/setup/launcher-status.cjs new file mode 100644 index 0000000..486ef58 --- /dev/null +++ b/setup/launcher-status.cjs @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-only +'use strict'; + +// GET /status returns the launcher help banner on current Seedsow saves. +// Older launchers returned an eval-style status line instead. +module.exports = (statusCode, body) => statusCode === 200 && + (/^n2h HTTP server \(seedsow\)(?:\r?\n|$)/.test(body) || + /^status: ok(?:\r?\n|$)/.test(body)); diff --git a/setup/test-controller.cjs b/setup/test-controller.cjs index d5bae5a..408967f 100644 --- a/setup/test-controller.cjs +++ b/setup/test-controller.cjs @@ -11,6 +11,7 @@ const crypto = require('node:crypto'); const {spawn} = require('node:child_process'); const policy = require('./host-policy.cjs'); const hostTools = require('./host-tools.cjs'); +const launcherStatus = require('./launcher-status.cjs'); const root = path.resolve(__dirname, '..'); const releaseSpec = JSON.parse(fs.readFileSync(path.join(root, 'config/release.json'))); @@ -67,6 +68,25 @@ test('host policy rejects unbundled architectures and native Windows', () => { assert.equal(policy.supported('ns2jb', 'linux', 'riscv64'), false); }); +test('Seedsow launcher status accepts the current read-only banner', () => { + const banner = 'n2h HTTP server (seedsow)\nPOST /eval body=\n' + + 'PUT|POST /save?path= body=\nDELETE /delete?path=\n'; + assert.equal(launcherStatus(200, banner), true); + assert.equal(launcherStatus(200, 'status: ok\n'), true); + assert.equal(launcherStatus(200, 'n2h HTTP server (other)\n'), false); + assert.equal(launcherStatus(404, banner), false); +}); + +test('Finder-style macOS PATH discovers installed zstd for SDK preparation', async t => { + if (process.platform !== 'darwin' || + !['/opt/homebrew/bin', '/usr/local/bin', '/opt/local/bin'].some(folder => + fs.existsSync(path.join(folder, 'zstd')))) + return t.skip('requires macOS with a standard zstd installation'); + const api = await startController(t, null, {PATH: '/usr/bin:/bin:/usr/sbin:/sbin'}); + const state = await (await api.get('/api/state')).json(); + assert.match(state.system.zstd, /Zstandard|zstd/i); +}); + test('Linux tool handoff keeps WSL names and executable paths as arguments', () => { const apt = hostTools.managers.find(item => item.name === 'apt'); const steps = hostTools.plan({wsl: true, distro: 'Ubuntu é test', @@ -92,7 +112,8 @@ test('wrong component hash is shown before a device action', async t => { const kit = await fsp.mkdtemp(path.join(os.tmpdir(), 'moader-setup-kit-')); t.after(() => fsp.rm(kit, {recursive: true, force: true})); const release = JSON.parse(await fsp.readFile(path.join(root, 'config/release.json'))); - const files = ['config/release.json', 'setup/controller.cjs', 'setup/host-policy.cjs', + const files = ['config/release.json', 'setup/controller.cjs', 'setup/launcher-status.cjs', + 'setup/host-policy.cjs', 'setup/host-tools.cjs', ...Object.values(release.binaries).map(x => x.source), release.patched_hen.source, release.patched_ro.source, @@ -115,7 +136,7 @@ test('wrong component hash is shown before a device action', async t => { {action: 'export-sd', kind: 'app'})).status, 202); const failed = await untilDone(noTools); assert.equal(failed.operation.status, 'failed'); - assert.match(failed.operation.firstError, /Python preparation helper is missing/i); + assert.match(failed.operation.firstError, /app and resident do not match this release/i); }); test('loopback token, origin, kit identity, SD export and support copy', async t => { diff --git a/setup/ui/app.js b/setup/ui/app.js index 684b15e..83d7b5d 100644 --- a/setup/ui/app.js +++ b/setup/ui/app.js @@ -170,14 +170,17 @@ function boot() { function prepareStep(ready) { const s = snapshot.system; const missing = [!s.git && 'Git', method === 'seedsow' && !s.clang && 'clang', - method === 'seedsow' && s.os === 'linux' && !s.zstd && 'zstd'].filter(Boolean); + method === 'seedsow' && !s.zstd && 'zstd'].filter(Boolean); + const macToolchainMissing = s.os === 'darwin' && missing.some(name => name !== 'zstd'); const handoff = missing.length ? note('Computer tool needed', 'Setup needs ' + safe(missing.join(', ')) + ' for this method. ' + - (s.os === 'darwin' ? 'Open the macOS tools installer, finish its prompts, then return here.' : + (s.os === 'darwin' ? (macToolchainMissing ? 'Open the macOS tools installer for Git and clang. ' : '') + + (missing.includes('zstd') ? 'Install zstd with your macOS package manager, then reopen Setup. ' : '') + + 'Return here when the named tools are available.' : s.wsl ? 'Install them into the selected WSL2 distribution through its signed package manager. This changes that distribution’s system packages; no Switch action starts.' : 'Install them through the signed Linux package manager. A graphical administrator prompt may appear. No Switch action starts.'), 'warning') + '
' + - (s.os === 'darwin' ? button('Open macOS tools installer', 'dependency-handoff', 'secondary') : + (s.os === 'darwin' ? (macToolchainMissing ? button('Open macOS tools installer', 'dependency-handoff', 'secondary') : '') : button(s.wsl ? 'Install tools in WSL2' : 'Install missing Linux tools', 'install-host-tools', 'secondary') + (s.wsl ? '' : button('Open Linux Software app', 'dependency-handoff', 'quiet'))) + diff --git a/tools/package-release.py b/tools/package-release.py index 9e2e4db..666a3d7 100644 --- a/tools/package-release.py +++ b/tools/package-release.py @@ -155,7 +155,7 @@ def public_source(root): 'Moader Setup.app/Contents/MacOS/Moader Setup', 'Moader Setup.app/Contents/Info.plist', 'setup/launch.sh', 'setup/windows-launch.ps1', 'setup/wsl-entry.sh', - 'setup/controller.cjs', 'setup/host-policy.cjs', + 'setup/controller.cjs', 'setup/launcher-status.cjs', 'setup/host-policy.cjs', 'setup/host-tools.cjs', 'setup/desktop-app/package.json', 'setup/desktop-app/main.cjs', 'setup/bridge.cjs', 'setup/export-sd.py', diff --git a/tools/test-package-setup-platform.py b/tools/test-package-setup-platform.py index 0d72205..6547e54 100644 --- a/tools/test-package-setup-platform.py +++ b/tools/test-package-setup-platform.py @@ -26,6 +26,7 @@ def main(): 'setup/desktop-app/main.cjs': b'// desktop entry', 'setup/desktop-app/package.json': b'{"main":"main.cjs"}', 'setup/launch.sh': b'#!/bin/sh\n', + 'setup/launcher-status.cjs': b'// launcher status fixture', 'dist/Moader.nro': b'NRO0fixture', 'vendor/kaihen-mo/hen/main': b'NSO0fixture', 'host-runtimes/node-v24.22.3/LICENSE': b'Node notice', @@ -68,6 +69,7 @@ def main(): assert root + ('Moader Setup.exe' if target == 'windows-x64' else 'Moader Setup') in names assert built.read(resources + 'app/main.cjs') == b'// desktop entry' assert built.read(resources + 'kit/branding/setup-icon.png') == b'rounded png fixture' + assert built.read(resources + 'kit/setup/launcher-status.cjs') == b'// launcher status fixture' assert built.read(resources + 'kit/dist/Moader.nro') == b'NRO0fixture' assert len([n for n in names if n.endswith('/node')]) == 1 assert len([n for n in names if n.endswith('/uv')]) == 1