From ab2991c64d0cd4604b249b1111256dc218c5162b Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 15:39:30 -0600 Subject: [PATCH 1/2] fix(catalog-sync): resolve target from --config, not OPENCODE_CONFIG_PATH (#4588) --- bin/provider-catalog-sync.mjs | 22 +++++++++++++-- bin/provider-catalog-sync.test.mjs | 44 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/bin/provider-catalog-sync.mjs b/bin/provider-catalog-sync.mjs index 029b629be9..cafb46989b 100644 --- a/bin/provider-catalog-sync.mjs +++ b/bin/provider-catalog-sync.mjs @@ -42,6 +42,13 @@ // merged effective config (default + overlay; --runtime-config) and skips // the sync-owned providers on --apply; sync-models owns their writes. // +// Config resolution (#4588): this tool's target is the tracked configured +// default — an explicit --config wins, then OPENCODE_CATALOG_SYNC_CONFIG, +// then /.opencode/opencode.jsonc. OPENCODE_CONFIG_PATH is never the +// target: it is sync-models' variable and since #4544 it names the runtime +// overlay, which this tool only reads (via --runtime-config) to compute the +// merged effective config. +// // Sources: laptop proxies are enumerated over HTTP on 127.0.0.1 (run this on // the laptop, or pass --source-dir with .json snapshots for an offline // reproducible run). models.dev is a cross-check for every provider and the @@ -817,6 +824,18 @@ export function parseArgs(argv) { return { options, flags }; } +// Resolution order for the catalog target (#4588): explicit --config, +// then the catalog-sync-specific OPENCODE_CATALOG_SYNC_CONFIG, then the +// tracked configured default. OPENCODE_CONFIG_PATH is deliberately not +// consulted — since #4544 it names the runtime overlay (sync-models' file). +export function resolveConfigPath({ options, env, root }) { + return ( + options['--config'] ?? + env.OPENCODE_CATALOG_SYNC_CONFIG ?? + path.join(root, '.opencode', 'opencode.jsonc') + ); +} + async function main(argv) { const { options, flags } = parseArgs(argv); if (flags.has('--help')) { @@ -825,8 +844,7 @@ async function main(argv) { } const opt = (name, dflt) => options[name] ?? dflt; const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..'); - const configPath = - process.env.OPENCODE_CONFIG_PATH || opt('--config', path.join(root, '.opencode', 'opencode.jsonc')); + const configPath = resolveConfigPath({ options, env: process.env, root }); const runtimeConfigPath = opt( '--runtime-config', process.env.OPENCODE_RUNTIME_CONFIG || diff --git a/bin/provider-catalog-sync.test.mjs b/bin/provider-catalog-sync.test.mjs index d52f16a162..dafc378d88 100644 --- a/bin/provider-catalog-sync.test.mjs +++ b/bin/provider-catalog-sync.test.mjs @@ -20,6 +20,7 @@ import { assertNotDefaultBranch, openPrCommands, runSync, + resolveConfigPath, deepMergeProviders, SYNC_OWNED_PROVIDERS, } from './provider-catalog-sync.mjs'; @@ -339,6 +340,49 @@ test('CLI control: dry run exits 3 without writing; --apply exits 0 and writes', assert.ok(fs.readFileSync(configPath, 'utf8').includes('acme-2')); }); +// --------------------------------------------------------------------------- +// #4588: config resolution — OPENCODE_CONFIG_PATH names the runtime overlay +// since #4544 and must never become this tool's target +// --------------------------------------------------------------------------- + +test('resolveConfigPath: --config beats env, catalog env beats default, OPENCODE_CONFIG_PATH ignored (#4588)', () => { + const root = '/repo'; + const overlay = '/state/opencode-runtime.jsonc'; + const dflt = path.join(root, '.opencode', 'opencode.jsonc'); + // Explicit flag wins over every env var. + assert.equal( + resolveConfigPath({ options: { '--config': '/flag.jsonc' }, env: { OPENCODE_CONFIG_PATH: overlay, OPENCODE_CATALOG_SYNC_CONFIG: '/env.jsonc' }, root }), + '/flag.jsonc', + ); + // Catalog-sync-specific env is the only env override. + assert.equal( + resolveConfigPath({ options: {}, env: { OPENCODE_CONFIG_PATH: overlay, OPENCODE_CATALOG_SYNC_CONFIG: '/env.jsonc' }, root }), + '/env.jsonc', + ); + // OPENCODE_CONFIG_PATH alone changes nothing: tracked default. + assert.equal(resolveConfigPath({ options: {}, env: { OPENCODE_CONFIG_PATH: overlay }, root }), dflt); + assert.equal(resolveConfigPath({ options: {}, env: {}, root }), dflt); +}); + +test('CLI: OPENCODE_CONFIG_PATH pointing at the overlay does not redirect the target (#4588)', () => { + const { configPath, sourceDir, modelsDev } = controlFixture(); + const dir = path.dirname(configPath); + const overlayPath = path.join(dir, 'opencode-runtime.jsonc'); + fs.writeFileSync(overlayPath, JSON.stringify({ provider: { openai: { models: { 'g-1': {} } } } })); + const r = runCli( + ['--config', configPath, '--runtime-config', overlayPath, '--models-dev', modelsDev, '--source-dir', sourceDir, '--json'], + { OPENCODE_CONFIG_PATH: overlayPath }, + ); + // The tracked file carries commandcode/acme-1 and the snapshot adds acme-2: + // a run against the tracked default reports the validated addition (exit 3). + // Against the overlay (the bug) it would report config=overlay and exit 0. + assert.equal(r.status, 3, `stdout: ${r.stdout} stderr: ${r.stderr}`); + const report = JSON.parse(r.stdout); + assert.equal(report.config, configPath); + assert.equal(report.runtime_overlay, overlayPath); + assert.ok(report.providers.commandcode, `providers: ${Object.keys(report.providers)}`); +}); + // --------------------------------------------------------------------------- // #4544: runtime overlay (sync-models-owned catalogs outside the tracked // configured default) From 0e4afc875fcc8e2c58300aa3a3542ef0177ba727 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 15:45:38 -0600 Subject: [PATCH 2/2] test(catalog-sync): let runCli pass OPENCODE_CONFIG_PATH when a test sets it explicitly (#4588) --- bin/provider-catalog-sync.test.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/provider-catalog-sync.test.mjs b/bin/provider-catalog-sync.test.mjs index dafc378d88..075408c6a0 100644 --- a/bin/provider-catalog-sync.test.mjs +++ b/bin/provider-catalog-sync.test.mjs @@ -288,7 +288,9 @@ test('parseArgs accepts the documented controls', () => { function runCli(args, env = {}) { const clean = { ...process.env, ...env }; - delete clean.OPENCODE_CONFIG_PATH; + // Scrub the ambient overlay variable unless a test passes it explicitly + // (#4588: the explicit-pass case is the regression under test). + if (!Object.hasOwn(env, 'OPENCODE_CONFIG_PATH')) delete clean.OPENCODE_CONFIG_PATH; return spawnSync(process.execPath, [SCRIPT, ...args], { encoding: 'utf8', env: clean }); }