forgedock 1.54.0 → 1.54.1
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/auth/app-token.mjs +2 -0
- package/bin/auth/app-token.test.mjs +9 -1
- package/bin/forgedock.mjs +2 -2
- package/bin/lean/mechfix.mjs +15 -3
- package/bin/lean/mechfix.test.mjs +20 -0
- package/bin/lean/release.mjs +7 -1
- package/bin/lean/release.test.mjs +9 -0
- package/bin/runner.mjs +6 -1
- package/docs/CI.md +1 -1
- package/package.json +1 -1
package/bin/auth/app-token.mjs
CHANGED
|
@@ -16,6 +16,8 @@ import { homedir } from "node:os";
|
|
|
16
16
|
import { PIPELINE_PERMISSIONS, API, mintInstallationToken, findInstallation, buildAppManifest, convertManifestCode, receiveManifestCode } from "./app-manifest.mjs";
|
|
17
17
|
|
|
18
18
|
export const REFRESH_BEFORE_MS = 10 * 60 * 1000;
|
|
19
|
+
// Commands that run long enough to outlive an installation token (1h, adopted with as little as REFRESH_BEFORE_MS left): they start startAuthRefresh.
|
|
20
|
+
export const AUTH_REFRESH_COMMANDS = new Set(["orchestrate", "schedd", "watch", "issue-watch", "prod-watch", "run-issue", "resume-stalled", "run", "bootstrap", "release"]);
|
|
19
21
|
const UA = { "User-Agent": "forgedock", Accept: "application/json", "Content-Type": "application/json" };
|
|
20
22
|
|
|
21
23
|
const homeDir = (env) => env.FORGE_HOME_DIR || join(homedir(), ".forge");
|
|
@@ -5,7 +5,7 @@ import assert from "node:assert/strict";
|
|
|
5
5
|
import { statSync, existsSync, readFileSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
8
|
-
import { resolveAuth, applyAuthEnv, startAuthRefresh, writeState, readState, statePath, deviceFlowLogin, mintViaBroker, assertSecureBroker, authFromCli, doctorAppAuth, clearState } from "./app-token.mjs";
|
|
8
|
+
import { resolveAuth, applyAuthEnv, startAuthRefresh, writeState, readState, statePath, deviceFlowLogin, mintViaBroker, assertSecureBroker, authFromCli, doctorAppAuth, clearState, AUTH_REFRESH_COMMANDS } from "./app-token.mjs";
|
|
9
9
|
|
|
10
10
|
const mkEnv = (extra = {}) => ({ FORGE_HOME_DIR: tmpDir("app-auth-"), ...extra });
|
|
11
11
|
const NOW = Date.parse("2026-01-01T00:00:00Z");
|
|
@@ -230,3 +230,11 @@ test("an inherited App token whose login was removed is dropped with its marker
|
|
|
230
230
|
assert.equal(out.fp, null);
|
|
231
231
|
assert.equal(out.timers, 0);
|
|
232
232
|
});
|
|
233
|
+
|
|
234
|
+
// Long-running lane commands must refresh the App token they adopt, or lanes past expiry 401.
|
|
235
|
+
test("AUTH_REFRESH_COMMANDS covers lane commands and the CLI uses it instead of an inline list", () => {
|
|
236
|
+
for (const c of ["orchestrate", "schedd", "watch", "issue-watch", "prod-watch", "run-issue", "resume-stalled", "run", "bootstrap", "release"]) assert.ok(AUTH_REFRESH_COMMANDS.has(c), c);
|
|
237
|
+
for (const c of ["auth", "gc", "doctor"]) assert.ok(!AUTH_REFRESH_COMMANDS.has(c), c);
|
|
238
|
+
const src = readFileSync(new URL("../forgedock.mjs", import.meta.url), "utf8");
|
|
239
|
+
assert.match(src, /AUTH_REFRESH_COMMANDS\.has\(command\)\) startAuthRefresh\(\)/);
|
|
240
|
+
});
|
package/bin/forgedock.mjs
CHANGED
|
@@ -93,7 +93,7 @@ import { checkContext, refreshContextFlow } from "./review-context.mjs";
|
|
|
93
93
|
import { runConfigCommand } from "./config-history.mjs";
|
|
94
94
|
import { validateForgeYaml } from "./config-schema.mjs";
|
|
95
95
|
import { botTokenStatus } from "./bot-token-status.mjs";
|
|
96
|
-
import { applyAuthEnv, startAuthRefresh, doctorAppAuth } from "./auth/app-token.mjs";
|
|
96
|
+
import { applyAuthEnv, startAuthRefresh, doctorAppAuth, AUTH_REFRESH_COMMANDS } from "./auth/app-token.mjs";
|
|
97
97
|
import {
|
|
98
98
|
parseNameStatusDiff,
|
|
99
99
|
classifyCommandChanges,
|
|
@@ -3929,7 +3929,7 @@ let exitCode = 0;
|
|
|
3929
3929
|
// #5301: an App login puts a scoped installation token in this process's env (GH_TOKEN) for child gh calls; no login, no change.
|
|
3930
3930
|
if (command !== "auth") await applyAuthEnv();
|
|
3931
3931
|
// #5381: installation tokens live 1h; long-running commands re-resolve before expiry so later gh calls and lanes inherit a fresh one.
|
|
3932
|
-
if (
|
|
3932
|
+
if (AUTH_REFRESH_COMMANDS.has(command)) startAuthRefresh();
|
|
3933
3933
|
switch (command) {
|
|
3934
3934
|
case "install": {
|
|
3935
3935
|
const c = ctx();
|
package/bin/lean/mechfix.mjs
CHANGED
|
@@ -69,14 +69,16 @@ export function applyEnumerating({ missing = [], cwd, fsx = fs } = {}) {
|
|
|
69
69
|
const groups = new Map();
|
|
70
70
|
for (const m of rows) { const k = `${m.line}\0${m.module}`; if (!groups.has(k)) groups.set(k, []); groups.get(k).push(m); }
|
|
71
71
|
let changed = false;
|
|
72
|
+
const mine = []; // this test's applied rows: a failed write moves only these, never another test's
|
|
72
73
|
// bottom-up: an insertion only shifts the lines below it, so the detector's line numbers stay valid
|
|
73
74
|
for (const g of [...groups.values()].sort((a, b) => b[0].line - a[0].line)) {
|
|
74
75
|
const r = insertIntoList(text, g[0].line, g.map((m) => m.symbol));
|
|
75
76
|
const done = new Set(r.inserted);
|
|
76
|
-
for (const m of g) (done.has(m.symbol) ?
|
|
77
|
+
for (const m of g) (done.has(m.symbol) ? mine : remaining).push(m);
|
|
77
78
|
if (r.inserted.length) { text = r.text; changed = true; }
|
|
78
79
|
}
|
|
79
|
-
if (changed) { try { fsx.writeFileSync(join(cwd, test), text); } catch {
|
|
80
|
+
if (changed) { try { fsx.writeFileSync(join(cwd, test), text); } catch { remaining.push(...mine); continue; } }
|
|
81
|
+
applied.push(...mine);
|
|
80
82
|
}
|
|
81
83
|
return { applied, remaining };
|
|
82
84
|
}
|
|
@@ -96,6 +98,12 @@ export function renamedExport(symbol, path) {
|
|
|
96
98
|
|
|
97
99
|
const word = (s) => new RegExp(`(?<![\\w$])${s.replace(/[\\$]/g, "\\$&")}(?![\\w$])`, "g");
|
|
98
100
|
|
|
101
|
+
/** True when `text` binds `name` from another module (ES import / `export {..} from`, python from-import): such a file references the lane's export, it does not merely declare its own. */
|
|
102
|
+
function importsName(text, name) {
|
|
103
|
+
const clauses = [...text.matchAll(/^\s*(?:import|export)\s+(?:type\s+)?([^;"'`]*?)\s*from\s*["'][^"']*["']/gm), ...text.matchAll(/^\s*from\s+\S+\s+import\s+(.*)$/gm)];
|
|
104
|
+
return clauses.some((m) => word(name).test(m[1]));
|
|
105
|
+
}
|
|
106
|
+
|
|
99
107
|
/**
|
|
100
108
|
* Duplicate exports: rename the lane's new export to `<AppPrefix><Symbol>` when the name occurs only in its declaring file and the
|
|
101
109
|
* other files that declare it themselves (`others`; so no importer, registry or test keyed by the name can be left behind) and never as a property, string or label.
|
|
@@ -110,7 +118,11 @@ export async function renameDuplicates({ dups = [], cwd, git, fsx = fs } = {}) {
|
|
|
110
118
|
const next = renamedExport(d.symbol, d.path);
|
|
111
119
|
if (!next || next === d.symbol || (await grep(next)).length) { remaining.push(d); continue; }
|
|
112
120
|
const files = await grep(d.symbol);
|
|
113
|
-
const
|
|
121
|
+
const others = d.others ?? [];
|
|
122
|
+
const reads = (f) => { try { return fsx.readFileSync(join(cwd, f), "utf8"); } catch { return null; } };
|
|
123
|
+
// the detector's others declare the name themselves, so they cannot import ours; a barrel (import then export) is listed as a declarer but does import it
|
|
124
|
+
if (others.some((f) => { const t = reads(f); return t === null || importsName(t, d.symbol); })) { remaining.push(d); continue; }
|
|
125
|
+
const ours = new Set([d.path, ...others]);
|
|
114
126
|
if (!files.includes(d.path) || files.some((f) => !ours.has(f))) { remaining.push(d); continue; }
|
|
115
127
|
const text = fsx.readFileSync(join(cwd, d.path), "utf8");
|
|
116
128
|
const re = word(d.symbol);
|
|
@@ -38,6 +38,20 @@ describe("#5348 enumerating list insertion", () => {
|
|
|
38
38
|
assert.deepEqual(r.remaining.map((m) => m.symbol), ["gone"]);
|
|
39
39
|
assert.equal(fs.readFileSync(join(cwd, "a.test.mjs"), "utf8"), `const L = ["one", "two", "three", "four"];\nconst M = ["x1", "x2", "x3", "x4"];\n`);
|
|
40
40
|
});
|
|
41
|
+
it("a failed write moves only that test's rows to remaining, not another test's applied rows", () => {
|
|
42
|
+
const cwd = tmp();
|
|
43
|
+
fs.writeFileSync(join(cwd, "a.test.mjs"), `const L = ["one", "two", "three"];\n`);
|
|
44
|
+
fs.writeFileSync(join(cwd, "b.test.mjs"), `const M = ["x1", "x2", "x3"];\nconst N = [a, b];\n`);
|
|
45
|
+
const missing = [
|
|
46
|
+
{ symbol: "four", module: "m", test: "a.test.mjs", line: 1 },
|
|
47
|
+
{ symbol: "x4", module: "n", test: "b.test.mjs", line: 1 },
|
|
48
|
+
{ symbol: "nope", module: "o", test: "b.test.mjs", line: 2 },
|
|
49
|
+
];
|
|
50
|
+
const fsx = { ...fs, writeFileSync: (f, t) => { if (String(f).endsWith("b.test.mjs")) throw new Error("EROFS"); return fs.writeFileSync(f, t); } };
|
|
51
|
+
const r = applyEnumerating({ missing, cwd, fsx });
|
|
52
|
+
assert.deepEqual(r.applied.map((m) => m.symbol), ["four"]);
|
|
53
|
+
assert.deepEqual(r.remaining.map((m) => m.symbol).sort(), ["nope", "x4"]);
|
|
54
|
+
});
|
|
41
55
|
});
|
|
42
56
|
|
|
43
57
|
describe("#5348 duplicate export rename", () => {
|
|
@@ -63,6 +77,12 @@ describe("#5348 duplicate export rename", () => {
|
|
|
63
77
|
assert.equal(fs.readFileSync(join(cwd, "app/ui.ts"), "utf8"), `export const UiButton = 1;\nexport const y = UiButton + 1;\n`);
|
|
64
78
|
assert.equal(fs.readFileSync(join(cwd, "app/other.ts"), "utf8"), `export const Button = 2;\n`);
|
|
65
79
|
});
|
|
80
|
+
it("leaves it for a session when a detector other is a barrel that imports the name", async () => {
|
|
81
|
+
const w = world({ "app/ui.ts": `export const Button = 1;\n`, "app/index.ts": `import { Button } from "./ui";\nexport { Button };\n` });
|
|
82
|
+
const r = await renameDuplicates({ dups: [{ symbol: "Button", path: "app/ui.ts", others: ["app/index.ts"] }], cwd: w.cwd, git: w.git });
|
|
83
|
+
assert.equal(r.applied.length, 0); assert.equal(r.remaining.length, 1);
|
|
84
|
+
assert.equal(fs.readFileSync(join(w.cwd, "app/ui.ts"), "utf8"), `export const Button = 1;\n`);
|
|
85
|
+
});
|
|
66
86
|
it("leaves it for a session when another file references the name, or it is used as a property", async () => {
|
|
67
87
|
let w = world({ "app/ui.ts": `export const Button = 1;\n`, "app/use.ts": `import { Button } from "./ui";\n` });
|
|
68
88
|
let r = await renameDuplicates({ dups: [{ symbol: "Button", path: "app/ui.ts", others: ["app/other.ts"] }], cwd: w.cwd, git: w.git });
|
package/bin/lean/release.mjs
CHANGED
|
@@ -152,7 +152,13 @@ export async function gateState({ io, repo, pr, head }) {
|
|
|
152
152
|
let marker = null;
|
|
153
153
|
for (const b of bodies) { if (b.includes("FORGE:GATE_PASS")) marker = "pass"; else if (b.includes("FORGE:GATE_FAILURE")) marker = "failure"; }
|
|
154
154
|
const checks = json(await io.gh(["api", `repos/${repo}/commits/${head}/check-runs`, "--jq", "[.check_runs[] | {name, conclusion}]"])) ?? [];
|
|
155
|
-
|
|
155
|
+
let gate = checks.find((c) => c.name === "forge/deploy-gate");
|
|
156
|
+
// gate-marker-check.yml posts forge/deploy-gate as a commit STATUS (POST /statuses), not a check run: read the
|
|
157
|
+
// combined status too, or promotion never sees the gate it waits for.
|
|
158
|
+
if (!gate) {
|
|
159
|
+
const statuses = json(await io.gh(["api", `repos/${repo}/commits/${head}/status`, "--jq", "[.statuses[] | {name: .context, conclusion: .state}]"])) ?? [];
|
|
160
|
+
gate = statuses.find((c) => c.name === "forge/deploy-gate");
|
|
161
|
+
}
|
|
156
162
|
return { marker, deployGate: gate?.conclusion ?? null };
|
|
157
163
|
}
|
|
158
164
|
|
|
@@ -34,6 +34,7 @@ function fakeIo(world = {}) {
|
|
|
34
34
|
if (a[0] === "pr" && a[1] === "view" && j.includes("--json state,mergeCommit,headRefOid")) return JSON.stringify({ state: w.prState ?? "OPEN", mergeCommit: w.prState === "MERGED" ? { oid: "m".repeat(40) } : null, headRefOid: HEAD });
|
|
35
35
|
if (j.includes("--json headRefOid")) return JSON.stringify({ headRefOid: HEAD });
|
|
36
36
|
if (j.includes("--json comments")) return JSON.stringify({ comments: w.comments });
|
|
37
|
+
if (a[0] === "api" && /\/commits\/[^/]+\/status$/.test(a[1])) return JSON.stringify(w.statusGate ? [{ name: "forge/deploy-gate", conclusion: w.statusGate }] : []);
|
|
37
38
|
if (a[0] === "api") return JSON.stringify(w.gate ? [{ name: "forge/deploy-gate", conclusion: w.gate }] : []);
|
|
38
39
|
if (a[0] === "pr" && a[1] === "merge") return "";
|
|
39
40
|
throw new Error(`unexpected gh ${j}`);
|
|
@@ -75,6 +76,14 @@ describe("release job (#5211)", () => {
|
|
|
75
76
|
}
|
|
76
77
|
});
|
|
77
78
|
|
|
79
|
+
it("forge/deploy-gate posted as a commit status (gate-marker-check.yml) counts: no check run, status success -> merges", async () => {
|
|
80
|
+
const ok = await promote({ gate: null, statusGate: "success" }, { opts: { merge: true } });
|
|
81
|
+
assert.equal(ok.out.status, "done");
|
|
82
|
+
assert.ok(ok.io.calls.some((a) => a[1] === "merge" && a.includes("--match-head-commit")));
|
|
83
|
+
const pend = await promote({ gate: null, statusGate: "pending" }, { opts: { merge: true } });
|
|
84
|
+
assert.equal(pend.out.status, "stopped");
|
|
85
|
+
});
|
|
86
|
+
|
|
78
87
|
it("#5266: a release PR merged by hand moves to post-merge with the merge sha, without the opt-in stop", async () => {
|
|
79
88
|
const io = fakeIo({ prState: "MERGED" }), root = tmp(), id = newReleaseId();
|
|
80
89
|
const mod = await import("./release.mjs");
|
package/bin/runner.mjs
CHANGED
|
@@ -1564,8 +1564,13 @@ export const CLI_ARGV_PROMPT_MAX_BYTES = 64 * 1024;
|
|
|
1564
1564
|
*/
|
|
1565
1565
|
export const CLI_ARGV_PROMPT_MAX_BYTES_WIN32 = 16 * 1024;
|
|
1566
1566
|
|
|
1567
|
-
/**
|
|
1567
|
+
/**
|
|
1568
|
+
* forge#4763: true when the prompt must go over stdin: prompt bytes plus the other argv bytes exceed the platform bound.
|
|
1569
|
+
* Also when the prompt starts with `-` (e.g. a brief opening with `---` front matter): as an argv word the CLI would
|
|
1570
|
+
* parse it as an option and exit 1 ("unknown option '---'").
|
|
1571
|
+
*/
|
|
1568
1572
|
export function promptGoesViaStdin(prompt, otherArgs = [], platform = process.platform) {
|
|
1573
|
+
if (/^\s*-/.test(String(prompt ?? ""))) return true;
|
|
1569
1574
|
const max = platform === "win32" ? CLI_ARGV_PROMPT_MAX_BYTES_WIN32 : CLI_ARGV_PROMPT_MAX_BYTES;
|
|
1570
1575
|
const rest = platform === "win32" ? otherArgs.reduce((n, a) => n + Buffer.byteLength(String(a), "utf-8") + 1, 0) : 0;
|
|
1571
1576
|
return Buffer.byteLength(String(prompt ?? ""), "utf-8") + rest > max;
|
package/docs/CI.md
CHANGED
|
@@ -65,7 +65,7 @@ A pass counts only when it is the review's final verdict (`FORGE:GATE_PASS:TYPE=
|
|
|
65
65
|
|
|
66
66
|
A posted marker re-runs the check, so the status follows the review. The workflow's own job check is not the gate. It stays green while a review runs, so the staging review's CI read is not blocked by the gate it is about to satisfy.
|
|
67
67
|
|
|
68
|
-
The status blocks nothing until main requires it. In **Settings → Rules → Rulesets** (or branch protection for `main`), add `forge/deploy-gate` as a required status check. GitHub then refuses to merge a staging→main PR that has no passing review on record, including a merge by hand.
|
|
68
|
+
The status blocks nothing until main requires it. In **Settings → Rules → Rulesets** (or branch protection for `main`), add `forge/deploy-gate` as a required status check. GitHub then refuses to merge a staging→main PR that has no passing review on record, including a merge by hand. The gate covers `staging`, `feature` and `release/<id>` (snapshot release) heads into `main`.
|
|
69
69
|
|
|
70
70
|
### 2. Copy the workflow template
|
|
71
71
|
|