From c8a1f53904bb62aa029dccd2bc8e9a31097b8e65 Mon Sep 17 00:00:00 2001 From: Francisco Solla Date: Mon, 24 Aug 2026 14:42:51 -0300 Subject: [PATCH] =?UTF-8?q?chore(worktree):=20preset=20model=20do=20launch?= =?UTF-8?q?er=20via=20OPENCODE=5FWORKTREE=5FMODEL=20=E2=80=94=20fallback?= =?UTF-8?q?=20comum=20deepseek-v4-flash=20(alinhamento=20infra-solla/iara-?= =?UTF-8?q?pwa)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/lib/worktree.mjs | 17 ++++++++++------- tests/unit/worktree.unit.spec.ts | 25 ++++++++++++++++--------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/scripts/lib/worktree.mjs b/scripts/lib/worktree.mjs index c2bd99d5..264df53a 100644 --- a/scripts/lib/worktree.mjs +++ b/scripts/lib/worktree.mjs @@ -20,14 +20,17 @@ export const PLAN_BRANCH_PREFIX = 'plans/plan-issue' export const WORKTREE_TERMINAL_ENV = 'TEQO_WORKTREE_TERMINAL' /** - * Preset model for the opencode launch — change the preset by editing this - * constant. OPS78: routes through the Vercel AI Gateway (cache/stability/ - * failover) instead of the direct provider. OPS82: the preset is the cheaper - * `-0731` flavor (input $0.076/M vs $0.13/M); the low/high/max variants are - * exposed by the `provider.vercel` override in the global opencode config - * (`~/.config/opencode/opencode.jsonc`, outside the repo — OPS89). + * Preset model for the opencode launch — fallback comum aos 3 repos do fluxo + * (infra-solla, teqo, iara-pwa). Override sem editar código: global via + * `export OPENCODE_WORKTREE_MODEL=…`, ou por repo na chave + * `OPENCODE_WORKTREE_MODEL` da `.forgejo/worktree.env`. Ex-OPS78/OPS82: o + * preset era o flavor `-0731` via Vercel AI Gateway; voltou ao provider + * direto porque o gateway está sem créditos (erros "positive credit balance" + * em 24/08/2026) e porque unificar o default reduz a sobrescrita confusa de + * seleção de modelo do TUI (opencode issues #8349/#13456). */ -export const OPENCODE_PRESET_MODEL = 'vercel/deepseek/deepseek-v4-flash-0731' +export const OPENCODE_PRESET_MODEL = + process.env.OPENCODE_WORKTREE_MODEL || 'deepseek/deepseek-v4-flash' /** * Skill command sent as the launch's initial message per purpose. `next` diff --git a/tests/unit/worktree.unit.spec.ts b/tests/unit/worktree.unit.spec.ts index 474c38c0..a5efa833 100644 --- a/tests/unit/worktree.unit.spec.ts +++ b/tests/unit/worktree.unit.spec.ts @@ -33,6 +33,13 @@ type TestIssue = { meta?: { id?: string } } +/** + * Valor esperado do preset no ambiente corrente: o fallback comum quando + * OPENCODE_WORKTREE_MODEL não está exportado (CI), ou o valor exportado + * (shell local) — o lib resolve exatamente nessa precedência. + */ +const presetInEffect = () => process.env.OPENCODE_WORKTREE_MODEL || 'deepseek/deepseek-v4-flash' + const issue = (over: Partial = {}): TestIssue => ({ number: 1, title: 'C15 — FullCalendar em /campanha/agenda', @@ -148,7 +155,7 @@ describe('opencodeLaunchDirective (terminal-only opencode launch, OPS26 + OPS33) it('next launches with the preset model, --auto and the /work-issue command sent (value always quoted)', () => { expect(opencodeLaunchDirective({ dir, purpose: 'next', terminal: true })).toBe( - `launch opencode ${dir} --model vercel/deepseek/deepseek-v4-flash-0731 --auto --prompt "/work-issue"`, + `launch opencode ${dir} --model ${presetInEffect()} --auto --prompt "/work-issue"`, ) }) @@ -156,33 +163,33 @@ describe('opencodeLaunchDirective (terminal-only opencode launch, OPS26 + OPS33) expect( opencodeLaunchDirective({ dir, purpose: 'next', terminal: true, issueNumber: 595 }), ).toBe( - `launch opencode ${dir} --model vercel/deepseek/deepseek-v4-flash-0731 --auto --prompt "/work-issue --issue 595"`, + `launch opencode ${dir} --model ${presetInEffect()} --auto --prompt "/work-issue --issue 595"`, ) }) it('plan launches with the same presets and /plan-issue sent (OPS31, value quoted)', () => { expect(opencodeLaunchDirective({ dir, purpose: 'plan', terminal: true })).toBe( - `launch opencode ${dir} --model vercel/deepseek/deepseek-v4-flash-0731 --auto --prompt "/plan-issue"`, + `launch opencode ${dir} --model ${presetInEffect()} --auto --prompt "/plan-issue"`, ) }) it('new launches prompt-less too — "apenas conversar", no skill sent', () => { expect(opencodeLaunchDirective({ dir, purpose: 'new', terminal: true })).toBe( - `launch opencode ${dir} --model vercel/deepseek/deepseek-v4-flash-0731 --auto`, + `launch opencode ${dir} --model ${presetInEffect()} --auto`, ) }) it('plan/new ignore the issueNumber — only next carries the claimed issue', () => { expect(opencodeLaunchDirective({ dir, purpose: 'plan', terminal: true, issueNumber: 7 })).toBe( - `launch opencode ${dir} --model vercel/deepseek/deepseek-v4-flash-0731 --auto --prompt "/plan-issue"`, + `launch opencode ${dir} --model ${presetInEffect()} --auto --prompt "/plan-issue"`, ) expect(opencodeLaunchDirective({ dir, purpose: 'new', terminal: true, issueNumber: 7 })).toBe( - `launch opencode ${dir} --model vercel/deepseek/deepseek-v4-flash-0731 --auto`, + `launch opencode ${dir} --model ${presetInEffect()} --auto`, ) }) - it('pins the preset constants — changing the model is editing a constant', () => { - expect(OPENCODE_PRESET_MODEL).toBe('vercel/deepseek/deepseek-v4-flash-0731') + it('pins the preset constants — fallback comum deepseek-v4-flash, override via OPENCODE_WORKTREE_MODEL', () => { + expect(OPENCODE_PRESET_MODEL).toBe(presetInEffect()) expect(WORKTREE_TERMINAL_ENV).toBe('TEQO_WORKTREE_TERMINAL') expect(OPENCODE_SKILL_COMMAND_BY_PURPOSE).toEqual({ next: '/work-issue', @@ -193,7 +200,7 @@ describe('opencodeLaunchDirective (terminal-only opencode launch, OPS26 + OPS33) it('an unknown purpose degrades to a prompt-less launch (fail-safe direction)', () => { expect(opencodeLaunchDirective({ dir, purpose: 'bogus', terminal: true })).toBe( - `launch opencode ${dir} --model vercel/deepseek/deepseek-v4-flash-0731 --auto`, + `launch opencode ${dir} --model ${presetInEffect()} --auto`, ) }) })