mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 03:01:50 +03:00
perf(test): reuse temp root in slack prepare contract suite
This commit is contained in:
@@ -2,7 +2,7 @@ import type { App } from "@slack/bolt";
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||||
import type { OpenClawConfig } from "../../../config/config.js";
|
import type { OpenClawConfig } from "../../../config/config.js";
|
||||||
import type { RuntimeEnv } from "../../../runtime.js";
|
import type { RuntimeEnv } from "../../../runtime.js";
|
||||||
import type { ResolvedSlackAccount } from "../../accounts.js";
|
import type { ResolvedSlackAccount } from "../../accounts.js";
|
||||||
@@ -14,6 +14,29 @@ import { createSlackMonitorContext } from "../context.js";
|
|||||||
import { prepareSlackMessage } from "./prepare.js";
|
import { prepareSlackMessage } from "./prepare.js";
|
||||||
|
|
||||||
describe("slack prepareSlackMessage inbound contract", () => {
|
describe("slack prepareSlackMessage inbound contract", () => {
|
||||||
|
let fixtureRoot = "";
|
||||||
|
let caseId = 0;
|
||||||
|
|
||||||
|
function makeTmpStorePath() {
|
||||||
|
if (!fixtureRoot) {
|
||||||
|
throw new Error("fixtureRoot missing");
|
||||||
|
}
|
||||||
|
const dir = path.join(fixtureRoot, `case-${caseId++}`);
|
||||||
|
fs.mkdirSync(dir);
|
||||||
|
return { dir, storePath: path.join(dir, "sessions.json") };
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-slack-thread-"));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
if (fixtureRoot) {
|
||||||
|
fs.rmSync(fixtureRoot, { recursive: true, force: true });
|
||||||
|
fixtureRoot = "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function createDefaultSlackCtx() {
|
function createDefaultSlackCtx() {
|
||||||
const slackCtx = createSlackMonitorContext({
|
const slackCtx = createSlackMonitorContext({
|
||||||
cfg: {
|
cfg: {
|
||||||
@@ -301,9 +324,7 @@ describe("slack prepareSlackMessage inbound contract", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("marks first thread turn and injects thread history for a new thread session", async () => {
|
it("marks first thread turn and injects thread history for a new thread session", async () => {
|
||||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-slack-thread-"));
|
const { storePath } = makeTmpStorePath();
|
||||||
const storePath = path.join(tmpDir, "sessions.json");
|
|
||||||
try {
|
|
||||||
const replies = vi
|
const replies = vi
|
||||||
.fn()
|
.fn()
|
||||||
.mockResolvedValueOnce({
|
.mockResolvedValueOnce({
|
||||||
@@ -354,15 +375,10 @@ describe("slack prepareSlackMessage inbound contract", () => {
|
|||||||
expect(prepared!.ctxPayload.ThreadHistoryBody).toContain("follow-up question");
|
expect(prepared!.ctxPayload.ThreadHistoryBody).toContain("follow-up question");
|
||||||
expect(prepared!.ctxPayload.ThreadHistoryBody).not.toContain("current message");
|
expect(prepared!.ctxPayload.ThreadHistoryBody).not.toContain("current message");
|
||||||
expect(replies).toHaveBeenCalledTimes(2);
|
expect(replies).toHaveBeenCalledTimes(2);
|
||||||
} finally {
|
|
||||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not mark first thread turn when thread session already exists in store", async () => {
|
it("does not mark first thread turn when thread session already exists in store", async () => {
|
||||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-slack-thread-"));
|
const { storePath } = makeTmpStorePath();
|
||||||
const storePath = path.join(tmpDir, "sessions.json");
|
|
||||||
try {
|
|
||||||
const cfg = {
|
const cfg = {
|
||||||
session: { store: storePath },
|
session: { store: storePath },
|
||||||
channels: { slack: { enabled: true, replyToMode: "all", groupPolicy: "open" } },
|
channels: { slack: { enabled: true, replyToMode: "all", groupPolicy: "open" } },
|
||||||
@@ -411,9 +427,6 @@ describe("slack prepareSlackMessage inbound contract", () => {
|
|||||||
expect(prepared).toBeTruthy();
|
expect(prepared).toBeTruthy();
|
||||||
expect(prepared!.ctxPayload.IsFirstThreadTurn).toBeUndefined();
|
expect(prepared!.ctxPayload.IsFirstThreadTurn).toBeUndefined();
|
||||||
expect(prepared!.ctxPayload.ThreadHistoryBody).toBeUndefined();
|
expect(prepared!.ctxPayload.ThreadHistoryBody).toBeUndefined();
|
||||||
} finally {
|
|
||||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("includes thread_ts and parent_user_id metadata in thread replies", async () => {
|
it("includes thread_ts and parent_user_id metadata in thread replies", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user