forgedock 1.56.0 → 1.58.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/bin/config-schema.mjs +1 -1
- package/bin/engine/outcome-codes.mjs +2 -1
- package/bin/engine/phases.mjs +4 -3
- package/bin/engine-cli.mjs +48 -12
- package/bin/forgedock.mjs +52 -3
- package/bin/gc.mjs +43 -6
- package/bin/help-text.mjs +4 -2
- package/bin/lean/batch-health.mjs +5 -1
- package/bin/lean/batch-health.test.mjs +7 -1
- package/bin/lean/batch.mjs +7 -2
- package/bin/lean/batch.test.mjs +45 -0
- package/bin/lean/conformance.e2e.test.mjs +3 -2
- package/bin/lean/conformance.mjs +118 -20
- package/bin/lean/conformance.test.mjs +172 -3
- package/bin/lean/decisions.mjs +98 -1
- package/bin/lean/decisions.test.mjs +30 -1
- package/bin/lean/depcache.mjs +124 -13
- package/bin/lean/depcache.test.mjs +121 -3
- package/bin/lean/design-gate.mjs +144 -0
- package/bin/lean/design-gate.test.mjs +169 -0
- package/bin/lean/effects-cap.test.mjs +17 -0
- package/bin/lean/effects.mjs +58 -13
- package/bin/lean/heavy.mjs +25 -8
- package/bin/lean/hostload.test.mjs +28 -0
- package/bin/lean/intake.mjs +97 -0
- package/bin/lean/intake.test.mjs +105 -0
- package/bin/lean/interfaces.mjs +181 -0
- package/bin/lean/interfaces.test.mjs +192 -0
- package/bin/lean/issuewatch-install.mjs +52 -12
- package/bin/lean/issuewatch-install.test.mjs +50 -0
- package/bin/lean/issuewatch-parity.mjs +16 -3
- package/bin/lean/issuewatch-parity.test.mjs +32 -0
- package/bin/lean/issuewatch-reconcile.mjs +29 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +21 -0
- package/bin/lean/issuewatch.mjs +34 -3
- package/bin/lean/issuewatch.test.mjs +49 -1
- package/bin/lean/lanecheck.test.mjs +15 -4
- package/bin/lean/lean.mjs +110 -24
- package/bin/lean/lean.test.mjs +183 -4
- package/bin/lean/orchestrate-blocked.test.mjs +18 -2
- package/bin/lean/orchestrate-owned.test.mjs +14 -5
- package/bin/lean/orchestrate.mjs +26 -4
- package/bin/lean/orphan-pr.mjs +3 -2
- package/bin/lean/orphan-pr.test.mjs +8 -1
- package/bin/lean/pagegate.mjs +35 -12
- package/bin/lean/pagegate.test.mjs +39 -1
- package/bin/lean/preflight.mjs +35 -1
- package/bin/lean/preflight.test.mjs +27 -1
- package/bin/lean/prompts.mjs +2 -1
- package/bin/lean/reap.test.mjs +39 -0
- package/bin/lean/recovery.test.mjs +28 -3
- package/bin/lean/release-config.mjs +169 -0
- package/bin/lean/release-config.test.mjs +132 -0
- package/bin/lean/release-control.mjs +171 -0
- package/bin/lean/release-control.test.mjs +167 -0
- package/bin/lean/release-deploy.mjs +209 -0
- package/bin/lean/release-deploy.test.mjs +217 -0
- package/bin/lean/release-fence.mjs +50 -0
- package/bin/lean/release-fence.test.mjs +105 -0
- package/bin/lean/release-flakes.mjs +139 -0
- package/bin/lean/release-flakes.test.mjs +116 -0
- package/bin/lean/release-gates.mjs +230 -0
- package/bin/lean/release-gates.test.mjs +146 -0
- package/bin/lean/release-ledger.mjs +176 -0
- package/bin/lean/release-ledger.test.mjs +226 -0
- package/bin/lean/release-minutes.mjs +102 -0
- package/bin/lean/release-minutes.test.mjs +107 -0
- package/bin/lean/release-nightly.mjs +75 -0
- package/bin/lean/release-nightly.test.mjs +48 -0
- package/bin/lean/release-postmerge.mjs +8 -2
- package/bin/lean/release-review.e2e.test.mjs +1 -0
- package/bin/lean/release-review.mjs +54 -7
- package/bin/lean/release-review.test.mjs +76 -7
- package/bin/lean/release-status.mjs +300 -0
- package/bin/lean/release-status.test.mjs +220 -0
- package/bin/lean/release-unitmap.mjs +35 -0
- package/bin/lean/release-unitmap.test.mjs +41 -0
- package/bin/lean/release-verify.mjs +221 -0
- package/bin/lean/release-verify.test.mjs +176 -0
- package/bin/lean/release.mjs +244 -22
- package/bin/lean/release.test.mjs +44 -0
- package/bin/lean/render.mjs +3 -1
- package/bin/lean/run-issue-placement.test.mjs +82 -0
- package/bin/lean/sandbox-remote.mjs +16 -0
- package/bin/lean/schedd.mjs +1 -1
- package/bin/lean/seam.mjs +115 -0
- package/bin/lean/seam.test.mjs +118 -0
- package/bin/lean/selftest-journey.mjs +40 -2
- package/bin/lean/selftest-journey.test.mjs +43 -3
- package/bin/lean/statuscomment.mjs +168 -0
- package/bin/lean/statuscomment.test.mjs +133 -0
- package/bin/lean/ui-quality.mjs +57 -0
- package/bin/lean/ui-quality.test.mjs +55 -0
- package/bin/lean/visual-gate.test.mjs +63 -0
- package/bin/pool/agent.mjs +16 -2
- package/bin/pool/router.mjs +5 -1
- package/bin/review-staging.mjs +5 -3
- package/bin/stats/card.mjs +117 -0
- package/bin/stats/card.test.mjs +109 -0
- package/bin/stats/conformance-outcomes.test.mjs +2 -1
- package/bin/stats/depth.mjs +1 -1
- package/bin/stats/gh-retry.test.mjs +152 -0
- package/bin/stats/github-source.mjs +147 -14
- package/bin/stats/index.mjs +35 -2
- package/bin/stats/stats.test.mjs +31 -3
- package/bin/vendor/js-yaml/LICENSE +21 -0
- package/bin/vendor/js-yaml/PIN.md +7 -0
- package/bin/vendor/js-yaml/js-yaml.mjs +3851 -0
- package/commands/design-render-critique-loop.md +2 -0
- package/commands/design.md +2 -0
- package/commands/issue.md +1 -1
- package/commands/milestone.md +1 -1
- package/commands/review-pr-agents/frontend.md +1 -0
- package/commands/review-pr-staging.md +5 -0
- package/docs/CONFIG.md +95 -2
- package/docs/ISSUE-WATCH.md +7 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/STATS.md +10 -0
- package/docs/design/visual-gate.md +25 -0
- package/docs/eval/adversarial-bench.md +2 -2
- package/docs/eval/corpus/adversarial-v1.json +3 -3
- package/docs/site/start-a-new-project.md +7 -0
- package/docs/spec/forge-protocol-v1.md +31 -0
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/scripts/acceptance-red-green.sh +15 -1
- package/scripts/acceptance-red-green.test.sh +12 -0
- package/scripts/bench-adversarial.mjs +4 -0
- package/scripts/bench-lightlane.mjs +4 -1
- package/scripts/bootstrap-create.mjs +8 -2
- package/scripts/ci-local/scoping.mjs +19 -0
- package/scripts/ci-local.test.sh +16 -3
- package/scripts/fixtures/ci-local/gha-dorny/.github/workflows/ci.yml +4 -0
- package/scripts/plan-validate-live.mjs +9 -6
- package/scripts/review-prepare.sh +7 -1
- package/scripts/review-roster.sh +5 -2
- package/scripts/review-roster.test.sh +9 -0
- package/scripts/visual-gate.mjs +64 -0
- package/templates/bootstrap/technical-spike.md +17 -0
- package/templates/contracts/seam-check.mjs +236 -0
package/bin/lean/decisions.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import * as nodeFs from "node:fs";
|
|
|
13
13
|
import { homedir } from "node:os";
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
import { noComments } from "./render.mjs";
|
|
16
|
+
import { parseSeamForm, roleAnchors, buildSeam, SEAM_KINDS } from "./seam.mjs";
|
|
16
17
|
|
|
17
18
|
export const DECISION_MARKER = "FORGE:DECISION";
|
|
18
19
|
/** Preserve rows the engine adds from history per lane; guards (#4694) share this cap. */
|
|
@@ -28,6 +29,19 @@ const one = (v, max = TEXT_MAX) => {
|
|
|
28
29
|
const strs = (v, max = ANCHORS_MAX, len = 200) => [...new Set((Array.isArray(v) ? v : []).map((x) => one(x, len)).filter(Boolean))].slice(0, max);
|
|
29
30
|
const cleanAnchor = (a) => String(a).replace(/^\.\//, "").replace(/^\/+/, "");
|
|
30
31
|
|
|
32
|
+
/** #5338: a stored seam (machine form of an interface) bounded and validated, or null. */
|
|
33
|
+
function cleanSeam(v) {
|
|
34
|
+
if (!v || typeof v !== "object" || !SEAM_KINDS.includes(v.kind) || !v[v.kind] || typeof v[v.kind] !== "object") return null;
|
|
35
|
+
const provider = strs(v.provider).map(cleanAnchor), consumer = strs(v.consumer).map(cleanAnchor);
|
|
36
|
+
if (!provider.length || !consumer.length) return null;
|
|
37
|
+
const form = v[v.kind];
|
|
38
|
+
const body = v.kind === "route" ? { method: one(form.method, 10), path: one(form.path, 200) }
|
|
39
|
+
: v.kind === "symbol" ? { name: one(form.name, 80), params: (Array.isArray(form.params) ? form.params : []).slice(0, 20).map((p) => ({ name: one(p?.name, 60), optional: Boolean(p?.optional), variadic: Boolean(p?.variadic) })).filter((p) => p.name) }
|
|
40
|
+
: { fields: strs(form.fields, 30, 60) };
|
|
41
|
+
if ((v.kind === "route" && (!body.method || !body.path)) || (v.kind === "symbol" && !body.name) || (v.kind === "payload" && !body.fields.length)) return null;
|
|
42
|
+
return { kind: v.kind, auth: one(v.auth, 160), provider, consumer, [v.kind]: body };
|
|
43
|
+
}
|
|
44
|
+
|
|
31
45
|
/** A bounded decision record from raw input, or null when it has no choice or no anchor. `issue` is the register issue. */
|
|
32
46
|
export function normaliseDecision(raw, { issue = null, n = 1 } = {}) {
|
|
33
47
|
const r = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
@@ -38,6 +52,10 @@ export function normaliseDecision(raw, { issue = null, n = 1 } = {}) {
|
|
|
38
52
|
const rec = { v: 1, id: one(r.id, 60) || `d${iss ?? 0}-${n}`, choice, why: one(r.why), anchors, issue: iss, status };
|
|
39
53
|
const symbols = strs(r.symbols, ANCHORS_MAX, 80);
|
|
40
54
|
if (symbols.length) rec.symbols = symbols;
|
|
55
|
+
const consumers = strs(r.consumers, ANCHORS_MAX, 120); // #5338: issues (#N) or names of the code that builds against an interface
|
|
56
|
+
if (consumers.length) rec.consumers = consumers;
|
|
57
|
+
const seam = cleanSeam(r.seam);
|
|
58
|
+
if (seam) rec.seam = seam;
|
|
41
59
|
if (one(r.supersedes, 60)) rec.supersedes = one(r.supersedes, 60);
|
|
42
60
|
if (status === "superseded" && one(r.superseded_by, 60)) rec.superseded_by = one(r.superseded_by, 60);
|
|
43
61
|
return rec;
|
|
@@ -63,6 +81,18 @@ export function parseDecisionComment(body, { issue = null } = {}) {
|
|
|
63
81
|
} catch { return null; }
|
|
64
82
|
}
|
|
65
83
|
|
|
84
|
+
/** #5547: `<!-- FORGE:DECISION {"requirement":"R2","disposition":"post-deploy","why":"..."} -->` -> {requirement, disposition, why}; null for anything else (anchored records included). */
|
|
85
|
+
export function parseRequirementDecision(body) {
|
|
86
|
+
const m = MARKER_RE.exec(String(body ?? "").split("\n", 1)[0]);
|
|
87
|
+
if (!m) return null;
|
|
88
|
+
try {
|
|
89
|
+
const raw = JSON.parse(m[1]);
|
|
90
|
+
const id = typeof raw?.requirement === "string" ? raw.requirement.trim() : "";
|
|
91
|
+
if (!/^R\d+$/.test(id) || raw.disposition !== "post-deploy") return null;
|
|
92
|
+
return { requirement: id, disposition: "post-deploy", why: one(raw.why) };
|
|
93
|
+
} catch { return null; }
|
|
94
|
+
}
|
|
95
|
+
|
|
66
96
|
/** One record per id, the latest wins (input in posting order); ids ordered by first appearance. */
|
|
67
97
|
export function foldDecisions(records) {
|
|
68
98
|
const by = new Map();
|
|
@@ -112,6 +142,7 @@ export function historyRows(records, deliverablePaths, { cap = HISTORY_ROWS_MAX,
|
|
|
112
142
|
what: `${d.choice}${d.why ? ` (${d.why})` : ""} [decision ${d.id}${d.issue ? `, #${d.issue}` : ""}; to change it, amend {kind:"decision", decision:{choice, anchors, supersedes:"${d.id}"}, why}]`,
|
|
113
143
|
source: "decision",
|
|
114
144
|
decision: d.id,
|
|
145
|
+
anchors: d.anchors,
|
|
115
146
|
}));
|
|
116
147
|
}
|
|
117
148
|
|
|
@@ -127,7 +158,8 @@ export function withDecisionRows(contract, records) {
|
|
|
127
158
|
|
|
128
159
|
/** {old, next}: the old record marked superseded by the new id, the new one linked back with `supersedes`. */
|
|
129
160
|
export function supersede(old, next) {
|
|
130
|
-
|
|
161
|
+
const inherit = !next.consumers?.length && old.consumers?.length ? { consumers: old.consumers } : {}; // #5338: the consumers of the old interface still consume the new one
|
|
162
|
+
return { old: { ...old, status: "superseded", superseded_by: next.id }, next: { ...next, ...inherit, supersedes: old.id } };
|
|
131
163
|
}
|
|
132
164
|
|
|
133
165
|
export const decisionsDir = () => process.env.FORGEDOCK_DECISIONS_DIR || join(homedir(), ".forge", "decisions");
|
|
@@ -179,3 +211,68 @@ export async function recordDecisions(list, { issue, repo, post, fs = nodeFs })
|
|
|
179
211
|
if (out.length) writeDecisionIndex(repo, index, { fs });
|
|
180
212
|
return out;
|
|
181
213
|
}
|
|
214
|
+
|
|
215
|
+
const cells = (line) => line.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim());
|
|
216
|
+
const anchorList = (s) => [...String(s ?? "").matchAll(/`([^`]+)`/g)].map((m) => m[1]);
|
|
217
|
+
const placeholder = (s) => /^\{.*\}$/.test(String(s ?? "").trim());
|
|
218
|
+
const consumerList = (s) => String(s ?? "").split(/[,;]/).map((x) => x.replace(/`/g, "").trim()).filter((x) => x && !placeholder(x) && !/^(none|n\/a|-)$/i.test(x));
|
|
219
|
+
|
|
220
|
+
const sectionsOf = (text) => {
|
|
221
|
+
const secs = [];
|
|
222
|
+
let fence = null;
|
|
223
|
+
for (const line of String(text ?? "").replace(/\r\n/g, "\n").split("\n")) {
|
|
224
|
+
const f = /^[ \t]*(`{3,}|~{3,})/.exec(line);
|
|
225
|
+
if (f) { fence = fence ? (f[1][0] === fence ? null : fence) : f[1][0]; if (secs.length) secs.at(-1).lines.push(line); continue; }
|
|
226
|
+
const h = fence ? null : /^##(?!#)[ \t]+(.+?)[ \t]*$/.exec(line);
|
|
227
|
+
if (h) secs.push({ heading: h[1], lines: [] });
|
|
228
|
+
else if (secs.length) secs.at(-1).lines.push(line);
|
|
229
|
+
}
|
|
230
|
+
return secs;
|
|
231
|
+
};
|
|
232
|
+
const COLS = { boundary: /^boundary|^seam|^interface/i, signature: /^signature|^schema|^contract/i, auth: /^auth/i, owner: /^owner/i, anchors: /^anchors?/i, consumers: /^consumers?/i };
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* #5338: the rows of the `## Interfaces` section of a spike or epic body: [{boundary, signature, auth, owner, anchors,
|
|
236
|
+
* consumers, roles, seam}]. Columns are matched by header name (Boundary | Signature or schema | Auth mode | Owner issue |
|
|
237
|
+
* Anchors | Consumers?), a five-column table without Consumers is valid. `{...}` template rows and rows with no anchor
|
|
238
|
+
* are skipped. `anchors` are the backticked paths (`provider:`/`consumer:` prefixes are roles, see seam.mjs). Pure.
|
|
239
|
+
*/
|
|
240
|
+
export const interfaceRows = (text) => rowsOfSection(sectionsOf(text).find((x) => /^interfaces\b/i.test(x.heading)));
|
|
241
|
+
function rowsOfSection(sec) {
|
|
242
|
+
const rows = (sec?.lines ?? []).filter((l) => l.trim().startsWith("|"));
|
|
243
|
+
if (rows.length < 3) return [];
|
|
244
|
+
const head = cells(rows[0]), idx = {};
|
|
245
|
+
for (const [k, re] of Object.entries(COLS)) idx[k] = head.findIndex((h) => re.test(h));
|
|
246
|
+
for (const [k, d] of Object.entries({ boundary: 0, signature: 1, auth: 2, owner: 3, anchors: 4 })) if (idx[k] < 0) idx[k] = d;
|
|
247
|
+
const out = [];
|
|
248
|
+
for (const l of rows.slice(2)) {
|
|
249
|
+
const c = cells(l), get = (k) => (idx[k] >= 0 ? c[idx[k]] ?? "" : "");
|
|
250
|
+
const boundary = get("boundary"), signature = get("signature");
|
|
251
|
+
if (!boundary || [boundary, signature, get("anchors")].some(placeholder)) continue;
|
|
252
|
+
const roles = roleAnchors(anchorList(get("anchors")));
|
|
253
|
+
if (!roles.all.length) continue;
|
|
254
|
+
const form = parseSeamForm(signature);
|
|
255
|
+
out.push({ boundary, signature, auth: get("auth"), owner: get("owner"), anchors: roles.all, consumers: consumerList(get("consumers")), roles, seam: buildSeam(form, roles, get("auth")) });
|
|
256
|
+
}
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* #5338: decision records from a technical spike or a feature epic. Each row of the `## Interfaces` table becomes
|
|
262
|
+
* "Interface <boundary>: <signature>; auth <mode>; owner <issue>" (carrying its consumers and, when the signature is a
|
|
263
|
+
* route, function or payload, its machine-form `seam`), and any other `## ` section that has both a `**Rationale**:` and
|
|
264
|
+
* an `**Anchors**:` line becomes "<heading>: <rationale>". Ids are `i<issue>-<n>`; pure, no LLM.
|
|
265
|
+
*/
|
|
266
|
+
export function interfaceDecisions(spikeText, { issue = null } = {}) {
|
|
267
|
+
const raw = [];
|
|
268
|
+
for (const s of sectionsOf(spikeText)) {
|
|
269
|
+
if (/^interfaces\b/i.test(s.heading)) {
|
|
270
|
+
for (const r of rowsOfSection(s)) raw.push({ choice: `Interface ${r.boundary}: ${r.signature}; auth ${r.auth}; owner ${r.owner}`, why: "Interfaces", anchors: r.anchors, consumers: r.consumers, seam: r.seam });
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const why = s.lines.map((l) => /\*\*Rationale\*\*:\s*(.+)/.exec(l)?.[1]).find(Boolean);
|
|
274
|
+
const anchors = anchorList(s.lines.map((l) => /\*\*Anchors\*\*:\s*(.+)/.exec(l)?.[1]).find(Boolean));
|
|
275
|
+
if (why && anchors.length && !placeholder(why)) raw.push({ choice: `${s.heading}: ${why}`, why: "architecture choice", anchors });
|
|
276
|
+
}
|
|
277
|
+
return raw.map((r, i) => normaliseDecision({ ...r, id: `i${issue ?? 0}-${i + 1}` }, { issue, n: i + 1 })).filter(Boolean);
|
|
278
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
6
|
-
import { normaliseDecision, renderDecision, parseDecisionComment, foldDecisions, anchorMatches, deadAnchors, staleDecisions, historyRows, withDecisionRows, supersede, readDecisionIndex, recordDecisions, HISTORY_ROWS_MAX } from "./decisions.mjs";
|
|
6
|
+
import { normaliseDecision, interfaceDecisions, renderDecision, parseDecisionComment, foldDecisions, anchorMatches, deadAnchors, staleDecisions, historyRows, withDecisionRows, supersede, readDecisionIndex, recordDecisions, HISTORY_ROWS_MAX } from "./decisions.mjs";
|
|
7
7
|
|
|
8
8
|
const D = (o) => normaliseDecision({ choice: "use A not B", why: "B leaks", anchors: ["src/a/**"], ...o }, { issue: 10, n: 1 });
|
|
9
9
|
|
|
@@ -68,4 +68,33 @@ describe("decisions (#4695)", () => {
|
|
|
68
68
|
assert.equal(idx.find((d) => d.id === "d10-1").status, "superseded");
|
|
69
69
|
assert.equal(idx.find((d) => d.id === "d11-1").supersedes, "d10-1");
|
|
70
70
|
});
|
|
71
|
+
it("interface decisions (#5338): spike rows and anchored choices become records; lanes on the anchors get H-rows; supersedes retires one", () => {
|
|
72
|
+
const spike = [
|
|
73
|
+
"## Stack", "next", "**Rationale**: one framework", "**Anchors**: `web/`", "",
|
|
74
|
+
"## Interfaces", "| Boundary | Signature or schema | Auth mode | Owner issue | Anchors |", "|---|---|---|---|---|",
|
|
75
|
+
"| api -> worker | refund(id: str, amount: int) | internal key | WORKER | `worker/refund.py`, `api/` |",
|
|
76
|
+
"| {x} | {y} | {z} | {o} | `{p}` |", "| no anchor | sig | key | O | |", "",
|
|
77
|
+
].join("\n");
|
|
78
|
+
const recs = interfaceDecisions(spike, { issue: 7 });
|
|
79
|
+
assert.deepEqual(recs.map((r) => r.id), ["i7-1", "i7-2"]);
|
|
80
|
+
assert.deepEqual(recs.map((r) => r.anchors), [["web/"], ["worker/refund.py", "api/"]]);
|
|
81
|
+
assert.equal(recs[1].choice, "Interface api -> worker: refund(id: str, amount: int); auth internal key; owner WORKER");
|
|
82
|
+
const lane = withDecisionRows({ deliverables: [{ id: "D1", path: "worker/refund.py" }], preserve: [] }, recs);
|
|
83
|
+
assert.equal(lane.preserve.length, 1);
|
|
84
|
+
assert.equal(lane.preserve[0].source, "decision");
|
|
85
|
+
assert.match(lane.preserve[0].what, /Interface api -> worker.*supersedes:"i7-2"/);
|
|
86
|
+
const { old, next } = supersede(recs[1], D({ id: "n" }));
|
|
87
|
+
const gone = withDecisionRows({ deliverables: [{ id: "D1", path: "worker/refund.py" }], preserve: [] }, [...recs, old, next]);
|
|
88
|
+
assert.ok(gone.preserve.every((p) => p.decision !== "i7-2"));
|
|
89
|
+
assert.deepEqual(interfaceDecisions("## Interfaces\nnone", { issue: 1 }), []);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
import { parseRequirementDecision } from "./decisions.mjs";
|
|
93
|
+
describe("#5547 requirement decisions", () => {
|
|
94
|
+
it("parses a post-deploy requirement decision and ignores anchored, prose and other dispositions", () => {
|
|
95
|
+
assert.deepEqual(parseRequirementDecision('<!-- FORGE:DECISION {"requirement":"R2","disposition":"post-deploy","why":"paid run"} -->\nx'), { requirement: "R2", disposition: "post-deploy", why: "paid run" });
|
|
96
|
+
assert.equal(parseRequirementDecision('<!-- FORGE:DECISION {"requirement":"R2","disposition":"deliver"} -->'), null);
|
|
97
|
+
assert.equal(parseRequirementDecision('<!-- FORGE:DECISION {"choice":"x","anchors":["a.js"]} -->'), null);
|
|
98
|
+
assert.equal(parseRequirementDecision("FORGE:DECISION prose"), null);
|
|
99
|
+
});
|
|
71
100
|
});
|
package/bin/lean/depcache.mjs
CHANGED
|
@@ -34,6 +34,8 @@ const pidAlive = (pid) => { try { process.kill(pid, 0); return true; } catch (e)
|
|
|
34
34
|
* Error text for a reason: pnpm prints its ERR_PNPM_* errors on stdout (#4522), so the first such line from either
|
|
35
35
|
* stream leads, then the last lines of stderr and stdout; the message only when both streams are empty.
|
|
36
36
|
*/
|
|
37
|
+
/** #5592: poetry cannot install the project itself (not package-mode: no package dir, no `package-mode = false`). */
|
|
38
|
+
const NO_ROOT_RE = /--no-root|current project could not be installed|No file\/folder found for package|does not contain any element/i;
|
|
37
39
|
const msg = (e) => {
|
|
38
40
|
const lines = (s) => String(s ?? "").split("\n").map((l) => l.trim()).filter(Boolean);
|
|
39
41
|
const err = lines(e?.stderr), out = lines(e?.stdout);
|
|
@@ -102,16 +104,55 @@ function serviceLocks(fs, wt) {
|
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
const JS = new Set(["pnpm", "npm", "yarn"]);
|
|
107
|
+
const PY = new Set(["uv", "poetry"]);
|
|
108
|
+
/** Files a finished install leaves at the top of node_modules (npm, yarn classic, yarn berry, pnpm). */
|
|
109
|
+
const JS_MARKERS = [".package-lock.json", ".yarn-integrity", ".yarn-state.yml", ".modules.yaml"];
|
|
110
|
+
|
|
111
|
+
/** #5590: the project's declared Python range (`[project] requires-python` / `[tool.poetry.dependencies] python`), null when absent. */
|
|
112
|
+
export function pyRange(text, eco) {
|
|
113
|
+
let section = "", poetry = null, pep = null;
|
|
114
|
+
for (const raw of String(text).split("\n")) {
|
|
115
|
+
const line = raw.trim();
|
|
116
|
+
const h = /^\[([^\]]+)\]$/.exec(line);
|
|
117
|
+
if (h) { section = h[1].trim(); continue; }
|
|
118
|
+
let m;
|
|
119
|
+
if (section === "project" && (m = /^requires-python\s*=\s*["']([^"']+)["']/.exec(line))) pep = m[1];
|
|
120
|
+
else if (section === "tool.poetry.dependencies" && (m = /^python\s*=\s*["']([^"']+)["']/.exec(line))) poetry = m[1];
|
|
121
|
+
}
|
|
122
|
+
return eco === "poetry" ? poetry ?? pep : pep ?? poetry;
|
|
123
|
+
}
|
|
124
|
+
const cmpVer = (a, b) => { for (let i = 0; i < 3; i++) { const d = (a[i] ?? 0) - (b[i] ?? 0); if (d) return d; } return 0; };
|
|
125
|
+
const prefixOf = (v, n) => n.every((x, i) => v[i] === x);
|
|
126
|
+
function clauseOk(clause, v) {
|
|
127
|
+
const m = /^(\^|~=|~|==|!=|>=|<=|>|<)?v?(\d+(?:\.\d+)*)(\.\*)?$/.exec(clause);
|
|
128
|
+
if (!m) return true; // unparseable: never constrain
|
|
129
|
+
const op = m[1] ?? "==", n = m[2].split(".").map(Number), wild = Boolean(m[3]) || (op === "==" && n.length < 3) || (op === "!=" && n.length < 3);
|
|
130
|
+
switch (op) {
|
|
131
|
+
case "==": return wild ? prefixOf(v, n) : cmpVer(v, n) === 0;
|
|
132
|
+
case "!=": return wild ? !prefixOf(v, n) : cmpVer(v, n) !== 0;
|
|
133
|
+
case ">=": return cmpVer(v, n) >= 0;
|
|
134
|
+
case ">": return cmpVer(v, n) > 0;
|
|
135
|
+
case "<=": return cmpVer(v, n) <= 0;
|
|
136
|
+
case "<": return cmpVer(v, n) < 0;
|
|
137
|
+
case "^": { let i = n.findIndex((x) => x !== 0); if (i < 0) i = n.length - 1; const up = n.slice(0, i + 1); up[i] += 1; return cmpVer(v, n) >= 0 && cmpVer(v, up) < 0; }
|
|
138
|
+
default: { const up = (op === "~=" ? n.length === 2 : n.length === 1) ? [n[0] + 1] : [n[0], (n[1] ?? 0) + 1]; return cmpVer(v, n) >= 0 && cmpVer(v, up) < 0; } // ~ / ~=
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/** #5590: does version `v` ([major, minor, patch]) satisfy the PEP 440 / poetry range `spec` ("||" alternatives, comma or space joined clauses)? */
|
|
142
|
+
export function pySatisfies(spec, v) {
|
|
143
|
+
return String(spec).split("||").some((grp) => grp.replace(/(\^|~=|~|==|!=|>=|<=|>|<)\s+/g, "$1").split(/[,\s]+/).filter(Boolean).every((c) => clauseOk(c, v)));
|
|
144
|
+
}
|
|
105
145
|
/** Full frozen install on a miss, and the warm no-op repair pass on a hit (null: nothing path-dependent to repair). */
|
|
106
|
-
function commands(d) {
|
|
146
|
+
function commands(d, py = null) {
|
|
147
|
+
const use = py ? [["poetry", ["env", "use", py.cmd]]] : [];
|
|
107
148
|
switch (d.eco) {
|
|
108
149
|
case "pnpm": return { install: [["pnpm", ["install", "--frozen-lockfile"]]], repair: [["pnpm", ["install", "--frozen-lockfile", "--offline"]]] };
|
|
109
150
|
// npm/yarn node_modules hold only relative links; npm's hidden lockfile is rewritten in place, which the read-only
|
|
110
151
|
// snapshot (correctly) refuses, so they get no repair pass.
|
|
111
152
|
case "npm": return { install: [["npm", ["ci", "--no-audit", "--no-fund"]]], repair: null };
|
|
112
153
|
case "yarn": return { install: [["yarn", ["install", d.berry ? "--immutable" : "--frozen-lockfile"]]], repair: null };
|
|
113
|
-
case "uv": return { install: [["uv", ["venv", "--relocatable", ".venv"]], ["uv", ["sync", "--frozen"]]], repair: [["uv", ["sync", "--frozen"]]] };
|
|
114
|
-
case "poetry": return { install: [["poetry", ["install", "--sync"]]], repair: [["poetry", ["install", "--sync"]]] };
|
|
154
|
+
case "uv": return { install: [["uv", ["venv", "--relocatable", ...(py ? ["--python", py.cmd] : []), ".venv"]], ["uv", ["sync", "--frozen"]]], repair: [["uv", ["sync", "--frozen"]]] };
|
|
155
|
+
case "poetry": return { install: [...use, ["poetry", ["install", "--sync"]]], repair: [...use, ["poetry", ["install", "--sync"]]] };
|
|
115
156
|
default: return null;
|
|
116
157
|
}
|
|
117
158
|
}
|
|
@@ -147,10 +188,39 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
147
188
|
return ["package.json"];
|
|
148
189
|
}
|
|
149
190
|
|
|
150
|
-
|
|
191
|
+
/**
|
|
192
|
+
* #5590: for a Python project whose pyproject declares a range the host's default python3 is outside of, the interpreter that
|
|
193
|
+
* does satisfy it ({cmd, version}: pythonX.Y on PATH, then `uv python find`); null keeps the default (no range, default in range, none found).
|
|
194
|
+
*/
|
|
195
|
+
async function pythonFor(wt, d) {
|
|
196
|
+
if (!PY.has(d.eco)) return null;
|
|
197
|
+
let range = null;
|
|
198
|
+
try { range = pyRange(String(fs.readFileSync(join(wt, "pyproject.toml"))), d.eco); } catch { /* no pyproject */ }
|
|
199
|
+
if (!range) return null;
|
|
200
|
+
const probe = async (cmd) => {
|
|
201
|
+
try {
|
|
202
|
+
const version = String(await exec(cmd, ["--version"], { timeoutMs: 30000 })).trim();
|
|
203
|
+
const m = /(\d+)\.(\d+)(?:\.(\d+))?/.exec(version);
|
|
204
|
+
return m ? { cmd, version, v: [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] } : null;
|
|
205
|
+
} catch { return null; }
|
|
206
|
+
};
|
|
207
|
+
const def = await probe("python3");
|
|
208
|
+
if (def && pySatisfies(range, def.v)) return null;
|
|
209
|
+
const minors = [14, 13, 12, 11, 10, 9, 8];
|
|
210
|
+
for (const x of minors) { const c = await probe(`python3.${x}`); if (c && pySatisfies(range, c.v)) return c; }
|
|
211
|
+
for (const x of minors) {
|
|
212
|
+
let path = "";
|
|
213
|
+
try { path = String(await exec("uv", ["python", "find", `3.${x}`], { timeoutMs: 30000 })).trim().split("\n")[0]; } catch { break; } // no uv
|
|
214
|
+
const c = path ? await probe(path) : null;
|
|
215
|
+
if (c && pySatisfies(range, c.v)) return c;
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function keyOf(wt, d, pkgs, py = null) {
|
|
151
221
|
const h = createHash("sha256").update(`v1\0${d.eco}\0${process.platform}-${process.arch}\0`);
|
|
152
222
|
if (d.dir) h.update(`${d.dir}\0`);
|
|
153
|
-
h.update(await runtime(JS.has(d.eco) ? "node" : "python3")).update("\0");
|
|
223
|
+
h.update(py ? py.version : await runtime(JS.has(d.eco) ? "node" : "python3")).update("\0");
|
|
154
224
|
const files = JS.has(d.eco) ? [d.lock, ...pkgs, "pnpm-workspace.yaml", ".npmrc", ".yarnrc.yml"] : [d.lock, "pyproject.toml", ".python-version"];
|
|
155
225
|
for (const f of files) {
|
|
156
226
|
h.update(`${f}\0`);
|
|
@@ -196,6 +266,12 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
196
266
|
fs.chmodSync(dp, fs.statSync(sp).mode & 0o7777);
|
|
197
267
|
}
|
|
198
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Package-manager state at the top of a node_modules tree (pnpm's .modules.yaml, .pnpm/lock.yaml, workspace state; npm's and
|
|
271
|
+
* yarn's hidden lockfiles) that the repair pass rewrites in place (#5574): lanes get a writable copy, never the read-only
|
|
272
|
+
* shared inode, or the open-for-write fails with EACCES and the lane falls back to a full install.
|
|
273
|
+
*/
|
|
274
|
+
const mutableState = (rel, name) => (rel === "" && /^\.(modules\.yaml|pnpm-workspace-state.*\.json|package-lock\.json|yarn-state\.yml)$/.test(name)) || (rel === ".pnpm" && name === "lock.yaml");
|
|
199
275
|
/** Hardlink `src` into `dst` (copy on EXDEV); symlinks recreated; files in bin dirs that name `from` are copied with `to` instead. */
|
|
200
276
|
function linkTree(src, dst, { from = null, to = null, binDir = () => false } = {}) {
|
|
201
277
|
const re = from && to && from !== to ? boundary(from) : null;
|
|
@@ -215,7 +291,10 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
215
291
|
continue;
|
|
216
292
|
}
|
|
217
293
|
}
|
|
218
|
-
|
|
294
|
+
if (mutableState(rel, ent.name)) {
|
|
295
|
+
fs.copyFileSync(sp, dp);
|
|
296
|
+
fs.chmodSync(dp, fs.statSync(sp).mode & 0o7777 | 0o200);
|
|
297
|
+
} else linkOrCopy(sp, dp);
|
|
219
298
|
}
|
|
220
299
|
}
|
|
221
300
|
};
|
|
@@ -234,6 +313,20 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
234
313
|
const binDirFor = (d) => (JS.has(d.eco) ? (rel) => rel.split("/").includes(".bin") : (rel) => rel === "bin");
|
|
235
314
|
const rmTrees = (wt, trees) => { for (const t of trees) { try { fs.rmSync(join(wt, t), { recursive: true, force: true }); } catch { /* best effort */ } } };
|
|
236
315
|
|
|
316
|
+
/** #5590: the existing trees an install did not finish (no marker, a declared dependency missing, a venv without a working python). */
|
|
317
|
+
function brokenTrees(wt, d, trees) {
|
|
318
|
+
return trees.filter((t) => {
|
|
319
|
+
const p = join(wt, t);
|
|
320
|
+
try {
|
|
321
|
+
if (!JS.has(d.eco)) return !fs.existsSync(join(p, "pyvenv.cfg")) || !fs.existsSync(join(p, "bin", "python"));
|
|
322
|
+
if (!JS_MARKERS.some((m) => fs.existsSync(join(p, m)))) return true;
|
|
323
|
+
const pj = JSON.parse(String(fs.readFileSync(join(wt, dirname(t), "package.json"))));
|
|
324
|
+
return Object.keys({ ...pj.dependencies, ...pj.devDependencies }).some((n) => !fs.existsSync(join(p, n)));
|
|
325
|
+
} catch { return true; }
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
const present = (p) => { try { fs.lstatSync(p); return true; } catch { return false; } };
|
|
329
|
+
|
|
237
330
|
function publish(wt, d, key, trees, snap) {
|
|
238
331
|
const tmp = `${snap}.tmp-${pid}`;
|
|
239
332
|
try {
|
|
@@ -255,24 +348,42 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
255
348
|
|
|
256
349
|
async function prepareOne(wt, keyRoot, d, laneEnv) {
|
|
257
350
|
const t0 = now();
|
|
258
|
-
|
|
351
|
+
let repaired = null;
|
|
352
|
+
const done = (status, extra = {}) => ({ status, eco: d.eco, key: extra.key ?? null, ms: now() - t0, reason: extra.reason ?? repaired, ...(extra.published === undefined ? {} : { published: extra.published }) });
|
|
259
353
|
if (d.skip) return done("skipped", { reason: d.skip });
|
|
260
354
|
const pkgs = JS.has(d.eco) ? await manifests(wt) : [];
|
|
261
|
-
const
|
|
355
|
+
const py = await pythonFor(wt, d);
|
|
356
|
+
const key = await keyOf(wt, d, pkgs, py);
|
|
262
357
|
const snap = join(keyRoot, `${d.eco}-${key}`);
|
|
263
|
-
const cmds = commands(d);
|
|
358
|
+
const cmds = commands(d, py);
|
|
264
359
|
const expected = JS.has(d.eco) ? [...new Set(pkgs.map((p) => (dirname(p) === "." ? "node_modules" : `${dirname(p)}/node_modules`)))] : [".venv"];
|
|
265
|
-
const existing = expected.filter((t) =>
|
|
266
|
-
if (existing.length)
|
|
360
|
+
const existing = expected.filter((t) => present(join(wt, t)));
|
|
361
|
+
if (existing.length) {
|
|
362
|
+
const broken = brokenTrees(wt, d, existing);
|
|
363
|
+
if (!broken.length) return done("skipped", { key, reason: `${existing[0]} already exists in the worktree` });
|
|
364
|
+
// #5590: an interrupted or borrowed install is rebuilt, not trusted (the trees go together: a snapshot links all of them).
|
|
365
|
+
rmTrees(wt, existing);
|
|
366
|
+
repaired = `repaired incomplete ${broken[0]}`;
|
|
367
|
+
}
|
|
267
368
|
fs.mkdirSync(keyRoot, { recursive: true, mode: 0o700 });
|
|
268
369
|
|
|
370
|
+
// #5592: `poetry install` fails on a project that is not package-mode (root package not installable): retry once with --no-root (dependencies only).
|
|
371
|
+
const runList = async (list) => {
|
|
372
|
+
for (const [c, a] of list) {
|
|
373
|
+
try { await run(c, a, wt, laneEnv); } catch (e) {
|
|
374
|
+
if (c !== "poetry" || a[0] !== "install" || a.includes("--no-root") || !NO_ROOT_RE.test(`${msg(e)}\n${e?.stderr ?? ""}\n${e?.stdout ?? ""}`)) throw e;
|
|
375
|
+
await run(c, [...a, "--no-root"], wt, laneEnv);
|
|
376
|
+
repaired = repaired ?? "poetry install --no-root (project is not package-mode)";
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
};
|
|
269
380
|
const materialize = async () => {
|
|
270
381
|
let man;
|
|
271
382
|
try { man = JSON.parse(String(fs.readFileSync(join(snap, "manifest.json")))); } catch { return null; }
|
|
272
383
|
const created = [];
|
|
273
384
|
try {
|
|
274
385
|
for (const t of man.trees ?? []) { created.push(t); linkTree(join(snap, t), join(wt, t), { from: man.prefix, to: wt, binDir: binDirFor(d) }); }
|
|
275
|
-
|
|
386
|
+
await runList(cmds.repair ?? []);
|
|
276
387
|
try { fs.writeFileSync(join(snap, "last-used"), String(now())); } catch { /* best effort */ }
|
|
277
388
|
return done("hit", { key });
|
|
278
389
|
} catch (e) {
|
|
@@ -282,7 +393,7 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
282
393
|
}
|
|
283
394
|
};
|
|
284
395
|
const install = async () => {
|
|
285
|
-
try {
|
|
396
|
+
try { await runList(cmds.install); } catch (e) {
|
|
286
397
|
rmTrees(wt, expected);
|
|
287
398
|
return { failed: done("failed", { key, reason: `${e?.code === "ENOENT" ? "tool not found" : "install failed"}: ${msg(e)}` }) };
|
|
288
399
|
}
|
|
@@ -38,7 +38,7 @@ const FIXTURES = {
|
|
|
38
38
|
const LOCKFILE = { pnpm: "pnpm-lock.yaml", npm: "package-lock.json", uv: "uv.lock", poetry: "poetry.lock" };
|
|
39
39
|
|
|
40
40
|
/** Fake package managers: write what a real install leaves behind, including the absolute paths that need rewriting. */
|
|
41
|
-
function fakeExec({ failInstall = false, failRepair = false, installDelayMs = 0 } = {}) {
|
|
41
|
+
function fakeExec({ failInstall = false, failRepair = false, installDelayMs = 0, rewriteState = false, pythons = null } = {}) {
|
|
42
42
|
const calls = [];
|
|
43
43
|
const venv = (cwd, lock) => {
|
|
44
44
|
const v = join(cwd, ".venv");
|
|
@@ -59,6 +59,12 @@ function fakeExec({ failInstall = false, failRepair = false, installDelayMs = 0
|
|
|
59
59
|
walk(cwd);
|
|
60
60
|
return out.join("\0");
|
|
61
61
|
}
|
|
62
|
+
if (pythons && /^python/.test(cmd)) {
|
|
63
|
+
if (args[0] === "--version" && pythons[cmd]) return `Python ${pythons[cmd]}\n`;
|
|
64
|
+
throw Object.assign(new Error(`spawn ${cmd} ENOENT`), { code: "ENOENT" });
|
|
65
|
+
}
|
|
66
|
+
if (cmd === "uv" && args[0] === "python") throw Object.assign(new Error("spawn uv ENOENT"), { code: "ENOENT" });
|
|
67
|
+
if (cmd === "poetry" && args[0] === "env") return "";
|
|
62
68
|
if (args[0] === "--version") return cmd === "node" ? "v22.1.0\n" : "Python 3.12.3\n";
|
|
63
69
|
const full = (cmd === "pnpm" && args.includes("--frozen-lockfile") && !args.includes("--offline")) || (cmd === "npm" && args[0] === "ci")
|
|
64
70
|
|| (cmd === "uv" && args[0] === "venv") || (cmd === "poetry" && !existsSync(join(cwd, ".venv")));
|
|
@@ -69,12 +75,18 @@ function fakeExec({ failInstall = false, failRepair = false, installDelayMs = 0
|
|
|
69
75
|
// pnpm prints its errors on stdout; execFile's error then carries an empty stderr (#4522).
|
|
70
76
|
throw Object.assign(new Error("Command failed: pnpm install --frozen-lockfile --offline"), { stderr: "", stdout: "Lockfile is up to date\n ERR_PNPM_TEST_REPAIR some cause\n" });
|
|
71
77
|
}
|
|
72
|
-
if (args.includes("--offline"))
|
|
78
|
+
if (args.includes("--offline")) {
|
|
79
|
+
// The real repair rewrites its state files in place (#5574); a read-only hardlinked inode fails with EACCES.
|
|
80
|
+
if (rewriteState) for (const f of ["node_modules/.modules.yaml", "node_modules/.pnpm/lock.yaml", "packages/a/node_modules/.modules.yaml"]) if (existsSync(join(cwd, f))) writeFileSync(join(cwd, f), "layoutVersion: 5\nrepaired: true\n");
|
|
81
|
+
return ""; // warm repair pass: nothing else to do
|
|
82
|
+
}
|
|
73
83
|
const lock = readFileSync(join(cwd, "pnpm-lock.yaml"), "utf8");
|
|
74
84
|
put(join(cwd, "node_modules/.pnpm/lodash@4/node_modules/lodash/index.js"), `module.exports = ${JSON.stringify(lock)};\n`);
|
|
75
85
|
symlinkSync(".pnpm/lodash@4/node_modules/lodash", join(cwd, "node_modules/lodash"));
|
|
76
86
|
put(join(cwd, "node_modules/.bin/lodash"), `#!/bin/sh\nexport NODE_PATH="${cwd}/node_modules/.pnpm/node_modules"\nexec node "$basedir/../lodash/cli.js"\n`, 0o755);
|
|
77
87
|
put(join(cwd, "node_modules/.modules.yaml"), "layoutVersion: 5\n");
|
|
88
|
+
put(join(cwd, "node_modules/.pnpm/lock.yaml"), "lockfileVersion: 9\n");
|
|
89
|
+
put(join(cwd, "packages/a/node_modules/.modules.yaml"), "layoutVersion: 5\n");
|
|
78
90
|
mkdirSync(join(cwd, "packages/a/node_modules"), { recursive: true });
|
|
79
91
|
symlinkSync("../../../node_modules/.pnpm/lodash@4/node_modules/lodash", join(cwd, "packages/a/node_modules/lodash"));
|
|
80
92
|
return "";
|
|
@@ -227,6 +239,28 @@ describe("depcache (#4220): shared dependency installs keyed by lock hash", () =
|
|
|
227
239
|
assert.equal(r.published, true, "the stale lock was replaced");
|
|
228
240
|
});
|
|
229
241
|
|
|
242
|
+
it("#5574 state files the repair rewrites in place are writable copies; the snapshot and package files stay read-only", async () => {
|
|
243
|
+
const s = setup("pnpm");
|
|
244
|
+
const f2 = fakeExec({ rewriteState: true });
|
|
245
|
+
const cache = makeDepCache({ root: s.root, exec: f2.exec, env: {}, pollMs: 5 });
|
|
246
|
+
const [ra] = await cache.prepare({ wt: s.lane("a"), repoKey: "r" });
|
|
247
|
+
assert.equal(ra.status, "miss-installed", ra.reason);
|
|
248
|
+
const [snap] = snapDirs(s.root, "pnpm");
|
|
249
|
+
const before = snapshotOf(snap);
|
|
250
|
+
const wt = s.lane("b");
|
|
251
|
+
const [rb] = await cache.prepare({ wt, repoKey: "r" });
|
|
252
|
+
assert.equal(rb.status, "hit", rb.reason);
|
|
253
|
+
for (const f of ["node_modules/.modules.yaml", "node_modules/.pnpm/lock.yaml", "packages/a/node_modules/.modules.yaml"]) {
|
|
254
|
+
assert.match(readFileSync(join(wt, f), "utf8"), /repaired: true/, f);
|
|
255
|
+
assert.notEqual(statSync(join(wt, f)).ino, statSync(join(snap, f)).ino, `${f} is a copy, not the snapshot inode`);
|
|
256
|
+
}
|
|
257
|
+
const after = snapshotOf(snap);
|
|
258
|
+
delete before["last-used"]; delete after["last-used"];
|
|
259
|
+
assert.deepEqual(after, before, "the snapshot is untouched");
|
|
260
|
+
const pkg = join(wt, "node_modules/.pnpm/lodash@4/node_modules/lodash/index.js");
|
|
261
|
+
assert.equal(statSync(pkg).ino, statSync(join(snap, "node_modules/.pnpm/lodash@4/node_modules/lodash/index.js")).ino, "package files stay hardlinks");
|
|
262
|
+
});
|
|
263
|
+
|
|
230
264
|
it("#4522 a snapshot whose repair fails falls back to a fresh install outside the lock, keeps the snapshot and records pnpm's stdout error", async () => {
|
|
231
265
|
const s = setup("pnpm");
|
|
232
266
|
const [ra] = await s.cache.prepare({ wt: s.lane("a"), repoKey: "r" });
|
|
@@ -309,7 +343,7 @@ describe("depcache (#4220): shared dependency installs keyed by lock hash", () =
|
|
|
309
343
|
assert.deepEqual((await s.cache.prepare({ wt: empty, repoKey: "r" })).map((r) => [r.status, r.reason]), [["skipped", "no lockfile"]]);
|
|
310
344
|
const y = join(s.base, "yarn"); put(join(y, "package.json"), "{}"); put(join(y, "yarn.lock"), "# yarn"); put(join(y, ".yarnrc.yml"), "yarnPath: x\n");
|
|
311
345
|
assert.equal((await s.cache.prepare({ wt: y, repoKey: "r" }))[0].status, "skipped");
|
|
312
|
-
const pre = s.lane("pre"); put(join(pre, "node_modules/keep.js"), "mine");
|
|
346
|
+
const pre = s.lane("pre"); put(join(pre, "node_modules/keep.js"), "mine"); put(join(pre, "node_modules/.modules.yaml"), "layoutVersion: 5\n"); // a finished install (#5590)
|
|
313
347
|
const [r] = await s.cache.prepare({ wt: pre, repoKey: "r" });
|
|
314
348
|
assert.equal(r.status, "skipped");
|
|
315
349
|
assert.equal(readFileSync(join(pre, "node_modules/keep.js"), "utf8"), "mine");
|
|
@@ -471,3 +505,87 @@ describe("depcache (#5423): nested JS lockfiles", () => {
|
|
|
471
505
|
assert.equal(r.reason, "no lockfile");
|
|
472
506
|
});
|
|
473
507
|
});
|
|
508
|
+
|
|
509
|
+
describe("depcache (#5590): incomplete installs are repaired, Python follows the project's range", () => {
|
|
510
|
+
it("a truncated node_modules is rebuilt; a complete one is still skipped", async () => {
|
|
511
|
+
const { cache, base, f } = setup("pnpm");
|
|
512
|
+
const wt = join(base, "wt", "trunc");
|
|
513
|
+
mkdirSync(wt, { recursive: true });
|
|
514
|
+
FIXTURES.pnpm(wt);
|
|
515
|
+
put(join(wt, "package.json"), '{"name":"web","devDependencies":{"vitest":"1"}}');
|
|
516
|
+
put(join(wt, "node_modules/.modules.yaml"), "layoutVersion: 5\n"); // marker but vitest never landed
|
|
517
|
+
const [r] = await cache.prepare({ wt, repoKey: "repo-trunc" });
|
|
518
|
+
assert.notEqual(r.status, "skipped", JSON.stringify(r));
|
|
519
|
+
assert.match(r.reason ?? "", /repaired incomplete node_modules/);
|
|
520
|
+
assert.ok(f.installs().length > 0, "a repair pass or install ran");
|
|
521
|
+
assert.ok(existsSync(join(wt, "node_modules/lodash")), "tree rebuilt");
|
|
522
|
+
put(join(wt, "node_modules/vitest/package.json"), "{}");
|
|
523
|
+
const calls = f.installs().length;
|
|
524
|
+
const [r2] = await cache.prepare({ wt, repoKey: "repo-trunc" });
|
|
525
|
+
assert.equal(r2.status, "skipped", JSON.stringify(r2));
|
|
526
|
+
assert.equal(f.installs().length, calls, "a complete tree runs nothing");
|
|
527
|
+
});
|
|
528
|
+
it("a venv with a dangling python is rebuilt", async () => {
|
|
529
|
+
const { cache, base } = setup("poetry");
|
|
530
|
+
const wt = join(base, "wt", "venv");
|
|
531
|
+
mkdirSync(wt, { recursive: true });
|
|
532
|
+
FIXTURES.poetry(wt);
|
|
533
|
+
put(join(wt, ".venv/pyvenv.cfg"), "home = /gone\n");
|
|
534
|
+
mkdirSync(join(wt, ".venv/bin"), { recursive: true });
|
|
535
|
+
symlinkSync("/nonexistent/python3", join(wt, ".venv/bin/python"));
|
|
536
|
+
const [r] = await cache.prepare({ wt, repoKey: "repo-venv" });
|
|
537
|
+
assert.notEqual(r.status, "skipped", JSON.stringify(r));
|
|
538
|
+
assert.ok(existsSync(join(wt, ".venv/bin/python")));
|
|
539
|
+
});
|
|
540
|
+
it("poetry uses the pythonX.Y that satisfies the range, before install, and the key follows it", async () => {
|
|
541
|
+
const pythons = { python3: "3.9.18", "python3.12": "3.12.3" };
|
|
542
|
+
const a = setup("poetry", { pythons }), b = setup("poetry", { pythons: { python3: "3.9.18", "python3.11": "3.11.8" } });
|
|
543
|
+
const res = [];
|
|
544
|
+
for (const s of [a, b]) {
|
|
545
|
+
const wt = s.lane("x");
|
|
546
|
+
put(join(wt, "pyproject.toml"), '[tool.poetry.dependencies]\npython = "^3.11"\n');
|
|
547
|
+
res.push((await s.cache.prepare({ wt, repoKey: "repo-py" }))[0]);
|
|
548
|
+
}
|
|
549
|
+
const cmds = a.f.installs().map((c) => `${c.cmd} ${c.args.join(" ")}`);
|
|
550
|
+
assert.deepEqual(cmds.slice(0, 2), ["poetry env use python3.12", "poetry install --sync"]);
|
|
551
|
+
assert.notEqual(res[0].key, res[1].key, "the chosen interpreter is part of the key");
|
|
552
|
+
});
|
|
553
|
+
it("a default python3 inside the range, or no declared range, changes nothing", async () => {
|
|
554
|
+
const { cache, lane, f } = setup("poetry", { pythons: { python3: "3.12.3" } });
|
|
555
|
+
const wt = lane("in");
|
|
556
|
+
put(join(wt, "pyproject.toml"), '[project]\nrequires-python = ">=3.11,<3.13"\n');
|
|
557
|
+
await cache.prepare({ wt, repoKey: "repo-in" });
|
|
558
|
+
assert.ok(!f.calls.some((c) => c.args[0] === "env"));
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
describe("depcache (#5592 3c): poetry --no-root fallback", () => {
|
|
563
|
+
it("a poetry install that cannot install the root package is retried with --no-root", async () => {
|
|
564
|
+
const f = fakeExec();
|
|
565
|
+
const tried = [];
|
|
566
|
+
const exec = async (cmd, args, o) => {
|
|
567
|
+
if (cmd === "poetry" && args[0] === "install") {
|
|
568
|
+
tried.push(args.join(" "));
|
|
569
|
+
if (!args.includes("--no-root")) throw Object.assign(new Error("failed"), { stderr: "Error: The current project could not be installed: No file/folder found for package proj\nIf you do not want to install the current project use --no-root." });
|
|
570
|
+
}
|
|
571
|
+
return f.exec(cmd, args, o);
|
|
572
|
+
};
|
|
573
|
+
const base = scratch(), wt = join(base, "wt"); mkdirSync(wt, { recursive: true }); FIXTURES.poetry(wt);
|
|
574
|
+
const cache = makeDepCache({ root: join(base, "cache"), exec, env: {}, pollMs: 5 });
|
|
575
|
+
const [r] = await cache.prepare({ wt, repoKey: "repo-noroot" });
|
|
576
|
+
assert.equal(r.status, "miss-installed", JSON.stringify(r));
|
|
577
|
+
assert.deepEqual(tried, ["install --sync", "install --sync --no-root"]);
|
|
578
|
+
});
|
|
579
|
+
it("an unrelated poetry failure is not retried", async () => {
|
|
580
|
+
const tried = [];
|
|
581
|
+
const exec = async (cmd, args) => {
|
|
582
|
+
if (cmd === "poetry" && args[0] === "install") { tried.push(args.join(" ")); throw Object.assign(new Error("failed"), { stderr: "SolverProblemError: no matching version" }); }
|
|
583
|
+
if (args[0] === "--version") return "Python 3.12.3\n";
|
|
584
|
+
return "";
|
|
585
|
+
};
|
|
586
|
+
const base = scratch(), wt = join(base, "wt"); mkdirSync(wt, { recursive: true }); FIXTURES.poetry(wt);
|
|
587
|
+
const [r] = await makeDepCache({ root: join(base, "cache"), exec, env: {}, pollMs: 5 }).prepare({ wt, repoKey: "repo-noroot2" });
|
|
588
|
+
assert.equal(r.status, "failed");
|
|
589
|
+
assert.deepEqual(tried, ["install --sync"]);
|
|
590
|
+
});
|
|
591
|
+
});
|