@quenty/nevermore-cli 4.43.3 → 4.44.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.
Files changed (154) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/build-scripts/{combine-test-places.luau → combine-test-places.lua} +3 -3
  3. package/build-scripts/{transform-inject-deploy-metadata.luau → transform-inject-deploy-metadata.lua} +3 -3
  4. package/dist/commands/batch-command/batch-deploy-command.js +4 -4
  5. package/dist/commands/batch-command/batch-deploy-command.js.map +1 -1
  6. package/dist/commands/batch-command/batch-test-command.d.ts.map +1 -1
  7. package/dist/commands/batch-command/batch-test-command.js +76 -19
  8. package/dist/commands/batch-command/batch-test-command.js.map +1 -1
  9. package/dist/commands/deploy-command/deploy-init-utils.d.ts.map +1 -1
  10. package/dist/commands/deploy-command/deploy-init-utils.js +7 -1
  11. package/dist/commands/deploy-command/deploy-init-utils.js.map +1 -1
  12. package/dist/commands/deploy-command/index.js +1 -1
  13. package/dist/commands/deploy-command/index.js.map +1 -1
  14. package/dist/commands/init-command/init-game-command.js +2 -2
  15. package/dist/commands/init-command/init-game-command.js.map +1 -1
  16. package/dist/commands/install-package-command.d.ts +14 -0
  17. package/dist/commands/install-package-command.d.ts.map +1 -1
  18. package/dist/commands/install-package-command.js +65 -12
  19. package/dist/commands/install-package-command.js.map +1 -1
  20. package/dist/utils/deploy/deploy-github-columns.d.ts +12 -2
  21. package/dist/utils/deploy/deploy-github-columns.d.ts.map +1 -1
  22. package/dist/utils/deploy/deploy-github-columns.js +11 -4
  23. package/dist/utils/deploy/deploy-github-columns.js.map +1 -1
  24. package/dist/utils/deploy/deploy-metadata.js +1 -1
  25. package/dist/utils/deploy/deploy-metadata.js.map +1 -1
  26. package/dist/utils/job-context/base-job-context.d.ts +2 -2
  27. package/dist/utils/job-context/base-job-context.d.ts.map +1 -1
  28. package/dist/utils/job-context/base-job-context.js +1 -1
  29. package/dist/utils/job-context/base-job-context.js.map +1 -1
  30. package/dist/utils/job-context/batch-script-job-context.d.ts +37 -2
  31. package/dist/utils/job-context/batch-script-job-context.d.ts.map +1 -1
  32. package/dist/utils/job-context/batch-script-job-context.js +59 -22
  33. package/dist/utils/job-context/batch-script-job-context.js.map +1 -1
  34. package/dist/utils/job-context/cloud-job-context.d.ts +2 -2
  35. package/dist/utils/job-context/cloud-job-context.d.ts.map +1 -1
  36. package/dist/utils/job-context/cloud-job-context.js +10 -5
  37. package/dist/utils/job-context/cloud-job-context.js.map +1 -1
  38. package/dist/utils/job-context/cloud-job-context.test.d.ts +7 -0
  39. package/dist/utils/job-context/cloud-job-context.test.d.ts.map +1 -0
  40. package/dist/utils/job-context/cloud-job-context.test.js +91 -0
  41. package/dist/utils/job-context/cloud-job-context.test.js.map +1 -0
  42. package/dist/utils/job-context/job-context.d.ts +70 -2
  43. package/dist/utils/job-context/job-context.d.ts.map +1 -1
  44. package/dist/utils/job-context/local-job-context.d.ts +2 -2
  45. package/dist/utils/job-context/local-job-context.d.ts.map +1 -1
  46. package/dist/utils/job-context/local-job-context.js +4 -2
  47. package/dist/utils/job-context/local-job-context.js.map +1 -1
  48. package/dist/utils/job-context/local-job-context.test.d.ts +7 -0
  49. package/dist/utils/job-context/local-job-context.test.d.ts.map +1 -0
  50. package/dist/utils/job-context/local-job-context.test.js +68 -0
  51. package/dist/utils/job-context/local-job-context.test.js.map +1 -0
  52. package/dist/utils/open-cloud/open-cloud-client.d.ts +50 -7
  53. package/dist/utils/open-cloud/open-cloud-client.d.ts.map +1 -1
  54. package/dist/utils/open-cloud/open-cloud-client.js +49 -13
  55. package/dist/utils/open-cloud/open-cloud-client.js.map +1 -1
  56. package/dist/utils/open-cloud/open-cloud-client.test.js +125 -1
  57. package/dist/utils/open-cloud/open-cloud-client.test.js.map +1 -1
  58. package/dist/utils/open-cloud/open-cloud-logs.characterization.test.d.ts +22 -0
  59. package/dist/utils/open-cloud/open-cloud-logs.characterization.test.d.ts.map +1 -0
  60. package/dist/utils/open-cloud/open-cloud-logs.characterization.test.js +202 -0
  61. package/dist/utils/open-cloud/open-cloud-logs.characterization.test.js.map +1 -0
  62. package/dist/utils/package-manager-utils.d.ts +29 -0
  63. package/dist/utils/package-manager-utils.d.ts.map +1 -0
  64. package/dist/utils/package-manager-utils.js +120 -0
  65. package/dist/utils/package-manager-utils.js.map +1 -0
  66. package/dist/utils/package-manager-utils.test.d.ts +2 -0
  67. package/dist/utils/package-manager-utils.test.d.ts.map +1 -0
  68. package/dist/utils/package-manager-utils.test.js +121 -0
  69. package/dist/utils/package-manager-utils.test.js.map +1 -0
  70. package/dist/utils/testing/batch-run.e2e.test.d.ts +17 -0
  71. package/dist/utils/testing/batch-run.e2e.test.d.ts.map +1 -0
  72. package/dist/utils/testing/batch-run.e2e.test.js +343 -0
  73. package/dist/utils/testing/batch-run.e2e.test.js.map +1 -0
  74. package/dist/utils/testing/batch-test-runner-template.test.d.ts +11 -0
  75. package/dist/utils/testing/batch-test-runner-template.test.d.ts.map +1 -0
  76. package/dist/utils/testing/batch-test-runner-template.test.js +38 -0
  77. package/dist/utils/testing/batch-test-runner-template.test.js.map +1 -0
  78. package/dist/utils/testing/log-fetch-stats.d.ts +40 -0
  79. package/dist/utils/testing/log-fetch-stats.d.ts.map +1 -0
  80. package/dist/utils/testing/log-fetch-stats.js +18 -0
  81. package/dist/utils/testing/log-fetch-stats.js.map +1 -0
  82. package/dist/utils/testing/log-fetch-stats.test.d.ts +2 -0
  83. package/dist/utils/testing/log-fetch-stats.test.d.ts.map +1 -0
  84. package/dist/utils/testing/log-fetch-stats.test.js +41 -0
  85. package/dist/utils/testing/log-fetch-stats.test.js.map +1 -0
  86. package/dist/utils/testing/parsers/batch-log-parser.d.ts +126 -1
  87. package/dist/utils/testing/parsers/batch-log-parser.d.ts.map +1 -1
  88. package/dist/utils/testing/parsers/batch-log-parser.js +440 -103
  89. package/dist/utils/testing/parsers/batch-log-parser.js.map +1 -1
  90. package/dist/utils/testing/parsers/batch-log-parser.test.js +494 -1
  91. package/dist/utils/testing/parsers/batch-log-parser.test.js.map +1 -1
  92. package/dist/utils/testing/parsers/batch-log-renderer.d.ts +79 -0
  93. package/dist/utils/testing/parsers/batch-log-renderer.d.ts.map +1 -0
  94. package/dist/utils/testing/parsers/batch-log-renderer.js +241 -0
  95. package/dist/utils/testing/parsers/batch-log-renderer.js.map +1 -0
  96. package/dist/utils/testing/parsers/batch-log-renderer.test.d.ts +2 -0
  97. package/dist/utils/testing/parsers/batch-log-renderer.test.d.ts.map +1 -0
  98. package/dist/utils/testing/parsers/batch-log-renderer.test.js +202 -0
  99. package/dist/utils/testing/parsers/batch-log-renderer.test.js.map +1 -0
  100. package/dist/utils/testing/runner/combined-project-generator.js +1 -1
  101. package/dist/utils/testing/runner/combined-project-generator.js.map +1 -1
  102. package/dist/utils/testing/runner/test-runner.d.ts +24 -0
  103. package/dist/utils/testing/runner/test-runner.d.ts.map +1 -1
  104. package/dist/utils/testing/runner/test-runner.js +166 -6
  105. package/dist/utils/testing/runner/test-runner.js.map +1 -1
  106. package/dist/utils/testing/runner/test-runner.test.js +228 -2
  107. package/dist/utils/testing/runner/test-runner.test.js.map +1 -1
  108. package/dist/utils/testing/structured-test-results.d.ts +77 -0
  109. package/dist/utils/testing/structured-test-results.d.ts.map +1 -0
  110. package/dist/utils/testing/structured-test-results.js +140 -0
  111. package/dist/utils/testing/structured-test-results.js.map +1 -0
  112. package/dist/utils/testing/structured-test-results.test.d.ts +7 -0
  113. package/dist/utils/testing/structured-test-results.test.d.ts.map +1 -0
  114. package/dist/utils/testing/structured-test-results.test.js +179 -0
  115. package/dist/utils/testing/structured-test-results.test.js.map +1 -0
  116. package/package.json +6 -6
  117. package/src/commands/batch-command/batch-deploy-command.ts +4 -4
  118. package/src/commands/batch-command/batch-test-command.ts +94 -19
  119. package/src/commands/deploy-command/deploy-init-utils.ts +7 -1
  120. package/src/commands/deploy-command/index.ts +1 -1
  121. package/src/commands/init-command/init-game-command.ts +2 -2
  122. package/src/commands/install-package-command.ts +107 -14
  123. package/src/utils/deploy/deploy-github-columns.ts +14 -4
  124. package/src/utils/deploy/deploy-metadata.ts +1 -1
  125. package/src/utils/job-context/base-job-context.ts +3 -2
  126. package/src/utils/job-context/batch-script-job-context.ts +98 -17
  127. package/src/utils/job-context/cloud-job-context.test.ts +112 -0
  128. package/src/utils/job-context/cloud-job-context.ts +12 -6
  129. package/src/utils/job-context/job-context.ts +71 -2
  130. package/src/utils/job-context/local-job-context.test.ts +89 -0
  131. package/src/utils/job-context/local-job-context.ts +7 -3
  132. package/src/utils/open-cloud/open-cloud-client.test.ts +155 -1
  133. package/src/utils/open-cloud/open-cloud-client.ts +94 -18
  134. package/src/utils/open-cloud/open-cloud-logs.characterization.test.ts +277 -0
  135. package/src/utils/package-manager-utils.test.ts +174 -0
  136. package/src/utils/package-manager-utils.ts +148 -0
  137. package/src/utils/testing/batch-run.e2e.test.ts +425 -0
  138. package/src/utils/testing/batch-test-runner-template.test.ts +62 -0
  139. package/src/utils/testing/log-fetch-stats.test.ts +48 -0
  140. package/src/utils/testing/log-fetch-stats.ts +55 -0
  141. package/src/utils/testing/parsers/batch-log-parser.test.ts +660 -1
  142. package/src/utils/testing/parsers/batch-log-parser.ts +721 -116
  143. package/src/utils/testing/parsers/batch-log-renderer.test.ts +330 -0
  144. package/src/utils/testing/parsers/batch-log-renderer.ts +329 -0
  145. package/src/utils/testing/runner/combined-project-generator.ts +1 -1
  146. package/src/utils/testing/runner/test-runner.test.ts +332 -2
  147. package/src/utils/testing/runner/test-runner.ts +231 -9
  148. package/src/utils/testing/structured-test-results.test.ts +267 -0
  149. package/src/utils/testing/structured-test-results.ts +199 -0
  150. package/templates/batch-test-runner.lua +242 -0
  151. package/tsconfig.tsbuildinfo +1 -1
  152. package/templates/batch-test-runner.luau +0 -137
  153. /package/build-scripts/{smoke-test-server.luau → smoke-test-server.lua} +0 -0
  154. /package/build-scripts/{transform-rojo-merge-place.luau → transform-rojo-merge-place.lua} +0 -0
@@ -0,0 +1,277 @@
1
+ /**
2
+ * Characterization tests for how Open Cloud actually delivers a Luau execution
3
+ * task's logs and return value. Nothing here tests our code: every assertion is
4
+ * a claim about Roblox's behaviour that our log handling is built on, written
5
+ * so the claim fails out loud if Roblox changes it.
6
+ *
7
+ * These claims decide real things — whether a truncated run is worth
8
+ * re-fetching, whether `maxPageSize` is worth sending, whether a batch package
9
+ * with no output was dropped or never ran — and none of them are documented by
10
+ * Roblox. Prose in a gotchas file cannot notice when it goes stale. This can.
11
+ *
12
+ * Disabled by default: it spends real Open Cloud quota. To run it:
13
+ *
14
+ * NEVERMORE_CHARACTERIZATION=1 npm test -- open-cloud-logs
15
+ *
16
+ * It reads the key through the same credential store the CLI uses, so
17
+ * `nevermore auth login` is the only setup. The universe and place default to
18
+ * the nevermore-test-runner test target and can be pointed elsewhere with
19
+ * NEVERMORE_CHARACTERIZATION_UNIVERSE / _PLACE.
20
+ */
21
+
22
+ import { describe, it, expect, beforeAll } from 'vitest';
23
+ import { loadStoredApiKeyAsync } from '@quenty/nevermore-cli-helpers';
24
+ import {
25
+ OpenCloudClient,
26
+ getTaskReturnValues,
27
+ type LuauTask,
28
+ } from './open-cloud-client.js';
29
+ import { RateLimiter } from './rate-limiter.js';
30
+
31
+ const ENABLED = process.env.NEVERMORE_CHARACTERIZATION === '1';
32
+
33
+ /** The nevermore-test-runner test target, which exists to be run against. */
34
+ const UNIVERSE_ID = Number(
35
+ process.env.NEVERMORE_CHARACTERIZATION_UNIVERSE ?? 9716264427
36
+ );
37
+ const PLACE_ID = Number(
38
+ process.env.NEVERMORE_CHARACTERIZATION_PLACE ?? 138951894938783
39
+ );
40
+
41
+ const LINES_THAT_FIT = 5_000;
42
+ const LINES_AT_CAPACITY = 8_000;
43
+ const LINES_THAT_OVERFLOW_LESS = 10_000;
44
+ const LINES_THAT_OVERFLOW = 20_000;
45
+
46
+ /**
47
+ * Retention is bounded by memory, and each retained message costs this many
48
+ * bytes beyond its own text — timestamp, type and framing. Derived by holding
49
+ * the print count at 20,000 and varying only the payload width, then solving
50
+ * `chars + k * messages` for the k that makes that budget constant.
51
+ */
52
+ const PER_MESSAGE_OVERHEAD_BYTES = 47;
53
+
54
+ /** A printed line that names its own position, so survivors identify themselves. */
55
+ const SEQ = new RegExp('^SEQ (' + String.raw`\d` + '+)');
56
+
57
+ describe.runIf(ENABLED)('Open Cloud task log delivery', () => {
58
+ let client: OpenCloudClient;
59
+ let placeVersion: number;
60
+
61
+ beforeAll(async () => {
62
+ const apiKey = await loadStoredApiKeyAsync();
63
+ if (!apiKey) {
64
+ throw new Error(
65
+ 'No stored Open Cloud API key. Run `nevermore auth login` first.'
66
+ );
67
+ }
68
+
69
+ client = new OpenCloudClient({ apiKey, rateLimiter: new RateLimiter() });
70
+ placeVersion = await client.resolveLatestPlaceVersionAsync(
71
+ UNIVERSE_ID,
72
+ PLACE_ID,
73
+ 'saved'
74
+ );
75
+ }, 120_000);
76
+
77
+ /**
78
+ * Run a task printing `lines` numbered messages, each optionally padded to
79
+ * widen it, and report what came back.
80
+ */
81
+ async function printLinesAsync(lines: number, padChars = 0) {
82
+ const script = padChars
83
+ ? `local pad = string.rep("p", ${padChars}) for i = 1, ${lines} do print("SEQ " .. i .. " " .. pad) end`
84
+ : `for i = 1, ${lines} do print("SEQ " .. i) end`;
85
+
86
+ const task = await client.createExecutionTaskAsync(
87
+ UNIVERSE_ID,
88
+ PLACE_ID,
89
+ placeVersion,
90
+ script,
91
+ 300_000
92
+ );
93
+ const completed = await client.pollTaskCompletionAsync(task.path);
94
+ expect(completed.state).toBe('COMPLETE');
95
+
96
+ const fetched = await client.getRawTaskLogsAsync(completed.path);
97
+ const seq = fetched.text
98
+ .split('\n')
99
+ .map((line) => SEQ.exec(line.trim())?.[1])
100
+ .filter((n): n is string => n !== undefined)
101
+ .map(Number);
102
+
103
+ return { task: completed, ...fetched, seq };
104
+ }
105
+
106
+ /** Bytes the buffer spent on what it kept, per-message overhead included. */
107
+ function retainedBudget(run: { stats: { chars: number; messages: number } }) {
108
+ return run.stats.chars + PER_MESSAGE_OVERHEAD_BYTES * run.stats.messages;
109
+ }
110
+
111
+ it('delivers a small run complete and in order', async () => {
112
+ const run = await printLinesAsync(LINES_THAT_FIT);
113
+
114
+ expect(run.seq).toHaveLength(LINES_THAT_FIT);
115
+ expect(run.seq[0]).toBe(1);
116
+ expect(run.seq[run.seq.length - 1]).toBe(LINES_THAT_FIT);
117
+ // Arrival order is chronological, so no client-side sort is needed — and
118
+ // sorting by createTime would be wrong, since a whole frame shares one.
119
+ expect(run.seq).toEqual([...run.seq].sort((a, b) => a - b));
120
+ }, 300_000);
121
+
122
+ it('truncates a large run by dropping the head, keeping a contiguous tail', async () => {
123
+ // Says a short log is missing output rather than proof a run printed
124
+ // little, and rules out the loss being a page we failed to request — an
125
+ // unrequested page would have held the head. It is why the batch parser
126
+ // closes sections on their END marker.
127
+ const run = await printLinesAsync(LINES_THAT_OVERFLOW);
128
+
129
+ expect(run.seq.length).toBeLessThan(LINES_THAT_OVERFLOW);
130
+ expect(run.seq[run.seq.length - 1]).toBe(LINES_THAT_OVERFLOW);
131
+ expect(run.seq[0]).toBeGreaterThan(1);
132
+ expect(run.seq).toEqual(
133
+ Array.from({ length: run.seq.length }, (_, i) => run.seq[0] + i)
134
+ );
135
+ }, 300_000);
136
+
137
+ it('bounds retention by memory, not by number of print calls', async () => {
138
+ // Both runs make exactly the same number of print calls. If the buffer held
139
+ // a fixed number of messages they would retain the same count; the padded
140
+ // one keeps a small fraction of it, so the budget is bytes.
141
+ const narrow = await printLinesAsync(LINES_THAT_OVERFLOW);
142
+ const wide = await printLinesAsync(LINES_THAT_OVERFLOW, 500);
143
+
144
+ expect(wide.stats.messages).toBeLessThan(narrow.stats.messages / 5);
145
+ expect(wide.stats.chars).toBeGreaterThan(narrow.stats.chars);
146
+
147
+ // And it is one budget in both: bytes kept, plus a fixed cost per message,
148
+ // lands on the same number however wide the messages are. ~450 KB.
149
+ expect(retainedBudget(wide)).toBeGreaterThan(retainedBudget(narrow) * 0.95);
150
+ expect(retainedBudget(wide)).toBeLessThan(retainedBudget(narrow) * 1.05);
151
+ expect(retainedBudget(narrow)).toBeGreaterThan(400_000);
152
+ expect(retainedBudget(narrow)).toBeLessThan(500_000);
153
+ }, 300_000);
154
+
155
+ it('keeps the same amount however much is printed, at one message width', async () => {
156
+ // The corollary: at a fixed message size, printing twice as much does not
157
+ // get twice as much back. A long run cannot be made to report itself by
158
+ // printing more carefully, which is why counts travel in the return value.
159
+ const atCapacity = await printLinesAsync(LINES_AT_CAPACITY);
160
+ expect(atCapacity.seq).toHaveLength(LINES_AT_CAPACITY);
161
+
162
+ const over = await printLinesAsync(LINES_THAT_OVERFLOW_LESS);
163
+ const wayOver = await printLinesAsync(LINES_THAT_OVERFLOW);
164
+
165
+ expect(over.seq.length).toBeLessThan(LINES_THAT_OVERFLOW_LESS);
166
+ expect(wayOver.seq.length).toBeLessThan(LINES_THAT_OVERFLOW);
167
+ expect(wayOver.seq.length).toBeGreaterThan(over.seq.length * 0.9);
168
+ expect(wayOver.seq.length).toBeLessThan(over.seq.length * 1.1);
169
+ }, 300_000);
170
+
171
+ it('returns only what the task printed, with nothing of its own mixed in', async () => {
172
+ // Rules out engine or internal messages taking room in the buffer: every
173
+ // message that came back is one of ours, so a retained count short of a
174
+ // round number is the byte budget, not foreign output.
175
+ const run = await printLinesAsync(LINES_THAT_OVERFLOW);
176
+
177
+ expect(run.seq).toHaveLength(run.stats.messages);
178
+ }, 300_000);
179
+
180
+ it('delivers the same messages structured or flat, and never a second page', async () => {
181
+ // Why we send no maxPageSize, and why the view is a free choice: asking for
182
+ // 10 still returns the whole window in one page. A page size that counted
183
+ // messages would cap this at 10 and hand back a token for the rest.
184
+ const run = await printLinesAsync(LINES_THAT_OVERFLOW);
185
+
186
+ const structured = await fetchOnePageAsync(run.task.path, {
187
+ view: 'STRUCTURED',
188
+ });
189
+ const flat = await fetchOnePageAsync(run.task.path, {});
190
+
191
+ // Same messages in the same order — the view changes the envelope, not the
192
+ // delivery.
193
+ expect(flat.messages).toEqual(structured.messages);
194
+ expect(structured.messages).toHaveLength(run.stats.messages);
195
+
196
+ const variants: Array<Record<string, string>> = [
197
+ { view: 'STRUCTURED', maxPageSize: '10' },
198
+ { view: 'STRUCTURED', maxPageSize: '100' },
199
+ { maxPageSize: '10' },
200
+ ];
201
+
202
+ for (const params of variants) {
203
+ const page = await fetchOnePageAsync(run.task.path, params);
204
+ expect(page.nextPageToken).toBeUndefined();
205
+ expect(page.messages).toEqual(structured.messages);
206
+ }
207
+ }, 300_000);
208
+
209
+ it('delivers a large return value, but drops the task entirely past a limit', async () => {
210
+ // Why the returned failure list is capped rather than trusted to arrive: an
211
+ // oversize return value does not come back truncated, it takes the whole
212
+ // run with it — and such a task carries no output and no message saying so,
213
+ // which is why "nothing came back" must stay distinguishable from "the
214
+ // script returned nothing".
215
+ const twoMegabytes = await returnStringAsync(2 * 1024 * 1024);
216
+ expect(twoMegabytes.state).toBe('COMPLETE');
217
+ expect(getTaskReturnValues(twoMegabytes)).toHaveLength(1);
218
+
219
+ const fiveMegabytes = await returnStringAsync(5 * 1024 * 1024);
220
+ expect(fiveMegabytes.state).not.toBe('COMPLETE');
221
+ expect(getTaskReturnValues(fiveMegabytes)).toBeUndefined();
222
+ }, 300_000);
223
+
224
+ /** Run a task returning a string of `bytes`, and wait for whatever happens. */
225
+ async function returnStringAsync(bytes: number): Promise<LuauTask> {
226
+ const task = await client.createExecutionTaskAsync(
227
+ UNIVERSE_ID,
228
+ PLACE_ID,
229
+ placeVersion,
230
+ `return string.rep("x", ${bytes})`,
231
+ 300_000
232
+ );
233
+
234
+ // Returns on any terminal state, failure included — which is one of the
235
+ // outcomes under test here, not an error.
236
+ return client.pollTaskCompletionAsync(task.path);
237
+ }
238
+
239
+ /**
240
+ * One raw request, bypassing the client so the query can be varied. Returns
241
+ * only what the claims above are about.
242
+ */
243
+ async function fetchOnePageAsync(
244
+ taskPath: string,
245
+ params: Record<string, string>
246
+ ): Promise<{ nextPageToken?: string; messages: string[] }> {
247
+ const apiKey = (await loadStoredApiKeyAsync())!;
248
+ const url = new URL(`https://apis.roblox.com/cloud/v2/${taskPath}/logs`);
249
+ for (const [key, value] of Object.entries(params)) {
250
+ url.searchParams.set(key, value);
251
+ }
252
+
253
+ const response = await fetch(url.toString(), {
254
+ headers: { 'X-API-Key': apiKey },
255
+ });
256
+ expect(response.ok).toBe(true);
257
+
258
+ const data = (await response.json()) as {
259
+ luauExecutionSessionTaskLogs?: Array<{
260
+ messages?: string[];
261
+ structuredMessages?: Array<{ message: string }>;
262
+ }>;
263
+ nextPageToken?: string;
264
+ };
265
+
266
+ const messages: string[] = [];
267
+ for (const entry of data.luauExecutionSessionTaskLogs ?? []) {
268
+ if (entry.structuredMessages?.length) {
269
+ messages.push(...entry.structuredMessages.map((m) => m.message));
270
+ } else if (entry.messages?.length) {
271
+ messages.push(...entry.messages);
272
+ }
273
+ }
274
+
275
+ return { nextPageToken: data.nextPageToken || undefined, messages };
276
+ }
277
+ });
@@ -0,0 +1,174 @@
1
+ import { describe, expect, it, beforeEach, afterEach } from 'vitest';
2
+ import * as fs from 'fs/promises';
3
+ import * as os from 'os';
4
+ import * as path from 'path';
5
+ import {
6
+ buildAddPackagesCommand,
7
+ detectPackageManagerAsync,
8
+ isPackageManager,
9
+ } from './package-manager-utils.js';
10
+
11
+ describe('package-manager-utils', () => {
12
+ let root: string;
13
+
14
+ beforeEach(async () => {
15
+ root = await fs.mkdtemp(path.join(os.tmpdir(), 'nevermore-pm-'));
16
+ });
17
+
18
+ afterEach(async () => {
19
+ await fs.rm(root, { recursive: true, force: true });
20
+ });
21
+
22
+ async function writeFileAsync(relativePath: string, contents: string) {
23
+ const filePath = path.join(root, relativePath);
24
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
25
+ await fs.writeFile(filePath, contents);
26
+ }
27
+
28
+ describe('detectPackageManagerAsync', () => {
29
+ it('reads the packageManager field', async () => {
30
+ await writeFileAsync(
31
+ 'package.json',
32
+ JSON.stringify({ packageManager: 'pnpm@10.27.0' })
33
+ );
34
+
35
+ expect(await detectPackageManagerAsync(root)).toBe('pnpm');
36
+ });
37
+
38
+ it('prefers the packageManager field over a lockfile', async () => {
39
+ await writeFileAsync(
40
+ 'package.json',
41
+ JSON.stringify({ packageManager: 'yarn@4.0.0' })
42
+ );
43
+ await writeFileAsync('package-lock.json', '{}');
44
+
45
+ expect(await detectPackageManagerAsync(root)).toBe('yarn');
46
+ });
47
+
48
+ it('falls back to lockfiles', async () => {
49
+ await writeFileAsync('package.json', JSON.stringify({ name: 'game' }));
50
+ await writeFileAsync('pnpm-lock.yaml', '');
51
+
52
+ expect(await detectPackageManagerAsync(root)).toBe('pnpm');
53
+ });
54
+
55
+ it('treats a pnpm workspace file as pnpm', async () => {
56
+ await writeFileAsync('pnpm-workspace.yaml', 'packages:\n');
57
+
58
+ expect(await detectPackageManagerAsync(root)).toBe('pnpm');
59
+ });
60
+
61
+ it('walks up from a subdirectory', async () => {
62
+ await writeFileAsync(
63
+ 'package.json',
64
+ JSON.stringify({ packageManager: 'pnpm@10.27.0' })
65
+ );
66
+ await fs.mkdir(path.join(root, 'src', 'shared'), { recursive: true });
67
+
68
+ expect(
69
+ await detectPackageManagerAsync(path.join(root, 'src', 'shared'))
70
+ ).toBe('pnpm');
71
+ });
72
+
73
+ it('lets the nearest project win', async () => {
74
+ await writeFileAsync(
75
+ 'package.json',
76
+ JSON.stringify({ packageManager: 'pnpm@10.27.0' })
77
+ );
78
+ await writeFileAsync(
79
+ 'nested/package.json',
80
+ JSON.stringify({ packageManager: 'yarn@4.0.0' })
81
+ );
82
+
83
+ expect(await detectPackageManagerAsync(path.join(root, 'nested'))).toBe(
84
+ 'yarn'
85
+ );
86
+ });
87
+
88
+ it('ignores an unknown packageManager field', async () => {
89
+ await writeFileAsync(
90
+ 'package.json',
91
+ JSON.stringify({ packageManager: 'cnpm@1.0.0' })
92
+ );
93
+ await writeFileAsync('yarn.lock', '');
94
+
95
+ expect(await detectPackageManagerAsync(root)).toBe('yarn');
96
+ });
97
+
98
+ it('survives malformed package.json', async () => {
99
+ await writeFileAsync('package.json', '{ not json');
100
+ await writeFileAsync('pnpm-lock.yaml', '');
101
+
102
+ expect(await detectPackageManagerAsync(root)).toBe('pnpm');
103
+ });
104
+
105
+ it('defaults to pnpm', async () => {
106
+ expect(await detectPackageManagerAsync(root)).toBe('pnpm');
107
+ });
108
+
109
+ it('ignores a lockfile sitting in the home directory', async () => {
110
+ // npm leaves a package-lock.json behind after one `npm install` run in a
111
+ // home directory, and walking to the filesystem root adopted it — every
112
+ // project below it then installed with the one tool that rejects this
113
+ // repo's `workspace:` ranges. This test was the symptom: the temp dir
114
+ // lives under the home directory on Windows, so "defaults to pnpm" here
115
+ // failed on a machine that had one and passed everywhere else.
116
+ const home = await fs.realpath(os.homedir());
117
+ const marker = path.join(home, 'package-lock.json');
118
+ const alreadyThere = await fs
119
+ .access(marker)
120
+ .then(() => true)
121
+ .catch(() => false);
122
+
123
+ if (!alreadyThere) {
124
+ await fs.writeFile(marker, '{}');
125
+ }
126
+
127
+ try {
128
+ expect(await detectPackageManagerAsync(root)).toBe('pnpm');
129
+ } finally {
130
+ if (!alreadyThere) {
131
+ await fs.rm(marker, { force: true });
132
+ }
133
+ }
134
+ });
135
+
136
+ it('still honors an npm project', async () => {
137
+ await writeFileAsync('package.json', JSON.stringify({ name: 'game' }));
138
+ await writeFileAsync('package-lock.json', '{}');
139
+
140
+ expect(await detectPackageManagerAsync(root)).toBe('npm');
141
+ });
142
+ });
143
+
144
+ describe('buildAddPackagesCommand', () => {
145
+ it('uses install for npm', () => {
146
+ expect(buildAddPackagesCommand('npm', ['@quenty/blend'])).toEqual({
147
+ command: 'npm',
148
+ args: ['install', '@quenty/blend'],
149
+ });
150
+ });
151
+
152
+ it('uses add for everything else', () => {
153
+ expect(buildAddPackagesCommand('pnpm', ['@quenty/blend'])).toEqual({
154
+ command: 'pnpm',
155
+ args: ['add', '@quenty/blend'],
156
+ });
157
+ expect(buildAddPackagesCommand('yarn', ['@quenty/maid'])).toEqual({
158
+ command: 'yarn',
159
+ args: ['add', '@quenty/maid'],
160
+ });
161
+ expect(buildAddPackagesCommand('bun', ['@quenty/maid'])).toEqual({
162
+ command: 'bun',
163
+ args: ['add', '@quenty/maid'],
164
+ });
165
+ });
166
+ });
167
+
168
+ describe('isPackageManager', () => {
169
+ it('accepts known managers and rejects others', () => {
170
+ expect(isPackageManager('pnpm')).toBe(true);
171
+ expect(isPackageManager('deno')).toBe(false);
172
+ });
173
+ });
174
+ });
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Detects which package manager owns a project so commands install with the
3
+ * same tool the project was set up with.
4
+ */
5
+
6
+ import * as fs from 'fs/promises';
7
+ import * as os from 'os';
8
+ import * as path from 'path';
9
+
10
+ export const PACKAGE_MANAGERS = ['pnpm', 'npm', 'yarn', 'bun'] as const;
11
+
12
+ export type PackageManager = typeof PACKAGE_MANAGERS[number];
13
+
14
+ export const DEFAULT_PACKAGE_MANAGER: PackageManager = 'pnpm';
15
+
16
+ const LOCKFILES: ReadonlyArray<readonly [string, PackageManager]> = [
17
+ ['pnpm-lock.yaml', 'pnpm'],
18
+ ['pnpm-workspace.yaml', 'pnpm'],
19
+ ['bun.lock', 'bun'],
20
+ ['bun.lockb', 'bun'],
21
+ ['yarn.lock', 'yarn'],
22
+ ['package-lock.json', 'npm'],
23
+ ];
24
+
25
+ export function isPackageManager(value: string): value is PackageManager {
26
+ return (PACKAGE_MANAGERS as readonly string[]).includes(value);
27
+ }
28
+
29
+ function parsePackageManagerField(value: unknown): PackageManager | undefined {
30
+ if (typeof value !== 'string') {
31
+ return undefined;
32
+ }
33
+
34
+ const name = value.split('@')[0]?.trim();
35
+ if (name && isPackageManager(name)) {
36
+ return name;
37
+ }
38
+
39
+ return undefined;
40
+ }
41
+
42
+ async function detectInDirectoryAsync(
43
+ directory: string
44
+ ): Promise<PackageManager | undefined> {
45
+ try {
46
+ const contents = await fs.readFile(
47
+ path.join(directory, 'package.json'),
48
+ 'utf-8'
49
+ );
50
+ const parsed = JSON.parse(contents) as { packageManager?: unknown };
51
+ const declared = parsePackageManagerField(parsed.packageManager);
52
+ if (declared) {
53
+ return declared;
54
+ }
55
+ } catch {
56
+ // No readable package.json here, fall through to lockfiles
57
+ }
58
+
59
+ for (const [fileName, packageManager] of LOCKFILES) {
60
+ try {
61
+ await fs.access(path.join(directory, fileName));
62
+ return packageManager;
63
+ } catch {
64
+ continue;
65
+ }
66
+ }
67
+
68
+ return undefined;
69
+ }
70
+
71
+ /**
72
+ * Detects the package manager for a project, walking up from the given
73
+ * directory so this works from a subfolder of the project.
74
+ *
75
+ * A `packageManager` field wins over a lockfile in the same directory, and the
76
+ * nearest directory with either wins over anything further up. Falls back to
77
+ * pnpm: Nevermore projects are pnpm projects — the templates pin it and gate it
78
+ * behind `only-allow pnpm` — so pnpm is the right guess for a directory that
79
+ * hasn't declared anything yet.
80
+ */
81
+ export async function detectPackageManagerAsync(
82
+ startDirectory: string
83
+ ): Promise<PackageManager> {
84
+ let directory = await resolveRealPathAsync(path.resolve(startDirectory));
85
+ // Walking to the filesystem root adopts lockfiles that belong to nobody. A
86
+ // stray package-lock.json in a home directory — npm leaves one behind after a
87
+ // single `npm install` run there — made every project below it detect as npm,
88
+ // and in this monorepo that means installing with the one tool that rejects
89
+ // `workspace:` ranges outright. Nothing above the home directory can be part
90
+ // of the project, so the search stops there.
91
+ const boundary = await resolveRealPathAsync(os.homedir());
92
+
93
+ for (;;) {
94
+ if (boundary !== undefined && isSamePath(directory, boundary)) {
95
+ break;
96
+ }
97
+
98
+ const detected = await detectInDirectoryAsync(directory);
99
+ if (detected) {
100
+ return detected;
101
+ }
102
+
103
+ const parent = path.dirname(directory);
104
+ if (parent === directory) {
105
+ break;
106
+ }
107
+ directory = parent;
108
+ }
109
+
110
+ return DEFAULT_PACKAGE_MANAGER;
111
+ }
112
+
113
+ /**
114
+ * Resolve symlinks and, on Windows, 8.3 short names — `C:\Users\JAMESO~1` and
115
+ * `C:\Users\James Onnen` are the same directory and must compare equal.
116
+ * Returns the input unchanged when the path does not exist.
117
+ */
118
+ async function resolveRealPathAsync(target: string): Promise<string> {
119
+ try {
120
+ return await fs.realpath(target);
121
+ } catch {
122
+ return target;
123
+ }
124
+ }
125
+
126
+ /** Windows paths are case-insensitive; POSIX ones are not. */
127
+ function isSamePath(left: string, right: string): boolean {
128
+ if (process.platform === 'win32') {
129
+ return left.toLowerCase() === right.toLowerCase();
130
+ }
131
+ return left === right;
132
+ }
133
+
134
+ /**
135
+ * Builds the command that adds dependencies to a project. Only npm spells this
136
+ * `install`; the rest treat a bare `install` as "install the lockfile" and need
137
+ * `add` to record new dependencies.
138
+ */
139
+ export function buildAddPackagesCommand(
140
+ packageManager: PackageManager,
141
+ packages: string[]
142
+ ): { command: string; args: string[] } {
143
+ if (packageManager === 'npm') {
144
+ return { command: 'npm', args: ['install', ...packages] };
145
+ }
146
+
147
+ return { command: packageManager, args: ['add', ...packages] };
148
+ }