mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-14 03:30:47 +00:00
test: tighten small model risk assertions
This commit is contained in:
@@ -2,6 +2,18 @@ import { describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { collectSmallModelRiskFindings } from "./audit-extra.summary.js";
|
||||
|
||||
function requireFirstSmallModelFinding(
|
||||
findings: ReturnType<typeof collectSmallModelRiskFindings>,
|
||||
label: string,
|
||||
) {
|
||||
const [finding] = findings;
|
||||
expect(finding, label).toBeDefined();
|
||||
if (!finding) {
|
||||
throw new Error(`Expected small-model risk finding for ${label}`);
|
||||
}
|
||||
return finding;
|
||||
}
|
||||
|
||||
describe("security audit small-model risk findings", () => {
|
||||
it("scores small-model risk by tool/sandbox exposure", () => {
|
||||
const cases: Array<{
|
||||
@@ -35,37 +47,43 @@ describe("security audit small-model risk findings", () => {
|
||||
];
|
||||
|
||||
for (const testCase of cases) {
|
||||
const [finding] = collectSmallModelRiskFindings({
|
||||
cfg: testCase.cfg,
|
||||
env: process.env,
|
||||
});
|
||||
expect(finding?.severity, testCase.name).toBe(testCase.expectedSeverity);
|
||||
const finding = requireFirstSmallModelFinding(
|
||||
collectSmallModelRiskFindings({
|
||||
cfg: testCase.cfg,
|
||||
env: process.env,
|
||||
}),
|
||||
testCase.name,
|
||||
);
|
||||
expect(finding.severity, testCase.name).toBe(testCase.expectedSeverity);
|
||||
for (const snippet of testCase.detailIncludes) {
|
||||
expect(finding?.detail, `${testCase.name}:${snippet}`).toContain(snippet);
|
||||
expect(finding.detail, `${testCase.name}:${snippet}`).toContain(snippet);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("resolves configured aliases before parameter-size classification", () => {
|
||||
const [finding] = collectSmallModelRiskFindings({
|
||||
cfg: {
|
||||
agents: {
|
||||
defaults: {
|
||||
model: { primary: "tiny" },
|
||||
models: {
|
||||
"ollama/mistral-8b": { alias: "tiny" },
|
||||
const finding = requireFirstSmallModelFinding(
|
||||
collectSmallModelRiskFindings({
|
||||
cfg: {
|
||||
agents: {
|
||||
defaults: {
|
||||
model: { primary: "tiny" },
|
||||
models: {
|
||||
"ollama/mistral-8b": { alias: "tiny" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
tools: { web: { search: { enabled: true }, fetch: { enabled: true } } },
|
||||
browser: { enabled: true },
|
||||
} satisfies OpenClawConfig,
|
||||
env: {},
|
||||
});
|
||||
tools: { web: { search: { enabled: true }, fetch: { enabled: true } } },
|
||||
browser: { enabled: true },
|
||||
} satisfies OpenClawConfig,
|
||||
env: {},
|
||||
}),
|
||||
"configured alias",
|
||||
);
|
||||
|
||||
expect(finding?.checkId).toBe("models.small_params");
|
||||
expect(finding?.detail).toContain("ollama/mistral-8b");
|
||||
expect(finding?.detail).toContain("@ agents.defaults.model.primary");
|
||||
expect(finding?.detail).not.toContain("- tiny");
|
||||
expect(finding.checkId).toBe("models.small_params");
|
||||
expect(finding.detail).toContain("ollama/mistral-8b");
|
||||
expect(finding.detail).toContain("@ agents.defaults.model.primary");
|
||||
expect(finding.detail).not.toContain("- tiny");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user