mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 15:41:40 +00:00
test: isolate task flow link validation stores
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
import { peekSystemEvents, resetSystemEventsForTest } from "../infra/system-events.js";
|
||||
import { withTempDir } from "../test-helpers/temp-dir.js";
|
||||
import { createManagedTaskFlow, resetTaskFlowRegistryForTests } from "./task-flow-registry.js";
|
||||
import { configureTaskFlowRegistryRuntime } from "./task-flow-registry.store.js";
|
||||
import {
|
||||
createTaskRecord,
|
||||
findLatestTaskForOwnerKey,
|
||||
@@ -182,6 +183,32 @@ async function withTaskRegistryTempDir<T>(run: (root: string) => Promise<T>): Pr
|
||||
});
|
||||
}
|
||||
|
||||
function configureInMemoryTaskStoresForLinkValidationTests() {
|
||||
configureTaskRegistryRuntime({
|
||||
store: {
|
||||
loadSnapshot: () => ({
|
||||
tasks: new Map(),
|
||||
deliveryStates: new Map(),
|
||||
}),
|
||||
saveSnapshot: () => {},
|
||||
upsertTask: () => {},
|
||||
deleteTask: () => {},
|
||||
close: () => {},
|
||||
},
|
||||
});
|
||||
configureTaskFlowRegistryRuntime({
|
||||
store: {
|
||||
loadSnapshot: () => ({
|
||||
flows: new Map(),
|
||||
}),
|
||||
saveSnapshot: () => {},
|
||||
upsertFlow: () => {},
|
||||
deleteFlow: () => {},
|
||||
close: () => {},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
describe("task-registry", () => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
@@ -301,8 +328,9 @@ describe("task-registry", () => {
|
||||
it("rejects cross-owner parent flow links during task creation", async () => {
|
||||
await withTaskRegistryTempDir(async (root) => {
|
||||
process.env.OPENCLAW_STATE_DIR = root;
|
||||
resetTaskRegistryForTests();
|
||||
resetTaskFlowRegistryForTests();
|
||||
resetTaskRegistryForTests({ persist: false });
|
||||
resetTaskFlowRegistryForTests({ persist: false });
|
||||
configureInMemoryTaskStoresForLinkValidationTests();
|
||||
|
||||
const flow = createManagedTaskFlow({
|
||||
ownerKey: "agent:main:main",
|
||||
@@ -326,8 +354,9 @@ describe("task-registry", () => {
|
||||
it("rejects system-scoped parent flow links during task creation", async () => {
|
||||
await withTaskRegistryTempDir(async (root) => {
|
||||
process.env.OPENCLAW_STATE_DIR = root;
|
||||
resetTaskRegistryForTests();
|
||||
resetTaskFlowRegistryForTests();
|
||||
resetTaskRegistryForTests({ persist: false });
|
||||
resetTaskFlowRegistryForTests({ persist: false });
|
||||
configureInMemoryTaskStoresForLinkValidationTests();
|
||||
|
||||
const flow = createManagedTaskFlow({
|
||||
ownerKey: "agent:main:main",
|
||||
@@ -352,8 +381,9 @@ describe("task-registry", () => {
|
||||
it("rejects cross-owner flow links for existing tasks", async () => {
|
||||
await withTaskRegistryTempDir(async (root) => {
|
||||
process.env.OPENCLAW_STATE_DIR = root;
|
||||
resetTaskRegistryForTests();
|
||||
resetTaskFlowRegistryForTests();
|
||||
resetTaskRegistryForTests({ persist: false });
|
||||
resetTaskFlowRegistryForTests({ persist: false });
|
||||
configureInMemoryTaskStoresForLinkValidationTests();
|
||||
|
||||
const task = createTaskRecord({
|
||||
runtime: "acp",
|
||||
@@ -384,8 +414,9 @@ describe("task-registry", () => {
|
||||
it("rejects parent flow links once cancellation has been requested", async () => {
|
||||
await withTaskRegistryTempDir(async (root) => {
|
||||
process.env.OPENCLAW_STATE_DIR = root;
|
||||
resetTaskRegistryForTests();
|
||||
resetTaskFlowRegistryForTests();
|
||||
resetTaskRegistryForTests({ persist: false });
|
||||
resetTaskFlowRegistryForTests({ persist: false });
|
||||
configureInMemoryTaskStoresForLinkValidationTests();
|
||||
|
||||
const flow = createManagedTaskFlow({
|
||||
ownerKey: "agent:main:main",
|
||||
@@ -417,8 +448,9 @@ describe("task-registry", () => {
|
||||
it("rejects parent flow links for terminal flows", async () => {
|
||||
await withTaskRegistryTempDir(async (root) => {
|
||||
process.env.OPENCLAW_STATE_DIR = root;
|
||||
resetTaskRegistryForTests();
|
||||
resetTaskFlowRegistryForTests();
|
||||
resetTaskRegistryForTests({ persist: false });
|
||||
resetTaskFlowRegistryForTests({ persist: false });
|
||||
configureInMemoryTaskStoresForLinkValidationTests();
|
||||
|
||||
const flow = createManagedTaskFlow({
|
||||
ownerKey: "agent:main:main",
|
||||
|
||||
Reference in New Issue
Block a user