modelTrajectorySearch.test.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { describe, expect, it } from "vitest";
  2. import { resolveTrajectoryTimelineItems } from "@/ModelTrajectoryPane.js";
  3. import { buildTrajectorySearchIndex } from "@/ModelTrajectorySearch.js";
  4. describe("model trajectory search", () => {
  5. it("indexes rendered message content and tool metadata without call metadata", () => {
  6. const items = resolveTrajectoryTimelineItems([
  7. {
  8. requestId: "req-1",
  9. attempt: 1,
  10. startedAt: "2026-08-24T01:00:00.000Z",
  11. durationMs: 9_999,
  12. model: { modelId: "hidden-model" },
  13. request: {
  14. messages: [
  15. { role: "system", parts: [{ kind: "text", text: "Alpha\n\tbeta" }] },
  16. {
  17. role: "tool",
  18. parts: [
  19. {
  20. kind: "tool-result",
  21. toolCallId: "call_visible-id",
  22. toolName: "visible-tool",
  23. output: { type: "error-text", value: "Failure needle" },
  24. },
  25. ],
  26. },
  27. ],
  28. toolNames: [],
  29. },
  30. response: {
  31. reasoningText: "Reasoning needle",
  32. text: "Assistant needle",
  33. toolCalls: [
  34. {
  35. kind: "tool-call",
  36. toolCallId: "call_write-file",
  37. toolName: "WriteFile",
  38. input: { path: "/tmp/needle.ts" },
  39. },
  40. ],
  41. },
  42. },
  43. ]);
  44. expect(buildTrajectorySearchIndex(items, "alpha beta").matches[0]).toMatchObject({
  45. callIndex: 0,
  46. expansionKey: "req-1:0:input:0",
  47. field: "content",
  48. sourceStart: 0,
  49. sourceEnd: 11,
  50. });
  51. expect(buildTrajectorySearchIndex(items, "needle").matches).toHaveLength(4);
  52. expect(buildTrajectorySearchIndex(items, "visible-tool").matches[0]).toMatchObject({
  53. expansionKey: "req-1:0:input:1",
  54. field: "tool-name",
  55. });
  56. expect(buildTrajectorySearchIndex(items, "visible-id").matches[0]).toMatchObject({
  57. field: "tool-id",
  58. });
  59. expect(buildTrajectorySearchIndex(items, "call_visible-id").matches).toHaveLength(0);
  60. expect(buildTrajectorySearchIndex(items, "hidden-model").matches).toHaveLength(0);
  61. expect(buildTrajectorySearchIndex(items, "9999").matches).toHaveLength(0);
  62. });
  63. it("tracks repeated occurrences with stable match keys", () => {
  64. const items = resolveTrajectoryTimelineItems([
  65. {
  66. requestId: "req-repeat",
  67. attempt: 1,
  68. startedAt: "2026-08-24T01:00:00.000Z",
  69. model: {},
  70. request: {
  71. messages: [{ role: "user", parts: [{ kind: "text", text: "find FIND find" }] }],
  72. toolNames: [],
  73. },
  74. },
  75. ]);
  76. const matches = buildTrajectorySearchIndex(items, "find").matches;
  77. expect(matches.map((match) => match.fieldMatchIndex)).toEqual([0, 1, 2]);
  78. expect(new Set(matches.map((match) => match.key)).size).toBe(3);
  79. });
  80. });