Add Seal approval run Langfuse bridge tools
This commit is contained in:
1 parent
d6a33de3d7
commit
0cc1f591dc
8 files changed
+392
-2
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { CorpConfig } from "./types.js";
|
||||
import { CorpContext } from "./manager.js";
|
||||
|
||||
function corp(id: string, name = id): CorpConfig {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
seal: {
|
||||
endpoints: {
|
||||
approvalStylePreferences: "api/v1/agent/ai-approval/config"
|
||||
}
|
||||
},
|
||||
source: {
|
||||
type: "direct",
|
||||
token: `${id}-token`,
|
||||
sealUrl: `https://${id}.seal.test`,
|
||||
expiresIn: 3600,
|
||||
staffId: "direct"
|
||||
},
|
||||
auth: {
|
||||
refreshTtl: 300
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
describe("CorpContext", () => {
|
||||
test("refresh adds newly loaded corps", () => {
|
||||
const context = new CorpContext([corp("corp-a")]);
|
||||
|
||||
context.refresh([corp("corp-a"), corp("corp-b")]);
|
||||
|
||||
expect(context.listCorps().map((item) => item.id)).toEqual(["corp-a", "corp-b"]);
|
||||
});
|
||||
|
||||
test("refresh keeps the selected corp when it still exists", () => {
|
||||
const context = new CorpContext([corp("corp-a"), corp("corp-b")]);
|
||||
expect(context.switchCorp("corp-b")).toBe(true);
|
||||
|
||||
context.refresh([corp("corp-a"), corp("corp-b", "Corp B updated")]);
|
||||
|
||||
expect(context.getCurrent()?.id).toBe("corp-b");
|
||||
expect(context.getCurrent()?.name).toBe("Corp B updated");
|
||||
});
|
||||
|
||||
test("refresh falls back when the selected corp disappears", () => {
|
||||
const context = new CorpContext([corp("corp-a"), corp("corp-b")]);
|
||||
expect(context.switchCorp("corp-b")).toBe(true);
|
||||
|
||||
context.refresh([corp("corp-c")]);
|
||||
|
||||
expect(context.getCurrent()?.id).toBe("corp-c");
|
||||
});
|
||||
});
|
||||
@@ -2,13 +2,25 @@ import { CorpConfig } from "./types.js";
|
||||
|
||||
export class CorpContext {
|
||||
private current: CorpConfig | null = null;
|
||||
private readonly corps = new Map<string, CorpConfig>();
|
||||
private corps = new Map<string, CorpConfig>();
|
||||
|
||||
constructor(corps: CorpConfig[]) {
|
||||
this.replaceCorps(corps);
|
||||
this.current = corps[0] ?? null;
|
||||
}
|
||||
|
||||
refresh(corps: CorpConfig[]): void {
|
||||
const currentId = this.current?.id ?? null;
|
||||
this.replaceCorps(corps);
|
||||
this.current = currentId ? this.corps.get(currentId) ?? null : null;
|
||||
this.current ??= corps[0] ?? null;
|
||||
}
|
||||
|
||||
private replaceCorps(corps: CorpConfig[]): void {
|
||||
this.corps = new Map();
|
||||
for (const corp of corps) {
|
||||
this.corps.set(corp.id, corp);
|
||||
}
|
||||
this.current = corps[0] ?? null;
|
||||
}
|
||||
|
||||
getCurrent(): CorpConfig | null {
|
||||
|
||||
Reference in new issue
Block a user