subagent-inherited-model-factory.test.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { describe, expect, it, vi } from "vitest";
  2. import type { Model } from "@zcode/contracts";
  3. import {
  4. createInheritedSubagentModelFactory,
  5. modelSelectionFromActiveModel,
  6. } from "../src/runtime/methods/subagent.js";
  7. function createModel(reasoningLevel: string, maxOutputTokens: number): Model {
  8. return {
  9. providerId: "provider-a",
  10. modelId: "model-a",
  11. options: { reasoningLevel, maxOutputTokens },
  12. } as Model;
  13. }
  14. describe("createInheritedSubagentModelFactory", () => {
  15. it("从实际继承的 Active Model 派生 child Selection", () => {
  16. const inherited = createModel("high", 8_000);
  17. expect(modelSelectionFromActiveModel(inherited)).toEqual({
  18. providerId: "provider-a",
  19. modelId: "model-a",
  20. options: { reasoningLevel: "high" },
  21. });
  22. });
  23. it("以父 Submission 的稀疏 Selection 复用已冻结的父 Model", () => {
  24. const inherited = createModel("high", 8_000);
  25. const rebound = createModel("low", 4_000);
  26. const fallback = vi.fn(() => rebound);
  27. const inheritedSelection = { providerId: "provider-a", modelId: "model-a" } as const;
  28. const factory = createInheritedSubagentModelFactory(inheritedSelection, inherited, fallback);
  29. expect(
  30. factory({
  31. selection: {
  32. providerId: "provider-a",
  33. modelId: "model-a",
  34. },
  35. }),
  36. ).toBe(inherited);
  37. expect(
  38. factory({
  39. selection: {
  40. providerId: "provider-a",
  41. modelId: "model-a",
  42. options: { reasoningLevel: "low" },
  43. },
  44. }),
  45. ).toBe(rebound);
  46. expect(fallback).toHaveBeenCalledTimes(1);
  47. });
  48. });