@omercnet/paseo-pr-radar 3.3.0-next.530.1 → 3.3.0-next.532.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omercnet/paseo-pr-radar",
3
- "version": "3.3.0-next.530.1",
3
+ "version": "3.3.0-next.532.1",
4
4
  "type": "module",
5
5
  "description": "A viewer-aware delivery queue for pull requests linked to Paseo workspaces.",
6
6
  "license": "MIT",
@@ -479,6 +479,8 @@ interface Snapshot {
479
479
  reviewRequestedScope: string[];
480
480
  inboxItems: GitHubInboxItem[];
481
481
  issueItems: GitHubIssueItem[];
482
+ /** Every role whose search returned each issue; a row shows only the highest-ranked one. */
483
+ issueRoles: Map<string, Set<GitHubIssueItem["role"]>>;
482
484
  issueTruncated: boolean;
483
485
  issueSearchFailures: number;
484
486
  /** When each role's issue search last succeeded (ms); a role's kept issues age from here. */
@@ -518,11 +520,21 @@ async function fetchSnapshot(windowDays: number, previous?: Snapshot): Promise<S
518
520
  searchIssues("owner", viewer, since),
519
521
  ]);
520
522
  const issueMap = new Map<string, GitHubIssueItem>();
521
- for (const record of ownedIssues.records) issueMap.set(record.id, toIssueItem(record, "owner"));
522
- for (const record of assignedIssues.records)
523
- issueMap.set(record.id, toIssueItem(record, "assignee"));
524
- for (const record of authoredIssues.records)
525
- issueMap.set(record.id, toIssueItem(record, "author"));
523
+ const issueRoles = new Map<string, Set<GitHubIssueItem["role"]>>();
524
+ const addRole = (id: string, role: GitHubIssueItem["role"]) => {
525
+ const roles = issueRoles.get(id) ?? new Set<GitHubIssueItem["role"]>();
526
+ issueRoles.set(id, roles.add(role));
527
+ };
528
+ for (const [role, result] of [
529
+ ["owner", ownedIssues],
530
+ ["assignee", assignedIssues],
531
+ ["author", authoredIssues],
532
+ ] as const) {
533
+ for (const record of result.records) {
534
+ issueMap.set(record.id, toIssueItem(record, role));
535
+ addRole(record.id, role);
536
+ }
537
+ }
526
538
  const searchedAt = Date.now();
527
539
  const kept = previous?.viewer === viewer ? previous : undefined;
528
540
  const searches = [
@@ -545,14 +557,25 @@ async function fetchSnapshot(windowDays: number, previous?: Snapshot): Promise<S
545
557
  }
546
558
  }
547
559
  }
560
+ // A kept row keeps every role it matched whose search failed. A role whose search succeeded
561
+ // without it has dropped it, but another failed role's search may still hold it.
548
562
  for (const item of kept?.issueItems ?? []) {
549
- if (!keptRoles.has(item.role)) continue;
550
- const fresh = issueMap.get(item.id);
551
- if (!fresh) issueMap.set(item.id, item);
552
- // Fresh fields win, but the kept row remembers a higher-ranked role whose search failed.
553
- else if (ISSUE_ROLE_RANK[item.role] > ISSUE_ROLE_RANK[fresh.role]) {
554
- issueMap.set(item.id, { ...fresh, role: item.role });
563
+ let held = false;
564
+ for (const role of kept?.issueRoles.get(item.id) ?? [item.role]) {
565
+ if (!keptRoles.has(role)) continue;
566
+ addRole(item.id, role);
567
+ held = true;
555
568
  }
569
+ // Fresh fields win over the kept row's.
570
+ if (held && !issueMap.has(item.id)) issueMap.set(item.id, item);
571
+ }
572
+ // The row shows the highest-ranked role among all that matched.
573
+ for (const [id, item] of issueMap) {
574
+ const roles = [...(issueRoles.get(id) ?? [item.role])];
575
+ const role = roles.reduce((best, next) =>
576
+ ISSUE_ROLE_RANK[next] > ISSUE_ROLE_RANK[best] ? next : best,
577
+ );
578
+ issueMap.set(id, { ...item, role });
556
579
  }
557
580
  const issueTruncated = Object.values(issueTruncatedBy).some(Boolean);
558
581
  const issueSearchFailures = [authoredIssues, assignedIssues, ownedIssues].filter(
@@ -618,6 +641,7 @@ async function fetchSnapshot(windowDays: number, previous?: Snapshot): Promise<S
618
641
  reviewRequestedScope,
619
642
  inboxItems,
620
643
  issueItems,
644
+ issueRoles,
621
645
  issueTruncated,
622
646
  issueSearchFailures,
623
647
  issueFreshAt,
@@ -853,7 +853,21 @@ async function resolveIssueStartPoint(baseRoot: string, remote: string): Promise
853
853
  if (resolved) return resolved;
854
854
  }
855
855
  // One commit is checked and one is returned: another launch can move HEAD in between.
856
- const head = await runGit(baseRoot, ["rev-parse", "--verify", "HEAD^{commit}"], 3_000);
856
+ // `--quiet` makes an unborn HEAD (no commit yet) exit 1 without a message; a timeout or any
857
+ // other failure still surfaces as itself.
858
+ const head = await runGit(
859
+ baseRoot,
860
+ ["rev-parse", "--verify", "--quiet", "HEAD^{commit}"],
861
+ 3_000,
862
+ ).catch((err: unknown) => {
863
+ if ((err as { code?: unknown } | null)?.code === 1) return "";
864
+ throw err;
865
+ });
866
+ if (!head) {
867
+ throw new Error(
868
+ `Base checkout ${baseRoot} has no recorded default branch for ${remote} and no commit checked out yet; run git remote set-head ${remote} --auto there, or make a first commit on the default branch.`,
869
+ );
870
+ }
857
871
  const branch = await currentBranch(baseRoot);
858
872
  if (branch?.startsWith("pr-radar/")) {
859
873
  throw new Error(
@@ -953,7 +967,7 @@ async function populateNewWorktree(baseRoot: string, worktreePath: string): Prom
953
967
  } catch (checkoutError) {
954
968
  try {
955
969
  // No short timeout: the cleanup must be allowed to finish.
956
- await runGit(baseRoot, ["worktree", "remove", "--force", worktreePath]);
970
+ await runGit(baseRoot, ["worktree", "remove", "--force", "--", worktreePath]);
957
971
  } catch (removalError) {
958
972
  throw new AggregateError(
959
973
  [checkoutError, removalError],
@@ -967,27 +981,35 @@ async function populateNewWorktree(baseRoot: string, worktreePath: string): Prom
967
981
  /**
968
982
  * Launches whose workspace is being prepared right now, one entry per repository and item. Two
969
983
  * launches for the same item would race into the same clone, branch and worktree (a double click,
970
- * or two devices), so a second one is refused instead of queued: the queue stays empty, and the
971
- * first launch's result is what the user sees.
984
+ * or two devices), so a second identical request gets the running launch's promise and both see one
985
+ * result. A second request that differs (another directory or mode) is refused instead, since the
986
+ * running launch's result would not answer it.
972
987
  */
973
- const launchesInFlight = new Set<string>();
988
+ const launchesInFlight = new Map<
989
+ string,
990
+ { signature: string; result: Promise<z.output<typeof prepareWorkspaceCwd.output>> }
991
+ >();
974
992
 
975
- export async function prepareWorkspaceCwdHandler(
993
+ export function prepareWorkspaceCwdHandler(
976
994
  input: z.output<typeof prepareWorkspaceCwd.input>,
977
995
  readSettings: ReadWorkspaceSettings,
978
996
  ): Promise<z.output<typeof prepareWorkspaceCwd.output>> {
979
997
  const launchKey = `${input.repository.toLowerCase()}#${input.itemKind}-${input.prNumber}`;
980
- if (launchesInFlight.has(launchKey)) {
981
- throw new Error(
982
- `A launch for ${input.itemKind} #${input.prNumber} of ${input.repository} is already preparing its workspace; wait for it to finish, then try again.`,
998
+ const signature = JSON.stringify(input);
999
+ const running = launchesInFlight.get(launchKey);
1000
+ if (running) {
1001
+ if (running.signature === signature) return running.result;
1002
+ return Promise.reject(
1003
+ new Error(
1004
+ `A launch for ${input.itemKind} #${input.prNumber} of ${input.repository} is already preparing its workspace with different settings; wait for it to finish, then try again.`,
1005
+ ),
983
1006
  );
984
1007
  }
985
- launchesInFlight.add(launchKey);
986
- try {
987
- return await prepareLockedWorkspaceCwd(input, readSettings);
988
- } finally {
1008
+ const result = prepareLockedWorkspaceCwd(input, readSettings).finally(() => {
989
1009
  launchesInFlight.delete(launchKey);
990
- }
1010
+ });
1011
+ launchesInFlight.set(launchKey, { signature, result });
1012
+ return result;
991
1013
  }
992
1014
 
993
1015
  async function prepareLockedWorkspaceCwd(