Initialize repository knowledge cache
This commit is contained in:
1 parent
14a30a3695
commit
2d50da41cd
3 files changed
+31
-2
No files matched your search
@@ -28,7 +28,9 @@ export async function loadRepositoryKnowledge(
|
||||
if (!isNotFoundError(error)) {
|
||||
throw error;
|
||||
}
|
||||
return normalizeKnowledge(EMPTY_KNOWLEDGE);
|
||||
const initial = normalizeKnowledge(EMPTY_KNOWLEDGE);
|
||||
await saveRepositoryKnowledgeCache(initial, runtimeDirectory);
|
||||
return initial;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -430,13 +430,25 @@ function validateAgentChangePath(relativePath: string): void {
|
||||
|
||||
async function assertConflictMarkersRemoved(root: string, conflictFiles: string[]): Promise<void> {
|
||||
for (const relativePath of conflictFiles) {
|
||||
const content = await fs.readFile(safeFilePath(root, relativePath), "utf8");
|
||||
const content = await fs.readFile(safeFilePath(root, relativePath), "utf8").catch((error: unknown) => {
|
||||
if (isFileNotFoundError(error)) {
|
||||
return undefined;
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
if (content === undefined) {
|
||||
continue;
|
||||
}
|
||||
if (/^(?:<<<<<<<|=======|>>>>>>>)(?: |$)/m.test(content)) {
|
||||
throw new Error(`Conflict markers remain in ${relativePath}.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isFileNotFoundError(error: unknown): boolean {
|
||||
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
||||
}
|
||||
|
||||
function safeFilePath(root: string, relativePath: string): string {
|
||||
if (path.isAbsolute(relativePath) || relativePath.split(/[\\/]/).includes("..")) {
|
||||
throw new Error(`Unsafe conflict path: ${relativePath}`);
|
||||
|
||||
@@ -31,6 +31,21 @@ test("repository knowledge persists in a repository-level cache file", async ()
|
||||
}
|
||||
});
|
||||
|
||||
test("loading an empty repository knowledge cache initializes the persisted file", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "ghbot-knowledge-initial-"));
|
||||
try {
|
||||
const knowledge = await loadRepositoryKnowledge(root);
|
||||
assert.match(knowledge, /repository can evolve/i);
|
||||
assert.equal(await loadRepositoryKnowledge(root), knowledge);
|
||||
assert.equal(
|
||||
await fs.readFile(path.join(root, ".ghbot-knowledge", "repository.md"), "utf8"),
|
||||
knowledge
|
||||
);
|
||||
} finally {
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("repository knowledge rejects credentials and oversized content", () => {
|
||||
assert.throws(
|
||||
() => validateRepositoryKnowledge("-----BEGIN PRIVATE KEY-----\nsecret"),
|
||||
|
||||
Reference in new issue
Block a user