providers.test.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /// <reference types="bun-types" />
  2. import { describe, expect, test } from 'bun:test';
  3. import { generateLiteConfig, MODEL_MAPPINGS } from './providers';
  4. describe('providers', () => {
  5. test('MODEL_MAPPINGS includes supported providers', () => {
  6. const keys = Object.keys(MODEL_MAPPINGS);
  7. expect(keys.sort()).toEqual([
  8. 'copilot',
  9. 'kimi',
  10. 'openai',
  11. 'opencode-go',
  12. 'zai-plan',
  13. ]);
  14. });
  15. test('generateLiteConfig defaults to openai and includes generated presets', () => {
  16. const config = generateLiteConfig({
  17. hasTmux: false,
  18. installCustomSkills: false,
  19. backgroundSubagents: 'no',
  20. reset: false,
  21. });
  22. expect(config.$schema).toBe(
  23. 'https://unpkg.com/oh-my-opencode-slim@latest/oh-my-opencode-slim.schema.json',
  24. );
  25. expect(config.preset).toBe('openai');
  26. expect(config.disabled_agents).toBeUndefined();
  27. expect((config.presets as any)['opencode-go']).toBeDefined();
  28. expect((config.presets as any)['opencode-go'].observer.model).toBe(
  29. 'opencode-go/kimi-k2.6',
  30. );
  31. const agents = (config.presets as any).openai;
  32. expect(agents).toBeDefined();
  33. expect(agents.orchestrator.model).toBe('openai/gpt-5.5');
  34. expect(agents.orchestrator.variant).toBe('medium');
  35. expect(agents.fixer.model).toBe('openai/gpt-5.5');
  36. expect(agents.fixer.variant).toBe('low');
  37. });
  38. test('generateLiteConfig uses correct OpenAI models', () => {
  39. const config = generateLiteConfig({
  40. hasTmux: false,
  41. installCustomSkills: false,
  42. backgroundSubagents: 'no',
  43. reset: false,
  44. });
  45. const agents = (config.presets as any).openai;
  46. expect(agents.orchestrator.model).toBe(
  47. MODEL_MAPPINGS.openai.orchestrator.model,
  48. );
  49. expect(agents.oracle.model).toBe('openai/gpt-5.5');
  50. expect(agents.oracle.variant).toBe('high');
  51. expect(agents.librarian.model).toBe('openai/gpt-5.4-mini');
  52. expect(agents.librarian.variant).toBe('low');
  53. expect(agents.explorer.model).toBe('openai/gpt-5.4-mini');
  54. expect(agents.explorer.variant).toBe('low');
  55. expect(agents.designer.model).toBe('openai/gpt-5.4-mini');
  56. expect(agents.designer.variant).toBe('medium');
  57. });
  58. test('generateLiteConfig can set opencode-go as active preset', () => {
  59. const config = generateLiteConfig({
  60. hasTmux: false,
  61. installCustomSkills: false,
  62. preset: 'opencode-go',
  63. reset: false,
  64. });
  65. expect(config.preset).toBe('opencode-go');
  66. expect(config.disabled_agents).toEqual([]);
  67. expect((config.presets as any).openai).toBeDefined();
  68. const agents = (config.presets as any)['opencode-go'];
  69. expect(agents).toBeDefined();
  70. expect(agents.orchestrator.model).toBe('opencode-go/glm-5.1');
  71. expect(agents.oracle.model).toBe('opencode-go/deepseek-v4-pro');
  72. expect(agents.oracle.variant).toBe('max');
  73. expect(agents.council.model).toBe('opencode-go/deepseek-v4-pro');
  74. expect(agents.council.variant).toBe('high');
  75. expect(agents.librarian.model).toBe('opencode-go/minimax-m2.7');
  76. expect(agents.explorer.model).toBe('opencode-go/minimax-m2.7');
  77. expect(agents.designer.model).toBe('opencode-go/kimi-k2.6');
  78. expect(agents.fixer.model).toBe('opencode-go/deepseek-v4-flash');
  79. expect(agents.fixer.variant).toBe('high');
  80. expect(agents.observer.model).toBe('opencode-go/kimi-k2.6');
  81. });
  82. test('generateLiteConfig rejects unsupported preset', () => {
  83. expect(() =>
  84. generateLiteConfig({
  85. hasTmux: false,
  86. installCustomSkills: false,
  87. preset: 'not-real',
  88. reset: false,
  89. }),
  90. ).toThrow('Unsupported preset "not-real"');
  91. });
  92. test('generateLiteConfig rejects non-generated model mappings as active presets', () => {
  93. expect(() =>
  94. generateLiteConfig({
  95. hasTmux: false,
  96. installCustomSkills: false,
  97. preset: 'kimi',
  98. reset: false,
  99. }),
  100. ).toThrow('Unsupported preset "kimi"');
  101. });
  102. test('generateLiteConfig rejects inherited property names as presets', () => {
  103. expect(() =>
  104. generateLiteConfig({
  105. hasTmux: false,
  106. installCustomSkills: false,
  107. preset: 'toString',
  108. reset: false,
  109. }),
  110. ).toThrow('Unsupported preset "toString"');
  111. });
  112. test('generateLiteConfig enables tmux when requested', () => {
  113. const config = generateLiteConfig({
  114. hasTmux: true,
  115. installCustomSkills: false,
  116. reset: false,
  117. });
  118. expect(config.tmux).toBeDefined();
  119. expect((config.tmux as any).enabled).toBe(true);
  120. expect((config.tmux as any).layout).toBe('main-vertical');
  121. });
  122. test('generateLiteConfig companion: yes', () => {
  123. const config = generateLiteConfig({
  124. hasTmux: false,
  125. installCustomSkills: false,
  126. backgroundSubagents: 'no',
  127. reset: false,
  128. companion: 'yes',
  129. });
  130. expect(config.companion).toBeDefined();
  131. expect((config.companion as any).enabled).toBe(true);
  132. expect((config.companion as any).position).toBe('bottom-right');
  133. expect((config.companion as any).size).toBe('medium');
  134. });
  135. test('generateLiteConfig companion: no or omitted', () => {
  136. const configYes = generateLiteConfig({
  137. hasTmux: false,
  138. installCustomSkills: false,
  139. backgroundSubagents: 'no',
  140. reset: false,
  141. companion: 'no',
  142. });
  143. expect(configYes.companion).toBeUndefined();
  144. const configOmitted = generateLiteConfig({
  145. hasTmux: false,
  146. installCustomSkills: false,
  147. backgroundSubagents: 'no',
  148. reset: false,
  149. });
  150. expect(configOmitted.companion).toBeUndefined();
  151. });
  152. test('generateLiteConfig includes default skills', () => {
  153. const config = generateLiteConfig({
  154. hasTmux: false,
  155. installCustomSkills: false,
  156. backgroundSubagents: 'no',
  157. reset: false,
  158. });
  159. const agents = (config.presets as any).openai;
  160. // Orchestrator should always have '*'
  161. expect(agents.orchestrator.skills).toEqual(['*']);
  162. // Oracle should have bundled simplify
  163. expect(agents.oracle.skills).toContain('simplify');
  164. // Orchestrator should implicitly cover bundled codemap via '*'
  165. expect(agents.orchestrator.skills).toContain('*');
  166. // Designer should have no bundled skills by default
  167. expect(agents.designer.skills).toEqual([]);
  168. // Explorer should have no bundled skills by default
  169. expect(agents.explorer.skills).toEqual([]);
  170. // Fixer should have no bundled skills by default
  171. expect(agents.fixer.skills).toEqual([]);
  172. });
  173. test('generateLiteConfig includes mcps field', () => {
  174. const config = generateLiteConfig({
  175. hasTmux: false,
  176. installCustomSkills: false,
  177. backgroundSubagents: 'no',
  178. reset: false,
  179. });
  180. const agents = (config.presets as any).openai;
  181. expect(agents.orchestrator.mcps).toBeDefined();
  182. expect(Array.isArray(agents.orchestrator.mcps)).toBe(true);
  183. expect(agents.librarian.mcps).toBeDefined();
  184. expect(Array.isArray(agents.librarian.mcps)).toBe(true);
  185. });
  186. test('generateLiteConfig openai includes correct mcps', () => {
  187. const config = generateLiteConfig({
  188. hasTmux: false,
  189. installCustomSkills: false,
  190. backgroundSubagents: 'no',
  191. reset: false,
  192. });
  193. const agents = (config.presets as any).openai;
  194. expect(agents.orchestrator.mcps).toEqual(['*', '!context7']);
  195. expect(agents.librarian.mcps).toContain('websearch');
  196. expect(agents.librarian.mcps).toContain('context7');
  197. expect(agents.librarian.mcps).toContain('gh_grep');
  198. expect(agents.designer.mcps).toEqual([]);
  199. });
  200. });