Skip to content

Commit

Permalink
Fix bugs in auth router, js sdk auto refresh (#1255)
Browse files Browse the repository at this point in the history
* JS testing fixes, bugs in auth

* More
  • Loading branch information
NolanTrem authored Sep 23, 2024
1 parent 86faf8c commit 4740935
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/r2r-js-sdk-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
POSTGRES_PROJECT_NAME: ${{ secrets.POSTGRES_PROJECT_NAME }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
r2r serve --port=7272 > r2r_server.log 2>&1 &
sleep 15
r2r serve --docker
sleep 60
- name: Use Node.js
uses: actions/setup-node@v2
Expand Down
106 changes: 88 additions & 18 deletions js/sdk/__tests__/r2rClientIntegrationSuperUser.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { r2rClient } from "../src/index";
const fs = require("fs");
import { describe, test, beforeAll, expect } from "@jest/globals";

const baseUrl = "http://localhost:7272";

Expand All @@ -9,6 +10,61 @@ const baseUrl = "http://localhost:7272";
* myshkin.txt should have an id of `2e05b285-2746-5778-9e4a-e293db92f3be`
*/

/**
* Coverage
* - health
* Auth:
* X register
* X verifyEmail
* - login
* - logout
* X user
* X updateUser
* - refreshAccessToken
* X changePassword
* X requestPasswordReset
* X confirmPasswordReset
* X deleteUser
* Ingestion:
* - ingestFiles
* - updateFiles
* Management:
* - serverStats
* X updatePrompt
* - analytics
* - logs
* - appSettings
* - scoreCompletion
* - usersOverview
* - delete
* X downloadFile
* - documentsOverview
* - documentChunks
* X inspectKnowledgeGraph
* X collectionsOverview
* X createCollection
* X getCollection
* X updateCollection
* X deleteCollection
* X listCollections
* X addUserToCollection
* X removeUserFromCollection
* X getUsersInCollection
* X getCollectionsForUser
* X assignDocumentToCollection
* X removeDocumentFromCollection
* X getDocumentCollections
* X getDocumentsInCollection
* Restructure:
* X enrichGraph
* Retrieval:
* - search
* - rag
* X streamingRag
* - agent
* X streamingAgent
*/

describe("r2rClient Integration Tests", () => {
let client: r2rClient;

Expand Down Expand Up @@ -94,32 +150,34 @@ describe("r2rClient Integration Tests", () => {
});

// TOOD: Fix in R2R, table logs has no column named run_id
// test("Agentic RAG response with streaming", async () => {
// const messages = [
// { role: "system", content: "You are a helpful assistant." },
// { role: "user", content: "Tell me about Raskolnikov." },
// ];
test("Agentic RAG response with streaming", async () => {
const messages = [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Tell me about Raskolnikov." },
];

// const stream = await client.agent(messages, undefined, undefined, {
// stream: true,
// });
const stream = await client.agent(messages, undefined, undefined, {
stream: true,
});

// expect(stream).toBeDefined();
expect(stream).toBeDefined();

// let fullResponse = "";
let fullResponse = "";

// for await (const chunk of stream) {
// fullResponse += chunk;
// }
for await (const chunk of stream) {
fullResponse += chunk;
}

// expect(fullResponse.length).toBeGreaterThan(0);
// }, 30000);
expect(fullResponse.length).toBeGreaterThan(0);
}, 30000);

// Deletes raskolnikov.txt
test("Delete document", async () => {
await expect(
client.delete({
document_id: "f9f61fc8-079c-52d0-910a-c657958e385b",
document_id: {
$eq: "f9f61fc8-079c-52d0-910a-c657958e385b",
},
}),
).resolves.toBe("");
});
Expand All @@ -132,6 +190,10 @@ describe("r2rClient Integration Tests", () => {
await expect(client.appSettings()).resolves.not.toThrow();
});

test("Refresh access token", async () => {
await expect(client.refreshAccessToken()).resolves.not.toThrow();
});

test("Get analytics", async () => {
const filterCriteria: Record<string, any> | string = {
search_latencies: "search_latency",
Expand Down Expand Up @@ -163,12 +225,20 @@ describe("r2rClient Integration Tests", () => {
test("Clean up remaining documents", async () => {
// Deletes karamozov.txt
await expect(
client.delete({ document_id: "73749580-1ade-50c6-8fbe-a5e9e87783c8" }),
client.delete({
document_id: {
$eq: "73749580-1ade-50c6-8fbe-a5e9e87783c8",
},
}),
).resolves.toBe("");

// Deletes myshkin.txt
await expect(
client.delete({ document_id: "2e05b285-2746-5778-9e4a-e293db92f3be" }),
client.delete({
document_id: {
$eq: "2e05b285-2746-5778-9e4a-e293db92f3be",
},
}),
).resolves.toBe("");
});

Expand Down
88 changes: 80 additions & 8 deletions js/sdk/__tests__/r2rClientIntegrationUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,61 @@ const baseUrl = "http://localhost:7272";
* myshkin.txt should have an id of `0b80081e-a37a-579f-a06d-7d2032435d65`
*/

/**
* Coverage
* - health
* Auth:
* - register
* X verifyEmail
* - login
* - logout
* X user
* X updateUser
* - refreshAccessToken
* - changePassword
* X requestPasswordReset
* X confirmPasswordReset
* - deleteUser
* Ingestion:
* - ingestFiles
* - updateFiles
* Management:
* X serverStats
* X updatePrompt
* X analytics
* X logs
* - appSettings
* X scoreCompletion
* X usersOverview
* - delete
* X downloadFile
* - documentsOverview
* X documentChunks
* X inspectKnowledgeGraph
* X collectionsOverview
* X createCollection
* X getCollection
* X updateCollection
* X deleteCollection
* X listCollections
* X addUserToCollection
* X removeUserFromCollection
* X getUsersInCollection
* X getCollectionsForUser
* X assignDocumentToCollection
* X removeDocumentFromCollection
* X getDocumentCollections
* X getDocumentsInCollection
* Restructure:
* X enrichGraph
* Retrieval:
* - search
* X rag
* X streamingRag
* X agent
* X streamingAgent
*/

describe("r2rClient Integration Tests", () => {
let client: r2rClient;

Expand Down Expand Up @@ -68,7 +123,11 @@ describe("r2rClient Integration Tests", () => {
// Deletes rasolnikov.txt
test("Delete document", async () => {
await expect(
client.delete({ document_id: "91662726-7271-51a5-a0ae-34818509e1fd" }),
client.delete({
document_id: {
$eq: "91662726-7271-51a5-a0ae-34818509e1fd",
},
}),
).resolves.not.toThrow();
});

Expand All @@ -78,6 +137,10 @@ describe("r2rClient Integration Tests", () => {
);
});

test("Refresh access token", async () => {
await expect(client.refreshAccessToken()).resolves.not.toThrow();
});

test("Get documents overview", async () => {
await expect(client.documentsOverview()).resolves.not.toThrow();
});
Expand All @@ -95,12 +158,20 @@ describe("r2rClient Integration Tests", () => {
test("Clean up remaining documents", async () => {
// Deletes karamozov.txt
await expect(
client.delete({ document_id: "00f69fa0-c947-5f5f-a374-1837a1283366" }),
client.delete({
document_id: {
$eq: "00f69fa0-c947-5f5f-a374-1837a1283366",
},
}),
).resolves.not.toThrow();

// Deletes myshkin.txt
await expect(
client.delete({ document_id: "0b80081e-a37a-579f-a06d-7d2032435d65" }),
client.delete({
document_id: {
$eq: "0b80081e-a37a-579f-a06d-7d2032435d65",
},
}),
).resolves.not.toThrow;
});

Expand All @@ -110,9 +181,10 @@ describe("r2rClient Integration Tests", () => {
).resolves.not.toThrow();
});

// TODO: Fix this test
// test("Delete User", async () => {
// const currentUser = await client.user();
// await expect(client.deleteUser(currentUser.id, "new_password")).resolves.not.toThrow();
// });
test("Delete User", async () => {
const currentUser = await client.user();
await expect(
client.deleteUser(currentUser.results.id, "new_password"),
).resolves.not.toThrow();
});
});
12 changes: 6 additions & 6 deletions js/sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion js/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
"author": "",
"license": "ISC",
"dependencies": {
"@jest/globals": "^29.7.0",
"axios": "^1.7.4",
"form-data": "^4.0.0",
"posthog-js": "^1.155.4",
"posthog-node": "^4.1.0",
"uuid": "^10.0.0"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/jest": "^29.5.13",
"@types/node": "^20.14.15",
"@types/uuid": "^10.0.0",
"jest": "^29.7.0",
Expand Down
13 changes: 8 additions & 5 deletions js/sdk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4740935

Please sign in to comment.