Skip to content

Commit 1d65631

Browse files
committed
test(ci): isolate inbound-handler state dirs
1 parent fa25f3f commit 1d65631

4 files changed

Lines changed: 79 additions & 63 deletions

File tree

tests/unit/inbound-handler-card-streaming.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from "node:fs";
2+
import os from "node:os";
23
import path from "node:path";
34
import { beforeEach, describe, expect, it, vi } from "vitest";
45
import type { DingTalkConfig } from "../../src/types";
@@ -98,6 +99,8 @@ import { clearCardRunRegistryForTest } from "../../src/card/card-run-registry";
9899
import { clearTargetDirectoryStateCache } from "../../src/targeting/target-directory-store";
99100

100101
const mockedUpsertInboundMessageContext = vi.mocked(messageContextStore.upsertInboundMessageContext);
102+
const TEST_TMP_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "dingtalk-card-streaming-unit-"));
103+
const STORE_PATH = path.join(TEST_TMP_DIR, "store.json");
101104

102105
function buildRuntime() {
103106
return {
@@ -115,7 +118,7 @@ function buildRuntime() {
115118
}),
116119
},
117120
session: {
118-
resolveStorePath: vi.fn().mockReturnValue("/tmp/store.json"),
121+
resolveStorePath: vi.fn().mockReturnValue(STORE_PATH),
119122
readSessionUpdatedAt: vi.fn().mockReturnValue(null),
120123
recordInboundSession: vi.fn().mockResolvedValue(undefined),
121124
},
@@ -139,7 +142,7 @@ function buildRuntime() {
139142
describe("inbound-handler card streaming", () => {
140143
beforeEach(() => {
141144
clearTargetDirectoryStateCache();
142-
const stateDir = path.join(path.dirname("/tmp/store.json"), "dingtalk-state");
145+
const stateDir = path.join(TEST_TMP_DIR, "dingtalk-state");
143146
try {
144147
fs.rmSync(stateDir, { recursive: true, force: true });
145148
} catch (e) {

tests/unit/inbound-handler-media.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from "node:fs";
2+
import os from "node:os";
23
import path from "node:path";
34
import { beforeEach, describe, expect, it, vi } from "vitest";
45
import type { DingTalkConfig } from "../../src/types";
@@ -107,6 +108,8 @@ const mockedUpsertInboundMessageContext = vi.mocked(messageContextStore.upsertIn
107108
const mockedResolveByMsgId = vi.mocked(messageContextStore.resolveByMsgId);
108109
const mockedResolveByAlias = vi.mocked(messageContextStore.resolveByAlias);
109110
const mockedResolveByCreatedAtWindow = vi.mocked(messageContextStore.resolveByCreatedAtWindow);
111+
const TEST_TMP_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "dingtalk-media-unit-"));
112+
const STORE_PATH = path.join(TEST_TMP_DIR, "store.json");
110113

111114
function buildRuntime() {
112115
return {
@@ -124,7 +127,7 @@ function buildRuntime() {
124127
}),
125128
},
126129
session: {
127-
resolveStorePath: vi.fn().mockReturnValue("/tmp/store.json"),
130+
resolveStorePath: vi.fn().mockReturnValue(STORE_PATH),
128131
readSessionUpdatedAt: vi.fn().mockReturnValue(null),
129132
recordInboundSession: vi.fn().mockResolvedValue(undefined),
130133
},
@@ -149,7 +152,7 @@ describe("inbound-handler media handling", () => {
149152
beforeEach(() => {
150153
clearTargetDirectoryStateCache();
151154
// Use rimraf-style cleanup: retry on ENOTEMPTY
152-
const stateDir = path.join(path.dirname("/tmp/store.json"), "dingtalk-state");
155+
const stateDir = path.join(TEST_TMP_DIR, "dingtalk-state");
153156
try {
154157
fs.rmSync(stateDir, { recursive: true, force: true });
155158
} catch (e) {
@@ -625,7 +628,7 @@ describe("inbound-handler media handling", () => {
625628
{
626629
accountId: "main",
627630
log: undefined,
628-
storePath: "/tmp/store.json",
631+
storePath: STORE_PATH,
629632
conversationId: "cid_ok",
630633
quotedRef: {
631634
targetDirection: "inbound",

0 commit comments

Comments
 (0)