mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 13:07:39 +00:00
fix(discord): enrich allowlist resolution logs
This commit is contained in:
@@ -27,6 +27,15 @@ describe("buildAllowlistResolutionSummary", () => {
|
||||
});
|
||||
expect(result.mapping).toEqual(["a→1 (note)"]);
|
||||
});
|
||||
|
||||
it("supports custom unresolved formatting", () => {
|
||||
const resolvedUsers = [{ input: "a", resolved: false, note: "missing" }];
|
||||
const result = buildAllowlistResolutionSummary(resolvedUsers, {
|
||||
formatUnresolved: (entry) =>
|
||||
`${entry.input}${(entry as { note?: string }).note ? " (missing)" : ""}`,
|
||||
});
|
||||
expect(result.unresolved).toEqual(["a (missing)"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("addAllowlistUserEntriesFromConfigEntry", () => {
|
||||
|
||||
@@ -36,7 +36,7 @@ export function mergeAllowlist(params: {
|
||||
|
||||
export function buildAllowlistResolutionSummary<T extends AllowlistUserResolutionLike>(
|
||||
resolvedUsers: T[],
|
||||
opts?: { formatResolved?: (entry: T) => string },
|
||||
opts?: { formatResolved?: (entry: T) => string; formatUnresolved?: (entry: T) => string },
|
||||
): {
|
||||
resolvedMap: Map<string, T>;
|
||||
mapping: string[];
|
||||
@@ -46,14 +46,13 @@ export function buildAllowlistResolutionSummary<T extends AllowlistUserResolutio
|
||||
const resolvedMap = new Map(resolvedUsers.map((entry) => [entry.input, entry]));
|
||||
const resolvedOk = (entry: T) => Boolean(entry.resolved && entry.id);
|
||||
const formatResolved = opts?.formatResolved ?? ((entry: T) => `${entry.input}→${entry.id}`);
|
||||
const formatUnresolved = opts?.formatUnresolved ?? ((entry: T) => entry.input);
|
||||
const mapping = resolvedUsers.filter(resolvedOk).map(formatResolved);
|
||||
const additions = resolvedUsers
|
||||
.filter(resolvedOk)
|
||||
.map((entry) => entry.id)
|
||||
.filter((entry): entry is string => Boolean(entry));
|
||||
const unresolved = resolvedUsers
|
||||
.filter((entry) => !resolvedOk(entry))
|
||||
.map((entry) => entry.input);
|
||||
const unresolved = resolvedUsers.filter((entry) => !resolvedOk(entry)).map(formatUnresolved);
|
||||
return { resolvedMap, mapping, unresolved, additions };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user