looply-cli 0.5.48 → 0.5.50

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 (40) hide show
  1. package/dist/.src-hash +1 -1
  2. package/dist/additive-union.d.ts +31 -0
  3. package/dist/additive-union.d.ts.map +1 -0
  4. package/dist/additive-union.js +129 -0
  5. package/dist/additive-union.js.map +1 -0
  6. package/dist/branch-delivery-wiring.d.ts +7 -3
  7. package/dist/branch-delivery-wiring.d.ts.map +1 -1
  8. package/dist/branch-delivery-wiring.js +9 -2
  9. package/dist/branch-delivery-wiring.js.map +1 -1
  10. package/dist/branch-delivery.d.ts +31 -2
  11. package/dist/branch-delivery.d.ts.map +1 -1
  12. package/dist/branch-delivery.js +152 -7
  13. package/dist/branch-delivery.js.map +1 -1
  14. package/dist/branch-replay.d.ts +9 -1
  15. package/dist/branch-replay.d.ts.map +1 -1
  16. package/dist/branch-replay.js +58 -6
  17. package/dist/branch-replay.js.map +1 -1
  18. package/dist/daemon-cmd.d.ts.map +1 -1
  19. package/dist/daemon-cmd.js +13 -1
  20. package/dist/daemon-cmd.js.map +1 -1
  21. package/dist/deliver-cmd.d.ts +1 -0
  22. package/dist/deliver-cmd.d.ts.map +1 -1
  23. package/dist/deliver-cmd.js +2 -0
  24. package/dist/deliver-cmd.js.map +1 -1
  25. package/dist/fresh-gates.d.ts +105 -0
  26. package/dist/fresh-gates.d.ts.map +1 -0
  27. package/dist/fresh-gates.js +200 -0
  28. package/dist/fresh-gates.js.map +1 -0
  29. package/dist/outcome-audit.d.ts +4 -2
  30. package/dist/outcome-audit.d.ts.map +1 -1
  31. package/dist/outcome-audit.js +6 -3
  32. package/dist/outcome-audit.js.map +1 -1
  33. package/dist/setup-check-wiring.d.ts +23 -0
  34. package/dist/setup-check-wiring.d.ts.map +1 -1
  35. package/dist/setup-check-wiring.js +72 -1
  36. package/dist/setup-check-wiring.js.map +1 -1
  37. package/dist/ticket-words.d.ts.map +1 -1
  38. package/dist/ticket-words.js +4 -0
  39. package/dist/ticket-words.js.map +1 -1
  40. package/package.json +2 -2
@@ -130,12 +130,12 @@ rebuild = {}) {
130
130
  .filter((ids) => /^[0-9a-f]{40}$/.test(ids[0] ?? ''))
131
131
  .map(([sha, ...parents]) => ({ sha: sha, parents }));
132
132
  },
133
- async replay(base, commits) {
133
+ async replay(base, commits, opts) {
134
134
  try {
135
135
  return await (0, branch_replay_1.replayOnto)(exec, (dir) => {
136
136
  const inner = (rebuild.execAt ?? git_driver_1.nodeGitExec)(dir);
137
137
  return (args) => inner(['-c', 'credential.interactive=never', ...args]);
138
- }, base, commits, rebuild.scratchRoot);
138
+ }, base, commits, rebuild.scratchRoot, opts);
139
139
  }
140
140
  catch (e) {
141
141
  return { ok: false, because: e.message.slice(0, 300) };
@@ -577,6 +577,7 @@ async function deliverOnce(deps, input) {
577
577
  ...((input.maintenance && !input.maintenance.autoMerge) || input.noAutoMerge === true ? { noAutoMerge: true } : {}),
578
578
  ...(input.checks ? { checks: { ...input.checks } } : {}),
579
579
  ...(input.clientRef ? { clientRef: input.clientRef } : {}),
580
+ ...(input.late === true ? { late: true } : {}),
580
581
  ...(input.parts ? { parts: input.parts.map((p) => ({ ...p })) } : {}),
581
582
  state: 'not-pushed',
582
583
  note: null,
@@ -999,6 +1000,85 @@ function decideChecks(required, checks) {
999
1000
  const waiting = checks.filter((c) => c.state === 'pending').map((c) => c.name);
1000
1001
  return waiting.length > 0 ? { kind: 'pending', waiting } : { kind: 'green' };
1001
1002
  }
1003
+ /**
1004
+ * THE PROJECT'S CHECKS ON WHAT WILL ACTUALLY LAND (`fresh-gates.ts`): the pull request's head when it is already on top of
1005
+ * the base as it is now, else its own commits replayed onto that base (never merged, never pushed — only checked). Kept
1006
+ * on the entry per head and base, so a pass that changes neither never runs them again.
1007
+ *
1008
+ * passed → merge; review → held for a person, saying why; later → asked again on a later pass.
1009
+ */
1010
+ async function landedChecks(deps, e, pull, at) {
1011
+ const where = `the current ${(0, delivery_rules_1.shortBranch)(pull.base)}`;
1012
+ if (deps.freshGates === undefined)
1013
+ return { kind: 'review', entry: e, why: `Looply cannot run its checks again on ${where} here` };
1014
+ const head = pull.headSha || e.sha;
1015
+ await deps.git.freshBase(pull.base).catch(() => pull.base);
1016
+ const base = await deps.git.remoteSha((0, delivery_rules_1.shortBranch)(pull.base)).catch(() => null);
1017
+ if (base === null)
1018
+ return { kind: 'later', because: `${(0, delivery_rules_1.shortBranch)(pull.base)} on origin could not be read` };
1019
+ // Origin's word can be newer than the fetch that just ran: a base not here yet is fetched again, else waited for.
1020
+ if (!(await deps.git.isAncestor(base, base).catch(() => false))) {
1021
+ await deps.git.freshBase(pull.base).catch(() => pull.base);
1022
+ if (!(await deps.git.isAncestor(base, base).catch(() => false)))
1023
+ return { kind: 'later', because: `${(0, delivery_rules_1.shortBranch)(pull.base)} at ${base.slice(0, 12)} is not fetched yet` };
1024
+ }
1025
+ const kept = e.freshGates;
1026
+ let answer;
1027
+ // A kept answer for the same head and base; an "unknown" (a full disk, the network) only for an hour.
1028
+ const keptFresh = kept && kept.head === head && kept.base === base && (kept.verdict !== 'unknown' || now(deps) - Date.parse(kept.at) < UNKNOWN_KEPT_MS);
1029
+ if (kept && keptFresh) {
1030
+ answer =
1031
+ kept.verdict === 'passed'
1032
+ ? { verdict: 'passed', checks: kept.checks ?? {} }
1033
+ : kept.verdict === 'failed'
1034
+ ? { verdict: 'failed', step: kept.step ?? 'a check', checks: kept.checks ?? {} }
1035
+ : { verdict: 'unknown', because: kept.because ?? 'it could not be judged' };
1036
+ }
1037
+ else {
1038
+ /**
1039
+ * What lands, made only when the checks actually start (in the background, `backgroundFreshGates`): the head when it
1040
+ * already sits on the base, else its commits replayed onto it. Asked by HEAD AND BASE, never by the replayed commit,
1041
+ * whose committer date — and so its sha — differs every time it is made.
1042
+ */
1043
+ const landing = async () => {
1044
+ if (await deps.git.isAncestor(base, head).catch(() => false))
1045
+ return head;
1046
+ const range = await deps.git.commitsBetween(base, head).catch(() => null);
1047
+ if (range === null || range.length === 0 || range.some((c) => c.parents.length !== 1))
1048
+ return null;
1049
+ const replayed = await deps.git.replay(base, range.map((c) => c.sha)).catch(() => null);
1050
+ return replayed !== null && replayed.ok ? replayed.sha : null;
1051
+ };
1052
+ answer = await deps.freshGates(head, base, landing).catch((err) => ({ verdict: 'unknown', because: err.message }));
1053
+ if (answer.verdict === 'later')
1054
+ return { kind: 'later', because: answer.because };
1055
+ }
1056
+ const entry = {
1057
+ ...e,
1058
+ freshGates: {
1059
+ head,
1060
+ base,
1061
+ verdict: answer.verdict,
1062
+ step: answer.verdict === 'failed' ? answer.step : null,
1063
+ because: answer.verdict === 'unknown' ? answer.because.slice(0, 300) : null,
1064
+ checks: answer.verdict === 'unknown' ? null : { ...answer.checks },
1065
+ at,
1066
+ },
1067
+ };
1068
+ // `fresh`: an answer just handed over (not one this entry already kept), which the caller keeps at once.
1069
+ if (answer.verdict === 'passed')
1070
+ return { kind: 'passed', entry, checks: { ...answer.checks }, fresh: !(kept && keptFresh) };
1071
+ return {
1072
+ kind: 'review',
1073
+ entry,
1074
+ why: answer.verdict === 'failed'
1075
+ ? `Looply's checks, run again on ${where}, failed ("${answer.step}"). They ran with the dependencies installed without their install scripts, which a step like Prisma generate or a native module may need, so this may not be the change's fault`
1076
+ : `Looply's checks could not be run again on ${where} (${answer.because.slice(0, 160)})`,
1077
+ };
1078
+ }
1079
+ /** How long a kept "could not be judged" answer stands before the checks are tried again. */
1080
+ const UNKNOWN_KEPT_MS = 60 * 60_000;
1081
+ const now = (deps) => deps.now();
1002
1082
  /** The last merge wait said per goal (`goalStillWanted`): each reason is logged once, not every pass. */
1003
1083
  const mergeWaitSaid = new Map();
1004
1084
  /**
@@ -1412,10 +1492,18 @@ async function advanceOne(deps, e) {
1412
1492
  * commit are the check instead — every one of them passed, or it goes to a person as before.
1413
1493
  */
1414
1494
  let noCiNote = null;
1495
+ let rerun = false;
1496
+ // The head is the commit Looply delivered (or rebuilt): nobody else pushed to it.
1497
+ const ownHead = pull.headSha === '' || pull.headSha === e.sha;
1415
1498
  if (verdict.kind === 'none' && !approved) {
1416
1499
  // The gates ran on the delivered commit: a head that moved, or a `-solo` rebuild, is not what they judged.
1417
- const sameCommit = (pull.headSha === '' || pull.headSha === e.sha) && !e.rebuiltFrom;
1418
- const gatesHold = OWN_GATES_STAND_IN.includes(mode) && gatesPassed(e.checks) && sameCommit;
1500
+ const sameCommit = ownHead && !e.rebuiltFrom;
1501
+ /**
1502
+ * Late (the outcome auditor's) or LOOPLY'S OWN rebuild: Looply's checks run AGAIN on what lands
1503
+ * (`fresh-gates.ts`), not the run's. A head somebody else pushed is theirs: it goes to a person, as before.
1504
+ */
1505
+ rerun = deps.freshGates !== undefined && OWN_GATES_STAND_IN.includes(mode) && ownHead && (e.late === true || e.rebuiltFrom != null);
1506
+ const gatesHold = OWN_GATES_STAND_IN.includes(mode) && (rerun || (gatesPassed(e.checks) && sameCommit));
1419
1507
  if (age < exports.NO_CHECKS_GRACE_MS) {
1420
1508
  /**
1421
1509
  * SAY WHAT WILL HAPPEN, NOT "WAITING FOR CI". Under ship to test with Looply's own checks
@@ -1435,6 +1523,46 @@ async function advanceOne(deps, e) {
1435
1523
  }
1436
1524
  noCiNote = `merged on Looply's own checks (${Object.keys(e.checks ?? {}).join(', ')} passed); the repository reports no CI`;
1437
1525
  }
1526
+ /**
1527
+ * 🔴 LATE OR REBUILT: THE CHECKS RUN AGAIN ON WHAT LANDS. A change the outcome auditor delivered hours after its run,
1528
+ * or one rebuilt on the current base, merges on Looply's own word only once the project's checks pass on the change
1529
+ * on top of the base as it is now. Failed or unknown: delivered for review, the ticket saying why in one line.
1530
+ */
1531
+ const late = e.late === true && ownHead && !approved && verdict.kind !== 'pending';
1532
+ const landed = rerun || late;
1533
+ if (landed) {
1534
+ const f = await landedChecks(deps, e, pull, at);
1535
+ if (f.kind === 'later') {
1536
+ /**
1537
+ * NEVER A SILENT WAIT: the ticket is told it waits for the checks (once), and after a day of waiting (a run of
1538
+ * the repository always in flight, the budget always spent) it goes to a person, saying why.
1539
+ */
1540
+ const since = e.freshWaitSince ? Date.parse(e.freshWaitSince) : NaN;
1541
+ if (!Number.isNaN(since) && now - since > exports.CHECKS_PATIENCE_MS) {
1542
+ const note = `not merged: Looply's checks could not be run again on the current ${(0, delivery_rules_1.shortBranch)(pull.base)} within a day (${f.because}); a person merges it`;
1543
+ deps.log(`deliver : ${e.goalId}: ${note}`);
1544
+ await save(deps, { ...e, state: 'pr-open', freshWaitSince: null, note, updatedAt: at });
1545
+ }
1546
+ else if (Number.isNaN(since)) {
1547
+ await save(deps, { ...e, freshWaitSince: at, note: `merging once Looply's checks pass again on the current ${(0, delivery_rules_1.shortBranch)(pull.base)} (${f.because})`, updatedAt: at });
1548
+ }
1549
+ return;
1550
+ }
1551
+ if (f.kind === 'review') {
1552
+ const note = `not merged: ${f.why}; a person merges it`;
1553
+ if (e.state !== 'pr-open' || e.note !== note) {
1554
+ deps.log(`deliver : ${e.goalId}: ${note}`);
1555
+ await save(deps, { ...f.entry, freshWaitSince: null, state: 'pr-open', note, updatedAt: at });
1556
+ }
1557
+ return;
1558
+ }
1559
+ e = { ...f.entry, freshWaitSince: null };
1560
+ // Kept NOW: the answer is handed over once, and a wait below (the goal changed on the server) must not lose it.
1561
+ if (f.fresh)
1562
+ deps.store.put(e);
1563
+ if (noCiNote !== null)
1564
+ noCiNote = `merged on Looply's own checks, run again on the current ${(0, delivery_rules_1.shortBranch)(pull.base)} (${Object.keys(f.checks).join(', ')} passed); the repository reports no CI`;
1565
+ }
1438
1566
  if (verdict.kind === 'pending') {
1439
1567
  if (age > exports.CHECKS_PATIENCE_MS) {
1440
1568
  await save(deps, { ...e, state: 'pr-open', note: `not merged: still waiting for ${verdict.waiting.join(', ')} after a day; a person merges`, updatedAt: at });
@@ -1466,6 +1594,15 @@ async function advanceOne(deps, e) {
1466
1594
  return;
1467
1595
  }
1468
1596
  }
1597
+ // 🔴 Checked on what lands: the base must still be the one the checks ran on. Moved since → checked again first.
1598
+ if (landed && e.freshGates) {
1599
+ await deps.git.freshBase(pull.base).catch(() => pull.base);
1600
+ const baseNow = await deps.git.remoteSha((0, delivery_rules_1.shortBranch)(pull.base)).catch(() => null);
1601
+ if (baseNow !== e.freshGates.base) {
1602
+ deps.log(`deliver : ${e.goalId}: ${(0, delivery_rules_1.shortBranch)(pull.base)} moved since its checks ran again; checked again before merging`);
1603
+ return;
1604
+ }
1605
+ }
1469
1606
  const merged = await api.merge(pull.number, pull.headSha, pullTitle(e.goalText));
1470
1607
  if (!merged.merged) {
1471
1608
  await save(deps, { ...e, state: 'checks-failed', failedHead: pull.headSha || e.sha, note: `checks allow it but GitHub would not merge: ${merged.message}`, updatedAt: at });
@@ -1614,9 +1751,14 @@ async function rebuildOnBase(deps, api, e, pull, at, mode) {
1614
1751
  const commits = range.filter((c) => mine.has(c.sha));
1615
1752
  if (commits.some((c) => c.parents.length !== 1))
1616
1753
  return held("its own commits include a merge, which Looply never replays");
1617
- const replayed = await deps.git.replay(ref, commits.map((c) => c.sha));
1754
+ // 🔴 A conflict that is only ADDITIONS on both sides to a JSON object (two goals each adding a script to package.json)
1755
+ // is united (`additive-union.ts`); any other conflict still refuses, naming its files, and waits for a person.
1756
+ const replayed = await deps.git.replay(ref, commits.map((c) => c.sha), { unionAdditive: true });
1618
1757
  if (!replayed.ok)
1619
1758
  return held(replayed.because);
1759
+ const unitedNote = replayed.unioned !== undefined && replayed.unioned.length > 0
1760
+ ? ` The only conflict, in ${replayed.unioned.join(', ')}, was additions on both sides; Looply kept both.`
1761
+ : '';
1620
1762
  const original = { branch: e.rebuiltFrom?.branch ?? e.branch, sha: e.rebuiltFrom?.sha ?? e.sha };
1621
1763
  const named = await soloBranch(deps, { goalId: e.goalId, claims, from: original.branch, replayed, ref, branches, onOrigin, at });
1622
1764
  if (!named.ok)
@@ -1661,7 +1803,7 @@ async function rebuildOnBase(deps, api, e, pull, at, mode) {
1661
1803
  }
1662
1804
  }
1663
1805
  await api
1664
- .closePull(pull.number, `Rebuilt on the current ${base} as ${fresh.url}, because this pull request conflicted with ${base}. Same changes, each commit applied as it was; nothing was resolved by guesswork.`)
1806
+ .closePull(pull.number, `Rebuilt on the current ${base} as ${fresh.url}, because this pull request conflicted with ${base}. Same changes, each commit applied as it was; nothing was resolved by guesswork.${unitedNote}`)
1665
1807
  .catch((err) => deps.log(`deliver : ${e.goalId}: could not close ${e.pullRequestUrl ?? `#${pull.number}`} (${err.message})`));
1666
1808
  deps.log(`deliver : ${e.goalId}: ${e.pullRequestUrl ?? `#${pull.number}`} conflicted with ${base}; rebuilt as ${fresh.url}`);
1667
1809
  const without = others.filter((f) => !unmerged.includes(f)).map((f) => ({ goalId: f.goalId ?? null, branch: f.branch, commits: f.commits.length }));
@@ -1678,6 +1820,9 @@ async function rebuildOnBase(deps, api, e, pull, at, mode) {
1678
1820
  mode,
1679
1821
  state: 'waiting-checks',
1680
1822
  rebuiltFrom: { branch: original.branch, sha: original.sha, without },
1823
+ // A new commit: no wait or answer of the checks on the old one carries over.
1824
+ freshWaitSince: null,
1825
+ freshGates: null,
1681
1826
  // 🔴 Nobody approved this commit: an earlier "Approve and ship" does not carry over to it.
1682
1827
  approvedAt: null,
1683
1828
  voidedApproval: e.approvedAt ?? e.voidedApproval ?? null,
@@ -1687,7 +1832,7 @@ async function rebuildOnBase(deps, api, e, pull, at, mode) {
1687
1832
  // The age clock is the original pull request's: a rebuild is not a newer piece of work.
1688
1833
  openedAt: e.openedAt,
1689
1834
  waitingSince: at,
1690
- note: `it conflicted with ${base}, so Looply rebuilt it on the current ${base} as ${fresh.url} (replaces ${e.pullRequestUrl ?? `#${pull.number}`}); merging once the checks allow`.slice(0, 600),
1835
+ note: `it conflicted with ${base}, so Looply rebuilt it on the current ${base} as ${fresh.url} (replaces ${e.pullRequestUrl ?? `#${pull.number}`})${replayed.unioned?.length ? `, keeping both sides' additions to ${replayed.unioned.join(', ')}` : ''}; merging once the checks allow`.slice(0, 600),
1691
1836
  updatedAt: at,
1692
1837
  });
1693
1838
  }