@@ -2,6 +2,7 @@ import path from "path"
22import fs from "fs/promises"
33import { describe , expect , test } from "bun:test"
44import { Effect , Fiber , Layer , Logger , Schema , Stream } from "effect"
5+ import { fromEnv , layer } from "effect/ConfigProvider"
56import { FastCheck } from "effect/testing"
67import { Config } from "@opencode/core/config"
78import { Directory , Document , Event , Info } from "@opencode/schema/config"
@@ -45,6 +46,7 @@ function testLayer(
4546 credentialNode = emptyCredentialNode ,
4647 wellknownNode = emptyWellknownNode ,
4748 options ?: Config . Options ,
49+ env : Record < string , string > = { } ,
4850) {
4951 const locationLayer = Layer . succeed (
5052 Location . Service ,
@@ -63,9 +65,10 @@ function testLayer(
6365 WellKnown . node . replace ( wellknownNode ) ,
6466 Watcher . node . replace ( watcher ) ,
6567 ] )
66- // Merge the watcher layer by reference so Watcher.Test resolves to the same
67- // memoized instance the built graph uses.
68- return Layer . mergeAll ( built , watcher )
68+ // Pin the config environment (empty by default) so discovery never reads the
69+ // ambient process environment. Merge the watcher layer by reference so
70+ // Watcher.Test resolves to the same memoized instance the built graph uses.
71+ return Layer . mergeAll ( built . pipe ( Layer . provide ( layer ( fromEnv ( { env } ) ) ) ) , watcher )
6972}
7073
7174const provider = {
@@ -1630,11 +1633,9 @@ describe("Config", () => {
16301633
16311634 return yield * Effect . gen ( function * ( ) {
16321635 const config = yield * Config . Service
1633- const entries = ( yield * config . entries ( ) ) . filter (
1634- ( entry ) => ! entry . path || inFixture ( tmp . path , entry . path ) ,
1635- )
1636- expect ( entries . filter ( ( entry ) => entry . type === "claude" ) . map ( ( entry ) => entry . path ) ) . toEqual ( [ ] )
1637- expect ( entries . filter ( ( entry ) => entry . type === "agents" ) . map ( ( entry ) => entry . path ) ) . toEqual ( [
1636+ const compatibility = yield * config . compatibility ! ( )
1637+ expect ( compatibility . claude . filter ( ( item ) => inFixture ( tmp . path , item ) ) ) . toEqual ( [ ] )
1638+ expect ( compatibility . agents . filter ( ( item ) => inFixture ( tmp . path , item ) ) ) . toEqual ( [
16381639 AbsolutePath . make ( globalAgents ) ,
16391640 AbsolutePath . make ( path . join ( directory , ".agents" ) ) ,
16401641 ] )
@@ -1649,4 +1650,72 @@ describe("Config", () => {
16491650 } ) ,
16501651 ) ,
16511652 )
1653+
1654+ it . live ( "excludes claude sources when OPENCODE_DISABLE_CLAUDE_CODE is set" , ( ) =>
1655+ Effect . acquireRelease (
1656+ Effect . promise ( ( ) => tmpdir ( ) ) ,
1657+ ( tmp ) => Effect . promise ( ( ) => tmp [ Symbol . asyncDispose ] ( ) ) ,
1658+ ) . pipe (
1659+ Effect . flatMap ( ( tmp ) => {
1660+ const global = path . join ( tmp . path , "global" )
1661+ const directory = path . join ( tmp . path , "repo" )
1662+ const globalAgents = path . join ( global , "home" , ".agents" )
1663+ const globalClaude = path . join ( global , "home" , ".claude" )
1664+ return Effect . gen ( function * ( ) {
1665+ yield * Effect . promise ( async ( ) => {
1666+ await fs . mkdir ( global , { recursive : true } )
1667+ await fs . mkdir ( globalAgents , { recursive : true } )
1668+ await fs . mkdir ( globalClaude , { recursive : true } )
1669+ await fs . mkdir ( directory , { recursive : true } )
1670+ await fs . mkdir ( path . join ( directory , ".agents" ) , { recursive : true } )
1671+ } )
1672+
1673+ yield * Effect . gen ( function * ( ) {
1674+ const config = yield * Config . Service
1675+ const compatibility = yield * config . compatibility ! ( )
1676+ expect ( compatibility . claude . filter ( ( item ) => inFixture ( tmp . path , item ) ) ) . toEqual ( [ ] )
1677+ expect ( compatibility . agents . filter ( ( item ) => inFixture ( tmp . path , item ) ) ) . toEqual ( [
1678+ AbsolutePath . make ( globalAgents ) ,
1679+ AbsolutePath . make ( path . join ( directory , ".agents" ) ) ,
1680+ ] )
1681+ } ) . pipe (
1682+ Effect . provide (
1683+ testLayer (
1684+ directory ,
1685+ global ,
1686+ directory ,
1687+ undefined ,
1688+ Watcher . testLayer ,
1689+ emptyCredentialNode ,
1690+ emptyWellknownNode ,
1691+ undefined ,
1692+ { OPENCODE_DISABLE_CLAUDE_CODE : "1" } ,
1693+ ) ,
1694+ ) ,
1695+ )
1696+
1697+ // Proves the empty claude list above comes from the flag, not a broken fixture.
1698+ yield * Effect . gen ( function * ( ) {
1699+ const config = yield * Config . Service
1700+ const compatibility = yield * config . compatibility ! ( )
1701+ expect ( compatibility . claude . filter ( ( item ) => inFixture ( tmp . path , item ) ) ) . toEqual ( [
1702+ AbsolutePath . make ( globalClaude ) ,
1703+ ] )
1704+ } ) . pipe (
1705+ Effect . provide (
1706+ testLayer (
1707+ directory ,
1708+ global ,
1709+ directory ,
1710+ undefined ,
1711+ Watcher . testLayer ,
1712+ emptyCredentialNode ,
1713+ emptyWellknownNode ,
1714+ ) ,
1715+ ) ,
1716+ )
1717+ } )
1718+ } ) ,
1719+ ) ,
1720+ )
16521721} )
0 commit comments