@saptools/cf-debugger 0.2.2 → 0.3.1

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
@@ -18,6 +18,35 @@ Without it, an explicit stop refuses to signal a state-recorded PID whose port
18
18
  ownership cannot be proved; teardown still completes when the spawned child is
19
19
  independently confirmed dead.
20
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/`.
49
+
21
50
  ## Quick start
22
51
 
23
52
  ```bash
@@ -88,7 +117,11 @@ When region, org, or space is omitted, the current `cf target` supplies it.
88
117
  > restarting the named app is acceptable. `CF_DEBUGGER_ALLOW_RESTART=0` keeps
89
118
  > the guard enabled for a production shell and also vetoes a programmatic
90
119
  > `allowSshEnableRestart: true`. The environment value `1` can opt in the CLI,
91
- > but never grants permission to a programmatic caller by itself.
120
+ > but never grants permission to a programmatic caller by itself. CF CLI v7+
121
+ > used to reach this path as `SSH_PERMISSION_DENIED`, so an existing opt-in
122
+ > (flag, environment value, or programmatic option) could never restart an app
123
+ > with those CLIs; it now can, when `cf ssh-enabled` names the app itself as the
124
+ > layer that disables SSH.
92
125
 
93
126
  `--api-endpoint` accepts arbitrary hostnames but requires an absolute `https:`
94
127
  URL with no userinfo, query, fragment, or non-root path. Invalid values are
@@ -98,16 +131,39 @@ endpoint.
98
131
 
99
132
  Even with permission, a restart occurs only when all of these are true:
100
133
 
101
- 1. the one-shot SSH error specifically says SSH support is disabled;
102
- 2. `cf ssh-enabled <app>` proves app-level SSH is disabled;
134
+ 1. the one-shot SSH attempt fails with the generic "not authorized" error that
135
+ CF CLI v6.40+ and v7+ print for an app whose own SSH flag is off, or with an
136
+ older "SSH support is disabled" diagnostic;
137
+ 2. `cf ssh-enabled <app>` names the app itself as the layer that disables SSH
138
+ (CF CLI v7+ prints that reason line);
103
139
  3. this invocation runs `cf enable-ssh <app>`;
104
- 4. a second probe proves app-level SSH is now enabled.
140
+ 4. a second probe proves SSH is now enabled.
105
141
 
106
- An unknown probe result, an already-enabled app, a permission error, or a
107
- space-level SSH policy never causes a restart. Before an allowed restart,
108
- stderr names the app and org/space. With an explicit `--node-pid`, automatic
109
- restart is always rejected because the container replacement invalidates that
110
- PID.
142
+ The CLI prints the same "not authorized" error for an app whose SSH flag is
143
+ off as for a user without the Space Developer role, so after any such failure
144
+ cf-debugger first runs the read-only `cf ssh-enabled <app>` probe, and only
145
+ then checks the restart permission:
146
+
147
+ | Probe result | Outcome |
148
+ | --- | --- |
149
+ | SSH enabled | `SSH_PERMISSION_DENIED`: check the role and the space policy, or restart an app whose SSH was enabled after it started |
150
+ | State unknown (probe failed) | `SSH_PERMISSION_DENIED` (or `SSH_STATE_UNKNOWN` after the older diagnostic), with the probe error |
151
+ | Disabled by a space or platform policy | `SSH_POLICY_DISABLED`; the app is never changed |
152
+ | Disabled, but no layer named (for example CF CLI v6) | `SSH_STATE_UNKNOWN`; the app is never changed |
153
+ | Disabled for the app itself | `SSH_NOT_ENABLED` with the opt-in hint, or the guarded enable and restart |
154
+
155
+ Copy-paste commands in these messages start with
156
+ `cf login -a <api> -o <org> -s <space> &&` for the session's API endpoint,
157
+ because cf-debugger uses its own `CF_HOME` and your shell may be logged in to
158
+ another landscape (`cf api` alone would log the CLI out, so one `cf login`
159
+ selects the API, org, and space before the command runs). Only Space Developers and admins may change an app's SSH feature
160
+ (Space Supporters may restart apps but not enable SSH), so a user without SSH
161
+ access is stopped at `cf enable-ssh` before any restart. If the confirming
162
+ probe fails after `cf enable-ssh`, startup fails with `SSH_STATE_UNKNOWN`
163
+ without a restart, and the app's SSH flag may already be on. Before an allowed
164
+ restart, stderr names the app and org/space. With an explicit `--node-pid`,
165
+ automatic restart is always rejected because the container replacement
166
+ invalidates that PID.
111
167
 
112
168
  Read-only CF commands have a 60-second per-attempt cap and retry transient
113
169
  transport errors with bounded exponential delays while the single overall
@@ -203,7 +259,8 @@ with `UNKNOWN_REGION`.
203
259
 
204
260
  1. Resolve and validate the endpoint, deadline, target, and credentials.
205
261
  2. Prune only provably stale state and register a unique session/port.
206
- 3. Run `cf api`, environment-only `cf auth`, `cf target`, and an app existence check.
262
+ 3. Run `cf api`, environment-only `cf auth`, `cf target`, and a GUID-only app
263
+ existence check (`cf app <app> --guid`).
207
264
  4. Probe the selected instance through one-shot `cf ssh`.
208
265
  5. If an inspector already owns the remote port and is Node, reuse that PID.
209
266
  6. Otherwise:
@@ -230,9 +287,13 @@ results. GNU `find -lname` is capability-probed and is normally fast; the
230
287
  portable fallback walks descriptors with `readlink` and can take roughly
231
288
  10–12 seconds in a descriptor-heavy non-GNU container.
232
289
 
233
- `--remote-port` does not choose the port opened by `SIGUSR1`; Node always uses
234
- its default inspector port for that signal. A non-default value is therefore
235
- for an app already started with matching `--inspect=<port>`.
290
+ `--remote-port` does not choose the port opened by `SIGUSR1`. Node opens the
291
+ port from the app's own `--inspect-port` option (default `9229`, also settable
292
+ through `NODE_OPTIONS`), so a non-default value is for an app started with a
293
+ matching `--inspect=<port>` or `--inspect-port=<port>`. When the requested
294
+ port never opens but the selected process now listens on `9229`,
295
+ `INSPECTOR_NOT_READY` says so. That inspector stays open until the instance
296
+ restarts, and a start without `--remote-port` reuses it.
236
297
 
237
298
  ### Status sequence
238
299
 
@@ -326,7 +387,8 @@ domain code; it is never converted into success.
326
387
  | `CF_MUTATION_TIMEOUT` | A deployment mutation timed out, was not retried, and may still be completing remotely |
327
388
  | `STARTUP_TIMEOUT`, `ABORTED` | Overall deadline expired, or caller/stop intent cancelled startup |
328
389
  | `APP_NOT_FOUND` | The targeted app does not exist in the selected org/space |
329
- | `SSH_NOT_ENABLED`, `SSH_PERMISSION_DENIED`, `SSH_STATE_UNKNOWN` | Restart refused/not useful, permission denied, or SSH state ambiguous |
390
+ | `SSH_NOT_ENABLED`, `SSH_PERMISSION_DENIED`, `SSH_STATE_UNKNOWN` | SSH is off for the app itself, enablement failed, or a restart would not help; `cf ssh-enabled` reports SSH as enabled (or cannot verify it) yet access is denied; or the probe could not prove which layer disables SSH, or could not confirm SSH after `cf enable-ssh` ran (the app's SSH flag may then be on; no restart was attempted) |
391
+ | `SSH_POLICY_DISABLED` | A space or platform policy disables SSH; cf-debugger never changes policy or the app, even with restart permission |
330
392
  | `NODE_PID_RESTART_UNSAFE` | Explicit PID cannot survive an app restart |
331
393
  | `NODE_PROCESS_NOT_FOUND`, `NODE_PROCESS_AMBIGUOUS`, `NODE_PID_INVALID` | Remote Node selection failed closed |
332
394
  | `USR1_SIGNAL_FAILED`, `INSPECTOR_NOT_READY`, `INSPECTOR_OWNER_MISMATCH`, `INSPECTOR_OUTPUT_TOO_LARGE` | Remote signal/ownership protocol failed |
@@ -389,8 +451,31 @@ Not by default. Inspector activation sends `SIGUSR1` to the verified Node
389
451
  process, but app-level SSH enablement and `cf restart` require explicit
390
452
  `--allow-ssh-enable-restart` permission. Even with permission, restart occurs
391
453
  only after this run changes app SSH from proven disabled to proven enabled; an
392
- already-enabled, unknown, permission-denied, or space-policy result never
393
- restarts the app.
454
+ already-enabled, unknown, permission-denied, or space/platform-policy result,
455
+ or a probe that does not name the app as the disabling layer, never restarts
456
+ the app. If `cf enable-ssh` ran but its effect could not be confirmed, startup
457
+ stops before the restart and says that the app's SSH flag may now be on.
458
+
459
+ The inspector that `SIGUSR1` opens listens on the container's loopback
460
+ interface and stays open after `stop`, which closes only the local tunnel. It
461
+ closes when that app instance restarts, and a later `start` reuses it without
462
+ another signal. Readiness checks only read `/json/list`; cf-debugger never
463
+ attaches a debugger session itself.
464
+
465
+ ### How can I confirm what happened inside the app container?
466
+
467
+ Node writes its inspector events to the app's stderr, so they appear in the
468
+ app log stream:
469
+
470
+ | Log line | Meaning |
471
+ | --- | --- |
472
+ | `Debugger listening on ws://127.0.0.1:9229/<id>` | `SIGUSR1` opened the inspector |
473
+ | `Debugger attached.` | A debugger client connected through the tunnel |
474
+ | `Debugger ending on ws://127.0.0.1:9229/<id>` | The last client disconnected; the inspector keeps listening |
475
+
476
+ A busy app can push these lines out of `cf logs <app> --recent` within
477
+ seconds, so search a historical log backend (for example SAP Cloud Logging)
478
+ when you need them later.
394
479
 
395
480
  ### Is session state always removed when the CLI exits?
396
481