@intentius/chant 0.124.57 → 0.124.59
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/dist/ci-product-words.d.ts +47 -2
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +59 -1
- package/dist/ci-product.d.ts +26 -2
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +25 -2
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +5 -1
- package/dist/cli/handlers/init.d.ts.map +1 -1
- package/dist/cli/handlers/init.js +16 -0
- package/dist/cli/handlers/lifecycle-drift.d.ts +2 -1
- package/dist/cli/handlers/lifecycle-drift.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle-drift.js +4 -2
- package/dist/cli/handlers/lock.d.ts.map +1 -1
- package/dist/cli/handlers/lock.js +45 -2
- package/dist/cli/handlers/serve.d.ts.map +1 -1
- package/dist/cli/handlers/serve.js +9 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +11 -3
- package/dist/cli/mcp/product-tools.d.ts +40 -7
- package/dist/cli/mcp/product-tools.d.ts.map +1 -1
- package/dist/cli/mcp/product-tools.js +58 -15
- package/dist/cli/mcp/read-only.d.ts +2 -1
- package/dist/cli/mcp/read-only.d.ts.map +1 -1
- package/dist/cli/mcp/read-only.js +2 -1
- package/dist/cli/mcp/server.d.ts +11 -0
- package/dist/cli/mcp/server.d.ts.map +1 -1
- package/dist/cli/mcp/server.js +15 -3
- package/dist/cli/mcp-config.d.ts +4 -1
- package/dist/cli/mcp-config.d.ts.map +1 -1
- package/dist/cli/mcp-config.js +6 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +27 -0
- package/dist/cli/registry.d.ts +14 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/pr-pipeline.d.ts +56 -0
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +55 -2
- package/dist/components/product-pipeline.d.ts +18 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +8 -2
- package/dist/drift-record.d.ts +5 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/e2e-harness/driver.d.ts.map +1 -1
- package/dist/e2e-harness/driver.js +97 -0
- package/dist/e2e-harness/forgejo.d.ts +5 -1
- package/dist/e2e-harness/forgejo.d.ts.map +1 -1
- package/dist/e2e-harness/forgejo.js +35 -0
- package/dist/e2e-harness/index.d.ts +7 -0
- package/dist/e2e-harness/index.d.ts.map +1 -1
- package/dist/e2e-harness/index.js +10 -1
- package/dist/e2e-harness/ports.d.ts +31 -0
- package/dist/e2e-harness/ports.d.ts.map +1 -1
- package/dist/e2e-harness/scenario.d.ts.map +1 -1
- package/dist/e2e-harness/scenario.js +9 -5
- package/dist/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
- package/dist/e2e-harness/schemas/index.d.ts +22 -1
- package/dist/e2e-harness/schemas/index.d.ts.map +1 -1
- package/dist/e2e-harness/schemas/index.js +1 -1
- package/dist/e2e-harness/steps.d.ts.map +1 -1
- package/dist/e2e-harness/steps.js +4 -0
- package/dist/lifecycle/lock-beat.d.ts +27 -0
- package/dist/lifecycle/lock-beat.d.ts.map +1 -0
- package/dist/lifecycle/lock-beat.js +84 -0
- package/dist/lifecycle/resource-lock.d.ts +54 -1
- package/dist/lifecycle/resource-lock.d.ts.map +1 -1
- package/dist/lifecycle/resource-lock.js +128 -7
- package/dist/mcp/types.d.ts +9 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/op/activities/activity-contracts.d.ts +4 -4
- package/dist/op/index.d.ts +1 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +1 -1
- package/dist/op/op-waves-notify.d.ts.map +1 -1
- package/dist/op/op-waves-notify.js +11 -0
- package/dist/op/op-waves-run.d.ts +28 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +92 -7
- package/dist/op/op-waves.d.ts +12 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +9 -2
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/template-request/index.d.ts +9 -0
- package/dist/template-request/index.d.ts.map +1 -0
- package/dist/template-request/index.js +8 -0
- package/dist/template-request/request-body.d.ts +21 -0
- package/dist/template-request/request-body.d.ts.map +1 -0
- package/dist/template-request/request-body.js +86 -0
- package/dist/template-request/template-request.d.ts +100 -0
- package/dist/template-request/template-request.d.ts.map +1 -0
- package/dist/template-request/template-request.js +149 -0
- package/dist/template-request/template-request.schema.json +100 -0
- package/dist/template-request/template-spec.d.ts +83 -0
- package/dist/template-request/template-spec.d.ts.map +1 -0
- package/dist/template-request/template-spec.js +146 -0
- package/dist/template-request/template.schema.json +114 -0
- package/dist/template-request/validate.d.ts +4 -0
- package/dist/template-request/validate.d.ts.map +1 -0
- package/dist/template-request/validate.js +21 -0
- package/dist/wave-runtime.mjs +298 -298
- package/dist/workspace/drift-cli.d.ts +13 -1
- package/dist/workspace/drift-cli.d.ts.map +1 -1
- package/dist/workspace/drift-cli.js +19 -3
- package/package.json +8 -1
- package/src/ci-product-words.test.ts +23 -0
- package/src/ci-product-words.ts +68 -3
- package/src/ci-product.ts +31 -1
- package/src/cli/commands/init.ts +3 -1
- package/src/cli/handlers/build.ts +5 -1
- package/src/cli/handlers/init.ts +18 -0
- package/src/cli/handlers/lifecycle-drift.test.ts +52 -0
- package/src/cli/handlers/lifecycle-drift.ts +4 -2
- package/src/cli/handlers/lock.ts +41 -2
- package/src/cli/handlers/serve.ts +9 -0
- package/src/cli/main.ts +11 -3
- package/src/cli/mcp/product-tools.test.ts +56 -1
- package/src/cli/mcp/product-tools.ts +66 -15
- package/src/cli/mcp/read-only.ts +2 -1
- package/src/cli/mcp/server.ts +20 -5
- package/src/cli/mcp-config.test.ts +52 -2
- package/src/cli/mcp-config.ts +6 -3
- package/src/cli/parse-args.ts +19 -0
- package/src/cli/registry.ts +14 -0
- package/src/components/pr-pipeline.ts +87 -2
- package/src/components/product-actions.test.ts +76 -0
- package/src/components/product-pipeline.ts +21 -2
- package/src/drift-record.ts +5 -0
- package/src/e2e-harness/driver.test.ts +163 -0
- package/src/e2e-harness/driver.ts +86 -1
- package/src/e2e-harness/forgejo.ts +42 -1
- package/src/e2e-harness/index.ts +11 -1
- package/src/e2e-harness/ports.ts +33 -0
- package/src/e2e-harness/scenario.ts +8 -6
- package/src/e2e-harness/schemas/README.md +11 -2
- package/src/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
- package/src/e2e-harness/schemas/index.ts +5 -1
- package/src/e2e-harness/schemas.test.ts +44 -1
- package/src/e2e-harness/steps.ts +4 -0
- package/src/lifecycle/lock-beat.ts +99 -0
- package/src/lifecycle/resource-lock-liveness.test.ts +289 -0
- package/src/lifecycle/resource-lock.ts +143 -8
- package/src/mcp/types.ts +9 -0
- package/src/op/index.ts +1 -0
- package/src/op/op-waves-notify.ts +11 -0
- package/src/op/op-waves-preview.test.ts +167 -0
- package/src/op/op-waves-run.ts +116 -8
- package/src/op/op-waves.ts +20 -3
- package/src/release-floors.ts +1 -1
- package/src/template-request/__fixtures__/request-body.md +41 -0
- package/src/template-request/index.ts +8 -0
- package/src/template-request/request-body.ts +91 -0
- package/src/template-request/template-request.schema.json +100 -0
- package/src/template-request/template-request.test.ts +315 -0
- package/src/template-request/template-request.ts +234 -0
- package/src/template-request/template-spec.ts +176 -0
- package/src/template-request/template.schema.json +114 -0
- package/src/template-request/validate.ts +28 -0
- package/src/workspace/drift-cli.test.ts +35 -1
- package/src/workspace/drift-cli.ts +21 -3
|
@@ -48,10 +48,19 @@ JSON Schemas (draft 2020-12) of the e2e harness (chant#4587). `index.ts` exports
|
|
|
48
48
|
| `reportUrl` | yes | The pipeline's `--report-url`, `s3://<bucket>/<prefix>`. |
|
|
49
49
|
| `env` | no | The chant environment the ledger records runs under. Default `local`. |
|
|
50
50
|
| `limits` | no | Seconds per kind of step, over the defaults in `steps.ts`. |
|
|
51
|
-
| `steps` | yes | In order. `do` is open, open-concurrent, plan, approve, merge, apply, out-of-band or kill-job; each may carry `expect`. |
|
|
51
|
+
| `steps` | yes | In order. `do` is open, open-concurrent, await-pull, plan, approve, merge, comment, apply, out-of-band or kill-job; each may carry `expect`. |
|
|
52
52
|
| `break` | yes | The BREAK arm: `env` with `BREAK: "1"`, and an optional `overlay` copied over every pull request of the break run. |
|
|
53
53
|
|
|
54
|
-
An outcome in `expect` has one key: `report` (`status`, `components`, `only`) on a plan or apply step, `ledger` (`op`, `status`, `count`), `comment`, `issue` (`title`, `open`), or `exit` on an out-of-band step.
|
|
54
|
+
An outcome in `expect` has one key: `report` (`status`, `components`, `only`) on a plan or apply step, `ledger` (`op`, `status`, `count`), `gated` (`op`, `status`, `count`), `comment`, `pull` (`title`, `files`, `only`) on a step with a pull request, `issue` (`title`, `open`), or `exit` on an out-of-band step.
|
|
55
|
+
|
|
56
|
+
The steps a product's pull request needs:
|
|
57
|
+
|
|
58
|
+
| Step | Fields | Does |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| `await-pull` | `branch`, `title`? | Waits, within its limit (300 s by default), for an open pull request from exactly `branch` whose title holds `title`, and binds it to the step's id. A product's command in an earlier `out-of-band` step opens it. Both runs wait for the same branch, and a pull request already open when the run started is never bound. |
|
|
61
|
+
| `comment` | `pull`, `body`, `as`? | Posts `body` on the pull request of the open or await-pull step `pull`, as `author` (the default), `reviewer` or `admin`. Limit 60 s. |
|
|
62
|
+
|
|
63
|
+
`plan`, `approve` and `merge` name an await-pull step in `pull` as they name an open step. The `pull` outcome reads the step's pull request: its title holds `title`, it changes every path in `files`, and with `only: true` it changes no other path. The `gated` outcome counts the gated requests of `op` asked since the run started, which write no op-run record and so never reach `ledger`: `gated` until a finished line names one, then `ok` when it applied or `failed`. These steps and outcomes were added within contract 1 by chant 0.124.58.
|
|
55
64
|
|
|
56
65
|
## e2e-claim-row/v1 and e2e-claims/v1
|
|
57
66
|
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"$defs": {
|
|
57
57
|
"name": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
|
|
58
|
-
"do": { "enum": ["open", "open-concurrent", "plan", "approve", "merge", "apply", "out-of-band", "kill-job"] },
|
|
58
|
+
"do": { "enum": ["open", "open-concurrent", "await-pull", "plan", "approve", "merge", "comment", "apply", "out-of-band", "kill-job"] },
|
|
59
59
|
"step": {
|
|
60
60
|
"type": "object",
|
|
61
61
|
"required": ["id", "do"],
|
|
@@ -81,10 +81,29 @@
|
|
|
81
81
|
"type": "object",
|
|
82
82
|
"properties": {
|
|
83
83
|
"do": { "enum": ["plan", "approve", "merge"] },
|
|
84
|
-
"pull": { "$ref": "#/$defs/name", "description": "The id of the open step whose pull request this is." }
|
|
84
|
+
"pull": { "$ref": "#/$defs/name", "description": "The id of the open or await-pull step whose pull request this is." }
|
|
85
85
|
},
|
|
86
86
|
"required": ["pull"]
|
|
87
87
|
},
|
|
88
|
+
{
|
|
89
|
+
"type": "object",
|
|
90
|
+
"properties": {
|
|
91
|
+
"do": { "const": "await-pull" },
|
|
92
|
+
"branch": { "type": "string", "minLength": 1, "description": "The exact head branch of the pull request a product opens. Both runs wait for this same branch: the BREAK run does not add -break to it." },
|
|
93
|
+
"title": { "type": "string", "minLength": 1, "description": "Text the pull request's title must hold, when given." }
|
|
94
|
+
},
|
|
95
|
+
"required": ["branch"]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"type": "object",
|
|
99
|
+
"properties": {
|
|
100
|
+
"do": { "const": "comment" },
|
|
101
|
+
"pull": { "$ref": "#/$defs/name", "description": "The id of the open or await-pull step whose pull request the comment goes on." },
|
|
102
|
+
"body": { "type": "string", "minLength": 1 },
|
|
103
|
+
"as": { "enum": ["author", "reviewer", "admin"], "description": "Who posts it. Default author." }
|
|
104
|
+
},
|
|
105
|
+
"required": ["pull", "body"]
|
|
106
|
+
},
|
|
88
107
|
{
|
|
89
108
|
"type": "object",
|
|
90
109
|
"properties": {
|
|
@@ -112,7 +131,7 @@
|
|
|
112
131
|
},
|
|
113
132
|
"outcome": {
|
|
114
133
|
"type": "object",
|
|
115
|
-
"description": "One thing a step must show. report reads the step's pr-plan.json or pr-apply.json; ledger reads the run records the scenario added; comment and
|
|
134
|
+
"description": "One thing a step must show. report reads the step's pr-plan.json or pr-apply.json; ledger reads the run records the scenario added; gated reads the gated requests the scenario added; comment, issue and pull read the forge; exit is an out-of-band command's exit code.",
|
|
116
135
|
"minProperties": 1,
|
|
117
136
|
"maxProperties": 1,
|
|
118
137
|
"additionalProperties": false,
|
|
@@ -136,7 +155,28 @@
|
|
|
136
155
|
"count": { "type": "integer", "minimum": 0 }
|
|
137
156
|
}
|
|
138
157
|
},
|
|
158
|
+
"gated": {
|
|
159
|
+
"type": "object",
|
|
160
|
+
"required": ["op"],
|
|
161
|
+
"additionalProperties": false,
|
|
162
|
+
"description": "Gated requests of op on the ledger, asked since the run started. A request is gated until a finished line names it, then ok when it applied and failed when it did not.",
|
|
163
|
+
"properties": {
|
|
164
|
+
"op": { "type": "string" },
|
|
165
|
+
"status": { "enum": ["gated", "ok", "failed"] },
|
|
166
|
+
"count": { "type": "integer", "minimum": 0 }
|
|
167
|
+
}
|
|
168
|
+
},
|
|
139
169
|
"comment": { "type": "string", "minLength": 1, "description": "Text one of the step's pull request comments holds." },
|
|
170
|
+
"pull": {
|
|
171
|
+
"type": "object",
|
|
172
|
+
"additionalProperties": false,
|
|
173
|
+
"description": "The step's pull request: its title holds title, it changes every path in files, and with only it changes no other path.",
|
|
174
|
+
"properties": {
|
|
175
|
+
"title": { "type": "string", "minLength": 1 },
|
|
176
|
+
"files": { "type": "array", "items": { "type": "string", "minLength": 1 } },
|
|
177
|
+
"only": { "type": "boolean", "description": "files names every path the pull request changes." }
|
|
178
|
+
}
|
|
179
|
+
},
|
|
140
180
|
"issue": {
|
|
141
181
|
"type": "object",
|
|
142
182
|
"required": ["title"],
|
|
@@ -111,14 +111,16 @@ export interface DemoCycle {
|
|
|
111
111
|
|
|
112
112
|
// ── e2e-scenario/v1 ───────────────────────────────────────────────────
|
|
113
113
|
|
|
114
|
-
export const SCENARIO_STEP_KINDS = ["open", "open-concurrent", "plan", "approve", "merge", "apply", "out-of-band", "kill-job"] as const;
|
|
114
|
+
export const SCENARIO_STEP_KINDS = ["open", "open-concurrent", "await-pull", "plan", "approve", "merge", "comment", "apply", "out-of-band", "kill-job"] as const;
|
|
115
115
|
export type ScenarioStepKind = (typeof SCENARIO_STEP_KINDS)[number];
|
|
116
116
|
|
|
117
117
|
/** One thing a step must show. Exactly one key is set. */
|
|
118
118
|
export type ScenarioOutcome =
|
|
119
119
|
| { report: { status?: string; components?: Record<string, string>; only?: boolean } }
|
|
120
120
|
| { ledger: { op: string; status?: "ok" | "fail" | "gated" | "waiting"; count?: number } }
|
|
121
|
+
| { gated: { op: string; status?: "gated" | "ok" | "failed"; count?: number } }
|
|
121
122
|
| { comment: string }
|
|
123
|
+
| { pull: { title?: string; files?: string[]; only?: boolean } }
|
|
122
124
|
| { issue: { title: string; open?: boolean } }
|
|
123
125
|
| { exit: number };
|
|
124
126
|
|
|
@@ -130,7 +132,9 @@ interface StepBase {
|
|
|
130
132
|
|
|
131
133
|
export type ScenarioStep =
|
|
132
134
|
| (StepBase & { do: "open" | "open-concurrent"; branch: string; overlay: string; title: string; body?: string })
|
|
135
|
+
| (StepBase & { do: "await-pull"; branch: string; title?: string })
|
|
133
136
|
| (StepBase & { do: "plan" | "approve" | "merge"; pull: string })
|
|
137
|
+
| (StepBase & { do: "comment"; pull: string; body: string; as?: "author" | "reviewer" | "admin" })
|
|
134
138
|
| (StepBase & { do: "apply"; merge: string })
|
|
135
139
|
| (StepBase & { do: "out-of-band"; command: string[] })
|
|
136
140
|
| (StepBase & { do: "kill-job"; match?: string });
|
|
@@ -65,7 +65,7 @@ describe("e2e-scenario/v1 and its lint", () => {
|
|
|
65
65
|
steps[2] = { id: "one-plan", do: "plan", pull: "nobody", expect: [{ report: { status: "planned" } }] };
|
|
66
66
|
steps[4] = { id: "one-apply", do: "apply", merge: "one", expect: [{ exit: 0 }] };
|
|
67
67
|
const findings = lintScenario(s);
|
|
68
|
-
expect(findings).toContainEqual({ at: "/steps/2/pull", message: "plan names nobody, which is not an earlier open step" });
|
|
68
|
+
expect(findings).toContainEqual({ at: "/steps/2/pull", message: "plan names nobody, which is not an earlier open or await-pull step" });
|
|
69
69
|
expect(findings).toContainEqual({ at: "/steps/4/merge", message: "apply names one, which is not an earlier merge step" });
|
|
70
70
|
expect(findings).toContainEqual({ at: "/steps/4/expect/0", message: "an exit outcome belongs on an out-of-band step" });
|
|
71
71
|
});
|
|
@@ -97,6 +97,49 @@ describe("e2e-scenario/v1 and its lint", () => {
|
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
+
describe("e2e-scenario/v1 steps for a pull request a product opens (chant#4650)", () => {
|
|
101
|
+
const product = (steps: unknown[]): Record<string, unknown> => ({ ...scenario(), steps });
|
|
102
|
+
const request = { id: "request", do: "out-of-band", command: ["terragucci", "request"], expect: [{ exit: 0 }] };
|
|
103
|
+
|
|
104
|
+
test("await-pull, comment and the pull and gated outcomes are in the schema", () => {
|
|
105
|
+
const s = product([
|
|
106
|
+
request,
|
|
107
|
+
{ id: "pr", do: "await-pull", branch: "request/bucket/orders", title: "orders", expect: [{ pull: { title: "orders", files: ["apps/orders/main.tf"], only: true } }] },
|
|
108
|
+
{ id: "pr-plan", do: "plan", pull: "pr", expect: [{ report: { status: "planned" } }] },
|
|
109
|
+
{ id: "invoke", do: "comment", pull: "pr", body: "/terragucci action orders rotate", as: "reviewer", expect: [{ gated: { op: "tf-action", status: "gated", count: 1 } }] },
|
|
110
|
+
]);
|
|
111
|
+
expect(validateScenario(s)).toMatchObject({ ok: true });
|
|
112
|
+
expect(lintScenario({ ...s, limits: { "await-pull": 600, comment: 30 } })).toEqual([]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("a plan naming an await-pull step lints clean, and one naming an unknown id has one finding naming it", () => {
|
|
116
|
+
const steps = (pull: string) => [request, { id: "pr", do: "await-pull", branch: "request/bucket/orders" }, { id: "pr-plan", do: "plan", pull, expect: [{ report: { status: "planned" } }] }];
|
|
117
|
+
expect(lintScenario(product(steps("pr")))).toEqual([]);
|
|
118
|
+
expect(lintScenario(product(steps("nobody")))).toEqual([{ at: "/steps/2/pull", message: "plan names nobody, which is not an earlier open or await-pull step" }]);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("a comment step names an earlier pull request, and a pull outcome belongs on a step with one", () => {
|
|
122
|
+
expect(lintScenario(product([request, { id: "c", do: "comment", pull: "later", body: "hi" }]))).toEqual([{ at: "/steps/1/pull", message: "comment names later, which is not an earlier open or await-pull step" }]);
|
|
123
|
+
expect(lintScenario(product([{ ...request, expect: [{ pull: { only: true } }] }]))).toEqual([{ at: "/steps/0/expect/0", message: "a pull outcome belongs on a step with a pull request" }]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("the schema refuses an await-pull with no branch, a comment with no pull or body, and unknown fields in the outcomes", () => {
|
|
127
|
+
for (const bad of [
|
|
128
|
+
{ id: "s", do: "await-pull", title: "T" },
|
|
129
|
+
{ id: "s", do: "comment", pull: "one" },
|
|
130
|
+
{ id: "s", do: "comment", body: "hi" },
|
|
131
|
+
{ id: "s", do: "comment", pull: "one", body: "hi", as: "stranger" },
|
|
132
|
+
{ id: "s", do: "plan", pull: "one", expect: [{ pull: { branch: "x" } }] },
|
|
133
|
+
{ id: "s", do: "plan", pull: "one", expect: [{ gated: { status: "ok" } }] },
|
|
134
|
+
{ id: "s", do: "plan", pull: "one", expect: [{ gated: { op: "tf-action", status: "applied" } }] },
|
|
135
|
+
]) {
|
|
136
|
+
const s = scenario();
|
|
137
|
+
(s.steps as unknown[]).push(bad);
|
|
138
|
+
expect(validateScenario(s).ok, JSON.stringify(bad)).toBe(false);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
100
143
|
const row = (over: Partial<ClaimRow> = {}): ClaimRow => ({
|
|
101
144
|
$schema: E2E_CLAIM_ROW_SCHEMA,
|
|
102
145
|
contract: 1,
|
package/src/e2e-harness/steps.ts
CHANGED
|
@@ -10,12 +10,16 @@ export const HARNESS_LIMITS: Record<ScenarioStepKind, number> = {
|
|
|
10
10
|
/** The branch push and the pull request open. */
|
|
11
11
|
open: 60,
|
|
12
12
|
"open-concurrent": 60,
|
|
13
|
+
/** An open pull request from the branch, which a product opens. */
|
|
14
|
+
"await-pull": 300,
|
|
13
15
|
/** pr-plan.json at the head, from the push. */
|
|
14
16
|
plan: 600,
|
|
15
17
|
/** The forge review and chant approve. */
|
|
16
18
|
approve: 120,
|
|
17
19
|
/** The merge and its merge commit. */
|
|
18
20
|
merge: 60,
|
|
21
|
+
/** Posting a comment on the pull request. */
|
|
22
|
+
comment: 60,
|
|
19
23
|
/** pr-apply.json at the merge commit, from the merge. */
|
|
20
24
|
apply: 900,
|
|
21
25
|
/** A command run out of band. */
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The heartbeat of a row hold (#4660). A job that is cancelled or killed
|
|
3
|
+
* never runs its cleanup, so the hold it took stays on `chant/lifecycle`
|
|
4
|
+
* and later waves on the stack wait on it. The hold carries a liveness
|
|
5
|
+
* token, `beat`, that a side process of the apply refreshes every
|
|
6
|
+
* `CHANT_LOCK_BEAT` seconds. The next waiter reads a hold whose beat is
|
|
7
|
+
* older than `CHANT_LOCK_BEAT_STALE` seconds as gone and takes it over
|
|
8
|
+
* (./resource-lock.ts `forgeLockLiveness`).
|
|
9
|
+
*
|
|
10
|
+
* The beat runs in its own process because an apply waits on its tool with
|
|
11
|
+
* `spawnSync`, which stops every timer of the job's process. The side
|
|
12
|
+
* process is `chant lock --beat <run> --parent <pid>`: it touches the hold,
|
|
13
|
+
* and ends when the hold is gone or when the job's process is. A job that is
|
|
14
|
+
* killed takes it along, and one that is not leaves a beat that goes stale.
|
|
15
|
+
*
|
|
16
|
+
* Only the chant CLI starts one ({@link setOwnChantCommand}); library
|
|
17
|
+
* callers and tests start none, and a hold without a beat keeps the forge
|
|
18
|
+
* and lease rules.
|
|
19
|
+
*/
|
|
20
|
+
import { spawn } from "node:child_process";
|
|
21
|
+
import type { LockBeatStarter } from "./resource-lock";
|
|
22
|
+
|
|
23
|
+
let own: string[] | undefined;
|
|
24
|
+
|
|
25
|
+
/** Record how to run this chant again; called by the CLI entry point. */
|
|
26
|
+
export function setOwnChantCommand(command: readonly string[] | undefined): void {
|
|
27
|
+
own = command && command.length > 0 && command.every((c) => typeof c === "string" && c !== "") ? [...command] : undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The starter of the heartbeat side process, or undefined outside the chant CLI or when `CHANT_LOCK_BEAT=off`. */
|
|
31
|
+
export function ownBeatStarter(env: Record<string, string | undefined> = process.env): LockBeatStarter | undefined {
|
|
32
|
+
if (!own || env.CHANT_LOCK_BEAT === "off") return undefined;
|
|
33
|
+
const command = own;
|
|
34
|
+
return ({ gate, holder, cwd }) => {
|
|
35
|
+
const [bin, ...lead] = command;
|
|
36
|
+
const child = spawn(bin!, [...lead, "lock", "--beat", holder.run, "--gate", gate, "--parent", String(process.pid)], {
|
|
37
|
+
...(cwd ? { cwd } : {}),
|
|
38
|
+
detached: true,
|
|
39
|
+
stdio: "ignore",
|
|
40
|
+
env,
|
|
41
|
+
});
|
|
42
|
+
child.on("error", () => {
|
|
43
|
+
// No side process: the hold keeps the forge and lease rules.
|
|
44
|
+
});
|
|
45
|
+
child.unref();
|
|
46
|
+
return () => {
|
|
47
|
+
try {
|
|
48
|
+
child.kill("SIGTERM");
|
|
49
|
+
} catch {
|
|
50
|
+
// Already gone.
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface BeatLoop {
|
|
57
|
+
gate: string;
|
|
58
|
+
run: string;
|
|
59
|
+
/** The process whose end ends the loop. */
|
|
60
|
+
parent: number;
|
|
61
|
+
intervalMs: number;
|
|
62
|
+
/** Touch the hold: `gone` ends the loop. */
|
|
63
|
+
beat(at: string): Promise<"held" | "gone">;
|
|
64
|
+
parentAlive?(pid: number): boolean;
|
|
65
|
+
sleep?(ms: number): Promise<void>;
|
|
66
|
+
now?(): number;
|
|
67
|
+
/** Where a failed touch is said. */
|
|
68
|
+
log?(line: string): void;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function processAlive(pid: number): boolean {
|
|
72
|
+
try {
|
|
73
|
+
process.kill(pid, 0);
|
|
74
|
+
return true;
|
|
75
|
+
} catch (e) {
|
|
76
|
+
return (e as NodeJS.ErrnoException).code === "EPERM";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Touch the hold now and every interval until it is released or taken over
|
|
82
|
+
* (`released`) or the parent process ends (`parent-gone`). A touch that fails
|
|
83
|
+
* is tried again at the next interval; the hold goes stale only after
|
|
84
|
+
* `CHANT_LOCK_BEAT_STALE` seconds of failures.
|
|
85
|
+
*/
|
|
86
|
+
export async function runBeatLoop(loop: BeatLoop): Promise<"released" | "parent-gone"> {
|
|
87
|
+
const alive = loop.parentAlive ?? processAlive;
|
|
88
|
+
const sleep = loop.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));
|
|
89
|
+
const now = loop.now ?? Date.now;
|
|
90
|
+
for (;;) {
|
|
91
|
+
if (!alive(loop.parent)) return "parent-gone";
|
|
92
|
+
try {
|
|
93
|
+
if ((await loop.beat(new Date(now()).toISOString())) === "gone") return "released";
|
|
94
|
+
} catch (err) {
|
|
95
|
+
loop.log?.(`could not touch the hold of run ${loop.run} on ${loop.gate}: ${err instanceof Error ? err.message : String(err)}`);
|
|
96
|
+
}
|
|
97
|
+
await sleep(loop.intervalMs);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4660: a hold left by a job that failed, lost its lock push or was
|
|
3
|
+
* cancelled must not block later waves forever, and a hold of a live job
|
|
4
|
+
* must still block. A bare remote and one clone per writer, as in
|
|
5
|
+
* resource-lock-wait.test.ts; the clock and the pause are the test's.
|
|
6
|
+
*/
|
|
7
|
+
import { afterAll, describe, expect, test } from "vitest";
|
|
8
|
+
import { execFileSync } from "node:child_process";
|
|
9
|
+
import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { stackRowKey, type LockRow } from "./lock-rows";
|
|
13
|
+
import { runBeatLoop } from "./lock-beat";
|
|
14
|
+
import {
|
|
15
|
+
beatLockRows,
|
|
16
|
+
clearRunLockRows,
|
|
17
|
+
forgeLockLiveness,
|
|
18
|
+
leaseLockRows,
|
|
19
|
+
readLockRows,
|
|
20
|
+
takeLockRows,
|
|
21
|
+
waitLockRows,
|
|
22
|
+
withWaiter,
|
|
23
|
+
type LockRowHolder,
|
|
24
|
+
} from "./resource-lock";
|
|
25
|
+
|
|
26
|
+
const dirs: string[] = [];
|
|
27
|
+
afterAll(() => {
|
|
28
|
+
for (const d of dirs) rmSync(d, { recursive: true, force: true });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function tmp(prefix: string): string {
|
|
32
|
+
const d = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
|
|
33
|
+
dirs.push(d);
|
|
34
|
+
return d;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function git(cwd: string, ...args: string[]): string {
|
|
38
|
+
return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function writers(n: number): { remote: string; clones: string[] } {
|
|
42
|
+
const remote = tmp("chant-lock-live-remote-");
|
|
43
|
+
git(remote, "init", "-q", "--bare", "-b", "main");
|
|
44
|
+
const seed = tmp("chant-lock-live-seed-");
|
|
45
|
+
git(seed, "init", "-q", "-b", "main");
|
|
46
|
+
git(seed, "config", "user.email", "seed@chant.dev");
|
|
47
|
+
git(seed, "config", "user.name", "Seed");
|
|
48
|
+
git(seed, "config", "commit.gpgsign", "false");
|
|
49
|
+
writeFileSync(join(seed, "README.md"), "# t\n");
|
|
50
|
+
git(seed, "add", "README.md");
|
|
51
|
+
git(seed, "commit", "-q", "-m", "init");
|
|
52
|
+
git(seed, "remote", "add", "origin", remote);
|
|
53
|
+
git(seed, "push", "-q", "origin", "main");
|
|
54
|
+
const clones: string[] = [];
|
|
55
|
+
for (let i = 0; i < n; i++) {
|
|
56
|
+
const c = tmp(`chant-lock-live-clone-${i}-`);
|
|
57
|
+
git(c, "clone", "-q", remote, ".");
|
|
58
|
+
git(c, "config", "user.email", `w${i}@chant.dev`);
|
|
59
|
+
git(c, "config", "user.name", `Writer ${i}`);
|
|
60
|
+
git(c, "config", "commit.gpgsign", "false");
|
|
61
|
+
clones.push(c);
|
|
62
|
+
}
|
|
63
|
+
return { remote, clones };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const row: LockRow = { key: stackRowKey("shop", "staging"), target: "shop/staging", address: "shop/staging" };
|
|
67
|
+
const holder = (run: string, at = new Date()): LockRowHolder => ({ run, at: at.toISOString() });
|
|
68
|
+
|
|
69
|
+
/** The forge cannot be asked (no token), so only the hold's own token and age speak. */
|
|
70
|
+
const liveness = (clock: () => number) => forgeLockLiveness({}, (async () => ({ ok: false, json: async () => ({}) })) as never, clock);
|
|
71
|
+
|
|
72
|
+
const MIN = 60_000;
|
|
73
|
+
|
|
74
|
+
describe("a failed job", () => {
|
|
75
|
+
test("lets go of its hold when its lease is released, so the next wave takes the row at once", async () => {
|
|
76
|
+
const { clones: [a, b] } = writers(2);
|
|
77
|
+
const first = await leaseLockRows("pr-apply", [row], { cwd: a, holder: holder("25"), beat: () => () => {} });
|
|
78
|
+
expect(first.ok).toBe(true);
|
|
79
|
+
expect((await readLockRows("pr-apply", { cwd: b })).rows).toEqual({ [row.key]: "25" });
|
|
80
|
+
if (first.ok) expect(await first.lease.release()).toBe(true);
|
|
81
|
+
expect((await readLockRows("pr-apply", { cwd: b })).rows).toEqual({});
|
|
82
|
+
const next = await takeLockRows("pr-apply", [row], holder("31"), { cwd: b, alive: liveness(Date.now) });
|
|
83
|
+
expect(next.ok).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("the beat stops before the rows are let go", async () => {
|
|
87
|
+
const { clones: [a] } = writers(1);
|
|
88
|
+
const order: string[] = [];
|
|
89
|
+
const first = await leaseLockRows("pr-apply", [row], { cwd: a, holder: holder("25"), beat: () => () => order.push("beat stopped") });
|
|
90
|
+
if (!first.ok) throw new Error("not held");
|
|
91
|
+
await first.lease.release();
|
|
92
|
+
order.push("released");
|
|
93
|
+
expect(order).toEqual(["beat stopped", "released"]);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("a job that lost its lock push", () => {
|
|
98
|
+
test("leaves no hold on the remote, so the next wave is not blocked", async () => {
|
|
99
|
+
const { clones: [a, b] } = writers(2);
|
|
100
|
+
// The push of chant/lifecycle from `a` cannot reach the remote.
|
|
101
|
+
git(a, "remote", "set-url", "--push", "origin", join(tmpdir(), "chant-lock-live-no-such-remote"));
|
|
102
|
+
await expect(leaseLockRows("pr-apply", [row], { cwd: a, holder: holder("25") })).rejects.toThrow();
|
|
103
|
+
expect((await readLockRows("pr-apply", { cwd: b })).rows).toEqual({});
|
|
104
|
+
const next = await takeLockRows("pr-apply", [row], holder("31"), { cwd: b, alive: liveness(Date.now) });
|
|
105
|
+
expect(next.ok).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("a job cancelled or killed with no cleanup", () => {
|
|
110
|
+
test("its hold is taken over once its beat is older than CHANT_LOCK_BEAT_STALE, with no token for the forge", async () => {
|
|
111
|
+
const { clones: [a, b] } = writers(2);
|
|
112
|
+
const t0 = Date.now();
|
|
113
|
+
// Run 26 took the row and beat once; then it was cancelled and never ran its cleanup.
|
|
114
|
+
const dead = await takeLockRows("pr-apply", [row], holder("26", new Date(t0)), { cwd: a, alive: liveness(() => t0) });
|
|
115
|
+
expect(dead.ok).toBe(true);
|
|
116
|
+
expect(await beatLockRows("pr-apply", "26", new Date(t0 + MIN).toISOString(), { cwd: a })).toBe("held");
|
|
117
|
+
|
|
118
|
+
// Nine minutes after the last beat the hold still blocks.
|
|
119
|
+
const early = await takeLockRows("pr-apply", [row], holder("44"), { cwd: b, alive: liveness(() => t0 + 10 * MIN) });
|
|
120
|
+
expect(early.ok).toBe(false);
|
|
121
|
+
|
|
122
|
+
// Past ten minutes it is gone, and the next wave takes the row over.
|
|
123
|
+
const late = await takeLockRows("pr-apply", [row], holder("44"), { cwd: b, alive: liveness(() => t0 + 12 * MIN) });
|
|
124
|
+
expect(late.ok).toBe(true);
|
|
125
|
+
if (late.ok) expect(late.tookOver.map((h) => h.run)).toEqual(["26"]);
|
|
126
|
+
expect((await readLockRows("pr-apply", { cwd: b })).rows).toEqual({ [row.key]: "44" });
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("a queued wave waits no longer than the beat, then takes the row", async () => {
|
|
130
|
+
const { clones: [a, b] } = writers(2);
|
|
131
|
+
const t0 = Date.now();
|
|
132
|
+
await takeLockRows("pr-apply", [row], holder("26", new Date(t0)), { cwd: a, alive: liveness(() => t0) });
|
|
133
|
+
await beatLockRows("pr-apply", "26", new Date(t0).toISOString(), { cwd: a });
|
|
134
|
+
let clock = t0 + 5 * MIN;
|
|
135
|
+
const got = await waitLockRows(
|
|
136
|
+
"pr-apply",
|
|
137
|
+
[row],
|
|
138
|
+
holder("44", new Date(clock)),
|
|
139
|
+
{
|
|
140
|
+
deadline: t0 + 60 * MIN,
|
|
141
|
+
pollMs: MIN,
|
|
142
|
+
now: () => clock,
|
|
143
|
+
// Each pause is a minute on the test's clock.
|
|
144
|
+
sleep: async (ms) => {
|
|
145
|
+
clock += ms;
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
{ cwd: b, alive: liveness(() => clock) },
|
|
149
|
+
);
|
|
150
|
+
expect(got.ok).toBe(true);
|
|
151
|
+
expect(got.tookOver.map((h) => h.run)).toEqual(["26"]);
|
|
152
|
+
// It waited for the beat to go stale, about five more minutes, and not for the 60 minute deadline.
|
|
153
|
+
expect(clock - t0).toBeLessThan(15 * MIN);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("a queued run that stopped refreshing its entry does not hold up the waves behind it", async () => {
|
|
157
|
+
const { clones: [a, b] } = writers(2);
|
|
158
|
+
const t0 = Date.now();
|
|
159
|
+
// Run 19 holds the row, and run 25 queues behind it with the older commit. Run 25 is then killed: its pause throws, so it never leaves the queue.
|
|
160
|
+
await takeLockRows("pr-apply", [row], holder("19", new Date(t0 - 10 * MIN)), { cwd: a, alive: liveness(() => t0 - 10 * MIN) });
|
|
161
|
+
await beatLockRows("pr-apply", "19", new Date(t0 - 10 * MIN).toISOString(), { cwd: a });
|
|
162
|
+
await expect(
|
|
163
|
+
waitLockRows(
|
|
164
|
+
"pr-apply",
|
|
165
|
+
[row],
|
|
166
|
+
holder("25", new Date(t0 - 10 * MIN)),
|
|
167
|
+
{ deadline: t0 + 60 * MIN, commitAt: "2026-10-30T20:00:00Z", now: () => t0 - 10 * MIN, sleep: async () => Promise.reject(new Error("killed")) },
|
|
168
|
+
{ cwd: a, alive: liveness(() => t0 - 10 * MIN) },
|
|
169
|
+
),
|
|
170
|
+
).rejects.toThrow("killed");
|
|
171
|
+
expect(Object.keys((await readLockRows("pr-apply", { cwd: b })).waiting ?? {})).toEqual(["25"]);
|
|
172
|
+
// Run 19 finishes and lets go.
|
|
173
|
+
await clearRunLockRows("pr-apply", "19", { cwd: a });
|
|
174
|
+
|
|
175
|
+
const wave = (clock: number) =>
|
|
176
|
+
waitLockRows(
|
|
177
|
+
"pr-apply",
|
|
178
|
+
[row],
|
|
179
|
+
holder("31", new Date(clock)),
|
|
180
|
+
{ deadline: clock, commitAt: "2026-10-30T21:00:00Z", now: () => clock, sleep: async () => {} },
|
|
181
|
+
{ cwd: b, alive: liveness(() => clock) },
|
|
182
|
+
);
|
|
183
|
+
// A minute on, run 25 may still be alive and goes first.
|
|
184
|
+
await expect(wave(t0 - 9 * MIN)).rejects.toThrow(/run 25/);
|
|
185
|
+
// Ten minutes after its last refresh it is gone, and run 31 takes the row.
|
|
186
|
+
const got = await wave(t0);
|
|
187
|
+
expect(got.ok).toBe(true);
|
|
188
|
+
expect((await readLockRows("pr-apply", { cwd: b })).rows).toEqual({ [row.key]: "31" });
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe("a live job", () => {
|
|
193
|
+
test("keeps blocking while its beat is fresh, even when its hold is older than the lease", async () => {
|
|
194
|
+
const { clones: [a, b] } = writers(2);
|
|
195
|
+
const t0 = Date.now();
|
|
196
|
+
await takeLockRows("pr-apply", [row], holder("19", new Date(t0)), { cwd: a, alive: liveness(() => t0) });
|
|
197
|
+
// Three hours on, an apply that still beats.
|
|
198
|
+
const later = t0 + 3 * 3600_000;
|
|
199
|
+
await beatLockRows("pr-apply", "19", new Date(later - MIN).toISOString(), { cwd: a });
|
|
200
|
+
const blocked = await takeLockRows("pr-apply", [row], holder("31"), { cwd: b, alive: liveness(() => later) });
|
|
201
|
+
expect(blocked.ok).toBe(false);
|
|
202
|
+
if (!blocked.ok) expect(blocked.held.map((h) => h.holder.run)).toEqual(["19"]);
|
|
203
|
+
expect((await readLockRows("pr-apply", { cwd: b })).rows).toEqual({ [row.key]: "19" });
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("a hold without a beat keeps the old rules: it blocks inside the lease", async () => {
|
|
207
|
+
const { clones: [a, b] } = writers(2);
|
|
208
|
+
const t0 = Date.now();
|
|
209
|
+
await takeLockRows("pr-apply", [row], holder("19", new Date(t0)), { cwd: a, alive: liveness(() => t0) });
|
|
210
|
+
const blocked = await takeLockRows("pr-apply", [row], holder("31"), { cwd: b, alive: liveness(() => t0 + 30 * MIN) });
|
|
211
|
+
expect(blocked.ok).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test("a wait that gives up names the hold and the command that frees it", async () => {
|
|
215
|
+
const { clones: [a, b] } = writers(2);
|
|
216
|
+
const t0 = Date.now();
|
|
217
|
+
await takeLockRows("pr-apply", [row], holder("19", new Date(t0)), { cwd: a, alive: liveness(() => t0) });
|
|
218
|
+
await beatLockRows("pr-apply", "19", new Date(t0).toISOString(), { cwd: a });
|
|
219
|
+
const got = await leaseLockRows("pr-apply", [row], {
|
|
220
|
+
cwd: b,
|
|
221
|
+
holder: holder("31"),
|
|
222
|
+
alive: liveness(() => t0),
|
|
223
|
+
wait: { deadline: t0, now: () => t0, sleep: async () => {} },
|
|
224
|
+
});
|
|
225
|
+
expect(got.ok).toBe(false);
|
|
226
|
+
if (!got.ok) {
|
|
227
|
+
expect(got.timedOut).toBe(true);
|
|
228
|
+
expect(got.message).toContain("run 19");
|
|
229
|
+
expect(got.message).toContain("last beat");
|
|
230
|
+
expect(got.message).toContain("chant unlock --run <id> --gate pr-apply");
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe("a hold cleared by hand", () => {
|
|
236
|
+
test("chant unlock --run frees the rows and the queue entry of a run, whatever its liveness", async () => {
|
|
237
|
+
const { clones: [a, b] } = writers(2);
|
|
238
|
+
await takeLockRows("pr-apply", [row], holder("26"), { cwd: a, alive: liveness(Date.now) });
|
|
239
|
+
const cleared = await clearRunLockRows("pr-apply", "26", { cwd: b });
|
|
240
|
+
expect(cleared.released).toEqual([row.key]);
|
|
241
|
+
const now = await readLockRows("pr-apply", { cwd: a });
|
|
242
|
+
expect(now.rows).toEqual({});
|
|
243
|
+
expect(now.holders).toEqual({});
|
|
244
|
+
// Nothing left to clear.
|
|
245
|
+
expect((await clearRunLockRows("pr-apply", "26", { cwd: b })).released).toEqual([]);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
describe("the heartbeat loop", () => {
|
|
250
|
+
const base = { gate: "pr-apply", run: "26", parent: 1, intervalMs: 60_000, sleep: async () => {}, now: () => 0 };
|
|
251
|
+
|
|
252
|
+
test("beats until the hold is gone", async () => {
|
|
253
|
+
let n = 0;
|
|
254
|
+
const end = await runBeatLoop({ ...base, parentAlive: () => true, beat: async () => (++n < 3 ? "held" : "gone") });
|
|
255
|
+
expect(end).toBe("released");
|
|
256
|
+
expect(n).toBe(3);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("ends with its parent process, and touches nothing after", async () => {
|
|
260
|
+
let n = 0;
|
|
261
|
+
let alive = true;
|
|
262
|
+
const end = await runBeatLoop({
|
|
263
|
+
...base,
|
|
264
|
+
parentAlive: () => alive,
|
|
265
|
+
beat: async () => {
|
|
266
|
+
if (++n === 2) alive = false;
|
|
267
|
+
return "held";
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
expect(end).toBe("parent-gone");
|
|
271
|
+
expect(n).toBe(2);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("a failed touch is tried again at the next interval", async () => {
|
|
275
|
+
let n = 0;
|
|
276
|
+
const lines: string[] = [];
|
|
277
|
+
const end = await runBeatLoop({
|
|
278
|
+
...base,
|
|
279
|
+
parentAlive: () => true,
|
|
280
|
+
log: (l) => lines.push(l),
|
|
281
|
+
beat: async () => {
|
|
282
|
+
if (++n === 1) throw new Error("push refused");
|
|
283
|
+
return "gone";
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
expect(end).toBe("released");
|
|
287
|
+
expect(lines[0]).toContain("push refused");
|
|
288
|
+
});
|
|
289
|
+
});
|