modes.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as assert from "assert"
  2. import { getCompletion, getMessage, sleep, waitForCompletion, waitUntilAborted } from "./utils"
  3. suite("Roo Code Modes", () => {
  4. test("Should handle switching modes correctly", async function () {
  5. const api = globalThis.api
  6. /**
  7. * Switch modes.
  8. */
  9. const switchModesPrompt =
  10. "For each mode (Code, Architect, Ask) respond with the mode name and what it specializes in after switching to that mode. " +
  11. "Do not start with the current mode."
  12. await api.setConfiguration({ mode: "Code", alwaysAllowModeSwitch: true, autoApprovalEnabled: true })
  13. const switchModesTaskId = await api.startNewTask(switchModesPrompt)
  14. await waitForCompletion({ api, taskId: switchModesTaskId, timeout: 60_000 })
  15. /**
  16. * Grade the response.
  17. */
  18. const gradePrompt =
  19. `Given this prompt: ${switchModesPrompt} grade the response from 1 to 10 in the format of "Grade: (1-10)": ` +
  20. api
  21. .getMessages(switchModesTaskId)
  22. .filter(({ type }) => type === "say")
  23. .map(({ text }) => text ?? "")
  24. .join("\n")
  25. await api.setConfiguration({ mode: "Ask" })
  26. const gradeTaskId = await api.startNewTask(gradePrompt)
  27. await waitForCompletion({ api, taskId: gradeTaskId, timeout: 60_000 })
  28. const completion = getCompletion({ api, taskId: gradeTaskId })
  29. const match = completion?.text?.match(/Grade: (\d+)/)
  30. const score = parseInt(match?.[1] ?? "0")
  31. assert.ok(score >= 7 && score <= 10, `Grade must be between 7 and 10 - ${completion?.text}`)
  32. await api.cancelCurrentTask()
  33. })
  34. })