fix(slice-17): bypass slice cache on focus refetch

This commit is contained in:
mvschwarz committed 2026-05-11 06:53:21 -07:00
1 parent 189112a3de
commit 047bcc71ed
3 files changed
+27 -1

No files matched your search

+4
View File
@@ -49,6 +49,10 @@ export function slicesRoutes(): Hono {
hint: `Unknown filter '${filter}'. Allowed: ${[...VALID_FILTERS].sort().join(", ")}.`,
}, 400);
}
const refresh = c.req.query("refresh");
if (refresh === "1" || refresh === "true") {
deps.indexer.invalidate();
}
const all = deps.indexer.list();
let filtered = filter === "all" ? all : all.filter((s) => s.status === filter);
// Workflows in Spec Library v0: optional lens filter — narrow to
@@ -357,4 +357,22 @@ describe("PL-slice-story-view-v0 slices routes", () => {
expect(res.status).toBe(503);
});
});
describe("GET /api/slices?refresh=1", () => {
it("drops the listing cache before returning the list", async () => {
writeSlice(slicesRoot, "before-slice", { "README.md": "---\n---\n" });
const first = await app.request("/api/slices");
const firstList = (await first.json()) as { slices: Array<{ name: string }> };
expect(firstList.slices.map((s) => s.name)).toEqual(["before-slice"]);
writeSlice(slicesRoot, "after-slice", { "README.md": "---\n---\n" });
const stale = await app.request("/api/slices");
const staleList = (await stale.json()) as { slices: Array<{ name: string }> };
expect(staleList.slices.map((s) => s.name)).toEqual(["before-slice"]);
const fresh = await app.request("/api/slices?refresh=1");
const freshList = (await fresh.json()) as { slices: Array<{ name: string }> };
expect(freshList.slices.map((s) => s.name).sort()).toEqual(["after-slice", "before-slice"]);
});
});
});
+5 -1
View File
@@ -54,7 +54,11 @@ async function fetchSlicesList(
filter: SliceFilter,
boundToWorkflow: BoundToWorkflowFilter | null,
): Promise<SliceListResponse | SlicesUnavailable> {
const params = new URLSearchParams({ filter });
// Explorer auto-show needs a daemon-side cache bypass as well as a
// React Query refetch. Otherwise a focus refetch can still receive the
// indexer's stale in-memory listing immediately after a slice folder is
// created.
const params = new URLSearchParams({ filter, refresh: "1" });
if (boundToWorkflow) {
params.set("boundToWorkflow", `${boundToWorkflow.specName}:${boundToWorkflow.specVersion}`);
}