Initial import of streamline
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { test, expect, describe } from "bun:test";
|
||||
import { aggregateCapabilities } from "../src/cluster";
|
||||
import type { NodeCapability } from "../src/types";
|
||||
|
||||
/**
|
||||
* The rule these lock down is asymmetric on purpose.
|
||||
*
|
||||
* Claiming a pool HAS a capability is a promise, so it needs unanimity: dispatch
|
||||
* hands the task to whichever machine is free, and a tool only two of three have
|
||||
* is a coin flip.
|
||||
*
|
||||
* Claiming a pool LACKS one is a louder statement still — the UI strikes the row
|
||||
* out and tells the user their link will be ignored — so it needs the pool to
|
||||
* have fully answered. A silent node (older satellite mid-rollout) proves
|
||||
* nothing, and absence of proof must not render as proof of absence.
|
||||
*
|
||||
* Regression: during this feature's own rollout, 1 of 4 nodes had upgraded and it
|
||||
* was the one machine missing the Lark MCP. Treating the 3 silent nodes as
|
||||
* "not capable" made the whole default pool advertise that it could not read
|
||||
* Lark docs — while three of its machines could.
|
||||
*/
|
||||
|
||||
const LARK: NodeCapability = "lark-doc";
|
||||
const FIGMA: NodeCapability = "figma";
|
||||
|
||||
describe("aggregateCapabilities", () => {
|
||||
test("unanimous and fully reported → promised", () => {
|
||||
const r = aggregateCapabilities([[LARK, FIGMA], [LARK, FIGMA]], 0);
|
||||
expect(r.capabilities.sort()).toEqual([FIGMA, LARK]);
|
||||
expect(r.partial).toEqual([]);
|
||||
});
|
||||
|
||||
test("some machines have it → partial, never promised", () => {
|
||||
const r = aggregateCapabilities([[LARK, FIGMA], [FIGMA]], 0);
|
||||
expect(r.capabilities).toEqual([FIGMA]);
|
||||
expect(r.partial).toEqual([LARK]);
|
||||
});
|
||||
|
||||
test("unanimous but someone is still silent → partial, not promised", () => {
|
||||
const r = aggregateCapabilities([[FIGMA]], 3);
|
||||
expect(r.capabilities).toEqual([]);
|
||||
expect(r.partial).toEqual([FIGMA]);
|
||||
});
|
||||
|
||||
test("nobody reports it AND everyone answered → absent (neither list)", () => {
|
||||
const r = aggregateCapabilities([[FIGMA], [FIGMA]], 0);
|
||||
expect(r.capabilities).toEqual([FIGMA]);
|
||||
expect(r.partial).toEqual([]);
|
||||
expect(r.capabilities.includes(LARK)).toBe(false);
|
||||
expect(r.partial.includes(LARK)).toBe(false);
|
||||
});
|
||||
|
||||
test("the rollout case: 1 of 4 reported, and it is the one without Lark", () => {
|
||||
// Must NOT end up looking like "this pool cannot read Lark docs" — the three
|
||||
// silent machines have not been asked yet.
|
||||
const r = aggregateCapabilities([[FIGMA]], 3);
|
||||
expect(r.capabilities).toEqual([]);
|
||||
expect(r.partial).toEqual([FIGMA]);
|
||||
// lark-doc is in neither list; with silent nodes present, callers read that
|
||||
// as "unknown" rather than "absent" (see links.capableOf / LinkRail.capState).
|
||||
expect(r.partial.includes(LARK)).toBe(false);
|
||||
});
|
||||
|
||||
test("nothing reported at all → no claims either way", () => {
|
||||
const r = aggregateCapabilities([], 4);
|
||||
expect(r.capabilities).toEqual([]);
|
||||
expect(r.partial).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user