Public: anyone can read this; the crew can change it.
Games survival step 1: a survival performance set (lithium, scalablelux, noisium, chunky) planned as one locked install #18099
Merged 9h 18m ago, live in production
torque/forge:torque/18086-games-survival-step-1-a-survival-perform → main 0 commits fork 2 threads · 2 unresolved
7 files
changed +226
−4
docs/features/game-mods.md +2 −1
| @@ -9,6 +9,7 @@ The server's mods or plugins come from Modrinth, for its loader and game version | ||
| 9 | 9 | - **Search** shows each result with a badge before any click: *Runs on 1.21.4*, or why not (*1.20.1 and older*, *Client only*). Mod searches use Modrinth's `environment` facet, so client-only mods stay out. |
| 10 | 10 | - **Preview** picks the newest compatible version (a release when there is one) and resolves what it requires, recursively: "Adds Chunky 1.4.28; Adds ChunkyLib 1.0.2 (required by Chunky)". A project with no version for the server, a requirement with none, or two projects that say they are incompatible are refused with the reason. A bare slug already in `MODRINTH_PROJECTS` is pinned by the same change. |
| 11 | 11 | - **Install and restart** is one commit on the commit you previewed: the lockfile `<compose dir>/modrinth/<service>.lock.json` (each project's version id, file path, url and sha512, and whether it was asked for or is a dependency) and the compose env made from it: `MODRINTH_PROJECTS` lists `slug:versionId` for every project and `MODRINTH_DOWNLOAD_DEPENDENCIES=none`, so the image fetches exactly the locked set. A proxy also gets `MINECRAFT_VERSION`, which its Modrinth step needs. On a proxy whose servers sleep, `MODRINTH_PROJECTS` also holds AutoStopper (`PG4gqnzX:EclCtvWk`, see [](games.md)): it is sleep's, so a Modrinth change carries it over as it is and never lists it as the proxy's own, and Warm again takes only that entry. |
| 12 | - **Sets**: a named set installs in one preview and one commit. `set:survival` is the survival performance set for a Fabric server: Lithium, ScalableLux, Noisium and Chunky, each at its newest release for the server's Minecraft version, with what they require (Chunky needs Fabric API). It adds only what is missing, and a server on another loader is refused with the reason. The web Mods block shows it with a *Preview the set* button until it is installed; the terminal shows the same lines and `s` previews it; MCP `mods_install` takes `project: "set:survival"`. | |
| 12 | 13 | - **Updates** post the locked sha512s to Modrinth's `/v2/version_files/update` (releases for the loader and version) and show "2 updates" as from → to, one click each or all. |
| 13 | 14 | - **Remove** takes a project and what only it required; a dependency something else requires stays. |
| 14 | 15 | |
| @@ -27,7 +28,7 @@ The image does not check a pack's file hashes (its Modrinth project path does; i | ||
| 27 | 28 | ## Where |
| 28 | 29 | |
| 29 | 30 | - **Web:** `/games/<box>/<service>`, the Mods (or Plugins) block: updates, what is installed, Search, Preview, Install and restart; on a mod server, the Modpack block: the pack, its locked files, Search packs, Preview, Install pack and restart. |
| 30 | - **Terminal:** a service's screen, `m`: `/` search, `a` install by a result's number or a slug, `u` update all, `d` remove, `p` a modpack by slug; `y` commits the preview shown, `n` drops it (`src/tui/screens/game_mods.ts`). | |
| 31 | - **Terminal:** a service's screen, `m`: `/` search, `a` install by a result's number or a slug, `s` the survival performance set, `u` update all, `d` remove, `p` a modpack by slug; `y` commits the preview shown, `n` drops it (`src/tui/screens/game_mods.ts`). | |
| 31 | 32 | - **MCP:** `games` with `mods`, `mods_search`, `mods_pack_search`, `mods_install`, `mods_update`, `mods_remove`, `mods_pack`; a change is planned until `dryRun: false`. |
| 32 | 33 | |
| 33 | 34 | All three read and write through `src/games/mods.ts`, over the client in `src/games/modrinth.ts`. |
src/games/mod_sets.ts added +54
| @@ -0,0 +1,54 @@ | ||
| 1 | /** | |
| 2 | * Named sets of Modrinth projects a server takes in one commit (#18086, step 1 of #18059): the | |
| 3 | * survival performance set is the four mods that cut a Fabric survival server's tick and chunk | |
| 4 | * cost without changing how it plays. A set is only names: the versions are pinned by the mods | |
| 5 | * planner (`mods.ts`) from Modrinth for the server's own loader and game version, with what each | |
| 6 | * requires (Chunky pulls Fabric API), and land in the lockfile like any install. | |
| 7 | */ | |
| 8 | ||
| 9 | export interface ModSet { | |
| 10 | readonly name: string; | |
| 11 | readonly title: string; | |
| 12 | /** The Modrinth loader its projects are for; a server on another loader is refused. */ | |
| 13 | readonly loader: string; | |
| 14 | readonly slugs: readonly string[]; | |
| 15 | /** One line for each project: what it is for. */ | |
| 16 | readonly why: readonly string[]; | |
| 17 | } | |
| 18 | ||
| 19 | /** What `project` carries to say "this set" rather than one project: `set:survival`. */ | |
| 20 | export const SET_PREFIX = "set:"; | |
| 21 | ||
| 22 | export const SURVIVAL: ModSet = Object.freeze({ | |
| 23 | name: "survival", | |
| 24 | title: "Survival performance", | |
| 25 | loader: "fabric", | |
| 26 | slugs: Object.freeze(["lithium", "scalablelux", "noisium", "chunky"]), | |
| 27 | why: Object.freeze([ | |
| 28 | "Lithium: game logic, physics and AI made cheaper, with vanilla behaviour", | |
| 29 | "ScalableLux: the lighting engine, rewritten to scale with cores", | |
| 30 | "Noisium: faster world generation, same terrain", | |
| 31 | "Chunky: pregenerates the world so players never wait on it (needs Fabric API)", | |
| 32 | ]), | |
| 33 | }); | |
| 34 | ||
| 35 | /** The set a `project` value names (`set:survival`), if there is one. */ | |
| 36 | export function setNamed(ref: string): ModSet | undefined { | |
| 37 | const r = ref.trim().toLowerCase(); | |
| 38 | return r === `${SET_PREFIX}${SURVIVAL.name}` ? SURVIVAL : undefined; | |
| 39 | } | |
| 40 | ||
| 41 | /** | |
| 42 | * The slugs of `set` the lock does not yet hold as a top-level install; the one answer the planner, | |
| 43 | * the page and the terminal share. | |
| 44 | */ | |
| 45 | export function missing(set: ModSet, lock: readonly { slug: string; top: boolean }[]): string[] { | |
| 46 | return set.slugs.filter((s) => !lock.some((l) => l.top && l.slug === s)); | |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * Whether to offer `set` on a server: its loader, not a modpack, and something of it still to add. | |
| 51 | */ | |
| 52 | export function offered(set: ModSet, target: { pack: boolean; loaders: readonly string[] }, lock: readonly { slug: string; top: boolean }[]): boolean { | |
| 53 | return !target.pack && target.loaders.includes(set.loader) && missing(set, lock).length > 0; | |
| 54 | } |
src/games/mods.ts +39
| @@ -20,6 +20,7 @@ import type { App } from "../app.ts"; | ||
| 20 | 20 | import type { User } from "../core/users.ts"; |
| 21 | 21 | import { commitCompose, composeDir, pluginUrls, readCompose, readRepoFile, serviceEnv, setServiceEnv } from "./compose.ts"; |
| 22 | 22 | import { byVersion, latestRelease, newestPack, packUpdate, readPack, resolve, targetOf, updates, type Locked, type LockedPack, type Result, type Target, type Version } from "./modrinth.ts"; |
| 23 | import { missing as setMissing, setNamed, SET_PREFIX, type ModSet } from "./mod_sets.ts"; | |
| 23 | 24 | import { AUTOSTOPPER } from "./sleep.ts"; |
| 24 | 25 | import type { GameBox } from "./store.ts"; |
| 25 | 26 | |
| @@ -193,6 +194,10 @@ export async function planInstall(app: App, m: Mods, service: string, ref: strin | ||
| 193 | 194 | if (m.target.pack) |
| 194 | 195 | return { ok: false, error: `This server runs ${m.pack === undefined ? "a modpack" : `the modpack ${m.pack.title}`}; its mods are the pack's, and extra mods on top of a pack come later.` }; |
| 195 | 196 | const wantedRef = ref.trim(); |
| 197 | if (wantedRef.toLowerCase().startsWith(SET_PREFIX)) { | |
| 198 | const set = setNamed(wantedRef); | |
| 199 | return set === undefined ? { ok: false, error: `There is no set called ${wantedRef.slice(SET_PREFIX.length)}; the sets are ${SET_PREFIX}survival.` } : planSet(app, m, service, set); | |
| 200 | } | |
| 196 | 201 | if (!/^[A-Za-z0-9][A-Za-z0-9_.-]{0,99}$/.test(wantedRef)) |
| 197 | 202 | return { ok: false, error: "Name a Modrinth project by its slug or id, like luckperms." }; |
| 198 | 203 | const had = find(m.lock, wantedRef); |
| @@ -223,6 +228,40 @@ export async function planInstall(app: App, m: Mods, service: string, ref: strin | ||
| 223 | 228 | }; |
| 224 | 229 | } |
| 225 | 230 | |
| 231 | /** | |
| 232 | * Install a named set (`mod_sets.ts`) as one plan: each project's newest version for this server | |
| 233 | * and everything they require, resolved together so one lock, one env and one commit cover them. | |
| 234 | * Projects the server already has are kept as they are; a bare slug loose in MODRINTH_PROJECTS is | |
| 235 | * pinned with it, as with a single install. | |
| 236 | */ | |
| 237 | async function planSet(app: App, m: Mods, service: string, set: ModSet): Promise<Result<Plan>> { | |
| 238 | if (!m.target.loaders.includes(set.loader)) | |
| 239 | return { ok: false, error: `The ${set.title.toLowerCase()} set is for ${set.loader[0]!.toUpperCase()}${set.loader.slice(1)} servers; ${service} runs ${m.target.label}.` }; | |
| 240 | const missing = setMissing(set, m.lock); | |
| 241 | if (missing.length === 0) return { ok: false, error: `The ${set.title.toLowerCase()} set is installed.` }; | |
| 242 | const adopt = m.loose.filter(bareSlug).filter((s) => !missing.includes(s.toLowerCase())); | |
| 243 | const kept = m.loose.filter((e) => !bareSlug(e) || missing.includes(e.toLowerCase())); | |
| 244 | const got = await resolve(app, m.target, m.lock, [ | |
| 245 | ...missing.map((s) => ({ project: find(m.lock, s)?.project ?? s, top: true })), | |
| 246 | ...adopt.map((s) => ({ project: s, top: true })), | |
| 247 | ]); | |
| 248 | if (!got.ok) return got; | |
| 249 | const deps = got.value.filter((l) => !l.top && !m.lock.some((o) => o.project === l.project)).length; | |
| 250 | const what = `the ${set.title.toLowerCase()} set (${missing.join(", ")})`; | |
| 251 | const withDeps = deps === 0 ? "" : ` and ${String(deps)} ${deps === 1 ? "dependency" : "dependencies"}`; | |
| 252 | return { | |
| 253 | ok: true, | |
| 254 | value: { | |
| 255 | lines: diffLines(m, got.value, new Set(adopt)), | |
| 256 | lock: got.value, | |
| 257 | env: envFor(m, got.value, kept), | |
| 258 | message: `games: ${service} mods: add ${what}${withDeps}`, | |
| 259 | sha: m.sha, | |
| 260 | done: `${what[0]!.toUpperCase()}${what.slice(1)} is installed${withDeps === "" ? "" : ` with ${withDeps.slice(5)}`}`, | |
| 261 | }, | |
| 262 | }; | |
| 263 | } | |
| 264 | ||
| 226 | 265 | /** The updates Modrinth has for the locked projects, as from → to. */ |
| 227 | 266 | export async function updatesOf(app: App, m: Mods): Promise<Result<{ from: Locked; to: Version }[]>> { |
| 228 | 267 | return updates(app, m.target, m.lock); |
src/http/mcp/tools/games.ts +1 −1
Diff not shown — a line 2,932 characters wide (limit 2,000). +1 −1
View filesrc/tui/screens/game_mods.ts +9 −1
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * shown and `n` drops it; `l` makes a link to the client pack for players and `x` ends every link. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { offered, SET_PREFIX, SURVIVAL } from "../../games/mod_sets.ts"; | |
| 10 | 11 | import { search, type Hit, type Result } from "../../games/modrinth.ts"; |
| 11 | 12 | import { commitPlan, modsOf, packUpdateOf, planInstall, planPack, planPackUpdate, planRemove, planUpdate, updatesOf, type Mods, type Plan } from "../../games/mods.ts"; |
| 12 | 13 | import { makePackLink, packRow, revokeLinks, type PackRow } from "../../games/client_pack.ts"; |
| @@ -65,6 +66,9 @@ export function gameModsScreen(f: Session, ctx: Ctx, box: GameBox, service: stri | ||
| 65 | 66 | ...(m.lock.length + m.loose.length + m.urls.length === 0 ? ["Nothing is installed."] : []), |
| 66 | 67 | ...(players === undefined ? [] : [`players: ${players.open > 0 ? `${String(players.open)} link(s) open; x ends all. ` : ""}${players.can ? "l makes a link. " : ""}${players.words}`]), |
| 67 | 68 | ...(link === "" ? [] : [`link (30 days, shown once): ${link}`]), |
| 69 | ...(offered(SURVIVAL, m.target, m.lock) | |
| 70 | ? [`${SURVIVAL.title} set: ${SURVIVAL.slugs.join(", ")}; s previews it`, ...SURVIVAL.why.map((w) => ` ${w}`)] | |
| 71 | : []), | |
| 68 | 72 | ...hits.map((h, i) => `${String(i + 1)}. ${h.title} (${h.slug}) ${h.fits ? `runs on ${m.target.gameVersion}` : h.why}`), |
| 69 | 73 | `Uploading a jar is on the web only: /games/${box.name}/${service}.`, |
| 70 | 74 | ]; |
| @@ -88,6 +92,7 @@ export function gameModsScreen(f: Session, ctx: Ctx, box: GameBox, service: stri | ||
| 88 | 92 | keys: [ |
| 89 | 93 | binding(["/"], "search Modrinth"), |
| 90 | 94 | binding(["a"], "install"), |
| 95 | binding(["s"], `preview the ${SURVIVAL.title.toLowerCase()} set`), | |
| 91 | 96 | binding(["u"], "update all"), |
| 92 | 97 | binding(["d"], "remove"), |
| 93 | 98 | binding(["p"], "modpack"), |
| @@ -130,7 +135,10 @@ export function gameModsScreen(f: Session, ctx: Ctx, box: GameBox, service: stri | ||
| 130 | 135 | const ref = /^\d+$/.test(v) ? (hits[Number(v) - 1]?.slug ?? v) : v; |
| 131 | 136 | return preview((m) => planInstall(f.app, m, service, ref)); |
| 132 | 137 | }); |
| 133 | else if (e.key === "d") ask("Remove", "The slug of what to remove", (raw) => preview((m) => planRemove(m, service, raw.trim()))); | |
| 138 | else if (e.key === "s") { | |
| 139 | if (!operator()) say(`You are not an operator of ${service}.`); | |
| 140 | else void preview((m) => planInstall(f.app, m, service, `${SET_PREFIX}${SURVIVAL.name}`)).then(say); | |
| 141 | } else if (e.key === "d") ask("Remove", "The slug of what to remove", (raw) => preview((m) => planRemove(m, service, raw.trim()))); | |
| 134 | 142 | else if (e.key === "p") ask("Modpack", "A Modrinth modpack's slug", (raw) => preview((m) => planPack(f.app, m, service, raw.trim()))); |
| 135 | 143 | else if (e.key === "l" || e.key === "x") { |
| 136 | 144 | if (!operator()) say(`You are not an operator of ${service}.`); |
src/web/pages/games.ts +5
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | import { addPluginUrl, commitServiceEnv, composeServices, readCompose, serviceEnv } from "../../games/compose.ts"; |
| 11 | import { offered, SET_PREFIX, SURVIVAL } from "../../games/mod_sets.ts"; | |
| 11 | 12 | import { commitPlan, modsOf, packUpdateOf, planInstall, planPack, planPackUpdate, planRemove, planUpdate, updatesOf, type Mods, type Plan } from "../../games/mods.ts"; |
| 12 | 13 | import { search, searchPacks, type Hit, type Result } from "../../games/modrinth.ts"; |
| 13 | 14 | import { packRow } from "../../games/client_pack.ts"; |
| @@ -895,6 +896,10 @@ function modsBlock(o: { | ||
| 895 | 896 | }), |
| 896 | 897 | ), |
| 897 | 898 | ])} |
| 899 | ${o.act && offered(SURVIVAL, t, m.lock) && o.adding !== `${SET_PREFIX}${SURVIVAL.name}` | |
| 900 | ? html`${rowList(SURVIVAL.why.map((w) => row({ title: w })))} | |
Design: |
||
| 901 | ${btn("Preview the set", { size: "sm", variant: "secondary", href: `${o.base}?add=${SET_PREFIX}${SURVIVAL.name}#mods`, label: `Preview installing the ${SURVIVAL.title.toLowerCase()} set` })}` | |
| 902 | : null} | |
| 898 | 903 | ${o.preview === undefined |
| 899 | 904 | ? null |
| 900 | 905 | : o.preview.ok |
test/game-mods.test.ts +116 −1
| @@ -20,7 +20,11 @@ import { boxNamed, createGameBox, type GameBox } from "../src/games/store.ts"; | ||
| 20 | 20 | import { forgeHttp, type ForgeHttp } from "../src/http/server.ts"; |
| 21 | 21 | import { packVerdict } from "../src/games/pack_check.ts"; |
| 22 | 22 | import { AUTOSTOPPER, commitPolicy } from "../src/games/sleep.ts"; |
| 23 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 24 | import { gameModsScreen } from "../src/tui/screens/game_mods.ts"; | |
| 25 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 23 | 26 | import { quietLogs } from "./helpers/globals.ts"; |
| 27 | import { settleUntil } from "./helpers/tui.ts"; | |
| 24 | 28 | |
| 25 | 29 | quietLogs(); |
| 26 | 30 | |
| @@ -37,6 +41,11 @@ const COMPOSE = `services: | ||
| 37 | 41 | environment: |
| 38 | 42 | TYPE: FABRIC |
| 39 | 43 | VERSION: "1.21.4" |
| 44 | smp: | |
| 45 | image: itzg/minecraft-server | |
| 46 | environment: | |
| 47 | TYPE: FABRIC | |
| 48 | VERSION: "1.21.4" | |
| 40 | 49 | proxy: |
| 41 | 50 | image: itzg/mc-proxy |
| 42 | 51 | environment: |
| @@ -46,7 +55,7 @@ const COMPOSE = `services: | ||
| 46 | 55 | |
| 47 | 56 | // ---- a stand-in Modrinth ---- |
| 48 | 57 | |
| 49 | const sha = (c: string): string => c.repeat(128); | |
| 58 | const sha = (c: string): string => c.repeat(128 / c.length); | |
| 50 | 59 | const sha512Prefix = (c: string): string => sha(c).slice(0, 32); |
| 51 | 60 | interface V { |
| 52 | 61 | id: string; |
| @@ -138,7 +147,12 @@ const PROJECTS = [ | ||
| 138 | 147 | { id: "COid0001", slug: "clientonly", title: "ClientOnly", server_side: "unsupported" }, |
| 139 | 148 | { id: "QTid0001", slug: "bad,slug", title: "Comma" }, |
| 140 | 149 | { id: "FNid0001", slug: "farfile", title: "FarFile" }, |
| 150 | { id: "LIid0001", slug: "lithium", title: "Lithium" }, | |
| 151 | { id: "SLid0001", slug: "scalablelux", title: "ScalableLux" }, | |
| 152 | { id: "NOid0001", slug: "noisium", title: "Noisium" }, | |
| 153 | { id: "FPid0001", slug: "fabric-api", title: "Fabric API" }, | |
| 141 | 154 | ]; |
| 155 | const FABRIC = ["fabric"]; | |
| 142 | 156 | const PAPER = ["paper", "spigot"]; |
| 143 | 157 | const VERSIONS: V[] = [ |
| 144 | 158 | { id: "LPv00001", project: "LPid0001", number: "5.4.100", date: "2024-10-01", games: ["1.21.4"], loaders: PAPER, hash: "1" }, |
| @@ -185,6 +199,20 @@ const VERSIONS: V[] = [ | ||
| 185 | 199 | { id: "QTv00001", project: "QTid0001", number: "1.0", date: "2024-12-07", games: ["1.21.4"], loaders: PAPER, hash: "d" }, |
| 186 | 200 | { id: "FNv00001", project: "FNid0001", number: "1.0", date: "2024-12-08", games: ["1.21.4"], loaders: PAPER, hash: "e", filename: "../x.jar" }, |
| 187 | 201 | { id: "VPv00001", project: "VPid0001", number: "3.1", date: "2024-12-06", games: ["1.21.4", "1.21.3"], loaders: ["velocity"], hash: "c" }, |
| 202 | { id: "LIv00001", project: "LIid0001", number: "0.17.0", date: "2025-01-01", games: ["1.21.4"], loaders: FABRIC, hash: "1a" }, | |
| 203 | { id: "SLv00001", project: "SLid0001", number: "0.1.5", date: "2025-01-02", games: ["1.21.4"], loaders: FABRIC, hash: "1b" }, | |
| 204 | { id: "NOv00001", project: "NOid0001", number: "2.0", date: "2025-01-03", games: ["1.21.4"], loaders: FABRIC, hash: "1c" }, | |
| 205 | { id: "FPv00001", project: "FPid0001", number: "0.119.2", date: "2025-01-04", games: ["1.21.4"], loaders: FABRIC, hash: "1d" }, | |
| 206 | { | |
| 207 | id: "CHv00002", | |
| 208 | project: "CHid0001", | |
| 209 | number: "1.4.28-fabric", | |
| 210 | date: "2025-01-05", | |
| 211 | games: ["1.21.4"], | |
| 212 | loaders: FABRIC, | |
| 213 | hash: "1e", | |
| 214 | deps: [{ project_id: "FPid0001", version_id: null, dependency_type: "required" }], | |
| 215 | }, | |
| 188 | 216 | { id: "PKv00001", project: "PKid0001", number: "1.0.0", date: "2024-11-01", games: ["1.21.1"], loaders: ["fabric"], hash: sha512(PACK1), mrpack: PACK1 }, |
| 189 | 217 | // Its bytes are not the ones its sha512 names. |
| 190 | 218 | { id: "BPv00001", project: "BPid0001", number: "1.0.0", date: "2024-11-01", games: ["1.21.1"], loaders: ["fabric"], hash: sha512(PACK2), mrpack: PACK1 }, |
| @@ -691,3 +719,90 @@ describe("the page and the MCP tool", () => { | ||
| 691 | 719 | expect((listed.value["installed"] as { project: string }[]).map((p) => p.project)).toContain("chunkylib"); |
| 692 | 720 | }); |
| 693 | 721 | }); |
| 722 | ||
| 723 | describe("the survival performance set", () => { | |
| 724 | const SLUGS = ["chunky", "fabric-api", "lithium", "noisium", "scalablelux"]; | |
| 725 | const mcp = async (args: Record<string, unknown>) => { | |
| 726 | const res = await http.handle( | |
| 727 | new Request(`${ORIGIN}/mcp`, { | |
| 728 | method: "POST", | |
| 729 | headers: { authorization: `Bearer ${tok}`, "content-type": "application/json", accept: "application/json, text/event-stream" }, | |
| 730 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "games", arguments: { box: "net", service: "smp", ...args } } }), | |
| 731 | }), | |
| 732 | ); | |
| 733 | const body = (await res.json()) as { result: { isError?: boolean; content: { text: string }[] } }; | |
| 734 | return { error: body.result.isError === true, value: JSON.parse(body.result.content[0]!.text) as Record<string, unknown> }; | |
| 735 | }; | |
| 736 | ||
| 737 | test("a plan names the four mods and Fabric API, and writes nothing", async () => { | |
| 738 | const m = await mods("smp"); | |
| 739 | const planned = await planInstall(app, m, "smp", "set:survival"); | |
| 740 | if (!planned.ok) throw new Error(planned.error); | |
| 741 | expect(planned.value.lock.map((l) => l.slug)).toEqual(SLUGS); | |
| 742 | expect(planned.value.lines).toEqual( | |
| 743 | expect.arrayContaining(["Adds Lithium 0.17.0", "Adds ScalableLux 0.1.5", "Adds Noisium 2.0", "Adds Chunky 1.4.28-fabric", "Adds Fabric API 0.119.2 (required by Chunky)"]), | |
| 744 | ); | |
| 745 | expect(planned.value.lock.find((l) => l.slug === "fabric-api")!.top).toBe(false); | |
| 746 | expect(planned.value.env["MODRINTH_DOWNLOAD_DEPENDENCIES"]).toBe("none"); | |
| 747 | expect((await mods("smp")).lock).toEqual([]); | |
| 748 | }); | |
| 749 | ||
| 750 | test("a server on another loader is refused with the reason", async () => { | |
| 751 | const paper = await planInstall(app, await mods("hub"), "hub", "set:survival"); | |
| 752 | expect(paper).toMatchObject({ ok: false, error: expect.stringContaining("Fabric servers") }); | |
| 753 | const unknown = await planInstall(app, await mods("smp"), "smp", "set:nothing"); | |
| 754 | expect(unknown).toMatchObject({ ok: false, error: expect.stringContaining("no set called nothing") }); | |
| 755 | }); | |
| 756 | ||
| 757 | test("the page offers it, previews it, and one commit locks all five", async () => { | |
| 758 | const offered = await (await asAlice("/games/net/smp")).text(); | |
| 759 | expect(offered).toContain("Preview the set"); | |
| 760 | expect(offered).toContain("Preview the set"); | |
| 761 | const preview = await (await asAlice("/games/net/smp?add=set:survival")).text(); | |
| 762 | expect(preview).toContain("Adds Noisium 2.0"); | |
| 763 | expect(preview).toContain("Install and restart"); | |
| 764 | const r = await asAlice("/games/net/smp/mods/install", { project: "set:survival", sha: (await mods("smp")).sha }); | |
| 765 | expect(r.status).toBe(303); | |
| 766 | const text = (await readCompose(app, box))!.text; | |
| 767 | const env = serviceEnv(text, "smp"); | |
| 768 | for (const slug of ["lithium", "scalablelux", "noisium", "chunky", "fabric-api"]) expect(env["MODRINTH_PROJECTS"]).toContain(`${slug}:`); | |
| 769 | const lock = JSON.parse((await readRepoFile(app, box, (await readCompose(app, box))!.sha, lockPath(box, "smp")))!) as { projects: { slug: string; sha512: string }[] }; | |
| 770 | expect(lock.projects.map((p) => p.slug).sort()).toEqual(SLUGS); | |
| 771 | expect(lock.projects.every((p) => p.sha512.length === 128)).toBe(true); | |
| 772 | // Installed: no longer offered, and planning it again says so. | |
| 773 | expect(await (await asAlice("/games/net/smp")).text()).not.toContain("Preview the set"); | |
| 774 | expect(await planInstall(app, await mods("smp"), "smp", "set:survival")).toMatchObject({ ok: false, error: expect.stringContaining("is installed") }); | |
| 775 | }); | |
| 776 | ||
| 777 | test("the MCP tool plans the set and commits it with dryRun false", async () => { | |
| 778 | // Remove one of its four so the set has something to add: the plan adds only what is missing. | |
| 779 | const removed = await planRemove(await mods("smp"), "smp", "noisium"); | |
| 780 | if (!removed.ok) throw new Error(removed.error); | |
| 781 | const gone = await commitPlan(app, alice, box, "smp", await mods("smp"), removed.value); | |
| 782 | expect(gone.ok).toBe(true); | |
| 783 | const planned = await mcp({ action: "mods_install", project: "set:survival" }); | |
| 784 | expect(planned.value).toMatchObject({ planned: true, lines: expect.arrayContaining(["Adds Noisium 2.0"]) }); | |
| 785 | expect((await mods("smp")).lock.some((l) => l.slug === "noisium")).toBe(false); | |
| 786 | const done = await mcp({ action: "mods_install", project: "set:survival", dryRun: false }); | |
| 787 | expect(done.error).toBe(false); | |
| 788 | expect((await mods("smp")).lock.some((l) => l.slug === "noisium")).toBe(true); | |
| 789 | }); | |
| 790 | ||
| 791 | test("the terminal shows the set as the page does, and s previews it", async () => { | |
| 792 | const removed = await planRemove(await mods("smp"), "smp", "lithium"); | |
| 793 | if (!removed.ok) throw new Error(removed.error); | |
| 794 | await commitPlan(app, alice, box, "smp", await mods("smp"), removed.value); | |
| 795 | const terminal = headlessTerminal(160, 30); | |
| 796 | const { app: tui, session } = createForgeApp(app, { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: alice }, { terminal, exitHooks: false }); | |
| 797 | tui.start(); | |
| 798 | tui.ctx.push(gameModsScreen(session, tui.ctx, box, "smp")); | |
| 799 | await settleUntil(tui, "Survival performance set"); | |
| 800 | terminal.feed("s"); | |
| 801 | await settleUntil(tui, "Adds Lithium 0.17.0"); | |
| 802 | expect(tui.screen.toText()).toContain("y commits it"); | |
| 803 | terminal.feed("y"); | |
| 804 | await settleUntil(tui, "is installed"); | |
| 805 | expect((await mods("smp")).lock.some((l) => l.slug === "lithium")).toBe(true); | |
| 806 | tui.stop?.(); | |
| 807 | }); | |
| 808 | }); |
new above
offline
Duplicates the 'set still to offer' test from the terminal screen and from
planSet. Move it to one function inmod_sets.ts(e.g.missing(set, lock)) and call it here, ingame_mods.tsand inplanSet.