Skip to content

Commit a51c976

Browse files
committed
refactor(tasks): rename flow registry modules to task-flow
1 parent c405bcf commit a51c976

15 files changed

Lines changed: 346 additions & 323 deletions

‎src/tasks/flow-owner-access.ts‎

Lines changed: 0 additions & 48 deletions
This file was deleted.

‎src/tasks/flow-registry.paths.ts‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎src/tasks/flow-registry.store.ts‎

Lines changed: 0 additions & 78 deletions
This file was deleted.

‎src/tasks/flow-runtime-internal.ts‎

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { afterEach, describe, expect, it } from "vitest";
22
import {
3-
findLatestFlowForOwner,
4-
getFlowByIdForOwner,
5-
listFlowsForOwner,
6-
resolveFlowForLookupTokenForOwner,
7-
} from "./flow-owner-access.js";
8-
import { createManagedFlow, resetFlowRegistryForTests } from "./flow-registry.js";
3+
findLatestTaskFlowForOwner,
4+
getTaskFlowByIdForOwner,
5+
listTaskFlowsForOwner,
6+
resolveTaskFlowForLookupTokenForOwner,
7+
} from "./task-flow-owner-access.js";
8+
import { createManagedTaskFlow, resetTaskFlowRegistryForTests } from "./task-flow-registry.js";
99

1010
afterEach(() => {
11-
resetFlowRegistryForTests({ persist: false });
11+
resetTaskFlowRegistryForTests({ persist: false });
1212
});
1313

14-
describe("flow owner access", () => {
14+
describe("task flow owner access", () => {
1515
it("returns owner-scoped flows for direct and owner-key lookups", () => {
16-
const older = createManagedFlow({
16+
const older = createManagedTaskFlow({
1717
ownerKey: "agent:main:main",
1818
controllerId: "tests/owner-access",
1919
goal: "Older flow",
2020
createdAt: 100,
2121
updatedAt: 100,
2222
});
23-
const latest = createManagedFlow({
23+
const latest = createManagedTaskFlow({
2424
ownerKey: "agent:main:main",
2525
controllerId: "tests/owner-access",
2626
goal: "Latest flow",
@@ -29,56 +29,56 @@ describe("flow owner access", () => {
2929
});
3030

3131
expect(
32-
getFlowByIdForOwner({
32+
getTaskFlowByIdForOwner({
3333
flowId: older.flowId,
3434
callerOwnerKey: "agent:main:main",
3535
})?.flowId,
3636
).toBe(older.flowId);
3737
expect(
38-
findLatestFlowForOwner({
38+
findLatestTaskFlowForOwner({
3939
callerOwnerKey: "agent:main:main",
4040
})?.flowId,
4141
).toBe(latest.flowId);
4242
expect(
43-
resolveFlowForLookupTokenForOwner({
43+
resolveTaskFlowForLookupTokenForOwner({
4444
token: "agent:main:main",
4545
callerOwnerKey: "agent:main:main",
4646
})?.flowId,
4747
).toBe(latest.flowId);
4848
expect(
49-
listFlowsForOwner({
49+
listTaskFlowsForOwner({
5050
callerOwnerKey: "agent:main:main",
5151
}).map((flow) => flow.flowId),
5252
).toEqual([latest.flowId, older.flowId]);
5353
});
5454

5555
it("denies cross-owner flow reads", () => {
56-
const flow = createManagedFlow({
56+
const flow = createManagedTaskFlow({
5757
ownerKey: "agent:main:main",
5858
controllerId: "tests/owner-access",
5959
goal: "Hidden flow",
6060
});
6161

6262
expect(
63-
getFlowByIdForOwner({
63+
getTaskFlowByIdForOwner({
6464
flowId: flow.flowId,
6565
callerOwnerKey: "agent:main:other",
6666
}),
6767
).toBeUndefined();
6868
expect(
69-
resolveFlowForLookupTokenForOwner({
69+
resolveTaskFlowForLookupTokenForOwner({
7070
token: flow.flowId,
7171
callerOwnerKey: "agent:main:other",
7272
}),
7373
).toBeUndefined();
7474
expect(
75-
resolveFlowForLookupTokenForOwner({
75+
resolveTaskFlowForLookupTokenForOwner({
7676
token: "agent:main:main",
7777
callerOwnerKey: "agent:main:other",
7878
}),
7979
).toBeUndefined();
8080
expect(
81-
listFlowsForOwner({
81+
listTaskFlowsForOwner({
8282
callerOwnerKey: "agent:main:other",
8383
}),
8484
).toEqual([]);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {
2+
findLatestTaskFlowForOwnerKey,
3+
getTaskFlowById,
4+
listTaskFlowsForOwnerKey,
5+
} from "./task-flow-registry.js";
6+
import type { TaskFlowRecord } from "./task-flow-registry.types.js";
7+
8+
function normalizeOwnerKey(ownerKey?: string): string | undefined {
9+
const trimmed = ownerKey?.trim();
10+
return trimmed ? trimmed : undefined;
11+
}
12+
13+
function canOwnerAccessFlow(flow: TaskFlowRecord, callerOwnerKey: string): boolean {
14+
return normalizeOwnerKey(flow.ownerKey) === normalizeOwnerKey(callerOwnerKey);
15+
}
16+
17+
export function getTaskFlowByIdForOwner(params: {
18+
flowId: string;
19+
callerOwnerKey: string;
20+
}): TaskFlowRecord | undefined {
21+
const flow = getTaskFlowById(params.flowId);
22+
return flow && canOwnerAccessFlow(flow, params.callerOwnerKey) ? flow : undefined;
23+
}
24+
25+
export function listTaskFlowsForOwner(params: { callerOwnerKey: string }): TaskFlowRecord[] {
26+
const ownerKey = normalizeOwnerKey(params.callerOwnerKey);
27+
return ownerKey ? listTaskFlowsForOwnerKey(ownerKey) : [];
28+
}
29+
30+
export function findLatestTaskFlowForOwner(params: {
31+
callerOwnerKey: string;
32+
}): TaskFlowRecord | undefined {
33+
const ownerKey = normalizeOwnerKey(params.callerOwnerKey);
34+
return ownerKey ? findLatestTaskFlowForOwnerKey(ownerKey) : undefined;
35+
}
36+
37+
export function resolveTaskFlowForLookupTokenForOwner(params: {
38+
token: string;
39+
callerOwnerKey: string;
40+
}): TaskFlowRecord | undefined {
41+
const direct = getTaskFlowByIdForOwner({
42+
flowId: params.token,
43+
callerOwnerKey: params.callerOwnerKey,
44+
});
45+
if (direct) {
46+
return direct;
47+
}
48+
const normalizedToken = normalizeOwnerKey(params.token);
49+
const normalizedCallerOwnerKey = normalizeOwnerKey(params.callerOwnerKey);
50+
if (!normalizedToken || normalizedToken !== normalizedCallerOwnerKey) {
51+
return undefined;
52+
}
53+
return findLatestTaskFlowForOwner({ callerOwnerKey: normalizedCallerOwnerKey });
54+
}

src/tasks/flow-registry-import-boundary.test.ts renamed to src/tasks/task-flow-registry-import-boundary.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { describe, expect, it } from "vitest";
55
const TASK_ROOT = path.resolve(import.meta.dirname);
66
const SRC_ROOT = path.resolve(TASK_ROOT, "..");
77

8-
const ALLOWED_IMPORTERS = new Set(["tasks/flow-owner-access.ts", "tasks/flow-runtime-internal.ts"]);
8+
const ALLOWED_IMPORTERS = new Set([
9+
"tasks/task-flow-owner-access.ts",
10+
"tasks/task-flow-runtime-internal.ts",
11+
]);
912

1013
async function listSourceFiles(root: string): Promise<string[]> {
1114
const entries = await fs.readdir(root, { withFileTypes: true });
@@ -24,13 +27,13 @@ async function listSourceFiles(root: string): Promise<string[]> {
2427
return files;
2528
}
2629

27-
describe("flow registry import boundary", () => {
28-
it("keeps direct flow-registry imports behind approved flow access seams", async () => {
30+
describe("task flow registry import boundary", () => {
31+
it("keeps direct task-flow-registry imports behind approved task-flow access seams", async () => {
2932
const importers: string[] = [];
3033
for (const file of await listSourceFiles(SRC_ROOT)) {
3134
const relative = path.relative(SRC_ROOT, file).replaceAll(path.sep, "/");
3235
const source = await fs.readFile(file, "utf8");
33-
if (source.includes("flow-registry.js")) {
36+
if (source.includes("task-flow-registry.js")) {
3437
importers.push(relative);
3538
}
3639
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import path from "node:path";
2+
import { resolveTaskStateDir } from "./task-registry.paths.js";
3+
4+
export function resolveTaskFlowRegistryDir(env: NodeJS.ProcessEnv = process.env): string {
5+
return path.join(resolveTaskStateDir(env), "flows");
6+
}
7+
8+
export function resolveTaskFlowRegistrySqlitePath(env: NodeJS.ProcessEnv = process.env): string {
9+
return path.join(resolveTaskFlowRegistryDir(env), "registry.sqlite");
10+
}

0 commit comments

Comments
 (0)