Manual pass: task cancelTask, workflow topologicalOrder/fail/reset, collab kick/replay, trust trustedPeers and multisig TTL sweep, graph shortestPath, inverted topTerms, dedup filterNew, bee notifyBatch/seekVersion — all with tests. Co-authored-by: Cursor <[email protected]>
61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
require('bare-process/global')
|
|
const test = require('brittle')
|
|
const { HyperP2PInvertedIndex, PROTOCOL } = require('../index.js')
|
|
|
|
test('exports', (t) => {
|
|
t.ok(HyperP2PInvertedIndex)
|
|
t.is(PROTOCOL, 'inverted-index/v1')
|
|
})
|
|
|
|
test('index search removeDoc', async (t) => {
|
|
const m = new HyperP2PInvertedIndex()
|
|
m.index('d1', ['Hello', 'World'])
|
|
t.alike(m.search('hello'), ['d1'])
|
|
t.ok(m.removeDoc('d1'))
|
|
t.is(m.search('world').length, 0)
|
|
await m.close()
|
|
})
|
|
|
|
test('validation', async (t) => {
|
|
const m = new HyperP2PInvertedIndex()
|
|
try { m.index('', ['x']) } catch (e) { t.ok(e) }
|
|
await m.close()
|
|
})
|
|
|
|
test('remote gossip', async (t) => {
|
|
const m = new HyperP2PInvertedIndex()
|
|
m._onGossip({ type: 'term-index-sync', op: 'add', term: 'cat', docId: 'd9' })
|
|
t.alike(m.search('cat'), ['d9'])
|
|
m._onGossip({ type: 'term-index-sync', op: 'remove', term: 'cat', docId: 'd9' })
|
|
t.is(m.search('cat').length, 0)
|
|
await m.close()
|
|
})
|
|
|
|
test('getStats', async (t) => {
|
|
const m = new HyperP2PInvertedIndex()
|
|
m.index('a', ['z'])
|
|
t.is(m.getStats().protocol, 'inverted-index/v1')
|
|
t.is(m.getStats().indexed, 1)
|
|
await m.close()
|
|
})
|
|
|
|
test('searchAll getDocTerms', async (t) => {
|
|
const m = new HyperP2PInvertedIndex()
|
|
m.index('d1', ['cat', 'dog'])
|
|
m.index('d2', ['cat'])
|
|
t.is(m.searchAll(['cat', 'dog'], 'and').length, 1)
|
|
t.is(m.searchAll(['cat', 'dog'], 'or').length, 2)
|
|
t.alike(m.getDocTerms('d1'), ['cat', 'dog'])
|
|
await m.close()
|
|
})
|
|
|
|
test('topTerms', async (t) => {
|
|
const m = new HyperP2PInvertedIndex()
|
|
m.index('a', ['x'])
|
|
m.index('b', ['x', 'y'])
|
|
m.index('c', ['x'])
|
|
t.is(m.topTerms(1)[0].term, 'x')
|
|
t.is(m.topTerms(1)[0].docs, 3)
|
|
await m.close()
|
|
})
|