@futurelastic/colab-handbook 1.20.2-rc.3 → 1.20.3-rc.2

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/package.json CHANGED
@@ -33,5 +33,5 @@
33
33
  "engines": {
34
34
  "node": ">=18"
35
35
  },
36
- "version": "1.20.2-rc.3"
36
+ "version": "1.20.3-rc.2"
37
37
  }
package/tools/colab CHANGED
@@ -13925,14 +13925,16 @@ function readTargetCodeowners(repoAbs, target) {
13925
13925
  * this repo's remote URL. Either unknown → `{ fork: false }`, nothing is dropped.
13926
13926
  */
13927
13927
  function codeownersForkContext(repoAbs) {
13928
- const declared = instructionFile.parseInstructionFiles(projectDoc(repoAbs)).exempt;
13929
- if (!adoptDetectFork(repoAbs) && !declared) return { fork: false, ownOrg: null };
13930
13928
  const name = git.remoteInfo(repoAbs).name || 'origin';
13931
13929
  // The configured url, as the gh pin reads it (#658): `get-url` expands `url.<x>.insteadOf`, which
13932
13930
  // changes how git reaches the remote, never which org owns it.
13933
13931
  const u = git.git(['config', '--get', `remote.${name}.url`], repoAbs);
13934
- const ownOrg = u.ok ? codeowners.remoteOwner(u.stdout) : null;
13935
- return { fork: !!ownOrg, ownOrg };
13932
+ const remoteOrg = u.ok ? codeowners.remoteOwner(u.stdout) : null;
13933
+ const declared = instructionFile.parseInstructionFiles(projectDoc(repoAbs)).exempt;
13934
+ // #702: `remoteOrg` rides along on a non-fork too — it drops nothing there (`ownOrg` stays null),
13935
+ // it only lets the review say "fork not detected" when the file is all other orgs' teams.
13936
+ if (!adoptDetectFork(repoAbs) && !declared) return { fork: false, ownOrg: null, remoteOrg };
13937
+ return { fork: !!remoteOrg, ownOrg: remoteOrg, remoteOrg };
13936
13938
  }
13937
13939
 
13938
13940
  function branchChangedPathsNoRenames(repoAbs, base, ref) {
@@ -13978,12 +13980,23 @@ function shipDirectCoreReview(repoAbs, gh, trunk, since) {
13978
13980
  }
13979
13981
  }
13980
13982
  }
13981
- return codeowners.directVerdict({ files: [before, readTargetCodeowners(repoAbs, trunk)], authors, changed, fork: codeownersForkContext(repoAbs) });
13983
+ const out = codeowners.directVerdict({ files: [before, readTargetCodeowners(repoAbs, trunk)], authors, changed, fork: codeownersForkContext(repoAbs) });
13984
+ if (out.forkSignal) out.detail += FORK_SIGNAL_TAIL;
13985
+ return out;
13982
13986
  }
13983
13987
 
13988
+ /** #702: the table row's tail when the file reads like an undetected fork's — the full note is a warning. */
13989
+ const FORK_SIGNAL_TAIL = ' · fork not detected: no `upstream` remote, no `instruction-files: upstream` (#702)';
13990
+
13984
13991
  function shipCoreReview(repoAbs, gh, target, branch) {
13992
+ const out = shipCoreReviewVerdict(repoAbs, gh, target, branch);
13993
+ if (out.forkSignal) out.detail += FORK_SIGNAL_TAIL;
13994
+ return out;
13995
+ }
13996
+
13997
+ function shipCoreReviewVerdict(repoAbs, gh, target, branch) {
13985
13998
  const out = { active: false, inertReason: null, codeownersPath: null, warnings: [], corePaths: [], ignoredOwners: [],
13986
- pr: null, approval: null, headSha: null, authors: [], verdict: 'inert', detail: '' };
13999
+ forkSignal: null, pr: null, approval: null, headSha: null, authors: [], verdict: 'inert', detail: '' };
13987
14000
  const file = readTargetCodeowners(repoAbs, target);
13988
14001
  if (!file) { out.inertReason = `no CODEOWNERS on ${target}`; out.detail = `inert: ${out.inertReason}`; return out; }
13989
14002
  out.codeownersPath = file.path;
@@ -13994,6 +14007,11 @@ function shipCoreReview(repoAbs, gh, target, branch) {
13994
14007
  const { rules, dropped } = codeowners.dropForeignTeams(parsedFile.rules, forkCtx);
13995
14008
  out.ignoredOwners = dropped;
13996
14009
  if (dropped.length) out.warnings = [...out.warnings, codeowners.foreignNote(dropped, forkCtx)];
14010
+ // #702: fork status comes from this checkout's remotes or a declaration, so a fork cloned without
14011
+ // `upstream` and never declared reads as active here and inert on a clone that has the remote.
14012
+ // Say so instead of silently pausing on teams nobody in this repo can be.
14013
+ out.forkSignal = codeowners.undetectedForkNote(parsedFile.rules, forkCtx);
14014
+ if (out.forkSignal) out.warnings = [...out.warnings, out.forkSignal];
13997
14015
  const parsed = branchName.parse(branch);
13998
14016
  out.authors = [...new Set([gh ? git.ghCurrentLogin() : null, parsed && parsed.login].filter(Boolean))];
13999
14017
  const inert = codeowners.inert(rules, out.authors);
@@ -14062,7 +14080,7 @@ function coreReviewPayload(cr) {
14062
14080
  if (!cr) return null;
14063
14081
  return {
14064
14082
  active: cr.active, verdict: cr.verdict, inertReason: cr.inertReason, codeownersPath: cr.codeownersPath,
14065
- ignoredOwners: cr.ignoredOwners || [], corePaths: cr.corePaths.map((c) => c.path), headSha: cr.headSha,
14083
+ ignoredOwners: cr.ignoredOwners || [], forkSignal: cr.forkSignal || null, corePaths: cr.corePaths.map((c) => c.path), headSha: cr.headSha,
14066
14084
  pr: cr.pr ? { number: cr.pr.number, url: cr.pr.url, state: cr.pr.state } : null,
14067
14085
  approval: cr.approval,
14068
14086
  };
@@ -177,6 +177,32 @@ function foreignNote(dropped, ctx) {
177
177
  return `fork of an upstream: ignored ${dropped.join(', ')} — team(s) of an org other than ${ctx.ownOrg}, inherited and unable to review here (#483)`;
178
178
  }
179
179
 
180
+ /**
181
+ * #702 — the fork test (#483) reads a clone-local `upstream` remote or a committed declaration, so a
182
+ * fork whose clone lacks the remote and whose descriptor declares nothing reads as "not a fork" on
183
+ * that clone alone: the same branch is then gated on one clone and not another. This cannot settle
184
+ * fork status itself (a repo may legitimately be owned by another org's teams), so it only names the
185
+ * missing signal, and only in the one shape that gives it away: NOT a fork, the repo's own remote
186
+ * owner known, and EVERY owner in the file a team (`@org/team`) of some other org. A login, an
187
+ * email or a team of the repo's own org anywhere in the file means someone here can review, so
188
+ * nothing is said. Returns the one-line note, or null.
189
+ */
190
+ function undetectedForkNote(rules, { fork, remoteOrg } = {}) {
191
+ if (fork || !remoteOrg) return null;
192
+ const own = String(remoteOrg).toLowerCase();
193
+ const owners = [...new Set((rules || []).flatMap((r) => r.owners))];
194
+ if (!owners.length) return null;
195
+ const orgs = new Set();
196
+ for (const o of owners) {
197
+ const m = TEAM_RE.exec(o);
198
+ if (!m || m[1].toLowerCase() === own) return null;
199
+ orgs.add('@' + m[1]);
200
+ }
201
+ return `fork not detected: every CODEOWNERS owner is a team of an org other than ${remoteOrg} (${[...orgs].join(', ')}), `
202
+ + 'yet this checkout has no `upstream` remote and project.yml has no `instruction-files: upstream`. '
203
+ + 'If this repo is a fork, add `instruction-files: upstream` to .github/project.yml so every clone ignores the inherited teams the same way (#483, #658, #702)';
204
+ }
205
+
180
206
  /**
181
207
  * Has a PR been approved by someone other than its author, AT `headSha`?
182
208
  *
@@ -228,7 +254,7 @@ function approvalVerdict(reviews, { prAuthor, authors = [], headSha }) {
228
254
  * before anything else is read (`dropForeignTeams`). Absent = nothing dropped.
229
255
  */
230
256
  function directVerdict({ files, authors, changed, fork = null }) {
231
- const out = { active: false, inertReason: null, codeownersPath: null, warnings: [], corePaths: [], verdict: 'inert', detail: '' };
257
+ const out = { active: false, inertReason: null, codeownersPath: null, warnings: [], corePaths: [], forkSignal: null, verdict: 'inert', detail: '' };
232
258
  const seen = new Set();
233
259
  const present = (files || []).filter((f) => f && !seen.has(f.text) && seen.add(f.text));
234
260
  if (!present.length) { out.inertReason = 'no CODEOWNERS on trunk before or after the unit'; out.detail = `inert: ${out.inertReason}`; return out; }
@@ -241,6 +267,9 @@ function directVerdict({ files, authors, changed, fork = null }) {
241
267
  // #483: a fork's inherited foreign-org teams bind neither file.
242
268
  const { rules, dropped } = dropForeignTeams(parsed.rules, fork || {});
243
269
  if (dropped.length) out.warnings.push(`${f.path}@${f.ref}: ${foreignNote(dropped, fork)}`);
270
+ // #702: not read as a fork, but the file says it probably is one — name the missing signal.
271
+ const unforked = undetectedForkNote(parsed.rules, fork || {});
272
+ if (unforked) { out.warnings.push(`${f.path}@${f.ref}: ${unforked}`); out.forkSignal = out.forkSignal || unforked; }
244
273
  const iv = inert(rules, authors);
245
274
  if (iv.inert) { inertReasons.push(`${f.path}@${f.ref}: ${iv.reason}`); continue; }
246
275
  out.active = true;
@@ -268,5 +297,5 @@ function directVerdict({ files, authors, changed, fork = null }) {
268
297
 
269
298
  module.exports = {
270
299
  CODEOWNERS_PATHS, parse, compile, ownerOf, corePaths, inert, approvalVerdict, directVerdict,
271
- remoteOwner, foreignTeams, dropForeignTeams, foreignNote,
300
+ remoteOwner, foreignTeams, dropForeignTeams, foreignNote, undetectedForkNote,
272
301
  };
@@ -42,7 +42,7 @@
42
42
  * `colab migration-grant` / `colab ci-grant` / `colab promote`, `colab decision --record` is
43
43
  * deliberately NOT gated on COLAB_HUMAN=1: those three AUTHORIZE a write to production or
44
44
  * trunk that did not exist before the command ran; this one TRANSCRIBES a call a human
45
- * already made elsewhere (the ordinary case is `Filed-by: boss` — an agent recording Boss's
45
+ * already made elsewhere (the ordinary case is `Filed-by: human` — an agent recording a person's
46
46
  * ruling, not inventing one). The safety property is carried by requiring `ruledBy` (no
47
47
  * default) plus TRUSTED_ASSOCIATIONS on read, not by gating who may type the command. If that
48
48
  * is judged too weak in review, requiring COLAB_HUMAN=1 here too is the safe direction and
package/tools/lib/git.js CHANGED
@@ -735,9 +735,17 @@ function ghOpenPrs(repo) {
735
735
  * #367: the forge's visibility for this repo — "PUBLIC" | "PRIVATE" | "INTERNAL" — or null when it
736
736
  * could not be read (no gh, no GitHub remote, offline). Null is "could not read", never "private":
737
737
  * tools/lib/machine-trailer.js fails closed on it.
738
+ *
739
+ * #701: the repo is NAMED — the resolved remote's slug (tracker-github `pinnedRepo`, the remote a
740
+ * squash is pushed to). A bare `gh repo view` ignores the GH_REPO pin every other call carries
741
+ * (#658: it takes a positional repo, not -R), so on a private fork with a public `upstream` it read
742
+ * the upstream and reported PUBLIC. No slug (a local-path remote, an SSH alias, a host gh does not
743
+ * serve) → null, never gh's own guess.
738
744
  */
739
745
  function ghRepoVisibility(repo) {
740
- const r = gh(['repo', 'view', '--json', 'visibility', '-q', '.visibility'], { cwd: repo });
746
+ const slug = require('./tracker-github').pinnedRepo(repo);
747
+ if (!slug) return null;
748
+ const r = gh(['repo', 'view', slug, '--json', 'visibility', '-q', '.visibility'], { cwd: repo });
741
749
  if (!r.ok) return null;
742
750
  const v = (r.stdout || '').trim().toUpperCase();
743
751
  return /^[A-Z]+$/.test(v) ? v : null;