mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-18 11:01:37 +00:00
* refactor: consolidate string reader mechanics * fix: declare model catalog normalization dependency * fix: keep model catalog dependency-free * refactor(core): keep string readers internal
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { isStringOption, readStringAlias, readTrimmedStringAlias } from "./string-readers.js";
|
|
|
|
describe("string readers", () => {
|
|
it("checks caller-owned string options from arrays and sets", () => {
|
|
const modes = ["off", "auto"] as const;
|
|
const states = new Set(["ready", "done"] as const);
|
|
|
|
expect(isStringOption("auto", modes)).toBe(true);
|
|
expect(isStringOption(" AUTO ", modes)).toBe(false);
|
|
expect(isStringOption("done", states)).toBe(true);
|
|
expect(isStringOption(1, modes)).toBe(false);
|
|
});
|
|
|
|
it("reads aliases with explicit raw and trimmed contracts", () => {
|
|
const record = {
|
|
empty: "",
|
|
spaced: " value ",
|
|
fallback: "fallback",
|
|
invalid: 1,
|
|
};
|
|
|
|
expect(readStringAlias(record, ["invalid", "empty", "fallback"])).toBe("");
|
|
expect(readStringAlias(record, ["spaced"])).toBe(" value ");
|
|
expect(readTrimmedStringAlias(record, ["invalid", "empty", "spaced", "fallback"])).toBe(
|
|
"value",
|
|
);
|
|
expect(readTrimmedStringAlias(record, ["invalid", "empty"])).toBeUndefined();
|
|
});
|
|
});
|