@hearsay-tools/squawk 0.18.0-dev.8189 → 0.18.0-dev.8203

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.
@@ -10,6 +10,7 @@ import { z } from 'zod';
10
10
  import { githubRequestGate } from './github-request-gate.js';
11
11
  import { refStatusQuery } from './github-ref-status-query.js';
12
12
  import { mergedPullRequestChunk } from './github-merged-pr-chunk.js';
13
+ import { reviewerKey, reviewerRefSchema } from './github-reviewer-ref.js';
13
14
  import { gh, githubContext, parseOwnerName } from './github-cli.js';
14
15
  import { canonicalRepoRef, discoverRepoHandle, forgetRepoHandle, forgettingNameOnMiss, resolveRepoHandle, sharedRepoHandle } from './github-repo-handle.js';
15
16
  export { parseOwnerName } from './github-cli.js';
@@ -975,7 +976,7 @@ export function __clearCommentsCacheForTests() {
975
976
  // answer (an item or a confirmed absence) is cached, never an unavailable one.
976
977
  const itemCache = new Map();
977
978
  function itemCacheKey(repoRoot, kind, number) {
978
- return `${repoRoot}\0${kind}#${number}`;
979
+ return `${githubContext(repoRoot).key}\0${kind}#${number}`;
979
980
  }
980
981
  export function forgetGithubItem(repoRoot, kind, number) {
981
982
  itemCache.delete(itemCacheKey(repoRoot, kind, number));
@@ -1228,7 +1229,7 @@ function mockGithubCommentCounts(kind, numbers) {
1228
1229
  }
1229
1230
  return { available: true, counts };
1230
1231
  }
1231
- // Per-PR checks cache: keyed `repoRoot␀number`, same 60 s TTL as the list cache but BOUNDED. Lets
1232
+ // Per-PR checks cache: keyed `githubContext␀number`, same 60 s TTL as the list cache but BOUNDED. Lets
1232
1233
  // a repeated visible-window hydration within a minute serve cached glyphs instead of re-querying.
1233
1234
  const checksCache = new Map();
1234
1235
  const CHECKS_CACHE_MAX = 500;
@@ -1249,8 +1250,9 @@ export async function fetchGithubChecks(repoRoot, numbers) {
1249
1250
  const checks = {};
1250
1251
  const misses = [];
1251
1252
  const now = Date.now();
1253
+ const context = githubContext(repoRoot);
1252
1254
  for (const n of wanted) {
1253
- const hit = checksCache.get(`${repoRoot}\0${n}`);
1255
+ const hit = checksCache.get(`${context.key}\0${n}`);
1254
1256
  if (hit && now - hit.at < CACHE_MS)
1255
1257
  checks[n] = hit.glyph;
1256
1258
  else
@@ -1259,20 +1261,20 @@ export async function fetchGithubChecks(repoRoot, numbers) {
1259
1261
  if (misses.length === 0)
1260
1262
  return { available: true, checks };
1261
1263
  try {
1262
- const repoOut = await gh(repoRoot, ['repo', 'view', '--json', 'nameWithOwner', '--jq', '.nameWithOwner']);
1264
+ const repoOut = await gh(repoRoot, ['repo', 'view', '--json', 'nameWithOwner', '--jq', '.nameWithOwner'], undefined, undefined, context);
1263
1265
  const ownerName = parseOwnerName(repoOut);
1264
1266
  if (!ownerName)
1265
1267
  return { available: false, reason: 'repository handle unavailable' };
1266
1268
  const runGraphql = (query, variables) => {
1267
1269
  const args = ghGraphqlArgs(query, variables);
1268
- return gh(repoRoot, args);
1270
+ return gh(repoRoot, args, undefined, undefined, context);
1269
1271
  };
1270
1272
  const fetched = await fetchPrChecks(runGraphql, ownerName.owner, ownerName.name, misses);
1271
1273
  for (const n of misses) {
1272
1274
  // Absent (unknown/closed PR) caches as `null` so a nonexistent number isn't re-queried.
1273
1275
  const glyph = n in fetched ? fetched[n] : null;
1274
1276
  checks[n] = glyph;
1275
- checksCache.set(`${repoRoot}\0${n}`, { at: now, glyph });
1277
+ checksCache.set(`${context.key}\0${n}`, { at: now, glyph });
1276
1278
  }
1277
1279
  while (checksCache.size > CHECKS_CACHE_MAX) {
1278
1280
  const oldest = checksCache.keys().next().value;
@@ -1305,21 +1307,6 @@ function mockGithubChecks(numbers) {
1305
1307
  * contract rather than restated, because the cockpit caps its batches by the same number and a
1306
1308
  * client that guessed high would have every chip in a batch 400 instead of losing its tail. */
1307
1309
  export const GH_REF_STATUS_MAX = REFERENCE_STATUS_MAX;
1308
- /** A requested reviewer, as either connection spells them. `login` covers `User` and `Bot`, `slug`
1309
- * covers `Team`; `reviewerKey` folds them into one comparable string. */
1310
- const reviewerRefSchema = z
1311
- .object({
1312
- __typename: z.string().nullish(),
1313
- login: z.string().nullish(),
1314
- slug: z.string().nullish(),
1315
- })
1316
- .nullish();
1317
- /** One reviewer as a comparable key, or `null` when GitHub named nobody we can match on — which
1318
- * must never compare equal to another unnamed reviewer, hence `null` rather than a shared "". */
1319
- function reviewerKey(ref) {
1320
- const name = ref?.login ?? ref?.slug;
1321
- return name ? `${ref?.__typename ?? '?'}:${name}` : null;
1322
- }
1323
1310
  const ghRefStatusPrSchema = z
1324
1311
  .object({
1325
1312
  state: z.string(),
@@ -1949,7 +1936,7 @@ function mockGithubRefStatus(prs, issues) {
1949
1936
  */
1950
1937
  function commentsCacheKey(repoRoot, kind, number) {
1951
1938
  // NUL separator: cannot appear in a filesystem path, so roots can never alias.
1952
- return `${repoRoot}\0${kind}#${number}`;
1939
+ return `${githubContext(repoRoot).key}\0${kind}#${number}`;
1953
1940
  }
1954
1941
  function cachedGithubComments(key, refresh) {
1955
1942
  const hit = commentsCache.get(key);
@@ -2238,18 +2225,18 @@ function mockGithubComments(kind, number) {
2238
2225
  }
2239
2226
  // ---- the driver -------------------------------------------------------------
2240
2227
  /**
2241
- * Cached availability probe so `GET /api/health` never pays a full listing. Keyed by repo root:
2228
+ * Cached availability probe so `GET /api/health` never pays a full listing. Keyed by GitHub context (root, host, account):
2242
2229
  * every registered project reads its own slot, so the boot project's constant health refresh can't
2243
2230
  * evict another project's answer (a single slot made `GET /automations` flap between "still being
2244
- * checked" and available). One in-flight probe per root dedupes a burst of reads.
2231
+ * checked" and available). One in-flight probe per context dedupes a burst of reads.
2245
2232
  */
2246
2233
  const DETECT_CACHE_MAX = 64;
2247
2234
  const detectCache = new Map();
2248
2235
  const detectInflight = new Map();
2249
- async function probeGithub(repoRoot) {
2236
+ async function probeGithub(repoRoot, context) {
2250
2237
  let result;
2251
2238
  try {
2252
- await gh(repoRoot, ['repo', 'view', '--json', 'nameWithOwner'], 5_000);
2239
+ await gh(repoRoot, ['repo', 'view', '--json', 'nameWithOwner'], 5_000, undefined, context);
2253
2240
  result = { available: true };
2254
2241
  }
2255
2242
  catch (err) {
@@ -2261,8 +2248,8 @@ async function probeGithub(repoRoot) {
2261
2248
  : firstLine(message),
2262
2249
  };
2263
2250
  }
2264
- detectCache.delete(repoRoot); // re-insert so Map order tracks recency
2265
- detectCache.set(repoRoot, { at: Date.now(), result });
2251
+ detectCache.delete(context.key); // re-insert so Map order tracks recency
2252
+ detectCache.set(context.key, { at: Date.now(), result });
2266
2253
  while (detectCache.size > DETECT_CACHE_MAX) {
2267
2254
  const oldest = detectCache.keys().next().value;
2268
2255
  if (oldest === undefined)
@@ -2274,14 +2261,15 @@ async function probeGithub(repoRoot) {
2274
2261
  async function detectGithub(repoRoot) {
2275
2262
  if (productEnv('DRY_RUN') === '1')
2276
2263
  return { available: true };
2277
- const hit = detectCache.get(repoRoot);
2264
+ const context = githubContext(repoRoot);
2265
+ const hit = detectCache.get(context.key);
2278
2266
  if (hit && Date.now() - hit.at < CACHE_MS)
2279
2267
  return hit.result;
2280
- const pending = detectInflight.get(repoRoot);
2268
+ const pending = detectInflight.get(context.key);
2281
2269
  if (pending)
2282
2270
  return pending;
2283
- const probe = probeGithub(repoRoot).finally(() => detectInflight.delete(repoRoot));
2284
- detectInflight.set(repoRoot, probe);
2271
+ const probe = probeGithub(repoRoot, context).finally(() => detectInflight.delete(context.key));
2272
+ detectInflight.set(context.key, probe);
2285
2273
  return probe;
2286
2274
  }
2287
2275
  /**
@@ -2306,7 +2294,7 @@ export const HEALTH_AVAILABILITY_TTL_MS = 10 * 60_000;
2306
2294
  export function detectGithubCached(repoRoot) {
2307
2295
  if (productEnv('DRY_RUN') === '1')
2308
2296
  return { available: true };
2309
- const hit = detectCache.get(repoRoot);
2297
+ const hit = detectCache.get(githubContext(repoRoot).key);
2310
2298
  const cached = hit?.result ?? null;
2311
2299
  const fresh = hit !== undefined && Date.now() - hit.at < HEALTH_AVAILABILITY_TTL_MS;
2312
2300
  if (!fresh) {
@@ -2386,11 +2374,11 @@ export function evictGithubProjectCaches(repoRoot) {
2386
2374
  mergeStateCache.delete(key);
2387
2375
  });
2388
2376
  commentsCache.forEach((_value, key) => {
2389
- if (key.startsWith(`${repoRoot}\0`))
2377
+ if (key.startsWith(`${contextKey}\0`))
2390
2378
  commentsCache.delete(key);
2391
2379
  });
2392
2380
  itemCache.forEach((_value, key) => {
2393
- if (key.startsWith(`${repoRoot}\0`))
2381
+ if (key.startsWith(`${contextKey}\0`))
2394
2382
  itemCache.delete(key);
2395
2383
  });
2396
2384
  }