import { describe, expect, test } from "bun:test";
import { embeddedScope, scopedId } from "./ids";
describe("scoped ids", () => {
test("carry a plain repo or account id and nothing else", () => {
const repo = "abcdefghij0123456789";
const id = scopedId(repo);
expect(id).toHaveLength(32);
expect(id.startsWith(repo)).toBe(true);
expect(embeddedScope(id)).toBe(repo);
});
test("fall back to a random id for scopes that aren't plain ids", () => {
const id = scopedId("site:abcdefghij0123456789");
expect(id).toHaveLength(20);
expect(embeddedScope(id)).toBeNull();
});
test("older ids and credential hashes carry no scope", () => {
expect(embeddedScope("abcdefghij0123456789")).toBeNull();
expect(embeddedScope("a".repeat(64))).toBeNull();
});
});