opencode-models.test.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /// <reference types="bun-types" />
  2. import { describe, expect, test } from 'bun:test';
  3. import { parseOpenCodeModelsVerboseOutput } from './opencode-models';
  4. const SAMPLE_OUTPUT = `
  5. opencode/gpt-5-nano
  6. {
  7. "id": "gpt-5-nano",
  8. "providerID": "opencode",
  9. "name": "GPT 5 Nano",
  10. "status": "active",
  11. "cost": { "input": 0, "output": 0, "cache": { "read": 0, "write": 0 } },
  12. "limit": { "context": 400000, "output": 128000 },
  13. "capabilities": { "reasoning": true, "toolcall": true, "attachment": true }
  14. }
  15. chutes/minimax-m2.1-5000
  16. {
  17. "id": "minimax-m2.1-5000",
  18. "providerID": "chutes",
  19. "name": "MiniMax M2.1 5000 req/day",
  20. "status": "active",
  21. "cost": { "input": 0, "output": 0, "cache": { "read": 0, "write": 0 } },
  22. "limit": { "context": 500000, "output": 64000 },
  23. "capabilities": { "reasoning": true, "toolcall": true, "attachment": false }
  24. }
  25. chutes/qwen3-coder-30b
  26. {
  27. "id": "qwen3-coder-30b",
  28. "providerID": "chutes",
  29. "name": "Qwen3 Coder 30B",
  30. "status": "active",
  31. "cost": { "input": 0.4, "output": 0.8, "cache": { "read": 0, "write": 0 } },
  32. "limit": { "context": 262144, "output": 32768 },
  33. "capabilities": { "reasoning": true, "toolcall": true, "attachment": false }
  34. }
  35. `;
  36. describe('opencode-models parser', () => {
  37. test('filters by provider and keeps free models', () => {
  38. const models = parseOpenCodeModelsVerboseOutput(SAMPLE_OUTPUT, 'opencode');
  39. expect(models.length).toBe(1);
  40. expect(models[0]?.model).toBe('opencode/gpt-5-nano');
  41. expect(models[0]?.providerID).toBe('opencode');
  42. });
  43. test('extracts chutes daily request limit from model metadata', () => {
  44. const models = parseOpenCodeModelsVerboseOutput(SAMPLE_OUTPUT, 'chutes');
  45. expect(models.length).toBe(1);
  46. expect(models[0]?.model).toBe('chutes/minimax-m2.1-5000');
  47. expect(models[0]?.dailyRequestLimit).toBe(5000);
  48. });
  49. test('includes non-free chutes models when freeOnly is disabled', () => {
  50. const models = parseOpenCodeModelsVerboseOutput(
  51. SAMPLE_OUTPUT,
  52. 'chutes',
  53. false,
  54. );
  55. expect(models.length).toBe(2);
  56. expect(models[1]?.model).toBe('chutes/qwen3-coder-30b');
  57. });
  58. });