diff --git a/src/resources/extensions/sf/tests/auto-unit-closeout.test.mjs b/src/resources/extensions/sf/tests/auto-unit-closeout.test.mjs new file mode 100644 index 000000000..f6322b667 --- /dev/null +++ b/src/resources/extensions/sf/tests/auto-unit-closeout.test.mjs @@ -0,0 +1,67 @@ +import assert from "node:assert/strict"; +import { mkdirSync, mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { afterEach, test } from "vitest"; +import { closeoutUnit } from "../uok/auto-unit-closeout.js"; +import { + _resetLogs, + drainLogs, + setStderrLoggingEnabled, +} from "../workflow-logger.js"; + +const tmpRoots = []; + +afterEach(() => { + for (const dir of tmpRoots.splice(0)) { + rmSync(dir, { recursive: true, force: true }); + } + _resetLogs(); +}); + +function makeProject() { + const root = mkdtempSync(join(tmpdir(), "sf-closeout-")); + tmpRoots.push(root); + mkdirSync(join(root, ".sf"), { recursive: true }); + return root; +} + +test("closeoutUnit_when_activity_log_exists_imports_memory_extractor_without_warning", async () => { + const root = makeProject(); + const previousStderr = setStderrLoggingEnabled(false); + _resetLogs(); + try { + const ctx = { + model: { provider: "test", id: "test-model" }, + modelRegistry: { + getAvailable: () => [], + }, + sessionManager: { + getEntries: () => [ + { + role: "assistant", + content: "verification complete", + }, + ], + }, + }; + + const activityFile = await closeoutUnit( + ctx, + root, + "execute-task", + "M001/S01/T01", + Date.now(), + {}, + ); + + assert.match(activityFile, /execute-task-M001-S01-T01\.jsonl$/); + const warnings = drainLogs(); + assert.equal( + warnings.some((entry) => entry.message.includes("memory-extractor.js")), + false, + ); + } finally { + setStderrLoggingEnabled(previousStderr); + } +}); diff --git a/src/resources/extensions/sf/uok/auto-unit-closeout.js b/src/resources/extensions/sf/uok/auto-unit-closeout.js index 715e0418f..225896783 100644 --- a/src/resources/extensions/sf/uok/auto-unit-closeout.js +++ b/src/resources/extensions/sf/uok/auto-unit-closeout.js @@ -4,11 +4,11 @@ * that appears 6+ times in auto.ts. */ import { saveActivityLog } from "../activity-log.js"; +import { getErrorMessage } from "../error-utils.js"; import { snapshotUnitMetrics } from "../metrics.js"; import { updateSubscriptionTokensUsed } from "../preferences-models.js"; import { logWarning } from "../workflow-logger.js"; import { writeTurnGitTransaction } from "./gitops.js"; -import { getErrorMessage } from "../error-utils.js"; /** * Snapshot metrics, save activity log, and fire-and-forget memory extraction * for a completed unit. Returns the activity log file path (if any). @@ -41,7 +41,7 @@ export async function closeoutUnit( if (activityFile) { try { const { buildMemoryLLMCall, extractMemoriesFromUnit } = await import( - "./memory-extractor.js" + "../memory-extractor.js" ); const llmCallFn = buildMemoryLLMCall(ctx); if (llmCallFn) { @@ -59,10 +59,7 @@ export async function closeoutUnit( } } catch (err) { /* non-fatal */ - logWarning( - "engine", - `operation failed: ${getErrorMessage(err)}`, - ); + logWarning("engine", `operation failed: ${getErrorMessage(err)}`); } } if (opts?.traceId && opts.turnId && opts.gitAction && opts.gitStatus) {