File size: 1,848 Bytes
3201ca6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { toAppConversation } from "#/api/agent-server-adapter";
import {
  getStoredConversationMetadata,
  removeStoredConversationMetadata,
  setStoredConversationMetadata,
} from "#/api/conversation-metadata-store";

const directInfo = (id: string) => ({
  id,
  created_at: "2026-05-05T00:00:00Z",
  updated_at: "2026-05-05T00:00:00Z",
});

describe("conversation-metadata-store", () => {
  beforeEach(() => {
    window.localStorage.clear();
  });
  afterEach(() => {
    window.localStorage.clear();
  });

  it("toAppConversation hydrates repo/branch/git_provider from the store", () => {
    setStoredConversationMetadata("conv-1", {
      selected_repository: "octocat/hello-world",
      selected_branch: "main",
      git_provider: "github",
    });

    const conversation = toAppConversation(directInfo("conv-1"));

    expect(conversation).toMatchObject({
      selected_repository: "octocat/hello-world",
      selected_branch: "main",
      git_provider: "github",
    });
  });

  it("toAppConversation falls back to nulls when no metadata is stored", () => {
    const conversation = toAppConversation(directInfo("conv-2"));

    expect(conversation.selected_repository).toBeNull();
    expect(conversation.selected_branch).toBeNull();
    expect(conversation.git_provider).toBeNull();
  });

  it("removeStoredConversationMetadata clears the entry so the adapter goes back to nulls", () => {
    setStoredConversationMetadata("conv-3", {
      selected_repository: "octocat/repo",
      selected_branch: "trunk",
      git_provider: "github",
    });

    removeStoredConversationMetadata("conv-3");

    expect(getStoredConversationMetadata("conv-3")).toBeNull();
    expect(toAppConversation(directInfo("conv-3")).selected_repository).toBeNull();
  });
});