looply-cli 0.5.34 → 0.5.36

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.
Files changed (43) hide show
  1. package/dist/.src-hash +1 -1
  2. package/dist/bin.d.ts.map +1 -1
  3. package/dist/bin.js +19 -0
  4. package/dist/bin.js.map +1 -1
  5. package/dist/branch-delivery-wiring.d.ts.map +1 -1
  6. package/dist/branch-delivery-wiring.js +1 -0
  7. package/dist/branch-delivery-wiring.js.map +1 -1
  8. package/dist/branch-delivery.d.ts +23 -0
  9. package/dist/branch-delivery.d.ts.map +1 -1
  10. package/dist/branch-delivery.js +159 -9
  11. package/dist/branch-delivery.js.map +1 -1
  12. package/dist/checkout-leftovers.d.ts +40 -0
  13. package/dist/checkout-leftovers.d.ts.map +1 -0
  14. package/dist/checkout-leftovers.js +55 -0
  15. package/dist/checkout-leftovers.js.map +1 -0
  16. package/dist/gate-draft.d.ts +9 -0
  17. package/dist/gate-draft.d.ts.map +1 -1
  18. package/dist/gate-draft.js +37 -0
  19. package/dist/gate-draft.js.map +1 -1
  20. package/dist/gate-health.d.ts +32 -1
  21. package/dist/gate-health.d.ts.map +1 -1
  22. package/dist/gate-health.js +155 -48
  23. package/dist/gate-health.js.map +1 -1
  24. package/dist/gate-tidy.d.ts +69 -0
  25. package/dist/gate-tidy.d.ts.map +1 -0
  26. package/dist/gate-tidy.js +98 -0
  27. package/dist/gate-tidy.js.map +1 -0
  28. package/dist/git-driver.d.ts +5 -0
  29. package/dist/git-driver.d.ts.map +1 -1
  30. package/dist/git-driver.js +9 -0
  31. package/dist/git-driver.js.map +1 -1
  32. package/dist/integration-deps.d.ts.map +1 -1
  33. package/dist/integration-deps.js.map +1 -1
  34. package/dist/round-runner.d.ts.map +1 -1
  35. package/dist/round-runner.js +2 -1
  36. package/dist/round-runner.js.map +1 -1
  37. package/dist/run-cmd.d.ts.map +1 -1
  38. package/dist/run-cmd.js +22 -5
  39. package/dist/run-cmd.js.map +1 -1
  40. package/dist/verify-pass.d.ts.map +1 -1
  41. package/dist/verify-pass.js +2 -1
  42. package/dist/verify-pass.js.map +1 -1
  43. package/package.json +2 -2
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FOLLOW_DEPLOYS_MS = exports.NO_CHECKS_GRACE_MS = exports.CHECKS_PATIENCE_MS = exports.BRANCH_DELIVERIES_FILE = void 0;
3
+ exports.MAX_LOGIN_RETRIES = exports.FAILED_RECHECK_MS = exports.FOLLOW_DEPLOYS_MS = exports.NO_CHECKS_GRACE_MS = exports.CHECKS_PATIENCE_MS = exports.BRANCH_DELIVERIES_FILE = void 0;
4
4
  exports.nodeDeliveryGit = nodeDeliveryGit;
5
5
  exports.makeDeployPush = makeDeployPush;
6
+ exports.makeDeployTip = makeDeployTip;
6
7
  exports.ciBaseReport = ciBaseReport;
7
8
  exports.fileDeliveryStore = fileDeliveryStore;
8
9
  exports.memoryDeliveryStore = memoryDeliveryStore;
@@ -23,6 +24,8 @@ exports.redOnBase = redOnBase;
23
24
  exports.redBaseNote = redBaseNote;
24
25
  exports.advanceDeliveries = advanceDeliveries;
25
26
  exports.noNewCommits = noNewCommits;
27
+ exports.herokuLoginSentence = herokuLoginSentence;
28
+ exports.herokuAuthRefusal = herokuAuthRefusal;
26
29
  exports.makeReleaseRunner = makeReleaseRunner;
27
30
  const node_child_process_1 = require("node:child_process");
28
31
  const node_fs_1 = require("node:fs");
@@ -203,6 +206,11 @@ function makeDeployPush(cwd, rawExec = (0, git_driver_1.nodeGitExec)(cwd)) {
203
206
  ${r.stdout}`.trim()).slice(0, 400) || `git push exited ${r.code}` };
204
207
  };
205
208
  }
209
+ /** The read-only half of the push deploy: is the commit already on the deploy branch? (`AdvanceDeps.deployTip`). */
210
+ function makeDeployTip(cwd, rawExec = (0, git_driver_1.nodeGitExec)(cwd)) {
211
+ const exec = (args) => rawExec(['-c', 'credential.interactive=never', ...args]);
212
+ return (remote, branch, sha) => deployTipContaining(exec, remote, branch, sha).catch(() => null);
213
+ }
206
214
  /**
207
215
  * 🔴 ALREADY THERE: the deploy branch's tip, when it IS or CONTAINS the commit — else null. An older
208
216
  * commit (a pull request merged by hand, whose head a later deploy already carries) is never pushed
@@ -464,7 +472,7 @@ function pullBody(input) {
464
472
  ? 'Looply merges this once the required CI checks are green.'
465
473
  : input.mode === 'test'
466
474
  ? "ship to test: Looply merges this once the required CI checks are green (or, when the repository has no CI, once its own checks above passed), then deploys the test environment only. Other environments are deployed only when a person promotes it."
467
- : "Looply merges this once the required CI checks are green, then runs the project's declared release step."}${input.modeCapped ? ` (${input.modeCapped}.)` : ''}`,
475
+ : "Looply merges this once the required CI checks are green (or, when the repository has no CI, once its own checks above passed), then runs the project's declared release step."}${input.modeCapped ? ` (${input.modeCapped}.)` : ''}`,
468
476
  ];
469
477
  if (input.maintenance)
470
478
  lines.push('', ...maintenanceSection(input.maintenance));
@@ -969,6 +977,19 @@ function redBaseNote(r, held) {
969
977
  }
970
978
  /** How a pull request parked only because no CI reports on it begins its note (re-examined under ship to test). */
971
979
  const NO_CI_NOTE = 'not merged: no CI checks report on this pull request';
980
+ /**
981
+ * Modes in which Looply's OWN gates for the delivered commit stand in for CI a repository does not have.
982
+ *
983
+ * 🔴 SHIP AUTOMATICALLY TRUSTED LESS THAN SHIP TO TEST (Tabsy, 2026-10-21/22). Tabsy's CI does not run
984
+ * on admin-only changes, so its pull requests report no checks at all. Under ship to test Looply's own
985
+ * gates were the check; under "ship automatically" (`deploy`) — the setting a person picks to have the
986
+ * work merged AND deployed with nobody in between — the same pull requests were handed to a person
987
+ * (TAB-B-78/79, #21–#23, a day each), and only "Approve and ship" moved one. The person who chose
988
+ * `deploy` already said Looply's checks are enough to ship to every environment; the stronger mode
989
+ * now trusts them at least as far as the weaker one. A red check, a moved head or a rebuild still
990
+ * goes to a person, as before.
991
+ */
992
+ const OWN_GATES_STAND_IN = ['test', 'deploy'];
972
993
  /**
973
994
  * States a pass may move on. `pr-open` and `checks-failed` move only on a person's approval.
974
995
  * `blocked` is re-examined on every pass: it unblocks by itself once the other goals' work it
@@ -991,8 +1012,9 @@ async function advanceDeliveries(deps) {
991
1012
  for (const e of deps.store.all()) {
992
1013
  if (!ADVANCING.includes(e.state))
993
1014
  continue;
994
- // A finished one is looked at again only for a promote it has not acted on yet.
995
- if (e.done === true && !(MERGED.includes(e.state) && pendingPromotes(deps, e).length > 0))
1015
+ // A finished one is looked at again for a promote it has not acted on yet — and, while its deploy
1016
+ // failed and it is inside the follow window, to see whether it is live after all (`recheckFailed`).
1017
+ if (e.done === true && !(MERGED.includes(e.state) && pendingPromotes(deps, e).length > 0) && !failedRecheckDue(deps, e))
996
1018
  continue;
997
1019
  try {
998
1020
  await advanceOne(deps, e);
@@ -1131,7 +1153,7 @@ async function advanceOne(deps, e) {
1131
1153
  * gates hold for its head (a rule that changed since, e.g. a `when:`-skipped gate, TAB-B-61).
1132
1154
  * Anything else that parked it — red CI, a different head, a rebuild — stays with a person.
1133
1155
  */
1134
- e.state === 'pr-open' && mode === 'test' && !approved && e.note !== null && e.note.startsWith(NO_CI_NOTE) &&
1156
+ e.state === 'pr-open' && OWN_GATES_STAND_IN.includes(mode) && !approved && e.note !== null && e.note.startsWith(NO_CI_NOTE) &&
1135
1157
  gatesPassed(e.checks) && (pull.headSha === '' || pull.headSha === e.sha) && !e.rebuiltFrom) {
1136
1158
  e = { ...e, state: 'waiting-checks', note: 'its own checks hold; merging once the checks allow', updatedAt: at };
1137
1159
  await save(deps, e);
@@ -1254,7 +1276,7 @@ async function advanceOne(deps, e) {
1254
1276
  if (verdict.kind === 'none' && !approved) {
1255
1277
  // The gates ran on the delivered commit: a head that moved, or a `-solo` rebuild, is not what they judged.
1256
1278
  const sameCommit = (pull.headSha === '' || pull.headSha === e.sha) && !e.rebuiltFrom;
1257
- const gatesHold = mode === 'test' && gatesPassed(e.checks) && sameCommit;
1279
+ const gatesHold = OWN_GATES_STAND_IN.includes(mode) && gatesPassed(e.checks) && sameCommit;
1258
1280
  if (age < exports.NO_CHECKS_GRACE_MS) {
1259
1281
  /**
1260
1282
  * SAY WHAT WILL HAPPEN, NOT "WAITING FOR CI". Under ship to test with Looply's own checks
@@ -1266,7 +1288,7 @@ async function advanceOne(deps, e) {
1266
1288
  return;
1267
1289
  }
1268
1290
  if (!gatesHold) {
1269
- const why = mode === 'test'
1291
+ const why = OWN_GATES_STAND_IN.includes(mode)
1270
1292
  ? `${NO_CI_NOTE}, and ${sameCommit ? "Looply's own checks for it did not all pass" : "Looply's own checks ran on a different commit than its head"}, so a person merges it`
1271
1293
  : `${NO_CI_NOTE}, so a person merges it`;
1272
1294
  await save(deps, { ...e, state: 'pr-open', note: why, updatedAt: at });
@@ -1421,6 +1443,7 @@ async function followDeploys(deps, api, e, wantsDeploy, mode) {
1421
1443
  x = { ...x, environments: (x.environments ?? []).map((row) => fromGitHub(row, plans, found)) };
1422
1444
  }
1423
1445
  x = await laterDeploys(deps, api, x, plans, sha, base, at, asked);
1446
+ x = await recheckFailed(deps, x, plans, sha, base, at, asked);
1424
1447
  }
1425
1448
  const rows = x.environments ?? [];
1426
1449
  const settled = rows.every((r) => r.state === 'deployed' || r.state === 'failed');
@@ -1432,6 +1455,11 @@ async function followDeploys(deps, api, e, wantsDeploy, mode) {
1432
1455
  ? null
1433
1456
  : `${expired && !settled ? 'after 14 days, ' : ''}${open.map((r) => `${r.name}: ${r.detail ?? r.state}`).join('; ')}`.slice(0, 600);
1434
1457
  x = { ...x, state, note, ...(settled || expired ? { done: true } : {}) };
1458
+ // A failed deploy tried again (`recheckFailed`) is followed again until it settles.
1459
+ if (!settled && !expired && x.done === true) {
1460
+ const { done: _done, ...following } = x;
1461
+ x = following;
1462
+ }
1435
1463
  const same = JSON.stringify({ ...x, updatedAt: '' }) === JSON.stringify({ ...e, updatedAt: '' });
1436
1464
  if (!same)
1437
1465
  await save(deps, { ...x, updatedAt: at });
@@ -1531,12 +1559,16 @@ async function deployOne(deps, e, p, sha, at, asked) {
1531
1559
  if (!who.ok)
1532
1560
  return row('failed', `not pushed: could not tell which account the Heroku CLI is signed in as (${who.because})`);
1533
1561
  if (who.account.toLowerCase() !== d.herokuAccount.toLowerCase())
1534
- return row('failed', `not pushed: Heroku CLI is signed in as ${who.account}, not ${d.herokuAccount}`);
1562
+ return row('failed', herokuLoginSentence(who.account, d.herokuApp ?? d.remote, d.herokuAccount));
1535
1563
  }
1536
1564
  deps.log(`deliver : deploying ${sha.slice(0, 12)} to ${d.remote} ${d.branch} (${p.name})`);
1537
1565
  const r = await deps.deployPush(d.remote, d.branch, sha, base);
1538
- if (!r.ok)
1566
+ if (!r.ok) {
1567
+ const refused = herokuAuthRefusal(r.because);
1568
+ if (refused !== null)
1569
+ return row('failed', herokuLoginSentence(refused.account, refused.app ?? d.herokuApp ?? d.remote, d.herokuAccount));
1539
1570
  return row('failed', `pushing to ${d.remote} ${d.branch} failed: ${r.because}`);
1571
+ }
1540
1572
  const pushed = r.already === undefined
1541
1573
  ? `pushed ${sha.slice(0, 12)} to ${d.branch} on ${d.remote}`
1542
1574
  : `already on ${d.branch} on ${d.remote} (${r.already.slice(0, 12)}${r.already === sha ? '' : ', which contains it'}); nothing pushed`;
@@ -1633,6 +1665,124 @@ async function laterDeploys(deps, api, e, plans, sha, base, at, asked) {
1633
1665
  }
1634
1666
  return { ...e, environments: rows };
1635
1667
  }
1668
+ /* ─────────────────────────────── a failed deploy is looked at again ── */
1669
+ /** How often a failed deploy is looked at again, inside the follow window. */
1670
+ exports.FAILED_RECHECK_MS = 15 * 60_000;
1671
+ /** How many times a push refused for the login is tried again by itself, per delivery. */
1672
+ exports.MAX_LOGIN_RETRIES = 3;
1673
+ const failedChecksDefault = new Map();
1674
+ const recheckKey = (e) => `${e.goalId}:${e.mergeSha ?? e.sha}`;
1675
+ /** A deploy-failed delivery, merged inside the follow window, not looked at again in the last 15 minutes. */
1676
+ function failedRecheckDue(deps, e) {
1677
+ if (e.state !== 'deploy-failed' || e.mergedAt === undefined || e.mergedAt === null)
1678
+ return false;
1679
+ const now = deps.now();
1680
+ if (now - Date.parse(e.mergedAt) > exports.FOLLOW_DEPLOYS_MS)
1681
+ return false;
1682
+ const last = (deps.failedChecks ?? failedChecksDefault).get(recheckKey(e));
1683
+ return last === undefined || now - last >= exports.FAILED_RECHECK_MS;
1684
+ }
1685
+ /**
1686
+ * THE HEROKU LOGIN, SAID PLAINLY (TAB-B-64…77, 2026-10-18/19: the PC was signed in as another account,
1687
+ * and the ticket read "pushing to heroku-qa main failed: … 403" for work that later shipped).
1688
+ */
1689
+ function herokuLoginSentence(account, app, needs) {
1690
+ const who = account === null ? 'not one with access to it' : account;
1691
+ return (`not pushed: the Heroku login on this PC is ${who}; ${app} needs ${needs ?? 'an account with access to it'}. ` +
1692
+ `It is pushed by itself once the Heroku login on this PC is right (heroku login)`).slice(0, 600);
1693
+ }
1694
+ /** A push Heroku refused for the login, and whom it named: "Your account X does not have access to APP", or a 403. */
1695
+ function herokuAuthRefusal(text) {
1696
+ const named = /Your account (\S+?) does not have access to ([A-Za-z0-9-]+)/i.exec(text);
1697
+ if (named)
1698
+ return { account: named[1], app: named[2] };
1699
+ if (/\b403\b|does not have access|Invalid credentials|not authorized|Unauthorized/i.test(text) && /heroku/i.test(text))
1700
+ return { account: null, app: null };
1701
+ return null;
1702
+ }
1703
+ /** The account a failed row says the PC was signed in as, when it says (all three wordings). */
1704
+ function accountInRow(detail) {
1705
+ const d = detail ?? '';
1706
+ const m = /Heroku login on this PC is (\S+?);/.exec(d) ?? /signed in as (\S+?), not /.exec(d) ?? /Your account (\S+?) does not have access/i.exec(d);
1707
+ if (m)
1708
+ return { auth: true, account: m[1] === 'not' ? null : m[1] };
1709
+ return { auth: herokuAuthRefusal(d) !== null, account: null };
1710
+ }
1711
+ /**
1712
+ * 🔴 A FAILED DEPLOY IS NOT FOR EVER (2026-10-21: eight Tabsy deliveries said "deploy failed" for days for
1713
+ * commits tabsy-qa-demo and tabsy-api were RUNNING — the 403 of 10-18 was the last word, because a
1714
+ * failed row was settled and never looked at again). Inside the follow window, every 15 minutes:
1715
+ *
1716
+ * - is it live after all? A Heroku app's newest release that is or contains the commit, else the
1717
+ * deploy branch's tip that does — `deployed`, "deployed later: …";
1718
+ * - else, a push refused for the Heroku LOGIN is pushed again once the login is right: the named
1719
+ * `herokuAccount`, or (none named) any account other than the one that was refused.
1720
+ * Nothing else about a failed row changes; its own failure stays its own until one of those is so.
1721
+ */
1722
+ async function recheckFailed(deps, e, plans, sha, base, at, asked) {
1723
+ const rows = [...(e.environments ?? [])];
1724
+ if (!rows.some((r) => r.state === 'failed'))
1725
+ return e;
1726
+ const checks = deps.failedChecks ?? failedChecksDefault;
1727
+ const last = checks.get(recheckKey(e));
1728
+ if (last !== undefined && deps.now() - last < exports.FAILED_RECHECK_MS)
1729
+ return e;
1730
+ checks.set(recheckKey(e), deps.now());
1731
+ for (const [i, row] of rows.entries()) {
1732
+ // Not a row this very pass made: it was just tried.
1733
+ if (row.state !== 'failed' || row.at === at)
1734
+ continue;
1735
+ const plan = plans.find((p) => p.name === row.name);
1736
+ const d = plan?.deploy;
1737
+ if (plan === undefined || d?.kind !== 'push')
1738
+ continue;
1739
+ // Live after all?
1740
+ if (d.herokuApp !== undefined && !asked.has(row.name)) {
1741
+ const c = await herokuRelease(deps, d.herokuApp, sha, base);
1742
+ if (c.state === 'deployed') {
1743
+ rows[i] = { ...row, state: 'deployed', at: c.at ?? at, detail: `deployed later: ${c.detail}`.slice(0, 600) };
1744
+ deps.log(`deliver : ${e.goalId}: ${row.name} is live after all — ${c.detail}`);
1745
+ continue;
1746
+ }
1747
+ }
1748
+ else if (d.herokuApp === undefined && deps.deployTip) {
1749
+ const tip = await deps.deployTip(d.remote, d.branch, sha);
1750
+ if (tip !== null) {
1751
+ const how = tip === sha ? 'is this commit' : `(${tip.slice(0, 12)}) contains this commit`;
1752
+ rows[i] = { ...row, state: 'deployed', at, detail: `deployed later: ${d.branch} on ${d.remote} ${how}`.slice(0, 600) };
1753
+ deps.log(`deliver : ${e.goalId}: ${row.name} is live after all — ${d.branch} on ${d.remote} ${how}`);
1754
+ continue;
1755
+ }
1756
+ }
1757
+ // Refused for the login, and the login is right now?
1758
+ const was = accountInRow(row.detail);
1759
+ if (!was.auth || !deps.heroku)
1760
+ continue;
1761
+ const who = await deps.heroku.whoami().catch(() => ({ ok: false, because: '' }));
1762
+ if (!who.ok)
1763
+ continue;
1764
+ const right = d.herokuAccount !== undefined
1765
+ ? who.account.toLowerCase() === d.herokuAccount.toLowerCase()
1766
+ : was.account !== null && who.account.toLowerCase() !== was.account.toLowerCase();
1767
+ if (!right) {
1768
+ // Still the wrong login: said in today's words, once.
1769
+ const said = herokuLoginSentence(who.account, d.herokuApp ?? d.remote, d.herokuAccount);
1770
+ if (d.herokuAccount !== undefined && row.detail !== said)
1771
+ rows[i] = { ...row, detail: said };
1772
+ continue;
1773
+ }
1774
+ // Bounded: a login the CLI reports right while git's push is still refused is not pushed every 15 minutes.
1775
+ const triesKey = `${recheckKey(e)}#login-retries`;
1776
+ const tries = checks.get(triesKey) ?? 0;
1777
+ if (tries >= exports.MAX_LOGIN_RETRIES)
1778
+ continue;
1779
+ checks.set(triesKey, tries + 1);
1780
+ deps.log(`deliver : ${e.goalId}: the Heroku login on this PC is now ${who.account} — deploying ${sha.slice(0, 12)} to ${row.name} again`);
1781
+ const again = await deployOne(deps, e, plan, sha, at, asked);
1782
+ rows[i] = { ...again, detail: `tried again once the Heroku login was right: ${again.detail ?? again.state}`.slice(0, 600) };
1783
+ }
1784
+ return { ...e, environments: rows };
1785
+ }
1636
1786
  /** GitHub's word on one environment, when it has one and the row is not already settled. */
1637
1787
  function fromGitHub(row, plans, found) {
1638
1788
  if (row.state === 'deployed' || row.state === 'failed')