Skip to content

Commit 193bfd3

Browse files
committed
fix: avoid stale workspace metadata reuse
1 parent bfceb0d commit 193bfd3

4 files changed

Lines changed: 47 additions & 2 deletions

File tree

src/plugins/manifest-model-id-normalization.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ describe("manifest model id normalization", () => {
220220
expect(normalizeDemoModel()).toBe("bravo/demo-model");
221221
});
222222

223+
it("does not reuse workspace-scoped current metadata without a workspace context", () => {
224+
setCurrentPluginMetadataSnapshot(
225+
createCurrentSnapshot({
226+
manifestHash: "alpha",
227+
prefix: "alpha",
228+
workspaceDir: "/workspace/a",
229+
}),
230+
{ config: {}, env: process.env },
231+
);
232+
233+
expect(normalizeDemoModel()).toBeUndefined();
234+
});
235+
223236
it("reflects manifest edits and state-dir changes on the next lookup", () => {
224237
const stateDirA = makeTempDir();
225238
const pluginDirA = path.join(stateDirA, "extensions", "normalizer");

src/plugins/manifest-model-id-normalization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function resolveMetadataSnapshotForPolicies(
4646
const current = getCurrentPluginMetadataSnapshot({
4747
config: params.config,
4848
env,
49-
...(workspaceDir !== undefined ? { workspaceDir } : { allowWorkspaceScopedSnapshot: true }),
49+
workspaceDir,
5050
});
5151
if (current) {
5252
return { snapshot: current, cacheable: true };

src/plugins/setup-registry.runtime.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,38 @@ describe("setup-registry runtime fallback", () => {
225225
expect(loadPluginMetadataSnapshotMock).not.toHaveBeenCalled();
226226
});
227227

228+
it("does not reuse workspace-scoped current metadata without a workspace context", async () => {
229+
loadPluginMetadataSnapshotMock.mockReturnValue({
230+
index: {
231+
diagnostics: [],
232+
plugins: [],
233+
},
234+
plugins: [],
235+
});
236+
237+
const { __testing, resolvePluginSetupCliBackendRuntime } =
238+
await import("./setup-registry.runtime.js");
239+
__testing.resetRuntimeState();
240+
__testing.setRuntimeModuleForTest(null);
241+
242+
setCurrentPluginMetadataSnapshot(
243+
createCurrentSnapshot({
244+
manifestHash: "alpha",
245+
cliBackends: ["Codex-CLI"],
246+
workspaceDir: "/workspace/a",
247+
}),
248+
{ config: {}, env: process.env },
249+
);
250+
251+
expect(
252+
resolvePluginSetupCliBackendRuntime({ backend: "codex-cli", config: {} }),
253+
).toBeUndefined();
254+
expect(loadPluginMetadataSnapshotMock).toHaveBeenCalledWith({
255+
config: {},
256+
env: process.env,
257+
});
258+
});
259+
228260
it("preserves fail-closed setup lookup when the runtime module explicitly declines to resolve", async () => {
229261
loadPluginMetadataSnapshotMock.mockReturnValue({
230262
index: {

src/plugins/setup-registry.runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function resolveMetadataSnapshotForSetupCliBackends(
6060
const current = getCurrentPluginMetadataSnapshot({
6161
config: params.config,
6262
env,
63-
...(workspaceDir !== undefined ? { workspaceDir } : { allowWorkspaceScopedSnapshot: true }),
63+
workspaceDir,
6464
});
6565
if (current) {
6666
return { snapshot: current, cacheable: true };

0 commit comments

Comments
 (0)