@puzzmo/cli 1.0.87 → 1.0.89
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/lib/commands/puzzles.js +3 -13
- package/lib/commands/puzzles.js.map +1 -1
- package/lib/commands/rounds.d.ts +13 -0
- package/lib/commands/rounds.js +42 -0
- package/lib/commands/rounds.js.map +1 -0
- package/lib/commands/upload.js +24 -2
- package/lib/commands/upload.js.map +1 -1
- package/lib/index.js +15 -0
- package/lib/index.js.map +1 -1
- package/lib/queries/__generated__/cliRoundFixturesQuery.graphql.d.ts +29 -0
- package/lib/queries/__generated__/cliRoundFixturesQuery.graphql.js +184 -0
- package/lib/queries/__generated__/cliRoundFixturesQuery.graphql.js.map +1 -0
- package/lib/queries/rounds.d.ts +10 -0
- package/lib/queries/rounds.js +30 -0
- package/lib/queries/rounds.js.map +1 -0
- package/lib/util/api.d.ts +8 -0
- package/lib/util/api.js +22 -3
- package/lib/util/api.js.map +1 -1
- package/lib/util/discoverGames.d.ts +13 -0
- package/lib/util/discoverGames.js +27 -1
- package/lib/util/discoverGames.js.map +1 -1
- package/lib/util/tokenForGame.d.ts +3 -0
- package/lib/util/tokenForGame.js +14 -0
- package/lib/util/tokenForGame.js.map +1 -0
- package/package.json +1 -1
- package/schemas/puzzmo-file-schema.json +4 -0
- package/src/commands/puzzles.ts +3 -12
- package/src/commands/rounds.ts +56 -0
- package/src/commands/upload.test.ts +164 -0
- package/src/commands/upload.ts +27 -2
- package/src/index.ts +17 -0
- package/src/queries/__generated__/cliRoundFixturesQuery.graphql.ts +222 -0
- package/src/queries/rounds.ts +32 -0
- package/src/util/api.ts +38 -5
- package/src/util/discoverGames.ts +41 -1
- package/src/util/tokenForGame.ts +12 -0
package/lib/util/api.js
CHANGED
|
@@ -46,8 +46,10 @@ const readResponse = async (res, url, step, verbose) => {
|
|
|
46
46
|
const body = json;
|
|
47
47
|
const serverMsg = body.error || res.statusText || "Unknown error";
|
|
48
48
|
const validation = body.validationErrors?.length ? `\n - ${body.validationErrors.join("\n - ")}` : "";
|
|
49
|
+
// A server bundle that fails its checks sends back what it logged, which is usually the clue
|
|
50
|
+
const logs = body.logs?.length ? `\n It logged:\n ${body.logs.join("\n ")}` : "";
|
|
49
51
|
const detail = verbose ? `\n${JSON.stringify(json, null, 2)}` : "";
|
|
50
|
-
throw new Error(`Server error during ${step} (${res.status} from ${url}): ${serverMsg}${validation}${detail}`);
|
|
52
|
+
throw new Error(`Server error during ${step} (${res.status} from ${url}): ${serverMsg}${validation}${logs}${detail}`);
|
|
51
53
|
}
|
|
52
54
|
return json;
|
|
53
55
|
};
|
|
@@ -95,7 +97,7 @@ const formatBytes = (bytes) => {
|
|
|
95
97
|
};
|
|
96
98
|
/** Multi-step upload: init -> batched file uploads -> complete */
|
|
97
99
|
export const uploadFiles = async (apiURL, token, gameSlug, sha, filePaths, baseDir, puzzmoFile, onProgress, options = {}) => {
|
|
98
|
-
const { verbose = false, description, repoURL, iconSVG, helpMD } = options;
|
|
100
|
+
const { verbose = false, description, repoURL, iconSVG, helpMD, serverBundle } = options;
|
|
99
101
|
if (verbose)
|
|
100
102
|
console.log(` API URL: ${apiURL}`);
|
|
101
103
|
// Step 1: Init session (includes puzzmo.json metadata)
|
|
@@ -119,7 +121,22 @@ export const uploadFiles = async (apiURL, token, gameSlug, sha, filePaths, baseD
|
|
|
119
121
|
totalUploaded += batch.length;
|
|
120
122
|
onProgress?.(batchNum, totalBatches, totalUploaded);
|
|
121
123
|
}
|
|
122
|
-
// Step 3:
|
|
124
|
+
// Step 3: The server bundle, before completing, so a bundle Puzzmo refuses fails the upload rather than live play
|
|
125
|
+
let serverBundleResult = null;
|
|
126
|
+
let serverBundleWarnings = [];
|
|
127
|
+
if (serverBundle) {
|
|
128
|
+
const step = "server bundle upload";
|
|
129
|
+
const bundleURL = `${apiURL}/cliUpload/${init.sessionID}/serverBundle?encoding=base64`;
|
|
130
|
+
const res = await fetchWithContext(bundleURL, {
|
|
131
|
+
method: "POST",
|
|
132
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/octet-stream" },
|
|
133
|
+
body: Buffer.from(serverBundle).toString("base64"),
|
|
134
|
+
}, step, verbose);
|
|
135
|
+
const checked = (await readResponse(res, bundleURL, step, verbose));
|
|
136
|
+
serverBundleResult = checked.capabilities;
|
|
137
|
+
serverBundleWarnings = checked.warnings ?? [];
|
|
138
|
+
}
|
|
139
|
+
// Step 4: Complete
|
|
123
140
|
const complete = (await jsonPost(`${apiURL}/cliUpload/${init.sessionID}/complete`, token, {}, "upload complete", verbose));
|
|
124
141
|
if (verbose)
|
|
125
142
|
console.log(` Assets base: ${complete.assetsBase}`);
|
|
@@ -130,6 +147,8 @@ export const uploadFiles = async (apiURL, token, gameSlug, sha, filePaths, baseD
|
|
|
130
147
|
helpChanged: !!init.helpChanged,
|
|
131
148
|
gameURL: init.gameURL ?? null,
|
|
132
149
|
versionsURL: init.versionsURL ?? null,
|
|
150
|
+
serverBundle: serverBundleResult,
|
|
151
|
+
serverBundleWarnings,
|
|
133
152
|
};
|
|
134
153
|
};
|
|
135
154
|
//# sourceMappingURL=api.js.map
|
package/lib/util/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/util/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/util/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAyB5B,MAAM,SAAS,GAAG,EAAE,CAAA;AAEpB,4FAA4F;AAC5F,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAExB;IADlB,YACkB,IAAY,EAC5B,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAA;QAHE,SAAI,GAAJ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AK,EAAE,EAAE,EAAE,iBAAiB,EAAE,OAAO,CAAC,CAGxH,CAAA;IACD,IAAI,OAAO;QAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAA;IACjE,OAAO;QACL,GAAG,QAAQ;QACX,mBAAmB,EAAE,CAAC,CAAC,IAAI,CAAC,mBAAmB;QAC/C,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW;QAC/B,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW;QAC/B,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI;QAC7B,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,IAAI;QACrC,YAAY,EAAE,kBAAkB;QAChC,oBAAoB;KACrB,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -16,6 +16,17 @@ export type DiscoveredGame = {
|
|
|
16
16
|
iconPath: string | null;
|
|
17
17
|
/** Absolute path to the help Markdown named by `game.helpPath`, or null when the file sets no help */
|
|
18
18
|
helpPath: string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Absolute path to the private server bundle to upload: `output.serverBundle` when set, otherwise dist-server/server-bundle.js beside
|
|
21
|
+
* the dist folder if that exists, otherwise null
|
|
22
|
+
*/
|
|
23
|
+
serverBundlePath: string | null;
|
|
24
|
+
};
|
|
25
|
+
/** Games which would all upload the same server bundle file */
|
|
26
|
+
export type SharedServerBundle = {
|
|
27
|
+
/** Absolute (real) path of the file they share */
|
|
28
|
+
serverBundlePath: string;
|
|
29
|
+
slugs: string[];
|
|
19
30
|
};
|
|
20
31
|
/** A puzzmo.json that was found but could not be used (invalid JSON, schema errors, missing dist) */
|
|
21
32
|
export type DiscoveryError = {
|
|
@@ -40,3 +51,5 @@ export type DiscoverOptions = {
|
|
|
40
51
|
};
|
|
41
52
|
/** Walks `rootDir` looking for puzzmo.json files, validates each, and resolves their dist directory */
|
|
42
53
|
export declare const discoverGames: (rootDir: string, options?: DiscoverOptions) => Promise<DiscoveryResult>;
|
|
54
|
+
/** Groups the games whose uploads would send the same server bundle file, so one game's bundle can't go up as another's */
|
|
55
|
+
export declare const findSharedServerBundles: (games: DiscoveredGame[]) => SharedServerBundle[];
|
|
@@ -50,14 +50,30 @@ export const discoverGames = async (rootDir, options = {}) => {
|
|
|
50
50
|
fileErrors.push(`Dist folder is empty: ${distDir}`);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
// Only an explicit path can be missing: the default is optional, as most games have no server bundle.
|
|
54
|
+
const serverBundlePath = resolveServerBundlePath(puzzmoFile, puzzmoJsonDir, distDir);
|
|
55
|
+
const configuredServerBundle = puzzmoFile.output?.serverBundle;
|
|
56
|
+
if (requireDist && configuredServerBundle && serverBundlePath && !isFile(serverBundlePath))
|
|
57
|
+
fileErrors.push(`Server bundle not found for ${puzzmoFile.game.slug}: "${configuredServerBundle}" (${serverBundlePath}) does not exist. Build the game first, or fix "output.serverBundle" in puzzmo.json.`);
|
|
53
58
|
if (fileErrors.length) {
|
|
54
59
|
errors.push({ puzzmoJsonPath, slug: puzzmoFile.game.slug, errors: fileErrors });
|
|
55
60
|
continue;
|
|
56
61
|
}
|
|
57
|
-
games.push({ puzzmoJsonPath, puzzmoJsonDir, puzzmoFile, distDir: distDir ?? "", iconPath, helpPath });
|
|
62
|
+
games.push({ puzzmoJsonPath, puzzmoJsonDir, puzzmoFile, distDir: distDir ?? "", iconPath, helpPath, serverBundlePath });
|
|
58
63
|
}
|
|
59
64
|
return { games, errors };
|
|
60
65
|
};
|
|
66
|
+
/** Groups the games whose uploads would send the same server bundle file, so one game's bundle can't go up as another's */
|
|
67
|
+
export const findSharedServerBundles = (games) => {
|
|
68
|
+
const slugsByPath = new Map();
|
|
69
|
+
for (const game of games) {
|
|
70
|
+
if (!game.serverBundlePath)
|
|
71
|
+
continue;
|
|
72
|
+
const realPath = safeRealpath(game.serverBundlePath) ?? game.serverBundlePath;
|
|
73
|
+
slugsByPath.set(realPath, [...(slugsByPath.get(realPath) ?? []), game.puzzmoFile.game.slug]);
|
|
74
|
+
}
|
|
75
|
+
return [...slugsByPath].filter(([, slugs]) => slugs.length > 1).map(([serverBundlePath, slugs]) => ({ serverBundlePath, slugs }));
|
|
76
|
+
};
|
|
61
77
|
/** Recursively finds puzzmo.json files under `dir`, skipping output / vendored folders. Tracks realpaths to avoid symlink cycles. */
|
|
62
78
|
const findPuzzmoJsonFiles = (dir) => {
|
|
63
79
|
const found = [];
|
|
@@ -113,6 +129,16 @@ const resolveDistDir = (puzzmoFile, puzzmoJsonDir, repoRoot) => {
|
|
|
113
129
|
}
|
|
114
130
|
return null;
|
|
115
131
|
};
|
|
132
|
+
/** Resolves `output.serverBundle` when set, otherwise the dist-server/server-bundle.js beside dist if one was built */
|
|
133
|
+
const resolveServerBundlePath = (puzzmoFile, puzzmoJsonDir, distDir) => {
|
|
134
|
+
if (puzzmoFile.output?.serverBundle)
|
|
135
|
+
return path.resolve(puzzmoJsonDir, puzzmoFile.output.serverBundle);
|
|
136
|
+
if (!distDir)
|
|
137
|
+
return null;
|
|
138
|
+
// serverBundlePlugin writes it beside dist, never in it, so it can't be served to players
|
|
139
|
+
const sibling = path.join(path.dirname(distDir), "dist-server", "server-bundle.js");
|
|
140
|
+
return isFile(sibling) ? sibling : null;
|
|
141
|
+
};
|
|
116
142
|
/** Returns the directories from `start` walking up to (and including) `stop` */
|
|
117
143
|
const walkUp = (start, stop) => {
|
|
118
144
|
const dirs = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discoverGames.js","sourceRoot":"","sources":["../../src/util/discoverGames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAmB,KAAK,IAAI,UAAU,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAGxF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,iFAAiF;AACjF,MAA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AAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AACpD,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { fetchGameSlugsForToken } from "../queries/puzzlePool.js";
|
|
2
|
+
import { getTokens, isServerReachable, sortByServerPriority, sourceToURL } from "./config.js";
|
|
3
|
+
/** Finds the first saved token, in server priority order, whose team owns the game */
|
|
4
|
+
export const findTokenForGame = async (gameSlug) => {
|
|
5
|
+
for (const entry of sortByServerPriority(getTokens())) {
|
|
6
|
+
if (!(await isServerReachable(entry.source)))
|
|
7
|
+
continue;
|
|
8
|
+
const slugs = await fetchGameSlugsForToken(sourceToURL(entry.source), entry.token).catch(() => null);
|
|
9
|
+
if (slugs?.includes(gameSlug))
|
|
10
|
+
return entry;
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=tokenForGame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenForGame.js","sourceRoot":"","sources":["../../src/util/tokenForGame.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAA;AAE9G,sFAAsF;AACtF,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,QAAgB,EAA8B,EAAE;IACrF,KAAK,MAAM,KAAK,IAAI,oBAAoB,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC;QACtD,IAAI,CAAC,CAAC,MAAM,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAAE,SAAQ;QACtD,MAAM,KAAK,GAAG,MAAM,sBAAsB,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;QACpG,IAAI,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,KAAK,CAAA;IAC7C,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -437,6 +437,10 @@
|
|
|
437
437
|
"dir": {
|
|
438
438
|
"type": "string",
|
|
439
439
|
"description": "Path to the built artifacts. Resolved relative to the puzzmo.json's directory. Can be shared across games (e.g. `../../dist/<slug>`) or per-game (e.g. `./build`)."
|
|
440
|
+
},
|
|
441
|
+
"serverBundle": {
|
|
442
|
+
"type": "string",
|
|
443
|
+
"description": "Path to the built server bundle file. Resolved relative to the puzzmo.json's directory, like `dir`. Set it per game when one repo builds several games; otherwise `puzzmo games upload` looks for `dist-server/server-bundle.js` beside the output folder."
|
|
440
444
|
}
|
|
441
445
|
},
|
|
442
446
|
"required": ["dir"],
|
package/src/commands/puzzles.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs"
|
|
2
2
|
import path from "node:path"
|
|
3
3
|
|
|
4
|
-
import { addPuzzlesToPool,
|
|
5
|
-
import {
|
|
4
|
+
import { addPuzzlesToPool, type PuzzleFile, validatePoolPuzzles } from "../queries/puzzlePool.js"
|
|
5
|
+
import { sourceToURL, tokenHelp } from "../util/config.js"
|
|
6
|
+
import { findTokenForGame } from "../util/tokenForGame.js"
|
|
6
7
|
|
|
7
8
|
type PuzzlesUploadOptions = {
|
|
8
9
|
game: string
|
|
@@ -89,16 +90,6 @@ const readPuzzleFiles = (target: string): PuzzleFile[] => {
|
|
|
89
90
|
.map((p) => ({ filename: path.basename(p), content: fs.readFileSync(p, "utf-8") }))
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
/** Finds the first saved token, in server priority order, whose team owns the game */
|
|
93
|
-
const findTokenForGame = async (gameSlug: string): Promise<TokenEntry | null> => {
|
|
94
|
-
for (const entry of sortByServerPriority(getTokens())) {
|
|
95
|
-
if (!(await isServerReachable(entry.source))) continue
|
|
96
|
-
const slugs = await fetchGameSlugsForToken(sourceToURL(entry.source), entry.token).catch(() => null)
|
|
97
|
-
if (slugs?.includes(gameSlug)) return entry
|
|
98
|
-
}
|
|
99
|
-
return null
|
|
100
|
-
}
|
|
101
|
-
|
|
102
93
|
/** Splits files into batches which stay under both the API's per-call count and its request size limit */
|
|
103
94
|
const toBatches = (files: PuzzleFile[]): PuzzleFile[][] => {
|
|
104
95
|
const batches: PuzzleFile[][] = []
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fs from "node:fs"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
|
|
4
|
+
import { fetchTracedRounds, type TracedRound } from "../queries/rounds.js"
|
|
5
|
+
import { sourceToURL, tokenHelp } from "../util/config.js"
|
|
6
|
+
import { findTokenForGame } from "../util/tokenForGame.js"
|
|
7
|
+
|
|
8
|
+
type RoundsPullOptions = {
|
|
9
|
+
game: string
|
|
10
|
+
/** Only this team member's rounds */
|
|
11
|
+
user?: string
|
|
12
|
+
/** Where the fixtures go, relative to the current folder */
|
|
13
|
+
out: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* CLI command: puzzmo rounds pull --game <slug> — writes the team's traced rounds as replay fixtures, so a local
|
|
18
|
+
* test of the server bundle's replayRound runs on real play with exactly what Puzzmo passed it
|
|
19
|
+
*/
|
|
20
|
+
export const roundsPull = async (options: RoundsPullOptions) => {
|
|
21
|
+
const entry = await findTokenForGame(options.game)
|
|
22
|
+
if (!entry) {
|
|
23
|
+
console.error(`None of your saved tokens can manage a game with the slug "${options.game}".\n${tokenHelp}`)
|
|
24
|
+
process.exit(1)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const rounds = (await fetchTracedRounds(sourceToURL(entry.source), entry.token, options.game)).filter(
|
|
28
|
+
(round) => !options.user || round.username === options.user,
|
|
29
|
+
)
|
|
30
|
+
if (!rounds.length) {
|
|
31
|
+
const who = options.user ? `${options.user} has` : "your team has"
|
|
32
|
+
console.log(`No rounds to pull: ${who} no traced rounds for ${options.game}. Play one on puzzmo.com signed in as a team member.`)
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const outDir = path.resolve(options.out)
|
|
37
|
+
fs.mkdirSync(outDir, { recursive: true })
|
|
38
|
+
let written = 0
|
|
39
|
+
for (const round of rounds) {
|
|
40
|
+
if (!round.hasLog || !round.fixture) {
|
|
41
|
+
console.log(` Skipped ${fixtureName(round)}: its log was too long for Puzzmo to keep`)
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
fs.writeFileSync(path.join(outDir, fixtureName(round)), JSON.stringify(round.fixture, null, 2) + "\n")
|
|
45
|
+
written++
|
|
46
|
+
}
|
|
47
|
+
console.log(`Wrote ${written} round fixture${written === 1 ? "" : "s"} to ${path.relative(process.cwd(), outDir) || "."}`)
|
|
48
|
+
console.log(`Each holds the input and config Puzzmo passed to replayRound, and what that build answered as expected.`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A name that sorts by when the round ended and says how it went, e.g. `orta-2026-11-12T09-30-00-completed.json` */
|
|
52
|
+
const fixtureName = (round: TracedRound) => {
|
|
53
|
+
const when = new Date(round.at).toISOString().slice(0, 19).replace(/:/g, "-")
|
|
54
|
+
const user = round.username.replace(/[^\w-]/g, "_")
|
|
55
|
+
return `${user}-${when}-${round.outcome}${round.verified ? "" : "-unverified"}.json`
|
|
56
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import fs from "node:fs"
|
|
2
|
+
import os from "node:os"
|
|
3
|
+
import path from "node:path"
|
|
4
|
+
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
|
|
6
|
+
|
|
7
|
+
import { uploadFiles } from "../util/api.js"
|
|
8
|
+
import { upload } from "./upload.js"
|
|
9
|
+
|
|
10
|
+
// The real validator fetches the schema over the network; these tests are about which files go up.
|
|
11
|
+
vi.mock("../util/validatePuzzmoFile.js", () => ({ validatePuzzmoJson: async (data: unknown) => ({ valid: true, data }) }))
|
|
12
|
+
|
|
13
|
+
vi.mock("../util/config.js", async (importOriginal) => {
|
|
14
|
+
const credential = { source: "https://api.puzzmo.com", token: "pzt-test" }
|
|
15
|
+
return { ...(await importOriginal<object>()), getTokens: () => [credential], resolveServerForTeam: async () => credential }
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
vi.mock("../util/api.js", async (importOriginal) => ({
|
|
19
|
+
...(await importOriginal<object>()),
|
|
20
|
+
uploadFiles: vi.fn(async () => ({
|
|
21
|
+
assetsBase: "https://assets.example/abc/",
|
|
22
|
+
versionID: "version-1",
|
|
23
|
+
integrationsChanged: false,
|
|
24
|
+
iconChanged: false,
|
|
25
|
+
helpChanged: false,
|
|
26
|
+
gameURL: null,
|
|
27
|
+
versionsURL: null,
|
|
28
|
+
serverBundle: null,
|
|
29
|
+
serverBundleWarnings: [],
|
|
30
|
+
})),
|
|
31
|
+
}))
|
|
32
|
+
|
|
33
|
+
class ExitError extends Error {
|
|
34
|
+
constructor(public readonly code: number | undefined) {
|
|
35
|
+
super(`process.exit(${code})`)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const tempDirs: string[] = []
|
|
40
|
+
let errorOutput: string[] = []
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
errorOutput = []
|
|
44
|
+
vi.mocked(uploadFiles).mockClear()
|
|
45
|
+
vi.spyOn(process, "exit").mockImplementation((code) => {
|
|
46
|
+
throw new ExitError(typeof code === "number" ? code : undefined)
|
|
47
|
+
})
|
|
48
|
+
vi.spyOn(console, "error").mockImplementation((...args: unknown[]) => void errorOutput.push(args.join(" ")))
|
|
49
|
+
vi.spyOn(console, "log").mockImplementation(() => {})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
vi.restoreAllMocks()
|
|
54
|
+
for (const dir of tempDirs.splice(0)) fs.rmSync(dir, { recursive: true, force: true })
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
describe(upload.name, () => {
|
|
58
|
+
it("uploads the file named by output.serverBundle, not the shared dist-server beside dist", async () => {
|
|
59
|
+
const repo = makeRepo({
|
|
60
|
+
...multiGameBuild("solitaire", { serverBundle: "../../dist-server/solitaire/server-bundle.js" }),
|
|
61
|
+
...multiGameBuild("klondike", { serverBundle: "../../dist-server/klondike/server-bundle.js" }),
|
|
62
|
+
"dist-server/solitaire/server-bundle.js": "solitaire bundle",
|
|
63
|
+
"dist-server/klondike/server-bundle.js": "klondike bundle",
|
|
64
|
+
// A stray build in the old shared spot must be ignored once each game names its own
|
|
65
|
+
"dist/dist-server/server-bundle.js": "stray bundle",
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
await upload(repo)
|
|
69
|
+
|
|
70
|
+
expect(sentServerBundles()).toEqual({ klondike: "klondike bundle", solitaire: "solitaire bundle" })
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it("fails a game whose output.serverBundle doesn't exist, and still uploads the others", async () => {
|
|
74
|
+
const repo = makeRepo({
|
|
75
|
+
...multiGameBuild("solitaire", { serverBundle: "../../dist-server/solitaire/server-bundle.js" }),
|
|
76
|
+
...multiGameBuild("klondike", { serverBundle: "../../dist-server/klondike/server-bundle.js" }),
|
|
77
|
+
"dist-server/klondike/server-bundle.js": "klondike bundle",
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
await expect(upload(repo)).rejects.toThrow(new ExitError(1))
|
|
81
|
+
|
|
82
|
+
expect(sentServerBundles()).toEqual({ klondike: "klondike bundle" })
|
|
83
|
+
const message = errorOutput.find((line) => line.includes("Server bundle not found"))
|
|
84
|
+
expect(message).toContain(`for solitaire: "../../dist-server/solitaire/server-bundle.js"`)
|
|
85
|
+
expect(message).toContain(`Build the game first, or fix "output.serverBundle" in puzzmo.json.`)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it("falls back to dist-server/server-bundle.js beside dist when output.serverBundle isn't set", async () => {
|
|
89
|
+
const repo = makeRepo({
|
|
90
|
+
"puzzmo.json": puzzmoJSON("solitaire", { dir: "dist" }),
|
|
91
|
+
"dist/index.html": "<html></html>",
|
|
92
|
+
"dist-server/server-bundle.js": "default bundle",
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
await upload(repo)
|
|
96
|
+
|
|
97
|
+
expect(sentServerBundles()).toEqual({ solitaire: "default bundle" })
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it("sends no server bundle when there's none beside dist", async () => {
|
|
101
|
+
const repo = makeRepo({ ...multiGameBuild("solitaire"), ...multiGameBuild("klondike") })
|
|
102
|
+
|
|
103
|
+
await upload(repo)
|
|
104
|
+
|
|
105
|
+
expect(sentServerBundles()).toEqual({ klondike: null, solitaire: null })
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it("refuses the whole run before uploading anything when games would share one server bundle", async () => {
|
|
109
|
+
const repo = makeRepo({
|
|
110
|
+
...multiGameBuild("solitaire"),
|
|
111
|
+
...multiGameBuild("klondike"),
|
|
112
|
+
...multiGameBuild("spider", { serverBundle: "../../dist-server/spider/server-bundle.js" }),
|
|
113
|
+
"dist/dist-server/server-bundle.js": "whichever game built last",
|
|
114
|
+
"dist-server/spider/server-bundle.js": "spider bundle",
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
await expect(upload(repo)).rejects.toThrow(new ExitError(1))
|
|
118
|
+
|
|
119
|
+
expect(uploadFiles).not.toHaveBeenCalled()
|
|
120
|
+
const output = errorOutput.join("\n")
|
|
121
|
+
expect(output).toContain("Refusing to upload: more than one game would send the same server bundle.")
|
|
122
|
+
expect(output).toContain(`${path.join("dist", "dist-server", "server-bundle.js")} would be sent for klondike, solitaire`)
|
|
123
|
+
expect(output).not.toContain("spider")
|
|
124
|
+
expect(output).toContain(`Set "output.serverBundle"`)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it("refuses when an explicit output.serverBundle points at another game's default bundle", async () => {
|
|
128
|
+
const repo = makeRepo({
|
|
129
|
+
...multiGameBuild("solitaire"),
|
|
130
|
+
...multiGameBuild("klondike", { serverBundle: "../../dist/dist-server/server-bundle.js" }),
|
|
131
|
+
"dist/dist-server/server-bundle.js": "solitaire bundle",
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
await expect(upload(repo)).rejects.toThrow(new ExitError(1))
|
|
135
|
+
|
|
136
|
+
expect(uploadFiles).not.toHaveBeenCalled()
|
|
137
|
+
expect(errorOutput.join("\n")).toContain("would be sent for klondike, solitaire")
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
/** Writes `files` (repo-relative path to contents) into a throwaway repo and returns its path */
|
|
142
|
+
const makeRepo = (files: Record<string, string>): string => {
|
|
143
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "puzzmo-upload-"))
|
|
144
|
+
tempDirs.push(dir)
|
|
145
|
+
for (const [relative, contents] of Object.entries(files)) {
|
|
146
|
+
const full = path.join(dir, relative)
|
|
147
|
+
fs.mkdirSync(path.dirname(full), { recursive: true })
|
|
148
|
+
fs.writeFileSync(full, contents)
|
|
149
|
+
}
|
|
150
|
+
return dir
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** A game laid out like a repo that builds many games from one root: games/<slug>/puzzmo.json building into dist/<slug> */
|
|
154
|
+
const multiGameBuild = (slug: string, output: { serverBundle?: string } = {}): Record<string, string> => ({
|
|
155
|
+
[`games/${slug}/puzzmo.json`]: puzzmoJSON(slug, { dir: `../../dist/${slug}`, ...output }),
|
|
156
|
+
[`dist/${slug}/index.html`]: "<html></html>",
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
const puzzmoJSON = (slug: string, output: { dir: string; serverBundle?: string }): string =>
|
|
160
|
+
JSON.stringify({ game: { displayName: slug, slug, teamID: "team-1" }, output })
|
|
161
|
+
|
|
162
|
+
/** The server bundle contents each uploaded game sent, keyed by slug */
|
|
163
|
+
const sentServerBundles = (): Record<string, string | null | undefined> =>
|
|
164
|
+
Object.fromEntries(vi.mocked(uploadFiles).mock.calls.map((call) => [call[2], call[8]?.serverBundle]))
|
package/src/commands/upload.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
type TokenEntry,
|
|
18
18
|
} from "../util/config.js"
|
|
19
19
|
import { createUserGame } from "../util/createGame.js"
|
|
20
|
-
import { discoverGames, type DiscoveredGame } from "../util/discoverGames.js"
|
|
20
|
+
import { discoverGames, findSharedServerBundles, type DiscoveredGame } from "../util/discoverGames.js"
|
|
21
21
|
import { lintDist } from "../util/lintDist.js"
|
|
22
22
|
import { lintPuzzmoFile } from "../util/lintPuzzmoFile.js"
|
|
23
23
|
import { mascotSmall, pickMascot } from "../util/mascot.js"
|
|
@@ -91,6 +91,18 @@ export const upload = async (dir: string, options: UploadOptions = {}) => {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
// Sending one file as several games' bundles would run one game's server code for the others, so nothing goes up.
|
|
95
|
+
const sharedBundles = findSharedServerBundles(games)
|
|
96
|
+
if (sharedBundles.length) {
|
|
97
|
+
console.error(`\nRefusing to upload: more than one game would send the same server bundle.`)
|
|
98
|
+
// The shared paths are real paths, so the root has to be too for the relative path to read well
|
|
99
|
+
const realRoot = fs.realpathSync(rootDir)
|
|
100
|
+
for (const shared of sharedBundles)
|
|
101
|
+
console.error(` - ${path.relative(realRoot, shared.serverBundlePath)} would be sent for ${shared.slugs.join(", ")}`)
|
|
102
|
+
console.error(`Set "output.serverBundle" in each of these games' puzzmo.json to the bundle built for that game.`)
|
|
103
|
+
process.exit(1)
|
|
104
|
+
}
|
|
105
|
+
|
|
94
106
|
const sha = getGitSHA(rootDir) || hashGames(games)
|
|
95
107
|
const description = getGitMessage(rootDir)
|
|
96
108
|
const repoURL = getGitRepoURL(rootDir)
|
|
@@ -161,7 +173,7 @@ type UploadOneOptions = {
|
|
|
161
173
|
/** Uploads a single discovered game; throws on failure */
|
|
162
174
|
const uploadOneGame = async (game: DiscoveredGame, opts: UploadOneOptions): Promise<GameSuccess> => {
|
|
163
175
|
const { credential, apiURL, sha, description, repoURL, verbose } = opts
|
|
164
|
-
const { puzzmoFile, distDir, iconPath, helpPath } = game
|
|
176
|
+
const { puzzmoFile, distDir, iconPath, helpPath, serverBundlePath } = game
|
|
165
177
|
const gameSlug = puzzmoFile.game.slug
|
|
166
178
|
|
|
167
179
|
const files = collectFiles(distDir)
|
|
@@ -182,6 +194,12 @@ const uploadOneGame = async (game: DiscoveredGame, opts: UploadOneOptions): Prom
|
|
|
182
194
|
warnAboutAbsoluteScriptURLs(distDir)
|
|
183
195
|
for (const warning of lintPuzzmoFile(puzzmoFile)) console.log(yellow(` Warning: ${warning}`))
|
|
184
196
|
|
|
197
|
+
const serverBundle = serverBundlePath ? fs.readFileSync(serverBundlePath, "utf-8") : null
|
|
198
|
+
if (serverBundlePath && serverBundle)
|
|
199
|
+
console.log(
|
|
200
|
+
` Server bundle: ${formatBytes(serverBundle.length)} from ${path.relative(game.puzzmoJsonDir, serverBundlePath)}, uploaded privately`,
|
|
201
|
+
)
|
|
202
|
+
|
|
185
203
|
const result = await uploadFiles(
|
|
186
204
|
apiURL,
|
|
187
205
|
credential.token,
|
|
@@ -199,9 +217,14 @@ const uploadOneGame = async (game: DiscoveredGame, opts: UploadOneOptions): Prom
|
|
|
199
217
|
repoURL,
|
|
200
218
|
iconSVG: iconPath ? fs.readFileSync(iconPath, "utf-8") : null,
|
|
201
219
|
helpMD: helpPath ? fs.readFileSync(helpPath, "utf-8") : null,
|
|
220
|
+
serverBundle,
|
|
202
221
|
},
|
|
203
222
|
)
|
|
204
223
|
|
|
224
|
+
if (result.serverBundle)
|
|
225
|
+
for (const [capability, summary] of Object.entries(result.serverBundle))
|
|
226
|
+
console.log(` Server bundle offers ${capability}: ${summary}.`)
|
|
227
|
+
for (const warning of result.serverBundleWarnings) console.log(yellow(` Warning: ${warning}`))
|
|
205
228
|
if (result.iconChanged && iconPath) console.log(` Icon updated from ${path.relative(game.puzzmoJsonDir, iconPath)}.`)
|
|
206
229
|
if (result.helpChanged && helpPath) console.log(` In-game help updated from ${path.relative(game.puzzmoJsonDir, helpPath)}, live now.`)
|
|
207
230
|
|
|
@@ -214,6 +237,8 @@ const uploadOneGame = async (game: DiscoveredGame, opts: UploadOneOptions): Prom
|
|
|
214
237
|
} else {
|
|
215
238
|
console.log(` Uploaded.`)
|
|
216
239
|
}
|
|
240
|
+
// Workshop and the MCP name a build by this, e.g. to check rules against it before it goes live
|
|
241
|
+
console.log(` Build ID: ${result.versionID}`)
|
|
217
242
|
return {
|
|
218
243
|
ok: true,
|
|
219
244
|
slug: gameSlug,
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { gameCreate } from "./commands/game/create.js"
|
|
|
8
8
|
import { login } from "./commands/login.js"
|
|
9
9
|
import { migrate } from "./commands/migrate.js"
|
|
10
10
|
import { puzzlesUpload } from "./commands/puzzles.js"
|
|
11
|
+
import { roundsPull } from "./commands/rounds.js"
|
|
11
12
|
import { upload } from "./commands/upload.js"
|
|
12
13
|
import { validate } from "./commands/validate.js"
|
|
13
14
|
import { defaultSource } from "./util/config.js"
|
|
@@ -95,6 +96,21 @@ const puzzlesCommand = defineCommand({
|
|
|
95
96
|
subCommands: { upload: puzzlesUploadCommand },
|
|
96
97
|
})
|
|
97
98
|
|
|
99
|
+
const roundsPullCommand = defineCommand({
|
|
100
|
+
meta: { name: "pull", description: "Write your team's traced rounds of a repeat-play game as replay fixtures" },
|
|
101
|
+
args: {
|
|
102
|
+
game: { type: "string", description: "The game slug to pull rounds for", required: true },
|
|
103
|
+
user: { type: "string", description: "Only this team member's rounds (their username)" },
|
|
104
|
+
out: { type: "string", description: "Folder to write the fixtures to", default: "fixtures/rounds" },
|
|
105
|
+
},
|
|
106
|
+
run: ({ args }) => roundsPull({ game: args.game, user: args.user, out: args.out }),
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const roundsCommand = defineCommand({
|
|
110
|
+
meta: { name: "rounds", description: "Work with the rounds Puzzmo traced for your repeat-play games" },
|
|
111
|
+
subCommands: { pull: roundsPullCommand },
|
|
112
|
+
})
|
|
113
|
+
|
|
98
114
|
const migrateCommand = defineCommand({
|
|
99
115
|
meta: { name: "migrate", description: "List and select migration skills from workshop.puzzmo.com" },
|
|
100
116
|
run: () => migrate(),
|
|
@@ -162,6 +178,7 @@ const main = defineCommand({
|
|
|
162
178
|
login: loginCommand,
|
|
163
179
|
games: gamesCommand,
|
|
164
180
|
puzzles: puzzlesCommand,
|
|
181
|
+
rounds: roundsCommand,
|
|
165
182
|
migrate: migrateCommand,
|
|
166
183
|
game: gameCommand,
|
|
167
184
|
upload: uploadAlias,
|