From 0e8e8627c935bf72b5bfdfd2cfc440023196ca53 Mon Sep 17 00:00:00 2001 From: RaghwendraSingh Date: Tue, 1 Dec 2026 15:54:54 +0530 Subject: [PATCH 1/5] test: the suite does not start real `@opencode-ai/plugin` installs A test that writes a tool or plugin file into a config dir makes the app start an `npm install` of `@opencode-ai/plugin` there. The install runs inside the test process and is not awaited, so it outlives the test. Several pile up, starve the event loop, and the tests that run next time out or the job is killed. This made the `TypeScript` shards fail on `main` and every PR from 2026-12-01. - `ConfigPlugin.shouldInstallDependencies` returns false when `ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1`. Without the variable nothing changes. - `test/preload.ts` sets it for the suite. - The config and TUI tests that check when an install is requested clear it. They use a recording installer and never reach the network. - One new test covers the switch. Co-Authored-By: Claude Fable 5.2 --- packages/opencode/src/config/plugin.ts | 9 ++++++++- packages/opencode/test/config/config.test.ts | 11 +++++++++++ packages/opencode/test/config/tui.test.ts | 5 +++-- packages/opencode/test/preload.ts | 6 ++++++ .../skill/release-v0.11.1-adversarial.test.ts | 19 ++++++++++++++++++- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/packages/opencode/src/config/plugin.ts b/packages/opencode/src/config/plugin.ts index 7cc49f4f04..341f0f6464 100644 --- a/packages/opencode/src/config/plugin.ts +++ b/packages/opencode/src/config/plugin.ts @@ -81,11 +81,18 @@ export function needsDependencies(dir: string, plugins: readonly ConfigPluginV1. // PURE mode skips dependency installs entirely: isolated-HOME environments and subprocess tests run // with no package cache, so the install attempt fails, npm retries, and the process hangs past exit. // Fold that check in here so both call sites (Config and TuiConfig) stay in sync. +/** `ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1` skips the install. The test suite sets it: an install + * started by one test is not awaited, outlives the test, and runs inside the test process. */ +function installDisabled(): boolean { + const v = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]?.toLowerCase() + return v === "true" || v === "1" +} + export function shouldInstallDependencies( dir: string, plugins: readonly ConfigPluginV1.Spec[] | undefined, ): boolean { - return !Flag.OPENCODE_PURE && needsDependencies(dir, plugins) + return !Flag.OPENCODE_PURE && !installDisabled() && needsDependencies(dir, plugins) } // altimate_change end diff --git a/packages/opencode/test/config/config.test.ts b/packages/opencode/test/config/config.test.ts index f32e56f635..9ad57c3fce 100644 --- a/packages/opencode/test/config/config.test.ts +++ b/packages/opencode/test/config/config.test.ts @@ -1063,6 +1063,17 @@ const loadConfigDirWithDependencies = ( describe("config dir plugin dependency install", () => { const npmIt = testEffect(Layer.mergeAll(infra, FSUtil.defaultLayer)) + // The suite's preload switches the background install off. These cases check when the app + // asks for one, through a recording installer that never reaches the network. + let installOff: string | undefined + beforeEach(() => { + installOff = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] + delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] + }) + afterEach(() => { + if (installOff !== undefined) process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = installOff + }) + npmIt.effect("skips the install in a bare writable config dir but still writes .gitignore", () => Effect.gen(function* () { const npm = recordingNpm() diff --git a/packages/opencode/test/config/tui.test.ts b/packages/opencode/test/config/tui.test.ts index 306b0cdb37..f84da7087b 100644 --- a/packages/opencode/test/config/tui.test.ts +++ b/packages/opencode/test/config/tui.test.ts @@ -93,8 +93,9 @@ const getTuiPluginOrigins = (directory: string) => // altimate_change start — cover the TUI call site independently from server Config. for (const source of ["bare", "npm", "file", "tool", "node_modules", "outside"] as const) { for (const pure of [false, true]) { + // The suite's preload switches the install off; this gate is checked through a recording installer. it.instance(`tui dependency install gate: ${source}${pure ? " (PURE)" : ""}`, () => - withEnv( + withEnv("ALTIMATE_DISABLE_DEPENDENCY_INSTALL", "0", withEnv( "OPENCODE_PURE", pure ? "1" : "0", withCleanState( @@ -130,7 +131,7 @@ for (const source of ["bare", "npm", "file", "tool", "node_modules", "outside"] expect(installs).toEqual(!pure && ["file", "tool", "node_modules"].includes(source) ? [local] : []) }), ), - ), + )), ) } } diff --git a/packages/opencode/test/preload.ts b/packages/opencode/test/preload.ts index 1367e86df2..6f1361d58d 100644 --- a/packages/opencode/test/preload.ts +++ b/packages/opencode/test/preload.ts @@ -50,6 +50,12 @@ process.env["ALTIMATE_DISABLE_WORKSPACE"] = "1" // keychain); tests must never write there. Credential-store tests inject a backend instead. process.env["ALTIMATE_CODE_DISABLE_OS_CREDENTIAL_STORE"] = "1" // altimate_change end +// altimate_change start — a test that writes a tool or plugin file into a config dir makes the +// app start a real `npm install` of `@opencode-ai/plugin` there, in this process and not awaited. +// It outlives the test: several pile up, starve the event loop, and the tests that run next time +// out. Tests that check the install itself clear this and inject an installer. +process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = "1" +// altimate_change end // Set test home directory to isolate tests from user's actual home directory // This prevents tests from picking up real user configs/skills from ~/.claude/skills diff --git a/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts b/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts index 5a805bdb51..e9ba2c086f 100644 --- a/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts +++ b/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts @@ -249,7 +249,24 @@ describe("shouldInstallDependencies — Flag.OPENCODE_PURE fold", () => { fs.mkdirSync(path.join(dir, "node_modules")) saved = process.env[ENV_KEY] delete process.env[ENV_KEY] - expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true) + // The suite's preload switches the install off; this case is about the product default. + const off = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] + delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] + try { + expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true) + } finally { + if (off !== undefined) process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = off + } + }) + + test("ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1 suppresses installation, as the test suite's preload does", () => { + const dir = tmp() + fs.mkdirSync(path.join(dir, "node_modules")) + saved = process.env[ENV_KEY] + delete process.env[ENV_KEY] + expect(process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]).toBe("1") + expect(ConfigPlugin.needsDependencies(dir, undefined)).toBe(true) + expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(false) }) }) From 65ccba1d53fb897bd2ed48834b6f3c32935ea085 Mon Sep 17 00:00:00 2001 From: RaghwendraSingh Date: Tue, 1 Dec 2026 16:04:31 +0530 Subject: [PATCH 2/5] test: read the install switch with the shared kill-switch parser, and document it - `ALTIMATE_DISABLE_DEPENDENCY_INSTALL` is read with `killSwitchSet`, as the other `ALTIMATE_DISABLE_*` switches are: any value but empty, `0` or `false` turns the install off. - Its test sets and restores the variable itself, and covers both sides. - The variable has a row in the CLI environment table. Co-Authored-By: Claude Fable 5.2 --- docs/docs/usage/cli.md | 1 + packages/opencode/src/config/plugin.ts | 5 ++--- .../skill/release-v0.11.1-adversarial.test.ts | 20 +++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docs/docs/usage/cli.md b/docs/docs/usage/cli.md index 422f0c02d3..fd49a08163 100644 --- a/docs/docs/usage/cli.md +++ b/docs/docs/usage/cli.md @@ -137,6 +137,7 @@ Configuration can be controlled via environment variables: | `ALTIMATE_CLI_DISABLE_MODELS_FETCH` | Don't fetch models from models.dev | | `ALTIMATE_DISABLE_WORKSPACE` | Set to `1` to turn off every workspace feature (linking, skill and memory sync, the workspace engine, and the project lookup each session makes). The value is trimmed and read without regard to case; anything other than `0`, `false` or an empty value counts as set. Workspaces are on by default | | `ALTIMATE_DISABLE_SCHEMA_VALUES` | Set to `1` to turn off `schema_inspect`'s column value profiles for every call, whatever the model passes as `values`, so no cell values are sampled or sent to the model provider. The value is trimmed and read without regard to case; anything other than `0`, `false` or an empty value counts as set | +| `ALTIMATE_DISABLE_DEPENDENCY_INSTALL` | Set to `1` to skip the background install of `@opencode-ai/plugin` into config directories that hold custom tools or plugins. Use it where that package is already provided or the npm registry is not reachable; custom tools that import the package then need it installed some other way. The value is trimmed and read without regard to case; anything other than `0`, `false` or an empty value counts as set | | `ALTIMATE_WORKSPACE_WEB_URL` | Development only: the base URL of a local web app's Workspaces pages, used instead of the tenant's for `link`'s browser hand-off and workspace links. Include the mount path, e.g. `http://acme.localhost:3000/workspaces` | | `ALTIMATE_INTEGRATIONS` | Set to `local` to keep warehouse tools local rather than routing them through a bound workspace's engine | | `ALTIMATE_CODE_SERVE` | Set to `1` by `altimate-code serve` itself, whether the IDE extension or you launched it. Marks that process as the extension's host — so it is the one that reads the pin variables — and is stripped from every child the bash and shell tools start | diff --git a/packages/opencode/src/config/plugin.ts b/packages/opencode/src/config/plugin.ts index 341f0f6464..c9274f804c 100644 --- a/packages/opencode/src/config/plugin.ts +++ b/packages/opencode/src/config/plugin.ts @@ -4,7 +4,7 @@ import { ConfigPluginV1 } from "@opencode-ai/core/v1/config/plugin" import { fileURLToPath, pathToFileURL } from "url" import { existsSync, realpathSync } from "fs" import { FSUtil } from "@opencode-ai/core/fs-util" -import { Flag } from "@opencode-ai/core/flag/flag" +import { Flag, env, killSwitchSet } from "@opencode-ai/core/flag/flag" // altimate_change end import { isPathPluginSpec, parsePluginSpecifier, resolvePathPluginTarget } from "@/plugin/shared" import path from "path" @@ -84,8 +84,7 @@ export function needsDependencies(dir: string, plugins: readonly ConfigPluginV1. /** `ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1` skips the install. The test suite sets it: an install * started by one test is not awaited, outlives the test, and runs inside the test process. */ function installDisabled(): boolean { - const v = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]?.toLowerCase() - return v === "true" || v === "1" + return killSwitchSet(env("ALTIMATE_DISABLE_DEPENDENCY_INSTALL")) } export function shouldInstallDependencies( diff --git a/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts b/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts index e9ba2c086f..1f22228f62 100644 --- a/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts +++ b/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts @@ -259,14 +259,26 @@ describe("shouldInstallDependencies — Flag.OPENCODE_PURE fold", () => { } }) - test("ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1 suppresses installation, as the test suite's preload does", () => { + test("ALTIMATE_DISABLE_DEPENDENCY_INSTALL suppresses installation; `0` and `false` leave it on", () => { const dir = tmp() fs.mkdirSync(path.join(dir, "node_modules")) saved = process.env[ENV_KEY] delete process.env[ENV_KEY] - expect(process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]).toBe("1") - expect(ConfigPlugin.needsDependencies(dir, undefined)).toBe(true) - expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(false) + const off = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] + try { + expect(ConfigPlugin.needsDependencies(dir, undefined)).toBe(true) + for (const value of ["1", "true", "yes"]) { + process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = value + expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(false) + } + for (const value of ["0", "false", ""]) { + process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = value + expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true) + } + } finally { + if (off === undefined) delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] + else process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = off + } }) }) From 2229e0e491c718bfc798371228e807c09390b98e Mon Sep 17 00:00:00 2001 From: RaghwendraSingh Date: Tue, 1 Dec 2026 16:14:17 +0530 Subject: [PATCH 3/5] docs: the install switch also applies to local plugins Co-Authored-By: Claude Fable 5.2 --- docs/docs/usage/cli.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/usage/cli.md b/docs/docs/usage/cli.md index fd49a08163..f2aeed498f 100644 --- a/docs/docs/usage/cli.md +++ b/docs/docs/usage/cli.md @@ -137,7 +137,7 @@ Configuration can be controlled via environment variables: | `ALTIMATE_CLI_DISABLE_MODELS_FETCH` | Don't fetch models from models.dev | | `ALTIMATE_DISABLE_WORKSPACE` | Set to `1` to turn off every workspace feature (linking, skill and memory sync, the workspace engine, and the project lookup each session makes). The value is trimmed and read without regard to case; anything other than `0`, `false` or an empty value counts as set. Workspaces are on by default | | `ALTIMATE_DISABLE_SCHEMA_VALUES` | Set to `1` to turn off `schema_inspect`'s column value profiles for every call, whatever the model passes as `values`, so no cell values are sampled or sent to the model provider. The value is trimmed and read without regard to case; anything other than `0`, `false` or an empty value counts as set | -| `ALTIMATE_DISABLE_DEPENDENCY_INSTALL` | Set to `1` to skip the background install of `@opencode-ai/plugin` into config directories that hold custom tools or plugins. Use it where that package is already provided or the npm registry is not reachable; custom tools that import the package then need it installed some other way. The value is trimmed and read without regard to case; anything other than `0`, `false` or an empty value counts as set | +| `ALTIMATE_DISABLE_DEPENDENCY_INSTALL` | Set to `1` to skip the background install of `@opencode-ai/plugin` into config directories that hold custom tools or plugins. Use it where that package is already provided or the npm registry is not reachable; custom tools or plugins that import the package then need it installed some other way. The value is trimmed and read without regard to case; anything other than `0`, `false` or an empty value counts as set | | `ALTIMATE_WORKSPACE_WEB_URL` | Development only: the base URL of a local web app's Workspaces pages, used instead of the tenant's for `link`'s browser hand-off and workspace links. Include the mount path, e.g. `http://acme.localhost:3000/workspaces` | | `ALTIMATE_INTEGRATIONS` | Set to `local` to keep warehouse tools local rather than routing them through a bound workspace's engine | | `ALTIMATE_CODE_SERVE` | Set to `1` by `altimate-code serve` itself, whether the IDE extension or you launched it. Marks that process as the extension's host — so it is the one that reads the pin variables — and is stripped from every child the bash and shell tools start | From 33cb41295ca2173e635d8e443667b152f91cc7b5 Mon Sep 17 00:00:00 2001 From: RaghwendraSingh Date: Tue, 1 Dec 2026 18:57:56 +0530 Subject: [PATCH 4/5] test: review changes: the cold-start test decides for itself, and the switch is covered at both call sites - `fresh-start.test.ts` sets `ALTIMATE_DISABLE_DEPENDENCY_INSTALL=0` for its child process. The child inherited the suite's switch, so the test passed whether or not the install decision was right. - The `OPENCODE_PURE` cases clear the switch in `beforeEach`, so the PURE case tests PURE again. - One Config case and one TUI case check that with the switch set and a tool file present the recording installer receives nothing. The TUI matrix runs with the switch unset, as users do. - The switch is a getter on `Flag`, like the other `ALTIMATE_DISABLE_*` switches. Co-Authored-By: Claude Fable 5.2 --- packages/core/src/flag/flag.ts | 9 ++ packages/opencode/src/config/plugin.ts | 11 +-- .../test/cli/serve/fresh-start.test.ts | 3 + packages/opencode/test/config/config.test.ts | 22 ++++- packages/opencode/test/config/tui.test.ts | 95 +++++++++++-------- .../skill/release-v0.11.1-adversarial.test.ts | 58 +++++------ 6 files changed, 113 insertions(+), 85 deletions(-) diff --git a/packages/core/src/flag/flag.ts b/packages/core/src/flag/flag.ts index d85627f1b5..1e1d8e1f0e 100644 --- a/packages/core/src/flag/flag.ts +++ b/packages/core/src/flag/flag.ts @@ -150,6 +150,15 @@ export const Flag = { const value = env("ALTIMATE_DISABLE_SCHEMA_VALUES")?.trim().toLowerCase() return value !== undefined && value !== "" && value !== "0" && value !== "false" }, + /** + * Skips the background install of `@opencode-ai/plugin` into config dirs (see + * `ConfigPlugin.shouldInstallDependencies`). The test suite sets it: an install one test + * starts is not awaited, outlives the test and runs inside the test process. Same + * fail-closed parsing as ALTIMATE_DISABLE_WORKSPACE. + */ + get ALTIMATE_DISABLE_DEPENDENCY_INSTALL() { + return killSwitchSet(env("ALTIMATE_DISABLE_DEPENDENCY_INSTALL")) + }, // altimate_change end // Evaluated at access time (not module load) because tests, the CLI, and diff --git a/packages/opencode/src/config/plugin.ts b/packages/opencode/src/config/plugin.ts index c9274f804c..454aee66d7 100644 --- a/packages/opencode/src/config/plugin.ts +++ b/packages/opencode/src/config/plugin.ts @@ -4,7 +4,7 @@ import { ConfigPluginV1 } from "@opencode-ai/core/v1/config/plugin" import { fileURLToPath, pathToFileURL } from "url" import { existsSync, realpathSync } from "fs" import { FSUtil } from "@opencode-ai/core/fs-util" -import { Flag, env, killSwitchSet } from "@opencode-ai/core/flag/flag" +import { Flag } from "@opencode-ai/core/flag/flag" // altimate_change end import { isPathPluginSpec, parsePluginSpecifier, resolvePathPluginTarget } from "@/plugin/shared" import path from "path" @@ -81,17 +81,12 @@ export function needsDependencies(dir: string, plugins: readonly ConfigPluginV1. // PURE mode skips dependency installs entirely: isolated-HOME environments and subprocess tests run // with no package cache, so the install attempt fails, npm retries, and the process hangs past exit. // Fold that check in here so both call sites (Config and TuiConfig) stay in sync. -/** `ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1` skips the install. The test suite sets it: an install - * started by one test is not awaited, outlives the test, and runs inside the test process. */ -function installDisabled(): boolean { - return killSwitchSet(env("ALTIMATE_DISABLE_DEPENDENCY_INSTALL")) -} - +// `ALTIMATE_DISABLE_DEPENDENCY_INSTALL` skips it the same way (see the flag). export function shouldInstallDependencies( dir: string, plugins: readonly ConfigPluginV1.Spec[] | undefined, ): boolean { - return !Flag.OPENCODE_PURE && !installDisabled() && needsDependencies(dir, plugins) + return !Flag.OPENCODE_PURE && !Flag.ALTIMATE_DISABLE_DEPENDENCY_INSTALL && needsDependencies(dir, plugins) } // altimate_change end diff --git a/packages/opencode/test/cli/serve/fresh-start.test.ts b/packages/opencode/test/cli/serve/fresh-start.test.ts index f93a3a79e9..89502e95f7 100644 --- a/packages/opencode/test/cli/serve/fresh-start.test.ts +++ b/packages/opencode/test/cli/serve/fresh-start.test.ts @@ -44,6 +44,9 @@ cliIt.live( extraArgs: ["--print-logs"], env: { OPENCODE_PURE: "0", + // The suite's preload switches the install off, and a child inherits it: a real cold + // start must decide for itself. The registry below answers 503 with no retries. + ALTIMATE_DISABLE_DEPENDENCY_INSTALL: "0", OPENCODE_CONFIG_DIR: configDir, OPENCODE_CONFIG_CONTENT: JSON.stringify({ plugin: [pathToFileURL(plugin).href] }), OPENCODE_DISABLE_DEFAULT_PLUGINS: "1", diff --git a/packages/opencode/test/config/config.test.ts b/packages/opencode/test/config/config.test.ts index 9ad57c3fce..169e208027 100644 --- a/packages/opencode/test/config/config.test.ts +++ b/packages/opencode/test/config/config.test.ts @@ -1018,7 +1018,7 @@ it.effect("does not try to install dependencies in read-only OPENCODE_CONFIG_DIR // altimate_change start — upstream_fix: a bare dir no longer installs; this asserts the .gitignore bootstrap it.effect("bootstraps .gitignore in a writable OPENCODE_CONFIG_DIR even when no install is needed", () => -// altimate_change end + // altimate_change end Effect.gen(function* () { const dir = yield* tmpdirScoped() const configDir = path.join(dir, "configdir") @@ -1071,7 +1071,8 @@ describe("config dir plugin dependency install", () => { delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] }) afterEach(() => { - if (installOff !== undefined) process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = installOff + if (installOff === undefined) delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] + else process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = installOff }) npmIt.effect("skips the install in a bare writable config dir but still writes .gitignore", () => @@ -1097,6 +1098,18 @@ describe("config dir plugin dependency install", () => { }).pipe(Effect.provide(testInstanceStoreLayer), Effect.provide(CrossSpawnSpawner.defaultLayer)), ) + npmIt.effect("ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1 asks for no install even with a local tool source", () => + Effect.gen(function* () { + process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = "1" + const npm = recordingNpm() + const dir = yield* tmpdirScoped() + const configDir = path.join(dir, "configdir") + yield* FSUtil.use.writeWithDirs(path.join(configDir, "tools", "hello.ts"), "export default {}\n") + yield* loadConfigDirWithDependencies(dir, configDir, npm) + expect(npm.dirs).toEqual([]) + }).pipe(Effect.provide(testInstanceStoreLayer), Effect.provide(CrossSpawnSpawner.defaultLayer)), + ) + npmIt.effect("installs when the config dir has a local plugin source", () => Effect.gen(function* () { const npm = recordingNpm() @@ -2437,7 +2450,10 @@ describe("learn keys set above project files", () => { JSON.stringify({ $schema: "https://opencode.ai/config.json", learn: { capture: false } }), Effect.gen(function* () { const test = yield* TestInstance - yield* writeConfigEffect(test.directory, { $schema: "https://opencode.ai/config.json", learn: { enabled: true, capture: true } }) + yield* writeConfigEffect(test.directory, { + $schema: "https://opencode.ai/config.json", + learn: { enabled: true, capture: true }, + }) const config = yield* Config.use.get() expect(config.learn).toMatchObject({ enabled: true, capture: false }) expect([...Config.learnKeysAboveProject(test.directory)]).toEqual(["capture"]) diff --git a/packages/opencode/test/config/tui.test.ts b/packages/opencode/test/config/tui.test.ts index f84da7087b..c427663b18 100644 --- a/packages/opencode/test/config/tui.test.ts +++ b/packages/opencode/test/config/tui.test.ts @@ -91,49 +91,62 @@ const getTuiPluginOrigins = (directory: string) => ) // altimate_change start — cover the TUI call site independently from server Config. -for (const source of ["bare", "npm", "file", "tool", "node_modules", "outside"] as const) { - for (const pure of [false, true]) { - // The suite's preload switches the install off; this gate is checked through a recording installer. - it.instance(`tui dependency install gate: ${source}${pure ? " (PURE)" : ""}`, () => - withEnv("ALTIMATE_DISABLE_DEPENDENCY_INSTALL", "0", withEnv( - "OPENCODE_PURE", - pure ? "1" : "0", - withCleanState( - Effect.gen(function* () { - const fs = yield* FSUtil.Service - const test = yield* TestInstance - const local = path.join(test.directory, ".opencode") - const installs: string[] = [] - yield* fs.makeDirectory(local, { recursive: true }) - const plugin = - source === "file" ? "./custom.ts" : source === "outside" ? "../custom.ts" : "npm-plugin@1.0.0" - if (source !== "bare") yield* fs.writeJson(path.join(local, "tui.json"), { plugin: [plugin] }) - if (source === "file" || source === "outside") { - yield* fs.writeWithDirs(path.resolve(local, plugin), "export default {}\n") - } - if (source === "tool") yield* fs.writeWithDirs(path.join(local, "tools", "hello.ts"), "export default {}\n") - if (source === "node_modules") yield* fs.makeDirectory(path.join(local, "node_modules")) - - const npm = Layer.mock(Npm.Service)({ - install: (dir: string) => - Effect.yieldNow.pipe(Effect.andThen(Effect.sync(() => void installs.push(dir)))), - }) - yield* TuiConfig.Service.use((svc) => svc.get().pipe(Effect.andThen(svc.waitForDependencies()))).pipe( - Effect.provide( - TuiConfig.layer.pipe( - Layer.provide(Layer.succeed(CurrentWorkingDirectory, test.directory)), - Layer.provide(Project.defaultLayer), - Layer.provide(npm), - Layer.provide(FSUtil.defaultLayer), +// The suite's preload switches the install off. Each case sets the switch itself: unset, as users +// run, or `1`. The installer only records the request. +const installSources = ["bare", "npm", "file", "tool", "node_modules", "outside"] as const +const installGates = [ + ...installSources.flatMap((source) => [false, true].map((pure) => ({ source, pure, off: false }))), + { source: "tool" as const, pure: false, off: true }, +] +for (const { source, pure, off } of installGates) { + it.instance( + `tui dependency install gate: ${source}${pure ? " (PURE)" : ""}${off ? " (install switched off)" : ""}`, + () => + withEnv( + "ALTIMATE_DISABLE_DEPENDENCY_INSTALL", + off ? "1" : undefined, + withEnv( + "OPENCODE_PURE", + pure ? "1" : "0", + withCleanState( + Effect.gen(function* () { + const fs = yield* FSUtil.Service + const test = yield* TestInstance + const local = path.join(test.directory, ".opencode") + const installs: string[] = [] + yield* fs.makeDirectory(local, { recursive: true }) + const plugin = + source === "file" ? "./custom.ts" : source === "outside" ? "../custom.ts" : "npm-plugin@1.0.0" + if (source !== "bare") yield* fs.writeJson(path.join(local, "tui.json"), { plugin: [plugin] }) + if (source === "file" || source === "outside") { + yield* fs.writeWithDirs(path.resolve(local, plugin), "export default {}\n") + } + if (source === "tool") + yield* fs.writeWithDirs(path.join(local, "tools", "hello.ts"), "export default {}\n") + if (source === "node_modules") yield* fs.makeDirectory(path.join(local, "node_modules")) + + const npm = Layer.mock(Npm.Service)({ + install: (dir: string) => + Effect.yieldNow.pipe(Effect.andThen(Effect.sync(() => void installs.push(dir)))), + }) + yield* TuiConfig.Service.use((svc) => svc.get().pipe(Effect.andThen(svc.waitForDependencies()))).pipe( + Effect.provide( + TuiConfig.layer.pipe( + Layer.provide(Layer.succeed(CurrentWorkingDirectory, test.directory)), + Layer.provide(Project.defaultLayer), + Layer.provide(npm), + Layer.provide(FSUtil.defaultLayer), + ), ), - ), - ) - expect(installs).toEqual(!pure && ["file", "tool", "node_modules"].includes(source) ? [local] : []) - }), + ) + expect(installs).toEqual( + !pure && !off && ["file", "tool", "node_modules"].includes(source) ? [local] : [], + ) + }), + ), ), - )), - ) - } + ), + ) } // altimate_change end diff --git a/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts b/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts index 1f22228f62..d72adad936 100644 --- a/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts +++ b/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts @@ -42,7 +42,7 @@ * check via a different branch than the existing `ftp://` test (plain `http://` and an * embedded-credentials `https://` URL). */ -import { afterEach, describe, expect, spyOn, test } from "bun:test" +import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test" import * as fs from "fs" import * as os from "os" import * as path from "path" @@ -228,18 +228,27 @@ describe("needsDependencies — glob source-detection edge cases", () => { }) describe("shouldInstallDependencies — Flag.OPENCODE_PURE fold", () => { - const ENV_KEY = "OPENCODE_PURE" - let saved: string | undefined + const PURE = "OPENCODE_PURE" + const OFF = "ALTIMATE_DISABLE_DEPENDENCY_INSTALL" + const saved: Record = {} + // The suite's preload sets OFF; every case here starts with both switches unset. + beforeEach(() => { + for (const key of [PURE, OFF]) { + saved[key] = process.env[key] + delete process.env[key] + } + }) afterEach(() => { - if (saved === undefined) delete process.env[ENV_KEY] - else process.env[ENV_KEY] = saved + for (const key of [PURE, OFF]) { + if (saved[key] === undefined) delete process.env[key] + else process.env[key] = saved[key] + } }) test("OPENCODE_PURE=1 suppresses installation even when needsDependencies would be true", () => { const dir = tmp() fs.mkdirSync(path.join(dir, "node_modules")) - saved = process.env[ENV_KEY] - process.env[ENV_KEY] = "1" + process.env[PURE] = "1" expect(ConfigPlugin.needsDependencies(dir, undefined)).toBe(true) expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(false) }) @@ -247,37 +256,20 @@ describe("shouldInstallDependencies — Flag.OPENCODE_PURE fold", () => { test("without OPENCODE_PURE, shouldInstallDependencies matches needsDependencies", () => { const dir = tmp() fs.mkdirSync(path.join(dir, "node_modules")) - saved = process.env[ENV_KEY] - delete process.env[ENV_KEY] - // The suite's preload switches the install off; this case is about the product default. - const off = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] - delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] - try { - expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true) - } finally { - if (off !== undefined) process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = off - } + expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true) }) test("ALTIMATE_DISABLE_DEPENDENCY_INSTALL suppresses installation; `0` and `false` leave it on", () => { const dir = tmp() fs.mkdirSync(path.join(dir, "node_modules")) - saved = process.env[ENV_KEY] - delete process.env[ENV_KEY] - const off = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] - try { - expect(ConfigPlugin.needsDependencies(dir, undefined)).toBe(true) - for (const value of ["1", "true", "yes"]) { - process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = value - expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(false) - } - for (const value of ["0", "false", ""]) { - process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = value - expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true) - } - } finally { - if (off === undefined) delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] - else process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = off + expect(ConfigPlugin.needsDependencies(dir, undefined)).toBe(true) + for (const value of ["1", "true", "yes"]) { + process.env[OFF] = value + expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(false) + } + for (const value of ["0", "false", ""]) { + process.env[OFF] = value + expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true) } }) }) From e1ea0f615a9383b01c2526643c233b61520d1420 Mon Sep 17 00:00:00 2001 From: RaghwendraSingh Date: Tue, 1 Dec 2026 19:15:10 +0530 Subject: [PATCH 5/5] test: drop two unrelated formatting changes from `config.test.ts` Co-Authored-By: Claude Fable 5.2 --- packages/opencode/test/config/config.test.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/opencode/test/config/config.test.ts b/packages/opencode/test/config/config.test.ts index 169e208027..c6f4cf2adb 100644 --- a/packages/opencode/test/config/config.test.ts +++ b/packages/opencode/test/config/config.test.ts @@ -1018,7 +1018,7 @@ it.effect("does not try to install dependencies in read-only OPENCODE_CONFIG_DIR // altimate_change start — upstream_fix: a bare dir no longer installs; this asserts the .gitignore bootstrap it.effect("bootstraps .gitignore in a writable OPENCODE_CONFIG_DIR even when no install is needed", () => - // altimate_change end +// altimate_change end Effect.gen(function* () { const dir = yield* tmpdirScoped() const configDir = path.join(dir, "configdir") @@ -2450,10 +2450,7 @@ describe("learn keys set above project files", () => { JSON.stringify({ $schema: "https://opencode.ai/config.json", learn: { capture: false } }), Effect.gen(function* () { const test = yield* TestInstance - yield* writeConfigEffect(test.directory, { - $schema: "https://opencode.ai/config.json", - learn: { enabled: true, capture: true }, - }) + yield* writeConfigEffect(test.directory, { $schema: "https://opencode.ai/config.json", learn: { enabled: true, capture: true } }) const config = yield* Config.use.get() expect(config.learn).toMatchObject({ enabled: true, capture: false }) expect([...Config.learnKeysAboveProject(test.directory)]).toEqual(["capture"])