attachmentSelectionProtocol.test.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { describe, expect, it } from "vitest";
  2. import { zcodeSessionSendParamsSchema } from "../src/zcode-protocol/index.js";
  3. import { commandPayloadSchemas } from "../src/zcode-protocol-v4/command.js";
  4. describe("附件与文本发送的模型合同", () => {
  5. const modelSelection = {
  6. providerId: "account:offpeak",
  7. modelId: "model",
  8. options: { reasoningLevel: "high" },
  9. };
  10. const modelExecution = {
  11. selectionScope: "execution",
  12. memoryExtraction: "skip",
  13. requestAuth: { headers: { "x-test-ticket": "fixture-only" } },
  14. subagents: { foregroundModel: "submission", background: "deny" },
  15. };
  16. it("两种发送保留相同 Selection 与执行约束", () => {
  17. const legacy = zcodeSessionSendParamsSchema.parse({
  18. sessionId: "session",
  19. content: "hi",
  20. attachments: [],
  21. modelSelection,
  22. modelExecution,
  23. });
  24. const current = commandPayloadSchemas.sendText.parse({
  25. text: "hi",
  26. modelSelection,
  27. modelExecution,
  28. });
  29. expect(legacy.modelSelection).toEqual(current.modelSelection);
  30. expect(legacy.modelExecution).toEqual(current.modelExecution);
  31. });
  32. it("缺 Selection 或非法执行范围不能通过附件入口绕过校验", () => {
  33. expect(
  34. zcodeSessionSendParamsSchema.safeParse({ sessionId: "s", content: "hi", modelExecution })
  35. .success,
  36. ).toBe(false);
  37. expect(
  38. zcodeSessionSendParamsSchema.safeParse({
  39. sessionId: "s",
  40. content: "hi",
  41. modelSelection,
  42. modelExecution: { ...modelExecution, selectionScope: "session" },
  43. }).success,
  44. ).toBe(false);
  45. });
  46. });