@codeyam-editor/codeyam-editor 0.1.5 → 0.1.7
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/npm/cli.js +5 -1
- package/npm/cloud.js +2079 -242
- package/npm/codesign-plan.js +68 -0
- package/npm/compose-conflict.js +59 -0
- package/npm/empty-project-dir.js +92 -7
- package/npm/fleet-add-failure.js +361 -0
- package/npm/fleet-asset-version.js +37 -0
- package/npm/fleet-auth-health.js +143 -5
- package/npm/fleet-build-data.js +60 -5
- package/npm/fleet-cleanup.js +243 -9
- package/npm/fleet-destroy-safety.js +230 -13
- package/npm/fleet-early-roster.js +87 -0
- package/npm/fleet-effect-poll.js +110 -0
- package/npm/fleet-env.js +86 -0
- package/npm/fleet-ghcr-secret.js +129 -0
- package/npm/fleet-git-maintenance.js +142 -0
- package/npm/fleet-host-op-limiter.js +68 -0
- package/npm/fleet-iap-token.js +165 -0
- package/npm/fleet-job-badge.js +28 -12
- package/npm/fleet-live-status.js +40 -8
- package/npm/fleet-memory.js +289 -9
- package/npm/fleet-plans.js +98 -4
- package/npm/fleet-pool.js +75 -16
- package/npm/fleet-prewarm.js +87 -11
- package/npm/fleet-probe-transport.js +155 -0
- package/npm/fleet-project-drift.js +58 -0
- package/npm/fleet-public-url.js +234 -0
- package/npm/fleet-queue.js +58 -1
- package/npm/fleet-reachability-debounce.js +69 -0
- package/npm/fleet-reachability.js +80 -0
- package/npm/fleet-reset.js +32 -0
- package/npm/fleet-revision.js +104 -0
- package/npm/fleet-running-plan.js +115 -0
- package/npm/fleet-session-token-cache.js +65 -0
- package/npm/fleet-setup-steps.js +19 -12
- package/npm/fleet-status-refs.js +96 -0
- package/npm/fleet-strand.js +39 -8
- package/npm/fleet-stuck-status.js +13 -7
- package/npm/fleet-vm-access.js +170 -0
- package/npm/fleet-vm-probe-target.js +282 -0
- package/npm/fleet-vm-readiness.js +136 -3
- package/npm/google-ingress.js +15 -0
- package/npm/ingress-invoke.js +478 -0
- package/npm/launch-config.js +302 -10
- package/npm/scenario-check.js +318 -12
- package/npm/scenario-handlers.js +85 -27
- package/npm/scenario-interactivity.js +145 -6
- package/npm/scenario-issues.js +13 -1
- package/npm/scenario-mocks.js +129 -26
- package/npm/scenario-playwright.js +330 -22
- package/npm/script-drift.js +72 -1
- package/npm/utils.js +37 -3
- package/package.json +5 -5
- package/ui/dist/assets/{ContainerInspector-D7VZkkaj.js → ContainerInspector-Cu1tSN-o.js} +1 -1
- package/ui/dist/assets/EditorShell--V2ExYQ6.js +260 -0
- package/ui/dist/assets/EditorShell-DP5UY20G.css +1 -0
- package/ui/dist/assets/{Markdown-BoLHHFXH.js → Markdown-Chgdf3PW.js} +1 -1
- package/ui/dist/assets/ProjectLauncherScreen-Dmm6Z0mv.js +1 -0
- package/ui/dist/assets/{ScenarioDataPanel-DYP7pi_n.css → ScenarioDataPanel-C1LukYI6.css} +1 -1
- package/ui/dist/assets/ScenarioDataPanel-DjprZq2L.js +9 -0
- package/ui/dist/assets/{ScenarioDataPanelFullPage-CBLTGC4-.js → ScenarioDataPanelFullPage-BqMxWVKW.js} +1 -1
- package/ui/dist/assets/ScenarioRenderer-DqLVVMYS.js +21 -0
- package/ui/dist/assets/{StepsSimulator-BFldWyoX.js → StepsSimulator-CymGgfbu.js} +1 -1
- package/ui/dist/assets/index-CjxWhkSy.css +1 -0
- package/ui/dist/assets/{index-QsOiOG9x.js → index-VuyqBbGJ.js} +4 -4
- package/ui/dist/assets/{markdown-v0F0UEt3.js → markdown-C9tbsVHX.js} +1 -1
- package/ui/dist/assets/react-nrLBr15I.js +28 -0
- package/ui/dist/assets/{useEvents-DHkLJZR4.js → useEvents-S3Qk1Y_d.js} +1 -1
- package/ui/dist/assets/useServerIdentity-BdXy8TQv.js +1 -0
- package/ui/dist/index.html +4 -4
- package/ui/dist/open-source/codeyam-counter.png +0 -0
- package/ui/dist/open-source/el-carot.png +0 -0
- package/ui/dist/open-source/tabcommand.png +0 -0
- package/ui/dist/assets/EditorShell-DHhIaotd.css +0 -1
- package/ui/dist/assets/EditorShell-r-796N_W.js +0 -191
- package/ui/dist/assets/ProjectLauncherScreen-Ck-XWkQN.js +0 -1
- package/ui/dist/assets/ScenarioDataPanel-B9iDSUpA.js +0 -5
- package/ui/dist/assets/ScenarioRenderer-BhLfT-nX.js +0 -21
- package/ui/dist/assets/index-CIXZkwfB.css +0 -1
- package/ui/dist/assets/react-CSS0HapR.js +0 -28
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Where the fleet dashboard sends a per-VM editor-API probe, and how to read
|
|
3
|
+
// the answer.
|
|
4
|
+
//
|
|
5
|
+
// The dashboard gets ALL per-VM live data — reachability, feature, step,
|
|
6
|
+
// selectedPlan, credential health, preview — by probing each VM's editor API.
|
|
7
|
+
// On a laptop that probe goes to `127.0.0.1:PORT_BASE+N`, which is fed by an SSH
|
|
8
|
+
// `-L` forward the vm-watchdog creates. On the GCE operator host those forwards
|
|
9
|
+
// cannot exist: the watchdog runs as root, the fleet VMs use metadata SSH keys
|
|
10
|
+
// (OS Login is OFF) and refuse root login, so `gcloud compute ssh` fails
|
|
11
|
+
// `Permission denied (publickey)`. No forwards ⇒ dead local ports ⇒ every card
|
|
12
|
+
// reads "unreachable" with no progress.
|
|
13
|
+
//
|
|
14
|
+
// On GCE we therefore probe each VM through the LB hostname it is already wired
|
|
15
|
+
// to (`https://vm-<N>.editor.<domain>`), authenticated with an IAP identity
|
|
16
|
+
// token minted by the operator service account. Same paths, same downstream
|
|
17
|
+
// parsing — only the transport changes.
|
|
18
|
+
//
|
|
19
|
+
// Pure logic only — no I/O, no env reads, no clock — so it stays unit-testable
|
|
20
|
+
// in isolation (npm/fleet-vm-probe-target.test.js), exactly like vm-urls.js.
|
|
21
|
+
|
|
22
|
+
// Loopback host for the laptop probe. The SSH `-L` forward binds here, so the
|
|
23
|
+
// probe must too — 'localhost' could resolve to ::1 and miss an IPv4-only bind.
|
|
24
|
+
const LOCAL_HOST = '127.0.0.1';
|
|
25
|
+
|
|
26
|
+
/** Resolve where a per-VM editor-API probe should be sent.
|
|
27
|
+
*
|
|
28
|
+
* Returns a descriptor the caller dispatches on:
|
|
29
|
+
* { mode: 'lb', url, headers, authMissing } — GCE: absolute LB URL
|
|
30
|
+
* { mode: 'local', host, port, path, headers } — laptop: forwarded port
|
|
31
|
+
*
|
|
32
|
+
* `authMissing` is true when a GCE probe has no IAP token to attach. The caller
|
|
33
|
+
* must NOT treat the resulting response as reachable — an unauthenticated
|
|
34
|
+
* request to an IAP-fronted backend gets a 302 to the Google login page, which
|
|
35
|
+
* is "auth misconfigured", not "the VM is up". See classifyProbeResponse.
|
|
36
|
+
*
|
|
37
|
+
* `sessionToken` (optional): the fail-closed editor requires each VM's own
|
|
38
|
+
* editor session token in `Authorization` on every gated control-API request.
|
|
39
|
+
* When one is supplied, it rides in `Authorization` and the IAP token moves to
|
|
40
|
+
* `Proxy-Authorization` (IAP honors it there), so both credentials are present
|
|
41
|
+
* without colliding on `Authorization`. When it is absent, header shape is
|
|
42
|
+
* byte-for-byte today's behavior (IAP in `Authorization`), keeping the open
|
|
43
|
+
* `/api/session-info` reachability probe unchanged.
|
|
44
|
+
*/
|
|
45
|
+
function resolveVmProbeTarget({ onGce, url, n, portBase, path, iapToken, sessionToken } = {}) {
|
|
46
|
+
const probePath = path == null ? '/' : String(path);
|
|
47
|
+
if (!probePath.startsWith('/')) {
|
|
48
|
+
throw new Error(`probe path must start with "/", got: ${probePath}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!onGce) {
|
|
52
|
+
const base = Number(portBase);
|
|
53
|
+
const num = Number(n);
|
|
54
|
+
if (!Number.isInteger(base) || !Number.isInteger(num)) {
|
|
55
|
+
throw new Error('local probe requires integer portBase and n');
|
|
56
|
+
}
|
|
57
|
+
return { mode: 'local', host: LOCAL_HOST, port: base + num, path: probePath, headers: {} };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// GCE: the LB URL is the ONLY way in. A VM with no derived URL (legacy
|
|
61
|
+
// quick-tunnel mode, or a roster entry the URL derivation skipped) has no
|
|
62
|
+
// reachable address on this host, so fail loud rather than silently falling
|
|
63
|
+
// back to a local port that is guaranteed dead.
|
|
64
|
+
const origin = url == null ? '' : String(url).trim().replace(/\/+$/, '');
|
|
65
|
+
if (origin === '') {
|
|
66
|
+
throw new Error(`VM-${n} has no LB URL to probe (FLEET_DOMAIN not configured?)`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const token = iapToken == null ? '' : String(iapToken).trim();
|
|
70
|
+
const session = sessionToken == null ? '' : String(sessionToken).trim();
|
|
71
|
+
// With a session token the fail-closed editor's own credential owns
|
|
72
|
+
// `Authorization`; IAP still fronts the LB, so its token moves to
|
|
73
|
+
// `Proxy-Authorization`. Without one, keep exactly today's IAP-in-
|
|
74
|
+
// `Authorization` shape. `authMissing` stays keyed on the IAP token alone —
|
|
75
|
+
// IAP is still required to reach the LB even when a session token is present.
|
|
76
|
+
let headers;
|
|
77
|
+
if (session !== '') {
|
|
78
|
+
headers = { Authorization: `Bearer ${session}` };
|
|
79
|
+
if (token !== '') headers['Proxy-Authorization'] = `Bearer ${token}`;
|
|
80
|
+
} else {
|
|
81
|
+
headers = token === '' ? {} : { Authorization: `Bearer ${token}` };
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
mode: 'lb',
|
|
85
|
+
url: origin + probePath,
|
|
86
|
+
headers,
|
|
87
|
+
authMissing: token === '',
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The one open control-API endpoint: `/api/session-info` answers WITHOUT the
|
|
92
|
+
// editor's session token — it is the reachability probe. Every other control-API
|
|
93
|
+
// path is gated under fail-closed auth, so the dashboard must attach the VM's
|
|
94
|
+
// session token or get a 401. Kept here (pure, tested) rather than inline in the
|
|
95
|
+
// caller so the open-vs-gated boundary has one authoritative home.
|
|
96
|
+
const OPEN_PROBE_PATHS = new Set(['/api/session-info']);
|
|
97
|
+
|
|
98
|
+
/** True when a probe path needs the VM's editor session token attached.
|
|
99
|
+
*
|
|
100
|
+
* Only the open reachability probe (`/api/session-info`) is exempt; every other
|
|
101
|
+
* control-API path is gated under fail-closed auth. A query string is ignored so
|
|
102
|
+
* `/api/session-info?foo` still reads as the open path. */
|
|
103
|
+
function pathNeedsSessionToken(apiPath) {
|
|
104
|
+
const p = (apiPath == null ? '' : String(apiPath)).split('?')[0];
|
|
105
|
+
return p !== '' && !OPEN_PROBE_PATHS.has(p);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Hostname IAP redirects an unauthenticated request to. Matching this is what
|
|
109
|
+
// separates "the token is missing/expired" from "the VM is genuinely down" —
|
|
110
|
+
// both would otherwise read as a non-200 and blank the card identically.
|
|
111
|
+
const IAP_LOGIN_HOST = 'accounts.google.com';
|
|
112
|
+
|
|
113
|
+
/** Classify a probe response into the three outcomes the dashboard cares about.
|
|
114
|
+
*
|
|
115
|
+
* 'ok' — 200; caller still has to parse the body.
|
|
116
|
+
* 'auth-misconfigured' — IAP rejected or challenged us (302→login, 401, 403).
|
|
117
|
+
* The VM may be perfectly healthy; OUR credential is
|
|
118
|
+
* the problem, so this must never render as reachable
|
|
119
|
+
* and must never feed a reset decision.
|
|
120
|
+
* 'unreachable' — anything else: the VM/LB backend is not serving.
|
|
121
|
+
*/
|
|
122
|
+
function classifyProbeResponse({ status, location } = {}) {
|
|
123
|
+
const code = Number(status);
|
|
124
|
+
if (code === 200) return 'ok';
|
|
125
|
+
if (code === 401 || code === 403) return 'auth-misconfigured';
|
|
126
|
+
if (code >= 300 && code < 400) {
|
|
127
|
+
const to = location == null ? '' : String(location);
|
|
128
|
+
return to.includes(IAP_LOGIN_HOST) ? 'auth-misconfigured' : 'unreachable';
|
|
129
|
+
}
|
|
130
|
+
return 'unreachable';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Name the LIKELY cause behind an 'auth-misconfigured' probe, for logs only.
|
|
134
|
+
*
|
|
135
|
+
* 401 and 403 both mean "our credential is the problem", so they deliberately
|
|
136
|
+
* share one outcome — but they have opposite fixes, and telling them apart
|
|
137
|
+
* previously cost a live `curl` session against the backend (2026-07-20):
|
|
138
|
+
*
|
|
139
|
+
* 401 — the fail-closed editor rejected our session token. IAP now rides in
|
|
140
|
+
* Proxy-Authorization, so a 401 from the backend means the VM's own
|
|
141
|
+
* editor session token in Authorization was missing, stale, or wrong —
|
|
142
|
+
* the dashboard invalidates its cached token and self-heals next poll.
|
|
143
|
+
* 403 — the token is valid but the caller is not authorized. The automation SA
|
|
144
|
+
* is missing roles/iap.httpsResourceAccessor on that backend service.
|
|
145
|
+
*
|
|
146
|
+
* Returns null for any other status, so callers can log unconditionally.
|
|
147
|
+
* Diagnostic only — this never feeds a reachability or reset decision. */
|
|
148
|
+
function describeAuthMisconfig(status) {
|
|
149
|
+
const code = Number(status);
|
|
150
|
+
if (code === 401) {
|
|
151
|
+
return "session token rejected — the fail-closed editor requires this VM's " +
|
|
152
|
+
'own editor session token in Authorization; the dashboard fetch was ' +
|
|
153
|
+
'missing/stale (it invalidates the cached token and re-fetches next poll)';
|
|
154
|
+
}
|
|
155
|
+
if (code === 403) {
|
|
156
|
+
return 'missing accessor — the automation service account lacks ' +
|
|
157
|
+
'roles/iap.httpsResourceAccessor on this backend service ' +
|
|
158
|
+
'(re-grant: bash scripts/gcp/iap-access.sh <N> grant)';
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Map a probe outcome (+ optional transport reason) to the per-VM card shape
|
|
164
|
+
* the dashboard merges into `state.vms[n]`.
|
|
165
|
+
*
|
|
166
|
+
* The rule this encodes: an 'auth-misconfigured' outcome is NOT reachable, and
|
|
167
|
+
* stays distinguishable from a dead VM. Collapsing the two would either render
|
|
168
|
+
* a broken credential as a healthy VM, or let our own expired token look like N
|
|
169
|
+
* dead boxes and feed a reset decision. Anything unrecognized fails closed to
|
|
170
|
+
* unreachable rather than leaking a truthy `reachable`. */
|
|
171
|
+
function probeOutcomeToInfo(outcome, error) {
|
|
172
|
+
if (outcome === 'ok') return { reachable: true };
|
|
173
|
+
if (outcome === 'auth-misconfigured') {
|
|
174
|
+
return { reachable: false, error: 'auth-misconfigured', authMisconfigured: true };
|
|
175
|
+
}
|
|
176
|
+
return error ? { reachable: false, error } : { reachable: false };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Merge a parsed `/api/session-info` body into the per-VM card shape.
|
|
180
|
+
*
|
|
181
|
+
* The contract, in one place instead of inlined in the dashboard's probe:
|
|
182
|
+
* • an unreachable card never takes a body (a credential fault or a dead VM
|
|
183
|
+
* must not gain fields from whatever the transport happened to return);
|
|
184
|
+
* • a reachable card takes the body ONLY when it is a usable object.
|
|
185
|
+
*
|
|
186
|
+
* That second rule used to be accidental rather than stated. The expression was
|
|
187
|
+
* `info.reachable ? { ...info, ...json } : info`, and spreading `null` (or an
|
|
188
|
+
* array, or a scalar) is a silent no-op — so an unusable body produced a card
|
|
189
|
+
* that read reachable with `clientProject` and `editorIdentity` absent, which is
|
|
190
|
+
* indistinguishable from a VM that genuinely reports neither. The resulting card
|
|
191
|
+
* shape is deliberately UNCHANGED by making the rule explicit; what changes is
|
|
192
|
+
* that the caller can now see the fault (probeBodyFault) and log it instead of
|
|
193
|
+
* discovering it days later through a blank card. Pure. */
|
|
194
|
+
function mergeSessionInfoBody(info, json) {
|
|
195
|
+
if (!info || !info.reachable) return info;
|
|
196
|
+
if (json === null || typeof json !== 'object' || Array.isArray(json)) return info;
|
|
197
|
+
return { ...info, ...json };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Name the fault when a probe SUCCEEDED at the transport layer but its body is
|
|
201
|
+
* not a usable object, else null.
|
|
202
|
+
*
|
|
203
|
+
* This is the hole that cost a full diagnostic session on 2026-07-29. The card
|
|
204
|
+
* merge is `info.reachable ? { ...info, ...json } : info`, and spreading `null`
|
|
205
|
+
* (or an array, or a JSON scalar) is a silent no-op — so a VM answering 200 with
|
|
206
|
+
* an unusable body produced a card that read REACHABLE with every session-info
|
|
207
|
+
* field absent (`clientProject` and `editorIdentity` null), and emitted no log
|
|
208
|
+
* line at all. `stickyClientProject` then hid it for as long as a previously
|
|
209
|
+
* polled value survived in memory, so the fault only surfaced after a dashboard
|
|
210
|
+
* restart cleared the sticky cache.
|
|
211
|
+
*
|
|
212
|
+
* A 'bad-json' transport error is the sibling case: the body was unparseable, so
|
|
213
|
+
* the probe already fails closed to unreachable — correct, but equally silent.
|
|
214
|
+
* Callers pass that through here too so both paths get one loud warning.
|
|
215
|
+
*
|
|
216
|
+
* Returns a short, log-safe fault name:
|
|
217
|
+
* 'bad-json' — body did not parse (caller passes error === 'bad-json')
|
|
218
|
+
* 'null-body' — parsed to JSON null
|
|
219
|
+
* 'array-body' — parsed to an array
|
|
220
|
+
* '<type>-body' — parsed to a scalar (number/string/boolean)
|
|
221
|
+
* and null when the body is a usable object (the normal case) or the outcome was
|
|
222
|
+
* never 'ok' (already classified by probeOutcomeToInfo). Pure. */
|
|
223
|
+
function probeBodyFault(outcome, json, error) {
|
|
224
|
+
if (error === 'bad-json') return 'bad-json';
|
|
225
|
+
if (outcome !== 'ok') return null;
|
|
226
|
+
if (json === null || json === undefined) return 'null-body';
|
|
227
|
+
if (Array.isArray(json)) return 'array-body';
|
|
228
|
+
if (typeof json !== 'object') return `${typeof json}-body`;
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** The log line for a probe-body fault, naming the VM, the fault and the HTTP
|
|
233
|
+
* status — the three things that were missing when this failure mode cost a
|
|
234
|
+
* full diagnostic session with zero log output to work from.
|
|
235
|
+
*
|
|
236
|
+
* A missing status renders as `?` rather than `undefined`: the transport error
|
|
237
|
+
* paths (timeout, socket error) never saw a response, and `HTTP undefined` reads
|
|
238
|
+
* like a bug in the logger instead of an absent status.
|
|
239
|
+
*
|
|
240
|
+
* Diagnostic only — this never feeds a reachability decision, same contract as
|
|
241
|
+
* its sibling describeAuthMisconfig. Pure. */
|
|
242
|
+
function describeProbeBodyFault(n, fault, status) {
|
|
243
|
+
const code = status == null || status === '' ? '?' : String(status);
|
|
244
|
+
return `probe VM-${n} /api/session-info: ${fault} (HTTP ${code}) — ` +
|
|
245
|
+
'card identity (clientProject/editorIdentity) absent this poll';
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Per-VM, per-fault throttle for probe-fault warnings.
|
|
249
|
+
*
|
|
250
|
+
* The poll cycle runs every ~3s across the whole fleet, so warning on every
|
|
251
|
+
* faulted probe would bury the log. Throttling per (VM, fault) keeps a
|
|
252
|
+
* persistent fault to one line per interval while still surfacing a NEW fault on
|
|
253
|
+
* a different VM immediately.
|
|
254
|
+
*
|
|
255
|
+
* Deterministic: the caller supplies `now`, so no clock is read here and the
|
|
256
|
+
* behavior is unit-testable. */
|
|
257
|
+
function createProbeFaultThrottle(intervalMs = 300000) {
|
|
258
|
+
const last = new Map();
|
|
259
|
+
return {
|
|
260
|
+
shouldWarn(n, fault, now) {
|
|
261
|
+
const key = `${n}:${fault}`;
|
|
262
|
+
const prev = last.get(key);
|
|
263
|
+
if (prev != null && now - prev < intervalMs) return false;
|
|
264
|
+
last.set(key, now);
|
|
265
|
+
return true;
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
module.exports = {
|
|
271
|
+
LOCAL_HOST,
|
|
272
|
+
IAP_LOGIN_HOST,
|
|
273
|
+
resolveVmProbeTarget,
|
|
274
|
+
pathNeedsSessionToken,
|
|
275
|
+
classifyProbeResponse,
|
|
276
|
+
describeAuthMisconfig,
|
|
277
|
+
probeOutcomeToInfo,
|
|
278
|
+
mergeSessionInfoBody,
|
|
279
|
+
probeBodyFault,
|
|
280
|
+
describeProbeBodyFault,
|
|
281
|
+
createProbeFaultThrottle,
|
|
282
|
+
};
|
|
@@ -36,6 +36,20 @@
|
|
|
36
36
|
// 'half-wired' — LB mode, the editor backend service is ABSENT (never
|
|
37
37
|
// created). The permanent 503 case — the public URL will fail
|
|
38
38
|
// until re-wired. The state that had NO signal before.
|
|
39
|
+
// 'iap-access-missing' — LB mode, the EDITOR backend service is IAP-enabled but
|
|
40
|
+
// has NO accessor binding, so IAP authorizes nobody: the public
|
|
41
|
+
// URL returns "Error code 51" for everyone even when the backend
|
|
42
|
+
// is healthy. Distinct from 'half-wired' (there the backend is
|
|
43
|
+
// absent; here it exists and serves, but nobody's granted) — the
|
|
44
|
+
// exact "wired + IAP-enabled but 51s in the browser" gap.
|
|
45
|
+
// 'preview-iap-access-missing' — LB mode, the editor surface grants access but
|
|
46
|
+
// the dedicated PREVIEW backend has no accessor binding. The
|
|
47
|
+
// editor URL works, but the framed Live Preview (served from the
|
|
48
|
+
// separate preview host on client-routed stacks) is blank for
|
|
49
|
+
// every authorized user because nobody is granted THERE. A
|
|
50
|
+
// softer, non-URL-blocking warning than 'iap-access-missing'
|
|
51
|
+
// (the editor link is live) — the monitoring blind spot the
|
|
52
|
+
// editor-only IAP probe used to hide.
|
|
39
53
|
// 'starting' — LB mode, the editor backend exists but is UNHEALTHY (LB has
|
|
40
54
|
// not yet marked it HEALTHY). The transient 503 case; flips to
|
|
41
55
|
// 'ready' on its own once the health check passes.
|
|
@@ -48,15 +62,84 @@
|
|
|
48
62
|
// supplied): there is no LB to health-check, so the backend-health branch is
|
|
49
63
|
// skipped and readiness degrades to today's reachability/broker behavior — no
|
|
50
64
|
// regression, no gcloud calls.
|
|
65
|
+
// 'ws-dead' — reachable + LB-healthy, but the public WebSocket path is
|
|
66
|
+
// dead: the LB either refused the upgrade outright
|
|
67
|
+
// (publicWsHealth 'unwired') or the backend-service timeout is
|
|
68
|
+
// below the fleet minimum so the LB severs the socket on a
|
|
69
|
+
// fixed interval (the VM5 guillotine). The editor answers HTTP
|
|
70
|
+
// but the Build tab can't hold a terminal — NOT 'ready'.
|
|
71
|
+
// 'cli-missing' — the editor is up but the build-agent CLI isn't installed
|
|
72
|
+
// (`providerAuth.cliInstalled === false`): a provisioning
|
|
73
|
+
// fault, not a usable VM.
|
|
74
|
+
// 'auth-unsettled' — the auth probe is wedged at `unknown` (timing out — the
|
|
75
|
+
// exact VM5 auth shape): we can't even tell if login is
|
|
76
|
+
// needed. A provisioning fault distinct from a clean
|
|
77
|
+
// needs-login.
|
|
78
|
+
// 'needs-login' — CLI installed and auth SETTLED to `needs-login`: a
|
|
79
|
+
// legitimate, expected state (the user must authenticate),
|
|
80
|
+
// surfaced with the Authenticate affordance — NOT a fault and
|
|
81
|
+
// NOT a provisioning fault that holds rostering.
|
|
51
82
|
const READINESS_STATES = [
|
|
52
83
|
'provisioning',
|
|
53
84
|
'unreachable',
|
|
54
85
|
'half-wired',
|
|
86
|
+
'iap-access-missing',
|
|
87
|
+
'preview-iap-access-missing',
|
|
55
88
|
'starting',
|
|
56
89
|
'broker-down',
|
|
90
|
+
'ws-dead',
|
|
91
|
+
'cli-missing',
|
|
92
|
+
'auth-unsettled',
|
|
93
|
+
'needs-login',
|
|
57
94
|
'ready',
|
|
58
95
|
];
|
|
59
96
|
|
|
97
|
+
// The WS-timeout floor classifier lives next to classifyPublicUrlHealth (the
|
|
98
|
+
// public-URL probe is one concern); readiness consumes its verdict.
|
|
99
|
+
const fpub = require('./fleet-public-url');
|
|
100
|
+
|
|
101
|
+
// Classify the build-agent usability axis from the editor's own `providerAuth`
|
|
102
|
+
// subtree (vm: Readiness Verifies Real Usability). control-api emits the SAME
|
|
103
|
+
// `providerAuth` (with `cliInstalled` + settled `state`) on BOTH /api/config and
|
|
104
|
+
// /api/session-info via build_provider_auth_json, so the dashboard reads it
|
|
105
|
+
// straight off the gathered VM record — no re-derivation. Returns one verdict:
|
|
106
|
+
// 'cli-missing' — `cliInstalled === false`: a provisioning fault.
|
|
107
|
+
// 'auth-unsettled' — CLI installed but `state === 'unknown'` (probe wedged /
|
|
108
|
+
// timing out — the VM5 shape): a provisioning fault.
|
|
109
|
+
// 'needs-login' — CLI installed, `state === 'needs-login'`: a LEGITIMATE,
|
|
110
|
+
// actionable state, not a fault.
|
|
111
|
+
// 'ready' — CLI installed, `state === 'authenticated'`: usable.
|
|
112
|
+
// 'unknown' — providerAuth absent (older editor / probe never landed),
|
|
113
|
+
// or any other shape: absence of evidence, never a fault.
|
|
114
|
+
// Only an EXPLICIT `cliInstalled === false` / `state === 'unknown'` is a fault;
|
|
115
|
+
// missing fields stay 'unknown' so an older editor never reads as broken.
|
|
116
|
+
function classifyAgentUsability(providerAuth) {
|
|
117
|
+
if (!providerAuth || typeof providerAuth !== 'object') return 'unknown';
|
|
118
|
+
if (providerAuth.cliInstalled === false) return 'cli-missing';
|
|
119
|
+
if (providerAuth.cliInstalled !== true) return 'unknown';
|
|
120
|
+
if (providerAuth.state === 'unknown') return 'auth-unsettled';
|
|
121
|
+
if (providerAuth.state === 'needs-login') return 'needs-login';
|
|
122
|
+
if (providerAuth.state === 'authenticated') return 'ready';
|
|
123
|
+
return 'unknown';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Map the agent-usability verdict to the tri-state the rostering gate
|
|
127
|
+
// (fleet-cleanup's reapVerdict) consumes, mirroring `projectWired`'s
|
|
128
|
+
// true|false|null contract so a flaky probe can never strand a healthy VM:
|
|
129
|
+
// false — a PROVISIONING FAULT ('cli-missing' / 'auth-unsettled'): the box is
|
|
130
|
+
// not usable, so don't roster it as healthy (the VM5 false-green).
|
|
131
|
+
// true — usable enough to roster: 'ready', or a legitimate 'needs-login'
|
|
132
|
+
// (the user must auth, but that's an expected state, not a
|
|
133
|
+
// half-provisioned box that should be held back).
|
|
134
|
+
// null — 'unknown' (no providerAuth / probe couldn't decide): absence of
|
|
135
|
+
// evidence must NEVER block rostering, exactly like reapVerdict's null
|
|
136
|
+
// tolerance for projectWired.
|
|
137
|
+
function agentRosterReady(verdict) {
|
|
138
|
+
if (verdict === 'cli-missing' || verdict === 'auth-unsettled') return false;
|
|
139
|
+
if (verdict === 'ready' || verdict === 'needs-login') return true;
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
60
143
|
// A VM mid-provision: an Add (incl. its recovering re-run) that is queued
|
|
61
144
|
// (number reserved, cloud:up not started) or running. Its public URL has no
|
|
62
145
|
// meaningful readiness yet, so this takes precedence over every other signal —
|
|
@@ -94,11 +177,61 @@ function deriveVmReadiness(v, ctx) {
|
|
|
94
177
|
// 'healthy' falls through to ready; 'unknown' (get-health errored) is
|
|
95
178
|
// absence-of-evidence — never rendered as a problem, falls through too.
|
|
96
179
|
}
|
|
180
|
+
// 3b. IAP access: the backend is IAP-enabled but has NO accessor binding, so
|
|
181
|
+
// IAP authorizes nobody and the public URL returns "Error code 51" for
|
|
182
|
+
// everyone — even when the backend is healthy. A wiring-class fault a plain
|
|
183
|
+
// GET / backend-health probe are both blind to. Only an EXPLICIT
|
|
184
|
+
// 'no-accessor' verdict fires; absence/'unknown' is never a fault (an older
|
|
185
|
+
// dashboard that never gathered it must not read as broken). Gated on
|
|
186
|
+
// lbMode — legacy quick-tunnel mode has no per-BES IAP to check.
|
|
187
|
+
if (c.lbMode && v.iapAccess === 'no-accessor') return 'iap-access-missing';
|
|
97
188
|
// 4. Reachable but the broker daemon is down: the VM can't start a session.
|
|
98
189
|
if (c.brokerStatus === 'down') return 'broker-down';
|
|
99
|
-
// 5.
|
|
100
|
-
//
|
|
190
|
+
// 5. WS-usability (LB mode): the editor answers HTTP and the backend is
|
|
191
|
+
// LB-healthy, but the public WebSocket path is dead — either the LB refused
|
|
192
|
+
// the upgrade outright (publicWsHealth 'unwired') or the backend-service
|
|
193
|
+
// timeout is below the fleet minimum so the LB severs the socket on a fixed
|
|
194
|
+
// interval (the VM5 guillotine). Either way the Build tab can't hold a
|
|
195
|
+
// terminal, so this is NOT 'ready'. Skipped in legacy mode (no LB). An
|
|
196
|
+
// 'unknown'/absent WS verdict is absence-of-evidence — never a fault.
|
|
197
|
+
if (c.lbMode) {
|
|
198
|
+
// Deterministic guillotine first: a BES timeout below the fleet minimum
|
|
199
|
+
// severs the socket on a fixed interval — trustworthy, no probe needed.
|
|
200
|
+
if (fpub.classifyWsTimeout(v.backendTimeoutSec) === 'ws-timeout-too-low') return 'ws-dead';
|
|
201
|
+
// The public WS probe is IAP-blind and false-positives `unwired` on a
|
|
202
|
+
// genuinely-healthy VM (VM-1, 2026-07-01: wired + HEALTHY + IAP-granted,
|
|
203
|
+
// yet `publicWsHealth: unwired` → phantom ws-dead → URL gated "not ready").
|
|
204
|
+
// Only trust an `unwired` verdict when the backend is NOT already HEALTHY —
|
|
205
|
+
// a HEALTHY backend with a valid/unknown timeout is never ws-dead.
|
|
206
|
+
if (v.publicWsHealth === 'unwired' && !(bh && bh.editor === 'healthy')) return 'ws-dead';
|
|
207
|
+
}
|
|
208
|
+
// 6. Agent usability: the box is up and the WS path carries frames, but the
|
|
209
|
+
// build agent itself may not be usable — CLI not installed, or the auth
|
|
210
|
+
// probe wedged at 'unknown'. A legitimate 'needs-login' surfaces as its own
|
|
211
|
+
// actionable state (Authenticate), distinct from a provisioning fault.
|
|
212
|
+
// Absence of providerAuth (older editor / unprobed) falls through to ready.
|
|
213
|
+
const usability = classifyAgentUsability(v.providerAuth);
|
|
214
|
+
if (usability === 'cli-missing') return 'cli-missing';
|
|
215
|
+
if (usability === 'auth-unsettled') return 'auth-unsettled';
|
|
216
|
+
if (usability === 'needs-login') return 'needs-login';
|
|
217
|
+
// 6b. Preview-host IAP gap: the editor surface grants access (the URL routes
|
|
218
|
+
// and the box is otherwise ready) but the dedicated preview backend has no
|
|
219
|
+
// accessor, so the framed Live Preview is blank for authorized users. A
|
|
220
|
+
// softer warning than the editor 'iap-access-missing' — it does NOT block
|
|
221
|
+
// the editor link (see URL_BLOCKED_READINESS) — so it is checked last, just
|
|
222
|
+
// before 'ready'. Only an EXPLICIT 'preview-no-accessor' verdict fires;
|
|
223
|
+
// absence/'unknown' is never a fault. Gated on lbMode like its editor twin.
|
|
224
|
+
if (c.lbMode && v.iapAccess === 'preview-no-accessor') return 'preview-iap-access-missing';
|
|
225
|
+
// 7. Reachable, broker up, WS carries frames, agent usable, and (LB mode) the
|
|
226
|
+
// editor backend is HEALTHY — genuinely ready: green, clickable, the public
|
|
227
|
+
// URL routes AND holds a WebSocket.
|
|
101
228
|
return 'ready';
|
|
102
229
|
}
|
|
103
230
|
|
|
104
|
-
module.exports = {
|
|
231
|
+
module.exports = {
|
|
232
|
+
deriveVmReadiness,
|
|
233
|
+
READINESS_STATES,
|
|
234
|
+
isProvisioning,
|
|
235
|
+
classifyAgentUsability,
|
|
236
|
+
agentRosterReady,
|
|
237
|
+
};
|
package/npm/google-ingress.js
CHANGED
|
@@ -194,6 +194,20 @@ function dashboardHostRule(domain) {
|
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
/** Extract the VM number from an LB-ingress resource name this module mints
|
|
198
|
+
* (`vm-<N>-<surface>-neg` or `vm-<N>-<surface>-bes`, surface ∈ SURFACES).
|
|
199
|
+
* Returns the number, or null for any name that isn't a per-VM ingress resource
|
|
200
|
+
* (the shared `codeyam-dashboard-*` backend, a foreign resource, junk). The
|
|
201
|
+
* inverse of negName / backendServiceName — the orphan sweep uses it to map the
|
|
202
|
+
* live LB backends back to the VM numbers that own them. The surface alternation
|
|
203
|
+
* is built from SURFACES so it stays in lockstep with the name derivations.
|
|
204
|
+
* Pure. */
|
|
205
|
+
function vmNumberFromResourceName(name) {
|
|
206
|
+
const re = new RegExp(`^vm-(\\d+)-(?:${SURFACES.join('|')})-(?:neg|bes)$`);
|
|
207
|
+
const m = re.exec(String(name == null ? '' : name).trim());
|
|
208
|
+
return m ? Number(m[1]) : null;
|
|
209
|
+
}
|
|
210
|
+
|
|
197
211
|
module.exports = {
|
|
198
212
|
SURFACES,
|
|
199
213
|
EDITOR_PORT,
|
|
@@ -201,6 +215,7 @@ module.exports = {
|
|
|
201
215
|
normalizeSurface,
|
|
202
216
|
negName,
|
|
203
217
|
backendServiceName,
|
|
218
|
+
vmNumberFromResourceName,
|
|
204
219
|
urlMapHostRules,
|
|
205
220
|
hostRuleOperation,
|
|
206
221
|
backendNegAttachOperation,
|