Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/config-extends/src/resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,40 @@ describe("resolve", () => {
});
});

it("returns the document as-is when optional autoExtend discovers the document itself", async () => {
const fs = createMemFs({
"/workspace/review.yaml": "title: Document"
});

await expect(
resolve(
[
{
source: "document",
filePath: "/workspace/review.yaml",
content: "title: Document"
},
{
source: "base",
path: "/workspace"
}
],
{
fs,
autoExtend: true
}
)
).resolves.toEqual({
data: {
title: "Document"
},
sources: {
title: "document"
},
chain: ["/workspace/review.yaml"]
});
});

it("does not auto-resolve when the document explicitly disables extends", async () => {
const fs = createMemFs({
"/bases/review.yaml": "prompt: Base prompt"
Expand Down
4 changes: 4 additions & 0 deletions packages/config-extends/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ async function resolveBaseChain({
}

if (visited.has(discoveredBase.filePath)) {
if (optional) {
return undefined;
}

throw new Error(
`Circular extends detected.\nVisited files:\n- ${[...visited, discoveredBase.filePath].join("\n- ")}`
);
Expand Down
20 changes: 20 additions & 0 deletions packages/poe-code-config/src/poe-code-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,26 @@ describe("store", () => {
});
});

it("uses only the global document when project config resolves to the global path", async () => {
const fs = createMockFs(
{
"~/.poe-code/config.json": `${JSON.stringify(
{
extends: true,
core: { apiKey: "global-key" }
},
null,
2
)}\n`
},
homeDir
);

await expect(readMergedDocument(fs, configPath, configPath)).resolves.toEqual({
core: { apiKey: "global-key" }
});
});

it("resolves the project config path from the current working directory", () => {
expect(resolveProjectConfigPath("/workspace/app")).toBe("/workspace/app/.poe-code/config.json");
});
Expand Down
2 changes: 1 addition & 1 deletion packages/poe-code-config/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function readMergedDocument(
projectPath?: string
): Promise<ConfigDocument> {
const globalDocument = await readStoredDocument(fs, globalPath);
if (!projectPath) {
if (!projectPath || projectPath === globalPath) {
return globalDocument.data;
}

Expand Down
Loading