Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit cdd6511

Browse files
authored
Merge pull request #34 from SciPhi-AI/Nolan/IntegrationTest
Add integration tests
2 parents 07bd72f + ee151a7 commit cdd6511

File tree

10 files changed

+203
-44
lines changed

10 files changed

+203
-44
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,3 @@ jobs:
2828

2929
- name: Build
3030
run: pnpm run build
31-
32-
- name: Run tests
33-
run: pnpm test
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: "3.x"
20+
21+
- name: Install R2R
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install r2r
25+
26+
- name: Start R2R server
27+
env:
28+
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
29+
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
30+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
31+
POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
32+
POSTGRES_DBNAME: ${{ secrets.POSTGRES_DBNAME }}
33+
POSTGRES_VECS_COLLECTION: ${{ secrets.POSTGRES_VECS_COLLECTION }}
34+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
35+
run: |
36+
r2r serve --port=8000 > r2r_server.log 2>&1 &
37+
sleep 15
38+
39+
- name: Use Node.js
40+
uses: actions/setup-node@v2
41+
with:
42+
node-version: "20.x"
43+
44+
- name: Install dependencies
45+
run: npm ci
46+
47+
- name: Check if R2R server is running
48+
run: |
49+
curl http://localhost:8000/health || echo "Server not responding"
50+
51+
- name: Display R2R server logs if server not responding
52+
if: failure()
53+
run: cat r2r_server.log
54+
55+
- name: Run integration tests
56+
run: npm run test
57+
58+
- name: Display R2R server logs if tests fail
59+
if: failure()
60+
run: cat r2r_server.log

__tests__/data/karamozov.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Alexius Fyodorovich Karamazov erat tertius filius Fyodoris Pavlovich Karamazov
2+
possessoris terrarum in nostro districtu bene noti sua aetate, et adhuc apud nos
3+
memoriae mandati ob mortem tragicam et obscuram, quae tredecim annos abhinc
4+
accidit, quamque suo loco describam.

__tests__/data/myshkin.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Sub finem Novembris, tempore liquationis, hora nona mane, tramen in via
2+
ferrea Varsaviae et Petropoli plenis velocitatibus Petropolim
3+
appropinquabat. Dies ita humidus et nebulosus erat ut magno cum labore
4+
viatores invicem videre possent.

__tests__/data/raskolnikov.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
In vespera praecipue calida ineunte Iulio iuvenis e cenaculo in quo hospitabatur in
2+
S. loco exiit et lente, quasi dubitans, versus pontem K. ambulavit. Feliciter vitavit
3+
ne domina sua eum in scala occurreret. Cenaculum suum sub tecto domus altae, quinque
4+
tabulatorum, erat, et magis armario quam conclavi simile erat. Domina, quae ei cenaculum,
5+
prandia et ministerium praebebat, in tabulato infra habitabat, et quotienscumque exibat,
6+
praeterire culinam eius, cuius ianua semper aperta erat, cogebatur. Et quoties praeteribat,
7+
iuvenis aegrotum et pavidum sensum habebat, quod eum corrugare frontem et pudere faciebat.
8+
Desperanter apud dominam suam aere alieno obrutus erat, et eam convenire timebat.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { r2rClient } from "../src/index";
2+
3+
const baseUrl = "http://localhost:8000";
4+
5+
describe("r2rClient Integration Tests", () => {
6+
let client: r2rClient;
7+
8+
beforeAll(async () => {
9+
client = new r2rClient(baseUrl);
10+
});
11+
12+
test("Health check", async () => {
13+
await expect(client.healthCheck()).resolves.not.toThrow();
14+
});
15+
16+
test("Ingest files", async () => {
17+
const files = [
18+
{ path: "__tests__/data/raskolnikov.txt", name: "raskolnikov.txt" },
19+
{ path: "__tests__/data/karamozov.txt", name: "karamozov.txt" },
20+
];
21+
await expect(
22+
client.ingestFiles(files, {
23+
metadatas: [{ title: "raskolnikov.txt" }, { title: "karamozov.txt" }],
24+
user_ids: [
25+
"123e4567-e89b-12d3-a456-426614174000",
26+
"123e4567-e89b-12d3-a456-426614174000",
27+
],
28+
skip_document_info: false,
29+
}),
30+
).resolves.not.toThrow();
31+
});
32+
33+
test("Update files", async () => {
34+
const updated_file = [
35+
{ path: "__tests__/data/myshkin.txt", name: "myshkin.txt" },
36+
];
37+
await expect(
38+
client.updateFiles(updated_file, {
39+
document_ids: ["48e29904-3010-54fe-abe5-a4f3fba59110"],
40+
metadatas: [{ title: "myshkin.txt" }],
41+
}),
42+
).resolves.not.toThrow();
43+
});
44+
45+
test("Search documents", async () => {
46+
await expect(client.search("test")).resolves.not.toThrow();
47+
});
48+
49+
test("Generate RAG response", async () => {
50+
await expect(client.rag({ query: "test" })).resolves.not.toThrow();
51+
});
52+
53+
test("Delete document", async () => {
54+
await expect(
55+
client.delete(["document_id"], ["153a0857-efc4-57dd-b629-1c7d58c24a93"]),
56+
).resolves.not.toThrow();
57+
});
58+
59+
test("Get logs", async () => {
60+
await expect(client.logs()).resolves.not.toThrow();
61+
});
62+
63+
test("Get app settings", async () => {
64+
await expect(client.appSettings()).resolves.not.toThrow();
65+
});
66+
67+
// test('Get analytics', async () => {
68+
// const filterCriteria = {
69+
// filters: {
70+
// "search_latencies": "search_latency"
71+
// }
72+
// };
73+
74+
// const analysisTypes = {
75+
// "search_latencies": ["basic_statistics", "search_latency"]
76+
// };
77+
78+
// await expect(client.analytics(filterCriteria, analysisTypes)).resolves.not.toThrow();
79+
// });
80+
81+
test("Get users overview", async () => {
82+
await expect(client.usersOverview()).resolves.not.toThrow();
83+
});
84+
85+
test("Get documents overview", async () => {
86+
await expect(client.documentsOverview()).resolves.not.toThrow();
87+
});
88+
89+
test("Get document chunks", async () => {
90+
await expect(
91+
client.documentChunks("48e29904-3010-54fe-abe5-a4f3fba59110"),
92+
).resolves.not.toThrow();
93+
});
94+
95+
afterAll(async () => {
96+
// Clean up
97+
await client.delete(
98+
["document_id"],
99+
["48e29904-3010-54fe-abe5-a4f3fba59110"],
100+
);
101+
});
102+
});

jest.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module.exports = {
22
preset: "ts-jest",
33
testEnvironment: "node",
4-
testMatch: ["**/__tests__/**/*.ts?(x)", "**/?(*.)+(spec|test).ts?(x)"],
4+
testMatch: [
5+
"**/__tests__/**/*.ts?(x)",
6+
"**/__tests__/**/?(*.)+(spec|test).ts?(x)",
7+
],
58
};

package-lock.json

Lines changed: 20 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"build": "tsc",
1313
"prepublishOnly": "npm run build",
1414
"format": "prettier --write .",
15+
"pretest:integration": "node setup.js",
1516
"test": "jest",
1617
"test:watch": "jest --watch",
1718
"test:coverage": "jest --coverage"

src/r2rClient.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,6 @@ export class r2rClient {
291291
},
292292
};
293293

294-
console.log("Sending RAG request:", JSON.stringify(request, null, 2));
295-
console.log("Request headers:", this.axiosInstance.defaults.headers);
296-
297294
if (rag_generation_config.stream) {
298295
return this.streamRag(request);
299296
} else {

0 commit comments

Comments
 (0)