fix(uok): import memory extractor from closeout
This commit is contained in:
parent
c5850c8039
commit
9ba9b55f7a
2 changed files with 70 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue