@nanobpm/nano-workforce 0.116.0 → 0.117.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.
@@ -0,0 +1,72 @@
1
+ name: Renovate
2
+
3
+ # Self-hosted Renovate (issue #406). renovate.json declares the policy — auto-merge
4
+ # non-major @nanobpm/* updates once CI is green, majors need a human — but nothing was
5
+ # ever running it, so the config sat dormant and nwf stayed pinned to old @nanobpm/urban.
6
+ # This workflow IS the runner: on a schedule (and on demand) it opens update PRs and, on a
7
+ # later pass once the PR's CI is green, merges the automerge ones itself. We self-host via
8
+ # GitHub Actions rather than the Mend hosted app so the whole capability is in-repo and
9
+ # reproducible, with no external app-install state to drift.
10
+ on:
11
+ schedule:
12
+ # Every 3 hours. Renovate needs to run periodically not just to DISCOVER new versions,
13
+ # but to COME BACK and merge automerge PRs: renovate.json sets platformAutomerge:false
14
+ # (main is unprotected, so GitHub-native auto-merge is unavailable), which means Renovate
15
+ # performs the merge itself on a subsequent run once the PR's branch status is green.
16
+ # A few-hourly cadence keeps that merge latency low without burning Actions minutes.
17
+ - cron: "0 */3 * * *"
18
+ # On-demand runs for immediate pickup (e.g. right after a new urban publishes) and for
19
+ # debugging with a raised log level.
20
+ workflow_dispatch:
21
+ inputs:
22
+ logLevel:
23
+ description: "Renovate log level"
24
+ default: "info"
25
+ type: choice
26
+ options:
27
+ - debug
28
+ - info
29
+ - warn
30
+ # Re-run whenever the policy or this runner itself changes, so config edits take effect
31
+ # without waiting for the next scheduled tick.
32
+ push:
33
+ branches: [main]
34
+ paths:
35
+ - renovate.json
36
+ - .github/workflows/renovate.yml
37
+
38
+ # Renovate authenticates with RENOVATE_TOKEN (a PAT) for all git/PR/merge operations, so the
39
+ # job's GITHUB_TOKEN needs no elevated scope.
40
+ permissions:
41
+ contents: read
42
+
43
+ # Never let two Renovate passes run concurrently — overlapping runs race on the same branches
44
+ # and can double-open PRs. cancel-in-progress:false lets an in-flight pass (which may be mid-merge)
45
+ # finish rather than being killed by a newer trigger.
46
+ concurrency:
47
+ group: renovate
48
+ cancel-in-progress: false
49
+
50
+ jobs:
51
+ renovate:
52
+ name: renovate
53
+ runs-on: ubuntu-latest
54
+ steps:
55
+ - name: Checkout
56
+ uses: actions/checkout@v4
57
+
58
+ - name: Renovate
59
+ uses: renovatebot/github-action@v46.2.2
60
+ with:
61
+ # A Personal Access Token (repo scope), NOT the default GITHUB_TOKEN. This is required,
62
+ # not a preference: PRs opened by GITHUB_TOKEN do not trigger `on: pull_request`, so CI
63
+ # would never run on them and the green-gated automerge in renovate.json could never fire.
64
+ # A PAT-authored PR triggers CI normally, which is what makes "merge when green" work.
65
+ token: ${{ secrets.RENOVATE_TOKEN }}
66
+ env:
67
+ # Only ever operate on this repo (no org-wide autodiscovery).
68
+ RENOVATE_REPOSITORIES: ${{ github.repository }}
69
+ RENOVATE_AUTODISCOVER: "false"
70
+ # Renovate reads the repo's own renovate.json as its config automatically once it
71
+ # clones the repo above — no global configurationFile needed.
72
+ LOG_LEVEL: ${{ inputs.logLevel || 'info' }}
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [0.117.0](https://github.com/nanobpm/nano-workforce/compare/v0.116.0...v0.117.0) (2026-08-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * **delivery-graph:** gated startDeliveryGraph dispatch door (ADR 0005 S5) ([#405](https://github.com/nanobpm/nano-workforce/issues/405)) ([dc7c78e](https://github.com/nanobpm/nano-workforce/commit/dc7c78e03ef1a3a8cfb70e4e51b721a4419c8962)), closes [#380](https://github.com/nanobpm/nano-workforce/issues/380)
7
+
1
8
  # [0.116.0](https://github.com/nanobpm/nano-workforce/compare/v0.115.0...v0.116.0) (2026-08-20)
2
9
 
3
10
 
package/README.md CHANGED
@@ -441,6 +441,23 @@ returns `401` without the matching header; unset = open. The source lives in
441
441
  model, **generate** the diagram — CI enforces DI freshness), migration policy, and
442
442
  the CI gates.
443
443
 
444
+ ### Dependency updates (Renovate)
445
+
446
+ First-party `@nanobpm/*` packages (notably `@nanobpm/urban`) are kept current by a
447
+ self-hosted [Renovate](https://docs.renovatebot.com/) runner:
448
+ [`.github/workflows/renovate.yml`](.github/workflows/renovate.yml) runs on a schedule (and
449
+ `workflow_dispatch`), opens update PRs, and — per [`renovate.json`](renovate.json) — merges
450
+ non-major `@nanobpm/*` bumps once CI is green while leaving majors for a human.
451
+
452
+ It requires a repository secret **`RENOVATE_TOKEN`**: a Personal Access Token with `repo` +
453
+ `workflow` scope (or a fine-grained PAT with *Contents: read & write*, *Pull requests: read &
454
+ write*, *Issues: read & write* — the Dependency Dashboard is a GitHub Issue — and *Workflows:
455
+ read & write*, so Renovate can update files under `.github/workflows`). A PAT is
456
+ mandatory rather than the built-in `GITHUB_TOKEN` because PRs opened by `GITHUB_TOKEN` do not
457
+ trigger `on: pull_request` CI — so the "merge when green" gate would never fire. Set it via
458
+ `gh secret set RENOVATE_TOKEN --repo nanobpm/nano-workforce` (or repo → Settings → Secrets →
459
+ Actions), then trigger a first run from the Actions tab.
460
+
444
461
  ## License
445
462
 
446
463
  Apache-2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,249 @@
1
+ // Unit coverage for the S5 dispatch-door aggregate (ADR 0005 Decision 7) — the pure decision helpers
2
+ // (the idempotency key, the approval gate, the parked human-label map, the derived parked-node phase),
3
+ // plus the durable at-most-once launch-claim fence (`claimRunForLaunch`) exercised against the real
4
+ // provisioned SQLite data layer so its actual `status <> 'running'` compare-and-swap SQL is validated,
5
+ // not just modelled. The integration test (operations/startDeliveryGraph.integration.test.ts) proves
6
+ // the COMPOSED behaviour at the edge.
7
+ import { mkdtempSync, rmSync } from "node:fs";
8
+ import { tmpdir } from "node:os";
9
+ import { join, resolve } from "node:path";
10
+ import { test } from "node:test";
11
+ import { assertEquals } from "#test-assert";
12
+ import type { DataLayer } from "@nanobpm/urban";
13
+ import { bootTestApp } from "@nanobpm/urban-testkit";
14
+ import { compileDeliveryGraph } from "./deliveryGraphCompiler.ts";
15
+ import {
16
+ buildDeliveryGraphRunRow,
17
+ buildHumanLabels,
18
+ claimRunForLaunch,
19
+ computeRunKey,
20
+ deriveDeliveryPhase,
21
+ DELIVERY_PHASE,
22
+ deliveryGraphRuns,
23
+ humanTaskElementId,
24
+ isDeliveryGraphApproved,
25
+ parkRunFencedAgainstLaunch,
26
+ parseHumanLabels,
27
+ } from "./deliveryGraphRun.ts";
28
+ import { pollDeliveryGraphPhase } from "./service.ts";
29
+
30
+ const APP_ROOT = resolve(import.meta.dirname, "..");
31
+
32
+ /** Boot an app purely for its provisioned data layer (migration 058 applied), run `fn`, tear down. */
33
+ async function withData(fn: (data: DataLayer) => Promise<void>): Promise<void> {
34
+ const dir = mkdtempSync(join(tmpdir(), "nwf-dgrun-"));
35
+ const app = await bootTestApp(APP_ROOT, { env: { NANO_APP_DB_URL: `file:${join(dir, "app.db")}` } });
36
+ try {
37
+ await fn(app.db);
38
+ } finally {
39
+ await app.stop?.();
40
+ rmSync(dir, { recursive: true, force: true });
41
+ }
42
+ }
43
+
44
+ const claimRow = (status: "awaiting-approval" | "running") =>
45
+ buildDeliveryGraphRunRow({
46
+ runKey: "rk",
47
+ digest: "d",
48
+ status,
49
+ sideEffecting: true,
50
+ nodeCount: 1,
51
+ humanNodeCount: 0,
52
+ sideEffectCount: 1,
53
+ title: "t",
54
+ phase: status === "running" ? DELIVERY_PHASE.RUNNING : DELIVERY_PHASE.AWAITING_APPROVAL,
55
+ processKey: null,
56
+ });
57
+
58
+ test("claimRunForLaunch: an empty slot is won by INSERT; a second racer that also read empty loses the run_key PK fence", async () => {
59
+ await withData(async (data) => {
60
+ const claim = claimRow("running");
61
+ assertEquals(await claimRunForLaunch(data, false, claim), true); // inserted the claim → this caller launches
62
+ assertEquals(await claimRunForLaunch(data, false, claim), false); // the row now exists → PK fence, no second launch
63
+ assertEquals((await deliveryGraphRuns(data).get("rk"))?.status, "running");
64
+ });
65
+ });
66
+
67
+ test("claimRunForLaunch: a parked awaiting-approval row is claimed by ONE compare-and-swap — a second approved racer loses the `status <> 'running'` guard, so a graph launches at most once", async () => {
68
+ await withData(async (data) => {
69
+ const runs = deliveryGraphRuns(data);
70
+ await runs.insert(claimRow("awaiting-approval")); // a prior unapproved POST parked this run
71
+ const claim = claimRow("running");
72
+ assertEquals(await claimRunForLaunch(data, true, claim), true); // CAS flips awaiting-approval → running
73
+ assertEquals(await claimRunForLaunch(data, true, claim), false); // already running → guard blocks the double-launch
74
+ assertEquals((await runs.get("rk"))?.status, "running");
75
+ });
76
+ });
77
+
78
+ test("claimRunForLaunch: a TERMINAL row re-runs — the CAS flips it to running, and a concurrent re-run racer loses the guard", async () => {
79
+ await withData(async (data) => {
80
+ const runs = deliveryGraphRuns(data);
81
+ await runs.insert({ ...claimRow("running"), status: "failed" }); // a completed/terminal prior run
82
+ const claim = claimRow("running");
83
+ assertEquals(await claimRunForLaunch(data, true, claim), true); // re-run: failed <> running → flips
84
+ assertEquals(await claimRunForLaunch(data, true, claim), false); // now running → no second launch
85
+ assertEquals((await runs.get("rk"))?.status, "running");
86
+ });
87
+ });
88
+
89
+ test("claimRunForLaunch: re-running a terminal row clears the PRIOR instance key in the SAME atomic flip — a claimed `running` row is never visible pointing at a stale process_key", async () => {
90
+ await withData(async (data) => {
91
+ const runs = deliveryGraphRuns(data);
92
+ // A terminal prior run still carrying its old instance key + parked-node projection.
93
+ await runs.insert({
94
+ ...claimRow("running"),
95
+ status: "failed",
96
+ process_key: "OLD-PI",
97
+ process_definition_id: "OLD-DEF",
98
+ phase: "Parked on human node: publish",
99
+ phase_node_id: "delivery-human-task__n1",
100
+ });
101
+ // The fresh launch claim carries no instance key yet (processKey: null).
102
+ assertEquals(await claimRunForLaunch(data, true, claimRow("running")), true);
103
+ const row = await runs.get("rk");
104
+ assertEquals(row?.status, "running");
105
+ assertEquals(row?.process_key, null); // stale key cleared atomically with the flip — not left as "OLD-PI"
106
+ assertEquals(row?.process_definition_id, null);
107
+ assertEquals(row?.phase_node_id, null);
108
+ assertEquals(row?.phase, DELIVERY_PHASE.RUNNING);
109
+ });
110
+ });
111
+
112
+ // ── pollDeliveryGraphPhase: engine-key coercion ───────────────────────────────
113
+ test("pollDeliveryGraphPhase: a numeric engine processInstanceKey still matches the string process_key, so a COMPLETED instance reconciles to done", async () => {
114
+ await withData(async (data) => {
115
+ const runs = deliveryGraphRuns(data);
116
+ await runs.insert({ ...claimRow("running"), process_key: "12345" });
117
+ // The engine can yield a NUMERIC key; the poller compares against the string process_key.
118
+ const engine = {
119
+ searchProcessInstances: async () => [{ processInstanceKey: 12345, state: "COMPLETED" }],
120
+ searchUserTasks: async () => [],
121
+ };
122
+ await pollDeliveryGraphPhase(data, engine as never);
123
+ assertEquals((await runs.get("rk"))?.status, "done");
124
+ });
125
+ });
126
+
127
+ // ── parkRunFencedAgainstLaunch: the approval-park write never clobbers a launched claim ────────────
128
+ test("parkRunFencedAgainstLaunch: an approval-park write onto a launched `running` claim is a no-op — the at-most-once dispatch fence survives (no clobber back to awaiting-approval, no nulled process_key)", async () => {
129
+ await withData(async (data) => {
130
+ const runs = deliveryGraphRuns(data);
131
+ // A concurrent APPROVED submit already launched: the row is `running` with a live instance key.
132
+ await runs.insert({ ...claimRow("running"), process_key: "PI-1" });
133
+ // A racing UNAPPROVED submit that read the pre-launch row now tries to (re-)park it. The guarded
134
+ // write must refuse to overwrite the launched claim — otherwise a later re-submit double-launches.
135
+ await parkRunFencedAgainstLaunch(data, true, claimRow("awaiting-approval"));
136
+ const row = await runs.get("rk");
137
+ assertEquals(row?.status, "running"); // NOT clobbered back to awaiting-approval
138
+ assertEquals(row?.process_key, "PI-1"); // instance key preserved
139
+ });
140
+ });
141
+
142
+ test("parkRunFencedAgainstLaunch: a first park INSERTs the row; a park onto a still-parked row idempotently re-parks it (metadata refreshed, status stays awaiting-approval)", async () => {
143
+ await withData(async (data) => {
144
+ const runs = deliveryGraphRuns(data);
145
+ // First unapproved submit: no row yet → INSERT.
146
+ await parkRunFencedAgainstLaunch(data, false, claimRow("awaiting-approval"));
147
+ assertEquals((await runs.get("rk"))?.status, "awaiting-approval");
148
+ // A second unapproved submit onto the existing parked row: guarded UPDATE re-parks it (status is
149
+ // not `running`, so it applies) without duplicating the row.
150
+ await parkRunFencedAgainstLaunch(data, true, { ...claimRow("awaiting-approval"), digest: "d2" });
151
+ const row = await runs.get("rk");
152
+ assertEquals(row?.status, "awaiting-approval");
153
+ assertEquals(row?.digest, "d2");
154
+ });
155
+ });
156
+
157
+ // ── computeRunKey ─────────────────────────────────────────────────────────────
158
+ test("computeRunKey: a non-blank caller key wins; a blank/absent key falls back to the digest", () => {
159
+ assertEquals(computeRunKey("run-1", "digestX"), "run-1");
160
+ assertEquals(computeRunKey(" run-2 ", "digestX"), "run-2"); // trimmed
161
+ assertEquals(computeRunKey("", "digestX"), "digestX");
162
+ assertEquals(computeRunKey(" ", "digestX"), "digestX");
163
+ assertEquals(computeRunKey(null, "digestX"), "digestX");
164
+ assertEquals(computeRunKey(undefined, "digestX"), "digestX");
165
+ });
166
+
167
+ // ── isDeliveryGraphApproved ───────────────────────────────────────────────────
168
+ test("isDeliveryGraphApproved: a non-side-effecting graph needs no approval", () => {
169
+ assertEquals(isDeliveryGraphApproved(false, null, "d"), true);
170
+ assertEquals(isDeliveryGraphApproved(false, "wrong", "d"), true);
171
+ });
172
+
173
+ test("isDeliveryGraphApproved: a side-effecting graph dispatches ONLY with the matching content token", () => {
174
+ assertEquals(isDeliveryGraphApproved(true, "d", "d"), true);
175
+ assertEquals(isDeliveryGraphApproved(true, " d ", "d"), true); // trimmed
176
+ assertEquals(isDeliveryGraphApproved(true, "wrong", "d"), false);
177
+ assertEquals(isDeliveryGraphApproved(true, null, "d"), false);
178
+ assertEquals(isDeliveryGraphApproved(true, "", "d"), false);
179
+ });
180
+
181
+ // ── buildHumanLabels / parseHumanLabels ───────────────────────────────────────
182
+ test("buildHumanLabels: maps each human node's compiled user-task element id → its instruction label", () => {
183
+ const graph = {
184
+ nodes: [
185
+ { id: "open-b", kind: "agent", agent: { jobType: "j" } },
186
+ { id: "publish", kind: "human", human: { prompt: "run the manual OTP publish\nsecond line" } },
187
+ { id: "ack", kind: "human" }, // no prompt → falls back to the node id
188
+ ],
189
+ edges: [{ from: "open-b", to: "publish" }, { from: "publish", to: "ack" }],
190
+ };
191
+ const compiled = compileDeliveryGraph(graph);
192
+ assertEquals(compiled.ok, true);
193
+ if (!compiled.ok) return;
194
+ const labels = buildHumanLabels(compiled);
195
+ const publishEl = compiled.resolved.nodes.find((n) => n.id === "publish")?.element ?? "";
196
+ const ackEl = compiled.resolved.nodes.find((n) => n.id === "ack")?.element ?? "";
197
+ assertEquals(labels[humanTaskElementId(publishEl)], "run the manual OTP publish"); // first line only
198
+ assertEquals(labels[humanTaskElementId(ackEl)], "ack"); // fallback to node id
199
+ });
200
+
201
+ test("parseHumanLabels: round-trips a stored map and tolerates null/blank/corrupt", () => {
202
+ assertEquals(parseHumanLabels(JSON.stringify({ a: "x" })), { a: "x" });
203
+ assertEquals(parseHumanLabels(null), {});
204
+ assertEquals(parseHumanLabels(""), {});
205
+ assertEquals(parseHumanLabels(" "), {});
206
+ assertEquals(parseHumanLabels("{not json"), {});
207
+ assertEquals(parseHumanLabels(JSON.stringify(["a"])), {}); // non-object
208
+ assertEquals(parseHumanLabels(JSON.stringify({ a: 1, b: "y" })), { b: "y" }); // drops non-string values
209
+ });
210
+
211
+ // ── deriveDeliveryPhase ───────────────────────────────────────────────────────
212
+ test("deriveDeliveryPhase: COMPLETED → done, TERMINATED → failed", () => {
213
+ assertEquals(deriveDeliveryPhase("COMPLETED", [], {}), { status: "done", phase: DELIVERY_PHASE.COMPLETED, phase_node_id: null });
214
+ assertEquals(deriveDeliveryPhase("TERMINATED", [], {}), { status: "failed", phase: DELIVERY_PHASE.FAILED, phase_node_id: null });
215
+ });
216
+
217
+ test("deriveDeliveryPhase: ACTIVE with an open human task → parked on that node with its label", () => {
218
+ const el = humanTaskElementId("n2");
219
+ const p = deriveDeliveryPhase("ACTIVE", [{ elementId: el }], { [el]: "manual OTP publish" });
220
+ assertEquals(p.status, "running");
221
+ assertEquals(p.phase, "Parked on human node: manual OTP publish");
222
+ assertEquals(p.phase_node_id, el);
223
+ });
224
+
225
+ test("deriveDeliveryPhase: a parked node with no stored label falls back to the element id", () => {
226
+ const el = humanTaskElementId("n5");
227
+ const p = deriveDeliveryPhase("ACTIVE", [{ elementId: el }], {});
228
+ assertEquals(p.phase, `Parked on human node: ${el}`);
229
+ assertEquals(p.phase_node_id, el);
230
+ });
231
+
232
+ test("deriveDeliveryPhase: ACTIVE with only a non-human open task (or none) → a bare Running", () => {
233
+ assertEquals(deriveDeliveryPhase("ACTIVE", [], {}), { status: "running", phase: DELIVERY_PHASE.RUNNING, phase_node_id: null });
234
+ assertEquals(deriveDeliveryPhase("ACTIVE", [{ elementId: "some-service-task" }], {}), {
235
+ status: "running",
236
+ phase: DELIVERY_PHASE.RUNNING,
237
+ phase_node_id: null,
238
+ });
239
+ // A null state (instance not found this pass) is treated as still-running, never a false terminal.
240
+ assertEquals(deriveDeliveryPhase(null, [], {}), { status: "running", phase: DELIVERY_PHASE.RUNNING, phase_node_id: null });
241
+ });
242
+
243
+ test("deriveDeliveryPhase: multiple open human tasks pick the lowest element id deterministically", () => {
244
+ const a = humanTaskElementId("n1");
245
+ const b = humanTaskElementId("n3");
246
+ const p = deriveDeliveryPhase("ACTIVE", [{ elementId: b }, { elementId: a }], { [a]: "first", [b]: "second" });
247
+ assertEquals(p.phase, "Parked on human node: first");
248
+ assertEquals(p.phase_node_id, a);
249
+ });