@united-workforce/cli 0.3.0 → 0.5.0
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/README.md +45 -11
- package/dist/.build-fingerprint +1 -0
- package/dist/__tests__/adapter-json-roundtrip.test.js +17 -7
- package/dist/__tests__/adapter-json-roundtrip.test.js.map +1 -1
- package/dist/__tests__/agent-resolution-llm-free.test.d.ts +2 -0
- package/dist/__tests__/agent-resolution-llm-free.test.d.ts.map +1 -0
- package/dist/__tests__/agent-resolution-llm-free.test.js +30 -0
- package/dist/__tests__/agent-resolution-llm-free.test.js.map +1 -0
- package/dist/__tests__/build-step-entry.test.d.ts +2 -0
- package/dist/__tests__/build-step-entry.test.d.ts.map +1 -0
- package/dist/__tests__/build-step-entry.test.js +173 -0
- package/dist/__tests__/build-step-entry.test.js.map +1 -0
- package/dist/__tests__/clear-thread-failed-attempts.test.d.ts +2 -0
- package/dist/__tests__/clear-thread-failed-attempts.test.d.ts.map +1 -0
- package/dist/__tests__/clear-thread-failed-attempts.test.js +93 -0
- package/dist/__tests__/clear-thread-failed-attempts.test.js.map +1 -0
- package/dist/__tests__/concurrency.test.d.ts +2 -0
- package/dist/__tests__/concurrency.test.d.ts.map +1 -0
- package/dist/__tests__/concurrency.test.js +196 -0
- package/dist/__tests__/concurrency.test.js.map +1 -0
- package/dist/__tests__/config.test.js +26 -302
- package/dist/__tests__/config.test.js.map +1 -1
- package/dist/__tests__/current-role.test.js +7 -6
- package/dist/__tests__/current-role.test.js.map +1 -1
- package/dist/__tests__/e2e-mock-agent.test.js +43 -30
- package/dist/__tests__/e2e-mock-agent.test.js.map +1 -1
- package/dist/__tests__/format-text-default.test.d.ts +2 -0
- package/dist/__tests__/format-text-default.test.d.ts.map +1 -0
- package/dist/__tests__/format-text-default.test.js +43 -0
- package/dist/__tests__/format-text-default.test.js.map +1 -0
- package/dist/__tests__/format-text-registry.test.d.ts +2 -0
- package/dist/__tests__/format-text-registry.test.d.ts.map +1 -0
- package/dist/__tests__/format-text-registry.test.js +158 -0
- package/dist/__tests__/format-text-registry.test.js.map +1 -0
- package/dist/__tests__/issue-180-workflow-ref-removed.test.d.ts +2 -0
- package/dist/__tests__/issue-180-workflow-ref-removed.test.d.ts.map +1 -0
- package/dist/__tests__/issue-180-workflow-ref-removed.test.js +40 -0
- package/dist/__tests__/issue-180-workflow-ref-removed.test.js.map +1 -0
- package/dist/__tests__/log-text-renderer.test.d.ts +2 -0
- package/dist/__tests__/log-text-renderer.test.d.ts.map +1 -0
- package/dist/__tests__/log-text-renderer.test.js +265 -0
- package/dist/__tests__/log-text-renderer.test.js.map +1 -0
- package/dist/__tests__/moderator-evaluate.test.js +9 -50
- package/dist/__tests__/moderator-evaluate.test.js.map +1 -1
- package/dist/__tests__/output-mapper-thread-list-startedat.test.d.ts +2 -0
- package/dist/__tests__/output-mapper-thread-list-startedat.test.d.ts.map +1 -0
- package/dist/__tests__/output-mapper-thread-list-startedat.test.js +102 -0
- package/dist/__tests__/output-mapper-thread-list-startedat.test.js.map +1 -0
- package/dist/__tests__/output-mapper-workflow-add.test.d.ts +2 -0
- package/dist/__tests__/output-mapper-workflow-add.test.d.ts.map +1 -0
- package/dist/__tests__/output-mapper-workflow-add.test.js +22 -0
- package/dist/__tests__/output-mapper-workflow-add.test.js.map +1 -0
- package/dist/__tests__/pid-recycling.test.d.ts +2 -0
- package/dist/__tests__/pid-recycling.test.d.ts.map +1 -0
- package/dist/__tests__/pid-recycling.test.js +273 -0
- package/dist/__tests__/pid-recycling.test.js.map +1 -0
- package/dist/__tests__/prompt.test.js +365 -2
- package/dist/__tests__/prompt.test.js.map +1 -1
- package/dist/__tests__/resolve-head-hash.test.js +12 -4
- package/dist/__tests__/resolve-head-hash.test.js.map +1 -1
- package/dist/__tests__/setup-agent-discovery.test.js +21 -30
- package/dist/__tests__/setup-agent-discovery.test.js.map +1 -1
- package/dist/__tests__/setup-complexity.test.js +2 -168
- package/dist/__tests__/setup-complexity.test.js.map +1 -1
- package/dist/__tests__/setup-no-llm.test.d.ts +2 -0
- package/dist/__tests__/setup-no-llm.test.d.ts.map +1 -0
- package/dist/__tests__/setup-no-llm.test.js +52 -0
- package/dist/__tests__/setup-no-llm.test.js.map +1 -0
- package/dist/__tests__/solve-issue-tea-worktree.test.js +27 -28
- package/dist/__tests__/solve-issue-tea-worktree.test.js.map +1 -1
- package/dist/__tests__/step-ask.test.d.ts +2 -0
- package/dist/__tests__/step-ask.test.d.ts.map +1 -0
- package/dist/__tests__/step-ask.test.js +507 -0
- package/dist/__tests__/step-ask.test.js.map +1 -0
- package/dist/__tests__/step-show-json.test.js +1 -0
- package/dist/__tests__/step-show-json.test.js.map +1 -1
- package/dist/__tests__/step-timing.test.js +2 -0
- package/dist/__tests__/step-timing.test.js.map +1 -1
- package/dist/__tests__/store-global-cas.test.js +2 -2
- package/dist/__tests__/store-global-cas.test.js.map +1 -1
- package/dist/__tests__/store-unified-threads.test.js +28 -26
- package/dist/__tests__/store-unified-threads.test.js.map +1 -1
- package/dist/__tests__/thread-cancel-status.test.js +25 -19
- package/dist/__tests__/thread-cancel-status.test.js.map +1 -1
- package/dist/__tests__/thread-cancel-text-renderer.test.d.ts +2 -0
- package/dist/__tests__/thread-cancel-text-renderer.test.d.ts.map +1 -0
- package/dist/__tests__/thread-cancel-text-renderer.test.js +110 -0
- package/dist/__tests__/thread-cancel-text-renderer.test.js.map +1 -0
- package/dist/__tests__/thread-list-filters.test.js +354 -17
- package/dist/__tests__/thread-list-filters.test.js.map +1 -1
- package/dist/__tests__/thread-list-template-ms-date.test.d.ts +2 -0
- package/dist/__tests__/thread-list-template-ms-date.test.d.ts.map +1 -0
- package/dist/__tests__/thread-list-template-ms-date.test.js +102 -0
- package/dist/__tests__/thread-list-template-ms-date.test.js.map +1 -0
- package/dist/__tests__/thread-list-workflow-corrupt.test.d.ts +2 -0
- package/dist/__tests__/thread-list-workflow-corrupt.test.d.ts.map +1 -0
- package/dist/__tests__/thread-list-workflow-corrupt.test.js +157 -0
- package/dist/__tests__/thread-list-workflow-corrupt.test.js.map +1 -0
- package/dist/__tests__/thread-poke.test.d.ts +2 -0
- package/dist/__tests__/thread-poke.test.d.ts.map +1 -0
- package/dist/__tests__/thread-poke.test.js +422 -0
- package/dist/__tests__/thread-poke.test.js.map +1 -0
- package/dist/__tests__/thread-read-xml-tags.test.js +10 -9
- package/dist/__tests__/thread-read-xml-tags.test.js.map +1 -1
- package/dist/__tests__/thread-resume.test.js +21 -15
- package/dist/__tests__/thread-resume.test.js.map +1 -1
- package/dist/__tests__/thread-show-status.test.js +17 -28
- package/dist/__tests__/thread-show-status.test.js.map +1 -1
- package/dist/__tests__/thread-start-cwd-cli.test.js +15 -3
- package/dist/__tests__/thread-start-cwd-cli.test.js.map +1 -1
- package/dist/__tests__/thread-stop-text-renderer.test.d.ts +2 -0
- package/dist/__tests__/thread-stop-text-renderer.test.d.ts.map +1 -0
- package/dist/__tests__/thread-stop-text-renderer.test.js +148 -0
- package/dist/__tests__/thread-stop-text-renderer.test.js.map +1 -0
- package/dist/__tests__/thread-suspend-step.test.js +13 -16
- package/dist/__tests__/thread-suspend-step.test.js.map +1 -1
- package/dist/__tests__/thread-suspended-display.test.js +10 -22
- package/dist/__tests__/thread-suspended-display.test.js.map +1 -1
- package/dist/__tests__/thread-test-helpers.d.ts +7 -0
- package/dist/__tests__/thread-test-helpers.d.ts.map +1 -1
- package/dist/__tests__/thread-test-helpers.js +13 -0
- package/dist/__tests__/thread-test-helpers.js.map +1 -1
- package/dist/__tests__/thread.test.js +15 -13
- package/dist/__tests__/thread.test.js.map +1 -1
- package/dist/__tests__/validate-semantic.test.js +105 -23
- package/dist/__tests__/validate-semantic.test.js.map +1 -1
- package/dist/__tests__/workflow-list-recursive.test.d.ts +2 -0
- package/dist/__tests__/workflow-list-recursive.test.d.ts.map +1 -0
- package/dist/__tests__/workflow-list-recursive.test.js +286 -0
- package/dist/__tests__/workflow-list-recursive.test.js.map +1 -0
- package/dist/__tests__/workflow-resolution.test.js +46 -28
- package/dist/__tests__/workflow-resolution.test.js.map +1 -1
- package/dist/__tests__/workflow-show-resolution.test.d.ts +2 -0
- package/dist/__tests__/workflow-show-resolution.test.d.ts.map +1 -0
- package/dist/__tests__/workflow-show-resolution.test.js +213 -0
- package/dist/__tests__/workflow-show-resolution.test.js.map +1 -0
- package/dist/__tests__/workflow-validate.test.d.ts +2 -0
- package/dist/__tests__/workflow-validate.test.d.ts.map +1 -0
- package/dist/__tests__/workflow-validate.test.js +707 -0
- package/dist/__tests__/workflow-validate.test.js.map +1 -0
- package/dist/__tests__/write-envelope.test.d.ts +2 -0
- package/dist/__tests__/write-envelope.test.d.ts.map +1 -0
- package/dist/__tests__/write-envelope.test.js +201 -0
- package/dist/__tests__/write-envelope.test.js.map +1 -0
- package/dist/background/background.d.ts +22 -1
- package/dist/background/background.d.ts.map +1 -1
- package/dist/background/background.js +83 -6
- package/dist/background/background.js.map +1 -1
- package/dist/background/index.d.ts +1 -1
- package/dist/background/index.d.ts.map +1 -1
- package/dist/background/index.js +1 -1
- package/dist/background/index.js.map +1 -1
- package/dist/background/types.d.ts +1 -0
- package/dist/background/types.d.ts.map +1 -1
- package/dist/cli.js +120 -62
- package/dist/cli.js.map +1 -1
- package/dist/commands/config.d.ts +3 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +17 -31
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/prompt.d.ts.map +1 -1
- package/dist/commands/prompt.js +57 -31
- package/dist/commands/prompt.js.map +1 -1
- package/dist/commands/setup.d.ts +12 -39
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +72 -303
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/step.d.ts +44 -1
- package/dist/commands/step.d.ts.map +1 -1
- package/dist/commands/step.js +255 -11
- package/dist/commands/step.js.map +1 -1
- package/dist/commands/thread.d.ts +16 -3
- package/dist/commands/thread.d.ts.map +1 -1
- package/dist/commands/thread.js +423 -142
- package/dist/commands/thread.js.map +1 -1
- package/dist/commands/workflow.d.ts +9 -1
- package/dist/commands/workflow.d.ts.map +1 -1
- package/dist/commands/workflow.js +126 -6
- package/dist/commands/workflow.js.map +1 -1
- package/dist/concurrency/concurrency.d.ts +34 -0
- package/dist/concurrency/concurrency.d.ts.map +1 -0
- package/dist/concurrency/concurrency.js +216 -0
- package/dist/concurrency/concurrency.js.map +1 -0
- package/dist/concurrency/index.d.ts +3 -0
- package/dist/concurrency/index.d.ts.map +1 -0
- package/dist/concurrency/index.js +2 -0
- package/dist/concurrency/index.js.map +1 -0
- package/dist/concurrency/types.d.ts +19 -0
- package/dist/concurrency/types.d.ts.map +1 -0
- package/dist/concurrency/types.js +2 -0
- package/dist/concurrency/types.js.map +1 -0
- package/dist/format.d.ts +69 -2
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +198 -1
- package/dist/format.js.map +1 -1
- package/dist/moderator/__tests__/evaluate.test.js +31 -17
- package/dist/moderator/__tests__/evaluate.test.js.map +1 -1
- package/dist/moderator/evaluate.d.ts.map +1 -1
- package/dist/moderator/evaluate.js +4 -16
- package/dist/moderator/evaluate.js.map +1 -1
- package/dist/moderator/index.d.ts +1 -2
- package/dist/moderator/index.d.ts.map +1 -1
- package/dist/moderator/index.js +0 -1
- package/dist/moderator/index.js.map +1 -1
- package/dist/moderator/types.d.ts +6 -10
- package/dist/moderator/types.d.ts.map +1 -1
- package/dist/moderator/types.js +1 -3
- package/dist/moderator/types.js.map +1 -1
- package/dist/output-mappers.d.ts +122 -0
- package/dist/output-mappers.d.ts.map +1 -0
- package/dist/output-mappers.js +134 -0
- package/dist/output-mappers.js.map +1 -0
- package/dist/schemas.d.ts +6 -1
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +34 -5
- package/dist/schemas.js.map +1 -1
- package/dist/store.d.ts +28 -9
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +75 -16
- package/dist/store.js.map +1 -1
- package/dist/text-renderers.d.ts +30 -0
- package/dist/text-renderers.d.ts.map +1 -0
- package/dist/text-renderers.js +251 -0
- package/dist/text-renderers.js.map +1 -0
- package/dist/validate-semantic.d.ts.map +1 -1
- package/dist/validate-semantic.js +95 -61
- package/dist/validate-semantic.js.map +1 -1
- package/dist/validate.d.ts +6 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +24 -0
- package/dist/validate.js.map +1 -1
- package/examples/brainstorm.yaml +130 -0
- package/examples/debate.yaml +169 -0
- package/examples/socratic-questioning.yaml +112 -0
- package/package.json +9 -10
- package/src/__tests__/adapter-json-roundtrip.test.ts +16 -7
- package/src/__tests__/agent-resolution-llm-free.test.ts +39 -0
- package/src/__tests__/build-step-entry.test.ts +203 -0
- package/src/__tests__/clear-thread-failed-attempts.test.ts +122 -0
- package/src/__tests__/concurrency.test.ts +266 -0
- package/src/__tests__/config.test.ts +33 -321
- package/src/__tests__/current-role.test.ts +7 -6
- package/src/__tests__/e2e-mock-agent.test.ts +65 -30
- package/src/__tests__/fixtures/e2e-count.workflow.yaml +1 -0
- package/src/__tests__/fixtures/e2e-linear.workflow.yaml +1 -0
- package/src/__tests__/fixtures/{e2e-mustache.workflow.yaml → e2e-liquid.workflow.yaml} +3 -2
- package/src/__tests__/fixtures/e2e-loop.workflow.yaml +1 -0
- package/src/__tests__/fixtures/e2e-suspend.mock.yaml +2 -2
- package/src/__tests__/fixtures/e2e-suspend.workflow.yaml +6 -10
- package/src/__tests__/format-text-default.test.ts +49 -0
- package/src/__tests__/format-text-registry.test.ts +173 -0
- package/src/__tests__/issue-180-workflow-ref-removed.test.ts +43 -0
- package/src/__tests__/log-text-renderer.test.ts +294 -0
- package/src/__tests__/moderator-evaluate.test.ts +9 -52
- package/src/__tests__/output-mapper-thread-list-startedat.test.ts +124 -0
- package/src/__tests__/output-mapper-workflow-add.test.ts +24 -0
- package/src/__tests__/pid-recycling.test.ts +329 -0
- package/src/__tests__/prompt.test.ts +443 -2
- package/src/__tests__/resolve-head-hash.test.ts +11 -4
- package/src/__tests__/setup-agent-discovery.test.ts +26 -51
- package/src/__tests__/setup-complexity.test.ts +1 -203
- package/src/__tests__/setup-no-llm.test.ts +68 -0
- package/src/__tests__/solve-issue-tea-worktree.test.ts +27 -31
- package/src/__tests__/step-ask.test.ts +677 -0
- package/src/__tests__/step-show-json.test.ts +1 -0
- package/src/__tests__/step-timing.test.ts +2 -0
- package/src/__tests__/store-global-cas.test.ts +2 -2
- package/src/__tests__/store-unified-threads.test.ts +30 -27
- package/src/__tests__/thread-cancel-status.test.ts +27 -20
- package/src/__tests__/thread-cancel-text-renderer.test.ts +125 -0
- package/src/__tests__/thread-list-filters.test.ts +443 -17
- package/src/__tests__/thread-list-template-ms-date.test.ts +110 -0
- package/src/__tests__/thread-list-workflow-corrupt.test.ts +198 -0
- package/src/__tests__/thread-poke.test.ts +554 -0
- package/src/__tests__/thread-read-xml-tags.test.ts +9 -11
- package/src/__tests__/thread-resume.test.ts +20 -15
- package/src/__tests__/thread-show-status.test.ts +17 -29
- package/src/__tests__/thread-start-cwd-cli.test.ts +15 -3
- package/src/__tests__/thread-stop-text-renderer.test.ts +168 -0
- package/src/__tests__/thread-suspend-step.test.ts +13 -16
- package/src/__tests__/thread-suspended-display.test.ts +10 -22
- package/src/__tests__/thread-test-helpers.ts +15 -1
- package/src/__tests__/thread.test.ts +14 -14
- package/src/__tests__/validate-semantic.test.ts +118 -33
- package/src/__tests__/workflow-list-recursive.test.ts +370 -0
- package/src/__tests__/workflow-resolution.test.ts +48 -29
- package/src/__tests__/workflow-show-resolution.test.ts +286 -0
- package/src/__tests__/workflow-validate.test.ts +828 -0
- package/src/__tests__/write-envelope.test.ts +257 -0
- package/src/background/background.ts +88 -6
- package/src/background/index.ts +2 -0
- package/src/background/types.ts +1 -0
- package/src/cli.ts +184 -77
- package/src/commands/config.ts +16 -33
- package/src/commands/prompt.ts +57 -31
- package/src/commands/setup.ts +80 -358
- package/src/commands/step.ts +339 -12
- package/src/commands/thread.ts +511 -171
- package/src/commands/workflow.ts +155 -4
- package/src/concurrency/concurrency.ts +245 -0
- package/src/concurrency/index.ts +10 -0
- package/src/concurrency/types.ts +19 -0
- package/src/format.ts +282 -2
- package/src/moderator/__tests__/evaluate.test.ts +34 -17
- package/src/moderator/evaluate.ts +5 -17
- package/src/moderator/index.ts +1 -6
- package/src/moderator/types.ts +6 -14
- package/src/output-mappers.ts +254 -0
- package/src/schemas.ts +51 -5
- package/src/store.ts +86 -20
- package/src/text-renderers.ts +355 -0
- package/src/validate-semantic.ts +125 -73
- package/src/validate.ts +27 -0
- package/dist/__tests__/setup-validate.test.d.ts +0 -2
- package/dist/__tests__/setup-validate.test.d.ts.map +0 -1
- package/dist/__tests__/setup-validate.test.js +0 -108
- package/dist/__tests__/setup-validate.test.js.map +0 -1
- package/src/__tests__/setup-validate.test.ts +0 -148
- /package/src/__tests__/fixtures/{e2e-mustache.mock.yaml → e2e-liquid.mock.yaml} +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import type { CasRef, ThreadId } from "@united-workforce/protocol";
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
6
|
+
import {
|
|
7
|
+
clearThreadFailedAttempts,
|
|
8
|
+
completeThread,
|
|
9
|
+
createUwfStore,
|
|
10
|
+
setThread,
|
|
11
|
+
type UwfStore,
|
|
12
|
+
} from "../store.js";
|
|
13
|
+
|
|
14
|
+
let tmpDir: string;
|
|
15
|
+
let originalEnv: string | undefined;
|
|
16
|
+
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
tmpDir = await mkdtemp(join(tmpdir(), "cli-clear-failed-"));
|
|
19
|
+
originalEnv = process.env.OCAS_HOME;
|
|
20
|
+
process.env.OCAS_HOME = join(tmpDir, "cas");
|
|
21
|
+
await mkdir(process.env.OCAS_HOME, { recursive: true });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(async () => {
|
|
25
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
26
|
+
if (originalEnv === undefined) {
|
|
27
|
+
delete process.env.OCAS_HOME;
|
|
28
|
+
} else {
|
|
29
|
+
process.env.OCAS_HOME = originalEnv;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function failedVarName(threadId: ThreadId, role: string): string {
|
|
34
|
+
return `@uwf/thread-failed/${threadId}/${role}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function seedFailedAttempt(uwf: UwfStore, threadId: ThreadId, role: string): Promise<void> {
|
|
38
|
+
const listHash = (await uwf.store.cas.put(
|
|
39
|
+
uwf.schemas.text,
|
|
40
|
+
JSON.stringify(["STEP00000000A"]),
|
|
41
|
+
)) as CasRef;
|
|
42
|
+
uwf.varStore.set(failedVarName(threadId, role), listHash);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function seedHead(uwf: UwfStore, label: string): Promise<CasRef> {
|
|
46
|
+
return (await uwf.store.cas.put(uwf.schemas.text, label)) as CasRef;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function countFailedVars(uwf: UwfStore, threadId: ThreadId): number {
|
|
50
|
+
return uwf.varStore.list({ namePrefix: `@uwf/thread-failed/${threadId}/` }).length;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("clearThreadFailedAttempts", () => {
|
|
54
|
+
test("removes all failed-attempts vars for the given thread only", async () => {
|
|
55
|
+
const uwf = await createUwfStore(tmpDir);
|
|
56
|
+
const threadId = "01JTESTCLEAR0000000000001A" as ThreadId;
|
|
57
|
+
const otherThread = "01JTESTCLEAR0000000000002B" as ThreadId;
|
|
58
|
+
|
|
59
|
+
await seedFailedAttempt(uwf, threadId, "planner");
|
|
60
|
+
await seedFailedAttempt(uwf, threadId, "reviewer");
|
|
61
|
+
await seedFailedAttempt(uwf, otherThread, "planner");
|
|
62
|
+
|
|
63
|
+
expect(countFailedVars(uwf, threadId)).toBe(2);
|
|
64
|
+
expect(countFailedVars(uwf, otherThread)).toBe(1);
|
|
65
|
+
|
|
66
|
+
clearThreadFailedAttempts(uwf.varStore, threadId);
|
|
67
|
+
|
|
68
|
+
expect(countFailedVars(uwf, threadId)).toBe(0);
|
|
69
|
+
// The other thread's lineage is untouched.
|
|
70
|
+
expect(countFailedVars(uwf, otherThread)).toBe(1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("is a no-op when no failed-attempts vars exist", async () => {
|
|
74
|
+
const uwf = await createUwfStore(tmpDir);
|
|
75
|
+
const threadId = "01JTESTCLEAR0000000000003C" as ThreadId;
|
|
76
|
+
expect(() => clearThreadFailedAttempts(uwf.varStore, threadId)).not.toThrow();
|
|
77
|
+
expect(countFailedVars(uwf, threadId)).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("completeThread clears failed-attempts lineage", () => {
|
|
82
|
+
test("completion clears the thread's failed-attempts vars", async () => {
|
|
83
|
+
const uwf = await createUwfStore(tmpDir);
|
|
84
|
+
const threadId = "01JTESTCLEAR0000000000004D" as ThreadId;
|
|
85
|
+
const head = await seedHead(uwf, "head");
|
|
86
|
+
|
|
87
|
+
setThread(uwf.varStore, threadId, {
|
|
88
|
+
head,
|
|
89
|
+
status: "idle",
|
|
90
|
+
suspendedRole: null,
|
|
91
|
+
suspendMessage: null,
|
|
92
|
+
completedAt: null,
|
|
93
|
+
});
|
|
94
|
+
await seedFailedAttempt(uwf, threadId, "planner");
|
|
95
|
+
expect(countFailedVars(uwf, threadId)).toBe(1);
|
|
96
|
+
|
|
97
|
+
completeThread(uwf.varStore, threadId, "end");
|
|
98
|
+
|
|
99
|
+
expect(countFailedVars(uwf, threadId)).toBe(0);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("cancellation clears the thread's failed-attempts vars", async () => {
|
|
103
|
+
const uwf = await createUwfStore(tmpDir);
|
|
104
|
+
const threadId = "01JTESTCLEAR0000000000005E" as ThreadId;
|
|
105
|
+
const head = await seedHead(uwf, "head");
|
|
106
|
+
|
|
107
|
+
setThread(uwf.varStore, threadId, {
|
|
108
|
+
head,
|
|
109
|
+
status: "running",
|
|
110
|
+
suspendedRole: null,
|
|
111
|
+
suspendMessage: null,
|
|
112
|
+
completedAt: null,
|
|
113
|
+
});
|
|
114
|
+
await seedFailedAttempt(uwf, threadId, "planner");
|
|
115
|
+
await seedFailedAttempt(uwf, threadId, "reviewer");
|
|
116
|
+
expect(countFailedVars(uwf, threadId)).toBe(2);
|
|
117
|
+
|
|
118
|
+
completeThread(uwf.varStore, threadId, "cancelled");
|
|
119
|
+
|
|
120
|
+
expect(countFailedVars(uwf, threadId)).toBe(0);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, readdir, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
acquireSlot,
|
|
8
|
+
cleanStaleSlots,
|
|
9
|
+
countActiveSlots,
|
|
10
|
+
DEFAULT_MAX_RUNNING,
|
|
11
|
+
getSlotsDir,
|
|
12
|
+
installSlotCleanup,
|
|
13
|
+
} from "../concurrency/index.js";
|
|
14
|
+
|
|
15
|
+
// ── test setup ────────────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
let tmpDir: string;
|
|
18
|
+
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
tmpDir = await mkdtemp(join(tmpdir(), "concurrency-test-"));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterEach(async () => {
|
|
24
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// ── Spec: concurrency-acquire-slot-under-limit ──────────────────────────────
|
|
28
|
+
|
|
29
|
+
describe("acquireSlot succeeds immediately when below maxRunning", () => {
|
|
30
|
+
test("creates slot file and returns SlotHandle when under limit", async () => {
|
|
31
|
+
const handle = await acquireSlot(tmpDir, 2);
|
|
32
|
+
|
|
33
|
+
// Slot file exists
|
|
34
|
+
const slotsDir = getSlotsDir(tmpDir);
|
|
35
|
+
const files = await readdir(slotsDir);
|
|
36
|
+
expect(files).toContain(`${process.pid}.slot`);
|
|
37
|
+
|
|
38
|
+
// Returns a SlotHandle with release()
|
|
39
|
+
expect(handle).toHaveProperty("release");
|
|
40
|
+
expect(typeof handle.release).toBe("function");
|
|
41
|
+
|
|
42
|
+
// countActiveSlots returns 1
|
|
43
|
+
const count = await countActiveSlots(tmpDir);
|
|
44
|
+
expect(count).toBe(1);
|
|
45
|
+
|
|
46
|
+
// Cleanup
|
|
47
|
+
await handle.release();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("returns immediately (no blocking) when slots available", async () => {
|
|
51
|
+
const start = Date.now();
|
|
52
|
+
const handle = await acquireSlot(tmpDir, 2);
|
|
53
|
+
const elapsed = Date.now() - start;
|
|
54
|
+
|
|
55
|
+
// Should complete in well under 1 second (no polling delay)
|
|
56
|
+
expect(elapsed).toBeLessThan(500);
|
|
57
|
+
|
|
58
|
+
await handle.release();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// ── Spec: concurrency-acquire-slot-blocks-at-limit ──────────────────────────
|
|
63
|
+
|
|
64
|
+
describe("acquireSlot blocks when at capacity", () => {
|
|
65
|
+
test("calls onWaiting when all slots are occupied", async () => {
|
|
66
|
+
// Create a slot file for a "live" process — use parent PID (same user, signalable)
|
|
67
|
+
const slotsDir = getSlotsDir(tmpDir);
|
|
68
|
+
await mkdir(slotsDir, { recursive: true });
|
|
69
|
+
const blockerPid = process.ppid;
|
|
70
|
+
await writeFile(join(slotsDir, `${blockerPid}.slot`), "", "utf8");
|
|
71
|
+
|
|
72
|
+
const onWaiting = vi.fn();
|
|
73
|
+
const onAcquired = vi.fn();
|
|
74
|
+
|
|
75
|
+
// maxRunning=1, one slot occupied → should block
|
|
76
|
+
// Release the blocking slot after a brief delay
|
|
77
|
+
setTimeout(async () => {
|
|
78
|
+
await rm(join(slotsDir, `${blockerPid}.slot`), { force: true });
|
|
79
|
+
}, 200);
|
|
80
|
+
|
|
81
|
+
const handle = await acquireSlot(tmpDir, 1, {
|
|
82
|
+
onWaiting,
|
|
83
|
+
onAcquired,
|
|
84
|
+
pollIntervalMs: 100,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(onWaiting).toHaveBeenCalled();
|
|
88
|
+
expect(onAcquired).toHaveBeenCalled();
|
|
89
|
+
|
|
90
|
+
await handle.release();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("polls with interval and proceeds after slot is freed", async () => {
|
|
94
|
+
const slotsDir = getSlotsDir(tmpDir);
|
|
95
|
+
await mkdir(slotsDir, { recursive: true });
|
|
96
|
+
const blockerPid = process.ppid;
|
|
97
|
+
await writeFile(join(slotsDir, `${blockerPid}.slot`), "", "utf8");
|
|
98
|
+
|
|
99
|
+
// Remove after 250ms
|
|
100
|
+
setTimeout(async () => {
|
|
101
|
+
await rm(join(slotsDir, `${blockerPid}.slot`), { force: true });
|
|
102
|
+
}, 250);
|
|
103
|
+
|
|
104
|
+
const start = Date.now();
|
|
105
|
+
const handle = await acquireSlot(tmpDir, 1, { pollIntervalMs: 100 });
|
|
106
|
+
const elapsed = Date.now() - start;
|
|
107
|
+
|
|
108
|
+
// Should have waited at least ~200ms (polling)
|
|
109
|
+
expect(elapsed).toBeGreaterThanOrEqual(150);
|
|
110
|
+
|
|
111
|
+
await handle.release();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// ── Spec: concurrency-stale-slot-cleanup ────────────────────────────────────
|
|
116
|
+
|
|
117
|
+
describe("cleanStaleSlots removes slot files for dead PIDs", () => {
|
|
118
|
+
test("removes slot file for dead PID, preserves live PID", async () => {
|
|
119
|
+
const slotsDir = getSlotsDir(tmpDir);
|
|
120
|
+
await mkdir(slotsDir, { recursive: true });
|
|
121
|
+
|
|
122
|
+
// Dead PID (99999999 should not exist)
|
|
123
|
+
await writeFile(join(slotsDir, "99999999.slot"), "", "utf8");
|
|
124
|
+
// Live PID (current process)
|
|
125
|
+
await writeFile(join(slotsDir, `${process.pid}.slot`), "", "utf8");
|
|
126
|
+
|
|
127
|
+
const cleaned = await cleanStaleSlots(tmpDir);
|
|
128
|
+
expect(cleaned).toBe(1);
|
|
129
|
+
|
|
130
|
+
const files = await readdir(slotsDir);
|
|
131
|
+
expect(files).not.toContain("99999999.slot");
|
|
132
|
+
expect(files).toContain(`${process.pid}.slot`);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("countActiveSlots reflects correct count after cleanup", async () => {
|
|
136
|
+
const slotsDir = getSlotsDir(tmpDir);
|
|
137
|
+
await mkdir(slotsDir, { recursive: true });
|
|
138
|
+
|
|
139
|
+
// 1 dead + 1 live
|
|
140
|
+
await writeFile(join(slotsDir, "99999999.slot"), "", "utf8");
|
|
141
|
+
await writeFile(join(slotsDir, `${process.pid}.slot`), "", "utf8");
|
|
142
|
+
|
|
143
|
+
// Before cleanup: 2 files
|
|
144
|
+
const beforeFiles = await readdir(slotsDir);
|
|
145
|
+
expect(beforeFiles.filter((f) => f.endsWith(".slot")).length).toBe(2);
|
|
146
|
+
|
|
147
|
+
await cleanStaleSlots(tmpDir);
|
|
148
|
+
|
|
149
|
+
// After cleanup
|
|
150
|
+
const count = await countActiveSlots(tmpDir);
|
|
151
|
+
expect(count).toBe(1);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// ── Spec: concurrency-race-protection-rollback ──────────────────────────────
|
|
156
|
+
|
|
157
|
+
describe("acquireSlot rolls back on race condition", () => {
|
|
158
|
+
test("rolls back slot file if post-write count exceeds maxRunning", async () => {
|
|
159
|
+
const slotsDir = getSlotsDir(tmpDir);
|
|
160
|
+
await mkdir(slotsDir, { recursive: true });
|
|
161
|
+
|
|
162
|
+
// Simulate: maxRunning=2, and we already have 1 slot from another live process
|
|
163
|
+
const blockerPid = process.ppid;
|
|
164
|
+
await writeFile(join(slotsDir, `${blockerPid}.slot`), "", "utf8");
|
|
165
|
+
|
|
166
|
+
// Our process writes its slot, making count=2 which equals maxRunning=2
|
|
167
|
+
// This should succeed (at limit, not over)
|
|
168
|
+
const handle = await acquireSlot(tmpDir, 2);
|
|
169
|
+
const count = await countActiveSlots(tmpDir);
|
|
170
|
+
expect(count).toBe(2);
|
|
171
|
+
|
|
172
|
+
await handle.release();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("when another slot appears during write, rollback occurs", async () => {
|
|
176
|
+
// This tests the double-check logic. We'll simulate by pre-filling to capacity.
|
|
177
|
+
const slotsDir = getSlotsDir(tmpDir);
|
|
178
|
+
await mkdir(slotsDir, { recursive: true });
|
|
179
|
+
|
|
180
|
+
// maxRunning=1, one slot already occupied by parent PID
|
|
181
|
+
const blockerPid = process.ppid;
|
|
182
|
+
await writeFile(join(slotsDir, `${blockerPid}.slot`), "", "utf8");
|
|
183
|
+
|
|
184
|
+
// Release after delay so acquireSlot can proceed
|
|
185
|
+
setTimeout(async () => {
|
|
186
|
+
await rm(join(slotsDir, `${blockerPid}.slot`), { force: true });
|
|
187
|
+
}, 200);
|
|
188
|
+
|
|
189
|
+
const handle = await acquireSlot(tmpDir, 1, { pollIntervalMs: 100 });
|
|
190
|
+
|
|
191
|
+
// After acquiring, only our slot should exist
|
|
192
|
+
const files = await readdir(slotsDir);
|
|
193
|
+
const slotFiles = files.filter((f) => f.endsWith(".slot"));
|
|
194
|
+
expect(slotFiles).toContain(`${process.pid}.slot`);
|
|
195
|
+
|
|
196
|
+
await handle.release();
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// ── Spec: concurrency-exec-signal-cleanup ────────────────────────────────────
|
|
201
|
+
|
|
202
|
+
describe("installSlotCleanup removes slot on signal", () => {
|
|
203
|
+
test("release function removes slot file", async () => {
|
|
204
|
+
const handle = await acquireSlot(tmpDir, 2);
|
|
205
|
+
|
|
206
|
+
// Verify slot exists
|
|
207
|
+
const slotsDir = getSlotsDir(tmpDir);
|
|
208
|
+
const filesBefore = await readdir(slotsDir);
|
|
209
|
+
expect(filesBefore).toContain(`${process.pid}.slot`);
|
|
210
|
+
|
|
211
|
+
// installSlotCleanup returns a cleanup function
|
|
212
|
+
const cleanup = installSlotCleanup(handle);
|
|
213
|
+
|
|
214
|
+
// Call release directly (simulating what signal handler would do)
|
|
215
|
+
await handle.release();
|
|
216
|
+
|
|
217
|
+
const filesAfter = await readdir(slotsDir);
|
|
218
|
+
expect(filesAfter).not.toContain(`${process.pid}.slot`);
|
|
219
|
+
|
|
220
|
+
// Uninstall the cleanup handler
|
|
221
|
+
cleanup();
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// ── Spec: concurrency-default-max-running ────────────────────────────────────
|
|
226
|
+
|
|
227
|
+
describe("DEFAULT_MAX_RUNNING is 2", () => {
|
|
228
|
+
test("constant equals 2", () => {
|
|
229
|
+
expect(DEFAULT_MAX_RUNNING).toBe(2);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// ── Spec: concurrency-exec-uses-slot (unit level) ───────────────────────────
|
|
234
|
+
|
|
235
|
+
describe("slot lifecycle during exec", () => {
|
|
236
|
+
test("acquireSlot + release = 0 active slots", async () => {
|
|
237
|
+
const handle = await acquireSlot(tmpDir, 2);
|
|
238
|
+
expect(await countActiveSlots(tmpDir)).toBe(1);
|
|
239
|
+
|
|
240
|
+
await handle.release();
|
|
241
|
+
expect(await countActiveSlots(tmpDir)).toBe(0);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("release is idempotent", async () => {
|
|
245
|
+
const handle = await acquireSlot(tmpDir, 2);
|
|
246
|
+
await handle.release();
|
|
247
|
+
// Calling release again should not throw
|
|
248
|
+
await handle.release();
|
|
249
|
+
expect(await countActiveSlots(tmpDir)).toBe(0);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// ── Spec: concurrency-config-set-max-running ─────────────────────────────────
|
|
254
|
+
|
|
255
|
+
describe("config set concurrency.maxRunning", () => {
|
|
256
|
+
test("concurrency config key is validated correctly", async () => {
|
|
257
|
+
// Import config module to test the key validation
|
|
258
|
+
const { parseDotPath, setNestedValue } = await import("../commands/config.js");
|
|
259
|
+
|
|
260
|
+
const config: Record<string, unknown> = {};
|
|
261
|
+
const path = parseDotPath("concurrency.maxRunning");
|
|
262
|
+
setNestedValue(config, path, 3);
|
|
263
|
+
|
|
264
|
+
expect(config).toEqual({ concurrency: { maxRunning: 3 } });
|
|
265
|
+
});
|
|
266
|
+
});
|