fix(projects): retain archived reference errors

This commit is contained in:
Mohamed Boudra
2026-07-29 10:09:43 +00:00
parent 0060c88399
commit 1ff152edcd
2 changed files with 21 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
import { describe, expect, test, vi } from "vitest";
import { describe, expect, test } from "vitest";
import type { PersistedProjectRecord } from "./workspace-registry.js";
import { resolveProjectReference } from "./project-reference.js";
@@ -36,12 +36,29 @@ describe("resolveProjectReference", () => {
rootPath: "/new/app",
});
const registry = {
get: vi.fn().mockResolvedValue(archivedLegacyProject),
list: vi.fn().mockResolvedValue([archivedLegacyProject, activeProject]),
get: async () => archivedLegacyProject,
list: async () => [archivedLegacyProject, activeProject],
};
await expect(resolveProjectReference(reference, registry, ["/new/app"])).resolves.toEqual(
activeProject,
);
});
test("preserves an archived direct project when there is no active replacement", async () => {
const archivedProject = project({
projectId: "archived-project-id",
projectKey: "remote:github.com/acme/app",
rootPath: "/old/app",
archivedAt: "2026-02-01T00:00:00.000Z",
});
const registry = {
get: async () => archivedProject,
list: async () => [archivedProject],
};
await expect(resolveProjectReference(archivedProject.projectId, registry)).resolves.toEqual(
archivedProject,
);
});
});

View File

@@ -20,5 +20,5 @@ export async function resolveProjectReference(
);
if (matches.length === 1) return matches[0] ?? null;
}
return candidates.length === 1 ? (candidates[0] ?? null) : null;
return candidates.length === 1 ? (candidates[0] ?? null) : direct;
}