mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 23:51:48 +00:00
refactor: share cli routing metadata
This commit is contained in:
46
src/cli/command-path-matches.test.ts
Normal file
46
src/cli/command-path-matches.test.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
matchesAnyCommandPath,
|
||||
matchesCommandPath,
|
||||
matchesCommandPathRule,
|
||||
} from "./command-path-matches.js";
|
||||
|
||||
describe("command-path-matches", () => {
|
||||
it("matches prefix and exact command paths", () => {
|
||||
expect(matchesCommandPath(["status"], ["status"])).toBe(true);
|
||||
expect(matchesCommandPath(["status", "watch"], ["status"])).toBe(true);
|
||||
expect(matchesCommandPath(["status", "watch"], ["status"], { exact: true })).toBe(false);
|
||||
expect(matchesCommandPath(["config", "get"], ["config", "get"], { exact: true })).toBe(true);
|
||||
});
|
||||
|
||||
it("matches declarative rules", () => {
|
||||
expect(matchesCommandPathRule(["plugins", "update"], ["plugins"])).toBe(true);
|
||||
expect(
|
||||
matchesCommandPathRule(["plugins", "update"], {
|
||||
pattern: ["plugins", "update"],
|
||||
exact: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
matchesCommandPathRule(["plugins", "update", "now"], {
|
||||
pattern: ["plugins", "update"],
|
||||
exact: true,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("matches any command path from a rule set", () => {
|
||||
expect(
|
||||
matchesAnyCommandPath(
|
||||
["config", "schema"],
|
||||
[["backup"], { pattern: ["config", "schema"], exact: true }],
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
matchesAnyCommandPath(
|
||||
["message", "send"],
|
||||
[["status"], { pattern: ["config", "schema"], exact: true }],
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user