Skip to content
TypeScript
3.4 KB
Raw Blame
/**
 * OpenRouter ('open' family) models for the model-agnostic agents.
 * family mapping · provider mapping · combo validity · free-tier pricing.
 */
import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { expand } from "../src/combos";
import { agentFamilies, modelFamily, providerFor, resolveModelAlias } from "../src/config";
import { estimateCost, resolveCost } from "../src/pricing";
import { MockRunner } from "../src/runners/mock";
import { parserFor } from "../src/transcripts/index";

describe("open family + provider mapping", () => {
  it("OpenRouter models are family 'open' and map to the openrouter provider", () => {
    expect(modelFamily("qwen3-coder")).toBe("open");
    expect(modelFamily("glm4.6")).toBe("open");
    expect(providerFor("open")).toBe("openrouter");
    // resolved id is vendor/model; combined arg would be openrouter/<vendor>/<model>
    expect(resolveModelAlias("qwen3-coder")).toBe("qwen/qwen3-coder");
    expect(`${providerFor("open")}/${resolveModelAlias("qwen3-coder")}`).toBe(
      "openrouter/qwen/qwen3-coder",
    );
  });

  it("multi-model agents accept the open family; cc/codex do not", () => {
    expect(agentFamilies("opencode")).toContain("open");
    expect(agentFamilies("hermes")).toContain("open");
    expect(agentFamilies("cc")).not.toContain("open");
    expect(agentFamilies("codex")).not.toContain("open");
  });
});

describe("expand with OpenRouter models", () => {
  it("opencode+qwen valid; cc/codex+qwen excluded with reason", () => {
    const { valid, excluded } = expand(
      ["qwen3-coder", "qwen3-coder-free"],
      ["opencode", "openclaw", "hermes", "cc", "codex"],
      ["none"],
    );
    const ids = new Set(valid.map((c) => c.comboId));
    expect(ids.has("opencode+qwen3-coder+none")).toBe(true);
    expect(ids.has("hermes+qwen3-coder-free+none")).toBe(true);
    expect(excluded.find((c) => c.comboId === "cc+qwen3-coder+none")?.excludeReason).toMatch(
      /incompatible/,
    );
    expect(excluded.find((c) => c.comboId === "codex+qwen3-coder+none")?.excludeReason).toMatch(
      /incompatible/,
    );
  });
});

describe("free-tier pricing", () => {
  it(":free model costs $0 (estimated, not null)", () => {
    expect(estimateCost("qwen3-coder-free", 1_000_000, 1_000_000, 0, 0)).toBe(0);
    const r = resolveCost("qwen3-coder-free", 1000, 1000, 0, 0, null);
    expect(r.costSource).toBe("estimated");
    expect(r.costUsd).toBe(0);
  });
  it("paid OpenRouter model estimates > 0", () => {
    expect(estimateCost("qwen3-coder", 1_000_000, 0, 0, 0)).toBeCloseTo(0.3, 5);
  });
});

describe("opencode + OpenRouter via mock", () => {
  it("produces tokens and stays flat (no subagents) on none harness", async () => {
    const work = mkdtempSync(join(tmpdir(), "theseus-or-"));
    const art = await new MockRunner(0).run({
      combo: {
        comboId: "opencode+qwen3-coder+none",
        agent: "opencode",
        model: "qwen3-coder",
        harness: "none",
        valid: true,
      },
      taskId: "subagent-101",
      runIdx: 0,
      workDir: work,
      timeoutS: 5,
      seed: 1,
      bench: "subagent",
    });
    const parsed = parserFor("opencode").parse(art.transcriptPath, { model: "qwen/qwen3-coder" });
    expect(parsed.totalTokens).toBeGreaterThan(0);
    expect(parsed.subagentCount).toBe(0);
  });
});