import { describe, expect, it } from "bun:test";

import {
  getRuntimeSessionContext,
  removeRuntimeSessionContext,
  setRuntimeSessionContext,
} from "../../src/runtime/sessionContext.js";

describe("runtime session context", () => {
  it("stores authentication context in process memory", () => {
    setRuntimeSessionContext({
      accessToken: "token-1",
      actorKey: "actor-1",
      allowLearningWrite: true,
      clientSessionId: "chat-session-1",
      learningMode: "interactive",
      network: "fengyang",
      projectId: "project-id-1",
      projectKey: "project-1",
      sessionId: "runtime-session-1",
      traceId: "trace-1",
    });

    const runtimeContext = getRuntimeSessionContext("runtime-session-1");

    expect(runtimeContext?.accessToken).toBe("token-1");
    expect(runtimeContext?.clientSessionId).toBe("chat-session-1");
    expect(runtimeContext?.network).toBe("fengyang");
    expect(runtimeContext?.sessionId).toBe("runtime-session-1");

    removeRuntimeSessionContext("runtime-session-1");
    expect(getRuntimeSessionContext("runtime-session-1")).toBeNull();
  });
});
