fix(plan-mode): compared canonical local urls for scan membership
The scan-membership test used a raw string includes, so a resumed single-slash local:/ state path failed to match the scanner's local:// entry and wrongly gained precedence over a newer draft. Normalize both sides via normalizeLocalScheme before comparing. Fixes #6569
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
resolveApprovedPlan,
|
||||
resolvePlanTitle,
|
||||
} from "@oh-my-pi/pi-coding-agent/plan-mode/approved-plan";
|
||||
import { normalizeLocalScheme } from "@oh-my-pi/pi-coding-agent/tools/path-utils";
|
||||
|
||||
describe("planFileUrlForSlug", () => {
|
||||
it("maps a slug to its local plan URL", () => {
|
||||
@@ -62,6 +63,28 @@ describe("resolveApprovedPlan", () => {
|
||||
expect(result.planContent).toContain("New plan");
|
||||
});
|
||||
|
||||
it("treats a single-slash state URL as in-scan and prefers the newer draft", async () => {
|
||||
// Mirror the real reader: canonicalize the local scheme before lookup, so a
|
||||
// `local:/…` state path resolves the same file as the scanner's `local://…`.
|
||||
const canonical = (files: Record<string, string>) => {
|
||||
const map: Record<string, string> = {};
|
||||
for (const url in files) map[normalizeLocalScheme(url)] = files[url];
|
||||
return async (url: string) => map[normalizeLocalScheme(url)] ?? null;
|
||||
};
|
||||
const result = await resolveApprovedPlan({
|
||||
suppliedTitle: undefined,
|
||||
// Resumed sessions can persist the accepted single-slash spelling.
|
||||
statePlanFilePath: "local:/completed-plan.md",
|
||||
readPlan: canonical({
|
||||
"local://completed-plan.md": "# Completed\n\nOld plan",
|
||||
"local://new-draft-plan.md": "# New\n\nNew plan",
|
||||
}),
|
||||
listPlanFiles: async () => ["local://new-draft-plan.md", "local://completed-plan.md"],
|
||||
});
|
||||
expect(result.planFilePath).toBe("local://new-draft-plan.md");
|
||||
expect(result.planContent).toContain("New plan");
|
||||
});
|
||||
|
||||
it("keeps a state plan the scan can't see ahead of older scanned artifacts", async () => {
|
||||
const result = await resolveApprovedPlan({
|
||||
suppliedTitle: undefined,
|
||||
|
||||
Reference in New Issue
Block a user