@saptools/cf-debugger 0.2.1 → 0.3.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/README.md CHANGED
@@ -14,6 +14,38 @@ Node.js 20+ and the official `cf` CLI are required. CF CLI v8 is recommended.
14
14
  Non-`web` process targeting uses `cf ssh --process` and requires CF CLI v7+.
15
15
  On macOS, `lsof` is a soft dependency used to prove which PID owns a local
16
16
  listening port. Install it if `cf-debugger` reports `TUNNEL_OWNER_UNVERIFIED`.
17
+ Without it, an explicit stop refuses to signal a state-recorded PID whose port
18
+ ownership cannot be proved; teardown still completes when the spawned child is
19
+ independently confirmed dead.
20
+
21
+ ## Updates
22
+
23
+ Every command first checks npm for a newer `@saptools/cf-debugger` (at most once an hour, one small request
24
+ with a 2-second timeout) and, when one exists, installs that exact version with the package manager
25
+ that owns the running binary and re-runs the command you typed on the new version. Both steps are
26
+ announced on stderr; nothing is printed when the install is already current:
27
+
28
+ ```text
29
+ cf-debugger: updating 0.3.0 -> 0.4.0 ...
30
+ cf-debugger: updated to 0.4.0; re-running the command
31
+ ```
32
+
33
+ If the install cannot complete, one stderr line gives the manual command and the command runs on the
34
+ installed version; that version is not retried for a day. `cf-debugger self-update` forces the check and
35
+ install now; `cf-debugger self-update --check` only reports.
36
+
37
+ | Control | Effect |
38
+ | --- | --- |
39
+ | `SAPTOOLS_AUTO_UPDATE=on\|notify\|off` | `on` (default) installs and re-runs; `notify` prints the manual command once per version; `off` never checks. Applies to every `@saptools` CLI. |
40
+ | `CF_DEBUGGER_AUTO_UPDATE` | same values, this CLI only; wins over the global variable |
41
+ | `SAPTOOLS_UPDATE_INTERVAL_MINUTES` | minutes between checks (default `60`; `0` checks on every run) |
42
+ | `SAPTOOLS_NPM_REGISTRY` | registry to check and install from (default: npm's configured registry, then npmjs) |
43
+ | `SAPTOOLS_UPDATE_DEBUG=1` | explain on stderr why nothing happened |
44
+
45
+ The updater switches itself off in CI (`CI` set), under `NODE_ENV=test` or `NO_UPDATE_NOTIFIER`, when
46
+ the binary runs from a source checkout, an `npm link` or an `npx` cache, and inside the re-run itself.
47
+ It never writes to stdout, never asks for input, never uses `sudo`, and never moves onto a prerelease.
48
+ Its state lives in `~/.saptools/updates/`.
17
49
 
18
50
  ## Quick start
19
51
 
@@ -43,9 +75,11 @@ Debugger ready for my-app (eu10/my-org/dev).
43
75
  Press Ctrl+C to stop.
44
76
  ```
45
77
 
46
- Attach the IDE to `127.0.0.1:20142`. The remote inspector advertises its own
47
- `ws://127.0.0.1:9229/...` URL through the tunnel; `cf-debugger` validates that
48
- the URL exists but does not print or follow that remote-authority URL.
78
+ Attach the IDE to `127.0.0.1:20142`. Node derives the advertised
79
+ `webSocketDebuggerUrl` from the incoming request's `Host` header, so a URL
80
+ returned through the forward already names the local forwarded port and is
81
+ directly usable. `cf-debugger` validates that the URL is well formed but does
82
+ not print or follow it.
49
83
 
50
84
  ## CLI
51
85
 
@@ -63,13 +97,13 @@ When region, org, or space is omitted, the current `cf target` supplies it.
63
97
  | Flag | Meaning |
64
98
  | --- | --- |
65
99
  | `--region <key>` | SAP region key; defaults to the current CF target |
66
- | `--api-endpoint <url>` | Exact endpoint override, including nonstandard landscapes |
100
+ | `--api-endpoint <url>` | Absolute HTTPS endpoint override, including private/nonstandard hosts |
67
101
  | `--org <name>`, `--space <name>`, `--app <name>` | CF target and app |
68
102
  | `--process <name>` | CF process, default `web` |
69
103
  | `-i, --instance <index>` | Zero-based process instance, default `0` |
70
104
  | `--node-pid <pid>` | Exact remote Node PID |
71
105
  | `--port <number>` | Preferred local port; otherwise choose from `20000–20999` |
72
- | `--remote-port <number>` | Remote inspector port, default `9229` |
106
+ | `--remote-port <number>` | Port where cf-debugger looks for an existing remote inspector, default `9229` |
73
107
  | `--timeout <seconds>` | Local-tunnel and inspector-readiness budget, default `180` |
74
108
  | `--startup-timeout <seconds>` | Overall startup deadline, default `300`, maximum `1800` |
75
109
  | `--allow-ssh-enable-restart` | Permit app-level SSH enablement and one app restart |
@@ -81,7 +115,15 @@ When region, org, or space is omitted, the current `cf target` supplies it.
81
115
  > `SSH_NOT_ENABLED` and no deployment mutation. Use
82
116
  > `--allow-ssh-enable-restart`, or set `CF_DEBUGGER_ALLOW_RESTART=1`, only when
83
117
  > restarting the named app is acceptable. `CF_DEBUGGER_ALLOW_RESTART=0` keeps
84
- > the guard enabled for a production shell.
118
+ > the guard enabled for a production shell and also vetoes a programmatic
119
+ > `allowSshEnableRestart: true`. The environment value `1` can opt in the CLI,
120
+ > but never grants permission to a programmatic caller by itself.
121
+
122
+ `--api-endpoint` accepts arbitrary hostnames but requires an absolute `https:`
123
+ URL with no userinfo, query, fragment, or non-root path. Invalid values are
124
+ rejected before `cf api` or `cf auth`. Version 0.2.2 intentionally rejects
125
+ plaintext `http://` landscapes because credentials would be sent to that
126
+ endpoint.
85
127
 
86
128
  Even with permission, a restart occurs only when all of these are true:
87
129
 
@@ -96,15 +138,18 @@ stderr names the app and org/space. With an explicit `--node-pid`, automatic
96
138
  restart is always rejected because the container replacement invalidates that
97
139
  PID.
98
140
 
99
- The per-attempt CF command timeout is 60 seconds. Transient transport errors
100
- retry with bounded exponential delays while the single overall startup budget
101
- still has time. `cf auth` has no outer retry loop, and rejected credentials fail
102
- after one attempt; repeated manual failures may count toward a tenant's
103
- identity-provider lockout policy. The one-shot SSH signal and readiness wait are
104
- also clamped to the same overall deadline. No retry configuration multiplies
105
- startup work past `--startup-timeout`. After a timeout, fail-closed tunnel and
106
- state cleanup still runs; that safety teardown can briefly extend the observed
107
- command wall time rather than abandoning an unverified child.
141
+ Read-only CF commands have a 60-second per-attempt cap and retry transient
142
+ transport errors with bounded exponential delays while the single overall
143
+ startup budget still has time. Deployment-mutating commands have a separate
144
+ 180-second cap and are never retried: a timed-out enable/restart reports
145
+ `CF_MUTATION_TIMEOUT` because the server-side mutation may still be completing.
146
+ `cf auth` has no outer retry loop, and rejected credentials fail after one
147
+ attempt; repeated manual failures may count toward a tenant's identity-provider
148
+ lockout policy. The one-shot SSH signal and readiness wait are also clamped to
149
+ the same overall deadline. No retry configuration multiplies startup work past
150
+ `--startup-timeout`. After a timeout, fail-closed tunnel and state cleanup still
151
+ runs; that safety teardown can briefly extend the observed command wall time
152
+ rather than abandoning an unverified child.
108
153
 
109
154
  ### `stop`
110
155
 
@@ -117,19 +162,20 @@ cf-debugger stop --all
117
162
  cf-debugger stop --session-id 550e8400-e29b-41d4-a716-446655440000 --force
118
163
  ```
119
164
 
120
- `stop --all` attempts every local session, reports stopped, stale, pending, and
121
- failed outcomes separately, and exits nonzero if any session failed. It cannot
165
+ `stop --all` attempts every local session, reports stopped, forced, stale,
166
+ pending, and failed outcomes separately, and exits `70` if any tunnel cleanup
167
+ failed (`1` for other failures). It cannot
122
168
  be combined with a positional selector, `--session-id`, or target selector
123
169
  options; ambiguous scope is rejected instead of widening to every session.
124
170
 
125
171
  `stop --force` means “forget safely,” not “kill harder.” It never signals a PID
126
- whose tunnel ownership is unproven. It removes the state record and only the
127
- exact derived v2 `CF_HOME`, then warns with the abandoned PID and port so they
128
- can be investigated manually. This is the supported recovery for a dead tunnel
129
- whose old port is now occupied by another program, or an abandoned startup
130
- record that cannot be verified. If a damaged record names a non-owned home
131
- path, that path is left untouched and named in the warning while the record is
132
- still forgotten.
172
+ whose tunnel ownership is unproven. It forgets the state record first, then
173
+ best-effort removes only the exact derived v2 `CF_HOME`. A deletion failure is
174
+ non-fatal and warns that the retained path may contain a live refresh token;
175
+ `doctor` then reports it as an orphan eligible for `doctor --cleanup`. The
176
+ warning also names the abandoned PID and port for manual investigation. If a
177
+ damaged record names a non-owned home path, that path is left untouched while
178
+ the record is still forgotten.
133
179
 
134
180
  ### `list` and `status`
135
181
 
@@ -161,12 +207,16 @@ The default is read-only JSON reporting. It includes:
161
207
  - v2 session homes with no state record;
162
208
  - listeners in `20000–20999` that no state record claims;
163
209
  - leftover state temp, lock, recovery, stop-intent, and corrupt-backup files;
164
- - legacy v1 state/homes and their credential-retention risk.
210
+ - legacy v1 state/homes, home count, parseable claimed sessions, conservative
211
+ PID liveness, and their credential-retention risk.
165
212
 
166
213
  `--cleanup` removes only canonical orphan v2 homes and sufficiently old,
167
214
  package-owned temp/lock/recovery/stop-intent artifacts. It revalidates orphan
168
215
  homes against lock-guarded state immediately before deletion. It never signals
169
216
  an unclaimed listener, removes corrupt evidence, or removes legacy v1 artifacts.
217
+ Corrupt backups include a manual-removal command in the report while remaining
218
+ ineligible for automatic cleanup. A symlinked v2 homes root is reported and
219
+ never traversed.
170
220
 
171
221
  ## Region resolution
172
222
 
@@ -205,7 +255,13 @@ explicitly if a worker is the intended target.
205
255
 
206
256
  The remote probe reads `/proc/<pid>/exe`, not argv. Its marker lines are filtered
207
257
  by a strict `saptools-inspector-*` prefix, so CF SSH banners cannot impersonate
208
- results.
258
+ results. GNU `find -lname` is capability-probed and is normally fast; the
259
+ portable fallback walks descriptors with `readlink` and can take roughly
260
+ 10–12 seconds in a descriptor-heavy non-GNU container.
261
+
262
+ `--remote-port` does not choose the port opened by `SIGUSR1`; Node always uses
263
+ its default inspector port for that signal. A non-default value is therefore
264
+ for an app already started with matching `--inspect=<port>`.
209
265
 
210
266
  ### Status sequence
211
267
 
@@ -251,6 +307,13 @@ individually, and the original state file is moved to a private
251
307
  version, or root shape is likewise preserved before a fresh empty v2 file is
252
308
  written.
253
309
 
310
+ During mixed-version use, an older cf-debugger sharing this v2 file may strip
311
+ optional fields it does not understand, including process-identity and startup
312
+ budget data. Newer code treats an absent/legacy identity as “cannot tell” and
313
+ retains the record with PID-only compatibility rather than pruning it; `doctor`
314
+ surfaces that degraded verdict. Updating every installed consumer is the only
315
+ way to restore the stronger identity check persistently.
316
+
254
317
  Legacy `~/.saptools/cf-debugger-homes/` directories may still contain live
255
318
  refresh and access tokens. `doctor` reports but never deletes them. After
256
319
  confirming no v1 tunnel is running, remove them explicitly:
@@ -274,7 +337,7 @@ and redact sensitive values before they reach errors or verbose output.
274
337
  | Variable | Meaning |
275
338
  | --- | --- |
276
339
  | `SAP_EMAIL`, `SAP_PASSWORD` | CF authentication credentials |
277
- | `CF_DEBUGGER_ALLOW_RESTART=0\|1` | Shell-level restart guard/default |
340
+ | `CF_DEBUGGER_ALLOW_RESTART=0\|1` | CLI default; `0` is also a hard veto for the programmatic API |
278
341
  | `CF_DEBUGGER_CF_BIN` | Replace the `cf` executable; useful for wrappers and deterministic test stubs |
279
342
 
280
343
  A caller-provided child environment cannot override the per-session `CF_HOME`.
@@ -289,6 +352,7 @@ domain code; it is never converted into success.
289
352
  | --- | --- |
290
353
  | `UNKNOWN_REGION`, `UNSAFE_INPUT`, `MISSING_CREDENTIALS` | Invalid endpoint/key, selector, numeric input, or credentials |
291
354
  | `CF_LOGIN_FAILED`, `CF_AUTH_FAILED`, `CF_TARGET_FAILED`, `CF_CLI_FAILED`, `CF_CLI_TIMEOUT` | CF command failure; rejected auth is not retried |
355
+ | `CF_MUTATION_TIMEOUT` | A deployment mutation timed out, was not retried, and may still be completing remotely |
292
356
  | `STARTUP_TIMEOUT`, `ABORTED` | Overall deadline expired, or caller/stop intent cancelled startup |
293
357
  | `APP_NOT_FOUND` | The targeted app does not exist in the selected org/space |
294
358
  | `SSH_NOT_ENABLED`, `SSH_PERMISSION_DENIED`, `SSH_STATE_UNKNOWN` | Restart refused/not useful, permission denied, or SSH state ambiguous |
@@ -302,13 +366,15 @@ domain code; it is never converted into success.
302
366
  | `TUNNEL_EXITED`, `TUNNEL_TERMINATION_FAILED`, `TUNNEL_OWNERSHIP_UNVERIFIED` | Tunnel died, cleanup could not terminate it, or stop could not safely signal it |
303
367
  | `SESSION_ALREADY_RUNNING`, `SESSION_AMBIGUOUS`, `SESSION_NOT_FOUND` | Session selection conflict |
304
368
  | `SESSION_STATE_LOST`, `SESSION_STATE_CONFLICT`, `STATE_LOCK_TIMEOUT` | Atomic state/lifecycle invariant failed |
369
+ | `CF_HOME_CLEANUP_FAILED` | Session state was removed but lifecycle cleanup could not remove its exact credential-bearing CF home |
370
+ | `PACKAGE_METADATA_INVALID` | Runtime package metadata has no usable version |
305
371
  | `STOP_FAILED` | One entry in a batch stop failed with a non-coded internal error |
306
372
 
307
373
  | Exit | Meaning |
308
374
  | --- | --- |
309
375
  | `0` | Clean completion |
310
376
  | `1` | Coded operational/startup error, including `STARTUP_TIMEOUT` |
311
- | `70` | Cleanup/termination failed and state was retained |
377
+ | `70` | Tunnel or lifecycle cleanup failed; ownership state or a credential-bearing home may remain |
312
378
  | SSH child's nonzero code | An unexpected numeric SSH exit is preserved, for example `255` |
313
379
  | `128 + signal` | Tunnel child died from a signal, for example `137` for `SIGKILL` |
314
380
  | `130`, `143` | User interrupted with `SIGINT` or `SIGTERM` |
@@ -337,7 +403,7 @@ const handle = await startDebugger({
337
403
  await handle.dispose();
338
404
 
339
405
  const summary = await stopAllDebuggers();
340
- // 0.2.0 returns per-session outcomes plus stopped/stale/pending/failed counts.
406
+ // Outcomes and counts distinguish stopped/forced/stale/pending/failed.
341
407
  ```
342
408
 
343
409
  Persisted schema additions in 0.2.0 are optional. Absence means compatible