/
vectorstore.test.js
68 lines (59 loc) · 2.24 KB
/
vectorstore.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright 2023 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
const { test } = require('tap')
const helper = require('../../../lib/agent_helper')
const GenericShim = require('../../../../lib/shim/shim')
const sinon = require('sinon')
test('langchain/core/vectorstore unit tests', (t) => {
t.beforeEach(function (t) {
const sandbox = sinon.createSandbox()
const agent = helper.loadMockedAgent()
agent.config.ai_monitoring = { enabled: true }
agent.config.feature_flag = { langchain_instrumentation: true }
const shim = new GenericShim(agent, 'langchain')
shim.pkgVersion = '0.1.26'
sandbox.stub(shim.logger, 'debug')
sandbox.stub(shim.logger, 'warn')
t.context.agent = agent
t.context.shim = shim
t.context.sandbox = sandbox
t.context.initialize = require('../../../../lib/instrumentation/langchain/vectorstore')
})
t.afterEach(function (t) {
helper.unloadAgent(t.context.agent)
t.context.sandbox.restore()
})
function getMockModule() {
function VectorStore() {}
VectorStore.prototype.similaritySearch = async function call() {}
return { VectorStore }
}
;[
{ aiMonitoring: false, langChain: true },
{ aiMonitoring: true, langChain: false },
{ aiMonitoring: false, langChain: false }
].forEach(({ aiMonitoring, langChain }) => {
t.test(
`should not register instrumentation if ai_monitoring is ${aiMonitoring} and langchain_instrumentation is ${langChain}`,
(t) => {
const { shim, agent, initialize } = t.context
const MockVectorstore = getMockModule()
agent.config.ai_monitoring.enabled = aiMonitoring
agent.config.feature_flag.langchain_instrumentation = langChain
initialize(shim, MockVectorstore)
t.equal(shim.logger.debug.callCount, 1, 'should log 1 debug messages')
t.equal(
shim.logger.debug.args[0][0],
'langchain instrumentation is disabled. To enable set `config.ai_monitoring.enabled` to true'
)
const isWrapped = shim.isWrapped(MockVectorstore.VectorStore.prototype.similaritySearch)
t.equal(isWrapped, false, 'should not wrap vectorstore similaritySearch')
t.end()
}
)
})
t.end()
})