Skip to content

Commit 2b752aa

Browse files
fix(cli)!: os serve asks the multi-node gate about a topology declared by OS_EXPECT_MULTI_NODE=true (#31750)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi98pnQTATbhdKpMadAsFvNFN)_ Fixes #31719 Clause-②: no (narrowing) Metadata-protocol: none ## 维护者速读 - 改了什么:`os serve` 问多节点门禁时,先用 `declaresMultiNode` 判断是否声明了多节点(两种写法都认);只写 `OS_EXPECT_MULTI_NODE=true`、没给副本数时,按 2 个节点去问门禁。容量受限的门禁提示在这种“没给数量”的情况下不再编造副本数,改为点名 `OS_EXPECT_MULTI_NODE=true`;文档里“门禁拒绝只会降级、不会失败”的错误说法一并改正。 - 为什么改:以前门禁只看 `OS_CLUSTER_REPLICAS`,只写 `OS_EXPECT_MULTI_NODE=true` 的部署被当成单节点放行,开源版没有门禁也能跑多节点;同一拓扑换一种写法就被拒。 - 风险与回滚:这是收紧——只写 `OS_EXPECT_MULTI_NODE=true`、用远程集群驱动、又没注册门禁的部署,升级后启动会被拒。回滚就是回退这一个提交。 - 先看:`packages/cli/src/commands/serve.ts` 门禁调用那几行(`__countUnknown` / `__requestedNodes`)和 `formatMultiNodeCapAdvisory`;`packages/cli/test/serve-multi-node-gate-declaration.integration.test.ts`。 - 两分钟验证:`pnpm --filter @objectstack/cli exec vitest run --project integration test/serve-multi-node-gate-declaration.integration.test.ts`,预期 4 个用例全过。 - 需要你做的:无,席位落地。 ## What changes `packages/cli/src/commands/serve.ts`, gate call region only. The gate is now asked about the topology `declaresMultiNode(process.env)` reads (the split-brain guard's predicate, from the same lazily loaded `@objectstack/service-cluster` namespace `checkMultiNodeAllowed` comes from). There is no second parse of either spelling in `serve.ts`: the count spelling is asked through the same predicate, `declaresMultiNode({ OS_CLUSTER_REPLICAS })`, only to learn whether a count was given. The refusal line is byte-identical. | Declaration | Asked as | Before | |:---|:---|:---| | none (`OS_CLUSTER_REPLICAS` unset / 0 / 1) | `Number(OS_CLUSTER_REPLICAS)`, unchanged | same | | `OS_CLUSTER_REPLICAS=N` (N > 1), with or without `OS_EXPECT_MULTI_NODE` | N, unchanged | same | | `OS_EXPECT_MULTI_NODE=true`, no count | **2** | `NaN`, read as "not declared" | ## The count for "declared, count unknown": 2 Measured on `multi-node-gate.ts` at the base (35a9c69). `checkMultiNodeAllowed(requested)` normalizes `requested` through `normalizeCount`: `undefined`, `NaN`, any non-finite value and any value ≤ 0 become "not declared"; 1 is single-node. With no gate registered it refuses only when the normalized count is > 1. So `NaN` / `undefined` / `Infinity` / 1 all read as "not declared" and are allowed, which is the defect. 2 is the smallest value the gate reads as declared multi-node. - No gate (open core): 2 is refused with `MULTI_NODE_NO_GATE_REASON`, the same as `OS_CLUSTER_REPLICAS=2`. - A registered gate is asked `allowMultiNode(2)`. An uncapped allowing gate (the EE gate returns a bare `{ allowed, reason }`) admits it. A cap-aware gate is asked about the fewest nodes a multi-node topology can be. - Telemetry (`describeMultiNodeCapTelemetry`) still reads `OS_CLUSTER_REPLICAS` itself, so no `cluster_declared_nodes` series is made from this 2. The gate's signature in service-cluster is unchanged; no spec change. ## The cap advisory for an uncounted declaration (seat ruling) That 2 is the call site's, not the operator's, so it must not reach the licensed-cap advisory as a count they wrote. `formatMultiNodeCapAdvisory` takes a second, required argument, `{ countDeclared: boolean }`, passed from the call site as `!__countUnknown`. The formatter re-reads nothing. With `countDeclared: false` (only `OS_EXPECT_MULTI_NODE=true`, and a cap-aware gate admits fewer than 2) it prints: ``` [cluster] licensed node cap exceeded: the licence admits 1 node(s), but OS_EXPECT_MULTI_NODE=true declares a multi-node topology without a replica count. [cluster] This cap is ADVISORY and is not enforced yet: nothing is refused, and every replica will still join the cluster. [cluster] Run at most 1 replica(s) (or set OS_CLUSTER_REPLICAS to the count you run), or raise the licensed node limit. ``` There is no declared count, no "N beyond the cap" and no "all N replicas". The counted case (`countDeclared: true`, every case `os serve` produced before this PR) is byte-identical. This edit is outside the gate call region (the formatter in `serve.ts`), as the seat ruled. `content/docs/kernel/cluster.mdx`: the sentence that a gate denial makes `os serve` downgrade "rather than failing" now says the remote driver is dropped for the in-memory one, which is a downgrade only when no multi-node topology is declared; with one declared (either spelling) the split-brain guard refuses the boot. It also says a declared topology is denied when no gate is registered. ## Tests - New `packages/cli/test/serve-multi-node-gate-declaration.integration.test.ts`: four real `os serve` boots. The app's `@objectstack/service-cluster` re-exports the framework's real ESM entry, so the gate and `declaresMultiNode` are the shipped code. The app's `@objectstack/service-cluster-redis` registers a `redis` driver that delegates to `memory`, so no Redis server is needed. 1. `OS_EXPECT_MULTI_NODE=true` + redis + no gate → the gate refuses with its own no-gate reason, and the split-brain guard refuses the in-process fallback; no ready banner. 2. CONTROL: single node + redis + no gate → boots, no gate line. 3. CONTROL: `OS_CLUSTER_REPLICAS=2` + redis + no gate → refused, as before. 4. CONTROL: `OS_EXPECT_MULTI_NODE=true` + redis + a registered gate that admits → boots (`OS_ALLOW_MEMORY_CLUSTER_MULTINODE=true`, because the stand-in driver is honestly in-process); the gate prints that it was asked for 2. - The file is named `.integration.test.ts` so it runs in the per-PR integration tier; `*.e2e.test.ts` runs nightly only. It carries `// test-budget: 40 — spawns the real producer once per single-cause fixture`, from a local reading of 29.04 s (no CI reading yet). Forced test edits (named): - `packages/cli/src/commands/serve-multi-node-cap-advisory.pin.test.ts` "passes the operator-declared replica count": the regex pinned the literal `checkMultiNodeAllowed(Number(process.env.OS_CLUSTER_REPLICAS))`. It now pins the `__countUnknown` expression (both `declaresMultiNode` calls), `__requestedNodes = __countUnknown ? 2 : Number(process.env.OS_CLUSTER_REPLICAS)`, the `checkMultiNodeAllowed(__requestedNodes)` call, and that no code in `serve.ts` reads `process.env.OS_EXPECT_MULTI_NODE`. A new case pins the call site passing `{ countDeclared: !__countUnknown }` and the required second parameter. - `packages/cli/src/commands/serve-multi-node-cap-advisory.test.ts`: every existing call passes `COUNTED` (the expected text is unchanged). Four new cases pin the uncounted text byte for byte, that it prints no declared count, excess or "all N replicas", that the same verdict with `COUNTED` keeps the counted text, and that the uncounted declaration is silent wherever the counted one is. The file gains module-top side-effect imports, because `check:test-source-alias` judges an edited test file whose source reaches dynamic `import()`s. - `packages/cli/test/serve-cluster-driver-diagnosis.e2e.test.ts` and `packages/cli/test/serve-app-anchored-optional-import.e2e.test.ts`: their stand-in `@objectstack/service-cluster` gains `declaresMultiNode() { return false; }`, because `serve` now calls it. The diagnosis file's vacuity guard ("varies exactly one slot") moves the shared prefix to include it. ## Acceptance notes - In the boot test the red leg on main also ends in the split-brain guard's refusal. That is a fixture fact: the stand-in driver is in-process. With a real Redis driver, main booted multi-node (the card's reach). The assertion that separates main from the fix is the gate's own refusal line. ## Verification <details><summary>Red on main, green on the fix, ablation</summary> - Green at 1ae7d5f (serve.ts as in head): `vitest run --project integration test/serve-multi-node-gate-declaration.integration.test.ts` → Test Files 1 passed, Tests 4 passed (tests 29.04 s); lock VERDICT command-exit 0. - Red on main: serve.ts restored from 35a9c69 in the working tree, same command → Tests 2 failed | 2 passed. `× REFUSES OS_EXPECT_MULTI_NODE=true …` (`expected … to contain '[cluster] multi-node not authorized (…'`), and `× CONTROL: a registered gate …` (`expected … to contain '[fixture] multi-node gate asked for 2'`; main asked with `undefined`). Both CONTROLs for single node and `OS_CLUSTER_REPLICAS=2` passed on main. Restore proven: `git diff HEAD` empty and blob == HEAD. - Ablation A1 through `scripts/ablation-replace.mjs`: `? 2` → `? 1 // ABLATION-A1` (anchor 1 → 0, blob ecf1ee2 → 457b8d187bd2) → the same two cases red, Tests 2 failed | 2 passed; restored, blob == HEAD, `git diff HEAD` empty. No rebuild: `runServe` spawns `bin/run-dev.js`, which runs `src/` through tsx. - Ablation B1: ` if (!declaration.countDeclared) {` → ` if (false as boolean) { // ABLATION-B1` (anchor 1 → 0, blob 91c4eba → 9a508e46c8f5) → `× names OS_EXPECT_MULTI_NODE and prints no count …` and `× ⚠️ never prints the 2 serve asked about …`, Tests 2 failed | 19 passed; restored, blob == HEAD, `git diff HEAD` empty. - Ablation B2: the call site's `{ countDeclared: !__countUnknown }` → `{ countDeclared: true /* ABLATION-B2 */ }` (blob 91c4eba → 13586c3aa1ba) → `× tells the cap advisory whether the count the gate saw is one the operator wrote`, Tests 1 failed | 20 passed; restored, blob == HEAD. </details> <details><summary>Package checks and gates</summary> Final head 9a7ee97 (round 2 on top of ed64040; no new main merge, serve.ts is touched by no open sibling). - On 9a7ee97: `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` → 102 families (the docs line adds families), every one exit 0. `--ran` reconciliation: "102 derived famil(ies) accounted for — 102 run, 0 NOT-MEASURED (a DERIVED zero)". The first pass on 29970f4 had one red, `check:test-source-alias` on the edited advisory test; 9a7ee97 adds the module-top imports it names. - On 9a7ee97: `pnpm --filter @objectstack/cli typecheck` → exit 0. Advisory test + pin test → Tests 21 passed. `eslint --no-inline-config` on the touched cli files → exit 0. - On 29970f4 (9a7ee97 differs only by test-file imports): `turbo run build --filter='./packages/**'` exit 0. New integration file → Tests 4 passed. `pnpm --filter @objectstack/cli exec vitest run --project unit` → Test Files 407 passed (407), Tests 5780 passed (5780). - Dogfood battery on 29970f4: `pnpm --filter @objectstack/dogfood test` under the lock → VERDICT command-exit 0, Test Files 440 passed / 3 skipped (443), Tests 3652 passed / 41 skipped (3693). Also green with the same counts on ed64040 and 20b3fb9. - Earlier (20b3fb9): nightly fixtures, `OS_TEST_TIERS=nightly … --project integration test/serve-cluster-driver-diagnosis.e2e.test.ts test/serve-app-anchored-optional-import.e2e.test.ts` → 2 files, 14 tests passed. The rest of the cli `integration` tier is declared to CI. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmSNEnhcDvnrhmAucKu)_ <!-- signed: domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent cd6c807 commit 2b752aa

8 files changed

Lines changed: 446 additions & 21 deletions
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
'@objectstack/cli': patch
3+
---
4+
5+
fix(cli)!: `os serve` asks the multi-node gate about a topology declared by `OS_EXPECT_MULTI_NODE=true`, not only by `OS_CLUSTER_REPLICAS`
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: none
9+
Skills-docs: `skills/**` names neither spelling of the multi-node declaration. `content/docs/kernel/cluster.mdx` already teaches both spellings as the declaration; its sentence that a gate denial "downgrades … rather than failing" is corrected in this diff: with a declared topology the split-brain guard refuses the boot.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No schema key, export, type or stored shape changes. The narrowing is a boot refusal keyed to environment variables an operator sets, so there is nothing for a metadata migration to rewrite and no tombstone. -->
12+
13+
**BREAKING** for a deployment that runs `os serve` with a remote cluster driver (`OS_CLUSTER_DRIVER` other than `memory`), declares multi-node only as `OS_EXPECT_MULTI_NODE=true`, and registers no multi-node gate.
14+
15+
A multi-node topology has two spellings, `OS_CLUSTER_REPLICAS` greater than 1 and `OS_EXPECT_MULTI_NODE=true`. With no gate registered, the gate refuses a declared multi-node topology, because multi-node is a licensed capability. `os serve` used to ask the gate with `OS_CLUSTER_REPLICAS` alone, so a topology declared only as `OS_EXPECT_MULTI_NODE=true` reached the gate as undeclared and booted the remote driver multi-node with no gate. The same deployment spelled `OS_CLUSTER_REPLICAS=2` was already refused.
16+
17+
After the upgrade both spellings answer the same way. `os serve` reads the declaration through `declaresMultiNode` from `@objectstack/service-cluster`. A declaration with no count is asked as 2 nodes, the smallest multi-node count. With no gate registered it prints `[cluster] multi-node not authorized (…)`, drops the remote driver, and the split-brain guard refuses the in-process fallback, so the boot stops.
18+
19+
FROM a multi-replica deployment that sets `OS_EXPECT_MULTI_NODE=true` over a remote driver with no gate TO either:
20+
21+
- register a multi-node gate (install the distribution that carries it), which authorizes the topology, or
22+
- drop `OS_EXPECT_MULTI_NODE` (and keep `OS_CLUSTER_REPLICAS` unset or 1) to run single-node.
23+
24+
A single-node boot, a boot declared as `OS_CLUSTER_REPLICAS`, and a boot whose registered gate admits the topology are unchanged.
25+
26+
When a gate that caps the node count admits fewer nodes than that 2, the licensed-cap advisory no longer prints a replica count the operator did not write. It names `OS_EXPECT_MULTI_NODE=true`, says what the licence admits, says the cap is advisory and every replica still joins, and asks the operator to run at most that many replicas (or set `OS_CLUSTER_REPLICAS`) or raise the limit. The advisory for a count declared as `OS_CLUSTER_REPLICAS` is unchanged.

‎content/docs/kernel/cluster.mdx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,12 @@ const cluster = defineCluster({ driver: 'memory' })
685685
Under `os serve` the driver is selected from the environment instead:
686686
`OS_CLUSTER_DRIVER` (anything other than `memory` triggers a dynamic import of
687687
`@objectstack/service-cluster-<driver>`) and `OS_REDIS_URL` for the connection
688-
string. A distribution may register a multi-node gate; when it denies,
689-
`os serve` logs a warning and downgrades to the single-node in-memory cluster
690-
rather than failing.
688+
string. A distribution may register a multi-node gate; with no gate
689+
registered, a declared multi-node topology is denied. When the gate denies,
690+
`os serve` logs a warning and drops the remote driver for the in-memory one.
691+
That is a single-node downgrade only when no multi-node topology is declared:
692+
with one declared (`OS_CLUSTER_REPLICAS` > 1 or `OS_EXPECT_MULTI_NODE=true`),
693+
the split-brain guard below refuses the boot.
691694

692695
A gate may instead admit **fewer** nodes than the deployment declares — a
693696
licensed node-cap overflow. That is a different verdict from a denial and is

‎packages/cli/src/commands/serve-multi-node-cap-advisory.pin.test.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,35 @@ describe('os serve ↔ multi-node gate', () => {
155155
// desired count, identical in every replica, not a live membership count —
156156
// which is right for an advisory message about the operator's own
157157
// configuration, and is NOT sufficient for enforcement.
158-
expect(MASKED_SERVE_SOURCE).toMatch(/checkMultiNodeAllowed\(\s*Number\(process\.env\.OS_CLUSTER_REPLICAS\)\s*\)/);
158+
//
159+
// The count is asked through the one reading of the declaration
160+
// (`declaresMultiNode`, both spellings): a topology declared only as
161+
// `OS_EXPECT_MULTI_NODE=true` carries no count, and asked with the bare
162+
// `NaN` the gate read it as "not declared". ⛔ No second parse of that
163+
// spelling here — the shared predicate is the only reader.
164+
expect(MASKED_SERVE_SOURCE).toMatch(
165+
/const __countUnknown =\s*declaresMultiNode\(process\.env\)\s*&&\s*!declaresMultiNode\(\{\s*OS_CLUSTER_REPLICAS:\s*process\.env\.OS_CLUSTER_REPLICAS\s*\}\);/,
166+
);
167+
expect(MASKED_SERVE_SOURCE).toMatch(
168+
/const __requestedNodes = __countUnknown \? 2 : Number\(process\.env\.OS_CLUSTER_REPLICAS\);/,
169+
);
170+
expect(MASKED_SERVE_SOURCE).toMatch(/checkMultiNodeAllowed\(\s*__requestedNodes\s*\)/);
171+
expect(MASKED_SERVE_SOURCE).not.toMatch(/process\.env\.OS_EXPECT_MULTI_NODE/);
172+
});
173+
174+
it('tells the cap advisory whether the count the gate saw is one the operator wrote', () => {
175+
// Both cases share one call: counted (`OS_CLUSTER_REPLICAS`, or nothing
176+
// declared) keeps the counted wording byte for byte; uncounted
177+
// (`OS_EXPECT_MULTI_NODE=true` alone, asked as 2) must never print that 2 as
178+
// a declared count. The flag comes from the call site's own reading, so the
179+
// formatter re-reads nothing — and the parameter is required, so no call can
180+
// fall back to the counted wording by leaving it out.
181+
expect(MASKED_SERVE_SOURCE).toMatch(
182+
/formatMultiNodeCapAdvisory\(\s*__gate\s*,\s*\{\s*countDeclared:\s*!__countUnknown\s*\}\s*\)/,
183+
);
184+
expect(MASKED_SERVE_SOURCE).toMatch(
185+
/export function formatMultiNodeCapAdvisory\(\s*verdict: MultiNodeGateVerdict,\s*declaration: \{ countDeclared: boolean \},\s*\)/,
186+
);
159187
});
160188

161189
it('types the dynamic import with the mirrored verdict, not an inline literal', () => {

‎packages/cli/src/commands/serve-multi-node-cap-advisory.test.ts‎

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
import { describe, it, expect } from 'vitest';
2222
import { formatMultiNodeCapAdvisory, type MultiNodeGateVerdict } from './serve.js';
2323

24+
// Pay the first load of what `serve.ts` reaches through dynamic `import()`s at
25+
// MODULE LOAD, outside any clocked case (`pnpm check:test-source-alias`).
26+
import '@objectstack/metadata-protocol';
27+
import '@objectstack/metadata';
28+
import '@objectstack/objectql';
29+
import '@objectstack/plugin-hono-server';
30+
import '@objectstack/rest';
31+
import '@objectstack/service-settings';
32+
import '@objectstack/service-datasource';
33+
import '@objectstack/driver-turso';
34+
import '@objectstack/driver-sql';
35+
import '@objectstack/platform-objects/plugin';
36+
import '@objectstack/plugin-security';
37+
2438
/**
2539
* The four verdicts the producer can hand this consumer, spelled the way
2640
* `checkMultiNodeAllowed` builds them (`multi-node-gate.ts`). The pin test
@@ -37,17 +51,25 @@ const VERDICTS = {
3751
denied: { allowed: false, reason: 'no clustering entitlement', admitted: 0, refused: 5, capped: false },
3852
} satisfies Record<string, MultiNodeGateVerdict>;
3953

54+
/** The operator wrote `OS_CLUSTER_REPLICAS`: the count the gate saw is theirs. */
55+
const COUNTED = { countDeclared: true };
56+
/** `OS_EXPECT_MULTI_NODE=true` with no count: `serve` asked the gate about 2 nodes. */
57+
const UNCOUNTED = { countDeclared: false };
58+
59+
/** An uncounted declaration under a cap of 1: the gate was asked about 2. */
60+
const UNCOUNTED_OVER_CAP = { allowed: true, admitted: 1, refused: 1, capped: true } satisfies MultiNodeGateVerdict;
61+
4062
describe('formatMultiNodeCapAdvisory', () => {
4163
it('says nothing when no cap is configured', () => {
42-
expect(formatMultiNodeCapAdvisory(VERDICTS.uncapped)).toBeNull();
64+
expect(formatMultiNodeCapAdvisory(VERDICTS.uncapped, COUNTED)).toBeNull();
4365
});
4466

4567
it('says nothing when a cap is configured and the declared topology fits', () => {
46-
expect(formatMultiNodeCapAdvisory(VERDICTS.withinCap)).toBeNull();
68+
expect(formatMultiNodeCapAdvisory(VERDICTS.withinCap, COUNTED)).toBeNull();
4769
});
4870

4971
it('warns on a licensed overflow, naming both numbers', () => {
50-
expect(formatMultiNodeCapAdvisory(VERDICTS.overflow)).toBe(
72+
expect(formatMultiNodeCapAdvisory(VERDICTS.overflow, COUNTED)).toBe(
5173
'[cluster] licensed node cap exceeded: the licence admits 3 node(s), '
5274
+ 'but OS_CLUSTER_REPLICAS declares 5 — 2 beyond the cap.\n'
5375
+ '[cluster] This cap is ADVISORY and is not enforced yet: nothing is refused, '
@@ -57,7 +79,7 @@ describe('formatMultiNodeCapAdvisory', () => {
5779
});
5880

5981
it('⚠️ never claims replicas were refused — nothing is refused today', () => {
60-
const text = formatMultiNodeCapAdvisory(VERDICTS.overflow) ?? '';
82+
const text = formatMultiNodeCapAdvisory(VERDICTS.overflow, COUNTED) ?? '';
6183

6284
// The false sentences, in the shapes they would plausibly be written.
6385
expect(text).not.toMatch(/\d+\s+(replicas?\s+)?(were\s+|was\s+|are\s+)?refused/i);
@@ -72,7 +94,7 @@ describe('formatMultiNodeCapAdvisory', () => {
7294
});
7395

7496
it('names the declared count, the admitted count and the remedy', () => {
75-
const text = formatMultiNodeCapAdvisory(VERDICTS.overflow) ?? '';
97+
const text = formatMultiNodeCapAdvisory(VERDICTS.overflow, COUNTED) ?? '';
7698
expect(text).toContain('admits 3');
7799
expect(text).toContain('declares 5');
78100
expect(text).toContain('2 beyond the cap');
@@ -85,7 +107,7 @@ describe('formatMultiNodeCapAdvisory', () => {
85107
// unlicensed case cannot be conflated with the licensed-overflow one. The
86108
// call site already prints its own downgrade warning; a second message here
87109
// would report one event twice, and would call a full denial a partial cap.
88-
expect(formatMultiNodeCapAdvisory(VERDICTS.denied)).toBeNull();
110+
expect(formatMultiNodeCapAdvisory(VERDICTS.denied, COUNTED)).toBeNull();
89111
});
90112

91113
it('surfaces the gate reason when the cap carries one', () => {
@@ -95,12 +117,12 @@ describe('formatMultiNodeCapAdvisory', () => {
95117
admitted: 3,
96118
refused: 2,
97119
capped: true,
98-
});
120+
}, COUNTED);
99121
expect(text).toContain('(plan: team (3 nodes))');
100122
});
101123

102124
it('scales with the numbers rather than hard-coding the 3/5 case', () => {
103-
const text = formatMultiNodeCapAdvisory({ allowed: true, admitted: 10, refused: 7, capped: true }) ?? '';
125+
const text = formatMultiNodeCapAdvisory({ allowed: true, admitted: 10, refused: 7, capped: true }, COUNTED) ?? '';
104126
expect(text).toContain('admits 10');
105127
expect(text).toContain('declares 17');
106128
expect(text).toContain('7 beyond the cap');
@@ -111,7 +133,44 @@ describe('formatMultiNodeCapAdvisory', () => {
111133
// a numeric `admitted`), so this pins the choice rather than a behaviour:
112134
// faced with a stale or foreign build, silence beats a warning with an
113135
// invented count in it.
114-
expect(formatMultiNodeCapAdvisory({ allowed: true, refused: 2, capped: true })).toBeNull();
115-
expect(formatMultiNodeCapAdvisory({ allowed: true, admitted: 3, refused: 0, capped: true })).toBeNull();
136+
expect(formatMultiNodeCapAdvisory({ allowed: true, refused: 2, capped: true }, COUNTED)).toBeNull();
137+
expect(formatMultiNodeCapAdvisory({ allowed: true, admitted: 3, refused: 0, capped: true }, COUNTED)).toBeNull();
138+
});
139+
140+
it('names OS_EXPECT_MULTI_NODE and prints no count when the operator gave none', () => {
141+
expect(formatMultiNodeCapAdvisory(UNCOUNTED_OVER_CAP, UNCOUNTED)).toBe(
142+
'[cluster] licensed node cap exceeded: the licence admits 1 node(s), '
143+
+ 'but OS_EXPECT_MULTI_NODE=true declares a multi-node topology without a replica count.\n'
144+
+ '[cluster] This cap is ADVISORY and is not enforced yet: nothing is refused, '
145+
+ 'and every replica will still join the cluster.\n'
146+
+ '[cluster] Run at most 1 replica(s) (or set OS_CLUSTER_REPLICAS to the count you run), '
147+
+ 'or raise the licensed node limit.',
148+
);
149+
});
150+
151+
it('⚠️ never prints the 2 serve asked about as a declared count, nor an excess', () => {
152+
const text = formatMultiNodeCapAdvisory(UNCOUNTED_OVER_CAP, UNCOUNTED) ?? '';
153+
expect(text).not.toBe('');
154+
expect(text).not.toMatch(/declares\s+\d/);
155+
expect(text).not.toMatch(/beyond the cap/);
156+
expect(text).not.toMatch(/all\s+\d+\s+replicas/);
157+
expect(text).not.toMatch(/Reduce OS_CLUSTER_REPLICAS/);
158+
expect(text).toMatch(/still join/);
159+
});
160+
161+
it('the same verdict with a counted declaration keeps the counted wording', () => {
162+
expect(formatMultiNodeCapAdvisory(UNCOUNTED_OVER_CAP, COUNTED)).toBe(
163+
'[cluster] licensed node cap exceeded: the licence admits 1 node(s), '
164+
+ 'but OS_CLUSTER_REPLICAS declares 2 — 1 beyond the cap.\n'
165+
+ '[cluster] This cap is ADVISORY and is not enforced yet: nothing is refused, '
166+
+ 'and all 2 replicas will still join the cluster.\n'
167+
+ '[cluster] Reduce OS_CLUSTER_REPLICAS to 1, or raise the licensed node limit.',
168+
);
169+
});
170+
171+
it('an uncounted declaration stays silent wherever the counted one does', () => {
172+
expect(formatMultiNodeCapAdvisory(VERDICTS.uncapped, UNCOUNTED)).toBeNull();
173+
expect(formatMultiNodeCapAdvisory(VERDICTS.denied, UNCOUNTED)).toBeNull();
174+
expect(formatMultiNodeCapAdvisory({ allowed: true, admitted: 2, refused: 0, capped: false }, UNCOUNTED)).toBeNull();
116175
});
117176
});

0 commit comments

Comments
 (0)