@roster-lock/match-agent 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/dist/assets/index-D2395vmC.css +1 -0
- package/client/dist/assets/index-DcKsa72V.js +125 -0
- package/client/dist/index.html +2 -2
- package/client/e2e/lib/env.ts +50 -0
- package/client/e2e/lib/fileDialog.ts +31 -0
- package/client/e2e/lib/mockGamepad.ts +71 -0
- package/client/e2e/lib/onscreenKeyboard.ts +32 -0
- package/client/e2e/playwright.config.ts +48 -0
- package/client/e2e/tests/gamepad-only.spec.ts +274 -0
- package/client/e2e/tests/keyboard-only.spec.ts +67 -0
- package/client/e2e/tsconfig.json +15 -0
- package/client/node_modules/.bin/playwright +17 -0
- package/client/node_modules/.bin/roster-lock-plugin-manager +17 -0
- package/client/node_modules/.vite/deps/@rjsf_core.js +95 -95
- package/client/node_modules/.vite/deps/@rjsf_validator-ajv8.js +4 -3
- package/client/node_modules/.vite/deps/@roster-lock_ts-client.js +25 -25
- package/client/node_modules/.vite/deps/@roster-lock_types.js +2 -1
- package/client/node_modules/.vite/deps/@roster-lock_utils.js +2 -1
- package/client/node_modules/.vite/deps/_metadata.json +27 -27
- package/client/node_modules/.vite/deps/{chunk-NE7PXY4V.js → chunk-3HBL6DQ6.js} +99 -98
- package/client/node_modules/.vite/deps/{chunk-NE7PXY4V.js.map → chunk-3HBL6DQ6.js.map} +3 -3
- package/client/node_modules/.vite/deps/{chunk-4D2L7OBZ.js → chunk-3IRPLLFB.js} +498 -501
- package/client/node_modules/.vite/deps/{chunk-4D2L7OBZ.js.map → chunk-3IRPLLFB.js.map} +1 -1
- package/client/node_modules/.vite/deps/{chunk-I55GDNGV.js → chunk-7DRNB6P7.js} +5 -5
- package/client/node_modules/.vite/deps/{chunk-77TXW5ZT.js → chunk-FFVS6IUX.js} +6 -6
- package/client/node_modules/.vite/deps/{chunk-5KLROPUR.js → chunk-G44QLPFQ.js} +6 -6
- package/client/node_modules/.vite/deps/{chunk-IIDO6PKU.js → chunk-QTQN6EZX.js} +98 -98
- package/client/node_modules/.vite/deps/chunk-QTQN6EZX.js.map +7 -0
- package/client/node_modules/.vite/deps/chunk-WMTNK64S.js +1 -0
- package/client/node_modules/.vite/deps/react-dom.js +3 -2
- package/client/node_modules/.vite/deps/react-dom_client.js +12 -12
- package/client/node_modules/.vite/deps/react-dom_client.js.map +1 -1
- package/client/node_modules/.vite/deps/react-router-dom.js +42 -9
- package/client/node_modules/.vite/deps/react.js +2 -1
- package/client/node_modules/.vite/deps/react_jsx-dev-runtime.js +5 -5
- package/client/node_modules/.vite/deps/react_jsx-runtime.js +3 -2
- package/client/package.json +4 -1
- package/client/src/App.tsx +23 -14
- package/client/src/NavBar.tsx +15 -5
- package/client/src/api/matchAgent.ts +208 -5
- package/client/src/bridge/hostBridge.ts +39 -10
- package/client/src/components/FullScreenMenu.tsx +32 -0
- package/client/src/components/GameLauncherSettingsForm.tsx +80 -5
- package/client/src/components/InputHints.tsx +37 -0
- package/client/src/components/InstallGameLauncherLightbox.tsx +27 -14
- package/client/src/components/OnScreenFileDialog.tsx +83 -0
- package/client/src/components/OnScreenKeyboard.tsx +75 -0
- package/client/src/components/Selection/PieceCard.tsx +29 -4
- package/client/src/components/Selection/PiecePreviewPanel.tsx +48 -0
- package/client/src/components/Selection/PieceTypeSection.tsx +124 -46
- package/client/src/components/Selection/PlayerSelectionPanel.tsx +1 -5
- package/client/src/components/Selection/index.tsx +72 -47
- package/client/src/context/GlobalNavContext.tsx +340 -0
- package/client/src/context/SelectionSourceContext.tsx +26 -0
- package/client/src/hooks/useCursorInput.ts +66 -24
- package/client/src/hooks/useDownloadedPieceVersions.ts +39 -0
- package/client/src/hooks/useGridColumns.ts +29 -0
- package/client/src/hooks/useInView.ts +32 -0
- package/client/src/hooks/usePiecePreview.ts +124 -0
- package/client/src/pages/Controls/index.tsx +126 -0
- package/client/src/pages/Game/index.tsx +11 -15
- package/client/src/pages/MatchMaking/index.tsx +14 -7
- package/client/src/pages/PreviewRoster/index.tsx +118 -0
- package/client/src/styles/global.css +355 -6
- package/client/src/utils/inputLabels.ts +25 -0
- package/client/test-results/.last-run.json +4 -0
- package/client/tsconfig.tsbuildinfo +1 -1
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -1
- package/dist/config/inputBindings.js +40 -0
- package/dist/config/inputBindings.js.map +1 -0
- package/dist/config/manage.js +1 -0
- package/dist/config/manage.js.map +1 -1
- package/dist/handle-room/version-1/game-launcher/binaries.js +36 -0
- package/dist/handle-room/version-1/game-launcher/binaries.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/listing.js +24 -0
- package/dist/handle-room/version-1/game-launcher/listing.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/preview.js +38 -0
- package/dist/handle-room/version-1/game-launcher/preview.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/process.js +52 -0
- package/dist/handle-room/version-1/game-launcher/process.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/router.js +32 -0
- package/dist/handle-room/version-1/game-launcher/router.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/settings.js +49 -0
- package/dist/handle-room/version-1/game-launcher/settings.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/shared.js +28 -0
- package/dist/handle-room/version-1/game-launcher/shared.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/start.js +76 -0
- package/dist/handle-room/version-1/game-launcher/start.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/version.js +63 -0
- package/dist/handle-room/version-1/game-launcher/version.js.map +1 -0
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js +22 -9
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js.map +1 -1
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js +50 -1
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js.map +1 -1
- package/dist/handle-room/version-1/index.js +15 -15
- package/dist/handle-room/version-1/index.js.map +1 -1
- package/dist/handle-room/version-1/input-bindings.js +22 -0
- package/dist/handle-room/version-1/input-bindings.js.map +1 -0
- package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js +2 -1
- package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js.map +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/http-handler.js +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/http-handler.js.map +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/steps.js +2 -1
- package/dist/handle-room/version-1/room-handler-bridge/steps.js.map +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js +2 -2
- package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js.map +1 -1
- package/dist/index.js +18 -4
- package/dist/index.js.map +1 -1
- package/dist/util-routers/file-system/env.js +3 -0
- package/dist/util-routers/file-system/env.js.map +1 -0
- package/dist/util-routers/file-system/index.js +31 -0
- package/dist/util-routers/file-system/index.js.map +1 -0
- package/dist/util-routers/file-system/list.js +50 -0
- package/dist/util-routers/file-system/list.js.map +1 -0
- package/dist/util-routers/file-system/resolve-within-root.js +18 -0
- package/dist/util-routers/file-system/resolve-within-root.js.map +1 -0
- package/dist/util-routers/file-system/roster-lock.js +56 -0
- package/dist/util-routers/file-system/roster-lock.js.map +1 -0
- package/dist/utils/pick-file.js +82 -0
- package/dist/utils/pick-file.js.map +1 -0
- package/dist/utils/pick-folder.js +84 -0
- package/dist/utils/pick-folder.js.map +1 -0
- package/package.json +10 -7
- package/src/config/index.ts +8 -3
- package/src/config/inputBindings.ts +56 -0
- package/src/config/manage.ts +7 -0
- package/src/handle-room/version-1/game-launcher/binaries.ts +52 -0
- package/src/handle-room/version-1/game-launcher/listing.ts +36 -0
- package/src/handle-room/version-1/game-launcher/preview.ts +54 -0
- package/src/handle-room/version-1/game-launcher/process.ts +75 -0
- package/src/handle-room/version-1/game-launcher/router.ts +42 -0
- package/src/handle-room/version-1/game-launcher/settings.ts +58 -0
- package/src/handle-room/version-1/game-launcher/shared.ts +34 -0
- package/src/handle-room/version-1/game-launcher/start.ts +113 -0
- package/src/handle-room/version-1/game-launcher/version.ts +85 -0
- package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.ts +39 -14
- package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.ts +83 -1
- package/src/handle-room/version-1/globals/FolderDB/types.ts +24 -0
- package/src/handle-room/version-1/globals/types.ts +24 -2
- package/src/handle-room/version-1/index.ts +27 -25
- package/src/handle-room/version-1/input-bindings.ts +19 -0
- package/src/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.ts +4 -1
- package/src/handle-room/version-1/room-handler-bridge/http-handler.ts +4 -1
- package/src/handle-room/version-1/room-handler-bridge/steps.ts +8 -0
- package/src/handle-room/version-1/room-handler-bridge/ws-handler.ts +2 -2
- package/src/index.ts +42 -10
- package/src/util-routers/file-system/env.ts +7 -0
- package/src/util-routers/file-system/index.ts +23 -0
- package/src/util-routers/file-system/list.ts +62 -0
- package/src/util-routers/file-system/resolve-within-root.ts +25 -0
- package/src/util-routers/file-system/roster-lock.ts +74 -0
- package/src/utils/pick-file.ts +81 -0
- package/src/utils/pick-folder.ts +92 -0
- package/tests/integration/filesystem.test.ts +117 -0
- package/tests/integration/game-launcher-binaries.test.ts +263 -0
- package/tests/integration/game-launcher-game-complete.test.ts +111 -0
- package/tests/integration/game-launcher-preview.test.ts +107 -0
- package/tests/integration/game-launcher-settings.test.ts +123 -8
- package/tests/integration/game-processes-ws.test.ts +122 -0
- package/tests/integration/helpers/fakeFolderDB.ts +16 -0
- package/tests/integration/helpers/fakePluginRuntime.ts +10 -1
- package/tests/integration/helpers/relayHarness.ts +24 -0
- package/tests/integration/helpers/server.ts +23 -3
- package/tests/integration/input-bindings.test.ts +94 -0
- package/tests/integration/piece-ensure-ws.test.ts +1 -1
- package/tests/integration/piece-files.test.ts +1 -1
- package/tests/integration/relay-protocol.test.ts +100 -0
- package/tests/integration/roster-lock.test.ts +86 -0
- package/tests/integration/sync-dl.test.ts +1 -1
- package/vitest.config.ts +7 -1
- package/client/dist/assets/index-DeYshswm.js +0 -125
- package/client/dist/assets/index-gxAuIfGQ.css +0 -1
- package/client/node_modules/.vite/deps/chunk-IIDO6PKU.js.map +0 -7
- package/client/node_modules/.vite/deps_temp_ab51ebe9/package.json +0 -3
- package/dist/handle-room/version-1/game-launcher.js +0 -181
- package/dist/handle-room/version-1/game-launcher.js.map +0 -1
- package/src/handle-room/version-1/game-launcher.ts +0 -263
- /package/client/node_modules/.vite/deps/{chunk-I55GDNGV.js.map → chunk-7DRNB6P7.js.map} +0 -0
- /package/client/node_modules/.vite/deps/{chunk-77TXW5ZT.js.map → chunk-FFVS6IUX.js.map} +0 -0
- /package/client/node_modules/.vite/deps/{chunk-5KLROPUR.js.map → chunk-G44QLPFQ.js.map} +0 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach, vi } from "vitest";
|
|
2
|
+
import { crc32 } from "node:zlib";
|
|
3
|
+
import { mkdir } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { startTestServer, TestServer, errorBody } from "./helpers/server";
|
|
6
|
+
import { makeTempFolder, cleanupFolder } from "./helpers/piece";
|
|
7
|
+
import { createFixturePluginDir } from "./helpers/plugin-dir";
|
|
8
|
+
import { makeValidLockConfig } from "./helpers/validLockConfig";
|
|
9
|
+
|
|
10
|
+
// Duplicated from game-launcher-settings.test.ts (see that file's own
|
|
11
|
+
// comment on buildStoredZip for why) - this test is about match-agent's
|
|
12
|
+
// list/remove routes and SQL usage-tracking, not about zip format details.
|
|
13
|
+
function buildStoredZip(path: string, contents: string): Buffer {
|
|
14
|
+
const nameBuf = Buffer.from(path, "utf8");
|
|
15
|
+
const dataBuf = Buffer.from(contents, "utf8");
|
|
16
|
+
const crc = crc32(dataBuf);
|
|
17
|
+
|
|
18
|
+
const localHeader = Buffer.alloc(30);
|
|
19
|
+
localHeader.writeUInt32LE(0x04034b50, 0);
|
|
20
|
+
localHeader.writeUInt16LE(20, 4);
|
|
21
|
+
localHeader.writeUInt32LE(crc, 14);
|
|
22
|
+
localHeader.writeUInt32LE(dataBuf.length, 18);
|
|
23
|
+
localHeader.writeUInt32LE(dataBuf.length, 22);
|
|
24
|
+
localHeader.writeUInt16LE(nameBuf.length, 26);
|
|
25
|
+
const localSection = Buffer.concat([localHeader, nameBuf, dataBuf]);
|
|
26
|
+
|
|
27
|
+
const centralHeader = Buffer.alloc(46);
|
|
28
|
+
centralHeader.writeUInt32LE(0x02014b50, 0);
|
|
29
|
+
centralHeader.writeUInt16LE(20, 4);
|
|
30
|
+
centralHeader.writeUInt16LE(20, 6);
|
|
31
|
+
centralHeader.writeUInt32LE(crc, 16);
|
|
32
|
+
centralHeader.writeUInt32LE(dataBuf.length, 20);
|
|
33
|
+
centralHeader.writeUInt32LE(dataBuf.length, 24);
|
|
34
|
+
centralHeader.writeUInt16LE(nameBuf.length, 28);
|
|
35
|
+
centralHeader.writeUInt32LE(0, 42);
|
|
36
|
+
const centralSection = Buffer.concat([centralHeader, nameBuf]);
|
|
37
|
+
|
|
38
|
+
const eocd = Buffer.alloc(22);
|
|
39
|
+
eocd.writeUInt32LE(0x06054b50, 0);
|
|
40
|
+
eocd.writeUInt16LE(1, 8);
|
|
41
|
+
eocd.writeUInt16LE(1, 10);
|
|
42
|
+
eocd.writeUInt32LE(centralSection.length, 12);
|
|
43
|
+
eocd.writeUInt32LE(localSection.length, 16);
|
|
44
|
+
|
|
45
|
+
return Buffer.concat([localSection, centralSection, eocd]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const PLUGIN_NAME = "@roster-lock/game-launcher-ikemen-go";
|
|
49
|
+
|
|
50
|
+
const IKEMEN_EXECUTABLE_NAME = (
|
|
51
|
+
process.platform === "win32" ? "Ikemen_GO.exe" : process.platform === "darwin" ? "Ikemen_GO_MacOS" : "Ikemen_GO_Linux"
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
describe("game-launcher binaries list/remove routes", () => {
|
|
55
|
+
const cleanups: Array<() => Promise<void> | void> = [];
|
|
56
|
+
afterEach(async () => {
|
|
57
|
+
while (cleanups.length) await cleanups.pop()!();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
async function setup(): Promise<{ server: TestServer, pluginDir: string }> {
|
|
61
|
+
const fixture = await createFixturePluginDir([PLUGIN_NAME]);
|
|
62
|
+
cleanups.push(fixture.cleanup);
|
|
63
|
+
const folder = await makeTempFolder();
|
|
64
|
+
cleanups.push(() => cleanupFolder(folder));
|
|
65
|
+
const server = await startTestServer(folder, undefined, fixture.pluginDir);
|
|
66
|
+
cleanups.push(() => server.close());
|
|
67
|
+
return { server, pluginDir: fixture.pluginDir };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function auth(server: TestServer): HeadersInit {
|
|
71
|
+
return { Authorization: `Bearer ${server.authCode}` };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Stubs fetch for the plugin's own GitHub/download calls, falling through
|
|
75
|
+
// to the real fetch for everything else (including this test's own calls
|
|
76
|
+
// to the match-agent server) - see game-launcher-settings.test.ts's
|
|
77
|
+
// identically-shaped stub for why both are necessary.
|
|
78
|
+
function stubDownload(zipBuffer: Buffer): () => void {
|
|
79
|
+
const realFetch = globalThis.fetch;
|
|
80
|
+
vi.stubGlobal("fetch", async (url: string, init?: RequestInit) => {
|
|
81
|
+
if (url === "https://api.github.com/repos/ikemen-engine/Ikemen-GO/releases/latest") {
|
|
82
|
+
return {
|
|
83
|
+
ok: true, status: 200,
|
|
84
|
+
json: async () => ({
|
|
85
|
+
tag_name: "v1.0.0",
|
|
86
|
+
assets: [{ name: "Ikemen_GO-v1.0.0-linux.zip", browser_download_url: "https://example.test/linux.zip" }],
|
|
87
|
+
}),
|
|
88
|
+
} as Response;
|
|
89
|
+
}
|
|
90
|
+
if (url === "https://example.test/linux.zip") {
|
|
91
|
+
const { Readable } = await import("node:stream");
|
|
92
|
+
return { ok: true, status: 200, body: Readable.toWeb(Readable.from(zipBuffer)) } as unknown as Response;
|
|
93
|
+
}
|
|
94
|
+
return realFetch(url, init);
|
|
95
|
+
});
|
|
96
|
+
return () => vi.unstubAllGlobals();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
it("GET binaries returns [] before anything has been downloaded", async () => {
|
|
100
|
+
const { server } = await setup();
|
|
101
|
+
const res = await fetch(
|
|
102
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/binaries?platform=linux&arch=x64`,
|
|
103
|
+
{ headers: auth(server) }
|
|
104
|
+
);
|
|
105
|
+
expect(res.status).toBe(200);
|
|
106
|
+
expect(await res.json()).toEqual([]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// version comes back null here, not a real {title,id} - the fake zip's
|
|
110
|
+
// "binary" is just a text file, and ikemen-go's getLocalVersion correctly
|
|
111
|
+
// refuses to call that a real Ikemen GO build (see readLocalVersion in
|
|
112
|
+
// plugins/game-launcher/ikemen-go/src/version.ts). Still listed, with
|
|
113
|
+
// downloadedAt/active populated from match-agent's own SQL tracking -
|
|
114
|
+
// exactly the "folder exists but doesn't look like a real install"
|
|
115
|
+
// scenario listBinaries is designed to surface rather than hide.
|
|
116
|
+
it("GET binaries reports what update downloaded, with downloadedAt and active true", async () => {
|
|
117
|
+
const { server } = await setup();
|
|
118
|
+
const unstub = stubDownload(buildStoredZip(IKEMEN_EXECUTABLE_NAME, "fake engine binary"));
|
|
119
|
+
try {
|
|
120
|
+
const updateRes = await fetch(
|
|
121
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/update?platform=linux&arch=x64`,
|
|
122
|
+
{ method: "POST", headers: auth(server) }
|
|
123
|
+
);
|
|
124
|
+
expect(updateRes.status).toBe(200);
|
|
125
|
+
|
|
126
|
+
const res = await fetch(
|
|
127
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/binaries?platform=linux&arch=x64`,
|
|
128
|
+
{ headers: auth(server) }
|
|
129
|
+
);
|
|
130
|
+
expect(res.status).toBe(200);
|
|
131
|
+
const binaries = await res.json();
|
|
132
|
+
expect(binaries).toHaveLength(1);
|
|
133
|
+
expect(binaries[0].active).toBe(true);
|
|
134
|
+
expect(binaries[0].version).toBeNull();
|
|
135
|
+
expect(typeof binaries[0].downloadedAt).toBe("number");
|
|
136
|
+
expect(binaries[0].lastUsedAt).toBeNull();
|
|
137
|
+
} finally {
|
|
138
|
+
unstub();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("DELETE binaries removes the folder, its usage row, and clears the active setting", async () => {
|
|
143
|
+
const { server } = await setup();
|
|
144
|
+
const unstub = stubDownload(buildStoredZip(IKEMEN_EXECUTABLE_NAME, "fake engine binary"));
|
|
145
|
+
try {
|
|
146
|
+
const updateRes = await fetch(
|
|
147
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/update?platform=linux&arch=x64`,
|
|
148
|
+
{ method: "POST", headers: auth(server) }
|
|
149
|
+
);
|
|
150
|
+
expect(updateRes.status).toBe(200);
|
|
151
|
+
} finally {
|
|
152
|
+
unstub();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const listBefore = await fetch(
|
|
156
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/binaries?platform=linux&arch=x64`,
|
|
157
|
+
{ headers: auth(server) }
|
|
158
|
+
);
|
|
159
|
+
const [{ binaryLocation: absoluteLocation }] = await listBefore.json();
|
|
160
|
+
|
|
161
|
+
const deleteRes = await fetch(
|
|
162
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/binaries?binaryLocation=${encodeURIComponent(absoluteLocation)}`,
|
|
163
|
+
{ method: "DELETE", headers: auth(server) }
|
|
164
|
+
);
|
|
165
|
+
expect(deleteRes.status).toBe(200);
|
|
166
|
+
|
|
167
|
+
const listAfter = await fetch(
|
|
168
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/binaries?platform=linux&arch=x64`,
|
|
169
|
+
{ headers: auth(server) }
|
|
170
|
+
);
|
|
171
|
+
expect(await listAfter.json()).toEqual([]);
|
|
172
|
+
|
|
173
|
+
const settingsRes = await fetch(
|
|
174
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/settings`, { headers: auth(server) }
|
|
175
|
+
);
|
|
176
|
+
expect((await settingsRes.json()).binaryLocation).toBeUndefined();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("DELETE binaries 400s for a path outside the plugin's own dataDir", async () => {
|
|
180
|
+
const { server } = await setup();
|
|
181
|
+
const res = await fetch(
|
|
182
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/binaries?binaryLocation=${encodeURIComponent("/etc/passwd")}`,
|
|
183
|
+
{ method: "DELETE", headers: auth(server) }
|
|
184
|
+
);
|
|
185
|
+
expect(res.status).toBe(400);
|
|
186
|
+
expect((await errorBody(res)).error).toBeTruthy();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("DELETE binaries 400s when binaryLocation query param is missing", async () => {
|
|
190
|
+
const { server } = await setup();
|
|
191
|
+
const res = await fetch(
|
|
192
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/binaries`,
|
|
193
|
+
{ method: "DELETE", headers: auth(server) }
|
|
194
|
+
);
|
|
195
|
+
expect(res.status).toBe(400);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Regression for a bug introduced alongside this feature: startGameLauncher
|
|
199
|
+
// (start.ts) reads binaryLocation straight off stored settings, which
|
|
200
|
+
// getBinary always persists *relative* to pluginDir (see
|
|
201
|
+
// relativizeBinaryLocation's own docs - exactly what a downloaded binary's
|
|
202
|
+
// settings looks like, unlike a hand-typed absolute path). listBinaries
|
|
203
|
+
// and getBinaryUsageFor both key off the *resolved absolute* path, so
|
|
204
|
+
// recording usage against the raw stored (relative) value would silently
|
|
205
|
+
// never match - lastUsedAt would stay null forever for the one case this
|
|
206
|
+
// bookkeeping exists for. Uses the headless fixture (manually seeding a
|
|
207
|
+
// folder under its own dataDir to stand in for what getBinary would have
|
|
208
|
+
// produced) rather than the real ikemen-go plugin, since this is about
|
|
209
|
+
// match-agent's own path bookkeeping, not actually spawning a process -
|
|
210
|
+
// see game-launcher-game-complete.test.ts's identical reasoning for
|
|
211
|
+
// picking headless over a real engine.
|
|
212
|
+
it("POST start records lastUsedAt against the same absolute path GET binaries reports", async () => {
|
|
213
|
+
const HEADLESS = "@roster-lock/game-launcher-headless";
|
|
214
|
+
const fixture = await createFixturePluginDir([HEADLESS]);
|
|
215
|
+
cleanups.push(fixture.cleanup);
|
|
216
|
+
const folder = await makeTempFolder();
|
|
217
|
+
cleanups.push(() => cleanupFolder(folder));
|
|
218
|
+
const server = await startTestServer(folder, undefined, fixture.pluginDir);
|
|
219
|
+
cleanups.push(() => server.close());
|
|
220
|
+
|
|
221
|
+
// Mirrors binariesDataDir's own layout (core/plugin-runtime/src/
|
|
222
|
+
// GameLauncher.ts) - <pluginDir>/data/<pluginName>/binaries/<tag> - without
|
|
223
|
+
// ever calling getBinary itself (headless doesn't implement one).
|
|
224
|
+
const relativeBinaryLocation = join("data", HEADLESS, "binaries", "v1");
|
|
225
|
+
await mkdir(join(fixture.pluginDir, relativeBinaryLocation), { recursive: true });
|
|
226
|
+
|
|
227
|
+
await fetch(`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(HEADLESS)}/settings`, {
|
|
228
|
+
method: "PUT",
|
|
229
|
+
headers: { ...auth(server), "Content-Type": "application/json" },
|
|
230
|
+
// Stored relative, exactly like getBinary would have persisted it -
|
|
231
|
+
// the whole point is that this is NOT already an absolute path.
|
|
232
|
+
body: JSON.stringify({ binaryLocation: relativeBinaryLocation }),
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const startRes = await fetch(`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(HEADLESS)}/start`, {
|
|
236
|
+
method: "POST",
|
|
237
|
+
headers: { ...auth(server), "Content-Type": "application/json" },
|
|
238
|
+
body: JSON.stringify({
|
|
239
|
+
connectionConfig: { type: "internal" },
|
|
240
|
+
currentMachine: { machineId: "m1", publicKey: "pk", privateKey: "sk" },
|
|
241
|
+
allMachines: [],
|
|
242
|
+
selectionResult: {},
|
|
243
|
+
rosterConfig: makeValidLockConfig(),
|
|
244
|
+
gameConfig: { winners: [], resultDelayMs: 0 },
|
|
245
|
+
relayRoomId: "room-binaries-regression",
|
|
246
|
+
}),
|
|
247
|
+
});
|
|
248
|
+
expect(startRes.status).toBe(200);
|
|
249
|
+
|
|
250
|
+
// recordBinaryUsed is fire-and-forget (see start.ts's own comment on
|
|
251
|
+
// why) - give its promise a tick to land before asserting.
|
|
252
|
+
await vi.waitFor(async () => {
|
|
253
|
+
const res = await fetch(
|
|
254
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(HEADLESS)}/binaries?platform=linux&arch=x64`,
|
|
255
|
+
{ headers: auth(server) }
|
|
256
|
+
);
|
|
257
|
+
const binaries = await res.json();
|
|
258
|
+
expect(binaries).toHaveLength(1);
|
|
259
|
+
expect(binaries[0].active).toBe(true);
|
|
260
|
+
expect(typeof binaries[0].lastUsedAt).toBe("number");
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach, vi } from "vitest";
|
|
2
|
+
import { startTestServer, TestServer } from "./helpers/server";
|
|
3
|
+
import { createFixturePluginDir } from "./helpers/plugin-dir";
|
|
4
|
+
import { makeTempFolder, cleanupFolder } from "./helpers/piece";
|
|
5
|
+
import { makeLockConfig, makeHeroSelection } from "./helpers/lockConfig";
|
|
6
|
+
import { makeValidLockConfig } from "./helpers/validLockConfig";
|
|
7
|
+
|
|
8
|
+
const HEADLESS = "@roster-lock/game-launcher-headless";
|
|
9
|
+
const HIGHEST_WINRATE_LOCALLY = "@roster-lock/piece-selection-sort-highest-winrate-locally";
|
|
10
|
+
|
|
11
|
+
// Exercises the one thing no other test does end-to-end: a real
|
|
12
|
+
// GameLauncherPlugin calling the gameEnded() callback match-agent hands it
|
|
13
|
+
// (see game-launcher/start.ts's startGameLauncher), and match-agent turning that
|
|
14
|
+
// into a real pieceSort.handleGameComplete call using the
|
|
15
|
+
// {lockConfig, localUsers, userSelections} a room's selection flow would
|
|
16
|
+
// have stashed in env.gameCompletionContext (see steps.ts's onGameComplete).
|
|
17
|
+
// Uses the headless plugin instead of a real engine so this runs in CI with
|
|
18
|
+
// no binary/display, and seeds gameCompletionContext directly instead of
|
|
19
|
+
// driving a real room negotiation (which needs an actual relay server -
|
|
20
|
+
// see helpers/relayHarness.ts for that heavier, separate concern).
|
|
21
|
+
describe("game-launcher gameEnded -> piece-selection-sort handleGameComplete", () => {
|
|
22
|
+
const cleanups: Array<() => Promise<void> | void> = [];
|
|
23
|
+
afterEach(async () => {
|
|
24
|
+
while (cleanups.length) await cleanups.pop()!();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
async function setup(): Promise<TestServer> {
|
|
28
|
+
const fixture = await createFixturePluginDir([HEADLESS, HIGHEST_WINRATE_LOCALLY]);
|
|
29
|
+
cleanups.push(fixture.cleanup);
|
|
30
|
+
const folder = await makeTempFolder();
|
|
31
|
+
cleanups.push(() => cleanupFolder(folder));
|
|
32
|
+
const server = await startTestServer(folder, undefined, fixture.pluginDir);
|
|
33
|
+
cleanups.push(() => server.close());
|
|
34
|
+
return server;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function auth(server: TestServer): HeadersInit {
|
|
38
|
+
return { Authorization: `Bearer ${server.authCode}` };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function startHeadlessMatch(server: TestServer, relayRoomId: string, winners: Array<string>) {
|
|
42
|
+
await fetch(`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(HEADLESS)}/settings`, {
|
|
43
|
+
method: "PUT",
|
|
44
|
+
headers: { ...auth(server), "Content-Type": "application/json" },
|
|
45
|
+
body: JSON.stringify({ binaryLocation: "headless" }),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return fetch(`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(HEADLESS)}/start`, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: { ...auth(server), "Content-Type": "application/json" },
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
connectionConfig: { type: "internal" },
|
|
53
|
+
currentMachine: { machineId: "m1", publicKey: "pk-a", privateKey: "sk" },
|
|
54
|
+
allMachines: [],
|
|
55
|
+
selectionResult: {},
|
|
56
|
+
// Just needs to pass castLockConfig's AJV schema (unlike
|
|
57
|
+
// makeLockConfig(), used below for the actual winrate bookkeeping) -
|
|
58
|
+
// the headless plugin never reads rosterConfig's contents at all.
|
|
59
|
+
rosterConfig: makeValidLockConfig(),
|
|
60
|
+
gameConfig: { winners, resultDelayMs: 0 },
|
|
61
|
+
relayRoomId,
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
it("calls handleGameComplete once the headless plugin reports a winner", async () => {
|
|
67
|
+
const server = await setup();
|
|
68
|
+
const lockConfig = makeLockConfig();
|
|
69
|
+
const localUsers = ["pk-a:0"];
|
|
70
|
+
const userSelections = { "pk-a:0": makeHeroSelection() };
|
|
71
|
+
// topRanked excludes anything with zero recorded games (see
|
|
72
|
+
// WinRateStore.ts) - a real room's selection flow would already have
|
|
73
|
+
// called handleFullSelection (steps.ts) before the game even started;
|
|
74
|
+
// this test isn't exercising that flow (handle-full-selection.test.ts
|
|
75
|
+
// already does), so it seeds the same call directly.
|
|
76
|
+
await server.env.pluginRuntime.pieceSort.handleFullSelection({ lockConfig, localUsers, userSelections });
|
|
77
|
+
server.env.gameCompletionContext.set("room-1", { lockConfig, localUsers, userSelections });
|
|
78
|
+
|
|
79
|
+
const res = await startHeadlessMatch(server, "room-1", ["pk-a:0"]);
|
|
80
|
+
expect(res.status).toBe(200);
|
|
81
|
+
|
|
82
|
+
// gameEnded fires off the headless plugin's own timer, after the /start
|
|
83
|
+
// response above already returned - poll rather than asserting immediately.
|
|
84
|
+
await vi.waitFor(async () => {
|
|
85
|
+
const ranked = await server.env.pluginRuntime.pieceSort.sortPieces(HIGHEST_WINRATE_LOCALLY, {
|
|
86
|
+
lockConfig, pieceType: "character",
|
|
87
|
+
});
|
|
88
|
+
expect(ranked).toEqual(["1.0.0"]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// The context is single-use - a second game "ending" for the same room
|
|
92
|
+
// should not find leftover state.
|
|
93
|
+
expect(server.env.gameCompletionContext.has("room-1")).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("doesn't fail the request or record anything when no room negotiated this relayRoomId", async () => {
|
|
97
|
+
const server = await setup();
|
|
98
|
+
|
|
99
|
+
const res = await startHeadlessMatch(server, "unknown-room", ["pk-a:0"]);
|
|
100
|
+
expect(res.status).toBe(200);
|
|
101
|
+
|
|
102
|
+
// gameEnded still fires (headless always reports its configured
|
|
103
|
+
// winners) - match-agent should log and drop it, not throw, since the
|
|
104
|
+
// response above already succeeded before gameEnded ever runs.
|
|
105
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
106
|
+
const ranked = await server.env.pluginRuntime.pieceSort.sortPieces(HIGHEST_WINRATE_LOCALLY, {
|
|
107
|
+
lockConfig: makeLockConfig(), pieceType: "character",
|
|
108
|
+
});
|
|
109
|
+
expect(ranked).toEqual([]);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from "vitest";
|
|
2
|
+
import { previewFile, defaultPreviewFor } from "@roster-lock/game-launcher-headless";
|
|
3
|
+
import { startTestServer, TestServer, errorBody } from "./helpers/server";
|
|
4
|
+
import {
|
|
5
|
+
makeEngine, makePiece, makeTempFolder, seedCompletePiece, cleanupFolder, TEST_PIECE_TYPE,
|
|
6
|
+
} from "./helpers/piece";
|
|
7
|
+
import { createFixturePluginDir } from "./helpers/plugin-dir";
|
|
8
|
+
|
|
9
|
+
const PLUGIN_NAME = "@roster-lock/game-launcher-headless";
|
|
10
|
+
// A fixed, test-chosen PiecePreview - not a real image format. What kind of
|
|
11
|
+
// asset a plugin's getPreview actually decodes (png, jpeg, a 3D model, ...)
|
|
12
|
+
// is that plugin's own business (see plugins/game-launcher/ikemen-go/test/
|
|
13
|
+
// preview.test.ts for that); this route just has to pass through whatever
|
|
14
|
+
// GameLauncherPlugin.getPreview/useDefaultPreview hands it, so the fixture
|
|
15
|
+
// used here (headless) never touches a real image codec.
|
|
16
|
+
const LIVE_PREVIEW = { kind: "image" as const, dataUri: "data:application/x-test;base64,bGl2ZQ==" };
|
|
17
|
+
|
|
18
|
+
describe("POST /v1/game-launcher/:pluginName/preview", () => {
|
|
19
|
+
const cleanups: Array<() => Promise<void> | void> = [];
|
|
20
|
+
afterEach(async () => {
|
|
21
|
+
while (cleanups.length) await cleanups.pop()!();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
async function setup(): Promise<{ server: TestServer, folder: string }> {
|
|
25
|
+
const fixture = await createFixturePluginDir([PLUGIN_NAME]);
|
|
26
|
+
cleanups.push(fixture.cleanup);
|
|
27
|
+
const folder = await makeTempFolder();
|
|
28
|
+
cleanups.push(() => cleanupFolder(folder));
|
|
29
|
+
const server = await startTestServer(folder, undefined, fixture.pluginDir);
|
|
30
|
+
cleanups.push(() => server.close());
|
|
31
|
+
return { server, folder };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const engine = makeEngine();
|
|
35
|
+
const piece = makePiece();
|
|
36
|
+
|
|
37
|
+
function post(server: TestServer, body: unknown) {
|
|
38
|
+
return fetch(`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/preview`, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: { Authorization: `Bearer ${server.authCode}`, "Content-Type": "application/json" },
|
|
41
|
+
body: JSON.stringify(body),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
it("400s on a malformed body", async () => {
|
|
46
|
+
const { server } = await setup();
|
|
47
|
+
const res = await post(server, {});
|
|
48
|
+
expect(res.status).toBe(400);
|
|
49
|
+
expect((await errorBody(res)).error).toBe("Bad Form");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("returns the plugin's own getPreview result for a completed piece", async () => {
|
|
53
|
+
const { server, folder } = await setup();
|
|
54
|
+
await seedCompletePiece({
|
|
55
|
+
folder, engine, pieceType: TEST_PIECE_TYPE, piece, folderName: "seen-folder",
|
|
56
|
+
files: previewFile(LIVE_PREVIEW),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const res = await post(server, { engine, pieceType: TEST_PIECE_TYPE, piece });
|
|
60
|
+
expect(res.status).toBe(200);
|
|
61
|
+
const { preview, source } = await res.json();
|
|
62
|
+
expect(preview).toEqual(LIVE_PREVIEW);
|
|
63
|
+
expect(source).toBe("piece");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("returns null when a completed piece has no preview to give", async () => {
|
|
67
|
+
const { server, folder } = await setup();
|
|
68
|
+
await seedCompletePiece({
|
|
69
|
+
folder, engine, pieceType: TEST_PIECE_TYPE, piece, folderName: "no-preview-folder", files: {},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const res = await post(server, { engine, pieceType: TEST_PIECE_TYPE, piece });
|
|
73
|
+
expect(res.status).toBe(200);
|
|
74
|
+
const { preview, source } = await res.json();
|
|
75
|
+
expect(preview).toBeNull();
|
|
76
|
+
// No preview at all - "piece" would tell the selection screen it got a
|
|
77
|
+
// real portrait back and stop it falling through to humanInfo.image.
|
|
78
|
+
expect(source).toBeNull();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("falls back to the plugin's default preview when the piece has never been seen", async () => {
|
|
82
|
+
const { server } = await setup();
|
|
83
|
+
const res = await post(server, { engine, pieceType: TEST_PIECE_TYPE, piece });
|
|
84
|
+
expect(res.status).toBe(200);
|
|
85
|
+
const { preview, source } = await res.json();
|
|
86
|
+
expect(preview).toEqual(defaultPreviewFor(TEST_PIECE_TYPE));
|
|
87
|
+
expect(source).toBe("default");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("also falls back to the default preview when the piece exists but hasn't finished downloading", async () => {
|
|
91
|
+
const { server, folder } = await setup();
|
|
92
|
+
await seedCompletePiece({
|
|
93
|
+
folder, engine, pieceType: TEST_PIECE_TYPE, piece, folderName: "pending-folder",
|
|
94
|
+
files: previewFile(LIVE_PREVIEW), complete: false,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const res = await post(server, { engine, pieceType: TEST_PIECE_TYPE, piece });
|
|
98
|
+
expect(res.status).toBe(200);
|
|
99
|
+
const { preview, source } = await res.json();
|
|
100
|
+
// Not yet downloaded means match-agent never even resolves the on-disk
|
|
101
|
+
// folder getPreview would read from - the seeded preview.json above
|
|
102
|
+
// (which getPreview would happily return if this ever regressed to
|
|
103
|
+
// reading it) must be ignored in favor of useDefaultPreview.
|
|
104
|
+
expect(preview).toEqual(defaultPreviewFor(TEST_PIECE_TYPE));
|
|
105
|
+
expect(source).toBe("default");
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -1,10 +1,53 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach } from "vitest";
|
|
2
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
1
|
+
import { describe, it, expect, afterEach, vi } from "vitest";
|
|
2
|
+
import { mkdir, writeFile, readFile } from "node:fs/promises";
|
|
3
|
+
import { join, isAbsolute } from "node:path";
|
|
4
|
+
import { crc32 } from "node:zlib";
|
|
4
5
|
import { startTestServer, TestServer, errorBody } from "./helpers/server";
|
|
5
6
|
import { makeTempFolder, cleanupFolder } from "./helpers/piece";
|
|
6
7
|
import { createFixturePluginDir } from "./helpers/plugin-dir";
|
|
7
8
|
|
|
9
|
+
// A hand-built "stored" (uncompressed) zip, one file - see
|
|
10
|
+
// plugins/game-launcher/ikemen-go/test/getBinary.test.ts's own copy of
|
|
11
|
+
// this for why (no zip-writing dependency exists in this repo, and the
|
|
12
|
+
// stored method needs nothing beyond a correct CRC32). Duplicated rather
|
|
13
|
+
// than shared across packages for the same reason IKEMEN_EXECUTABLE_NAME
|
|
14
|
+
// above is: this test is about match-agent's own plumbing calling the
|
|
15
|
+
// real plugin, not about the plugin's internals.
|
|
16
|
+
function buildStoredZip(path: string, contents: string): Buffer {
|
|
17
|
+
const nameBuf = Buffer.from(path, "utf8");
|
|
18
|
+
const dataBuf = Buffer.from(contents, "utf8");
|
|
19
|
+
const crc = crc32(dataBuf);
|
|
20
|
+
|
|
21
|
+
const localHeader = Buffer.alloc(30);
|
|
22
|
+
localHeader.writeUInt32LE(0x04034b50, 0);
|
|
23
|
+
localHeader.writeUInt16LE(20, 4);
|
|
24
|
+
localHeader.writeUInt32LE(crc, 14);
|
|
25
|
+
localHeader.writeUInt32LE(dataBuf.length, 18);
|
|
26
|
+
localHeader.writeUInt32LE(dataBuf.length, 22);
|
|
27
|
+
localHeader.writeUInt16LE(nameBuf.length, 26);
|
|
28
|
+
const localSection = Buffer.concat([localHeader, nameBuf, dataBuf]);
|
|
29
|
+
|
|
30
|
+
const centralHeader = Buffer.alloc(46);
|
|
31
|
+
centralHeader.writeUInt32LE(0x02014b50, 0);
|
|
32
|
+
centralHeader.writeUInt16LE(20, 4);
|
|
33
|
+
centralHeader.writeUInt16LE(20, 6);
|
|
34
|
+
centralHeader.writeUInt32LE(crc, 16);
|
|
35
|
+
centralHeader.writeUInt32LE(dataBuf.length, 20);
|
|
36
|
+
centralHeader.writeUInt32LE(dataBuf.length, 24);
|
|
37
|
+
centralHeader.writeUInt16LE(nameBuf.length, 28);
|
|
38
|
+
centralHeader.writeUInt32LE(0, 42);
|
|
39
|
+
const centralSection = Buffer.concat([centralHeader, nameBuf]);
|
|
40
|
+
|
|
41
|
+
const eocd = Buffer.alloc(22);
|
|
42
|
+
eocd.writeUInt32LE(0x06054b50, 0);
|
|
43
|
+
eocd.writeUInt16LE(1, 8);
|
|
44
|
+
eocd.writeUInt16LE(1, 10);
|
|
45
|
+
eocd.writeUInt32LE(centralSection.length, 12);
|
|
46
|
+
eocd.writeUInt32LE(localSection.length, 16);
|
|
47
|
+
|
|
48
|
+
return Buffer.concat([localSection, centralSection, eocd]);
|
|
49
|
+
}
|
|
50
|
+
|
|
8
51
|
const PLUGIN_NAME = "@roster-lock/game-launcher-ikemen-go";
|
|
9
52
|
|
|
10
53
|
// Mirrors plugins/game-launcher/ikemen-go/src/binaryLocation.ts's own mapping -
|
|
@@ -102,15 +145,29 @@ describe("game-launcher local settings/version/update routes", () => {
|
|
|
102
145
|
expect(await res.json()).toEqual({ valid: true });
|
|
103
146
|
});
|
|
104
147
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
148
|
+
// ikemen-go itself now declares getBinary (downloads+extracts the
|
|
149
|
+
// official release zip - see plugins/game-launcher/ikemen-go/src/
|
|
150
|
+
// getBinary.ts, unit-tested there against a mocked fetch; the test below
|
|
151
|
+
// this one exercises the same plugin through the real route instead),
|
|
152
|
+
// so this needs a plugin that genuinely still has no download hook -
|
|
153
|
+
// game-launcher-headless, in its own fixture dir rather than the
|
|
154
|
+
// describe block's shared ikemen-go one.
|
|
155
|
+
it("POST update 400s when the plugin has no getBinary", async () => {
|
|
156
|
+
const headlessPluginName = "@roster-lock/game-launcher-headless";
|
|
157
|
+
const fixture = await createFixturePluginDir([headlessPluginName]);
|
|
158
|
+
cleanups.push(fixture.cleanup);
|
|
159
|
+
const folder = await makeTempFolder();
|
|
160
|
+
cleanups.push(() => cleanupFolder(folder));
|
|
161
|
+
const server = await startTestServer(folder, undefined, fixture.pluginDir);
|
|
162
|
+
cleanups.push(() => server.close());
|
|
163
|
+
|
|
164
|
+
await fetch(`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(headlessPluginName)}/settings`, {
|
|
108
165
|
method: "PUT",
|
|
109
166
|
headers: { ...auth(server), "Content-Type": "application/json" },
|
|
110
|
-
body: JSON.stringify({ binaryLocation: "/opt/
|
|
167
|
+
body: JSON.stringify({ binaryLocation: "/opt/headless" }),
|
|
111
168
|
});
|
|
112
169
|
|
|
113
|
-
const res = await fetch(`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(
|
|
170
|
+
const res = await fetch(`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(headlessPluginName)}/update`, {
|
|
114
171
|
method: "POST",
|
|
115
172
|
headers: auth(server),
|
|
116
173
|
});
|
|
@@ -118,6 +175,64 @@ describe("game-launcher local settings/version/update routes", () => {
|
|
|
118
175
|
expect((await errorBody(res)).error).toMatch(/in-app updates/);
|
|
119
176
|
});
|
|
120
177
|
|
|
178
|
+
// The real ikemen-go plugin's getBinary, through match-agent's actual
|
|
179
|
+
// route - not just the mocked-fetch unit test in the plugin's own
|
|
180
|
+
// package. Proves the two layers actually agree: dataDir gets passed
|
|
181
|
+
// correctly, the returned binaryLocation gets persisted (and comes back
|
|
182
|
+
// relative, same portability reasoning as every other binaryLocation -
|
|
183
|
+
// see docs/v2/binary-location.md), and no binaryLocation has to exist
|
|
184
|
+
// beforehand (unlike every other route in this file - see
|
|
185
|
+
// updateGameLauncherBinary's own comment on why).
|
|
186
|
+
it("POST update downloads the real plugin's binary with no prior binaryLocation, and persists the result", async () => {
|
|
187
|
+
const { server, pluginDir } = await setup();
|
|
188
|
+
|
|
189
|
+
const zipBuffer = buildStoredZip(IKEMEN_EXECUTABLE_NAME, "fake engine binary");
|
|
190
|
+
// stubGlobal replaces fetch for this test's own calls to the match-agent
|
|
191
|
+
// server too, not just the plugin's GitHub/download calls - anything
|
|
192
|
+
// that isn't one of those two has to fall through to the real fetch.
|
|
193
|
+
const realFetch = globalThis.fetch;
|
|
194
|
+
vi.stubGlobal("fetch", async (url: string, init?: RequestInit) => {
|
|
195
|
+
if (url === "https://api.github.com/repos/ikemen-engine/Ikemen-GO/releases/latest") {
|
|
196
|
+
return {
|
|
197
|
+
ok: true, status: 200,
|
|
198
|
+
json: async () => ({
|
|
199
|
+
tag_name: "v1.0.0",
|
|
200
|
+
assets: [{ name: "Ikemen_GO-v1.0.0-linux.zip", browser_download_url: "https://example.test/linux.zip" }],
|
|
201
|
+
}),
|
|
202
|
+
} as Response;
|
|
203
|
+
}
|
|
204
|
+
if (url === "https://example.test/linux.zip") {
|
|
205
|
+
const { Readable } = await import("node:stream");
|
|
206
|
+
return { ok: true, status: 200, body: Readable.toWeb(Readable.from(zipBuffer)) } as unknown as Response;
|
|
207
|
+
}
|
|
208
|
+
return realFetch(url, init);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
const res = await fetch(`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/update?platform=linux&arch=x64`, {
|
|
213
|
+
method: "POST",
|
|
214
|
+
headers: auth(server),
|
|
215
|
+
});
|
|
216
|
+
expect(res.status).toBe(200);
|
|
217
|
+
const body = await res.json();
|
|
218
|
+
expect(body.ok).toBe(true);
|
|
219
|
+
expect(typeof body.binaryLocation).toBe("string");
|
|
220
|
+
|
|
221
|
+
const settingsRes = await fetch(
|
|
222
|
+
`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/settings`, { headers: auth(server) }
|
|
223
|
+
);
|
|
224
|
+
const settings = await settingsRes.json();
|
|
225
|
+
// Lands under pluginDir (data/<plugin>/binaries/<tag>) - portable, so
|
|
226
|
+
// stored relative rather than as the absolute path getBinary returned.
|
|
227
|
+
expect(isAbsolute(settings.binaryLocation)).toBe(false);
|
|
228
|
+
|
|
229
|
+
const binaryPath = join(pluginDir, settings.binaryLocation, IKEMEN_EXECUTABLE_NAME);
|
|
230
|
+
expect(await readFile(binaryPath, "utf8")).toBe("fake engine binary");
|
|
231
|
+
} finally {
|
|
232
|
+
vi.unstubAllGlobals();
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
121
236
|
it("GET process/:handleId 404s for an unknown handle", async () => {
|
|
122
237
|
const { server } = await setup();
|
|
123
238
|
const res = await fetch(`${server.httpUrl}/v1/game-launcher/${encodeURIComponent(PLUGIN_NAME)}/process/not-a-real-handle`, {
|