@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.
- package/CHANGELOG.md +22 -0
- package/dist/args/global-args.d.ts +13 -0
- package/dist/args/global-args.d.ts.map +1 -1
- package/dist/commands/batch-command/batch-deploy-command.d.ts +3 -0
- package/dist/commands/batch-command/batch-deploy-command.d.ts.map +1 -1
- package/dist/commands/batch-command/batch-deploy-command.js +90 -1
- package/dist/commands/batch-command/batch-deploy-command.js.map +1 -1
- package/dist/commands/batch-command/batch-test-command.d.ts.map +1 -1
- package/dist/commands/batch-command/batch-test-command.js +7 -2
- package/dist/commands/batch-command/batch-test-command.js.map +1 -1
- package/dist/commands/deploy-command/deploy-init.js +1 -1
- package/dist/commands/deploy-command/deploy-init.js.map +1 -1
- package/dist/commands/deploy-command/index.d.ts +3 -0
- package/dist/commands/deploy-command/index.d.ts.map +1 -1
- package/dist/commands/deploy-command/index.js +301 -60
- package/dist/commands/deploy-command/index.js.map +1 -1
- package/dist/commands/deploy-command/select-target.js +1 -1
- package/dist/commands/deploy-command/select-target.js.map +1 -1
- package/dist/commands/deploy-command/version-command.d.ts.map +1 -1
- package/dist/commands/deploy-command/version-command.js +138 -12
- package/dist/commands/deploy-command/version-command.js.map +1 -1
- package/dist/commands/test-command/test-command.d.ts.map +1 -1
- package/dist/commands/test-command/test-command.js +17 -7
- package/dist/commands/test-command/test-command.js.map +1 -1
- package/dist/nevermore.js +17 -0
- package/dist/nevermore.js.map +1 -1
- package/dist/utils/batch/changed-packages-utils.d.ts +1 -1
- package/dist/utils/batch/changed-packages-utils.d.ts.map +1 -1
- package/dist/utils/batch/changed-packages-utils.js +1 -1
- package/dist/utils/batch/changed-packages-utils.js.map +1 -1
- package/dist/utils/build/base-place-resolver-factory.d.ts +25 -0
- package/dist/utils/build/base-place-resolver-factory.d.ts.map +1 -0
- package/dist/utils/build/base-place-resolver-factory.js +40 -0
- package/dist/utils/build/base-place-resolver-factory.js.map +1 -0
- package/dist/utils/build/build.d.ts +13 -2
- package/dist/utils/build/build.d.ts.map +1 -1
- package/dist/utils/build/build.js.map +1 -1
- package/dist/utils/build/upload.d.ts +1 -1
- package/dist/utils/build/upload.d.ts.map +1 -1
- package/dist/utils/deploy/deploy-metadata.d.ts +1 -1
- package/dist/utils/deploy/deploy-metadata.d.ts.map +1 -1
- package/dist/utils/job-context/base-job-context.d.ts +3 -1
- package/dist/utils/job-context/base-job-context.d.ts.map +1 -1
- package/dist/utils/job-context/base-job-context.js +45 -6
- package/dist/utils/job-context/base-job-context.js.map +1 -1
- package/dist/utils/job-context/batch-script-job-context.d.ts +6 -0
- package/dist/utils/job-context/batch-script-job-context.d.ts.map +1 -1
- package/dist/utils/job-context/batch-script-job-context.js +13 -0
- package/dist/utils/job-context/batch-script-job-context.js.map +1 -1
- package/dist/utils/job-context/cloud-job-context.d.ts +2 -1
- package/dist/utils/job-context/cloud-job-context.d.ts.map +1 -1
- package/dist/utils/job-context/cloud-job-context.js +2 -2
- package/dist/utils/job-context/cloud-job-context.js.map +1 -1
- package/dist/utils/job-context/local-job-context.d.ts +2 -1
- package/dist/utils/job-context/local-job-context.d.ts.map +1 -1
- package/dist/utils/job-context/local-job-context.js +2 -2
- package/dist/utils/job-context/local-job-context.js.map +1 -1
- package/dist/utils/open-cloud/open-cloud-client.d.ts +20 -2
- package/dist/utils/open-cloud/open-cloud-client.d.ts.map +1 -1
- package/dist/utils/open-cloud/open-cloud-client.js +74 -20
- package/dist/utils/open-cloud/open-cloud-client.js.map +1 -1
- package/dist/utils/open-cloud/open-cloud-client.test.js +89 -12
- package/dist/utils/open-cloud/open-cloud-client.test.js.map +1 -1
- package/dist/utils/testing/runner/combined-project-generator.d.ts +1 -1
- package/dist/utils/testing/runner/combined-project-generator.d.ts.map +1 -1
- package/dist/utils/testing/runner/test-runner.d.ts +1 -1
- package/dist/utils/testing/runner/test-runner.d.ts.map +1 -1
- package/dist/utils/watch/github-context.d.ts +50 -0
- package/dist/utils/watch/github-context.d.ts.map +1 -0
- package/dist/utils/watch/github-context.js +125 -0
- package/dist/utils/watch/github-context.js.map +1 -0
- package/dist/utils/watch/github-context.test.d.ts +2 -0
- package/dist/utils/watch/github-context.test.d.ts.map +1 -0
- package/dist/utils/watch/github-context.test.js +112 -0
- package/dist/utils/watch/github-context.test.js.map +1 -0
- package/dist/utils/watch/http-watch-registry.d.ts +40 -0
- package/dist/utils/watch/http-watch-registry.d.ts.map +1 -0
- package/dist/utils/watch/http-watch-registry.js +262 -0
- package/dist/utils/watch/http-watch-registry.js.map +1 -0
- package/dist/utils/watch/http-watch-registry.test.d.ts +2 -0
- package/dist/utils/watch/http-watch-registry.test.d.ts.map +1 -0
- package/dist/utils/watch/http-watch-registry.test.js +211 -0
- package/dist/utils/watch/http-watch-registry.test.js.map +1 -0
- package/dist/utils/watch/local-watch-loop.d.ts +50 -0
- package/dist/utils/watch/local-watch-loop.d.ts.map +1 -0
- package/dist/utils/watch/local-watch-loop.js +103 -0
- package/dist/utils/watch/local-watch-loop.js.map +1 -0
- package/dist/utils/watch/local-watch-loop.test.d.ts +2 -0
- package/dist/utils/watch/local-watch-loop.test.d.ts.map +1 -0
- package/dist/utils/watch/local-watch-loop.test.js +170 -0
- package/dist/utils/watch/local-watch-loop.test.js.map +1 -0
- package/dist/utils/watch/register-notify-watches.d.ts +41 -0
- package/dist/utils/watch/register-notify-watches.d.ts.map +1 -0
- package/dist/utils/watch/register-notify-watches.js +159 -0
- package/dist/utils/watch/register-notify-watches.js.map +1 -0
- package/dist/utils/watch/register-notify-watches.test.d.ts +2 -0
- package/dist/utils/watch/register-notify-watches.test.d.ts.map +1 -0
- package/dist/utils/watch/register-notify-watches.test.js +225 -0
- package/dist/utils/watch/register-notify-watches.test.js.map +1 -0
- package/dist/utils/watch/register-watches.d.ts +68 -0
- package/dist/utils/watch/register-watches.d.ts.map +1 -0
- package/dist/utils/watch/register-watches.js +221 -0
- package/dist/utils/watch/register-watches.js.map +1 -0
- package/dist/utils/watch/register-watches.test.d.ts +2 -0
- package/dist/utils/watch/register-watches.test.d.ts.map +1 -0
- package/dist/utils/watch/register-watches.test.js +576 -0
- package/dist/utils/watch/register-watches.test.js.map +1 -0
- package/dist/utils/watch/stream-watch-loop.d.ts +54 -0
- package/dist/utils/watch/stream-watch-loop.d.ts.map +1 -0
- package/dist/utils/watch/stream-watch-loop.js +282 -0
- package/dist/utils/watch/stream-watch-loop.js.map +1 -0
- package/dist/utils/watch/stream-watch-loop.test.d.ts +2 -0
- package/dist/utils/watch/stream-watch-loop.test.d.ts.map +1 -0
- package/dist/utils/watch/stream-watch-loop.test.js +392 -0
- package/dist/utils/watch/stream-watch-loop.test.js.map +1 -0
- package/dist/utils/watch/websocket-watch-stream.d.ts +25 -0
- package/dist/utils/watch/websocket-watch-stream.d.ts.map +1 -0
- package/dist/utils/watch/websocket-watch-stream.js +306 -0
- package/dist/utils/watch/websocket-watch-stream.js.map +1 -0
- package/dist/utils/watch/websocket-watch-stream.test.d.ts +2 -0
- package/dist/utils/watch/websocket-watch-stream.test.d.ts.map +1 -0
- package/dist/utils/watch/websocket-watch-stream.test.js +475 -0
- package/dist/utils/watch/websocket-watch-stream.test.js.map +1 -0
- package/package.json +7 -4
- package/src/args/global-args.ts +13 -0
- package/src/commands/batch-command/batch-deploy-command.ts +105 -1
- package/src/commands/batch-command/batch-test-command.ts +8 -2
- package/src/commands/deploy-command/deploy-init.ts +1 -1
- package/src/commands/deploy-command/index.ts +331 -32
- package/src/commands/deploy-command/select-target.ts +1 -1
- package/src/commands/deploy-command/version-command.ts +215 -21
- package/src/commands/test-command/test-command.ts +24 -18
- package/src/nevermore.ts +19 -0
- package/src/utils/batch/changed-packages-utils.ts +1 -1
- package/src/utils/build/base-place-resolver-factory.ts +49 -0
- package/src/utils/build/build.ts +13 -2
- package/src/utils/build/upload.ts +1 -1
- package/src/utils/deploy/deploy-metadata.ts +1 -1
- package/src/utils/job-context/base-job-context.ts +68 -6
- package/src/utils/job-context/batch-script-job-context.ts +18 -0
- package/src/utils/job-context/cloud-job-context.ts +7 -2
- package/src/utils/job-context/local-job-context.ts +7 -2
- package/src/utils/open-cloud/open-cloud-client.test.ts +133 -14
- package/src/utils/open-cloud/open-cloud-client.ts +127 -34
- package/src/utils/testing/runner/combined-project-generator.ts +1 -1
- package/src/utils/testing/runner/test-runner.ts +1 -1
- package/src/utils/watch/github-context.test.ts +154 -0
- package/src/utils/watch/github-context.ts +184 -0
- package/src/utils/watch/http-watch-registry.test.ts +330 -0
- package/src/utils/watch/http-watch-registry.ts +341 -0
- package/src/utils/watch/local-watch-loop.test.ts +197 -0
- package/src/utils/watch/local-watch-loop.ts +190 -0
- package/src/utils/watch/register-notify-watches.test.ts +282 -0
- package/src/utils/watch/register-notify-watches.ts +226 -0
- package/src/utils/watch/register-watches.test.ts +696 -0
- package/src/utils/watch/register-watches.ts +369 -0
- package/src/utils/watch/stream-watch-loop.test.ts +625 -0
- package/src/utils/watch/stream-watch-loop.ts +411 -0
- package/src/utils/watch/websocket-watch-stream.test.ts +581 -0
- package/src/utils/watch/websocket-watch-stream.ts +403 -0
- package/tsconfig.json +19 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/build/deploy-config.d.ts +0 -71
- package/dist/utils/build/deploy-config.d.ts.map +0 -1
- package/dist/utils/build/deploy-config.js +0 -164
- package/dist/utils/build/deploy-config.js.map +0 -1
- package/dist/utils/build/deploy-config.test.d.ts +0 -2
- package/dist/utils/build/deploy-config.test.d.ts.map +0 -1
- package/dist/utils/build/deploy-config.test.js +0 -126
- package/dist/utils/build/deploy-config.test.js.map +0 -1
- package/src/utils/build/deploy-config.test.ts +0 -149
- package/src/utils/build/deploy-config.ts +0 -259
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { OutputHelper } from '@quenty/cli-output-helpers';
|
|
2
|
+
import {
|
|
3
|
+
type BasePlaceVersionKeyword,
|
|
4
|
+
type PlaceVersionSource,
|
|
5
|
+
} from '@quenty/nevermore-deploy';
|
|
6
|
+
|
|
7
|
+
/** How often to ask Open Cloud whether a base place moved. */
|
|
8
|
+
const DEFAULT_POLL_INTERVAL_MS = 15_000;
|
|
9
|
+
|
|
10
|
+
/** One base place being watched, and what to rebuild when it moves. */
|
|
11
|
+
export interface LocalWatchEntry {
|
|
12
|
+
/** Human label for output, e.g. `integration.places.hub`. */
|
|
13
|
+
label: string;
|
|
14
|
+
universeId: number;
|
|
15
|
+
placeId: number;
|
|
16
|
+
versionType: BasePlaceVersionKeyword;
|
|
17
|
+
/**
|
|
18
|
+
* Version this entry was last built from. Undefined means "adopt whatever
|
|
19
|
+
* the first poll sees", which avoids a rebuild on startup for a place that
|
|
20
|
+
* has never been locked.
|
|
21
|
+
*/
|
|
22
|
+
baseline?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface LocalWatchLoopOptions {
|
|
26
|
+
entries: LocalWatchEntry[];
|
|
27
|
+
source: PlaceVersionSource;
|
|
28
|
+
/** Stop watching after this long. */
|
|
29
|
+
durationMs: number;
|
|
30
|
+
pollIntervalMs?: number;
|
|
31
|
+
/** Rebuild and redeploy. Errors are reported and the loop continues. */
|
|
32
|
+
redeployAsync: (entry: LocalWatchEntry, version: number) => Promise<void>;
|
|
33
|
+
/** Lets a caller stop the loop; SIGINT is wired to one by default. */
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
/** Injected in tests. */
|
|
36
|
+
now?: () => number;
|
|
37
|
+
sleepAsync?: (ms: number, signal: AbortSignal) => Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface LocalWatchLoopResult {
|
|
41
|
+
/** Rebuilds that completed. */
|
|
42
|
+
redeploys: number;
|
|
43
|
+
/** Rebuilds that were attempted and threw. */
|
|
44
|
+
failures: number;
|
|
45
|
+
/** True when the duration ran out rather than the user interrupting. */
|
|
46
|
+
expired: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Poll base places and redeploy in-process when one moves.
|
|
51
|
+
*
|
|
52
|
+
* This is what `--watch` does outside CI. Registering with the watch service
|
|
53
|
+
* would be pointless on a laptop: the service's only action is dispatching a
|
|
54
|
+
* GitHub workflow, which would rebuild on a runner rather than here — so a
|
|
55
|
+
* local run keeps the loop in the terminal, where the developer can see it.
|
|
56
|
+
*
|
|
57
|
+
* Poll failures never end the loop. A watch is meant to be left running for
|
|
58
|
+
* hours, and a dropped connection is not a reason to stop watching.
|
|
59
|
+
*/
|
|
60
|
+
export async function runLocalWatchLoopAsync(
|
|
61
|
+
options: LocalWatchLoopOptions
|
|
62
|
+
): Promise<LocalWatchLoopResult> {
|
|
63
|
+
const {
|
|
64
|
+
entries,
|
|
65
|
+
source,
|
|
66
|
+
durationMs,
|
|
67
|
+
redeployAsync,
|
|
68
|
+
pollIntervalMs = DEFAULT_POLL_INTERVAL_MS,
|
|
69
|
+
now = () => Date.now(),
|
|
70
|
+
sleepAsync = _sleepAsync,
|
|
71
|
+
} = options;
|
|
72
|
+
|
|
73
|
+
const controller = new AbortController();
|
|
74
|
+
const signal = options.signal ?? controller.signal;
|
|
75
|
+
const onSigint = () => controller.abort();
|
|
76
|
+
if (!options.signal) {
|
|
77
|
+
process.on('SIGINT', onSigint);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const seen = new Map<string, number | undefined>(
|
|
81
|
+
entries.map((e) => [_key(e), e.baseline])
|
|
82
|
+
);
|
|
83
|
+
const deadline = now() + durationMs;
|
|
84
|
+
let redeploys = 0;
|
|
85
|
+
let failures = 0;
|
|
86
|
+
|
|
87
|
+
OutputHelper.info(
|
|
88
|
+
`Watching ${entries.length} base place${
|
|
89
|
+
entries.length === 1 ? '' : 's'
|
|
90
|
+
} locally. Ctrl-C to stop.`
|
|
91
|
+
);
|
|
92
|
+
for (const entry of entries) {
|
|
93
|
+
OutputHelper.info(
|
|
94
|
+
` ${entry.label} — base place ${entry.placeId} (${entry.versionType}${
|
|
95
|
+
entry.baseline == null ? '' : ` v${entry.baseline}`
|
|
96
|
+
})`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
while (!signal.aborted && now() < deadline) {
|
|
102
|
+
for (const entry of entries) {
|
|
103
|
+
if (signal.aborted) {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let latest: number;
|
|
108
|
+
try {
|
|
109
|
+
latest = await source.resolveLatestPlaceVersionAsync(
|
|
110
|
+
entry.universeId,
|
|
111
|
+
entry.placeId,
|
|
112
|
+
entry.versionType
|
|
113
|
+
);
|
|
114
|
+
} catch (err) {
|
|
115
|
+
OutputHelper.warn(
|
|
116
|
+
`Could not check ${entry.label}: ` +
|
|
117
|
+
(err instanceof Error ? err.message : String(err))
|
|
118
|
+
);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const key = _key(entry);
|
|
123
|
+
const previous = seen.get(key);
|
|
124
|
+
if (previous === undefined) {
|
|
125
|
+
// First sighting of a place with no recorded baseline: adopt it
|
|
126
|
+
// rather than treating "unknown -> something" as a change.
|
|
127
|
+
seen.set(key, latest);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (latest === previous) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
OutputHelper.info(
|
|
135
|
+
`${entry.label}: base place moved v${previous} → v${latest}, rebuilding...`
|
|
136
|
+
);
|
|
137
|
+
try {
|
|
138
|
+
await redeployAsync(entry, latest);
|
|
139
|
+
redeploys++;
|
|
140
|
+
// Recorded only on success, so a failed rebuild is retried on the
|
|
141
|
+
// next poll instead of being silently skipped forever.
|
|
142
|
+
seen.set(key, latest);
|
|
143
|
+
OutputHelper.info(`${entry.label}: rebuilt from v${latest}.`);
|
|
144
|
+
} catch (err) {
|
|
145
|
+
failures++;
|
|
146
|
+
OutputHelper.error(
|
|
147
|
+
`${entry.label}: rebuild failed — ` +
|
|
148
|
+
(err instanceof Error ? err.message : String(err))
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (signal.aborted || now() >= deadline) {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
await sleepAsync(pollIntervalMs, signal);
|
|
157
|
+
}
|
|
158
|
+
} finally {
|
|
159
|
+
if (!options.signal) {
|
|
160
|
+
process.off('SIGINT', onSigint);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const expired = !signal.aborted;
|
|
165
|
+
OutputHelper.info(
|
|
166
|
+
expired
|
|
167
|
+
? `Watch lease elapsed. ${redeploys} rebuild${
|
|
168
|
+
redeploys === 1 ? '' : 's'
|
|
169
|
+
}.`
|
|
170
|
+
: `Stopped watching. ${redeploys} rebuild${redeploys === 1 ? '' : 's'}.`
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
return { redeploys, failures, expired };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function _key(entry: LocalWatchEntry): string {
|
|
177
|
+
return `${entry.placeId}:${entry.versionType}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function _sleepAsync(ms: number, signal: AbortSignal): Promise<void> {
|
|
181
|
+
return new Promise((resolve) => {
|
|
182
|
+
const timer = setTimeout(finish, ms);
|
|
183
|
+
function finish() {
|
|
184
|
+
clearTimeout(timer);
|
|
185
|
+
signal.removeEventListener('abort', finish);
|
|
186
|
+
resolve();
|
|
187
|
+
}
|
|
188
|
+
signal.addEventListener('abort', finish, { once: true });
|
|
189
|
+
});
|
|
190
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
parseWatchOption,
|
|
4
|
+
type WatchNotifyAction,
|
|
5
|
+
type WatchRegistrationRequest,
|
|
6
|
+
type WatchRegistry,
|
|
7
|
+
} from '@quenty/nevermore-deploy';
|
|
8
|
+
import { type LocalWatchEntry } from './local-watch-loop.js';
|
|
9
|
+
import {
|
|
10
|
+
describeNotifyWatchFallback,
|
|
11
|
+
tryRegisterNotifyWatchesAsync,
|
|
12
|
+
} from './register-notify-watches.js';
|
|
13
|
+
|
|
14
|
+
const REGISTER_BASE = 'https://watch.example.com/v1/register/';
|
|
15
|
+
const watchOption = () => parseWatchOption(`${REGISTER_BASE}30m`);
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
vi.stubEnv('GITHUB_REPOSITORY', 'Quenty/egg-hunt-2026');
|
|
19
|
+
vi.stubEnv('GITHUB_REF_NAME', 'release');
|
|
20
|
+
vi.stubEnv('NEVERMORE_WATCH_TOKEN', 'token-value');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
vi.unstubAllEnvs();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function makeEntry(overrides: Partial<LocalWatchEntry> = {}): LocalWatchEntry {
|
|
28
|
+
return {
|
|
29
|
+
label: 'integration.places.hub',
|
|
30
|
+
universeId: 10,
|
|
31
|
+
placeId: 20,
|
|
32
|
+
versionType: 'published',
|
|
33
|
+
...overrides,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function makeRecordingRegistry(monitorId?: string) {
|
|
38
|
+
const requests: WatchRegistrationRequest[] = [];
|
|
39
|
+
const create = (): WatchRegistry => ({
|
|
40
|
+
registerAsync: async (request) => {
|
|
41
|
+
requests.push(request);
|
|
42
|
+
return { monitorId: monitorId ?? 'mon_1', changed: true };
|
|
43
|
+
},
|
|
44
|
+
triggerAsync: async () => ({ results: [] }),
|
|
45
|
+
});
|
|
46
|
+
return { requests, create };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function notifyAction(
|
|
50
|
+
request: WatchRegistrationRequest,
|
|
51
|
+
index = 0
|
|
52
|
+
): WatchNotifyAction {
|
|
53
|
+
const action = request.watches[index]!.action;
|
|
54
|
+
expect(action.type).toBe('notify');
|
|
55
|
+
return action as WatchNotifyAction;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('tryRegisterNotifyWatchesAsync', () => {
|
|
59
|
+
it('registers notify actions carrying the selector', async () => {
|
|
60
|
+
const registry = makeRecordingRegistry();
|
|
61
|
+
|
|
62
|
+
const result = await tryRegisterNotifyWatchesAsync({
|
|
63
|
+
option: watchOption(),
|
|
64
|
+
monitorName: 'egg-hunt/integration',
|
|
65
|
+
entries: [makeEntry({ baseline: 158 })],
|
|
66
|
+
createRegistry: registry.create,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(result.success).toBe(true);
|
|
70
|
+
const request = registry.requests[0]!;
|
|
71
|
+
// No baseline: the service compares its own token (an asset-delivery
|
|
72
|
+
// content hash) by string equality, so the lock's Open Cloud version number
|
|
73
|
+
// would read as drift on the first poll. The `ready` reconcile covers it.
|
|
74
|
+
expect(request.watches[0]!.baselineVersion).toBeUndefined();
|
|
75
|
+
expect(request.watches[0]!.baselineVersionKind).toBeUndefined();
|
|
76
|
+
expect(request.watches[0]!.source).toEqual({
|
|
77
|
+
type: 'roblox-place',
|
|
78
|
+
universeId: 10,
|
|
79
|
+
placeId: 20,
|
|
80
|
+
versionType: 'published',
|
|
81
|
+
});
|
|
82
|
+
expect(notifyAction(request).payload).toEqual({
|
|
83
|
+
target: 'integration.places.hub',
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Re-registering replaces a monitor's whole watch list, so a local watch that
|
|
88
|
+
// shared CI's monitor name would silently disarm the workflow dispatch.
|
|
89
|
+
it('registers under a monitor name distinct from the dispatching one', async () => {
|
|
90
|
+
const registry = makeRecordingRegistry();
|
|
91
|
+
|
|
92
|
+
await tryRegisterNotifyWatchesAsync({
|
|
93
|
+
option: watchOption(),
|
|
94
|
+
monitorName: 'egg-hunt/integration',
|
|
95
|
+
entries: [makeEntry()],
|
|
96
|
+
createRegistry: registry.create,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
expect(registry.requests[0]!.monitorName).toBe(
|
|
100
|
+
'egg-hunt/integration/local'
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('hands back stream entries keyed by the registered watch name', async () => {
|
|
105
|
+
const registry = makeRecordingRegistry();
|
|
106
|
+
|
|
107
|
+
const result = await tryRegisterNotifyWatchesAsync({
|
|
108
|
+
option: watchOption(),
|
|
109
|
+
monitorName: 'egg-hunt/integration',
|
|
110
|
+
entries: [makeEntry()],
|
|
111
|
+
createRegistry: registry.create,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
expect(result.success && result.entries[0]!.watchName).toBe(
|
|
115
|
+
registry.requests[0]!.watches[0]!.name
|
|
116
|
+
);
|
|
117
|
+
expect(result.success && result.monitorId).toBe('mon_1');
|
|
118
|
+
expect(result.success && result.credential).toBe('token-value');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Places are only optionally named, so a multi-place target with unnamed
|
|
122
|
+
// places produces the same selector twice. The service resolves a duplicate
|
|
123
|
+
// name by dropping a watch rather than failing.
|
|
124
|
+
it('separates watches that would share a name', async () => {
|
|
125
|
+
const registry = makeRecordingRegistry();
|
|
126
|
+
|
|
127
|
+
await tryRegisterNotifyWatchesAsync({
|
|
128
|
+
option: watchOption(),
|
|
129
|
+
monitorName: 'egg-hunt/integration',
|
|
130
|
+
entries: [makeEntry({ placeId: 20 }), makeEntry({ placeId: 21 })],
|
|
131
|
+
createRegistry: registry.create,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const names = registry.requests[0]!.watches.map((w) => w.name);
|
|
135
|
+
expect(new Set(names).size).toBe(2);
|
|
136
|
+
expect(names).toEqual([
|
|
137
|
+
'integration.places.hub/20',
|
|
138
|
+
'integration.places.hub/21',
|
|
139
|
+
]);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('shares the Open Cloud key only when asked', async () => {
|
|
143
|
+
const registry = makeRecordingRegistry();
|
|
144
|
+
|
|
145
|
+
await tryRegisterNotifyWatchesAsync({
|
|
146
|
+
option: watchOption(),
|
|
147
|
+
monitorName: 'egg-hunt/integration',
|
|
148
|
+
entries: [makeEntry()],
|
|
149
|
+
createRegistry: registry.create,
|
|
150
|
+
});
|
|
151
|
+
expect(registry.requests[0]!.robloxApiKey).toBeUndefined();
|
|
152
|
+
|
|
153
|
+
await tryRegisterNotifyWatchesAsync({
|
|
154
|
+
option: watchOption(),
|
|
155
|
+
monitorName: 'egg-hunt/integration',
|
|
156
|
+
entries: [makeEntry()],
|
|
157
|
+
robloxApiKey: 'secret',
|
|
158
|
+
createRegistry: registry.create,
|
|
159
|
+
});
|
|
160
|
+
expect(registry.requests[1]!.robloxApiKey).toBe('secret');
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('tryRegisterNotifyWatchesAsync falling back', () => {
|
|
165
|
+
// Every failure here has a working answer already — poll Open Cloud from this
|
|
166
|
+
// machine — so none of them may throw.
|
|
167
|
+
it('watches a "saved" place when a key is shared', async () => {
|
|
168
|
+
const registry = makeRecordingRegistry();
|
|
169
|
+
|
|
170
|
+
const result = await tryRegisterNotifyWatchesAsync({
|
|
171
|
+
option: watchOption(),
|
|
172
|
+
monitorName: 'egg-hunt/integration',
|
|
173
|
+
entries: [makeEntry({ versionType: 'saved', baseline: 158 })],
|
|
174
|
+
robloxApiKey: 'secret',
|
|
175
|
+
createRegistry: registry.create,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
expect(result.success).toBe(true);
|
|
179
|
+
const watch = registry.requests[0]!.watches[0]!;
|
|
180
|
+
expect(watch.source.versionType).toBe('saved');
|
|
181
|
+
// Same vocabulary once a key is in play, so the lock value is sendable.
|
|
182
|
+
expect(watch.baselineVersion).toBe('158');
|
|
183
|
+
expect(watch.baselineVersionKind).toBe('roblox-place-version');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('declines a "saved" base place the service cannot poll', async () => {
|
|
187
|
+
const registry = makeRecordingRegistry();
|
|
188
|
+
|
|
189
|
+
const result = await tryRegisterNotifyWatchesAsync({
|
|
190
|
+
option: watchOption(),
|
|
191
|
+
monitorName: 'egg-hunt/integration',
|
|
192
|
+
entries: [makeEntry({ versionType: 'saved' })],
|
|
193
|
+
createRegistry: registry.create,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
expect(result).toMatchObject({
|
|
197
|
+
success: false,
|
|
198
|
+
reason: 'unwatchable_version_type',
|
|
199
|
+
});
|
|
200
|
+
expect(registry.requests).toEqual([]);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// Splitting the run — streaming the published places and polling the saved
|
|
204
|
+
// one — would leave two watch loops disagreeing about what is current.
|
|
205
|
+
it('declines the whole run when only some places are unwatchable', async () => {
|
|
206
|
+
const result = await tryRegisterNotifyWatchesAsync({
|
|
207
|
+
option: watchOption(),
|
|
208
|
+
monitorName: 'egg-hunt/integration',
|
|
209
|
+
entries: [
|
|
210
|
+
makeEntry({ label: 'integration.places.hub' }),
|
|
211
|
+
makeEntry({ label: 'integration.places.lobby', versionType: 'saved' }),
|
|
212
|
+
],
|
|
213
|
+
createRegistry: makeRecordingRegistry().create,
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
expect(result).toMatchObject({ success: false });
|
|
217
|
+
expect(
|
|
218
|
+
result.success === false && describeNotifyWatchFallback(result)
|
|
219
|
+
).toMatch(/integration\.places\.lobby/);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('declines without a token, since registration has no identity', async () => {
|
|
223
|
+
vi.stubEnv('NEVERMORE_WATCH_TOKEN', '');
|
|
224
|
+
vi.stubEnv('GITHUB_TOKEN', '');
|
|
225
|
+
|
|
226
|
+
const result = await tryRegisterNotifyWatchesAsync({
|
|
227
|
+
option: watchOption(),
|
|
228
|
+
monitorName: 'egg-hunt/integration',
|
|
229
|
+
entries: [makeEntry()],
|
|
230
|
+
createRegistry: makeRecordingRegistry().create,
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
expect(result).toMatchObject({ success: false, reason: 'no_token' });
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('declines when the service refuses the registration', async () => {
|
|
237
|
+
const result = await tryRegisterNotifyWatchesAsync({
|
|
238
|
+
option: watchOption(),
|
|
239
|
+
monitorName: 'egg-hunt/integration',
|
|
240
|
+
entries: [makeEntry()],
|
|
241
|
+
createRegistry: () => ({
|
|
242
|
+
registerAsync: async () => {
|
|
243
|
+
throw new Error('503 Service Unavailable');
|
|
244
|
+
},
|
|
245
|
+
triggerAsync: async () => ({ results: [] }),
|
|
246
|
+
}),
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
expect(result).toMatchObject({
|
|
250
|
+
success: false,
|
|
251
|
+
reason: 'register_failed',
|
|
252
|
+
});
|
|
253
|
+
expect(
|
|
254
|
+
result.success === false && describeNotifyWatchFallback(result)
|
|
255
|
+
).toMatch(/503 Service Unavailable/);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('declines when the service returns no monitor to stream', async () => {
|
|
259
|
+
const result = await tryRegisterNotifyWatchesAsync({
|
|
260
|
+
option: watchOption(),
|
|
261
|
+
monitorName: 'egg-hunt/integration',
|
|
262
|
+
entries: [makeEntry()],
|
|
263
|
+
createRegistry: () => ({
|
|
264
|
+
registerAsync: async () => ({ changed: true }),
|
|
265
|
+
triggerAsync: async () => ({ results: [] }),
|
|
266
|
+
}),
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
expect(result).toMatchObject({ success: false, reason: 'no_monitor_id' });
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('declines when there is nothing to watch', async () => {
|
|
273
|
+
const result = await tryRegisterNotifyWatchesAsync({
|
|
274
|
+
option: watchOption(),
|
|
275
|
+
monitorName: 'egg-hunt/integration',
|
|
276
|
+
entries: [],
|
|
277
|
+
createRegistry: makeRecordingRegistry().create,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
expect(result).toMatchObject({ success: false, reason: 'no_entries' });
|
|
281
|
+
});
|
|
282
|
+
});
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { OutputHelper } from '@quenty/cli-output-helpers';
|
|
2
|
+
import {
|
|
3
|
+
WATCH_BASELINE_KIND,
|
|
4
|
+
WATCH_INPUT_NAME,
|
|
5
|
+
sanitizeWatchName,
|
|
6
|
+
type WatchEntry,
|
|
7
|
+
type WatchOption,
|
|
8
|
+
type WatchRegistry,
|
|
9
|
+
} from '@quenty/nevermore-deploy';
|
|
10
|
+
import { HttpWatchRegistry } from './http-watch-registry.js';
|
|
11
|
+
import { tryResolveGithubDispatchContext } from './github-context.js';
|
|
12
|
+
import { type LocalWatchEntry } from './local-watch-loop.js';
|
|
13
|
+
import { type StreamWatchEntry } from './stream-watch-loop.js';
|
|
14
|
+
|
|
15
|
+
export interface RegisterNotifyWatchesOptions {
|
|
16
|
+
option: WatchOption;
|
|
17
|
+
/** Lease key within the repository, as for a dispatching monitor. */
|
|
18
|
+
monitorName: string;
|
|
19
|
+
entries: LocalWatchEntry[];
|
|
20
|
+
/** Open Cloud key to share, so the service can poll a private base place. */
|
|
21
|
+
robloxApiKey?: string;
|
|
22
|
+
/** Let the GitHub CLI supply the token when no env var does. */
|
|
23
|
+
useGhAuth?: boolean;
|
|
24
|
+
/** Injected in tests; defaults to the HTTP registry. */
|
|
25
|
+
createRegistry?: (registerUrl: string) => WatchRegistry;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type RegisterNotifyWatchesResult =
|
|
29
|
+
| {
|
|
30
|
+
success: true;
|
|
31
|
+
monitorId: string;
|
|
32
|
+
/** Bearer token for the stream; the same one registration used. */
|
|
33
|
+
credential: string;
|
|
34
|
+
entries: StreamWatchEntry[];
|
|
35
|
+
}
|
|
36
|
+
| {
|
|
37
|
+
success: false;
|
|
38
|
+
reason:
|
|
39
|
+
| 'no_github_context'
|
|
40
|
+
| 'no_token'
|
|
41
|
+
| 'unwatchable_version_type'
|
|
42
|
+
| 'no_entries'
|
|
43
|
+
| 'register_failed'
|
|
44
|
+
| 'no_monitor_id';
|
|
45
|
+
detail?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Register a monitor that notifies this process instead of dispatching CI.
|
|
50
|
+
*
|
|
51
|
+
* Best-effort on purpose. Every way this can fail — no GitHub identity to
|
|
52
|
+
* register under, no token, a `"saved"` base place the service cannot poll, a
|
|
53
|
+
* service that is unreachable — has a working answer already: poll Open Cloud
|
|
54
|
+
* from here. So a failure downgrades the watch rather than the run, and the
|
|
55
|
+
* caller falls back.
|
|
56
|
+
*/
|
|
57
|
+
export async function tryRegisterNotifyWatchesAsync(
|
|
58
|
+
options: RegisterNotifyWatchesOptions
|
|
59
|
+
): Promise<RegisterNotifyWatchesResult> {
|
|
60
|
+
const { option, entries } = options;
|
|
61
|
+
|
|
62
|
+
if (entries.length === 0) {
|
|
63
|
+
return { success: false, reason: 'no_entries' };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Without a shared key the service reads asset delivery, which reports
|
|
67
|
+
// published content only — it refuses `"saved"` at registration, and one
|
|
68
|
+
// refusal fails the whole request. Rather than watch some places one way and
|
|
69
|
+
// some the other, the whole run falls back to polling, which handles every
|
|
70
|
+
// version type this machine has credentials for.
|
|
71
|
+
const credentialed = options.robloxApiKey != null;
|
|
72
|
+
const unwatchable = credentialed
|
|
73
|
+
? []
|
|
74
|
+
: entries.filter((e) => e.versionType !== 'published');
|
|
75
|
+
if (unwatchable.length > 0) {
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
reason: 'unwatchable_version_type',
|
|
79
|
+
detail: unwatchable.map((e) => e.label).join(', '),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const contextResult = tryResolveGithubDispatchContext({
|
|
84
|
+
useGhAuth: options.useGhAuth,
|
|
85
|
+
});
|
|
86
|
+
if (!contextResult.success) {
|
|
87
|
+
return { success: false, reason: 'no_github_context' };
|
|
88
|
+
}
|
|
89
|
+
const context = contextResult.context;
|
|
90
|
+
// Registration needs a write-scoped PAT even though a notify never spends it:
|
|
91
|
+
// the repository is the only identity this service has, and it is what a
|
|
92
|
+
// monitor's leases and caps are counted against.
|
|
93
|
+
if (!context.token) {
|
|
94
|
+
return { success: false, reason: 'no_token' };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const streamEntries: StreamWatchEntry[] = entries.map((entry) => ({
|
|
98
|
+
...entry,
|
|
99
|
+
watchName: sanitizeWatchName(entry.label),
|
|
100
|
+
}));
|
|
101
|
+
_disambiguateWatchNames(streamEntries);
|
|
102
|
+
|
|
103
|
+
const watches: WatchEntry[] = streamEntries.map((entry) => ({
|
|
104
|
+
name: entry.watchName,
|
|
105
|
+
source: {
|
|
106
|
+
type: 'roblox-place',
|
|
107
|
+
universeId: entry.universeId,
|
|
108
|
+
placeId: entry.placeId,
|
|
109
|
+
versionType: entry.versionType,
|
|
110
|
+
},
|
|
111
|
+
// Only when a key is shared do the two sides speak the same language; the
|
|
112
|
+
// `ready` reconcile covers this either way, by re-checking every watch
|
|
113
|
+
// against Open Cloud on connect.
|
|
114
|
+
...(credentialed && entry.baseline != null
|
|
115
|
+
? {
|
|
116
|
+
baselineVersion: String(entry.baseline),
|
|
117
|
+
baselineVersionKind: WATCH_BASELINE_KIND,
|
|
118
|
+
}
|
|
119
|
+
: {}),
|
|
120
|
+
action: {
|
|
121
|
+
type: 'notify',
|
|
122
|
+
// Same key a dispatching watch puts the selector under, so the two modes
|
|
123
|
+
// describe a change the same way even though only one crosses into CI.
|
|
124
|
+
payload: { [WATCH_INPUT_NAME]: entry.label },
|
|
125
|
+
},
|
|
126
|
+
}));
|
|
127
|
+
|
|
128
|
+
const registry = (options.createRegistry ?? _defaultRegistry)(
|
|
129
|
+
option.registerUrl
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
let result;
|
|
133
|
+
try {
|
|
134
|
+
result = await registry.registerAsync({
|
|
135
|
+
// Distinct from the dispatching monitor's name. They hold different
|
|
136
|
+
// actions, and re-registering replaces a monitor's whole watch list — so
|
|
137
|
+
// sharing a name would mean a local watch silently disarming CI's.
|
|
138
|
+
monitorName: sanitizeWatchName(`${options.monitorName}/local`),
|
|
139
|
+
repository: context.repository,
|
|
140
|
+
githubToken: context.token,
|
|
141
|
+
robloxApiKey: options.robloxApiKey,
|
|
142
|
+
watches,
|
|
143
|
+
});
|
|
144
|
+
} catch (err) {
|
|
145
|
+
return {
|
|
146
|
+
success: false,
|
|
147
|
+
reason: 'register_failed',
|
|
148
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!result.monitorId) {
|
|
153
|
+
return { success: false, reason: 'no_monitor_id' };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
OutputHelper.verbose(
|
|
157
|
+
`Registered a notify monitor (${result.monitorId}), lease ${option.lease}.`
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
success: true,
|
|
162
|
+
monitorId: result.monitorId,
|
|
163
|
+
credential: context.token,
|
|
164
|
+
entries: streamEntries,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Why the run is polling instead, in words a user can act on. */
|
|
169
|
+
export function describeNotifyWatchFallback(
|
|
170
|
+
result: RegisterNotifyWatchesResult & { success: false }
|
|
171
|
+
): string {
|
|
172
|
+
switch (result.reason) {
|
|
173
|
+
case 'no_entries':
|
|
174
|
+
return 'nothing to watch';
|
|
175
|
+
case 'unwatchable_version_type':
|
|
176
|
+
return (
|
|
177
|
+
`${result.detail} tracks "saved", which the service can only see ` +
|
|
178
|
+
'with a shared Open Cloud key (--watch-share-api-key)'
|
|
179
|
+
);
|
|
180
|
+
case 'no_github_context':
|
|
181
|
+
return 'this checkout has no GitHub repository to register under';
|
|
182
|
+
case 'no_token':
|
|
183
|
+
return (
|
|
184
|
+
'no GitHub token — set NEVERMORE_WATCH_TOKEN, or pass ' +
|
|
185
|
+
'--watch-use-gh-auth to use the one `gh` already holds'
|
|
186
|
+
);
|
|
187
|
+
case 'no_monitor_id':
|
|
188
|
+
return 'the service registered the monitor but returned no id';
|
|
189
|
+
case 'register_failed':
|
|
190
|
+
return `the watch service refused the registration — ${result.detail}`;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function _defaultRegistry(registerUrl: string): WatchRegistry {
|
|
195
|
+
return new HttpWatchRegistry({ registerUrl });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Make every watch name unique within the monitor.
|
|
200
|
+
*
|
|
201
|
+
* Names come from selectors, which are unique per target — except that an
|
|
202
|
+
* unnamed place in a multi-place target has no name to contribute, so two of
|
|
203
|
+
* them produce the same selector. Appending the place id separates them without
|
|
204
|
+
* failing a deploy that already shipped.
|
|
205
|
+
*/
|
|
206
|
+
function _disambiguateWatchNames(entries: StreamWatchEntry[]): void {
|
|
207
|
+
const byName = new Map<string, StreamWatchEntry[]>();
|
|
208
|
+
for (const entry of entries) {
|
|
209
|
+
const group = byName.get(entry.watchName);
|
|
210
|
+
if (group) {
|
|
211
|
+
group.push(entry);
|
|
212
|
+
} else {
|
|
213
|
+
byName.set(entry.watchName, [entry]);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
for (const group of byName.values()) {
|
|
217
|
+
if (group.length === 1) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
for (const entry of group) {
|
|
221
|
+
entry.watchName = sanitizeWatchName(
|
|
222
|
+
`${entry.watchName}/${entry.placeId}`
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|