@theholocron/kyber 5.0.0-alpha.372 → 5.0.0-alpha.373
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 +14 -14
- package/dist/plugins.d.mts +7 -0
- package/dist/plugins.mjs +12 -5
- package/dist/testing.d.mts +10 -1
- package/dist/testing.mjs +50 -13
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -10,20 +10,20 @@ Published, so a second CLI can import it. `@theholocron/cli` is its first consum
|
|
|
10
10
|
|
|
11
11
|
## Subpaths
|
|
12
12
|
|
|
13
|
-
| Subpath | What it gives a CLI
|
|
14
|
-
| ---------------- |
|
|
15
|
-
| `/ui` | Status glyphs and colours, padded status rows, a check-rows renderer (`printCheckRows`, `printCheckSummary`, `summariseChecks`, `declaredVsActual`), a depth-limited JSON view, a spinner that only shows on a terminal (and `createRetryNotice(subscribe)`, which says on it when a request is retried, given the HTTP client's retry hook), wait-for-Enter, open-in-file-browser, the error for "a prompt was needed but there is no terminal", and the cleaning of error text before it reaches a terminal (`describeError`, `commandFailureMessage`, `logReason`, `sanitizeDetail`, `stripControl`).
|
|
16
|
-
| `/notifier` | A cached, best-effort "a newer version exists" notice for an npm package: `checkForUpdates({ name, currentVersion, cacheDir })` returns a function that prints a boxed notice to stderr, or `null`. Silent in CI and with `NO_UPDATE_NOTIFIER`.
|
|
17
|
-
| `/secrets` | Handling tokens safely, with no terminal UI: owner-only (`0600`) files, shredding a file that held tokens, the wait-for-the-import-then-delete step that follows (`finishCredentialsFile`: deletes the file on Enter, Ctrl-C or a closed terminal), "does git ignore this path", dotenv lines that survive quoting, reading a `.env` at the repo root, the clipboard, the OS keyring (`createKeyring({ service })`, best-effort, `@napi-rs/keyring` optional), an in-process store for credentials a provider returned, `--token` / `--token vendor=value` parsing, and resolving a token from the flag, the environment, that store and the keyring (`createResolveToken`, `createFeatureResolver`, `AuthError`).
|
|
18
|
-
| `/prompts` | A searchable menu (`pickMenuItem`), and prompting for the positionals and options a command left out (`promptForPositionals`, `promptForOptions`): required options always asked, the rest behind one checkbox, mutually exclusive `modes`, secret options masked, and a value that is asked last (`askLast`). They take small structural types (`PositionalCommand`, `OptionsCommand`), not the CLI's command registry.
|
|
19
|
-
| `/menu` | The interactive menu of a CLI, driven by data: `launchMenu(entries, argv, { bin, envPrefix })` shows a searchable, nested picker over a list of `MenuEntry`, asks for the positionals and options the command needs, then spawns the CLI again with the answers. A command that supports `--dry-run` is previewed first and then confirmed (`--skip-dry-run` opts out); a preview that reports `DRY_RUN_NOOP_EXIT_CODE` skips the question. Secret options never reach argv: they travel as `<envPrefix>_<OPTION>` env vars, and a preview child gets `dryRunPreviewEnvVar(envPrefix)`. `createMenu({ bin, envPrefix })` binds it once (returning `launchMenu(entries, argv, options?)` and `dryRunPreviewEnvVar`). `createCommandRegistry(entries, label?)` declares the commands once and returns `{ entries, getEntry(name) }` (a repeated name throws), and `numeric` is a ready `validate` for a number prompt. Also `menuItems`, `buildChildArgv`, `forwardedFlags`, `secretEnv`, `shouldPreviewDryRun`.
|
|
20
|
-
| `/testing` | A test harness for a CLI: `createCliRunner` runs a built binary in a fresh directory with an environment built from nothing, `runCommand` runs one yargs command module through a real parse, `ensureBuilt` is a Vitest global setup that builds only when `dist` is missing or stale, and `hermeticCreateRequire` resolves modules only from one directory.
|
|
21
|
-
| `/observability` | The logging and telemetry wiring of a CLI: `createCliLogger({ envPrefix, resolveAxiom? })` returns a memoized root logger (`buildCliLogger`, `getLogger`, `reportError`, `getRunId`, `resolveLogLevel`) whose level comes from `--log` / `--verbose` / `--quiet`, then `<PREFIX>_LOG_LEVEL`, then the config file, and is quiet on a terminal unless asked; `createCliTelemetry({ envPrefix, dsn, posthogKey, posthogHost })` returns Sentry error reporting and PostHog analytics behind `<PREFIX>_TELEMETRY=false`. `@theholocron/observability` is an optional peer.
|
|
22
|
-
| `/config` | A `<name>.config.{ts,js,mjs,cjs,json}` for a new CLI: `createConfigSystem({ name, areas?, place?, derive?, resolve, merge })` returns `defineConfig`, `loadConfig` (walks up to `.git`) and `compose()` (dedupe by `id`, all unmet `requires` in one `ConfigError`, per-key merge). Strategies: `lastWins`, `shallowMerge`, `union`, `mergeByKey`. `@theholocron/datapad` is an optional peer.
|
|
23
|
-
| `/plugins` | A plugin system for a new CLI: `createPluginSystem({ packagePrefix, providers, communityPrefix?, configFile?, pluginOptions?, preload? })` returns a `PluginLoader` class and `resolvePackage`. `load()` imports each configured provider's package (from the working directory first, importer injectable), calls its `createPlugin(options)` and fills a registry typed by your capability map: `get(key)` is one implementation for a `single` capability and an array for a `many` one. A package may export a capability config (`{ provider, options? }`) whose preset options sit under the project's. A failing provider is recorded in `loadFailures()` and `get` rethrows its error; `load()` never throws for one. Also `assertPluginsResolvable`, `isModuleNotFound`, `resolvePluginPackage`, `defaultImporter` and `LoaderError`.
|
|
24
|
-
| `/flags` | The options every command of a tool takes: `addGlobalOptions(parser, { describe?, cwd? })` declares `--dry-run`, a repeatable `--token` and `--cwd` once on the root; `tokenContext(values, report)` parses the `--token` values and reports a bad one without a stack trace; `groupMenu(parent, open)` is the hidden default command that makes a bare group (`tool repo`) do something useful; `InferArgs` types a command's handler arguments from its builder.
|
|
25
|
-
| `/checks` | `runCheckAgainstUrl(input, opts?)` runs an HTTP check with assertions (`status_code`, `response_time`, `body`, `header`) over `fetch` and returns `{ passed, failures, requestError? }`, with no monitoring vendor involved; `connectionProbe({ provider, url?, token, verify })` is a probe that tells a network problem from a credential problem (and `describeNetworkError` words a network failure).
|
|
26
|
-
| `/git` | `moveMajorTag({ group, version?, dryRun?, remote? })` moves a version group's major tag (`ci-v1`) to its latest stable release and force-pushes it; `runGit(args, cwd)` runs `git` without a shell.
|
|
13
|
+
| Subpath | What it gives a CLI |
|
|
14
|
+
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| `/ui` | Status glyphs and colours, padded status rows, a check-rows renderer (`printCheckRows`, `printCheckSummary`, `summariseChecks`, `declaredVsActual`), a depth-limited JSON view, a spinner that only shows on a terminal (and `createRetryNotice(subscribe)`, which says on it when a request is retried, given the HTTP client's retry hook), wait-for-Enter, open-in-file-browser, the error for "a prompt was needed but there is no terminal", and the cleaning of error text before it reaches a terminal (`describeError`, `commandFailureMessage`, `logReason`, `sanitizeDetail`, `stripControl`). |
|
|
16
|
+
| `/notifier` | A cached, best-effort "a newer version exists" notice for an npm package: `checkForUpdates({ name, currentVersion, cacheDir })` returns a function that prints a boxed notice to stderr, or `null`. Silent in CI and with `NO_UPDATE_NOTIFIER`. |
|
|
17
|
+
| `/secrets` | Handling tokens safely, with no terminal UI: owner-only (`0600`) files, shredding a file that held tokens, the wait-for-the-import-then-delete step that follows (`finishCredentialsFile`: deletes the file on Enter, Ctrl-C or a closed terminal), "does git ignore this path", dotenv lines that survive quoting, reading a `.env` at the repo root, the clipboard, the OS keyring (`createKeyring({ service })`, best-effort, `@napi-rs/keyring` optional), an in-process store for credentials a provider returned, `--token` / `--token vendor=value` parsing, and resolving a token from the flag, the environment, that store and the keyring (`createResolveToken`, `createFeatureResolver`, `AuthError`). |
|
|
18
|
+
| `/prompts` | A searchable menu (`pickMenuItem`), and prompting for the positionals and options a command left out (`promptForPositionals`, `promptForOptions`): required options always asked, the rest behind one checkbox, mutually exclusive `modes`, secret options masked, and a value that is asked last (`askLast`). They take small structural types (`PositionalCommand`, `OptionsCommand`), not the CLI's command registry. |
|
|
19
|
+
| `/menu` | The interactive menu of a CLI, driven by data: `launchMenu(entries, argv, { bin, envPrefix })` shows a searchable, nested picker over a list of `MenuEntry`, asks for the positionals and options the command needs, then spawns the CLI again with the answers. A command that supports `--dry-run` is previewed first and then confirmed (`--skip-dry-run` opts out); a preview that reports `DRY_RUN_NOOP_EXIT_CODE` skips the question. Secret options never reach argv: they travel as `<envPrefix>_<OPTION>` env vars, and a preview child gets `dryRunPreviewEnvVar(envPrefix)`. `createMenu({ bin, envPrefix })` binds it once (returning `launchMenu(entries, argv, options?)` and `dryRunPreviewEnvVar`). `createCommandRegistry(entries, label?)` declares the commands once and returns `{ entries, getEntry(name) }` (a repeated name throws), and `numeric` is a ready `validate` for a number prompt. Also `menuItems`, `buildChildArgv`, `forwardedFlags`, `secretEnv`, `shouldPreviewDryRun`. |
|
|
20
|
+
| `/testing` | A test harness for a CLI: `createCliRunner` runs a built binary in a fresh directory with an environment built from nothing, `runCommand` runs one yargs command module through a real parse, `ensureBuilt` is a Vitest global setup that builds only when `dist` is missing or stale, and `hermeticCreateRequire` resolves modules only from one directory. |
|
|
21
|
+
| `/observability` | The logging and telemetry wiring of a CLI: `createCliLogger({ envPrefix, resolveAxiom? })` returns a memoized root logger (`buildCliLogger`, `getLogger`, `reportError`, `getRunId`, `resolveLogLevel`) whose level comes from `--log` / `--verbose` / `--quiet`, then `<PREFIX>_LOG_LEVEL`, then the config file, and is quiet on a terminal unless asked; `createCliTelemetry({ envPrefix, dsn, posthogKey, posthogHost })` returns Sentry error reporting and PostHog analytics behind `<PREFIX>_TELEMETRY=false`. `@theholocron/observability` is an optional peer. |
|
|
22
|
+
| `/config` | A `<name>.config.{ts,js,mjs,cjs,json}` for a new CLI: `createConfigSystem({ name, areas?, place?, derive?, resolve, merge })` returns `defineConfig`, `loadConfig` (walks up to `.git`) and `compose()` (dedupe by `id`, all unmet `requires` in one `ConfigError`, per-key merge). Strategies: `lastWins`, `shallowMerge`, `union`, `mergeByKey`. `@theholocron/datapad` is an optional peer. |
|
|
23
|
+
| `/plugins` | A plugin system for a new CLI: `createPluginSystem({ packagePrefix, providers, communityPrefix?, configFile?, pluginOptions?, preload? })` returns a `PluginLoader` class and `resolvePackage`. `load()` imports each configured provider's package (from the working directory first, importer injectable), calls its `createPlugin(options)` and fills a registry typed by your capability map: `get(key)` is one implementation for a `single` capability and an array for a `many` one. A package may export a capability config (`{ provider, options? }`) whose preset options sit under the project's. A failing provider is recorded in `loadFailures()` and `get` rethrows its error; `load()` never throws for one. `loadProvider(tuple)` builds one provider's plugin with the options given, with no capability slot and no registry entry, for a command that works on a provider the config does not name (it throws). Also `assertPluginsResolvable`, `isModuleNotFound`, `resolvePluginPackage`, `defaultImporter` and `LoaderError`. |
|
|
24
|
+
| `/flags` | The options every command of a tool takes: `addGlobalOptions(parser, { describe?, cwd? })` declares `--dry-run`, a repeatable `--token` and `--cwd` once on the root; `tokenContext(values, report)` parses the `--token` values and reports a bad one without a stack trace; `groupMenu(parent, open)` is the hidden default command that makes a bare group (`tool repo`) do something useful; `InferArgs` types a command's handler arguments from its builder. |
|
|
25
|
+
| `/checks` | `runCheckAgainstUrl(input, opts?)` runs an HTTP check with assertions (`status_code`, `response_time`, `body`, `header`) over `fetch` and returns `{ passed, failures, requestError? }`, with no monitoring vendor involved; `connectionProbe({ provider, url?, token, verify })` is a probe that tells a network problem from a credential problem (and `describeNetworkError` words a network failure). |
|
|
26
|
+
| `/git` | `moveMajorTag({ group, version?, dryRun?, remote? })` moves a version group's major tag (`ci-v1`) to its latest stable release and force-pushes it; `runGit(args, cwd)` runs `git` without a shell. |
|
|
27
27
|
|
|
28
28
|
## Build a plugin system
|
|
29
29
|
|
package/dist/plugins.d.mts
CHANGED
|
@@ -139,6 +139,13 @@ interface PluginLoader<Caps extends CapabilityShape, Extra extends object = Reco
|
|
|
139
139
|
loadFailures(): readonly PluginLoadFailure<CapabilityKeyOf<Caps>>[];
|
|
140
140
|
/** The plugin object of each provider that was created, by provider name. */
|
|
141
141
|
plugins(): ReadonlyMap<string, LoadedPlugin<Caps, Extra>>;
|
|
142
|
+
/**
|
|
143
|
+
* Imports one provider and builds its plugin with the given options, without any capability slot: nothing is added to
|
|
144
|
+
* the registry, and the plugin is recorded in {@link PluginLoader.plugins} (replacing one of the same provider that
|
|
145
|
+
* `load()` made). Throws {@link LoaderError} when the package cannot be imported or is not a plugin, and whatever
|
|
146
|
+
* `createPlugin` throws. For a command that works on a provider the config does not name.
|
|
147
|
+
*/
|
|
148
|
+
loadProvider(tuple: ProviderTuple): Promise<LoadedPlugin<Caps, Extra>>;
|
|
142
149
|
}
|
|
143
150
|
/** The class {@link createPluginSystem} returns; extend it or construct it directly. */
|
|
144
151
|
interface PluginLoaderConstructor<Caps extends CapabilityShape, Config, Context extends object, Extra extends object = Record<never, never>, LoadOptions = undefined> {
|
package/dist/plugins.mjs
CHANGED
|
@@ -165,9 +165,18 @@ function createPluginSystem(options) {
|
|
|
165
165
|
error: err instanceof Error ? err : new Error(String(err))
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
|
+
async loadProvider(tuple) {
|
|
169
|
+
return this.instantiate("provider", tuple);
|
|
170
|
+
}
|
|
168
171
|
async loadOne(key, tuple) {
|
|
172
|
+
const factory = (await this.instantiate(`capability \`${key}\``, tuple)).capabilities[key];
|
|
173
|
+
if (typeof factory !== "function") throw new LoaderError(`\`${tuple.packageName}\` does not implement the \`${key}\` capability`);
|
|
174
|
+
return factory();
|
|
175
|
+
}
|
|
176
|
+
/** Imports the package and builds the plugin (following a capability config package to its provider). */
|
|
177
|
+
async instantiate(subject, tuple) {
|
|
169
178
|
const mod = await this.importer(tuple.packageName).catch((err) => {
|
|
170
|
-
throw new LoaderError(`failed to import \`${tuple.packageName}\` for
|
|
179
|
+
throw new LoaderError(`failed to import \`${tuple.packageName}\` for ${subject}: ${messageOf(err)}`);
|
|
171
180
|
});
|
|
172
181
|
if (isPluginModule(mod)) {
|
|
173
182
|
const plugin = mod.createPlugin(pluginOptions ? pluginOptions({
|
|
@@ -179,13 +188,11 @@ function createPluginSystem(options) {
|
|
|
179
188
|
...tuple.options
|
|
180
189
|
});
|
|
181
190
|
this.created.set(tuple.provider, plugin);
|
|
182
|
-
|
|
183
|
-
if (typeof factory !== "function") throw new LoaderError(`\`${tuple.packageName}\` does not implement the \`${key}\` capability`);
|
|
184
|
-
return factory();
|
|
191
|
+
return plugin;
|
|
185
192
|
}
|
|
186
193
|
if (isCapabilityConfigModule(mod)) {
|
|
187
194
|
const cap = mod.default;
|
|
188
|
-
return this.
|
|
195
|
+
return this.instantiate(subject, {
|
|
189
196
|
provider: cap.provider,
|
|
190
197
|
packageName: resolvePackage(cap.provider),
|
|
191
198
|
options: {
|
package/dist/testing.d.mts
CHANGED
|
@@ -12,6 +12,8 @@ interface CliRun {
|
|
|
12
12
|
timedOut: boolean;
|
|
13
13
|
/** How long the run took, from spawn to close, in milliseconds. */
|
|
14
14
|
elapsedMs: number;
|
|
15
|
+
/** How long node took to run its first line of JavaScript after the spawn, in milliseconds; -1 if it never did. */
|
|
16
|
+
startMs: number;
|
|
15
17
|
}
|
|
16
18
|
/** What one run of the CLI is given. */
|
|
17
19
|
interface RunCliOptions {
|
|
@@ -19,8 +21,10 @@ interface RunCliOptions {
|
|
|
19
21
|
config?: object | string;
|
|
20
22
|
/** Added to the controlled environment for this run. */
|
|
21
23
|
env?: Record<string, string>;
|
|
22
|
-
/** How long the run may take before it is killed. Default 60 seconds. */
|
|
24
|
+
/** How long the run may take, from the moment node starts running, before it is killed. Default 60 seconds. */
|
|
23
25
|
timeoutMs?: number;
|
|
26
|
+
/** How long node may take to start at all (the machine's launch latency, not the tool) before it is killed. Default 50 seconds. */
|
|
27
|
+
startTimeoutMs?: number;
|
|
24
28
|
}
|
|
25
29
|
/** What {@link createCliRunner} needs to run a tool's built binary. */
|
|
26
30
|
interface CliRunnerOptions {
|
|
@@ -37,6 +41,11 @@ interface CliRunnerOptions {
|
|
|
37
41
|
* A function that runs a tool's built binary in a fresh temporary directory with a controlled environment, and returns
|
|
38
42
|
* what it printed and how it exited. The environment is built from nothing: no tokens, no telemetry and no update check
|
|
39
43
|
* leak in from whoever runs the tests, and stdin is closed, so a command that wants a terminal behaves as it does in CI.
|
|
44
|
+
*
|
|
45
|
+
* Two clocks bound a run. `startTimeoutMs` bounds the wait until node runs its first line of JavaScript, and `timeoutMs`
|
|
46
|
+
* bounds the run from there on, so a machine that is slow to launch processes (an endpoint-security agent under load can
|
|
47
|
+
* hold a launch for tens of seconds, #1902) is not mistaken for a tool that hangs, and a tool that does hang is still
|
|
48
|
+
* killed after `timeoutMs`.
|
|
40
49
|
*/
|
|
41
50
|
export declare function createCliRunner(options: CliRunnerOptions): (args: string[], run?: RunCliOptions) => Promise<CliRun>;
|
|
42
51
|
/** What {@link ensureBuilt} needs to decide whether a build is current. */
|
package/dist/testing.mjs
CHANGED
|
@@ -7,32 +7,53 @@ import { fileURLToPath } from "node:url";
|
|
|
7
7
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
8
8
|
import yargs from "yargs";
|
|
9
9
|
// src/testing/cli-runner/cli-runner.ts
|
|
10
|
+
const ALIVE_PRELOAD = "try { require(\"node:fs\").writeSync(3, \"1\"); } catch {}\n";
|
|
10
11
|
/**
|
|
11
|
-
* How long one run may take by default
|
|
12
|
-
* machine running every package's tests at once, so the budget is well
|
|
13
|
-
*
|
|
12
|
+
* How long one run may take by default, from the moment node runs its first line of JavaScript. A run of the built CLI
|
|
13
|
+
* takes about a second idle and 15 s or more on a machine running every package's tests at once, so the budget is well
|
|
14
|
+
* over that and, with {@link DEFAULT_START_TIMEOUT_MS}, under the preset's test timeout (`@theholocron/vitest-config`,
|
|
15
|
+
* 120 s), which keeps this runner, the one that can say what happened, the first to give up.
|
|
14
16
|
*/
|
|
15
17
|
const DEFAULT_TIMEOUT_MS = 6e4;
|
|
16
18
|
/**
|
|
19
|
+
* How long node may take to start by default. Launching `node` was held for up to a minute on a loaded machine (#1902).
|
|
20
|
+
* This and {@link DEFAULT_TIMEOUT_MS} add up to 110 s, under the preset's 120 s test timeout.
|
|
21
|
+
*/
|
|
22
|
+
const DEFAULT_START_TIMEOUT_MS = 5e4;
|
|
23
|
+
/**
|
|
17
24
|
* A function that runs a tool's built binary in a fresh temporary directory with a controlled environment, and returns
|
|
18
25
|
* what it printed and how it exited. The environment is built from nothing: no tokens, no telemetry and no update check
|
|
19
26
|
* leak in from whoever runs the tests, and stdin is closed, so a command that wants a terminal behaves as it does in CI.
|
|
27
|
+
*
|
|
28
|
+
* Two clocks bound a run. `startTimeoutMs` bounds the wait until node runs its first line of JavaScript, and `timeoutMs`
|
|
29
|
+
* bounds the run from there on, so a machine that is slow to launch processes (an endpoint-security agent under load can
|
|
30
|
+
* hold a launch for tens of seconds, #1902) is not mistaken for a tool that hangs, and a tool that does hang is still
|
|
31
|
+
* killed after `timeoutMs`.
|
|
20
32
|
*/
|
|
21
33
|
function createCliRunner(options) {
|
|
22
34
|
return async (args, run = {}) => {
|
|
23
35
|
const dir = await mkdtemp(join(tmpdir(), options.prefix ?? "cli-"));
|
|
36
|
+
const aliveDir = await mkdtemp(join(tmpdir(), "cli-alive-"));
|
|
24
37
|
try {
|
|
25
38
|
if (run.config !== void 0) {
|
|
26
39
|
if (!options.configFile) throw new Error("this runner has no configFile, so a run cannot be given a config");
|
|
27
40
|
const body = typeof run.config === "string" ? run.config : JSON.stringify(run.config);
|
|
28
41
|
await writeFile(join(dir, options.configFile), body);
|
|
29
42
|
}
|
|
43
|
+
const alive = join(aliveDir, "alive.cjs");
|
|
44
|
+
await writeFile(alive, ALIVE_PRELOAD);
|
|
30
45
|
return await new Promise((resolve, reject) => {
|
|
31
|
-
const child = spawn(process.execPath, [
|
|
46
|
+
const child = spawn(process.execPath, [
|
|
47
|
+
"--require",
|
|
48
|
+
alive,
|
|
49
|
+
options.bin,
|
|
50
|
+
...args
|
|
51
|
+
], {
|
|
32
52
|
cwd: dir,
|
|
33
53
|
stdio: [
|
|
34
54
|
"ignore",
|
|
35
55
|
"pipe",
|
|
56
|
+
"pipe",
|
|
36
57
|
"pipe"
|
|
37
58
|
],
|
|
38
59
|
env: {
|
|
@@ -46,23 +67,34 @@ function createCliRunner(options) {
|
|
|
46
67
|
...run.env
|
|
47
68
|
}
|
|
48
69
|
});
|
|
70
|
+
const pipes = child.stdio;
|
|
49
71
|
let stdout = "";
|
|
50
72
|
let stderr = "";
|
|
51
|
-
|
|
52
|
-
|
|
73
|
+
pipes[1].on("data", (d) => stdout += d);
|
|
74
|
+
pipes[2].on("data", (d) => stderr += d);
|
|
53
75
|
const timeoutMs = run.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
54
|
-
const
|
|
76
|
+
const startTimeoutMs = run.startTimeoutMs ?? DEFAULT_START_TIMEOUT_MS;
|
|
77
|
+
const spawned = Date.now();
|
|
78
|
+
let startMs = -1;
|
|
55
79
|
let timedOut = false;
|
|
56
|
-
|
|
80
|
+
let runTimer;
|
|
81
|
+
const kill = () => {
|
|
57
82
|
timedOut = true;
|
|
58
83
|
child.kill("SIGKILL");
|
|
59
|
-
}
|
|
84
|
+
};
|
|
85
|
+
const startTimer = setTimeout(kill, startTimeoutMs);
|
|
86
|
+
pipes[3].once("data", () => {
|
|
87
|
+
startMs = Date.now() - spawned;
|
|
88
|
+
clearTimeout(startTimer);
|
|
89
|
+
runTimer = setTimeout(kill, timeoutMs);
|
|
90
|
+
});
|
|
60
91
|
child.on("error", reject);
|
|
61
92
|
child.on("close", (code, signal) => {
|
|
62
|
-
clearTimeout(
|
|
63
|
-
|
|
93
|
+
clearTimeout(startTimer);
|
|
94
|
+
clearTimeout(runTimer);
|
|
95
|
+
const elapsedMs = Date.now() - spawned;
|
|
64
96
|
if (timedOut) {
|
|
65
|
-
const note = `[cli-runner] killed after ${elapsedMs} ms (timeout ${timeoutMs} ms, ${signal}), pid ${child.pid}; stdout ${stdout.length} chars, stderr ${stderr.length} chars before this line; args: [${args.join(" ")}]`;
|
|
97
|
+
const note = `[cli-runner] ${startMs < 0 ? `killed before node started, after ${elapsedMs} ms (start timeout ${startTimeoutMs} ms, ${signal})` : `killed after ${elapsedMs} ms (timeout ${timeoutMs} ms, ${signal}; node started after ${startMs} ms)`}, pid ${child.pid}; stdout ${stdout.length} chars, stderr ${stderr.length} chars before this line; args: [${args.join(" ")}]`;
|
|
66
98
|
stderr += `\n${note}`;
|
|
67
99
|
console.error(note);
|
|
68
100
|
}
|
|
@@ -76,7 +108,8 @@ function createCliRunner(options) {
|
|
|
76
108
|
stderr,
|
|
77
109
|
code: code ?? -1,
|
|
78
110
|
timedOut,
|
|
79
|
-
elapsedMs
|
|
111
|
+
elapsedMs,
|
|
112
|
+
startMs
|
|
80
113
|
});
|
|
81
114
|
});
|
|
82
115
|
});
|
|
@@ -85,6 +118,10 @@ function createCliRunner(options) {
|
|
|
85
118
|
recursive: true,
|
|
86
119
|
force: true
|
|
87
120
|
});
|
|
121
|
+
await rm(aliveDir, {
|
|
122
|
+
recursive: true,
|
|
123
|
+
force: true
|
|
124
|
+
});
|
|
88
125
|
}
|
|
89
126
|
};
|
|
90
127
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/kyber",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.373",
|
|
4
4
|
"description": "The reusable parts of a command-line tool: terminal output, prompts, the interactive menu, the update notifier, safe handling of tokens, a test harness and the global flags.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -105,12 +105,12 @@
|
|
|
105
105
|
"typescript": "^5.9.3",
|
|
106
106
|
"vitest": "^5.1.0",
|
|
107
107
|
"yargs": "^18.1.0",
|
|
108
|
-
"@theholocron/
|
|
109
|
-
"@theholocron/datapad": "5.0.0-alpha.372",
|
|
108
|
+
"@theholocron/datapad": "5.0.0-alpha.373",
|
|
110
109
|
"@theholocron/observability": "0.7.0-alpha.2",
|
|
111
|
-
"@theholocron/
|
|
110
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.12",
|
|
111
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.12",
|
|
112
112
|
"@theholocron/vitest-config": "^8.9.0-alpha.12",
|
|
113
|
-
"@theholocron/
|
|
113
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.12"
|
|
114
114
|
},
|
|
115
115
|
"peerDependencies": {
|
|
116
116
|
"@inquirer/prompts": "^8.0.0",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"dotenv": "^17.0.0",
|
|
122
122
|
"ora": "^9.0.0",
|
|
123
123
|
"yargs": "^18.0.0",
|
|
124
|
-
"@theholocron/datapad": "^5.0.0-alpha.
|
|
124
|
+
"@theholocron/datapad": "^5.0.0-alpha.373",
|
|
125
125
|
"@theholocron/observability": "^0.7.0-alpha.2"
|
|
126
126
|
},
|
|
127
127
|
"peerDependenciesMeta": {
|