test(perf): trim cron and audit fixture overhead

This commit is contained in:
Peter Steinberger
2026-03-02 19:47:43 +00:00
parent d979eeda9f
commit 39afcee864
2 changed files with 12 additions and 16 deletions

View File

@@ -20,11 +20,11 @@ import {
import type { CronJob, CronJobState } from "./types.js"; import type { CronJob, CronJobState } from "./types.js";
const noopLogger = { const noopLogger = {
info: vi.fn(), info: () => {},
warn: vi.fn(), warn: () => {},
error: vi.fn(), error: () => {},
debug: vi.fn(), debug: () => {},
trace: vi.fn(), trace: () => {},
}; };
const TOP_OF_HOUR_STAGGER_MS = 5 * 60 * 1_000; const TOP_OF_HOUR_STAGGER_MS = 5 * 60 * 1_000;
const FAST_TIMEOUT_SECONDS = 0.0025; const FAST_TIMEOUT_SECONDS = 0.0025;
@@ -447,7 +447,7 @@ describe("Cron issue regressions", () => {
const now = Date.parse("2026-02-06T10:05:00.000Z"); const now = Date.parse("2026-02-06T10:05:00.000Z");
const state = createRunningCronServiceState({ const state = createRunningCronServiceState({
storePath: store.storePath, storePath: store.storePath,
log: noopLogger, log: noopLogger as unknown as Parameters<typeof createRunningCronServiceState>[0]["log"],
nowMs: () => now, nowMs: () => now,
jobs: [createDueIsolatedJob({ id: "due", nowMs: now, nextRunAtMs: now - 1 })], jobs: [createDueIsolatedJob({ id: "due", nowMs: now, nextRunAtMs: now - 1 })],
}); });

View File

@@ -149,7 +149,7 @@ function expectNoFinding(res: SecurityAuditReport, checkId: string): void {
describe("security audit", () => { describe("security audit", () => {
let fixtureRoot = ""; let fixtureRoot = "";
let caseId = 0; let caseId = 0;
let channelSecurityStateDir = ""; let channelSecurityRoot = "";
let sharedCodeSafetyStateDir = ""; let sharedCodeSafetyStateDir = "";
let sharedCodeSafetyWorkspaceDir = ""; let sharedCodeSafetyWorkspaceDir = "";
let sharedExtensionsStateDir = ""; let sharedExtensionsStateDir = "";
@@ -162,12 +162,11 @@ describe("security audit", () => {
}; };
const withChannelSecurityStateDir = async (fn: (tmp: string) => Promise<void>) => { const withChannelSecurityStateDir = async (fn: (tmp: string) => Promise<void>) => {
const channelSecurityStateDir = path.join(channelSecurityRoot, `state-${caseId++}`);
const credentialsDir = path.join(channelSecurityStateDir, "credentials"); const credentialsDir = path.join(channelSecurityStateDir, "credentials");
await fs.rm(credentialsDir, { recursive: true, force: true });
await fs.mkdir(credentialsDir, { recursive: true, mode: 0o700 }); await fs.mkdir(credentialsDir, { recursive: true, mode: 0o700 });
await withEnvAsync( await withEnvAsync({ OPENCLAW_STATE_DIR: channelSecurityStateDir }, () =>
{ OPENCLAW_STATE_DIR: channelSecurityStateDir }, fn(channelSecurityStateDir),
async () => await fn(channelSecurityStateDir),
); );
}; };
@@ -213,11 +212,8 @@ description: test skill
beforeAll(async () => { beforeAll(async () => {
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-security-audit-")); fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-security-audit-"));
channelSecurityStateDir = path.join(fixtureRoot, "channel-security"); channelSecurityRoot = path.join(fixtureRoot, "channel-security");
await fs.mkdir(path.join(channelSecurityStateDir, "credentials"), { await fs.mkdir(channelSecurityRoot, { recursive: true, mode: 0o700 });
recursive: true,
mode: 0o700,
});
const codeSafetyFixture = await createSharedCodeSafetyFixture(); const codeSafetyFixture = await createSharedCodeSafetyFixture();
sharedCodeSafetyStateDir = codeSafetyFixture.stateDir; sharedCodeSafetyStateDir = codeSafetyFixture.stateDir;
sharedCodeSafetyWorkspaceDir = codeSafetyFixture.workspaceDir; sharedCodeSafetyWorkspaceDir = codeSafetyFixture.workspaceDir;