06e959e7a5
CI / check (pull_request) Failing after 1m39s
Cover high-priority untested modules: - util: base32, result, refs-field, storage-root, log-tag - util-agent: storage (normalizeWorkflowConfig, resolveStorageRoot), run (parseArgv) - agent-builtin: tools (read-file, write-file, run-command), session, detail 627 → 719 tests (+92), all passing. Refs #35
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { mkdtemp, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
import { createMemoryStore } from "@ocas/core";
|
|
import { storeBuiltinDetail } from "../src/detail.js";
|
|
import { appendSessionTurn, initSessionDir } from "../src/session.js";
|
|
import type { BuiltinTurnPayload } from "../src/types.js";
|
|
|
|
describe("storeBuiltinDetail", () => {
|
|
let storageRoot: string;
|
|
|
|
beforeEach(async () => {
|
|
storageRoot = await mkdtemp(join(tmpdir(), "builtin-detail-storage-"));
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await rm(storageRoot, { recursive: true, force: true });
|
|
});
|
|
|
|
const makeTurn = (role: "assistant" | "tool", content: string): BuiltinTurnPayload => ({
|
|
role,
|
|
content,
|
|
toolCalls: null,
|
|
reasoning: null,
|
|
});
|
|
|
|
test("stores detail with turns, returns hash and turnCount", async () => {
|
|
const store = createMemoryStore();
|
|
await initSessionDir(storageRoot);
|
|
const sid = "detail-test";
|
|
await appendSessionTurn(storageRoot, sid, makeTurn("tool", "question"));
|
|
await appendSessionTurn(storageRoot, sid, makeTurn("assistant", "answer"));
|
|
|
|
const result = await storeBuiltinDetail(store, storageRoot, sid, "test-model", 1000, 2000);
|
|
expect(result.turnCount).toBe(2);
|
|
expect(typeof result.detailHash).toBe("string");
|
|
expect(result.detailHash.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test("empty session returns turnCount 0", async () => {
|
|
const store = createMemoryStore();
|
|
const sid = "empty-session";
|
|
|
|
const result = await storeBuiltinDetail(store, storageRoot, sid, "test-model", 1000, 2000);
|
|
expect(result.turnCount).toBe(0);
|
|
expect(typeof result.detailHash).toBe("string");
|
|
});
|
|
});
|