@wirecat/cli-base 0.94.0 → 0.96.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 +31 -0
- package/dist/keyring.js +10 -1
- package/dist/paths.d.ts +8 -0
- package/dist/paths.js +40 -9
- package/dist/skill/index.js +6 -1
- package/dist/standards/flags-what.js +7 -0
- package/dist/testing/sandbox.js +2 -0
- package/docs/standards/testing.md +7 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,37 @@ Versions before 0.8.0 are in the [git tags](https://github.com/WireCatLabs/cli-b
|
|
|
8
8
|
Every entry says what changed as a caller sees it, why, and what to watch for — the rules are
|
|
9
9
|
[`docs/dev/CONVENTIONS.md`](docs/dev/CONVENTIONS.md#the-changelog).
|
|
10
10
|
|
|
11
|
+
## 0.96.0 — 11.11.2026
|
|
12
|
+
|
|
13
|
+
### Changed — may break callers
|
|
14
|
+
|
|
15
|
+
- **`--from` takes a person, `--from <person>`, and is in the flag vocabulary as a target**: the one identities leave
|
|
16
|
+
(`people unlink --from`, `contacts unlink --from`) or the one who sent it (`bot search messages --from`). The unlink
|
|
17
|
+
commands now require it, and without an entry they failed `option-role`. To watch for: a command that declares
|
|
18
|
+
`--from` with another placeholder, such as `--from <who>`, now fails `flag-two-meanings`; rename it to `<person>`.
|
|
19
|
+
A baseline entry for `--from` under `option-role` turns stale and fails the lint until it is removed.
|
|
20
|
+
|
|
21
|
+
- **A test that still has the owner's real home, or reaches the real keyring, now fails even when the shared test
|
|
22
|
+
setup did not load.** Under vitest (`VITEST` in the `env` passed, or in the process when that `env` names no home),
|
|
23
|
+
`resolvePaths` and the skill commands (`~/.claude/skills`, `~/.agents/skills`, Hermes, `HERMES_HOME` included) throw
|
|
24
|
+
while `HOME` or `USERPROFILE` is the account's own, read from the user database and compared through symlinks; and
|
|
25
|
+
`systemKeyring` throws under vitest whenever the shared setup's throwing stand-in is not loaded, whatever `HOME`
|
|
26
|
+
says. A probe run as `vitest run --root <folder outside the repository>` reads no `vitest.config.ts`, so the sandbox
|
|
27
|
+
never loaded, and it wrote test accounts and runs into the owner's real data. Inside the sandbox nothing changes.
|
|
28
|
+
To watch for: a test that builds an `env` with `VITEST` and the owner's real `HOME` now throws, whatever its XDG
|
|
29
|
+
folders or `<PREFIX>_*_DIR` overrides say; an `env` without `VITEST`, such as `{ HOME: userInfo().homedir }` built to
|
|
30
|
+
find the owner's folders on purpose, is left alone.
|
|
31
|
+
|
|
32
|
+
## 0.95.0 — 09.11.2026
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- **`node-ci.yml`: re-running a failed test shard can turn `coverage` green.** `gh run rerun --failed` kept the failed
|
|
37
|
+
attempt's shard report under the same artifact name, and `coverage` merged whichever copy it downloaded last, so a
|
|
38
|
+
flaky test that passed on the re-run still failed coverage on every re-run (cli-core release #2799). The shard and
|
|
39
|
+
argv artifacts now carry the run attempt, and `coverage` takes each shard's latest attempt. A caller picks it up
|
|
40
|
+
by moving its `node-ci.yml` pin.
|
|
41
|
+
|
|
11
42
|
## 0.94.0 — 09.11.2026
|
|
12
43
|
|
|
13
44
|
### Added
|
package/dist/keyring.js
CHANGED
|
@@ -11,7 +11,16 @@ const entryClass = () => {
|
|
|
11
11
|
cached ??= require("@napi-rs/keyring").Entry;
|
|
12
12
|
return cached;
|
|
13
13
|
};
|
|
14
|
-
const
|
|
14
|
+
const STAND_IN = Symbol.for("@wirecat/cli-base/testing/keyring-stand-in");
|
|
15
|
+
// The keyring is reached over D-Bus or the OS keychain whatever HOME says, so a test without the shared setup's
|
|
16
|
+
// stand-in is refused outright. The stand-in itself goes first: it records the reach that `Credentials` would
|
|
17
|
+
// otherwise swallow by falling back to a file.
|
|
18
|
+
const entry = (service, account) => {
|
|
19
|
+
const Entry = entryClass();
|
|
20
|
+
if (!(STAND_IN in Entry) && process.env.VITEST !== undefined)
|
|
21
|
+
throw new Error("a test reached the real OS keyring without the test setup; pass memoryKeyring()");
|
|
22
|
+
return new Entry(service, account, ENTRY_OPTIONS);
|
|
23
|
+
};
|
|
15
24
|
export const systemKeyring = {
|
|
16
25
|
// Returns null for an absent entry rather than throwing — measured against @napi-rs/keyring
|
|
17
26
|
// on 2026-09-13, and the difference matters: a throw here means the keychain is unusable.
|
package/dist/paths.d.ts
CHANGED
|
@@ -24,6 +24,14 @@ export declare const PATH_KINDS: readonly ["config", "state", "cache"];
|
|
|
24
24
|
* `env`, never the global one, so a test can point every directory at a temp folder.
|
|
25
25
|
*/
|
|
26
26
|
export declare const defaultPaths: ({ appName, env, platform }: PathsOptions) => Paths;
|
|
27
|
+
/**
|
|
28
|
+
* Under vitest, throws while `env` still has the account's own home. The test sandbox lives in `setupFiles`, and a run
|
|
29
|
+
* that skips the config (`vitest --root` outside the repository) once wrote test accounts and runs into the owner's real
|
|
30
|
+
* data (2026-10-26). The `env` passed in says whether this is a test: a caller that builds `{ HOME: <owner's home> }`
|
|
31
|
+
* on purpose, to find the owner's folders, carries no `VITEST`. An `env` that names no home falls back to the process's
|
|
32
|
+
* own, so the process's own `VITEST` decides then.
|
|
33
|
+
*/
|
|
34
|
+
export declare const refuseOwnerHomeInTests: (env?: Readonly<Record<string, string | undefined>>, platform?: NodeJS.Platform, account?: () => string | undefined) => void;
|
|
27
35
|
/**
|
|
28
36
|
* Each directory is overridable by environment variable, which is what makes a test — and a
|
|
29
37
|
* throwaway profile — possible without touching the real ones.
|
package/dist/paths.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
1
2
|
import { homedir, userInfo } from "node:os";
|
|
2
3
|
import { join, posix, win32 } from "node:path";
|
|
3
4
|
export const PATH_KINDS = ["config", "state", "cache"];
|
|
@@ -26,12 +27,50 @@ export const defaultPaths = ({ appName, env = process.env, platform = process.pl
|
|
|
26
27
|
cache: posix.join(env.XDG_CACHE_HOME || posix.join(home, ".cache"), appName),
|
|
27
28
|
};
|
|
28
29
|
};
|
|
30
|
+
const accountHome = () => {
|
|
31
|
+
try {
|
|
32
|
+
return userInfo().homedir;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const sameFolder = (a, b, platform) => {
|
|
39
|
+
if ((platform === "win32" ? win32 : posix).relative(a, b) === "")
|
|
40
|
+
return true;
|
|
41
|
+
try {
|
|
42
|
+
return realpathSync.native(a) === realpathSync.native(b);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Under vitest, throws while `env` still has the account's own home. The test sandbox lives in `setupFiles`, and a run
|
|
50
|
+
* that skips the config (`vitest --root` outside the repository) once wrote test accounts and runs into the owner's real
|
|
51
|
+
* data (2026-10-26). The `env` passed in says whether this is a test: a caller that builds `{ HOME: <owner's home> }`
|
|
52
|
+
* on purpose, to find the owner's folders, carries no `VITEST`. An `env` that names no home falls back to the process's
|
|
53
|
+
* own, so the process's own `VITEST` decides then.
|
|
54
|
+
*/
|
|
55
|
+
export const refuseOwnerHomeInTests = (env = process.env, platform = process.platform, account = accountHome) => {
|
|
56
|
+
const named = [env.HOME, env.USERPROFILE].filter((home) => Boolean(home));
|
|
57
|
+
if ((named.length > 0 ? env.VITEST : (env.VITEST ?? process.env.VITEST)) === undefined)
|
|
58
|
+
return;
|
|
59
|
+
const owner = account();
|
|
60
|
+
if (owner === undefined)
|
|
61
|
+
return;
|
|
62
|
+
for (const home of named.length > 0 ? named : [homedir()])
|
|
63
|
+
if (sameFolder(owner, home, platform))
|
|
64
|
+
throw new Error(`a test is running with the owner's real home (${home}); load @wirecat/cli-base/testing/setup ` +
|
|
65
|
+
"(`vitest --root` outside the repository skips it) or give the test a HOME of its own");
|
|
66
|
+
};
|
|
29
67
|
/**
|
|
30
68
|
* Each directory is overridable by environment variable, which is what makes a test — and a
|
|
31
69
|
* throwaway profile — possible without touching the real ones.
|
|
32
70
|
*/
|
|
33
71
|
export const resolvePaths = (options) => {
|
|
34
|
-
const { appName, prefix, env = process.env } = options;
|
|
72
|
+
const { appName, prefix, env = process.env, platform = process.platform } = options;
|
|
73
|
+
refuseOwnerHomeInTests(env, platform);
|
|
35
74
|
const base = defaultPaths(options);
|
|
36
75
|
return {
|
|
37
76
|
config: env[overrideName(appName, prefix, "config")] ?? base.config,
|
|
@@ -41,14 +80,6 @@ export const resolvePaths = (options) => {
|
|
|
41
80
|
};
|
|
42
81
|
/** Whether any of the three directories came from the environment rather than the OS convention. */
|
|
43
82
|
export const pathsAreOverridden = ({ appName, prefix, env = process.env }) => PATH_KINDS.some((kind) => env[overrideName(appName, prefix, kind)] !== undefined);
|
|
44
|
-
const accountHome = () => {
|
|
45
|
-
try {
|
|
46
|
-
return userInfo().homedir;
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
83
|
/**
|
|
53
84
|
* Whether `HOME` or an XDG (or Windows) folder in `env` puts the default folders anywhere but under the account's own
|
|
54
85
|
* home, which comes from the user database: `os.homedir()` returns `$HOME` and would miss exactly this. An account with
|
package/dist/skill/index.js
CHANGED
|
@@ -13,9 +13,13 @@ import crossSpawn from "cross-spawn";
|
|
|
13
13
|
import { annotate } from "../commands/index.js";
|
|
14
14
|
import { CliError } from "../errors.js";
|
|
15
15
|
import { executableEnvironment, executableOnPath } from "../executable.js";
|
|
16
|
+
import { refuseOwnerHomeInTests } from "../paths.js";
|
|
16
17
|
import { CHECK_EVERY_MS, isNewer, readNoticeState, writeUpdateState } from "../update/index.js";
|
|
17
18
|
export const SKILL_TARGETS = ["claude", "agents"];
|
|
18
|
-
const homeOf = (env) =>
|
|
19
|
+
const homeOf = (env) => {
|
|
20
|
+
refuseOwnerHomeInTests(env);
|
|
21
|
+
return env.HOME || env.USERPROFILE || homedir();
|
|
22
|
+
};
|
|
19
23
|
/** `~/.claude/skills` is Claude Code's; `~/.agents/skills` is read by Codex, Gemini CLI and OpenClaw. */
|
|
20
24
|
export const skillPath = (target, appName, env) => join(homeOf(env), target === "claude" ? ".claude" : ".agents", "skills", appName, "SKILL.md");
|
|
21
25
|
const FRONTMATTER = /^---(\r?\n)([\s\S]*?\r?\n)?---(\r?\n|$)/;
|
|
@@ -119,6 +123,7 @@ const runProgram = (file, args, env) => {
|
|
|
119
123
|
};
|
|
120
124
|
/** `HERMES_HOME`, else the folder Hermes itself defaults to. */
|
|
121
125
|
export const hermesHome = (env, platform = process.platform) => {
|
|
126
|
+
refuseOwnerHomeInTests(env, platform);
|
|
122
127
|
const set = env.HERMES_HOME?.trim();
|
|
123
128
|
if (set)
|
|
124
129
|
return set;
|
|
@@ -313,6 +313,13 @@ export const WHAT_FLAGS = [
|
|
|
313
313
|
type: "list",
|
|
314
314
|
meaning: "the agents to install for, comma-separated",
|
|
315
315
|
},
|
|
316
|
+
{
|
|
317
|
+
name: "--from",
|
|
318
|
+
value: "<person>",
|
|
319
|
+
role: "target",
|
|
320
|
+
type: "id",
|
|
321
|
+
meaning: "a person: the one identities leave, or the one who sent it; a search takes it repeated for any of several",
|
|
322
|
+
},
|
|
316
323
|
{
|
|
317
324
|
name: "--from-dir",
|
|
318
325
|
value: "<dir>",
|
package/dist/testing/sandbox.js
CHANGED
|
@@ -111,6 +111,8 @@ class ThrowingEntry {
|
|
|
111
111
|
throw error;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
+
// `keyring.ts` lets the stand-in throw first, so the reach is recorded even when the test put the owner's HOME back.
|
|
115
|
+
Object.assign(ThrowingEntry, { [Symbol.for("@wirecat/cli-base/testing/keyring-stand-in")]: true });
|
|
114
116
|
/** The stack of the first reach of the keyring stand-in since the last call, and forgets it. */
|
|
115
117
|
export const takeKeyringReach = () => {
|
|
116
118
|
const stack = reached;
|
|
@@ -29,7 +29,7 @@ and which run after merge is in [CI](ci.md).
|
|
|
29
29
|
### WC-TEST-1 · Point every path a test could write at a temporary directory
|
|
30
30
|
|
|
31
31
|
- **Why:** one test that falls back to a default path writes into the owner's config, state, cache or store.
|
|
32
|
-
- **Enforced by:** `src/testing/sandbox.test.ts`.
|
|
32
|
+
- **Enforced by:** `src/testing/sandbox.test.ts` · `src/paths.test.ts`.
|
|
33
33
|
- **Example:** a CLI adopts the shared setup with one line in `vitest.config.ts`:
|
|
34
34
|
`setupFiles: ["@wirecat/cli-base/testing/setup"]`. It holds for every test file, including the next one. Each
|
|
35
35
|
file gets a fresh directory: `TMPDIR`, `TMP`, `TEMP`, `HOME`, `USERPROFILE`, the XDG and Windows folders, and
|
|
@@ -41,7 +41,9 @@ and which run after merge is in [CI](ci.md).
|
|
|
41
41
|
sandboxed home stays within the 104-byte limit. When the file is done, after its own hooks have closed their
|
|
42
42
|
resources, the setup restores the variables and removes the directory; when the file fails while loading or its
|
|
43
43
|
own `afterAll` throws, vitest skips that step and the directory is removed as the worker ends. A CLI's own setup
|
|
44
|
-
file, listed after the shared one, adds only what is its own, such as a default profile.
|
|
44
|
+
file, listed after the shared one, adds only what is its own, such as a default profile. Behind the sandbox,
|
|
45
|
+
`resolvePaths` and the skill commands throw under vitest while `HOME` is the account's own, so a run that skips
|
|
46
|
+
`setupFiles` (`vitest run --root` outside the repository) fails instead of writing into the owner's folders.
|
|
45
47
|
- **Exceptions:** keep coverage reports and debug traces outside the sandbox, with bounded retention. Never clean
|
|
46
48
|
another session's scratch directory as test teardown.
|
|
47
49
|
- **Applies to:** all CLIs and the shared packages. cli-base, cli-core, every CLI and cli-template load the shared
|
|
@@ -51,11 +53,12 @@ and which run after merge is in [CI](ci.md).
|
|
|
51
53
|
|
|
52
54
|
- **Why:** the owner's tokens live in the real keychain, and a messenger's device keys in a file of their own; one
|
|
53
55
|
test that forgets an option would read or write the real one.
|
|
54
|
-
- **Enforced by:** `src/keyring.test.ts` · `whatsapp-cli: src/testing/sandbox.test.ts`.
|
|
56
|
+
- **Enforced by:** `src/keyring.test.ts` · `src/testing/sandbox.test.ts` · `whatsapp-cli: src/testing/sandbox.test.ts`.
|
|
55
57
|
- **Example:** every test passes `memoryKeyring()` from `@wirecat/cli-base/testing`. The shared setup
|
|
56
58
|
(`@wirecat/cli-base/testing/setup`, [WC-TEST-1](#wc-test-1--point-every-path-a-test-could-write-at-a-temporary-directory))
|
|
57
59
|
also replaces `@napi-rs/keyring` with a module that throws, so a forgotten option fails the test instead of
|
|
58
|
-
reaching the keychain, and `src/keyring.test.ts` asserts that `systemKeyring` throws under it.
|
|
60
|
+
reaching the keychain, and `src/keyring.test.ts` asserts that `systemKeyring` throws under it. Without the shared
|
|
61
|
+
setup, `systemKeyring` itself throws under vitest.
|
|
59
62
|
A credential store that is a file, such as WhatsApp's linked-device keys in `private.db`, resolves under the
|
|
60
63
|
sandbox's state directory, and a sandbox test asserts that its path is inside the temporary root, as wa's does.
|
|
61
64
|
- **Exceptions:** none. Until a CLI adopts the shared setup, its sandbox does not replace `@napi-rs/keyring`; tg and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.96.0",
|
|
4
4
|
"description": "The parts every command line tool needs: output modes, terminal rendering, error model, exit codes, credentials, clocks",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|