From f06dfae864370c4e284bf434059e1c86682e938f Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sat, 10 Aug 2024 22:40:50 -0400 Subject: [PATCH] branch tests for planning layer --- core/test/indexing/CodebaseIndexer.test.ts | 37 +++++++++++++++++++--- core/test/testUtils/testDir.ts | 3 +- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/core/test/indexing/CodebaseIndexer.test.ts b/core/test/indexing/CodebaseIndexer.test.ts index 7e92d0865..1a36b76d3 100644 --- a/core/test/indexing/CodebaseIndexer.test.ts +++ b/core/test/indexing/CodebaseIndexer.test.ts @@ -1,4 +1,5 @@ import { jest } from "@jest/globals"; +import { execSync } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; import { ConfigHandler } from "../../config/ConfigHandler.js"; @@ -128,11 +129,13 @@ describe("CodebaseIndexer", () => { removeTag: number, del: number, ) { - const results = await getIndexPlan(); - expect(results.compute).toHaveLength(compute); - expect(results.addTag).toHaveLength(addTag); - expect(results.removeTag).toHaveLength(removeTag); - expect(results.del).toHaveLength(del); + const plan = await getIndexPlan(); + console.log("PLAN: ", plan); + expect(plan.compute).toHaveLength(compute); + expect(plan.addTag).toHaveLength(addTag); + expect(plan.removeTag).toHaveLength(removeTag); + expect(plan.del).toHaveLength(del); + return plan; } test("should index test folder without problem", async () => { @@ -188,5 +191,29 @@ describe("CodebaseIndexer", () => { test("shouldn't index any files when nothing changed", async () => { await expectPlan(0, 0, 0, 0); + const updates = await refreshIndex(); + expect(updates.length).toBeGreaterThan(0); + }); + + test("should create git repo for testing", async () => { + execSync( + `cd ${TEST_DIR} && git init && git checkout -b main && git add -A && git commit -m "First commit"`, + ); + }); + + test.skip("should only re-index the changed files when changing branches", async () => { + execSync(`cd ${TEST_DIR} && git checkout -b test2`); + // Rewriting the file + addToTestDir([["test.ts", "// This is different"]]); + + // Should re-compute test.ts, but just re-tag the .py file + await expectPlan(1, 1, 0, 0); + + execSync(`cd ${TEST_DIR} && git add -A && git commit -m "Change .ts file"`); + }); + + test.skip("shouldn't re-index anything when changing back to original branch", async () => { + execSync(`cd ${TEST_DIR} && git checkout main`); + await expectPlan(0, 0, 0, 0); }); }); diff --git a/core/test/testUtils/testDir.ts b/core/test/testUtils/testDir.ts index 094086ebd..557906cef 100644 --- a/core/test/testUtils/testDir.ts +++ b/core/test/testUtils/testDir.ts @@ -1,7 +1,8 @@ import fs from "fs"; import path from "path"; -export const TEST_DIR = path.join(__dirname, "testDir"); +// Want this outside of the git repository so we can change branches in tests +export const TEST_DIR = path.join(__dirname, "..", "..", "testDir"); export function setUpTestDir() { if (fs.existsSync(TEST_DIR)) {