@quenty/nevermore-cli 4.43.4 → 4.45.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 (147) 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/deploy-init.d.ts.map +1 -1
  13. package/dist/commands/deploy-command/deploy-init.js +24 -7
  14. package/dist/commands/deploy-command/deploy-init.js.map +1 -1
  15. package/dist/commands/deploy-command/index.js +1 -1
  16. package/dist/commands/deploy-command/index.js.map +1 -1
  17. package/dist/utils/deploy/deploy-github-columns.d.ts +12 -2
  18. package/dist/utils/deploy/deploy-github-columns.d.ts.map +1 -1
  19. package/dist/utils/deploy/deploy-github-columns.js +11 -4
  20. package/dist/utils/deploy/deploy-github-columns.js.map +1 -1
  21. package/dist/utils/deploy/deploy-metadata.js +1 -1
  22. package/dist/utils/deploy/deploy-metadata.js.map +1 -1
  23. package/dist/utils/job-context/base-job-context.d.ts +2 -2
  24. package/dist/utils/job-context/base-job-context.d.ts.map +1 -1
  25. package/dist/utils/job-context/base-job-context.js +1 -1
  26. package/dist/utils/job-context/base-job-context.js.map +1 -1
  27. package/dist/utils/job-context/batch-script-job-context.d.ts +37 -2
  28. package/dist/utils/job-context/batch-script-job-context.d.ts.map +1 -1
  29. package/dist/utils/job-context/batch-script-job-context.js +59 -22
  30. package/dist/utils/job-context/batch-script-job-context.js.map +1 -1
  31. package/dist/utils/job-context/cloud-job-context.d.ts +2 -2
  32. package/dist/utils/job-context/cloud-job-context.d.ts.map +1 -1
  33. package/dist/utils/job-context/cloud-job-context.js +10 -5
  34. package/dist/utils/job-context/cloud-job-context.js.map +1 -1
  35. package/dist/utils/job-context/cloud-job-context.test.d.ts +7 -0
  36. package/dist/utils/job-context/cloud-job-context.test.d.ts.map +1 -0
  37. package/dist/utils/job-context/cloud-job-context.test.js +91 -0
  38. package/dist/utils/job-context/cloud-job-context.test.js.map +1 -0
  39. package/dist/utils/job-context/job-context.d.ts +70 -2
  40. package/dist/utils/job-context/job-context.d.ts.map +1 -1
  41. package/dist/utils/job-context/local-job-context.d.ts +2 -2
  42. package/dist/utils/job-context/local-job-context.d.ts.map +1 -1
  43. package/dist/utils/job-context/local-job-context.js +4 -2
  44. package/dist/utils/job-context/local-job-context.js.map +1 -1
  45. package/dist/utils/job-context/local-job-context.test.d.ts +7 -0
  46. package/dist/utils/job-context/local-job-context.test.d.ts.map +1 -0
  47. package/dist/utils/job-context/local-job-context.test.js +68 -0
  48. package/dist/utils/job-context/local-job-context.test.js.map +1 -0
  49. package/dist/utils/open-cloud/open-cloud-client.d.ts +50 -7
  50. package/dist/utils/open-cloud/open-cloud-client.d.ts.map +1 -1
  51. package/dist/utils/open-cloud/open-cloud-client.js +49 -13
  52. package/dist/utils/open-cloud/open-cloud-client.js.map +1 -1
  53. package/dist/utils/open-cloud/open-cloud-client.test.js +125 -1
  54. package/dist/utils/open-cloud/open-cloud-client.test.js.map +1 -1
  55. package/dist/utils/open-cloud/open-cloud-logs.characterization.test.d.ts +22 -0
  56. package/dist/utils/open-cloud/open-cloud-logs.characterization.test.d.ts.map +1 -0
  57. package/dist/utils/open-cloud/open-cloud-logs.characterization.test.js +202 -0
  58. package/dist/utils/open-cloud/open-cloud-logs.characterization.test.js.map +1 -0
  59. package/dist/utils/package-manager-utils.d.ts.map +1 -1
  60. package/dist/utils/package-manager-utils.js +32 -1
  61. package/dist/utils/package-manager-utils.js.map +1 -1
  62. package/dist/utils/package-manager-utils.test.js +25 -0
  63. package/dist/utils/package-manager-utils.test.js.map +1 -1
  64. package/dist/utils/testing/batch-run.e2e.test.d.ts +17 -0
  65. package/dist/utils/testing/batch-run.e2e.test.d.ts.map +1 -0
  66. package/dist/utils/testing/batch-run.e2e.test.js +343 -0
  67. package/dist/utils/testing/batch-run.e2e.test.js.map +1 -0
  68. package/dist/utils/testing/batch-test-runner-template.test.d.ts +11 -0
  69. package/dist/utils/testing/batch-test-runner-template.test.d.ts.map +1 -0
  70. package/dist/utils/testing/batch-test-runner-template.test.js +38 -0
  71. package/dist/utils/testing/batch-test-runner-template.test.js.map +1 -0
  72. package/dist/utils/testing/log-fetch-stats.d.ts +40 -0
  73. package/dist/utils/testing/log-fetch-stats.d.ts.map +1 -0
  74. package/dist/utils/testing/log-fetch-stats.js +18 -0
  75. package/dist/utils/testing/log-fetch-stats.js.map +1 -0
  76. package/dist/utils/testing/log-fetch-stats.test.d.ts +2 -0
  77. package/dist/utils/testing/log-fetch-stats.test.d.ts.map +1 -0
  78. package/dist/utils/testing/log-fetch-stats.test.js +41 -0
  79. package/dist/utils/testing/log-fetch-stats.test.js.map +1 -0
  80. package/dist/utils/testing/parsers/batch-log-parser.d.ts +126 -1
  81. package/dist/utils/testing/parsers/batch-log-parser.d.ts.map +1 -1
  82. package/dist/utils/testing/parsers/batch-log-parser.js +440 -103
  83. package/dist/utils/testing/parsers/batch-log-parser.js.map +1 -1
  84. package/dist/utils/testing/parsers/batch-log-parser.test.js +494 -1
  85. package/dist/utils/testing/parsers/batch-log-parser.test.js.map +1 -1
  86. package/dist/utils/testing/parsers/batch-log-renderer.d.ts +79 -0
  87. package/dist/utils/testing/parsers/batch-log-renderer.d.ts.map +1 -0
  88. package/dist/utils/testing/parsers/batch-log-renderer.js +241 -0
  89. package/dist/utils/testing/parsers/batch-log-renderer.js.map +1 -0
  90. package/dist/utils/testing/parsers/batch-log-renderer.test.d.ts +2 -0
  91. package/dist/utils/testing/parsers/batch-log-renderer.test.d.ts.map +1 -0
  92. package/dist/utils/testing/parsers/batch-log-renderer.test.js +202 -0
  93. package/dist/utils/testing/parsers/batch-log-renderer.test.js.map +1 -0
  94. package/dist/utils/testing/runner/combined-project-generator.js +1 -1
  95. package/dist/utils/testing/runner/combined-project-generator.js.map +1 -1
  96. package/dist/utils/testing/runner/test-runner.d.ts +24 -0
  97. package/dist/utils/testing/runner/test-runner.d.ts.map +1 -1
  98. package/dist/utils/testing/runner/test-runner.js +166 -6
  99. package/dist/utils/testing/runner/test-runner.js.map +1 -1
  100. package/dist/utils/testing/runner/test-runner.test.js +228 -2
  101. package/dist/utils/testing/runner/test-runner.test.js.map +1 -1
  102. package/dist/utils/testing/structured-test-results.d.ts +77 -0
  103. package/dist/utils/testing/structured-test-results.d.ts.map +1 -0
  104. package/dist/utils/testing/structured-test-results.js +140 -0
  105. package/dist/utils/testing/structured-test-results.js.map +1 -0
  106. package/dist/utils/testing/structured-test-results.test.d.ts +7 -0
  107. package/dist/utils/testing/structured-test-results.test.d.ts.map +1 -0
  108. package/dist/utils/testing/structured-test-results.test.js +179 -0
  109. package/dist/utils/testing/structured-test-results.test.js.map +1 -0
  110. package/package.json +6 -6
  111. package/src/commands/batch-command/batch-deploy-command.ts +4 -4
  112. package/src/commands/batch-command/batch-test-command.ts +94 -19
  113. package/src/commands/deploy-command/deploy-init-utils.ts +7 -1
  114. package/src/commands/deploy-command/deploy-init.ts +41 -11
  115. package/src/commands/deploy-command/index.ts +1 -1
  116. package/src/utils/deploy/deploy-github-columns.ts +14 -4
  117. package/src/utils/deploy/deploy-metadata.ts +1 -1
  118. package/src/utils/job-context/base-job-context.ts +3 -2
  119. package/src/utils/job-context/batch-script-job-context.ts +98 -17
  120. package/src/utils/job-context/cloud-job-context.test.ts +112 -0
  121. package/src/utils/job-context/cloud-job-context.ts +12 -6
  122. package/src/utils/job-context/job-context.ts +71 -2
  123. package/src/utils/job-context/local-job-context.test.ts +89 -0
  124. package/src/utils/job-context/local-job-context.ts +7 -3
  125. package/src/utils/open-cloud/open-cloud-client.test.ts +155 -1
  126. package/src/utils/open-cloud/open-cloud-client.ts +94 -18
  127. package/src/utils/open-cloud/open-cloud-logs.characterization.test.ts +277 -0
  128. package/src/utils/package-manager-utils.test.ts +27 -0
  129. package/src/utils/package-manager-utils.ts +34 -1
  130. package/src/utils/testing/batch-run.e2e.test.ts +425 -0
  131. package/src/utils/testing/batch-test-runner-template.test.ts +62 -0
  132. package/src/utils/testing/log-fetch-stats.test.ts +48 -0
  133. package/src/utils/testing/log-fetch-stats.ts +55 -0
  134. package/src/utils/testing/parsers/batch-log-parser.test.ts +660 -1
  135. package/src/utils/testing/parsers/batch-log-parser.ts +721 -116
  136. package/src/utils/testing/parsers/batch-log-renderer.test.ts +330 -0
  137. package/src/utils/testing/parsers/batch-log-renderer.ts +329 -0
  138. package/src/utils/testing/runner/combined-project-generator.ts +1 -1
  139. package/src/utils/testing/runner/test-runner.test.ts +332 -2
  140. package/src/utils/testing/runner/test-runner.ts +231 -9
  141. package/src/utils/testing/structured-test-results.test.ts +267 -0
  142. package/src/utils/testing/structured-test-results.ts +199 -0
  143. package/templates/batch-test-runner.lua +242 -0
  144. package/tsconfig.tsbuildinfo +1 -1
  145. package/templates/batch-test-runner.luau +0 -137
  146. /package/build-scripts/{smoke-test-server.luau → smoke-test-server.lua} +0 -0
  147. /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
+ });
@@ -106,6 +106,33 @@ describe('package-manager-utils', () => {
106
106
  expect(await detectPackageManagerAsync(root)).toBe('pnpm');
107
107
  });
108
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
+
109
136
  it('still honors an npm project', async () => {
110
137
  await writeFileAsync('package.json', JSON.stringify({ name: 'game' }));
111
138
  await writeFileAsync('package-lock.json', '{}');
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import * as fs from 'fs/promises';
7
+ import * as os from 'os';
7
8
  import * as path from 'path';
8
9
 
9
10
  export const PACKAGE_MANAGERS = ['pnpm', 'npm', 'yarn', 'bun'] as const;
@@ -80,9 +81,20 @@ async function detectInDirectoryAsync(
80
81
  export async function detectPackageManagerAsync(
81
82
  startDirectory: string
82
83
  ): Promise<PackageManager> {
83
- let directory = path.resolve(startDirectory);
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());
84
92
 
85
93
  for (;;) {
94
+ if (boundary !== undefined && isSamePath(directory, boundary)) {
95
+ break;
96
+ }
97
+
86
98
  const detected = await detectInDirectoryAsync(directory);
87
99
  if (detected) {
88
100
  return detected;
@@ -98,6 +110,27 @@ export async function detectPackageManagerAsync(
98
110
  return DEFAULT_PACKAGE_MANAGER;
99
111
  }
100
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
+
101
134
  /**
102
135
  * Builds the command that adds dependencies to a project. Only npm spells this
103
136
  * `install`; the rest treat a bare `install` as "install the lockfile" and need