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
3 changes: 3 additions & 0 deletions packages/core/src/flag/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export const Flag = {
get OPENCODE_DISABLE_PROJECT_CONFIG() {
return truthy("OPENCODE_DISABLE_PROJECT_CONFIG")
},
get OPENCODE_DISABLE_CONFIG_INSTALL() {
return truthy("OPENCODE_DISABLE_CONFIG_INSTALL")
},
get OPENCODE_EXPERIMENTAL_REFERENCES() {
return enabledByExperimental("OPENCODE_EXPERIMENTAL_REFERENCES")
},
Expand Down
2 changes: 2 additions & 0 deletions packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ const layer = Layer.effect(
],
})
.pipe(
// Without this guard, each start with an empty cache downloads the full package version list.
Effect.when(Effect.sync(() => !Flag.OPENCODE_DISABLE_CONFIG_INSTALL)),
Effect.exit,
Effect.tap((exit) =>
Exit.isFailure(exit)
Expand Down
31 changes: 30 additions & 1 deletion packages/opencode/test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ const configLayer = (
auth?: Layer.Layer<Auth.Service>
account?: Layer.Layer<Account.Service>
client?: HttpClient.HttpClient
npm?: Layer.Layer<Npm.Service>
} = {},
) =>
LayerNode.compile(LayerNode.group([Config.node, FSUtil.node, Env.node, CrossSpawnSpawner.node]), [
[Auth.node, options.auth ?? AuthTest.empty],
[Account.node, options.account ?? AccountTest.empty],
[Npm.node, NpmTest.noop],
[Npm.node, options.npm ?? NpmTest.noop],
[httpClient, Layer.succeed(HttpClient.HttpClient, options.client ?? unexpectedHttp)],
])

Expand Down Expand Up @@ -966,6 +967,34 @@ it.effect("installs dependencies in writable OPENCODE_CONFIG_DIR", () =>
}).pipe(Effect.provide(testInstanceStoreLayer), Effect.provide(LayerNode.compile(CrossSpawnSpawner.node))),
)

const installs: string[] = []
const recordedInstalls = testEffect(
configLayer({
npm: Layer.mock(Npm.Service)({ install: (dir) => Effect.sync(() => void installs.push(dir)) }),
}),
)

recordedInstalls.effect("skips the dependency install only when OPENCODE_DISABLE_CONFIG_INSTALL is set", () =>
Effect.gen(function* () {
const load = Effect.fnUntraced(function* (disabled: string | undefined) {
const dir = yield* tmpdirScoped()
const configDir = path.join(dir, "configdir")
yield* withProcessEnvs(
{ OPENCODE_CONFIG_DIR: configDir, OPENCODE_DISABLE_CONFIG_INSTALL: disabled },
Config.Service.use((svc) => svc.get().pipe(Effect.andThen(svc.waitForDependencies()))).pipe(
provideInstanceEffect(dir),
),
)
return configDir
})

const before = installs.length
yield* load("1")
expect(installs.length).toBe(before)
expect(installs).toContain(yield* load(undefined))
}).pipe(Effect.provide(testInstanceStoreLayer), Effect.provide(LayerNode.compile(CrossSpawnSpawner.node))),
)

// Note: deduplication and serialization of npm installs is now handled by the
// core Npm.Service (via EffectFlock). Those behaviors are tested in the core
// package's npm tests, not here.
Expand Down
Loading