mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 16:03:43 +00:00
refactor(agents): dedupe config and truncation guards
This commit is contained in:
53
src/shared/config-eval.test.ts
Normal file
53
src/shared/config-eval.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { evaluateRuntimeEligibility } from "./config-eval.js";
|
||||
|
||||
describe("evaluateRuntimeEligibility", () => {
|
||||
it("rejects entries when required OS does not match local or remote", () => {
|
||||
const result = evaluateRuntimeEligibility({
|
||||
os: ["definitely-not-a-runtime-platform"],
|
||||
remotePlatforms: [],
|
||||
hasBin: () => true,
|
||||
hasEnv: () => true,
|
||||
isConfigPathTruthy: () => true,
|
||||
});
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts entries when remote platform satisfies OS requirements", () => {
|
||||
const result = evaluateRuntimeEligibility({
|
||||
os: ["linux"],
|
||||
remotePlatforms: ["linux"],
|
||||
hasBin: () => true,
|
||||
hasEnv: () => true,
|
||||
isConfigPathTruthy: () => true,
|
||||
});
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("bypasses runtime requirements when always=true", () => {
|
||||
const result = evaluateRuntimeEligibility({
|
||||
always: true,
|
||||
requires: { env: ["OPENAI_API_KEY"] },
|
||||
hasBin: () => false,
|
||||
hasEnv: () => false,
|
||||
isConfigPathTruthy: () => false,
|
||||
});
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("evaluates runtime requirements when always is false", () => {
|
||||
const result = evaluateRuntimeEligibility({
|
||||
requires: {
|
||||
bins: ["node"],
|
||||
anyBins: ["bun", "node"],
|
||||
env: ["OPENAI_API_KEY"],
|
||||
config: ["browser.enabled"],
|
||||
},
|
||||
hasBin: (bin) => bin === "node",
|
||||
hasAnyRemoteBin: () => false,
|
||||
hasEnv: (name) => name === "OPENAI_API_KEY",
|
||||
isConfigPathTruthy: (path) => path === "browser.enabled",
|
||||
});
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user