@preventive/triage 1.0.0-alpha.65 → 1.0.0-alpha.67

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 (64) hide show
  1. package/common/bundle-imports.js +20 -0
  2. package/common/bundle-metadata.js +1 -1
  3. package/common/bundle-reasons.d.ts +4 -0
  4. package/common/bundle-reasons.js +38 -1
  5. package/common/bundle-sources.d.ts +1 -0
  6. package/common/bundle-sources.js +22 -0
  7. package/common/managed/npm-packages.js +3 -3
  8. package/common/managed/routes.js +23 -11
  9. package/common/managed/stasis-config.ts +7 -0
  10. package/out/activity.js +4 -4
  11. package/out/chunk-5F5FPI75.js +3 -0
  12. package/out/chunk-6ATPGDDI.js +1 -0
  13. package/out/chunk-6YGH7BJG.js +42 -0
  14. package/out/{chunk-ISXL3KOS.js → chunk-A5A3LEMV.js} +1 -1
  15. package/out/chunk-CGRIZ5M5.js +1 -0
  16. package/out/chunk-FUHRMY7R.js +247 -0
  17. package/out/{chunk-J2FWBXFV.js → chunk-LBJVV6UB.js} +1 -1
  18. package/out/chunk-LDO42LAC.js +1 -0
  19. package/out/{chunk-24AKGEH3.js → chunk-NB4JBTKK.js} +1 -1
  20. package/out/{chunk-IZ6MYRYB.js → chunk-R3WUYD4F.js} +1 -1
  21. package/out/chunk-U5C2TNNQ.js +52 -0
  22. package/out/chunk-VG5RH6KN.js +2 -0
  23. package/out/{chunk-XCWGOW63.js → chunk-VR3NRE5V.js} +1 -1
  24. package/out/chunk-WFDXHPT2.js +12 -0
  25. package/out/client-managed-import.js +2 -2
  26. package/out/client-managed.js +19 -19
  27. package/out/compare.js +15 -15
  28. package/out/dialogs.js +38 -38
  29. package/out/graph.js +8 -8
  30. package/out/index.html +9 -9
  31. package/out/scan.js +2 -2
  32. package/out/view.css +1 -1
  33. package/out/view.js +15 -15
  34. package/package.json +11 -8
  35. package/server-managed/activity.ts +21 -12
  36. package/server-managed/bundle-build-diagnostics.d.ts +1 -1
  37. package/server-managed/bundle-build-worker.js +84 -15
  38. package/server-managed/bundle-build.ts +95 -19
  39. package/server-managed/bundle-cache.ts +28 -6
  40. package/server-managed/bundle-dependency-reviews.ts +38 -22
  41. package/server-managed/commit-lockfiles.ts +2 -1
  42. package/server-managed/db-neon.ts +1 -1
  43. package/server-managed/dependency-review-comments.ts +31 -12
  44. package/server-managed/http.ts +127 -59
  45. package/server-managed/locked-packages.ts +34 -14
  46. package/server-managed/lockfile-scope.ts +10 -1
  47. package/server-managed/npm-kept.ts +10 -0
  48. package/server-managed/npm-patch.ts +127 -50
  49. package/server-managed/public-workspace.ts +3 -2
  50. package/server-managed/pull-dependencies.ts +55 -37
  51. package/server-managed/pull-dependency-reviews.ts +15 -11
  52. package/server-managed/report-sources.ts +6 -3
  53. package/server-managed/repository-issues.ts +14 -11
  54. package/server-managed/stasis-dependencies.ts +153 -0
  55. package/out/chunk-65PLAG3I.js +0 -12
  56. package/out/chunk-D34CUNO5.js +0 -247
  57. package/out/chunk-DCBXCBLL.js +0 -52
  58. package/out/chunk-F3UI65ZI.js +0 -42
  59. package/out/chunk-FAG6E5RC.js +0 -3
  60. package/out/chunk-PTFQKLKO.js +0 -1
  61. package/out/chunk-QVKFY4FA.js +0 -1
  62. package/out/chunk-SYXT3SFP.js +0 -2
  63. package/out/chunk-WL3SPQB4.js +0 -1
  64. /package/out/{chunk-WCPJDAYA.js → chunk-D6NVKGGG.js} +0 -0
@@ -19,13 +19,15 @@
19
19
  import { type CommitLockfiles, lockedIn } from './commit-lockfiles.ts'
20
20
  import type { LockedPackage } from './locked-packages.ts'
21
21
  import { MAX_LOCKED, type PullDependencies, lockedWith, lockfileFormat } from './pull-dependencies.ts'
22
- import { MAX_UNREVIEWED } from './pull-dependency-reviews.ts'
22
+ import { MAX_UNREVIEWED, hashesOf } from './pull-dependency-reviews.ts'
23
23
 
24
- // A version a bundle holds: its package's name and its version.
25
- export interface BundledVersion { name: string; version: string }
24
+ // A version a bundle holds: its package's name and its version; and, as a
25
+ // Stasis lockfile tells one (stasis-dependencies.ts), how it was installed:
26
+ // its tarball's integrity, and pnpm's hash of the patch applied to it.
27
+ export interface BundledVersion { name: string; version: string; integrity?: string; patch?: string }
26
28
 
27
- // The directory a lockfile at `path` is in, '' for the repository's root.
28
- const directoryOf = (path: string) => path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : ''
29
+ // The directory a file at `path` is in, '' for the repository's root.
30
+ export const directoryOf = (path: string) => path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : ''
29
31
  // A bundle's directory as one is compared: without the slashes either end.
30
32
  const bundleDirectory = (directory: string) => directory.replaceAll(/^\/+|\/+$/gu, '')
31
33
  const depth = (dir: string) => dir === '' ? 0 : dir.split('/').length
@@ -37,32 +39,46 @@ export function installsBundle(path: string, directory: string): boolean {
37
39
  return dir === '' || at === dir || at.startsWith(`${dir}/`)
38
40
  }
39
41
 
40
- // The versions `bundled` as `read`'s lockfiles (those installing the bundle,
41
- // read at `commit`) lock them, as one directory of a pull request's
42
- // lockfiles (pull-dependencies.ts) whose versions it adds none of, each as
43
- // the nearest of their directories locking it locks it, those past
44
- // MAX_LOCKED counted (`moreLocked`), and each lockfile left unread a
45
- // directory of its own failing the review; with those none lock
46
- // (`unlocked`, as many as MAX_UNREVIEWED, how many more `moreUnlocked`) and
47
- // how many versions it bundles (`versions`), each once.
48
- export function bundleDependencies(bundled: BundledVersion[], read: CommitLockfiles, commit: string) {
49
- const versions = [...new Map(bundled.map(one => [`${one.name}@${one.version}`, one])).values()]
42
+ // Whether `pkg` is locked as `one` was installed, where it tells how: with
43
+ // its tarball's integrity among its own, and its patch, or none.
44
+ const lockedAsInstalled = (one: BundledVersion, pkg: LockedPackage) => one.integrity !== undefined
45
+ && hashesOf(pkg).includes(one.integrity) && (pkg.patchHash ?? '') === (one.patch ?? '')
46
+
47
+ // The versions `bundled` as `read`'s lockfiles lock them (`locked`), each as
48
+ // the nearest of their directories locking it locks it; one told with how it
49
+ // was installed, as the nearest locking it so does, where one does. With
50
+ // those none lock (`unlocked`), how many versions there are (`versions`),
51
+ // and the lockfiles' paths, the nearest first.
52
+ export function lockedVersions(bundled: BundledVersion[], read: CommitLockfiles) {
50
53
  const byDirectory = Map.groupBy(read.lockfiles.map(({ path }) => path), directoryOf)
51
54
  // Each directory's versions by their name and version, the nearest first.
52
55
  const nearest = [...byDirectory].toSorted(([a], [b]) => depth(b) - depth(a)).map(([dir, paths]) =>
53
56
  ({ paths, locked: Map.groupBy(lockedIn(read, path => directoryOf(path) === dir).packages, pkg => `${pkg.name}@${pkg.version ?? ''}`) }))
54
57
  const found = new Map<string, LockedPackage>()
55
- const unlocked: BundledVersion[] = []
56
- for (const one of versions) {
58
+ const unlocked = new Map<string, BundledVersion>()
59
+ for (const one of bundled) {
57
60
  const key = `${one.name}@${one.version}`
58
- const variants = nearest.find(({ locked }) => locked.has(key))?.locked.get(key)
59
- if (!variants) { unlocked.push(one); continue }
61
+ const locking = nearest.flatMap(({ locked }) => locked.has(key) ? [locked.get(key)!] : [])
62
+ const variants = locking.map(locks => locks.filter(pkg => lockedAsInstalled(one, pkg))).find(locks => locks.length > 0) ?? locking[0]
63
+ if (!variants) { unlocked.set(key, { name: one.name, version: one.version }); continue }
60
64
  for (const pkg of variants) if (!found.has(lockedWith(pkg))) found.set(lockedWith(pkg), pkg)
61
65
  }
62
- const locked = [...found.values()]
66
+ return { locked: [...found.values()], unlocked: [...unlocked.values()], versions: new Set(bundled.map(one => `${one.name}@${one.version}`)).size,
67
+ paths: nearest.flatMap(({ paths }) => paths) }
68
+ }
69
+
70
+ // The versions `bundled` as `read`'s lockfiles (those installing the bundle,
71
+ // read at `commit`) lock them (lockedVersions), as one directory of a pull
72
+ // request's lockfiles (pull-dependencies.ts) whose versions it adds none of,
73
+ // those past MAX_LOCKED counted (`moreLocked`), and each lockfile left
74
+ // unread a directory of its own failing the review; with those none lock
75
+ // (`unlocked`, as many as MAX_UNREVIEWED, how many more `moreUnlocked`) and
76
+ // how many versions it bundles (`versions`), each once.
77
+ export function bundleDependencies(bundled: BundledVersion[], read: CommitLockfiles, commit: string) {
78
+ const { locked, unlocked, versions, paths } = lockedVersions(bundled, read)
63
79
  const told: PullDependencies = { base: commit, head: commit, cut: false, lockfiles: [
64
- { paths: nearest.flatMap(({ paths }) => paths), added: [], more: 0, locked: locked.slice(0, MAX_LOCKED), moreLocked: Math.max(0, locked.length - MAX_LOCKED) },
80
+ { paths, added: [], more: 0, locked: locked.slice(0, MAX_LOCKED), moreLocked: Math.max(0, locked.length - MAX_LOCKED) },
65
81
  ...read.unread.map(path => ({ paths: [path], error: lockfileFormat(path) === 'bun' ? 'lockfile-unsupported' : 'lockfile-unreadable' })),
66
82
  ] }
67
- return { told, versions: versions.length, unlocked: unlocked.slice(0, MAX_UNREVIEWED), moreUnlocked: Math.max(0, unlocked.length - MAX_UNREVIEWED) }
83
+ return { told, versions, unlocked: unlocked.slice(0, MAX_UNREVIEWED), moreUnlocked: Math.max(0, unlocked.length - MAX_UNREVIEWED) }
68
84
  }
@@ -59,7 +59,8 @@ export async function lockedAt(fullName: string, token: string, sha: string, kep
59
59
 
60
60
  // The versions those of `read`'s lockfiles `held` holds to lock, each once,
61
61
  // each patch's file from the repository's root (patchedIn), the first of
62
- // them that names one there, and their paths.
62
+ // them that names one there, with the directory of the first lockfile that
63
+ // locks it so, and their paths.
63
64
  export function lockedIn(read: CommitLockfiles, held: (path: string) => boolean = () => true) {
64
65
  const packages = new Map<string, LockedPackage>()
65
66
  const paths: string[] = []
@@ -292,7 +292,7 @@ export async function openPostgresManagedDb(leased: PgConnect, options: ManagedD
292
292
  for (const row of result.rows) {
293
293
  if (row[field.name] == null) continue
294
294
  const value = Number(row[field.name])
295
- if (!Number.isSafeInteger(value)) throw new Error('Managed integer exceeds safe range')
295
+ if (!Number.isSafeInteger(value)) throw new RangeError('Managed integer exceeds safe range')
296
296
  row[field.name] = value
297
297
  }
298
298
  }
@@ -2,16 +2,19 @@
2
2
  // button to give (reviewed-dependencies.ts `formatDependencyReviews`): of each
3
3
  // of one's reviews, as their lists and the review page show them
4
4
  // (`withFormatted`), and of those of the versions an open pull request adds
5
- // (`formattedPull`). It is given one's own published reviews alone, never
5
+ // (`formattedPull`), but the versions the host's `lookup` passes already,
6
+ // which want no review there, and those one's own comments there review
7
+ // alike already. It is given one's own published reviews alone, never
6
8
  // another's, a draft or a revoked one, however it is asked (`formatOwn`, the
7
9
  // only caller of the hook); and is told of none where it answers nothing, or
8
10
  // fails, which is logged.
9
11
  import type { DependencyReview, DependencyReviewStore } from './dependency-reviews.ts'
12
+ import type { LockedPackage } from './locked-packages.ts'
10
13
  import type { PullDependencies } from './pull-dependencies.ts'
11
- import { comparedWith, reviewsByVersion, reviewsOf } from './pull-dependency-reviews.ts'
14
+ import { askedOf, comparedWith, reviewsByVersion, reviewsOf } from './pull-dependency-reviews.ts'
12
15
  import { eachOf } from './queue.ts'
13
16
  import type { PublishedReview, RepoReviewState } from './repository-dependency-reviews.ts'
14
- import type { DependencyReviewEntry, ReviewedDependencies } from './reviewed-dependencies.ts'
17
+ import { type DependencyReviewEntry, type ReviewedDependencies, askReviewed } from './reviewed-dependencies.ts'
15
18
 
16
19
  const FORMAT_AT_ONCE = 8
17
20
  // The longest comment told, past which none is.
@@ -63,17 +66,21 @@ export function withFormatted<T extends DependencyReview>(reviewed: ReviewedDepe
63
66
  })
64
67
  }
65
68
 
66
- // The ids of those of `reviews` `user` published of the versions `told`
67
- // adds, as its lockfiles lock each: of its version, of an integrity it is
68
- // locked with and of its patch, whole or compared with a version it was
69
- // (pull-dependency-reviews.ts reviewsOf, comparedWith).
70
- function ownOfPull(told: PullDependencies, reviews: PublishedReview[], user: string): Set<string> {
69
+ // Those of `reviews` `user` published of the versions `told` adds, by their
70
+ // ids, each with the versions it is of, as its lockfiles lock each: of its
71
+ // version, of an integrity it is locked with and of its patch, whole or
72
+ // compared with a version it was (pull-dependency-reviews.ts reviewsOf,
73
+ // comparedWith).
74
+ interface Own { review: PublishedReview; pkgs: LockedPackage[] }
75
+ function ownOfPull(told: PullDependencies, reviews: PublishedReview[], user: string): Map<string, Own> {
71
76
  // Theirs by the version they are of, each version probed once.
72
77
  const theirs = reviewsByVersion(reviews.filter(review => review.id !== undefined && review.reviewer === user))
73
- const mine = new Set<string>()
78
+ const mine = new Map<string, Own>()
74
79
  if (theirs.size === 0) return mine
75
80
  for (const pkg of told.lockfiles.flatMap(dir => 'added' in dir ? dir.added : [])) {
76
- for (const review of reviewsOf(pkg, theirs)) if (comparedWith(review, pkg, pkg.was ?? [])) mine.add(review.id!)
81
+ for (const review of reviewsOf(pkg, theirs)) {
82
+ if (comparedWith(review, pkg, pkg.was ?? [])) (mine.get(review.id!) ?? mine.set(review.id!, { review, pkgs: [] }).get(review.id!)!).pkgs.push(pkg)
83
+ }
77
84
  }
78
85
  return mine
79
86
  }
@@ -81,12 +88,24 @@ function ownOfPull(told: PullDependencies, reviews: PublishedReview[], user: str
81
88
  // The comment the host formats of `user`'s reviews of the versions pull
82
89
  // request `number` of `repository` adds (`told`), those its review's state
83
90
  // tells of, published to a team counting for it; none where it has none.
91
+ // A review is left out where every version it is of, as locked, wants no
92
+ // comment of it there: the host's `lookup` passes it already, or `user`'s
93
+ // own comments there (of `commented`, the reviews its comments make) review
94
+ // it with the same verdict, as copying it would but repeat them: by their
95
+ // latest of it, which tells where they stand there (pull-dependency-
96
+ // reviews.ts stancesOf), an older one of that verdict not counting. A
97
+ // version `lookup` fails to answer of keeps its review.
84
98
  export async function formattedPull(reviewed: ReviewedDependencies | null, db: Pick<DependencyReviewStore, 'listOwnDependencyReviewsById'>, user: string,
85
- told: PullDependencies, state: RepoReviewState | null, pullRequest: { repository: string; number: number }): Promise<string | null> {
99
+ told: PullDependencies, state: RepoReviewState | null, pullRequest: { repository: string; number: number }, commented: PublishedReview[] = []): Promise<string | null> {
86
100
  if (!reviewed?.formatDependencyReviews || !state) return null
87
101
  const mine = ownOfPull(told, state.reviews, user)
88
102
  if (mine.size === 0) return null
89
- const ids = [...mine], reviews: DependencyReview[] = []
103
+ const { passed } = await askReviewed(reviewed.lookup, new Map([...mine.values()].flatMap(({ pkgs }) => pkgs.map(askedOf))))
104
+ const there = reviewsByVersion(commented.filter(review => review.reviewer === user))
105
+ const stands = (pkg: LockedPackage) => reviewsOf(pkg, there).reduce<PublishedReview | null>((one, other) => one && one.time >= other.time ? one : other, null)?.status
106
+ const ids = [...mine].filter(([, { review, pkgs }]) => pkgs.some(pkg => !passed.has(askedOf(pkg)[0]) && stands(pkg) !== review.status)).map(([id]) => id)
107
+ if (ids.length === 0) return null
108
+ const reviews: DependencyReview[] = []
90
109
  for (let at = 0; at < ids.length; at += REVIEWS_AT_ONCE) reviews.push(...await db.listOwnDependencyReviewsById(user, ids.slice(at, at + REVIEWS_AT_ONCE)))
91
110
  return formatOwn(reviewed, user, reviews, pullRequest)
92
111
  }
@@ -55,7 +55,7 @@
55
55
  // { pulls }, one GitHub fails told { number, error } | 400/401/403/404/409/429/502
56
56
  // GET /api/admin/repositories/branch-dependencies?repoId= → the versions the default branch's lockfiles lock that want review, where
57
57
  // its review is in effect for the reader, GitHub not asked where it reviews none | 400/401/403/404/409/429/502
58
- // GET /api/admin/repositories/lockfiles?repoId= → the lockfiles of the default branch its dependency review reads, by their
58
+ // GET /api/admin/repositories/lockfiles?repoId= → the lockfiles of the default branch its dependency review reads, and its stasis.config.json files, by their
59
59
  // paths, for its settings to name | 400/401/403/404/409/429/502
60
60
  // GET /api/admin/repositories/pulse?repoId=&weeks=1|4|13|52 → the default branch's commits and lines a week and a day over
61
61
  // the last year, its contributors and when in the period they commit, counted from its commits as Commits keeps them (how many are
@@ -75,7 +75,7 @@
75
75
  // POST /api/admin/reports/set-repo → admin|manage attaches/detaches a report's repo | 401/403/404
76
76
  // GET /api/admin/reports/<id>/location → admin|manage live location suggestion | 401/403/404/503
77
77
  // GET /api/bundles/<id>/{metadata,contents} → authorized encoded bytes | 401/404/422
78
- // GET /api/bundles/<id>/advisories → published dependency advisories (security access) | 401/403/404
78
+ // GET /api/bundles/<id>/advisories → published dependency advisories (security access), of one ?reason= or ?entry= point where given | 400/401/403/404
79
79
  // GET /api/bundles/<id>/dependency-review → what the npm versions it bundles want of review, as the lockfiles installing it lock
80
80
  // them at the commit it was built from, where its repository's review is in effect for a reader of all of it | 401/404/409/413/422/429/502
81
81
  // GET /api/bundles/<id>/validation → its last validation the reader may see, else none; POST validates it anew: its own code
@@ -148,7 +148,8 @@ import { pipeline } from 'node:stream/promises'
148
148
  import { setTimeout as delay } from 'node:timers/promises'
149
149
  import { type KeptStore, REPOSITORY_READ_KEPT_MS, authoredCommitStore, branchTipStore, bundleValidationStore, codeHeadStore, codeTreeStore, commitPullStore, githubTagStore, historyChangeStore, historyPageStore, historySquashStore, historyTreeStore,
150
150
  issueListStore, lockfileReadStore,
151
- npmDeltaStore, npmPublishTimeStore, npmVersionStore, ownKeptPrunes, pullDependencyStore, pullListStore, repositoryReadStore, reviewBaselineStore, riskLineStore, scanReadStore } from './npm-kept.ts'
151
+ npmDeltaStore, npmPublishTimeStore, npmVersionStore, ownKeptPrunes, patchStore, pullDependencyStore, pullListStore, repositoryReadStore, reviewBaselineStore, riskLineStore,
152
+ scanReadStore, stasisDependencyStore } from './npm-kept.ts'
152
153
  import { plainObject } from './npm-manifest.ts'
153
154
  import { type NpmDelta, deltaKey, keptNpmDeltas, npmDelta } from './npm-delta.ts'
154
155
  import { ADVISORIES_TIMEOUT_MS, fetchBundleAdvisories } from './bundle-advisories.ts'
@@ -225,12 +226,12 @@ import { teamAppKey, teamAppStates, withWorkspaceSummary } from './team-app.ts'
225
226
  import { hashToken, randomToken, safeEqual } from './crypto.ts'
226
227
  import { canDeleteComment, parseCommentBody } from '../common/managed/comments.ts'
227
228
  import { ManagedMutationError, reportReferenceSnapshot } from './management.ts'
228
- import { BundleBuildError, buildRepositoryBundle, parseBundleBuild, withBundleBuildLease } from './bundle-build.ts'
229
+ import { BundleBuildError, buildRepositoryBundle, buildRepositoryLockfile, parseBundleBuild, withBundleBuildLease } from './bundle-build.ts'
229
230
  import { NpmPackageError, type NpmReader, type NpmVersionDocument, type NpmVersionStore, VERSION_KEPT_MS, canReadPrivateNpm, npmFileRows, npmPublishTime, npmScopesCount, npmTarballFilename, readNpmVersion, readNpmVersions, readTogether } from './npm-packages.ts'
230
231
  import { loadNpmFiles, loadNpmPackageBody, loadNpmTarball } from './npm-loads.ts'
231
- import { type NpmPatch, type PatchedFile, patchedFiles, readPatch, requestedPatch } from './npm-patch.ts'
232
+ import { type ReadPatch, type RequestedPatch, patchedFiles, readPatch, requestedPatch, withPatchFiles } from './npm-patch.ts'
232
233
  import { type RepositoryCodeKept, loadRepositoryCodeBody, repositoryCodeFits, repositoryCodeKept } from './repository-code.ts'
233
- import { type ChangesStore, type CommitChanges, type CommitTree, TREES_READ, changesAsked, changesWithin, directoryFiles, repositoryChanges } from './repository-changes.ts'
234
+ import { type ChangesStore, type CommitChanges, type CommitTree, TREES_READ, changesAsked, changesWithin, directoryFiles, repositoryChanges, repositoryTree } from './repository-changes.ts'
234
235
  import { COAUTHORS_READ, coauthorsOf } from './commit-coauthors.ts'
235
236
  import { type AllHeads, type HistoryCommit, type HistoryPages, MAX_HISTORY_PAGE, historyFrom, historyStarts, openPullHeads,
236
237
  repositoryAllHeads, repositoryAllHistory, repositoryHistory, repositoryRefTips } from './repository-history.ts'
@@ -238,13 +239,14 @@ import { type KnownMerges, type SquashedPull, type Squashes, squashedPulls } fro
238
239
  import { AGENTS_READ_VERSION, type AuthoredCommit, type BranchTip, type BranchTips, COMMITS_CURSOR, type CommitPulls, repositoryAgents } from './repository-agents.ts'
239
240
  import { DEPENDENCIES_LABEL, ISSUES_CURSOR, ISSUES_READ_VERSION, OPEN_PULLS_READ, OPEN_PULLS_SIZES, repositoryIssues, repositoryItem, repositoryLabel, repositoryOpenPulls } from './repository-issues.ts'
240
241
  import { type GithubAsked, type ListedLockfile, type LockfileRead, type LockfileStore, MAX_LOCKED, PULL_DEPENDENCIES_READ, type PullCommits, type PullDependencies,
241
- type PullDependencyStore, lockfileFormat, pullDependenciesAt } from './pull-dependencies.ts'
242
+ type PullDependencyStore, type PullRefs, lockfileFormat, pullDependenciesAt, pullRefs } from './pull-dependencies.ts'
242
243
  import { eachOf } from './queue.ts'
243
244
  import { lockedAt, lockedIn, lockfilesAt } from './commit-lockfiles.ts'
244
- import { MAX_REQUIRED_REVIEWS, type RepoDependencyReview } from './repository-dependency-reviews.ts'
245
- import { EVERY_LOCKFILE, heldTo, reviewedIn, scopeOf } from './lockfile-scope.ts'
245
+ import { MAX_REQUIRED_REVIEWS, type PublishedReview, type RepoDependencyReview } from './repository-dependency-reviews.ts'
246
+ import { EVERY_LOCKFILE, type LockfileScope, heldTo, isStasisConfig, reviewedIn, scopeOf, stasisConfigs } from './lockfile-scope.ts'
247
+ import { type StasisDependencyReader, stasisDependencyReader, stasisDirectory, withReach } from './stasis-dependencies.ts'
246
248
  import { type BundledVersion, bundleDependencies, installsBundle } from './bundle-dependency-reviews.ts'
247
- import { type ReviewBaselineStore, baselineFor, heldDependencies, reviewedDependencies, reviewedPackages } from './pull-dependency-reviews.ts'
249
+ import { type CommentReviews, type ReviewBaselineStore, baselineFor, heldDependencies, reviewedDependencies, reviewedPackages } from './pull-dependency-reviews.ts'
248
250
  import { formattedPull, withFormatted } from './dependency-review-comments.ts'
249
251
  import type { ReviewedDependencies } from './reviewed-dependencies.ts'
250
252
  import { commentReviews } from './pull-comment-reviews.ts'
@@ -2006,17 +2008,22 @@ async function handleRepositoryChanges(res: ServerResponse, deps: ManagedHttpDep
2006
2008
  async function handleRepositoryTree(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, query: URLSearchParams): Promise<void> {
2007
2009
  const commit = query.get('commit') ?? ''
2008
2010
  if (!SHA.test(commit)) { sendJson(res, 400, { error: 'bad-request' }); return }
2009
- const store = historyTreeStore<CommitTree>(deps.db, deps.config.debug)
2010
2011
  await readForReplay(res, deps, cookie, query, async (fullName, token, repoId, path) => {
2011
- const kept = { read: async (sha: string) => {
2012
- const value = (await store.read(`${repoId}\0${TREES_READ}\0${sha}`))?.value
2013
- return value && Array.isArray(value.files) && Array.isArray(value.sizes) && value.sizes.length === value.files.length ? value : null
2014
- }, write: (sha: string, tree: CommitTree) => store.write(`${repoId}\0${TREES_READ}\0${sha}`, tree, Date.now()) }
2015
- const tree = await directoryFiles(fullName, token, commit, path, kept)
2012
+ const tree = await directoryFiles(fullName, token, commit, path, commitTreeKept(deps, repoId))
2016
2013
  return { commit, path, ...tree ?? { files: null, sizes: null, cut: false } }
2017
2014
  })
2018
2015
  }
2019
2016
 
2017
+ // The files repository `repoId`'s commits hold, each kept whole by the commit
2018
+ // and the rules it is read by (historyTreeStore, TREES_READ).
2019
+ function commitTreeKept(deps: ManagedHttpDeps, repoId: number) {
2020
+ const store = historyTreeStore<CommitTree>(deps.db, deps.config.debug)
2021
+ return { read: async (sha: string) => {
2022
+ const value = (await store.read(`${repoId}\0${TREES_READ}\0${sha}`))?.value
2023
+ return value && Array.isArray(value.files) && Array.isArray(value.sizes) && value.sizes.length === value.files.length ? value : null
2024
+ }, write: (sha: string, tree: CommitTree) => store.write(`${repoId}\0${TREES_READ}\0${sha}`, tree, Date.now()) }
2025
+ }
2026
+
2020
2027
  // What Replay reads of repository `repoId` within `path` (`read`, with its
2021
2028
  // name and the reader's token), as the history is read: with the reader's
2022
2029
  // own GitHub access, within their grants as the code is, a directory they
@@ -2386,15 +2393,19 @@ function sendRefusal(res: ServerResponse, { status, error, retryAfter }: Refusal
2386
2393
  // GitHub's failure `err`, as a request is refused for it: a token GitHub
2387
2394
  // rejects told as GitHub failing (502), never as the reader's session refused.
2388
2395
  const githubRefusal = (err: GithubApiError) => refusal(err.status === 401 ? 502 : err.status, err.message, err.retryAfter)
2389
- // The whole of repository `repoId`, where the session `cookie` names may
2396
+ // The whole of repository `repo`, where the session `cookie` names may
2390
2397
  // read all of it, and who reads it; else why not: none of it
2391
- // (`no-repository`), or only some (`no-directory`).
2398
+ // (`no-repository`), or only some (`no-directory`). `repo` its id, or its
2399
+ // name (`owner/name`), which the one connected repository its reader reads
2400
+ // answers to: one none has, or several, is none of theirs.
2392
2401
  type WholeAccess = { repo: SelectedRepo; user: StoredUser }
2393
- async function wholeRepositoryAccess(deps: ManagedHttpDeps, cookie: string | undefined, repoId: number, { handed = false } = {}): Promise<WholeAccess | Refusal> {
2402
+ async function wholeRepositoryAccess(deps: ManagedHttpDeps, cookie: string | undefined, repo: number | string, { handed = false } = {}): Promise<WholeAccess | Refusal> {
2394
2403
  const s = await readSession(deps.config, deps.db, cookie, Date.now(), { handed })
2395
2404
  if (s == null) return refusal(401, 'unauthenticated')
2396
2405
  if (!roleAtLeast(s.user.role, 'view')) return refusal(403, 'forbidden')
2397
- return wholeAccessIn(await repositoryGrants(deps, s.user), s.user, repoId)
2406
+ const grants = await repositoryGrants(deps, s.user)
2407
+ const ids = typeof repo === 'number' ? [repo] : grants.repos.filter(item => item.fullName.toLowerCase() === repo.toLowerCase()).map(item => item.repoId)
2408
+ return ids.length === 1 ? wholeAccessIn(grants, s.user, ids[0]!) : refusal(404, 'no-repository')
2398
2409
  }
2399
2410
  function wholeAccessIn(grants: Awaited<ReturnType<typeof repositoryGrants>>, user: StoredUser, repoId: number): WholeAccess | Refusal {
2400
2411
  const access = repositoryAccessIn(grants, repoId, '')
@@ -2424,18 +2435,20 @@ async function readWholeRepositoryOf<T>(deps: ManagedHttpDeps, access: WholeAcce
2424
2435
  }
2425
2436
  }
2426
2437
 
2427
- // The patch `patch` names (npm-patch.ts), read of the whole of its repository
2428
- // as readWholeRepositoryOf reads it, with its reader's own GitHub access, and
2429
- // held to its hash: as kept, else with that access checked again after; else
2430
- // why it was refused. Its failing to read or to apply throws.
2431
- async function npmPatchOf(deps: ManagedHttpDeps, cookie: string | undefined, patch: NpmPatch): Promise<{ files: PatchedFile[] } | Refusal> {
2438
+ // The patch `patch` names (npm-patch.ts), and where it was read (`source`),
2439
+ // read of the whole of its repository as readWholeRepositoryOf reads it,
2440
+ // with its reader's own GitHub access, and held to its hash: as kept, for
2441
+ // good (patchStore), else with that access checked again after; else why it
2442
+ // was refused. Its failing to read or to apply throws.
2443
+ async function npmPatchOf(deps: ManagedHttpDeps, cookie: string | undefined, patch: RequestedPatch): Promise<ReadPatch | Refusal> {
2432
2444
  const access = await wholeRepositoryAccess(deps, cookie, patch.repoId)
2433
2445
  if ('error' in access) return access
2446
+ const { repoId } = access.repo
2434
2447
  const read = await readWholeRepositoryOf(deps, access, async (fullName, token) => {
2435
2448
  const asked: GithubAsked = { github: false }
2436
- return { value: await readPatch(fullName, token, patch, asked), kept: !asked.github }
2437
- }, () => wholeRepositoryAccess(deps, cookie, patch.repoId))
2438
- return 'error' in read ? read : { files: read.value }
2449
+ return { value: await readPatch(fullName, token, { ...patch, repoId }, patchStore(deps.db, deps.config.debug), asked), kept: !asked.github }
2450
+ }, () => wholeRepositoryAccess(deps, cookie, repoId))
2451
+ return 'error' in read ? read : read.value
2439
2452
  }
2440
2453
  // The patch a request's fields name, as npm-patch.ts requestedPatch takes them.
2441
2454
  const patchFields = (field: (key: string) => unknown) => requestedPatch({ hash: field('patchHash'), repoId: field('patchRepoId'), commit: field('patchCommit'), path: field('patchPath') })
@@ -2568,11 +2581,12 @@ async function pullDependencyAnswer(deps: ManagedHttpDeps, fullName: string, tok
2568
2581
  commits?: PullCommits) {
2569
2582
  const kept = pullDependencyKept(deps, repoId)
2570
2583
  const reading: { told?: PullDependencies } = {}
2571
- const answered = commits ? { value: { commits: `${commits.base}...${commits.head}` }, kept: true }
2584
+ // With the branches they are of, where told, kept with them.
2585
+ const answered = commits ? { value: { baseRef: commits.baseRef, headRef: commits.headRef, commits: `${commits.base}...${commits.head}` }, kept: true }
2572
2586
  : await keptAnswer(deps, `${repoId}\0pull-commits\0${PULL_DEPENDENCIES_READ}\0${number}`, async () => {
2573
- const read = await pullDependenciesAt(fullName, token, number, kept)
2574
- reading.told = read.told
2575
- return { commits: read.commits }
2587
+ const { told, ...read } = await pullDependenciesAt(fullName, token, number, kept)
2588
+ reading.told = told
2589
+ return read
2576
2590
  }, undefined, false, stampOf(deps, repoId, fullName, token))
2577
2591
  // What its commits tell, as read, else as kept by them, else, no longer
2578
2592
  // kept, read again: by those given, without asking GitHub for them.
@@ -2581,7 +2595,13 @@ async function pullDependencyAnswer(deps: ManagedHttpDeps, fullName: string, tok
2581
2595
  // Where its review is on, those of lockfiles it leaves out told to none,
2582
2596
  // whoever asks.
2583
2597
  const setting = await deps.db.repoDependencyReview(repoId)
2584
- const scoped = setting?.enabled ? heldDependencies(pulled, setting.lockfiles) : pulled
2598
+ // With what the stasis.config.json files it holds to reach, each a
2599
+ // directory of its own, none waited for; a lockfile's versions those reach
2600
+ // not marked as its package manager's alone (withReach).
2601
+ const asked: GithubAsked = { github: false }
2602
+ const scoped = setting?.enabled ? withReach(heldDependencies({ ...pulled, lockfiles: [...pulled.lockfiles,
2603
+ ...await stasisDirectories(deps, fullName, token, repoId, setting.lockfiles, pulled.base, pulled.head, asked, pullRefs(answered.value.baseRef, answered.value.headRef))] },
2604
+ setting.lockfiles)) : pulled
2585
2605
  const now = review ? await deps.db.repoDependencyReviewState(repoId, user.id, reviewedPackages(scoped)) : null
2586
2606
  // Its review by the lockfiles they were told by, though they have changed
2587
2607
  // since; turned off meanwhile, all of them, as where it is off.
@@ -2594,11 +2614,52 @@ async function pullDependencyAnswer(deps: ManagedHttpDeps, fullName: string, tok
2594
2614
  // open (pull-comment-reviews.ts reads whether it is with them).
2595
2615
  const parse = reviewed?.parseComments
2596
2616
  const comments = state && parse ? commentReviews({ fullName, number, token, parse, reviewers: accounts => repoReviewers(deps, repoId, accounts) }) : null
2597
- // The comment the host formats of the reader's reviews of its versions, for its copy button.
2598
- const formatted = await formattedPull(reviewed, deps.db, user.id, told, state, { repository: fullName, number })
2599
- return { value: { number: told.number, ...await reviewedDependencies(told, state, { baseline, baselineUnread: unread, baselineError: error, reviewed, commentReviews: comments }),
2600
- ...formatted ? { formatted } : {} }, kept: answered.kept && held !== null }
2601
-
2617
+ // The reviews its comments make, as read for its review, the reader's own among them.
2618
+ const commented: PublishedReview[] = []
2619
+ const noting: CommentReviews | null = comments && (async wanting => {
2620
+ const read = await comments(wanting)
2621
+ commented.push(...read.reviews)
2622
+ return read
2623
+ })
2624
+ // Each patch its lockfiles name by its hash alone with its file (npm-patch.ts), where its review is in effect.
2625
+ const patched = state ? await withPatchFiles(told, repoId, fullName, token, patchStore(deps.db, deps.config.debug), asked) : told
2626
+ const dependencies = await reviewedDependencies(patched, state, { baseline, baselineUnread: unread, baselineError: error, reviewed, commentReviews: noting })
2627
+ // The comment the host formats of the reader's reviews of its versions, for
2628
+ // its copy button, but those its comments make of theirs already.
2629
+ const formatted = await formattedPull(reviewed, deps.db, user.id, told, state, { repository: fullName, number }, commented)
2630
+ return { value: { number: told.number, ...dependencies, ...formatted ? { formatted } : {} }, kept: answered.kept && held !== null && !asked.github }
2631
+ }
2632
+
2633
+ // What the stasis.config.json files repository `repoId`'s review holds to
2634
+ // (`scope`) have Stasis reach, each a directory of dependencies by its own
2635
+ // path (stasis-dependencies.ts stasisDirectory): at `head`, against `base`
2636
+ // where one is given. None is waited for: one not built yet is built behind
2637
+ // the answer (stasisReader), told the branch its commit is of where `refs`
2638
+ // names it, a pull request's head's, or its base's, which holds `base`.
2639
+ function stasisDirectories(deps: ManagedHttpDeps, fullName: string, token: string, repoId: number, scope: LockfileScope, base: string | null, head: string,
2640
+ asked: GithubAsked, refs: PullRefs = {}) {
2641
+ const reader = stasisReader(deps), reads = lockfileKept(deps, repoId)
2642
+ return Promise.all(stasisConfigs(scope).map(config => stasisDirectory(config, base, head,
2643
+ commit => reader.read({ repoId, fullName }, token, commit, config, commit === head ? refs.headRef : refs.baseRef),
2644
+ (commit, held) => lockedAt(fullName, token, commit, reads, held, asked))))
2645
+ }
2646
+
2647
+ // What reads repositories' Stasis dependencies, one a database: kept by it,
2648
+ // each built in the build worker under the deployment's lease
2649
+ // (buildRepositoryLockfile), behind the answer asking for it (trackBehind).
2650
+ const stasisReaders = new WeakMap<ManagedDb, StasisDependencyReader>()
2651
+ function stasisReader(deps: ManagedHttpDeps): StasisDependencyReader {
2652
+ let reader = stasisReaders.get(deps.db)
2653
+ if (!reader) {
2654
+ reader = stasisDependencyReader({
2655
+ store: stasisDependencyStore(deps.db, deps.config.debug),
2656
+ build: (input, github, token, signal) => buildRepositoryLockfile(deps.db, { input, github, token, cacheDir: deps.config.upstreamCacheDir ?? null }, signal),
2657
+ behind: work => { trackBehind(deps, work) },
2658
+ stopping: () => deps.isShuttingDown(),
2659
+ })
2660
+ stasisReaders.set(deps.db, reader)
2661
+ }
2662
+ return reader
2602
2663
  }
2603
2664
 
2604
2665
  // GET /api/admin/repositories/branch-dependencies: what the lockfiles of the
@@ -2633,10 +2694,14 @@ async function branchDependencyAnswer(deps: ManagedHttpDeps, fullName: string, t
2633
2694
  const reads = lockfileKept(deps, repoId)
2634
2695
  const read = await lockedAt(fullName, token, head, reads, path => heldTo(setting.lockfiles, path), asked)
2635
2696
  const { packages, paths } = lockedIn(read)
2636
- const told = { base: head, head, cut: false, lockfiles: [{ paths, added: [], more: 0, locked: packages.slice(0, MAX_LOCKED), moreLocked: Math.max(0, packages.length - MAX_LOCKED) },
2637
- ...read.unread.map(path => ({ paths: [path], error: lockfileFormat(path) === 'bun' ? 'lockfile-unsupported' : 'lockfile-unreadable' }))] }
2638
- const now = await deps.db.repoDependencyReviewState(repoId, user.id, reviewedPackages(told))
2697
+ // And what the stasis.config.json files it holds to reach there (stasisDirectories, withReach).
2698
+ const locked = withReach({ base: head, head, cut: false, lockfiles: [
2699
+ { paths, added: [], more: 0, locked: packages.slice(0, MAX_LOCKED), moreLocked: Math.max(0, packages.length - MAX_LOCKED) },
2700
+ ...read.unread.map(path => ({ paths: [path], error: lockfileFormat(path) === 'bun' ? 'lockfile-unsupported' : 'lockfile-unreadable' })),
2701
+ ...await stasisDirectories(deps, fullName, token, repoId, setting.lockfiles, null, head, asked)] }, read.lockfiles)
2702
+ const now = await deps.db.repoDependencyReviewState(repoId, user.id, reviewedPackages(locked))
2639
2703
  if (!now) return { value: { head, review: null }, kept: !asked.github }
2704
+ const told = await withPatchFiles(locked, repoId, fullName, token, patchStore(deps.db, deps.config.debug), asked)
2640
2705
  // Told by the lockfiles it held to as they were read, though they have
2641
2706
  // changed since.
2642
2707
  const state = { ...now, lockfiles: setting.lockfiles }
@@ -2649,13 +2714,16 @@ async function branchDependencyAnswer(deps: ManagedHttpDeps, fullName: string, t
2649
2714
  // GET /api/admin/repositories/lockfiles: the lockfiles of the repository's
2650
2715
  // default branch its dependency review reads (commit-lockfiles.ts), by their
2651
2716
  // paths, with their formats, at its head, as its pulse reads it, for its
2652
- // settings to name those it holds to (lockfile-scope.ts).
2717
+ // settings to name those it holds to (lockfile-scope.ts); and the
2718
+ // stasis.config.json files there (`configs`), which it may hold to as well.
2653
2719
  async function handleRepositoryLockfiles(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, query: URLSearchParams): Promise<void> {
2654
2720
  const repoId = askedRepoId(query)
2655
2721
  if (repoId === null) { sendJson(res, 400, { error: 'bad-request' }); return }
2656
2722
  await answerWholeRepository(res, deps, cookie, repoId, async (fullName, token) => {
2657
2723
  const head = (await defaultTip(deps, repoId, fullName, token)).sha
2658
- return { value: { head, lockfiles: head ? (await lockfilesAt(fullName, token, head, lockfileKept(deps, repoId))).map(({ path, format }) => ({ path, format })) : [] }, kept: false }
2724
+ if (!head) return { value: { head, lockfiles: [], configs: [] }, kept: false }
2725
+ const [lockfiles, tree] = await Promise.all([lockfilesAt(fullName, token, head, lockfileKept(deps, repoId)), repositoryTree(fullName, token, head, commitTreeKept(deps, repoId))])
2726
+ return { value: { head, lockfiles: lockfiles.map(({ path, format }) => ({ path, format })), configs: (tree?.files ?? []).filter(isStasisConfig) }, kept: false }
2659
2727
  })
2660
2728
  }
2661
2729
 
@@ -2826,10 +2894,10 @@ type OpenPullsPage = { items?: unknown; more?: unknown; after?: unknown; commits
2826
2894
  // Each open pull request's base's and head's commits a page of them names,
2827
2895
  // into `commits` by its number.
2828
2896
  function pageCommits(page: OpenPullsPage, commits: Map<number, PullCommits>) {
2829
- for (const pull of Array.isArray(page.commits) ? page.commits as { number?: unknown; base?: unknown; head?: unknown }[] : []) {
2830
- const { number, base, head } = pull ?? {}
2897
+ for (const pull of Array.isArray(page.commits) ? page.commits as { number?: unknown; base?: unknown; head?: unknown; baseRef?: unknown; headRef?: unknown }[] : []) {
2898
+ const { number, base, head, baseRef, headRef } = pull ?? {}
2831
2899
  if (Number.isSafeInteger(number) && typeof base === 'string' && SHA.test(base) && typeof head === 'string' && SHA.test(head)) {
2832
- commits.set(number as number, { base, head })
2900
+ commits.set(number as number, { base, head, ...pullRefs(baseRef, headRef) })
2833
2901
  }
2834
2902
  }
2835
2903
  }
@@ -3479,7 +3547,7 @@ async function handleBundleChanges(res: ServerResponse, deps: ManagedHttpDeps, s
3479
3547
 
3480
3548
  // Published dependency advisories require security access, independently of access to
3481
3549
  // unpublished dependency findings. Managers retain their normal bundle access.
3482
- async function handleBundleAdvisories(res: ServerResponse, deps: ManagedHttpDeps, session: ManagedSession, id: string, teamId: string | null, reason: string, repoAdvisories: boolean, details: boolean) {
3550
+ async function handleBundleAdvisories(res: ServerResponse, deps: ManagedHttpDeps, session: ManagedSession, id: string, teamId: string | null, reason: string, entry: string, repoAdvisories: boolean, details: boolean) {
3483
3551
  const authorize = async () => {
3484
3552
  const access = await deps.db.getBundleAccessSnapshot(session.id, Date.now(), id, teamId)
3485
3553
  if (!access) { sendJson(res, 401, { error: 'unauthenticated' }); return null }
@@ -3494,11 +3562,11 @@ async function handleBundleAdvisories(res: ServerResponse, deps: ManagedHttpDeps
3494
3562
  if (record.kind !== 'stasis') { sendJson(res, 422, { error: 'unsupported-bundle' }); return }
3495
3563
  if (!deps.bundleCache) { sendJson(res, 503, { error: 'unavailable' }); return }
3496
3564
  let inventory: BundleAdvisoryInventory | null | undefined
3497
- try { inventory = await deps.bundleCache.advisoryInventory(record, reason) }
3565
+ try { inventory = await deps.bundleCache.advisoryInventory(record, reason, entry) }
3498
3566
  catch { sendJson(res, 422, { error: 'bundle-unavailable' }); return }
3499
3567
  if (!(await authorize())) return
3500
3568
  if (inventory === null) { sendJson(res, 413, { error: 'payload-too-large' }); return }
3501
- if (inventory === undefined) { sendJson(res, 400, { error: 'unknown-reason' }); return }
3569
+ if (inventory === undefined) { sendJson(res, 400, { error: entry ? 'unknown-entry' : 'unknown-reason' }); return }
3502
3570
  if (Buffer.byteLength(JSON.stringify(inventory)) > MAX_PACKAGE_INVENTORY_BYTES) { sendJson(res, 413, { error: 'payload-too-large' }); return }
3503
3571
  const controller = new AbortController()
3504
3572
  const onClose = () => { if (!res.writableEnded) controller.abort() }
@@ -3596,9 +3664,10 @@ async function bundleDependencyAnswer(deps: ManagedHttpDeps, fullName: string, t
3596
3664
  const installing = (await lockfilesAt(fullName, token, commit, reads, asked)).map(({ path }) => path).filter(path => installsBundle(path, directory))
3597
3665
  if (!reviewedIn(setting.lockfiles, installing)) return { value: { review: null }, kept: !asked.github }
3598
3666
  const read = await lockedAt(fullName, token, commit, reads, path => installsBundle(path, directory) && heldTo(setting.lockfiles, path), asked)
3599
- const { told, ...bundle } = bundleDependencies(bundled, read, commit)
3600
- const now = await deps.db.repoDependencyReviewState(repoId, user.id, reviewedPackages(told), setting)
3667
+ const { told: locked, ...bundle } = bundleDependencies(bundled, read, commit)
3668
+ const now = await deps.db.repoDependencyReviewState(repoId, user.id, reviewedPackages(locked), setting)
3601
3669
  if (!now) return { value: { review: null }, kept: !asked.github }
3670
+ const told = await withPatchFiles(locked, repoId, fullName, token, patchStore(deps.db, deps.config.debug), asked)
3602
3671
  const state = { ...now, lockfiles: setting.lockfiles }
3603
3672
  const reviewed = deps.reviewedDependencies ?? null
3604
3673
  const { baseline, unread: baselineUnread, error } = reviewed ? { baseline: null, unread: [], error: null }
@@ -4867,10 +4936,10 @@ function reviewChange(res: ServerResponse, body: Record<string, unknown>): Revie
4867
4936
  // each change but a revocation loads both versions' files, of tarballs held
4868
4937
  // to their integrity and to their shasum where npm tells one (npm-loads.ts),
4869
4938
  // and the review keeps those shasums. A patched version's (`patchHash`) are
4870
- // its files as its patch changes them, the patch read where the request says
4871
- // (`patchRepoId`, `patchCommit`, `patchPath`), of the whole of a repository
4872
- // its reader reads (npmPatchOf), which the review keeps. Access to both
4873
- // versions is rechecked before returning or saving annotations.
4939
+ // its files as its patch changes them, the patch read as kept, else where the
4940
+ // request says (`patchRepoId`, `patchCommit`, `patchPath`), of the whole of a
4941
+ // repository its reader reads (npmPatchOf), the review keeping where it was
4942
+ // read. Access to both versions is rechecked before returning or saving annotations.
4874
4943
  async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, params: URLSearchParams): Promise<void> {
4875
4944
  const method = req.method ?? 'GET'
4876
4945
  if (!['GET', 'POST'].includes(method)) { send405(res, 'GET, POST'); return }
@@ -4930,8 +4999,7 @@ async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps:
4930
4999
  try {
4931
5000
  const files = await Promise.all(loads.map(load => load.result))
4932
5001
  if (loads.length > 0) {
4933
- tarballs = { shasum: doc.dist.shasum, baseShasum: base?.dist.shasum ?? null,
4934
- ...patchRead && patch ? { patch: { repoId: patch.repoId, commit: patch.commit, path: patch.path } } : {} }
5002
+ tarballs = { shasum: doc.dist.shasum, baseShasum: base?.dist.shasum ?? null, ...patchRead ? { patch: patchRead.source } : {} }
4935
5003
  }
4936
5004
  if (change?.action === 'publish' || change?.action === 'save') {
4937
5005
  const maps = files.map((list, at) => new Map<string, unknown>(npmFileRows(at === 0 && patchRead ? patchedFiles(list, patchRead.files) : list)
@@ -5268,7 +5336,7 @@ async function handleNpm(req: IncomingMessage, res: ServerResponse, deps: Manage
5268
5336
  if ('error' in patched) { sendRefusal(res, patched); return }
5269
5337
  const load = loadNpmFiles(doc)
5270
5338
  let body
5271
- try { body = await patchedVersionBody(doc, patch, patchedFiles(await load.result, patched.files)) } finally { load.release() }
5339
+ try { body = await patchedVersionBody(doc, { hash: patch.hash, ...patched.source }, patchedFiles(await load.result, patched.files)) } finally { load.release() }
5272
5340
  if (!(await recheck(doc.private))) { body.stream.destroy(); return }
5273
5341
  dropIdle(res)
5274
5342
  await sendEncoded(req, res, body, 'application/json')
@@ -5574,7 +5642,7 @@ export function createManagedRequestHandler(deps: ManagedHttpDeps): Handler {
5574
5642
  const bundleAdvisories = /^\/api\/bundles\/([a-f\d-]{36})\/advisories$/iu.exec(path)
5575
5643
  if (bundleAdvisories) {
5576
5644
  if (method !== 'GET') { send405(res, 'GET'); return }
5577
- await handleBundleAdvisories(res, deps, workspaceSession!.session, bundleAdvisories[1]!, url.searchParams.get('team'), url.searchParams.get('reason') ?? '', url.searchParams.get('repoAdvisories') === 'true', url.searchParams.get('details') === 'true')
5645
+ await handleBundleAdvisories(res, deps, workspaceSession!.session, bundleAdvisories[1]!, url.searchParams.get('team'), url.searchParams.get('reason') ?? '', url.searchParams.get('entry') ?? '', url.searchParams.get('repoAdvisories') === 'true', url.searchParams.get('details') === 'true')
5578
5646
  return
5579
5647
  }
5580
5648
  const bundleValidationRoute = /^\/api\/bundles\/([a-f\d-]{36})\/validation$/iu.exec(path)