| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import { describe, expect } from "bun:test"
- import { LayerNode } from "@kirincode-ai/core/effect/layer-node"
- import { Effect } from "effect"
- import { Auth } from "../../src/auth"
- import { testEffect } from "../lib/effect"
- const it = testEffect(LayerNode.compile(Auth.node))
- describe("Auth", () => {
- it.instance("set normalizes trailing slashes in keys", () =>
- Effect.gen(function* () {
- const auth = yield* Auth.Service
- yield* auth.set("https://example.com/", {
- type: "wellknown",
- key: "TOKEN",
- token: "abc",
- })
- const data = yield* auth.all()
- expect(data["https://example.com"]).toBeDefined()
- expect(data["https://example.com/"]).toBeUndefined()
- }),
- )
- it.instance("set cleans up pre-existing trailing-slash entry", () =>
- Effect.gen(function* () {
- const auth = yield* Auth.Service
- yield* auth.set("https://example.com/", {
- type: "wellknown",
- key: "TOKEN",
- token: "old",
- })
- yield* auth.set("https://example.com", {
- type: "wellknown",
- key: "TOKEN",
- token: "new",
- })
- const data = yield* auth.all()
- const keys = Object.keys(data).filter((key) => key.includes("example.com"))
- expect(keys).toEqual(["https://example.com"])
- const entry = data["https://example.com"]!
- expect(entry.type).toBe("wellknown")
- if (entry.type === "wellknown") expect(entry.token).toBe("new")
- }),
- )
- it.instance("remove deletes both trailing-slash and normalized keys", () =>
- Effect.gen(function* () {
- const auth = yield* Auth.Service
- yield* auth.set("https://example.com", {
- type: "wellknown",
- key: "TOKEN",
- token: "abc",
- })
- yield* auth.remove("https://example.com/")
- const data = yield* auth.all()
- expect(data["https://example.com"]).toBeUndefined()
- expect(data["https://example.com/"]).toBeUndefined()
- }),
- )
- it.instance("set and remove are no-ops on keys without trailing slashes", () =>
- Effect.gen(function* () {
- const auth = yield* Auth.Service
- yield* auth.set("anthropic", {
- type: "api",
- key: "sk-test",
- })
- const data = yield* auth.all()
- expect(data["anthropic"]).toBeDefined()
- yield* auth.remove("anthropic")
- const after = yield* auth.all()
- expect(after["anthropic"]).toBeUndefined()
- }),
- )
- })
|