@quenty/nevermore-cli 4.42.0 → 4.42.1-canary.783.30683606415.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 (172) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/args/global-args.d.ts +13 -0
  3. package/dist/args/global-args.d.ts.map +1 -1
  4. package/dist/commands/batch-command/batch-deploy-command.d.ts +3 -0
  5. package/dist/commands/batch-command/batch-deploy-command.d.ts.map +1 -1
  6. package/dist/commands/batch-command/batch-deploy-command.js +90 -1
  7. package/dist/commands/batch-command/batch-deploy-command.js.map +1 -1
  8. package/dist/commands/batch-command/batch-test-command.d.ts.map +1 -1
  9. package/dist/commands/batch-command/batch-test-command.js +7 -2
  10. package/dist/commands/batch-command/batch-test-command.js.map +1 -1
  11. package/dist/commands/deploy-command/deploy-init.js +1 -1
  12. package/dist/commands/deploy-command/deploy-init.js.map +1 -1
  13. package/dist/commands/deploy-command/index.d.ts +3 -0
  14. package/dist/commands/deploy-command/index.d.ts.map +1 -1
  15. package/dist/commands/deploy-command/index.js +301 -60
  16. package/dist/commands/deploy-command/index.js.map +1 -1
  17. package/dist/commands/deploy-command/select-target.js +1 -1
  18. package/dist/commands/deploy-command/select-target.js.map +1 -1
  19. package/dist/commands/deploy-command/version-command.d.ts.map +1 -1
  20. package/dist/commands/deploy-command/version-command.js +138 -12
  21. package/dist/commands/deploy-command/version-command.js.map +1 -1
  22. package/dist/commands/test-command/test-command.d.ts.map +1 -1
  23. package/dist/commands/test-command/test-command.js +17 -7
  24. package/dist/commands/test-command/test-command.js.map +1 -1
  25. package/dist/nevermore.js +17 -0
  26. package/dist/nevermore.js.map +1 -1
  27. package/dist/utils/batch/changed-packages-utils.d.ts +1 -1
  28. package/dist/utils/batch/changed-packages-utils.d.ts.map +1 -1
  29. package/dist/utils/batch/changed-packages-utils.js +1 -1
  30. package/dist/utils/batch/changed-packages-utils.js.map +1 -1
  31. package/dist/utils/build/base-place-resolver-factory.d.ts +25 -0
  32. package/dist/utils/build/base-place-resolver-factory.d.ts.map +1 -0
  33. package/dist/utils/build/base-place-resolver-factory.js +40 -0
  34. package/dist/utils/build/base-place-resolver-factory.js.map +1 -0
  35. package/dist/utils/build/build.d.ts +13 -2
  36. package/dist/utils/build/build.d.ts.map +1 -1
  37. package/dist/utils/build/build.js.map +1 -1
  38. package/dist/utils/build/upload.d.ts +1 -1
  39. package/dist/utils/build/upload.d.ts.map +1 -1
  40. package/dist/utils/deploy/deploy-metadata.d.ts +1 -1
  41. package/dist/utils/deploy/deploy-metadata.d.ts.map +1 -1
  42. package/dist/utils/job-context/base-job-context.d.ts +3 -1
  43. package/dist/utils/job-context/base-job-context.d.ts.map +1 -1
  44. package/dist/utils/job-context/base-job-context.js +45 -6
  45. package/dist/utils/job-context/base-job-context.js.map +1 -1
  46. package/dist/utils/job-context/batch-script-job-context.d.ts +6 -0
  47. package/dist/utils/job-context/batch-script-job-context.d.ts.map +1 -1
  48. package/dist/utils/job-context/batch-script-job-context.js +13 -0
  49. package/dist/utils/job-context/batch-script-job-context.js.map +1 -1
  50. package/dist/utils/job-context/cloud-job-context.d.ts +2 -1
  51. package/dist/utils/job-context/cloud-job-context.d.ts.map +1 -1
  52. package/dist/utils/job-context/cloud-job-context.js +2 -2
  53. package/dist/utils/job-context/cloud-job-context.js.map +1 -1
  54. package/dist/utils/job-context/local-job-context.d.ts +2 -1
  55. package/dist/utils/job-context/local-job-context.d.ts.map +1 -1
  56. package/dist/utils/job-context/local-job-context.js +2 -2
  57. package/dist/utils/job-context/local-job-context.js.map +1 -1
  58. package/dist/utils/open-cloud/open-cloud-client.d.ts +20 -2
  59. package/dist/utils/open-cloud/open-cloud-client.d.ts.map +1 -1
  60. package/dist/utils/open-cloud/open-cloud-client.js +74 -20
  61. package/dist/utils/open-cloud/open-cloud-client.js.map +1 -1
  62. package/dist/utils/open-cloud/open-cloud-client.test.js +89 -12
  63. package/dist/utils/open-cloud/open-cloud-client.test.js.map +1 -1
  64. package/dist/utils/testing/runner/combined-project-generator.d.ts +1 -1
  65. package/dist/utils/testing/runner/combined-project-generator.d.ts.map +1 -1
  66. package/dist/utils/testing/runner/test-runner.d.ts +1 -1
  67. package/dist/utils/testing/runner/test-runner.d.ts.map +1 -1
  68. package/dist/utils/watch/github-context.d.ts +50 -0
  69. package/dist/utils/watch/github-context.d.ts.map +1 -0
  70. package/dist/utils/watch/github-context.js +125 -0
  71. package/dist/utils/watch/github-context.js.map +1 -0
  72. package/dist/utils/watch/github-context.test.d.ts +2 -0
  73. package/dist/utils/watch/github-context.test.d.ts.map +1 -0
  74. package/dist/utils/watch/github-context.test.js +112 -0
  75. package/dist/utils/watch/github-context.test.js.map +1 -0
  76. package/dist/utils/watch/http-watch-registry.d.ts +40 -0
  77. package/dist/utils/watch/http-watch-registry.d.ts.map +1 -0
  78. package/dist/utils/watch/http-watch-registry.js +262 -0
  79. package/dist/utils/watch/http-watch-registry.js.map +1 -0
  80. package/dist/utils/watch/http-watch-registry.test.d.ts +2 -0
  81. package/dist/utils/watch/http-watch-registry.test.d.ts.map +1 -0
  82. package/dist/utils/watch/http-watch-registry.test.js +211 -0
  83. package/dist/utils/watch/http-watch-registry.test.js.map +1 -0
  84. package/dist/utils/watch/local-watch-loop.d.ts +50 -0
  85. package/dist/utils/watch/local-watch-loop.d.ts.map +1 -0
  86. package/dist/utils/watch/local-watch-loop.js +103 -0
  87. package/dist/utils/watch/local-watch-loop.js.map +1 -0
  88. package/dist/utils/watch/local-watch-loop.test.d.ts +2 -0
  89. package/dist/utils/watch/local-watch-loop.test.d.ts.map +1 -0
  90. package/dist/utils/watch/local-watch-loop.test.js +170 -0
  91. package/dist/utils/watch/local-watch-loop.test.js.map +1 -0
  92. package/dist/utils/watch/register-notify-watches.d.ts +41 -0
  93. package/dist/utils/watch/register-notify-watches.d.ts.map +1 -0
  94. package/dist/utils/watch/register-notify-watches.js +159 -0
  95. package/dist/utils/watch/register-notify-watches.js.map +1 -0
  96. package/dist/utils/watch/register-notify-watches.test.d.ts +2 -0
  97. package/dist/utils/watch/register-notify-watches.test.d.ts.map +1 -0
  98. package/dist/utils/watch/register-notify-watches.test.js +225 -0
  99. package/dist/utils/watch/register-notify-watches.test.js.map +1 -0
  100. package/dist/utils/watch/register-watches.d.ts +68 -0
  101. package/dist/utils/watch/register-watches.d.ts.map +1 -0
  102. package/dist/utils/watch/register-watches.js +221 -0
  103. package/dist/utils/watch/register-watches.js.map +1 -0
  104. package/dist/utils/watch/register-watches.test.d.ts +2 -0
  105. package/dist/utils/watch/register-watches.test.d.ts.map +1 -0
  106. package/dist/utils/watch/register-watches.test.js +576 -0
  107. package/dist/utils/watch/register-watches.test.js.map +1 -0
  108. package/dist/utils/watch/stream-watch-loop.d.ts +54 -0
  109. package/dist/utils/watch/stream-watch-loop.d.ts.map +1 -0
  110. package/dist/utils/watch/stream-watch-loop.js +282 -0
  111. package/dist/utils/watch/stream-watch-loop.js.map +1 -0
  112. package/dist/utils/watch/stream-watch-loop.test.d.ts +2 -0
  113. package/dist/utils/watch/stream-watch-loop.test.d.ts.map +1 -0
  114. package/dist/utils/watch/stream-watch-loop.test.js +392 -0
  115. package/dist/utils/watch/stream-watch-loop.test.js.map +1 -0
  116. package/dist/utils/watch/websocket-watch-stream.d.ts +25 -0
  117. package/dist/utils/watch/websocket-watch-stream.d.ts.map +1 -0
  118. package/dist/utils/watch/websocket-watch-stream.js +306 -0
  119. package/dist/utils/watch/websocket-watch-stream.js.map +1 -0
  120. package/dist/utils/watch/websocket-watch-stream.test.d.ts +2 -0
  121. package/dist/utils/watch/websocket-watch-stream.test.d.ts.map +1 -0
  122. package/dist/utils/watch/websocket-watch-stream.test.js +475 -0
  123. package/dist/utils/watch/websocket-watch-stream.test.js.map +1 -0
  124. package/package.json +7 -4
  125. package/src/args/global-args.ts +13 -0
  126. package/src/commands/batch-command/batch-deploy-command.ts +105 -1
  127. package/src/commands/batch-command/batch-test-command.ts +8 -2
  128. package/src/commands/deploy-command/deploy-init.ts +1 -1
  129. package/src/commands/deploy-command/index.ts +331 -32
  130. package/src/commands/deploy-command/select-target.ts +1 -1
  131. package/src/commands/deploy-command/version-command.ts +215 -21
  132. package/src/commands/test-command/test-command.ts +24 -18
  133. package/src/nevermore.ts +19 -0
  134. package/src/utils/batch/changed-packages-utils.ts +1 -1
  135. package/src/utils/build/base-place-resolver-factory.ts +49 -0
  136. package/src/utils/build/build.ts +13 -2
  137. package/src/utils/build/upload.ts +1 -1
  138. package/src/utils/deploy/deploy-metadata.ts +1 -1
  139. package/src/utils/job-context/base-job-context.ts +68 -6
  140. package/src/utils/job-context/batch-script-job-context.ts +18 -0
  141. package/src/utils/job-context/cloud-job-context.ts +7 -2
  142. package/src/utils/job-context/local-job-context.ts +7 -2
  143. package/src/utils/open-cloud/open-cloud-client.test.ts +133 -14
  144. package/src/utils/open-cloud/open-cloud-client.ts +127 -34
  145. package/src/utils/testing/runner/combined-project-generator.ts +1 -1
  146. package/src/utils/testing/runner/test-runner.ts +1 -1
  147. package/src/utils/watch/github-context.test.ts +154 -0
  148. package/src/utils/watch/github-context.ts +184 -0
  149. package/src/utils/watch/http-watch-registry.test.ts +330 -0
  150. package/src/utils/watch/http-watch-registry.ts +341 -0
  151. package/src/utils/watch/local-watch-loop.test.ts +197 -0
  152. package/src/utils/watch/local-watch-loop.ts +190 -0
  153. package/src/utils/watch/register-notify-watches.test.ts +282 -0
  154. package/src/utils/watch/register-notify-watches.ts +226 -0
  155. package/src/utils/watch/register-watches.test.ts +696 -0
  156. package/src/utils/watch/register-watches.ts +369 -0
  157. package/src/utils/watch/stream-watch-loop.test.ts +625 -0
  158. package/src/utils/watch/stream-watch-loop.ts +411 -0
  159. package/src/utils/watch/websocket-watch-stream.test.ts +581 -0
  160. package/src/utils/watch/websocket-watch-stream.ts +403 -0
  161. package/tsconfig.json +19 -6
  162. package/tsconfig.tsbuildinfo +1 -1
  163. package/dist/utils/build/deploy-config.d.ts +0 -71
  164. package/dist/utils/build/deploy-config.d.ts.map +0 -1
  165. package/dist/utils/build/deploy-config.js +0 -164
  166. package/dist/utils/build/deploy-config.js.map +0 -1
  167. package/dist/utils/build/deploy-config.test.d.ts +0 -2
  168. package/dist/utils/build/deploy-config.test.d.ts.map +0 -1
  169. package/dist/utils/build/deploy-config.test.js +0 -126
  170. package/dist/utils/build/deploy-config.test.js.map +0 -1
  171. package/src/utils/build/deploy-config.test.ts +0 -149
  172. package/src/utils/build/deploy-config.ts +0 -259
@@ -0,0 +1,369 @@
1
+ import { OutputHelper } from '@quenty/cli-output-helpers';
2
+ import {
3
+ WATCH_BASELINE_KIND,
4
+ WATCH_INPUT_NAME,
5
+ buildWatchPlan,
6
+ describeWatchPlanSkip,
7
+ parseTargetSelector,
8
+ sanitizeWatchName,
9
+ type BasePlaceResolver,
10
+ type DeployTarget,
11
+ type WatchEntry,
12
+ type WatchOption,
13
+ type WatchRegistrationRequest,
14
+ type WatchRegistry,
15
+ type WatchWorkflowDispatchAction,
16
+ } from '@quenty/nevermore-deploy';
17
+ import { HttpWatchRegistry } from './http-watch-registry.js';
18
+ import {
19
+ describeGithubContextFailure,
20
+ describeMissingWatchToken,
21
+ tryResolveGithubDispatchContext,
22
+ } from './github-context.js';
23
+
24
+ /**
25
+ * A watch this path is registering, narrowed to the action it always builds.
26
+ *
27
+ * `WatchEntry.action` is a union because a monitor can also notify a held
28
+ * stream, but this is the CI-shaped half of `--watch` and only ever dispatches
29
+ * a workflow — narrowing here keeps `ref` and `inputs` reachable without a cast.
30
+ */
31
+ type DispatchWatchEntry = WatchEntry & { action: WatchWorkflowDispatchAction };
32
+
33
+ /** One place `--watch` should consider registering. */
34
+ export interface WatchCandidate {
35
+ /**
36
+ * Deploy target the place belongs to. A selector (`integration.places.hub`)
37
+ * is accepted and narrowed to its target, since the dispatch selector is
38
+ * rebuilt from the target and the place — appending to a selector that
39
+ * already names a place would produce `integration.places.hub.places.hub`,
40
+ * which nothing can re-resolve.
41
+ */
42
+ targetName: string;
43
+ /** npm package name, used to keep watch names unique across a batch. */
44
+ packageName: string;
45
+ /** Package directory, used to read the base place version out of the lock. */
46
+ packagePath: string;
47
+ place: DeployTarget;
48
+ }
49
+
50
+ export interface RegisterWatchesOptions {
51
+ option: WatchOption;
52
+ /**
53
+ * Lease key within the repository. Every watch this invocation is
54
+ * responsible for goes under this one name, and re-registering replaces the
55
+ * whole list — so the candidates must be the complete set, not just what
56
+ * deployed.
57
+ */
58
+ monitorName: string;
59
+ candidates: WatchCandidate[];
60
+ /**
61
+ * Open Cloud key to share, so the service can read private base places, see
62
+ * `"saved"` versions, and report versions in the same vocabulary as the lock.
63
+ */
64
+ robloxApiKey?: string;
65
+ /** Reads base place versions out of the lock, for baselines. */
66
+ resolver: BasePlaceResolver;
67
+ /** Let the GitHub CLI supply the token when no env var does. */
68
+ useGhAuth?: boolean;
69
+ /**
70
+ * Force a dispatch immediately after registering, ignoring drift.
71
+ *
72
+ * Registering only proves the service accepted the config. Firing proves the
73
+ * workflow actually receives the selector, which is the half that has
74
+ * historically broken — so a dryrun asks for it.
75
+ */
76
+ triggerAfterRegister?: boolean;
77
+ /** Injected in tests; defaults to the HTTP registry. */
78
+ createRegistry?: (registerUrl: string) => WatchRegistry;
79
+ }
80
+
81
+ export interface RegisterWatchesResult {
82
+ /** Watches in the registered monitor. Zero means nothing was sent. */
83
+ registered: number;
84
+ /** True when the service reported the config differing from what it held. */
85
+ changed?: boolean;
86
+ /** Watches that dispatched, when a trigger was requested. */
87
+ triggered?: number;
88
+ }
89
+
90
+ /**
91
+ * Register every watch this invocation owns, in one call.
92
+ *
93
+ * One call is not just an efficiency: the service replaces a monitor's entire
94
+ * watch list on re-apply, so splitting a run across several registrations under
95
+ * one name would leave only the last one standing. The caller decides what the
96
+ * complete set is; this turns it into a request.
97
+ *
98
+ * Runs after the deploy so the monitor only exists once the build it is meant
99
+ * to keep fresh has actually shipped.
100
+ */
101
+ export async function registerWatchesAsync(
102
+ options: RegisterWatchesOptions
103
+ ): Promise<RegisterWatchesResult> {
104
+ const { option, candidates, resolver } = options;
105
+ // What the service can see, and what language it will answer in.
106
+ const credentialed = options.robloxApiKey != null;
107
+
108
+ const watches: DispatchWatchEntry[] = [];
109
+ const skipped: string[] = [];
110
+
111
+ // A place that declared `watch` and then got left out is worth saying out
112
+ // loud — the user asked for it. A place that never declared one is just
113
+ // ordinary config, and there are usually many, so that stays verbose-only.
114
+ const unmet: string[] = [];
115
+
116
+ for (const candidate of candidates) {
117
+ const { targetName } = parseTargetSelector(candidate.targetName);
118
+ const plan = buildWatchPlan(targetName, [candidate.place], {
119
+ credentialed,
120
+ });
121
+ for (const skip of plan.skipped) {
122
+ const described = describeWatchPlanSkip(skip);
123
+ skipped.push(described);
124
+ if (skip.reason !== 'no-watch-field') {
125
+ unmet.push(described);
126
+ }
127
+ }
128
+ for (const entry of plan.entries) {
129
+ watches.push(
130
+ await _buildWatchEntryAsync(
131
+ resolver,
132
+ candidate,
133
+ targetName,
134
+ entry,
135
+ credentialed
136
+ )
137
+ );
138
+ }
139
+ }
140
+
141
+ _disambiguateWatchNames(watches);
142
+
143
+ if (skipped.length > 0) {
144
+ OutputHelper.verbose(`Not watching ${skipped.length} place(s):`);
145
+ for (const line of skipped) {
146
+ OutputHelper.verbose(` ${line}`);
147
+ }
148
+ }
149
+
150
+ if (watches.length === 0) {
151
+ OutputHelper.warn(
152
+ [
153
+ '--watch was requested, but no place is watchable.',
154
+ ...skipped.map((line) => ` ${line}`),
155
+ 'Add a "watch" path and a "published" basePlace to the place you want ' +
156
+ 'hot-reloaded.',
157
+ ].join('\n')
158
+ );
159
+ return { registered: 0 };
160
+ }
161
+
162
+ if (unmet.length > 0) {
163
+ OutputHelper.warn(
164
+ [
165
+ `${unmet.length} place(s) asked to be watched but could not be:`,
166
+ ...unmet.map((line) => ` ${line}`),
167
+ ].join('\n')
168
+ );
169
+ }
170
+
171
+ const contextResult = tryResolveGithubDispatchContext({
172
+ useGhAuth: options.useGhAuth,
173
+ });
174
+ if (!contextResult.success) {
175
+ throw new Error(describeGithubContextFailure(contextResult.reason));
176
+ }
177
+ const context = contextResult.context;
178
+ if (!context.token) {
179
+ throw new Error(describeMissingWatchToken());
180
+ }
181
+
182
+ // The ref is baked into each action rather than left to the service's
183
+ // default-branch fallback: a watch registered from a branch should rebuild
184
+ // that branch, not whatever main happens to hold.
185
+ for (const watch of watches) {
186
+ watch.action.ref = context.ref;
187
+ }
188
+
189
+ const request: WatchRegistrationRequest = {
190
+ // The ref is part of the monitor's identity because it is part of what the
191
+ // monitor does: every action dispatches at `context.ref`. Without it, a
192
+ // `batch deploy --watch` from any branch would re-point the production
193
+ // monitor's whole watch list at that branch, and the next base place edit
194
+ // would rebuild the wrong ref — or a deleted one.
195
+ monitorName: sanitizeWatchName(`${options.monitorName}/${context.ref}`),
196
+ repository: context.repository,
197
+ githubToken: context.token,
198
+ robloxApiKey: options.robloxApiKey,
199
+ watches,
200
+ };
201
+
202
+ const registry = (options.createRegistry ?? _defaultRegistry)(
203
+ option.registerUrl
204
+ );
205
+ const result = await registry.registerAsync(request);
206
+
207
+ const label = result.changed === false ? 'Renewed' : 'Registered';
208
+ OutputHelper.info(
209
+ `${label} watch monitor "${request.monitorName}" — ${watches.length} ` +
210
+ `watch${watches.length === 1 ? '' : 'es'}, lease ${option.lease}` +
211
+ (result.leaseExpiresAt ? ` (expires ${result.leaseExpiresAt})` : '')
212
+ );
213
+ for (const watch of watches) {
214
+ OutputHelper.verbose(
215
+ ` ${watch.name}: base place ${watch.source.placeId} → ` +
216
+ `${watch.action.inputs?.[WATCH_INPUT_NAME] ?? watch.action.workflow}`
217
+ );
218
+ }
219
+
220
+ let triggered: number | undefined;
221
+ if (options.triggerAfterRegister) {
222
+ triggered = await _triggerAsync(registry, result, context.token);
223
+ }
224
+
225
+ return { registered: watches.length, changed: result.changed, triggered };
226
+ }
227
+
228
+ /**
229
+ * Force a dispatch and report what each watch did.
230
+ *
231
+ * Reported rather than thrown: the registration succeeded, and a monitor that
232
+ * exists is worth keeping even if the demonstration dispatch failed. The
233
+ * per-watch `ok` is what actually proves routing, so a failure there is
234
+ * surfaced loudly.
235
+ */
236
+ async function _triggerAsync(
237
+ registry: WatchRegistry,
238
+ result: { monitorId?: string },
239
+ token: string
240
+ ): Promise<number | undefined> {
241
+ if (!result.monitorId) {
242
+ OutputHelper.warn(
243
+ 'Registered, but the service returned no monitorId — cannot force a ' +
244
+ 'dispatch to prove routing.'
245
+ );
246
+ return undefined;
247
+ }
248
+
249
+ let outcome;
250
+ try {
251
+ outcome = await registry.triggerAsync(result.monitorId, token);
252
+ } catch (err) {
253
+ OutputHelper.error(
254
+ `Registered, but forcing a dispatch failed: ` +
255
+ (err instanceof Error ? err.message : String(err))
256
+ );
257
+ return undefined;
258
+ }
259
+
260
+ const ok = outcome.results.filter((r) => r.ok !== false);
261
+ const failed = outcome.results.filter((r) => r.ok === false);
262
+
263
+ OutputHelper.info(
264
+ `Forced a dispatch: ${ok.length} of ${outcome.results.length} watch` +
265
+ `${outcome.results.length === 1 ? '' : 'es'} fired.`
266
+ );
267
+ for (const r of outcome.results) {
268
+ const line = ` ${r.watchName ?? '(unnamed)'}: ${
269
+ r.ok === false ? 'FAILED' : 'dispatched'
270
+ }${r.detail ? ` — ${r.detail}` : ''}`;
271
+ if (r.ok === false) {
272
+ OutputHelper.warn(line);
273
+ } else {
274
+ OutputHelper.info(line);
275
+ }
276
+ }
277
+ if (failed.length > 0) {
278
+ OutputHelper.warn(
279
+ 'A watch registered but could not dispatch. The routing is not working ' +
280
+ 'end to end yet — check the workflow path and the ref.'
281
+ );
282
+ }
283
+
284
+ return ok.length;
285
+ }
286
+
287
+ function _defaultRegistry(registerUrl: string): WatchRegistry {
288
+ return new HttpWatchRegistry({ registerUrl });
289
+ }
290
+
291
+ /**
292
+ * Make every watch name unique within the monitor.
293
+ *
294
+ * `Watch.name` is documented as unique per monitor but the schema does not
295
+ * enforce it, so a collision is resolved server-side — silently dropping a
296
+ * watch rather than failing. Places are only *optionally* named, so a
297
+ * multi-place target with unnamed places collides by construction. Appending
298
+ * the base place id disambiguates without failing a deploy that already
299
+ * shipped, and only touches the names that actually clash.
300
+ */
301
+ function _disambiguateWatchNames(watches: WatchEntry[]): void {
302
+ const byName = new Map<string, WatchEntry[]>();
303
+ for (const watch of watches) {
304
+ const group = byName.get(watch.name);
305
+ if (group) {
306
+ group.push(watch);
307
+ } else {
308
+ byName.set(watch.name, [watch]);
309
+ }
310
+ }
311
+
312
+ for (const group of byName.values()) {
313
+ if (group.length === 1) {
314
+ continue;
315
+ }
316
+ for (const watch of group) {
317
+ watch.name = sanitizeWatchName(`${watch.name}/${watch.source.placeId}`);
318
+ }
319
+ }
320
+ }
321
+
322
+ async function _buildWatchEntryAsync(
323
+ resolver: BasePlaceResolver,
324
+ candidate: WatchCandidate,
325
+ targetName: string,
326
+ entry: { selector: string; workflow: string },
327
+ credentialed: boolean
328
+ ): Promise<DispatchWatchEntry> {
329
+ const basePlace = candidate.place.basePlace!;
330
+
331
+ // From the lock, not the network: this is the version the build we just
332
+ // shipped was made from. A package that did not deploy this run still has a
333
+ // lock entry, which is exactly the right baseline for it — it is how the
334
+ // service notices a change that happened while that package was untouched.
335
+ //
336
+ // Only when a key is shared. Reading anonymously, the service compares
337
+ // asset-delivery content hashes, and a place version number could never match
338
+ // one — it would read as drift and rebuild on the first poll.
339
+ const baseline = credentialed
340
+ ? await resolver.peekAsync(candidate.packagePath, basePlace)
341
+ : undefined;
342
+
343
+ return {
344
+ name: sanitizeWatchName(
345
+ `${candidate.packageName}/${candidate.place.name ?? targetName}`
346
+ ),
347
+ source: {
348
+ type: 'roblox-place',
349
+ universeId: basePlace.universeId,
350
+ placeId: basePlace.placeId,
351
+ // An omitted pin resolves as "published", the same default the resolver
352
+ // builds with, so the watch observes exactly what the build used.
353
+ versionType: basePlace.version === 'saved' ? 'saved' : 'published',
354
+ },
355
+ ...(baseline == null
356
+ ? {}
357
+ : {
358
+ baselineVersion: String(baseline),
359
+ // Declared so a vocabulary mismatch is a 422 at the moment the
360
+ // manifest changed, rather than one silent rebuild later.
361
+ baselineVersionKind: WATCH_BASELINE_KIND,
362
+ }),
363
+ action: {
364
+ type: 'github-workflow-dispatch',
365
+ workflow: entry.workflow,
366
+ inputs: { [WATCH_INPUT_NAME]: entry.selector },
367
+ },
368
+ };
369
+ }