Skip to content
Closed
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
10 changes: 6 additions & 4 deletions packages/pi-fff/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export function normalizePathConstraint(
if (path.isAbsolute(trimmed)) {
const relative = path.relative(cwd, trimmed).replaceAll(path.sep, "/");
if (relative === "") return null;
trimmed = relative;
if (relative.startsWith("../") || relative === ".." || path.isAbsolute(relative)) {
throw new Error(
`Path constraint must be relative to the workspace: ${pathConstraint}`,
);
// Outside the workspace — the relative path now starts with ../.
// Let it continue through glob collapsing so .agents/** still becomes
// ../other/.agents/ etc. FFF will return empty, which is the correct
// silent-fail behavior. Throwing here was a regression: agents
// legitimately search outside their workspace.
}
trimmed = relative;
}

if (trimmed === "." || trimmed === "./") return null;
Expand Down
21 changes: 15 additions & 6 deletions packages/pi-fff/test/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ describe("path constraint normalization", () => {
);
});

test("rejects absolute paths outside the workspace", () => {
expect(() => normalizePathConstraint("/tmp/other/.agents/**", cwd)).toThrow(
"Path constraint must be relative to the workspace",
test("passes through absolute paths outside the workspace as relative", () => {
expect(normalizePathConstraint("/tmp/other/.agents/**", cwd)).toBe(
"../other/.agents/",
);
expect(normalizePathConstraint("/home/devkit/.config/nvim/**", cwd)).toBe(
"../../home/devkit/.config/nvim/",
);
});

Expand Down Expand Up @@ -48,18 +51,24 @@ describe("path constraint normalization", () => {
});

test("converts absolute in-workspace file path to repo-relative", () => {
expect(normalizePathConstraint("/tmp/workspace/src/main.rs", cwd)).toBe("src/main.rs");
expect(normalizePathConstraint("/tmp/workspace/src/main.rs", cwd)).toBe(
"src/main.rs",
);
expect(buildQuery("/tmp/workspace/src/main.rs", "needle", undefined, cwd)).toBe(
"src/main.rs needle",
);
});

test("converts absolute in-workspace directory (without trailing slash) to repo-relative", () => {
expect(normalizePathConstraint("/tmp/workspace/src", cwd)).toBe("src/");
expect(buildQuery("/tmp/workspace/src", "needle", undefined, cwd)).toBe("src/ needle");
expect(buildQuery("/tmp/workspace/src", "needle", undefined, cwd)).toBe(
"src/ needle",
);
});

test("converts absolute in-workspace glob path to repo-relative glob", () => {
expect(normalizePathConstraint("/tmp/workspace/src/**/*.ts", cwd)).toBe("src/**/*.ts");
expect(normalizePathConstraint("/tmp/workspace/src/**/*.ts", cwd)).toBe(
"src/**/*.ts",
);
});
});
Loading