@afokapu/atdd-flow 0.3.12 → 0.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core.ts +3 -2
- package/src/tasks.ts +3 -1
- package/src/threads.ts +9 -4
package/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, resolve } from "node:path";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
5
6
|
|
|
6
7
|
export type Role = { address: string; branch: string; agent?: string; purpose?: string; worktree?: string; base?: string };
|
|
7
8
|
export type Group = { role?: string; members?: string[] };
|
|
@@ -129,8 +130,8 @@ export const required = <T>(value: T | undefined, label: string) => {
|
|
|
129
130
|
return value;
|
|
130
131
|
};
|
|
131
132
|
export const yaml = {
|
|
132
|
-
parse: <T>(text: string) =>
|
|
133
|
-
print: (value: unknown) =>
|
|
133
|
+
parse: <T>(text: string) => parseYaml(text) as T,
|
|
134
|
+
print: (value: unknown) => stringifyYaml(value, { collectionStyle: "flow", flowCollectionPadding: false }),
|
|
134
135
|
};
|
|
135
136
|
|
|
136
137
|
export function addressParts(address: string) {
|
package/src/tasks.ts
CHANGED
|
@@ -246,8 +246,10 @@ export async function unblock(root: string, projectName: string, id: string, arg
|
|
|
246
246
|
const task = await readTask(root, projectName, taskId(id));
|
|
247
247
|
const actor = await canonicalAddress(root, required(words(args, "--by"), "--by"));
|
|
248
248
|
if (actor !== task.coordinator) throw new Error(`Only ${task.coordinator} may unblock task ${id}.`);
|
|
249
|
-
if (task.status !== "in_progress") throw new Error(`Task ${id} can only be unblocked while in_progress.`);
|
|
249
|
+
if (task.status !== "todo" && task.status !== "in_progress") throw new Error(`Task ${id} can only be unblocked while todo or in_progress.`);
|
|
250
250
|
if (!task.blocker) throw new Error(`Task ${id} has no blocker to clear.`);
|
|
251
|
+
const waiting = await ready(root, projectName, task);
|
|
252
|
+
if (waiting.length) throw new Error(`Task ${id} is waiting on: ${waiting.join(", ")}.`);
|
|
251
253
|
const { assertDependentsMayUnblock } = await import("./ephemeral-resources");
|
|
252
254
|
await assertDependentsMayUnblock(root, { project: projectName, task: id });
|
|
253
255
|
delete task.blocker;
|
package/src/threads.ts
CHANGED
|
@@ -84,12 +84,16 @@ function inboxDirectory(root: string, address: string) {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
const pause = (milliseconds: number) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
87
|
+
const inboxLockStaleMs = 30_000;
|
|
88
|
+
const inboxLockAcquireTimeoutMs = 5_000;
|
|
89
|
+
const inboxLockRetryMs = 5;
|
|
87
90
|
|
|
88
91
|
/** mkdir is atomic across CLI processes; stale locks are recoverable after a crashed writer. */
|
|
89
92
|
async function withInboxLock<T>(directory: string, action: () => Promise<T>) {
|
|
90
93
|
await mkdir(directory, { recursive: true });
|
|
91
94
|
const lock = join(directory, "queue.lock");
|
|
92
|
-
|
|
95
|
+
const deadline = Date.now() + inboxLockAcquireTimeoutMs;
|
|
96
|
+
while (Date.now() < deadline) {
|
|
93
97
|
try {
|
|
94
98
|
await mkdir(lock, { recursive: false });
|
|
95
99
|
try { return await action(); }
|
|
@@ -97,9 +101,10 @@ async function withInboxLock<T>(directory: string, action: () => Promise<T>) {
|
|
|
97
101
|
} catch (error) {
|
|
98
102
|
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
99
103
|
try {
|
|
100
|
-
if (Date.now() - (await stat(lock)).mtimeMs >
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
if (Date.now() - (await stat(lock)).mtimeMs > inboxLockStaleMs) await rm(lock, { recursive: true, force: true });
|
|
105
|
+
} catch { /* A competing release or recovery is retried below. */ }
|
|
106
|
+
const remaining = deadline - Date.now();
|
|
107
|
+
if (remaining > 0) await pause(Math.min(inboxLockRetryMs, remaining));
|
|
103
108
|
}
|
|
104
109
|
}
|
|
105
110
|
throw new Error(`Timed out waiting for inbox queue lock ${directory}`);
|