Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/models-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
46 changes: 46 additions & 0 deletions packages/core/test/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
Loading