papertrail/backend/engines/R2R/js/sdk/__tests__/ChunksIntegrationSuperUser.test.ts
caelum0x 174222bcaa feat: Builder-Track named-user tools, bio + evidence-intelligence platform, Apache-2.0
Builds PaperTrail from the base skeleton into a full evidence-verification platform
for the "Built with Claude: Life Sciences" hackathon (Builder Track).

New named-user features (Build Beyond the Bench):
- Lab Notebook Companion — rough bench notes -> structured, searchable, grounded
  experiment records (lib/labNotebook, /console/lab-notebook, migration 0059)
- Clinical Trial Matcher — de-identified patient notes -> ranked eligible
  ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning
  (lib/trialMatcher, /console/trial-matcher, migrations 0060)

Platform:
- Deterministic verification moat (biostats recompute, exact-span grounding)
- 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar,
  PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier)
- Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise
  governance (RBAC, /api/v1 gateway, metering, audit chain, retention)
- 17 OSS projects assimilated into native TypeScript on our stack (backend/engines
  retained + credited in NOTICE)
- Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site
- Next.js 16 upgrade, benchmark harness (honest smoke-test caveat)

Licensing: Apache-2.0 (LICENSE + NOTICE).
2026-07-10 16:23:13 +03:00

173 lines
4.9 KiB
TypeScript

import { r2rClient } from "../src/index";
import { describe, test, beforeAll, expect } from "@jest/globals";
const baseUrl = "http://localhost:7272";
describe("r2rClient V3 Collections Integration Tests", () => {
let client: r2rClient;
let documentId: string;
let chunkId: string;
let collectionId: string;
beforeAll(async () => {
client = new r2rClient(baseUrl);
await client.users.login({
email: "admin@example.com",
password: "change_me_immediately",
});
});
test("Create a chunk", async () => {
const response = await client.documents.create({
chunks: ["Hello, world!"],
runWithOrchestration: false,
});
documentId = response.results.documentId;
expect(response.results).toEqual({
documentId: expect.any(String),
message: "Document created and ingested successfully.",
taskId: null,
});
});
test("Create a document from chunks with an id", async () => {
const response = await client.documents.create({
id: "1fb70f3b-37eb-4325-8c83-694a03144a67",
chunks: ["Hallo, Welt!"],
});
expect(response.results.documentId).toBe(
"1fb70f3b-37eb-4325-8c83-694a03144a67",
);
expect(response.results.message).toBe(
"Document created and ingested successfully.",
);
expect(response.results.taskId).toBeNull();
});
test("Retrieve document's chunks", async () => {
const response = await client.documents.listChunks({
id: documentId,
});
chunkId = response.results[0]?.id;
expect(chunkId).toBeDefined();
expect(response.results[0]).toMatchObject({
id: expect.any(String),
documentId: expect.any(String),
text: expect.any(String),
collectionIds: expect.any(Array),
metadata: expect.any(Object),
});
});
test("Retrieve a chunk", async () => {
const response = await client.chunks.retrieve({
id: chunkId,
});
expect(response.results).toMatchObject({
id: expect.any(String),
documentId: expect.any(String),
text: expect.any(String),
collectionIds: expect.any(Array),
metadata: expect.any(Object),
});
});
test("Update a chunk", async () => {
const response = await client.chunks.update({
id: chunkId,
text: "Hello, world! How are you?",
});
expect(response.results).toMatchObject({
id: expect.any(String),
documentId: expect.any(String),
text: "Hello, world! How are you?",
collectionIds: expect.any(Array),
metadata: expect.any(Object),
});
});
test("Retrieve a chunk after update and check text", async () => {
const response = await client.chunks.retrieve({
id: chunkId,
});
expect(response.results.text).toBe("Hello, world! How are you?");
});
test("List chunks", async () => {
const response = await client.chunks.list();
expect(response.results).toBeDefined();
});
test("Delete a chunk", async () => {
const response = await client.chunks.delete({
id: chunkId,
});
expect(response.results.success).toBe(true);
});
test("Delete a document", async () => {
const response = await client.documents.delete({
id: "1fb70f3b-37eb-4325-8c83-694a03144a67",
});
expect(response.results.success).toBe(true);
});
test("Create a document assigned to a new collection", async () => {
const collectionResponse = await client.collections.create({
name: "Test Collection",
description: "A collection for testing purposes",
});
collectionId = collectionResponse.results.id;
console.log("Collection ID:", collectionId);
const documentResponse = await client.documents.create({
chunks: ["This is a test document."],
collectionIds: [collectionId],
});
documentId = documentResponse.results.documentId;
expect(documentResponse.results.documentId).toBeDefined();
expect(documentResponse.results.message).toBe(
"Document created and ingested successfully.",
);
expect(documentResponse.results.taskId).toBeNull();
});
test("Retrieve a document assigned to a collection", async () => {
const response = await client.documents.list({});
console.log(response.results);
expect(response.results).toBeDefined();
expect(response.results.length).toBeGreaterThan(0);
expect(response.results[0].collectionIds).toContain(collectionId);
});
test("Delete the collection", async () => {
const response = await client.collections.delete({
id: collectionId,
});
expect(response.results.success).toBe(true);
});
test("Delete the document created in the collection", async () => {
const response = await client.documents.delete({
id: documentId,
});
expect(response.results.success).toBe(true);
});
// test("Delete a chunk that does not exist", async () => {
// await expect(client.chunks.delete({ id: chunkId })).rejects.toThrow(
// /Status 404/,
// );
// });
});