mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 16:30:22 +00:00
test: combine task boundary scans
This commit is contained in:
82
src/tasks/task-boundaries.test.ts
Normal file
82
src/tasks/task-boundaries.test.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import {
|
||||
listTaskBoundarySourceFiles,
|
||||
readTaskBoundarySource,
|
||||
toTaskBoundaryRelativePath,
|
||||
} from "./import-boundary.test-helpers.js";
|
||||
|
||||
type TaskBoundarySource = {
|
||||
relative: string;
|
||||
source: string;
|
||||
};
|
||||
|
||||
const RAW_TASK_MUTATORS = [
|
||||
"createTaskRecord",
|
||||
"markTaskRunningByRunId",
|
||||
"markTaskTerminalByRunId",
|
||||
"markTaskTerminalById",
|
||||
"setTaskRunDeliveryStatusByRunId",
|
||||
] as const;
|
||||
|
||||
const RAW_TASK_MUTATOR_ALLOWED_CALLERS = new Set([
|
||||
"tasks/task-executor.ts",
|
||||
"tasks/task-registry.ts",
|
||||
"tasks/task-registry.maintenance.ts",
|
||||
]);
|
||||
|
||||
const TASK_FLOW_REGISTRY_ALLOWED_IMPORTERS = new Set([
|
||||
"tasks/task-flow-owner-access.ts",
|
||||
"tasks/task-flow-registry.audit.ts",
|
||||
"tasks/task-flow-registry.maintenance.ts",
|
||||
"tasks/task-flow-runtime-internal.ts",
|
||||
]);
|
||||
|
||||
const TASK_REGISTRY_ALLOWED_IMPORTERS = new Set([
|
||||
"tasks/runtime-internal.ts",
|
||||
"tasks/task-owner-access.ts",
|
||||
"tasks/task-status-access.ts",
|
||||
]);
|
||||
|
||||
let sources: TaskBoundarySource[] = [];
|
||||
|
||||
beforeAll(async () => {
|
||||
sources = await Promise.all(
|
||||
(await listTaskBoundarySourceFiles()).map(async (file) => ({
|
||||
relative: toTaskBoundaryRelativePath(file),
|
||||
source: await readTaskBoundarySource(file),
|
||||
})),
|
||||
);
|
||||
});
|
||||
|
||||
describe("task boundaries", () => {
|
||||
it("keeps raw task lifecycle mutators behind task internals", () => {
|
||||
const offenders: string[] = [];
|
||||
for (const { relative, source } of sources) {
|
||||
if (RAW_TASK_MUTATOR_ALLOWED_CALLERS.has(relative)) {
|
||||
continue;
|
||||
}
|
||||
for (const symbol of RAW_TASK_MUTATORS) {
|
||||
if (source.includes(`${symbol}(`)) {
|
||||
offenders.push(`${relative}:${symbol}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps direct task-flow-registry imports behind approved task-flow access seams", () => {
|
||||
const importers = sources
|
||||
.filter(({ source }) => source.includes("task-flow-registry.js"))
|
||||
.map(({ relative }) => relative);
|
||||
|
||||
expect(importers.toSorted()).toEqual([...TASK_FLOW_REGISTRY_ALLOWED_IMPORTERS].toSorted());
|
||||
});
|
||||
|
||||
it("keeps direct task-registry imports behind the approved task access seams", () => {
|
||||
const importers = sources
|
||||
.filter(({ source }) => source.includes("task-registry.js"))
|
||||
.map(({ relative }) => relative);
|
||||
|
||||
expect(importers.toSorted()).toEqual([...TASK_REGISTRY_ALLOWED_IMPORTERS].toSorted());
|
||||
});
|
||||
});
|
||||
@@ -1,39 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
listTaskBoundarySourceFiles,
|
||||
readTaskBoundarySource,
|
||||
toTaskBoundaryRelativePath,
|
||||
} from "./import-boundary.test-helpers.js";
|
||||
|
||||
const RAW_TASK_MUTATORS = [
|
||||
"createTaskRecord",
|
||||
"markTaskRunningByRunId",
|
||||
"markTaskTerminalByRunId",
|
||||
"markTaskTerminalById",
|
||||
"setTaskRunDeliveryStatusByRunId",
|
||||
] as const;
|
||||
|
||||
const ALLOWED_CALLERS = new Set([
|
||||
"tasks/task-executor.ts",
|
||||
"tasks/task-registry.ts",
|
||||
"tasks/task-registry.maintenance.ts",
|
||||
]);
|
||||
|
||||
describe("task executor boundary", () => {
|
||||
it("keeps raw task lifecycle mutators behind task internals", async () => {
|
||||
const offenders: string[] = [];
|
||||
for (const file of await listTaskBoundarySourceFiles()) {
|
||||
const relative = toTaskBoundaryRelativePath(file);
|
||||
if (ALLOWED_CALLERS.has(relative)) {
|
||||
continue;
|
||||
}
|
||||
const source = await readTaskBoundarySource(file);
|
||||
for (const symbol of RAW_TASK_MUTATORS) {
|
||||
if (source.includes(`${symbol}(`)) {
|
||||
offenders.push(`${relative}:${symbol}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -1,27 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
listTaskBoundarySourceFiles,
|
||||
readTaskBoundarySource,
|
||||
toTaskBoundaryRelativePath,
|
||||
} from "./import-boundary.test-helpers.js";
|
||||
|
||||
const ALLOWED_IMPORTERS = new Set([
|
||||
"tasks/task-flow-owner-access.ts",
|
||||
"tasks/task-flow-registry.audit.ts",
|
||||
"tasks/task-flow-registry.maintenance.ts",
|
||||
"tasks/task-flow-runtime-internal.ts",
|
||||
]);
|
||||
|
||||
describe("task flow registry import boundary", () => {
|
||||
it("keeps direct task-flow-registry imports behind approved task-flow access seams", async () => {
|
||||
const importers: string[] = [];
|
||||
for (const file of await listTaskBoundarySourceFiles()) {
|
||||
const relative = toTaskBoundaryRelativePath(file);
|
||||
const source = await readTaskBoundarySource(file);
|
||||
if (source.includes("task-flow-registry.js")) {
|
||||
importers.push(relative);
|
||||
}
|
||||
}
|
||||
expect(importers.toSorted()).toEqual([...ALLOWED_IMPORTERS].toSorted());
|
||||
});
|
||||
});
|
||||
@@ -1,26 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
listTaskBoundarySourceFiles,
|
||||
readTaskBoundarySource,
|
||||
toTaskBoundaryRelativePath,
|
||||
} from "./import-boundary.test-helpers.js";
|
||||
|
||||
const ALLOWED_IMPORTERS = new Set([
|
||||
"tasks/runtime-internal.ts",
|
||||
"tasks/task-owner-access.ts",
|
||||
"tasks/task-status-access.ts",
|
||||
]);
|
||||
|
||||
describe("task registry import boundary", () => {
|
||||
it("keeps direct task-registry imports behind the approved task access seams", async () => {
|
||||
const importers: string[] = [];
|
||||
for (const file of await listTaskBoundarySourceFiles()) {
|
||||
const relative = toTaskBoundaryRelativePath(file);
|
||||
const source = await readTaskBoundarySource(file);
|
||||
if (source.includes("task-registry.js")) {
|
||||
importers.push(relative);
|
||||
}
|
||||
}
|
||||
expect(importers.toSorted()).toEqual([...ALLOWED_IMPORTERS].toSorted());
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user