@serfab/cadre-host 0.11.0 → 0.13.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 +406 -296
- package/dist/bin/host.d.ts +11 -7
- package/dist/bin/host.js +40 -12
- package/dist/bin/host.js.map +1 -1
- package/dist/installer/config.d.ts +4 -4
- package/dist/installer/config.js +5 -39
- package/dist/installer/config.js.map +1 -1
- package/dist/installer/identity.d.ts +8 -1
- package/dist/installer/identity.js +8 -1
- package/dist/installer/identity.js.map +1 -1
- package/dist/orchestrator/host-process-orchestrator.d.ts +2 -2
- package/dist/orchestrator/host-process-orchestrator.js +14 -4
- package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
- package/dist/server/routes/bootstrap-node-validation.d.ts +96 -0
- package/dist/server/routes/bootstrap-node-validation.js +178 -0
- package/dist/server/routes/bootstrap-node-validation.js.map +1 -0
- package/dist/server/routes/grants.js +8 -25
- package/dist/server/routes/grants.js.map +1 -1
- package/dist/server/routes/provision-request-validation.d.ts +45 -0
- package/dist/server/routes/provision-request-validation.js +97 -0
- package/dist/server/routes/provision-request-validation.js.map +1 -0
- package/dist/server/settings-store.d.ts +1 -1
- package/dist/server/settings-store.js +5 -1
- package/dist/server/settings-store.js.map +1 -1
- package/package.json +5 -4
- package/src/__tests__/cli.smoke.test.ts +8 -3
- package/src/__tests__/global-setup.ts +9 -4
- package/src/__tests__/orchestrator-node-identity.test.ts +204 -204
- package/src/__tests__/orchestrator.test.ts +951 -951
- package/src/bin/__tests__/cli-reference.test.ts +167 -0
- package/src/bin/host.ts +1326 -1299
- package/src/donation/__tests__/donation-service.test.ts +1068 -1068
- package/src/donation/__tests__/donation-supervisor.test.ts +510 -510
- package/src/donation/__tests__/fake-orchestrator.test.ts +168 -168
- package/src/installer/__tests__/config.test.ts +134 -112
- package/src/installer/config.ts +5 -43
- package/src/installer/identity.ts +8 -1
- package/src/nat/__tests__/nat-service.test.ts +515 -497
- package/src/orchestrator/host-process-orchestrator.ts +1143 -1133
- package/src/server/__tests__/bootstrap-node-validation.test.ts +134 -0
- package/src/server/__tests__/grants-route.test.ts +326 -263
- package/src/server/__tests__/settings-route.test.ts +8 -7
- package/src/server/routes/bootstrap-node-validation.ts +187 -0
- package/src/server/routes/grants.ts +9 -26
- package/src/server/routes/provision-request-validation.ts +105 -0
- package/src/server/settings-store.ts +41 -37
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drift guard for the README's `## CLI reference` section.
|
|
3
|
+
*
|
|
4
|
+
* The section is hand-maintained prose, one `### ` heading per command, and
|
|
5
|
+
* nothing used to check it against the commander program in `../host.ts` — so
|
|
6
|
+
* the whole `cadre-host push` group shipped undocumented. This test compares
|
|
7
|
+
* the two in both directions.
|
|
8
|
+
*
|
|
9
|
+
* Scope is deliberately narrow: **presence of a heading only**. A heading's
|
|
10
|
+
* command path must name a real command, and every leaf command must have a
|
|
11
|
+
* heading. The flag list inside a heading is *not* validated — doing so would
|
|
12
|
+
* turn a wording tweak into a red build for no correctness gain.
|
|
13
|
+
*
|
|
14
|
+
* NOTE: a heading advertising a flag the CLI no longer accepts therefore slips
|
|
15
|
+
* through; if that drift is ever observed in practice, compare the bracketed
|
|
16
|
+
* tokens against `cmd.options` rather than widening the parse.
|
|
17
|
+
*
|
|
18
|
+
* NOTE: every `### ` heading inside the section must be a command reference —
|
|
19
|
+
* the malformed-heading assertion is a hard failure, not a skip. Explanatory
|
|
20
|
+
* prose belongs in the section preamble or under a different `## ` section.
|
|
21
|
+
*
|
|
22
|
+
* Importing `../host.js` is inert: its module scope only builds the commander
|
|
23
|
+
* tree and reads `package.json` for `.version()`. Nothing spawns, binds, or
|
|
24
|
+
* exits until an action fires, and `parseAsync()` is gated behind an
|
|
25
|
+
* entry-point check. The counter-guard for that gate is
|
|
26
|
+
* `src/__tests__/cli.smoke.test.ts`, which spawns `dist/bin/host.js --help` as
|
|
27
|
+
* a child process — run `yarn workspace @serfab/cadre-host build:server`
|
|
28
|
+
* before the suite so it checks the current source.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { readFileSync } from 'node:fs';
|
|
32
|
+
import { fileURLToPath } from 'node:url';
|
|
33
|
+
import { dirname, resolve } from 'node:path';
|
|
34
|
+
import { describe, it, expect } from 'vitest';
|
|
35
|
+
import type { Command } from 'commander';
|
|
36
|
+
|
|
37
|
+
import { program } from '../host.js';
|
|
38
|
+
|
|
39
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
40
|
+
const packageRoot = resolve(here, '..', '..', '..');
|
|
41
|
+
const readmePath = resolve(packageRoot, 'README.md');
|
|
42
|
+
const packageJsonPath = resolve(packageRoot, 'package.json');
|
|
43
|
+
|
|
44
|
+
/** Commander's implicit `help [command]` is never documented in the README. */
|
|
45
|
+
const IMPLICIT_HELP = 'help';
|
|
46
|
+
|
|
47
|
+
interface CommandNode {
|
|
48
|
+
/** Space-joined path below `cadre-host`, e.g. `push fcm`, `nat ddns set`. */
|
|
49
|
+
path: string;
|
|
50
|
+
/** True when the command is a *visible leaf* — no subcommands, not hidden. */
|
|
51
|
+
requiresHeading: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Walk the commander tree, collecting every command's path.
|
|
56
|
+
*
|
|
57
|
+
* `visible` tracks whether the command is reachable in `--help` output:
|
|
58
|
+
* a `.hidden()` command (or anything under one) is *allowed* a README heading
|
|
59
|
+
* but never *required* to have one, so hiding a command doesn't force a doc
|
|
60
|
+
* edit in the same commit.
|
|
61
|
+
*/
|
|
62
|
+
function collectCommands(cmd: Command, prefix: string[] = [], visible = true): CommandNode[] {
|
|
63
|
+
const visibleChildren = new Set(cmd.createHelp().visibleCommands(cmd));
|
|
64
|
+
const out: CommandNode[] = [];
|
|
65
|
+
for (const child of cmd.commands) {
|
|
66
|
+
if (child.name() === IMPLICIT_HELP) continue;
|
|
67
|
+
const path = [...prefix, child.name()];
|
|
68
|
+
const childVisible = visible && visibleChildren.has(child);
|
|
69
|
+
const subcommands = child.commands.filter((c) => c.name() !== IMPLICIT_HELP);
|
|
70
|
+
out.push({ path: path.join(' '), requiresHeading: subcommands.length === 0 && childVisible });
|
|
71
|
+
out.push(...collectCommands(child, path, childVisible));
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface ReadmeHeading {
|
|
77
|
+
/** The raw `### ` line, for failure messages. */
|
|
78
|
+
line: string;
|
|
79
|
+
/** Space-joined command path below `cadre-host`, or null when unparseable. */
|
|
80
|
+
path: string | null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Slice the README between `## CLI reference` and the next `## ` heading, and
|
|
85
|
+
* return every `### ` heading found there.
|
|
86
|
+
*
|
|
87
|
+
* Throws when the section is missing rather than returning an empty list — an
|
|
88
|
+
* absent or renamed section must fail loudly, not pass vacuously.
|
|
89
|
+
*/
|
|
90
|
+
function readCliReferenceHeadings(): ReadmeHeading[] {
|
|
91
|
+
// Split on /\r?\n/ — this repo is developed on Windows and a bare \n split
|
|
92
|
+
// leaves a \r glued to the end of every heading.
|
|
93
|
+
const lines = readFileSync(readmePath, 'utf8').split(/\r?\n/);
|
|
94
|
+
const start = lines.findIndex((l) => l.trim() === '## CLI reference');
|
|
95
|
+
if (start === -1) {
|
|
96
|
+
throw new Error(`No "## CLI reference" heading in ${readmePath} — was the section renamed or removed?`);
|
|
97
|
+
}
|
|
98
|
+
// The section ends at the next `## ` heading. Anchor on `^## ` rather than a
|
|
99
|
+
// literal title: the following heading contains backticks today.
|
|
100
|
+
const rest = lines.slice(start + 1);
|
|
101
|
+
const relativeEnd = rest.findIndex((l) => /^## /.test(l));
|
|
102
|
+
const section = relativeEnd === -1 ? rest : rest.slice(0, relativeEnd);
|
|
103
|
+
|
|
104
|
+
return section.filter((l) => l.startsWith('### ')).map((line) => ({ line, path: parseHeading(line) }));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Extract the command path from a heading of the shape
|
|
109
|
+
* ``### `cadre-host <path...> [flags]` ``.
|
|
110
|
+
*
|
|
111
|
+
* Returns null when the heading doesn't match — malformed headings are
|
|
112
|
+
* reported as a failure, never silently skipped, because silent skipping is
|
|
113
|
+
* exactly how the section rots.
|
|
114
|
+
*/
|
|
115
|
+
function parseHeading(line: string): string | null {
|
|
116
|
+
const code = /^###\s+`([^`]+)`\s*$/.exec(line)?.[1];
|
|
117
|
+
if (!code) return null;
|
|
118
|
+
const tokens = code.trim().split(/\s+/);
|
|
119
|
+
if (tokens[0] !== 'cadre-host') return null;
|
|
120
|
+
const path: string[] = [];
|
|
121
|
+
for (const token of tokens.slice(1)) {
|
|
122
|
+
if (token.startsWith('<') || token.startsWith('[') || token.startsWith('-')) break;
|
|
123
|
+
path.push(token);
|
|
124
|
+
}
|
|
125
|
+
return path.length > 0 ? path.join(' ') : null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
describe('README CLI reference matches the commander tree', () => {
|
|
129
|
+
const commands = collectCommands(program);
|
|
130
|
+
const headings = readCliReferenceHeadings();
|
|
131
|
+
const documented = new Set(headings.map((h) => h.path).filter((p): p is string => p !== null));
|
|
132
|
+
|
|
133
|
+
it('has a heading for every leaf command', () => {
|
|
134
|
+
const missing = commands
|
|
135
|
+
.filter((c) => c.requiresHeading && !documented.has(c.path))
|
|
136
|
+
.map((c) => `cadre-host ${c.path}`);
|
|
137
|
+
expect(
|
|
138
|
+
missing,
|
|
139
|
+
`Commands with no "### " heading under "## CLI reference" in ${readmePath}:\n ${missing.join('\n ')}`,
|
|
140
|
+
).toEqual([]);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('has no heading for a command that does not exist', () => {
|
|
144
|
+
const known = new Set(commands.map((c) => c.path));
|
|
145
|
+
const ghosts = [...documented].filter((p) => !known.has(p)).map((p) => `cadre-host ${p}`);
|
|
146
|
+
expect(
|
|
147
|
+
ghosts,
|
|
148
|
+
`Headings under "## CLI reference" in ${readmePath} naming commands the CLI does not accept:\n ${ghosts.join('\n ')}`,
|
|
149
|
+
).toEqual([]);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('has no malformed headings in the section', () => {
|
|
153
|
+
const malformed = headings.filter((h) => h.path === null).map((h) => h.line);
|
|
154
|
+
expect(
|
|
155
|
+
malformed,
|
|
156
|
+
'Headings under "## CLI reference" must have the shape "### `cadre-host <path...> [flags]`":\n ' +
|
|
157
|
+
malformed.join('\n '),
|
|
158
|
+
).toEqual([]);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('CLI version', () => {
|
|
163
|
+
it('reports the version from package.json', () => {
|
|
164
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as { version: string };
|
|
165
|
+
expect(program.version()).toBe(pkg.version);
|
|
166
|
+
});
|
|
167
|
+
});
|