diff --git a/packages/core/src/models-dev.ts b/packages/core/src/models-dev.ts index 54c197d1aa44..cc4b42635f3e 100644 --- a/packages/core/src/models-dev.ts +++ b/packages/core/src/models-dev.ts @@ -420,7 +420,7 @@ export const layer = (options?: Options) => yield* decodeCatalog(text) yield* writeCache(text, digest) yield* invalidate - yield* bus.publish(ModelsDev.Event.Refreshed, {}) + yield* bus.publish(ModelsDev.Event.Refreshed, {}, { global: true }) }), ) .pipe( diff --git a/packages/core/test/models.test.ts b/packages/core/test/models.test.ts index 20422913f6a9..2919c8c2b4e9 100644 --- a/packages/core/test/models.test.ts +++ b/packages/core/test/models.test.ts @@ -7,9 +7,12 @@ import { LayerNodePlatform } from "@opencode/util/effect/app-node-platform" import { LayerNode } from "@opencode/util/effect/layer-node" import { Bus } from "@opencode/core/bus" import { KV } from "@opencode/core/kv" +import { Location } from "@opencode/core/location" import { Model } from "@opencode/core/model" import { bodyDigest, ModelsDev } from "@opencode/core/models-dev" import { Provider } from "@opencode/core/provider" +import { AbsolutePath } from "@opencode/core/schema" +import { location } from "./fixture/location" import { it } from "./lib/effect" const cacheKey = "models-dev:catalog" @@ -485,6 +488,49 @@ describe("ModelsDev Service", () => { }), ) + it.live("refresh publishes Refreshed globally across locations", () => + Effect.gen(function* () { + const cache = makeCache() + writeCache(cache, fixture, Date.now() - 10 * 60 * 1000) + const state = yield* Ref.make({ ...initialState, body: JSON.stringify(fixture2) }) + yield* provided( + state, + cache, + Effect.gen(function* () { + const svc = yield* ModelsDev.Service + const bus = yield* Bus.Service + const refreshed = yield* bus + .subscribe(ModelsDev.Event.Refreshed) + .pipe( + Stream.take(1), + Stream.runCollect, + Effect.provideService( + Location.Service, + Location.Service.of(location({ directory: AbsolutePath.make("/other-location") })), + ), + Effect.forkScoped, + ) + .pipe( + Effect.flatMap((fiber) => + Effect.gen(function* () { + yield* Effect.yieldNow + yield* svc.refresh(true).pipe( + Effect.provideService( + Location.Service, + Location.Service.of(location({ directory: AbsolutePath.make("/initial-location") })), + ), + ) + return yield* Fiber.join(fiber) + }), + ), + ) + expect(refreshed.length).toBe(1) + expect(refreshed[0]?.location).toBeUndefined() + }), + ) + }), + ) + it.live("refresh(false) stays quiet when the fetched body matches the cached digest", () => Effect.gen(function* () { const cache = makeCache()