* Write opencode.json + magic-context.jsonc + tui.json into config/workdir. * * - opencode.json: registers our plugin via file:// spec, defines a mock-anthropic * provider and a mock model, sets provider.mock-anthropic.options.baseURL to the * mock server's URL. * - magic-context.jsonc: sta
(
env: IsolatedEnv,
mockProviderURL: string,
opts: SpawnOptions,
)
| 91 | * deterministically with modest scripted token counts. |
| 92 | */ |
| 93 | function writeConfigs( |
| 94 | env: IsolatedEnv, |
| 95 | mockProviderURL: string, |
| 96 | opts: SpawnOptions, |
| 97 | ): void { |
| 98 | const pluginSpec = `file://${PLUGIN_ENTRY}`; |
| 99 | |
| 100 | const opencodeConfig: Record<string, unknown> = { |
| 101 | $schema: "https://opencode.ai/config.json", |
| 102 | plugin: [pluginSpec], |
| 103 | // Disable telemetry-style checks that could reach out. |
| 104 | autoupdate: false, |
| 105 | // Match what `setup`/`doctor` writes for real users. OpenCode compaction |
| 106 | // defaults to enabled; if we leave it on, magic-context's conflict |
| 107 | // detector disables itself and the plugin becomes a no-op. |
| 108 | compaction: { auto: false, prune: false }, |
| 109 | provider: { |
| 110 | "mock-anthropic": { |
| 111 | api: "@ai-sdk/anthropic", |
| 112 | name: "Mock Anthropic", |
| 113 | npm: "@ai-sdk/anthropic", |
| 114 | env: [], |
| 115 | options: { |
| 116 | apiKey: "test-key-not-real", |
| 117 | baseURL: mockProviderURL, |
| 118 | }, |
| 119 | models: { |
| 120 | "mock-sonnet": { |
| 121 | id: "mock-sonnet", |
| 122 | name: "Mock Sonnet", |
| 123 | cost: { input: 0, output: 0 }, |
| 124 | limit: { context: opts.modelContextLimit ?? 200000, output: 8192 }, |
| 125 | // Advertise image + pdf input support so OpenCode does |
| 126 | // not substitute inline file parts with "this model |
| 127 | // does not support X input" text messages. Matches the |
| 128 | // real Sonnet capabilities this mock is standing in for. |
| 129 | modalities: { |
| 130 | input: ["text", "image", "pdf"], |
| 131 | output: ["text"], |
| 132 | }, |
| 133 | options: {}, |
| 134 | }, |
| 135 | }, |
| 136 | }, |
| 137 | }, |
| 138 | ...(opts.openCodeConfigExtra ?? {}), |
| 139 | }; |
| 140 | |
| 141 | // magic-context defaults tuned for fast triggering in tests. |
| 142 | const magicContext = { |
| 143 | $schema: |
| 144 | "https://raw.githubusercontent.com/cortexkit/opencode-magic-context/master/assets/magic-context.schema.json", |
| 145 | execute_threshold_percentage: 40, |
| 146 | history_budget_percentage: 0.15, |
| 147 | dreamer: { disable: true }, |
| 148 | sidekick: { disable: true }, |
| 149 | ...(opts.magicContextConfig ?? {}), |
| 150 | }; |