mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
refactor(cli): remove stale adapter helpers
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
// Command path match tests cover CLI command path matching and normalization.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
matchesCommandPath,
|
||||
matchesCommandPathRule,
|
||||
} from "./command-path-matches.js";
|
||||
import { matchesCommandPath } from "./command-path-matches.js";
|
||||
|
||||
describe("command-path-matches", () => {
|
||||
it("matches prefix and exact command paths", () => {
|
||||
@@ -13,28 +10,4 @@ describe("command-path-matches", () => {
|
||||
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("treats structured rules without exact as prefix matches", () => {
|
||||
expect(
|
||||
matchesCommandPathRule(["plugins", "update", "now"], {
|
||||
pattern: ["plugins", "update"],
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,28 +1,4 @@
|
||||
// Shared command-path matching helpers for CLI startup and registration policy.
|
||||
type StructuredCommandPathMatchRule = {
|
||||
pattern: readonly string[];
|
||||
exact?: boolean;
|
||||
};
|
||||
|
||||
type CommandPathMatchRule = readonly string[] | StructuredCommandPathMatchRule;
|
||||
|
||||
type NormalizedCommandPathMatchRule = {
|
||||
pattern: readonly string[];
|
||||
exact: boolean;
|
||||
};
|
||||
|
||||
function isStructuredCommandPathMatchRule(
|
||||
rule: CommandPathMatchRule,
|
||||
): rule is StructuredCommandPathMatchRule {
|
||||
return !Array.isArray(rule);
|
||||
}
|
||||
|
||||
function normalizeCommandPathMatchRule(rule: CommandPathMatchRule): NormalizedCommandPathMatchRule {
|
||||
if (!isStructuredCommandPathMatchRule(rule)) {
|
||||
return { pattern: rule, exact: false };
|
||||
}
|
||||
return { pattern: rule.pattern, exact: rule.exact ?? false };
|
||||
}
|
||||
|
||||
/** Matches a command path prefix, or the full path when `exact` is requested. */
|
||||
export function matchesCommandPath(
|
||||
@@ -35,11 +11,3 @@ export function matchesCommandPath(
|
||||
}
|
||||
return !params?.exact || commandPath.length === pattern.length;
|
||||
}
|
||||
|
||||
/** Applies the shared command-path rule shape used by startup and help policies. */
|
||||
export function matchesCommandPathRule(commandPath: string[], rule: CommandPathMatchRule): boolean {
|
||||
const normalizedRule = normalizeCommandPathMatchRule(rule);
|
||||
return matchesCommandPath(commandPath, normalizedRule.pattern, {
|
||||
exact: normalizedRule.exact,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildNpmInstallRecordFields,
|
||||
logPinnedNpmSpecMessages,
|
||||
mapNpmResolutionMetadata,
|
||||
resolvePinnedNpmInstallRecord,
|
||||
resolvePinnedNpmInstallRecordForCli,
|
||||
resolvePinnedNpmSpec,
|
||||
@@ -58,26 +57,6 @@ describe("npm-resolution helpers", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("maps npm resolution metadata to install fields", () => {
|
||||
expect(
|
||||
mapNpmResolutionMetadata({
|
||||
name: "@openclaw/plugin-alpha",
|
||||
version: "1.2.3",
|
||||
resolvedSpec: "@openclaw/plugin-alpha@1.2.3",
|
||||
integrity: "sha512-abc",
|
||||
shasum: "deadbeef",
|
||||
resolvedAt: "2026-02-21T00:00:00.000Z",
|
||||
}),
|
||||
).toEqual({
|
||||
resolvedName: "@openclaw/plugin-alpha",
|
||||
resolvedVersion: "1.2.3",
|
||||
resolvedSpec: "@openclaw/plugin-alpha@1.2.3",
|
||||
integrity: "sha512-abc",
|
||||
shasum: "deadbeef",
|
||||
resolvedAt: "2026-02-21T00:00:00.000Z",
|
||||
});
|
||||
});
|
||||
|
||||
it("builds common npm install record fields", () => {
|
||||
expect(
|
||||
buildNpmInstallRecordFields({
|
||||
|
||||
@@ -26,18 +26,6 @@ export function resolvePinnedNpmSpec(params: {
|
||||
};
|
||||
}
|
||||
|
||||
/** Convert npm resolver metadata into persisted install-record fields. */
|
||||
export function mapNpmResolutionMetadata(resolution?: NpmResolutionMetadata): {
|
||||
resolvedName?: string;
|
||||
resolvedVersion?: string;
|
||||
resolvedSpec?: string;
|
||||
integrity?: string;
|
||||
shasum?: string;
|
||||
resolvedAt?: string;
|
||||
} {
|
||||
return buildNpmResolutionFields(resolution);
|
||||
}
|
||||
|
||||
/** Build the npm section of a plugin install record. */
|
||||
export function buildNpmInstallRecordFields(params: {
|
||||
spec: string;
|
||||
|
||||
Reference in New Issue
Block a user