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

import { workbenchActivityDispatchRequested } from "./workbench-command-proxy.ts";
import { normalizeWorkbenchCloudAuthorization } from "../workbench/cloud-authorization.ts";

test("accepts activity dispatch header from Node and Fetch request shapes", () => {
  expect(workbenchActivityDispatchRequested({ headers: { "x-workbench-activity-dispatch": "1" } })).toBe(true);
  expect(workbenchActivityDispatchRequested({ headers: new Headers({ "x-workbench-activity-dispatch": "1" }) })).toBe(true);
  expect(workbenchActivityDispatchRequested({ headers: new Headers({ "x-workbench-activity-dispatch": "0" }) })).toBe(false);
});

test("normalizes the unified Workbench Cloud authorization on both sides", () => {
  expect(normalizeWorkbenchCloudAuthorization(" unified-internal-key ")).toBe("Bearer unified-internal-key");
  expect(normalizeWorkbenchCloudAuthorization("Bearer unified-internal-key")).toBe("Bearer unified-internal-key");
  expect(normalizeWorkbenchCloudAuthorization("  ")).toBe("");
});
