mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
test: tighten read-only channel assertions
This commit is contained in:
@@ -26,6 +26,15 @@ function pluginIds(plugins: ReturnType<typeof listReadOnlyChannelPluginsForConfi
|
||||
return plugins.map((entry) => entry.id);
|
||||
}
|
||||
|
||||
function expectRecordFields(record: unknown, expected: Record<string, unknown>) {
|
||||
expect(record).toBeDefined();
|
||||
const actual = record as Record<string, unknown>;
|
||||
for (const [key, value] of Object.entries(expected)) {
|
||||
expect(actual[key]).toEqual(value);
|
||||
}
|
||||
return actual;
|
||||
}
|
||||
|
||||
vi.mock("../../plugins/bundled-dir.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../../plugins/bundled-dir.js")>();
|
||||
return {
|
||||
@@ -584,8 +593,8 @@ describe("listReadOnlyChannelPluginsForConfig", () => {
|
||||
"alpha-chat": { token: "alpha-token" },
|
||||
"beta-chat": { token: "beta-token" },
|
||||
},
|
||||
} as never),
|
||||
).toMatchObject({ token: "beta-token" });
|
||||
} as never).token,
|
||||
).toBe("beta-token");
|
||||
expect(fs.existsSync(setupMarker)).toBe(true);
|
||||
expect(fs.existsSync(fullMarker)).toBe(false);
|
||||
});
|
||||
@@ -627,8 +636,8 @@ describe("listReadOnlyChannelPluginsForConfig", () => {
|
||||
channels: {
|
||||
"beta-chat": { token: "beta-token" },
|
||||
},
|
||||
} as never),
|
||||
).toMatchObject({ token: "beta-token" });
|
||||
} as never).token,
|
||||
).toBe("beta-token");
|
||||
expect(fs.existsSync(setupMarker)).toBe(true);
|
||||
expect(fs.existsSync(fullMarker)).toBe(false);
|
||||
});
|
||||
@@ -718,26 +727,24 @@ describe("listReadOnlyChannelPluginsForConfig", () => {
|
||||
expect(plugin?.meta.label).toBe("External Chat Manifest");
|
||||
expect(plugin?.meta.blurb).toBe("manifest config");
|
||||
expect(plugin?.meta.preferOver).toEqual(["legacy-external-chat"]);
|
||||
expect(plugin?.configSchema?.schema).toMatchObject({
|
||||
properties: {
|
||||
token: { type: "string" },
|
||||
},
|
||||
});
|
||||
expect(plugin?.configSchema?.uiHints?.token).toMatchObject({
|
||||
const schema = plugin?.configSchema?.schema as
|
||||
| { properties?: Record<string, { type?: string }> }
|
||||
| undefined;
|
||||
expect(schema?.properties?.token?.type).toBe("string");
|
||||
expectRecordFields(plugin?.configSchema?.uiHints?.token, {
|
||||
label: "Token",
|
||||
sensitive: true,
|
||||
});
|
||||
expect(
|
||||
plugin?.config.listAccountIds({ channels: { "external-chat": { token: "t" } } } as never),
|
||||
).toEqual(["default"]);
|
||||
expect(
|
||||
plugin?.config.resolveAccount({
|
||||
channels: { "external-chat": { token: "configured" } },
|
||||
} as never),
|
||||
).toMatchObject({
|
||||
const account = plugin?.config.resolveAccount({
|
||||
channels: { "external-chat": { token: "configured" } },
|
||||
} as never);
|
||||
const accountFields = expectRecordFields(account, {
|
||||
accountId: "default",
|
||||
config: { token: "configured" },
|
||||
});
|
||||
expectRecordFields(accountFields.config, { token: "configured" });
|
||||
expect(fs.existsSync(setupMarker)).toBe(false);
|
||||
expect(fs.existsSync(fullMarker)).toBe(false);
|
||||
});
|
||||
@@ -830,13 +837,15 @@ describe("listReadOnlyChannelPluginsForConfig", () => {
|
||||
}).find((entry) => entry.id === "external-chat");
|
||||
|
||||
expect(plugin?.config.listAccountIds(cfg)).toEqual(["default", "named"]);
|
||||
expect(plugin?.config.resolveAccount(cfg, "__proto__")).toMatchObject({
|
||||
const defaultAccount = plugin?.config.resolveAccount(cfg, "__proto__");
|
||||
const defaultFields = expectRecordFields(defaultAccount, {
|
||||
accountId: "default",
|
||||
config: { token: "default-token" },
|
||||
});
|
||||
expect(plugin?.config.resolveAccount(cfg, "inherited")).not.toMatchObject({
|
||||
config: { token: "prototype-token" },
|
||||
});
|
||||
expectRecordFields(defaultFields.config, { token: "default-token" });
|
||||
const inheritedAccount = plugin?.config.resolveAccount(cfg, "inherited") as
|
||||
| { config?: { token?: string } }
|
||||
| undefined;
|
||||
expect(inheritedAccount?.config?.token).not.toBe("prototype-token");
|
||||
});
|
||||
|
||||
it("keeps setup-entry precedence when channel config descriptors are not runtime cutoffs", () => {
|
||||
|
||||
Reference in New Issue
Block a user