Files
openclaw/src/secrets/target-registry-pattern.test.ts
Vincent Koc 42e3d8d693 Secrets: add inline allowlist review set (#38314)
* Secrets: add inline allowlist review set

* Secrets: narrow detect-secrets file exclusions

* Secrets: exclude Docker fingerprint false positive

* Secrets: allowlist test and docs false positives

* Secrets: refresh baseline after allowlist updates

* Secrets: fix gateway chat fixture pragma

* Secrets: format pre-commit config

* Android: keep talk mode fixture JSON valid

* Feishu: rely on client timeout injection

* Secrets: allowlist provider auth test fixtures

* Secrets: allowlist onboard search fixtures

* Secrets: allowlist onboard mode fixture

* Secrets: allowlist gateway auth mode fixture

* Secrets: allowlist APNS wake test key

* Secrets: allowlist gateway reload fixtures

* Secrets: allowlist moonshot video fixture

* Secrets: allowlist auto audio fixture

* Secrets: allowlist tiny audio fixture

* Secrets: allowlist embeddings fixtures

* Secrets: allowlist resolve fixtures

* Secrets: allowlist target registry pattern fixtures

* Secrets: allowlist gateway chat env fixture

* Secrets: refresh baseline after fixture allowlists

* Secrets: reapply gateway chat env allowlist

* Secrets: reapply gateway chat env allowlist

* Secrets: stabilize gateway chat env allowlist

* Secrets: allowlist runtime snapshot save fixture

* Secrets: allowlist oauth profile fixtures

* Secrets: allowlist compaction identifier fixture

* Secrets: allowlist model auth fixture

* Secrets: allowlist model status fixtures

* Secrets: allowlist custom onboarding fixture

* Secrets: allowlist mattermost token summary fixtures

* Secrets: allowlist gateway auth suite fixtures

* Secrets: allowlist channel summary fixture

* Secrets: allowlist provider usage auth fixtures

* Secrets: allowlist media proxy fixture

* Secrets: allowlist secrets audit fixtures

* Secrets: refresh baseline after final fixture allowlists

* Feishu: prefer explicit client timeout

* Feishu: test direct timeout precedence
2026-03-06 19:35:26 -05:00

104 lines
2.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
expandPathTokens,
matchPathTokens,
materializePathTokens,
parsePathPattern,
} from "./target-registry-pattern.js";
describe("target registry pattern helpers", () => {
it("matches wildcard and array tokens with stable capture ordering", () => {
const tokens = parsePathPattern("agents.list[].memorySearch.providers.*.apiKey");
const match = matchPathTokens(
["agents", "list", "2", "memorySearch", "providers", "openai", "apiKey"],
tokens,
);
expect(match).toEqual({
captures: ["2", "openai"],
});
expect(
matchPathTokens(
["agents", "list", "x", "memorySearch", "providers", "openai", "apiKey"],
tokens,
),
).toBeNull();
});
it("materializes sibling ref paths from wildcard and array captures", () => {
const refTokens = parsePathPattern("agents.list[].memorySearch.providers.*.apiKeyRef");
expect(materializePathTokens(refTokens, ["1", "anthropic"])).toEqual([
"agents",
"list",
"1",
"memorySearch",
"providers",
"anthropic",
"apiKeyRef",
]);
expect(materializePathTokens(refTokens, ["anthropic"])).toBeNull();
});
it("expands wildcard and array patterns over config objects", () => {
const root = {
agents: {
list: [
{ memorySearch: { remote: { apiKey: "a" } } },
{ memorySearch: { remote: { apiKey: "b" } } },
],
},
talk: {
providers: {
openai: { apiKey: "oa" }, // pragma: allowlist secret
anthropic: { apiKey: "an" }, // pragma: allowlist secret
},
},
};
const arrayMatches = expandPathTokens(
root,
parsePathPattern("agents.list[].memorySearch.remote.apiKey"),
);
expect(
arrayMatches.map((entry) => ({
segments: entry.segments.join("."),
captures: entry.captures,
value: entry.value,
})),
).toEqual([
{
segments: "agents.list.0.memorySearch.remote.apiKey",
captures: ["0"],
value: "a",
},
{
segments: "agents.list.1.memorySearch.remote.apiKey",
captures: ["1"],
value: "b",
},
]);
const wildcardMatches = expandPathTokens(root, parsePathPattern("talk.providers.*.apiKey"));
expect(
wildcardMatches
.map((entry) => ({
segments: entry.segments.join("."),
captures: entry.captures,
value: entry.value,
}))
.toSorted((left, right) => left.segments.localeCompare(right.segments)),
).toEqual([
{
segments: "talk.providers.anthropic.apiKey",
captures: ["anthropic"],
value: "an",
},
{
segments: "talk.providers.openai.apiKey",
captures: ["openai"],
value: "oa",
},
]);
});
});