This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

197 lines
6.5 KiB
TypeScript

/**
* Integration Tests: Data Sources Routes
*
* Tests the /v1/data-sources endpoints:
* - GET /v1/data-sources - List data sources
* - POST /v1/data-sources - Create a data source (scrape URL)
* - GET /v1/data-sources/:id - Get data source details
* - DELETE /v1/data-sources/:id - Delete a data source
* - GET /v1/data-sources/:id/content - Get scraped content
* - PATCH /v1/data-sources/:id - Rename data source
*/
import { describe, it, expect, beforeAll, beforeEach } from "vitest";
import request from "supertest";
import type { Express } from "express";
import {
seedTestData,
createTestApp,
TEST_API_KEY,
mockProjects,
} from "../setup.js";
let app: Express;
beforeAll(async () => {
app = await createTestApp();
});
beforeEach(() => {
seedTestData();
});
describe("Data Sources Routes - /v1/data-sources", () => {
// ========================================================================
// GET /v1/data-sources - List data sources
// ========================================================================
describe("GET /v1/data-sources", () => {
it("should require authentication", async () => {
const res = await request(app).get("/v1/data-sources");
expect(res.status).toBe(401);
});
it("should return a list of data sources", async () => {
const res = await request(app)
.get("/v1/data-sources")
.set("X-API-Key", TEST_API_KEY);
expect(res.status).toBe(200);
expect(res.body).toHaveProperty("data");
expect(Array.isArray(res.body.data)).toBe(true);
expect(res.body).toHaveProperty("has_more");
});
});
// ========================================================================
// POST /v1/data-sources - Create data source
// ========================================================================
describe("POST /v1/data-sources", () => {
it("should require authentication", async () => {
const res = await request(app)
.post("/v1/data-sources")
.send({ url: "https://example.com" });
expect(res.status).toBe(401);
});
it("should create a new data source with a valid URL", async () => {
const res = await request(app)
.post("/v1/data-sources")
.set("X-API-Key", TEST_API_KEY)
.send({
url: "https://example.com/docs",
name: "Example Docs",
});
expect(res.status).toBe(201);
expect(res.body).toHaveProperty("id");
expect(res.body.id).toMatch(/^ds_/);
expect(res.body).toHaveProperty("url", "https://example.com/docs");
expect(res.body).toHaveProperty("created_at");
});
it("should return 400 when url is missing", async () => {
const res = await request(app)
.post("/v1/data-sources")
.set("X-API-Key", TEST_API_KEY)
.send({ name: "No URL" });
expect(res.status).toBe(400);
expect(res.body).toHaveProperty("error");
});
it("should return 400 for an invalid URL", async () => {
const res = await request(app)
.post("/v1/data-sources")
.set("X-API-Key", TEST_API_KEY)
.send({ url: "not-a-valid-url" });
expect(res.status).toBe(400);
expect(res.body).toHaveProperty("error");
});
});
// ========================================================================
// GET /v1/data-sources/:id - Get data source details
// ========================================================================
describe("GET /v1/data-sources/:id", () => {
it("should require authentication", async () => {
const res = await request(app).get("/v1/data-sources/proj_test_001");
expect(res.status).toBe(401);
});
it("should return data source details for existing project", async () => {
const res = await request(app)
.get("/v1/data-sources/proj_test_001")
.set("X-API-Key", TEST_API_KEY);
expect(res.status).toBe(200);
expect(res.body).toHaveProperty("id", "proj_test_001");
expect(res.body).toHaveProperty("name");
expect(res.body).toHaveProperty("status");
});
it("should return 404 for a non-existent data source", async () => {
const res = await request(app)
.get("/v1/data-sources/ds_nonexistent")
.set("X-API-Key", TEST_API_KEY);
expect(res.status).toBe(404);
});
});
// ========================================================================
// DELETE /v1/data-sources/:id - Delete data source
// ========================================================================
describe("DELETE /v1/data-sources/:id", () => {
it("should require authentication", async () => {
const res = await request(app).delete("/v1/data-sources/proj_test_001");
expect(res.status).toBe(401);
});
it("should delete an existing data source", async () => {
const res = await request(app)
.delete("/v1/data-sources/proj_test_001")
.set("X-API-Key", TEST_API_KEY);
expect(res.status).toBe(200);
expect(res.body).toHaveProperty("deleted", true);
expect(res.body).toHaveProperty("id", "proj_test_001");
});
it("should return 404 for a non-existent data source", async () => {
const res = await request(app)
.delete("/v1/data-sources/ds_nonexistent")
.set("X-API-Key", TEST_API_KEY);
expect(res.status).toBe(404);
});
});
// ========================================================================
// PATCH /v1/data-sources/:id - Rename data source
// ========================================================================
describe("PATCH /v1/data-sources/:id", () => {
it("should require authentication", async () => {
const res = await request(app)
.patch("/v1/data-sources/proj_test_001")
.send({ name: "Renamed" });
expect(res.status).toBe(401);
});
it("should rename an existing data source", async () => {
const res = await request(app)
.patch("/v1/data-sources/proj_test_001")
.set("X-API-Key", TEST_API_KEY)
.send({ name: "Renamed Data Source" });
expect(res.status).toBe(200);
expect(res.body).toHaveProperty("id", "proj_test_001");
expect(res.body).toHaveProperty("name", "Renamed Data Source");
expect(res.body).toHaveProperty("updated_at");
});
it("should return 404 for a non-existent data source", async () => {
const res = await request(app)
.patch("/v1/data-sources/ds_nonexistent")
.set("X-API-Key", TEST_API_KEY)
.send({ name: "Fail" });
expect(res.status).toBe(404);
});
});
});