|
| 1 | +// CLI flag parsing for the indexer. parseArgs produces an env-overlay that |
| 2 | +// runIndexer merges over process.env (flags win, env is the fallback). |
| 3 | +import test from 'node:test'; |
| 4 | +import assert from 'node:assert/strict'; |
| 5 | +import { parseArgs, planIngest } from '../src/indexer.js'; |
| 6 | + |
| 7 | +const profiles = { name: 'profiles', kinds: [0] }; |
| 8 | +const follows = { name: 'follows', kinds: [3] }; |
| 9 | +const ALL = [profiles, follows]; |
| 10 | + |
| 11 | +test('no flags -> empty overlay', () => { |
| 12 | + assert.deepEqual(parseArgs([]), {}); |
| 13 | +}); |
| 14 | + |
| 15 | +test('--hoses with a space-separated value', () => { |
| 16 | + assert.deepEqual(parseArgs(['--hoses', 'profiles,follows']), { HOSES: 'profiles,follows' }); |
| 17 | +}); |
| 18 | + |
| 19 | +test('--hoses=value form', () => { |
| 20 | + assert.deepEqual(parseArgs(['--hoses=profiles']), { HOSES: 'profiles' }); |
| 21 | +}); |
| 22 | + |
| 23 | +test('--hoses with no value -> empty string (planIngest treats as default)', () => { |
| 24 | + assert.deepEqual(parseArgs(['--hoses']), { HOSES: '' }); |
| 25 | + assert.deepEqual(parseArgs(['--hoses', '--no-legacy']), { HOSES: '', INDEX_LEGACY_KINDS: '0' }); |
| 26 | +}); |
| 27 | + |
| 28 | +test('--no-legacy and --legacy map to INDEX_LEGACY_KINDS', () => { |
| 29 | + assert.deepEqual(parseArgs(['--no-legacy']), { INDEX_LEGACY_KINDS: '0' }); |
| 30 | + assert.deepEqual(parseArgs(['--legacy']), { INDEX_LEGACY_KINDS: '1' }); |
| 31 | +}); |
| 32 | + |
| 33 | +test('--help / -h set help', () => { |
| 34 | + assert.equal(parseArgs(['--help']).help, true); |
| 35 | + assert.equal(parseArgs(['-h']).help, true); |
| 36 | +}); |
| 37 | + |
| 38 | +test('flags compose', () => { |
| 39 | + assert.deepEqual(parseArgs(['--hoses', 'profiles', '--no-legacy']), |
| 40 | + { HOSES: 'profiles', INDEX_LEGACY_KINDS: '0' }); |
| 41 | +}); |
| 42 | + |
| 43 | +test('flags override env when merged (the runIndexer contract)', () => { |
| 44 | + const env = { HOSES: 'profiles,follows', INDEX_LEGACY_KINDS: '1' }; |
| 45 | + const merged = { ...env, ...parseArgs(['--hoses', 'profiles', '--no-legacy']) }; |
| 46 | + const p = planIngest(ALL, merged, []); |
| 47 | + assert.deepEqual(p.hoses.map((h) => h.name), ['profiles']); // flag won over env |
| 48 | + assert.equal(p.legacy, false); |
| 49 | + assert.deepEqual(p.kinds, [0]); |
| 50 | +}); |
0 commit comments