perf(test): skip skills snapshot work in fast env

This commit is contained in:
Peter Steinberger
2026-02-14 20:07:47 +00:00
parent 9762e48134
commit e1220c48f5
2 changed files with 36 additions and 16 deletions
+10
View File
@@ -127,6 +127,16 @@ export async function ensureSkillSnapshot(params: {
skillsSnapshot?: SessionEntry["skillsSnapshot"]; skillsSnapshot?: SessionEntry["skillsSnapshot"];
systemSent: boolean; systemSent: boolean;
}> { }> {
if (process.env.OPENCLAW_TEST_FAST === "1") {
// In fast unit-test runs we skip filesystem scanning, watchers, and session-store writes.
// Dedicated skills tests cover snapshot generation behavior.
return {
sessionEntry: params.sessionEntry,
skillsSnapshot: params.sessionEntry?.skillsSnapshot,
systemSent: params.sessionEntry?.systemSent ?? false,
};
}
const { const {
sessionEntry, sessionEntry,
sessionStore, sessionStore,
+26 -16
View File
@@ -121,6 +121,7 @@ export async function runCronIsolatedAgentTurn(params: {
agentId?: string; agentId?: string;
lane?: string; lane?: string;
}): Promise<RunCronAgentTurnResult> { }): Promise<RunCronAgentTurnResult> {
const isFastTestEnv = process.env.OPENCLAW_TEST_FAST === "1";
const defaultAgentId = resolveDefaultAgentId(params.cfg); const defaultAgentId = resolveDefaultAgentId(params.cfg);
const requestedAgentId = const requestedAgentId =
typeof params.agentId === "string" && params.agentId.trim() typeof params.agentId === "string" && params.agentId.trim()
@@ -162,7 +163,7 @@ export async function runCronIsolatedAgentTurn(params: {
const agentDir = resolveAgentDir(params.cfg, agentId); const agentDir = resolveAgentDir(params.cfg, agentId);
const workspace = await ensureAgentWorkspace({ const workspace = await ensureAgentWorkspace({
dir: workspaceDirRaw, dir: workspaceDirRaw,
ensureBootstrapFiles: !agentCfg?.skipBootstrap, ensureBootstrapFiles: !agentCfg?.skipBootstrap && !isFastTestEnv,
}); });
const workspaceDir = workspace.dir; const workspaceDir = workspace.dir;
@@ -232,6 +233,9 @@ export async function runCronIsolatedAgentTurn(params: {
? `${agentSessionKey}:run:${runSessionId}` ? `${agentSessionKey}:run:${runSessionId}`
: agentSessionKey; : agentSessionKey;
const persistSessionEntry = async () => { const persistSessionEntry = async () => {
if (isFastTestEnv) {
return;
}
cronSession.store[agentSessionKey] = cronSession.sessionEntry; cronSession.store[agentSessionKey] = cronSession.sessionEntry;
if (runSessionKey !== agentSessionKey) { if (runSessionKey !== agentSessionKey) {
cronSession.store[runSessionKey] = cronSession.sessionEntry; cronSession.store[runSessionKey] = cronSession.sessionEntry;
@@ -364,24 +368,30 @@ export async function runCronIsolatedAgentTurn(params: {
`${commandBody}\n\nReturn your summary as plain text; it will be delivered automatically. If the task explicitly calls for messaging a specific external recipient, note who/where it should go instead of sending it yourself.`.trim(); `${commandBody}\n\nReturn your summary as plain text; it will be delivered automatically. If the task explicitly calls for messaging a specific external recipient, note who/where it should go instead of sending it yourself.`.trim();
} }
const existingSnapshot = cronSession.sessionEntry.skillsSnapshot; let skillsSnapshot = cronSession.sessionEntry.skillsSnapshot;
const skillsSnapshotVersion = getSkillsSnapshotVersion(workspaceDir); if (isFastTestEnv) {
const needsSkillsSnapshot = // Fast unit-test mode: avoid scanning the workspace and writing session stores.
!existingSnapshot || existingSnapshot.version !== skillsSnapshotVersion; skillsSnapshot = skillsSnapshot ?? { prompt: "", skills: [] };
const skillsSnapshot = needsSkillsSnapshot } else {
? buildWorkspaceSkillSnapshot(workspaceDir, { const existingSnapshot = cronSession.sessionEntry.skillsSnapshot;
const skillsSnapshotVersion = getSkillsSnapshotVersion(workspaceDir);
const needsSkillsSnapshot =
!existingSnapshot || existingSnapshot.version !== skillsSnapshotVersion;
if (needsSkillsSnapshot) {
skillsSnapshot = buildWorkspaceSkillSnapshot(workspaceDir, {
config: cfgWithAgentDefaults, config: cfgWithAgentDefaults,
eligibility: { remote: getRemoteSkillEligibility() }, eligibility: { remote: getRemoteSkillEligibility() },
snapshotVersion: skillsSnapshotVersion, snapshotVersion: skillsSnapshotVersion,
}) });
: cronSession.sessionEntry.skillsSnapshot; if (skillsSnapshot) {
if (needsSkillsSnapshot && skillsSnapshot) { cronSession.sessionEntry = {
cronSession.sessionEntry = { ...cronSession.sessionEntry,
...cronSession.sessionEntry, updatedAt: Date.now(),
updatedAt: Date.now(), skillsSnapshot,
skillsSnapshot, };
}; await persistSessionEntry();
await persistSessionEntry(); }
}
} }
// Persist systemSent before the run, mirroring the inbound auto-reply behavior. // Persist systemSent before the run, mirroring the inbound auto-reply behavior.