mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
test(plugins): keep policy warning coverage within lint budget
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { InstallPolicyWarningAcknowledgementRequest } from "./install-security-scan.types.js";
|
||||
import { expectOneShotInstallPolicyWarningAcknowledgement } from "./test-helpers/install-policy-warning.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
applyUninstall: vi.fn(),
|
||||
@@ -797,25 +797,7 @@ describe("plugin management service", () => {
|
||||
onInstallPolicyWarning: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
const installParams = expectDefined(
|
||||
mocks.clawhubInstall.mock.calls[0],
|
||||
"clawhub install call test invariant",
|
||||
)[0] as {
|
||||
onInstallPolicyWarning?: (
|
||||
request: InstallPolicyWarningAcknowledgementRequest,
|
||||
) => Promise<boolean>;
|
||||
};
|
||||
const acknowledge = installParams.onInstallPolicyWarning;
|
||||
if (!acknowledge) {
|
||||
throw new Error("expected install-policy acknowledgement callback");
|
||||
}
|
||||
const warningRequest: InstallPolicyWarningAcknowledgementRequest = {
|
||||
targetName: "diffs",
|
||||
targetType: "plugin",
|
||||
requestMode: "install",
|
||||
};
|
||||
expect(await acknowledge(warningRequest)).toBe(true);
|
||||
expect(await acknowledge(warningRequest)).toBe(false);
|
||||
await expectOneShotInstallPolicyWarningAcknowledgement(mocks.clawhubInstall);
|
||||
});
|
||||
|
||||
it("removes only the newly installed managed target after persistence conflicts", async () => {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
import { expect } from "vitest";
|
||||
import type { InstallPolicyWarningAcknowledgementRequest } from "../install-security-scan.types.js";
|
||||
|
||||
type InstallPolicyWarningCall = {
|
||||
onInstallPolicyWarning?: (
|
||||
request: InstallPolicyWarningAcknowledgementRequest,
|
||||
) => Promise<boolean>;
|
||||
};
|
||||
|
||||
export async function expectOneShotInstallPolicyWarningAcknowledgement(mock: {
|
||||
mock: { calls: unknown[][] };
|
||||
}): Promise<void> {
|
||||
const call = expectDefined(mock.mock.calls[0], "clawhub install call test invariant");
|
||||
const params = call[0] as InstallPolicyWarningCall;
|
||||
const acknowledge = expectDefined(
|
||||
params.onInstallPolicyWarning,
|
||||
"expected install-policy acknowledgement callback",
|
||||
);
|
||||
const request: InstallPolicyWarningAcknowledgementRequest = {
|
||||
targetName: "diffs",
|
||||
targetType: "plugin",
|
||||
requestMode: "install",
|
||||
};
|
||||
expect(await acknowledge(request)).toBe(true);
|
||||
expect(await acknowledge(request)).toBe(false);
|
||||
}
|
||||
Reference in New Issue
Block a user