mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-29 11:13:36 +00:00
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
// Android node capability policy config fixture describes gateway policy config.
|
|
import type { OpenClawConfig } from "../../../src/config/config.js";
|
|
|
|
// Test helper for unwrapping gateway config.get response shapes.
|
|
|
|
/** Narrow unknown payloads to plain records for fixture parsing. */
|
|
function asRecord(value: unknown): Record<string, unknown> {
|
|
return typeof value === "object" && value !== null ? (value as Record<string, unknown>) : {};
|
|
}
|
|
|
|
/** Unwrap current and legacy remote config snapshot envelopes. */
|
|
export function unwrapRemoteConfigSnapshot(raw: unknown): OpenClawConfig {
|
|
const rawObj = asRecord(raw);
|
|
const resolved = asRecord(rawObj.resolved);
|
|
if (Object.keys(resolved).length > 0) {
|
|
return resolved as OpenClawConfig;
|
|
}
|
|
|
|
const wrapped = asRecord(rawObj.config);
|
|
if (Object.keys(wrapped).length > 0) {
|
|
return wrapped as OpenClawConfig;
|
|
}
|
|
|
|
const legacyPayload = asRecord(rawObj.payload);
|
|
const legacyResolved = asRecord(legacyPayload.resolved);
|
|
if (Object.keys(legacyResolved).length > 0) {
|
|
return legacyResolved as OpenClawConfig;
|
|
}
|
|
|
|
const legacyConfig = asRecord(legacyPayload.config);
|
|
if (Object.keys(legacyConfig).length > 0) {
|
|
return legacyConfig as OpenClawConfig;
|
|
}
|
|
|
|
if (Object.keys(rawObj).length > 0 && !Object.hasOwn(rawObj, "payload")) {
|
|
return rawObj as OpenClawConfig;
|
|
}
|
|
|
|
throw new Error("remote gateway config.get returned empty config payload");
|
|
}
|