|
1 | 1 | // The HOSES / INDEX_LEGACY_KINDS switch: planIngest selects which hoses run |
2 | | -// and which kinds get subscribed. Pure function — test with fake hoses. |
| 2 | +// and which kinds get subscribed. Pure function — test with fake hoses and an |
| 3 | +// explicit legacy-kind set (so these stay stable as real hoses are added). |
3 | 4 | import test from 'node:test'; |
4 | 5 | import assert from 'node:assert/strict'; |
5 | 6 | import { planIngest } from '../src/indexer.js'; |
6 | 7 |
|
7 | | -// Fakes — the real LEGACY_KINDS is [10002] (kinds 0 and 3 are now hose-owned). |
8 | 8 | const profiles = { name: 'profiles', kinds: [0] }; |
9 | 9 | const follows = { name: 'follows', kinds: [3] }; |
10 | | -const ONE = [profiles]; // only profiles registered |
11 | | -const TWO = [profiles, follows]; // the real registry |
| 10 | +const ALL = [profiles, follows]; |
| 11 | +const LEGACY = [10002]; // a kind with no hose yet, for these scenarios |
12 | 12 |
|
13 | 13 | const sorted = (a) => [...a].sort((x, y) => x - y); |
14 | 14 |
|
15 | 15 | test('default (no env): all registered hoses on + legacy kinds', () => { |
16 | | - const p = planIngest(ONE, {}); |
17 | | - assert.deepEqual(p.hoses.map((h) => h.name), ['profiles']); |
| 16 | + const p = planIngest(ALL, {}, LEGACY); |
| 17 | + assert.deepEqual(p.hoses.map((h) => h.name), ['profiles', 'follows']); |
18 | 18 | assert.equal(p.legacy, true); |
19 | | - assert.deepEqual(sorted(p.kinds), [0, 10002]); // 10002 is the only legacy kind |
| 19 | + assert.deepEqual(sorted(p.kinds), [0, 3, 10002]); |
20 | 20 | assert.deepEqual(p.unknown, []); |
21 | 21 | }); |
22 | 22 |
|
23 | 23 | test('empty HOSES string falls back to the default (all on)', () => { |
24 | | - assert.deepEqual(sorted(planIngest(ONE, { HOSES: '' }).kinds), [0, 10002]); |
| 24 | + assert.deepEqual(sorted(planIngest(ALL, { HOSES: '' }, LEGACY).kinds), [0, 3, 10002]); |
| 25 | +}); |
| 26 | + |
| 27 | +test('HOSES selects a subset', () => { |
| 28 | + const p = planIngest(ALL, { HOSES: 'profiles' }, LEGACY); |
| 29 | + assert.deepEqual(p.hoses.map((h) => h.name), ['profiles']); |
| 30 | + assert.deepEqual(sorted(p.kinds), [0, 10002]); // profiles + legacy |
25 | 31 | }); |
26 | 32 |
|
27 | 33 | test('INDEX_LEGACY_KINDS=0 → only enabled hoses\' kinds, no legacy', () => { |
28 | | - const p = planIngest(ONE, { HOSES: 'profiles', INDEX_LEGACY_KINDS: '0' }); |
| 34 | + const p = planIngest(ALL, { HOSES: 'profiles', INDEX_LEGACY_KINDS: '0' }, LEGACY); |
29 | 35 | assert.equal(p.legacy, false); |
30 | 36 | assert.deepEqual(p.kinds, [0]); |
31 | 37 | }); |
32 | 38 |
|
33 | 39 | test('INDEX_LEGACY_KINDS=false is also off', () => { |
34 | | - assert.equal(planIngest(ONE, { INDEX_LEGACY_KINDS: 'false' }).legacy, false); |
| 40 | + assert.equal(planIngest(ALL, { INDEX_LEGACY_KINDS: 'false' }, LEGACY).legacy, false); |
35 | 41 | }); |
36 | 42 |
|
37 | 43 | test('unknown hose names are reported and ignored', () => { |
38 | | - const p = planIngest(ONE, { HOSES: 'profiles,nope' }); |
| 44 | + const p = planIngest(ALL, { HOSES: 'profiles,nope' }, LEGACY); |
39 | 45 | assert.deepEqual(p.hoses.map((h) => h.name), ['profiles']); |
40 | 46 | assert.deepEqual(p.unknown, ['nope']); |
41 | 47 | }); |
42 | 48 |
|
43 | | -test('selecting only an unknown hose leaves no hose kinds (legacy still applies)', () => { |
44 | | - const p = planIngest(ONE, { HOSES: 'nope' }); |
45 | | - assert.deepEqual(p.hoses, []); |
46 | | - assert.deepEqual(sorted(p.kinds), [10002]); // legacy fallback only |
47 | | -}); |
48 | | - |
49 | | -test('the real two-hose registry: profiles + follows own 0 and 3, legacy = 10002', () => { |
50 | | - const p = planIngest(TWO, {}); // follows owns kind 3 |
51 | | - assert.deepEqual(p.hoses.map((h) => h.name), ['profiles', 'follows']); |
| 49 | +test('a hose that owns a legacy kind removes it from the legacy set', () => { |
| 50 | + // follows owns kind 3 — if 3 were also "legacy" it must not double-subscribe. |
| 51 | + const p = planIngest(ALL, {}, [3, 10002]); |
52 | 52 | assert.deepEqual(p.legacyKinds, [10002]); |
53 | 53 | assert.deepEqual(sorted(p.kinds), [0, 3, 10002]); |
54 | 54 | }); |
55 | 55 |
|
56 | | -test('single-hose deploy: HOSES=follows + no legacy → just kind 3', () => { |
57 | | - const p = planIngest(TWO, { HOSES: 'follows', INDEX_LEGACY_KINDS: '0' }); |
58 | | - assert.deepEqual(p.kinds, [3]); |
| 56 | +test('no legacy kinds (the real phase-3 state): just the hose kinds', () => { |
| 57 | + const p = planIngest(ALL, {}, []); |
| 58 | + assert.deepEqual(p.legacyKinds, []); |
| 59 | + assert.deepEqual(sorted(p.kinds), [0, 3]); |
59 | 60 | }); |
0 commit comments