@preventive/triage 1.0.0-alpha.72 → 1.0.0-alpha.74

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 (138) hide show
  1. package/common/bundle-compare-diff.d.ts +4 -1
  2. package/common/bundle-compare-diff.js +4 -3
  3. package/common/bundle-sources.d.ts +2 -0
  4. package/common/bundle-sources.js +22 -3
  5. package/common/finding-duplicates.js +5 -0
  6. package/common/finding-filters.js +45 -4
  7. package/common/line-diff.d.ts +2 -2
  8. package/common/line-diff.js +20 -8
  9. package/common/managed/finding-detail.js +1 -1
  10. package/common/managed/review-view-routes.js +23 -0
  11. package/common/managed/risk-routes.js +30 -0
  12. package/common/managed/routes.js +11 -6
  13. package/common/managed/team-app.d.ts +8 -6
  14. package/common/managed/team-app.js +15 -3
  15. package/common/stasis-files.d.ts +5 -0
  16. package/common/stasis-files.js +20 -0
  17. package/common/stasis-tgz.d.ts +6 -0
  18. package/common/stasis-tgz.js +27 -0
  19. package/common/workspace-app.js +20 -0
  20. package/out/activity.js +2 -4
  21. package/out/{chunk-2F3CYNPZ.js → chunk-2IHCVA3Y.js} +1 -1
  22. package/out/{chunk-HAZKDK4M.js → chunk-2V6Q4ZOZ.js} +1 -1
  23. package/out/{chunk-RRBIJL2B.js → chunk-4IW3VD3H.js} +1 -1
  24. package/out/chunk-4YZOXAXR.js +2 -0
  25. package/out/chunk-5YP7P5KA.js +1 -0
  26. package/out/chunk-62QT2RXR.js +6 -0
  27. package/out/chunk-6VOB5WXX.js +2 -0
  28. package/out/chunk-A4BBBHQU.js +1 -0
  29. package/out/{chunk-4ISO5F7Y.js → chunk-ADMVRLNP.js} +1 -1
  30. package/out/{chunk-HETCVNO4.js → chunk-BLPHP4U3.js} +1 -1
  31. package/out/{chunk-Y5ZHFNBD.js → chunk-BXQCCW7F.js} +1 -1
  32. package/out/chunk-C6OPCPCA.js +1 -0
  33. package/out/{chunk-JFL7WLRV.js → chunk-CU3FPB3P.js} +1 -1
  34. package/out/chunk-DQJEVHRE.js +52 -0
  35. package/out/chunk-ESJZZF2Y.js +255 -0
  36. package/out/{chunk-M37X4LCF.js → chunk-EXQQ5VQJ.js} +1 -1
  37. package/out/{chunk-NXATZJQ2.js → chunk-GSNSP3EF.js} +1 -1
  38. package/out/chunk-GV5U7OLP.js +40 -0
  39. package/out/{chunk-JOXLZXMI.js → chunk-GX5UXWT4.js} +1 -1
  40. package/out/chunk-HLMQ7QYS.js +1 -0
  41. package/out/{chunk-YF4M5OCI.js → chunk-I6UQQKAH.js} +1 -1
  42. package/out/{chunk-UCP3JRE2.js → chunk-LVW7WWV4.js} +1 -1
  43. package/out/chunk-NEFCZAIY.js +11 -0
  44. package/out/{chunk-TOXMUOIW.js → chunk-OQS2USZM.js} +1 -1
  45. package/out/chunk-PLF4LBLE.js +1 -0
  46. package/out/chunk-QBFT2DDR.js +1 -0
  47. package/out/{chunk-QMVOEBWC.js → chunk-S2ZIKK45.js} +1 -1
  48. package/out/chunk-S5HSDGTP.js +8 -0
  49. package/out/chunk-SSPDMA6D.js +1 -0
  50. package/out/{chunk-4XIH7YTX.js → chunk-UH6NZBSU.js} +1 -1
  51. package/out/{chunk-M3Y6SLC4.js → chunk-UJP4PQJA.js} +1 -1
  52. package/out/{chunk-PAD2JHZT.js → chunk-UJSJMXEG.js} +1 -1
  53. package/out/chunk-VRAJCPV5.js +3 -0
  54. package/out/chunk-VS7RV24Z.js +4 -0
  55. package/out/{chunk-E3LFSUDJ.js → chunk-VYYUMYVW.js} +1 -1
  56. package/out/chunk-W5PRH5D7.js +2 -0
  57. package/out/{chunk-VRX2APNA.js → chunk-XVKDPU4D.js} +1 -1
  58. package/out/{chunk-WKFBZYJX.js → chunk-YI4D6XVX.js} +1 -1
  59. package/out/client-managed-import.js +3 -3
  60. package/out/client-managed.js +30 -28
  61. package/out/compare.js +16 -23
  62. package/out/dialogs.js +38 -38
  63. package/out/graph.js +14 -14
  64. package/out/index.html +31 -51
  65. package/out/scan.js +2 -2
  66. package/out/terminal.js +239 -240
  67. package/out/view.css +1 -1
  68. package/out/view.js +15 -15
  69. package/package.json +21 -13
  70. package/risk/actions/resolve.js +47 -16
  71. package/risk/actions/uses.js +27 -9
  72. package/risk/actions/workflow.js +75 -2
  73. package/risk/files/hosts.js +4 -4
  74. package/risk/files/readability.js +5 -2
  75. package/risk/files/runs-code.js +12 -25
  76. package/risk/files/script.js +141 -19
  77. package/risk/index.d.ts +24 -7
  78. package/risk/index.js +1 -0
  79. package/risk/npm/assess.js +1 -1
  80. package/risk/npm/compare.js +5 -4
  81. package/risk/npm/diff.js +1 -1
  82. package/risk/npm/held.js +6 -2
  83. package/risk/npm/registry.js +5 -2
  84. package/risk/npm/tarball.js +79 -22
  85. package/server-managed/bundle-advisories.ts +12 -36
  86. package/server-managed/bundle-build-worker.js +29 -11
  87. package/server-managed/bundle-build.ts +4 -3
  88. package/server-managed/bundle-cache.ts +53 -13
  89. package/server-managed/bundle.ts +45 -13
  90. package/server-managed/comparison.ts +7 -6
  91. package/server-managed/db-methods.ts +54 -17
  92. package/server-managed/db-neon.ts +9 -2
  93. package/server-managed/db-schema.ts +12 -2
  94. package/server-managed/db.ts +4 -1
  95. package/server-managed/dependency-reviews.ts +8 -5
  96. package/server-managed/github-errors.ts +22 -0
  97. package/server-managed/github-requests.ts +4 -2
  98. package/server-managed/http.ts +238 -27
  99. package/server-managed/management.ts +10 -4
  100. package/server-managed/npm-delta.ts +1 -1
  101. package/server-managed/npm-loads.ts +2 -2
  102. package/server-managed/npm-packages.ts +34 -29
  103. package/server-managed/npm-patch-paths.ts +57 -0
  104. package/server-managed/npm-patch.ts +77 -82
  105. package/server-managed/package-entry-points.ts +54 -6
  106. package/server-managed/rename-diff-worker.js +11 -7
  107. package/server-managed/rename-diff.ts +5 -4
  108. package/server-managed/report-opening.ts +77 -0
  109. package/server-managed/report-sources.ts +2 -1
  110. package/server-managed/repository-aliases.ts +34 -0
  111. package/server-managed/repository-browser.ts +87 -32
  112. package/server-managed/repository-code.ts +14 -8
  113. package/server-managed/repository-dependency-reviews.ts +21 -0
  114. package/server-managed/repository-risk-read.ts +71 -4
  115. package/server-managed/repository-risk.ts +9 -2
  116. package/server-managed/stasis-config.ts +97 -5
  117. package/server-managed/team-reports.ts +5 -3
  118. package/server-managed/type-only-proof.js +26 -4
  119. package/server-managed/upstream-cache.ts +18 -12
  120. package/server-managed/workspace-shares.ts +4 -4
  121. package/out/chunk-27Y75UQR.js +0 -4
  122. package/out/chunk-4RS3NDOG.js +0 -1
  123. package/out/chunk-4XSH6ZLT.js +0 -1
  124. package/out/chunk-7CHIFYQW.js +0 -42
  125. package/out/chunk-CZ3U2LI4.js +0 -2
  126. package/out/chunk-ETL5ZPPR.js +0 -259
  127. package/out/chunk-L6VIWL2Y.js +0 -1
  128. package/out/chunk-OSHR3N4S.js +0 -3
  129. package/out/chunk-UD33S2MG.js +0 -52
  130. package/out/chunk-VG5RH6KN.js +0 -2
  131. package/out/chunk-WFDXHPT2.js +0 -12
  132. package/out/chunk-WMFDQS2L.js +0 -11
  133. package/out/chunk-WREU7JAG.js +0 -1
  134. /package/out/{chunk-4LZK6C6N.js → chunk-74JZTGTO.js} +0 -0
  135. /package/out/{chunk-JMG5DXII.js → chunk-7HP2VYIC.js} +0 -0
  136. /package/out/{chunk-HOB3YPS5.js → chunk-K4XJHM2T.js} +0 -0
  137. /package/out/{chunk-4EMM6UCD.js → chunk-QI66YA4F.js} +0 -0
  138. /package/out/{chunk-G3LY2FV4.js → chunk-WCDYSIKG.js} +0 -0
@@ -0,0 +1,77 @@
1
+ // Whether a stored report may be switched to open on Confirmed (Manage →
2
+ // Reports), told of its content alone: where its pass leaves Confirmed rows of
3
+ // its own but it is no App view on its own, by the stricter rule App mode
4
+ // keeps (common/workspace-app.js confirmedDefaultOffered). A switched report's
5
+ // findings count as covered wherever Confirmed would hide them
6
+ // (common/finding-filters.js confirmedCoverage), both for the outcome a view
7
+ // opens on and for its team's App mode.
8
+ //
9
+ // Read as a report is uploaded, and kept (managed_report confirmed_offered):
10
+ // its bytes never change. One uploaded before the column is read as the
11
+ // reports page lists it, a bounded share of them each time, or as its switch
12
+ // is asked for.
13
+ import { backfillFindingIds, reportEntries } from '@preventive/report'
14
+ import { readManagedReport } from '../common/managed/report-content.ts'
15
+ import { managedReportConfirmedDefaultOffered } from '../common/managed/team-app.js'
16
+ import type { BlobStore } from './blob-store.ts'
17
+ import type { ManagedDb } from './db.ts'
18
+ import { eachOf } from './queue.ts'
19
+
20
+ // Of a report's parsed content, its findings' IDs backfilled first as a team's
21
+ // are (team-reports.ts), which it changes in place. A report whose rows cannot
22
+ // be read this way has no switch to offer.
23
+ export async function confirmedDefaultOffered(filename: string, data: unknown): Promise<boolean> {
24
+ try {
25
+ const findings = (reportEntries(data) ?? []).flatMap(entry => Array.isArray(entry) ? entry : [entry])
26
+ .filter((finding): finding is Record<string, unknown> => finding !== null && typeof finding === 'object' && !Array.isArray(finding))
27
+ await backfillFindingIds(findings)
28
+ return managedReportConfirmedDefaultOffered(filename, data)
29
+ } catch (error) {
30
+ console.warn('managed: reading a report for its opening failed:', error)
31
+ return false
32
+ }
33
+ }
34
+
35
+ // Of a stored report, read of its blob: null where its bytes cannot be read
36
+ // now, so a later read tries again.
37
+ async function readStored(store: BlobStore, report: { id: string; filename: string }): Promise<boolean | null> {
38
+ const bytes = await store.get(report.id).catch(() => null)
39
+ if (!bytes) return null
40
+ const { data } = readManagedReport(bytes.toString('utf8'), report.filename)
41
+ return data == null ? false : confirmedDefaultOffered(report.filename, data)
42
+ }
43
+
44
+ // The same, kept.
45
+ export async function readConfirmedOffered(db: ManagedDb, store: BlobStore, report: { id: string; filename: string }): Promise<boolean | null> {
46
+ const offered = await readStored(store, report)
47
+ if (offered !== null) await db.setReportsConfirmedOffered([{ id: report.id, offered }])
48
+ return offered
49
+ }
50
+
51
+ // At most this many bytes of reports not read yet are read for one listing,
52
+ // two at a time, and kept in one write; the rest wait for the next.
53
+ const LISTING_READ_BYTES = 64 * 1024 * 1024
54
+ const LISTING_READS_AT_ONCE = 2
55
+
56
+ // The listed reports, those not read for their opening yet read, as many as
57
+ // fit the bound: the first always, however large.
58
+ export async function withConfirmedOffered<T extends { id: string; filename: string; byteSize: number; confirmedOffered: boolean | null }>(
59
+ db: ManagedDb, store: BlobStore, reports: readonly T[]): Promise<T[]> {
60
+ let budget = LISTING_READ_BYTES
61
+ const unread = reports.filter(report => {
62
+ if (report.confirmedOffered !== null || budget <= 0) return false
63
+ budget -= report.byteSize
64
+ return true
65
+ })
66
+ if (unread.length === 0) return [...reports]
67
+ const read = new Map<string, boolean>()
68
+ await eachOf(unread, LISTING_READS_AT_ONCE, async report => {
69
+ const offered = await readStored(store, report).catch((error: unknown) => {
70
+ console.warn('managed: reading a report for its opening failed:', error)
71
+ return null
72
+ })
73
+ if (offered !== null) read.set(report.id, offered)
74
+ })
75
+ if (read.size > 0) await db.setReportsConfirmedOffered([...read].map(([id, offered]) => ({ id, offered })))
76
+ return reports.map(report => read.has(report.id) ? { ...report, confirmedOffered: read.get(report.id)! } : report)
77
+ }
@@ -15,6 +15,7 @@ import type { BlobStore } from './blob-store.ts'
15
15
  import type { BundleStore } from './bundle-store.ts'
16
16
  import type { ManagedBundle, ManagedDb, ReportRecord } from './db.ts'
17
17
  import { inTurns } from './queue.ts'
18
+ import { ourRepositoryNames } from './repository-aliases.ts'
18
19
 
19
20
  const compress = promisify(gzip)
20
21
  const reportFormat = (filename: string) => extname(filename).toLowerCase()
@@ -88,7 +89,7 @@ async function lendSourcemapEdges(details: BundleDetails, bundle: ManagedBundle,
88
89
  // The repositories that are ours, so that a finding's `repo` none of them is
89
90
  // left out (common/finding-repo.js isStrayRepo).
90
91
  async function oursFor(db: ManagedDb, repo: { github: string | null }): Promise<Set<string>> {
91
- return ourRepoSlugs([...(await db.listSelectedRepos()).map(selected => selected.fullName), repo.github])
92
+ return ourRepoSlugs([...await ourRepositoryNames(db), repo.github])
92
93
  }
93
94
 
94
95
  // Immutable report hashes share a derivative across duplicate uploads. Bundle
@@ -22,6 +22,15 @@ export interface RepositoryAliasStore {
22
22
  saveRepositoryAlias(sessionId: string, id: string | null, input: unknown): Promise<RepositoryAlias>
23
23
  deleteRepositoryAlias(sessionId: string, id: string): Promise<void>
24
24
  getRepositoryImportLocation(github: string, directory: string, filePrefix?: string): Promise<{ repoId: number | null; directory: string }>
25
+ // Connected repository `repo.repoId`, which GitHub renamed or transferred
26
+ // since it was named `from`, named as GitHub names it now (`fullName`,
27
+ // `htmlUrl`), and `from` an alias of the whole of it, as reports and
28
+ // bundles made before name it: where GitHub still sends `from` to it
29
+ // (`redirected`) and nothing here has that name, no repository connected
30
+ // (active or not) nor an alias of a whole repository. Resolves whether it
31
+ // was renamed here: false where it is no longer named `from`, as where
32
+ // another request renamed it first.
33
+ renameRepository(repo: { repoId: number; fullName: string; htmlUrl: string }, from: string, redirected: boolean): Promise<boolean>
25
34
  }
26
35
 
27
36
  // Keep expensive inventory reads outside database transactions and skip them
@@ -36,6 +45,16 @@ export async function resolveRepositoryImportLocation(db: ManagedDb, github: str
36
45
  return db.getRepositoryImportLocation(github, directory, filePrefix)
37
46
  }
38
47
 
48
+ // The names our repositories go by: each active one's as connected, and each
49
+ // alias's of one of them, as reports from before a rename name it
50
+ // (renameRepository). For a finding's `repo` to tell ours by
51
+ // (common/finding-repo.js ourRepoSlugs).
52
+ export async function ourRepositoryNames(db: Pick<ManagedDb, 'listSelectedRepos' | 'listRepositoryAliases'>): Promise<string[]> {
53
+ const [repos, aliases] = await Promise.all([db.listSelectedRepos(), db.listRepositoryAliases()])
54
+ const active = new Set(repos.map(repo => repo.repoId))
55
+ return [...repos.map(repo => repo.fullName), ...aliases.filter(alias => active.has(alias.repoId)).map(alias => alias.oldRepo)]
56
+ }
57
+
39
58
  function parseAlias(input: unknown): RepositoryAliasInput {
40
59
  if (!input || typeof input !== 'object') throw new ManagedMutationError(400, 'bad-alias')
41
60
  const { oldRepo, oldPath, repoId, newPath } = input as RepositoryAliasInput
@@ -72,6 +91,21 @@ export function repositoryAliasMethods(db: ManagedSql): RepositoryAliasStore {
72
91
  await sessionAdmin(db, sessionId)
73
92
  if (!(await db.prepare('DELETE FROM managed_repository_alias WHERE id = ?').run(id)).changes) throw new ManagedMutationError(404, 'no-alias')
74
93
  },
94
+ async renameRepository(repo, from, redirected) {
95
+ if (!Number((await db.prepare('UPDATE managed_selected_repo SET full_name = ?, html_url = ?, updated_at = ? WHERE repo_id = ? AND full_name = ?')
96
+ .run(repo.fullName, repo.htmlUrl, Date.now(), repo.repoId, from)).changes)) return false
97
+ // Normalized as an administrator's is (parseAlias); none where only the
98
+ // name's case changed, which aliases never tell apart.
99
+ const old = reportRepoGithub({ repo: { github: from } })?.toLowerCase()
100
+ if (!redirected || !old || old === repo.fullName.toLowerCase()) return true
101
+ const taken = await db.prepare(`SELECT 1 AS taken FROM managed_selected_repo WHERE LOWER(full_name) = ?
102
+ UNION ALL SELECT 1 AS taken FROM managed_repository_alias WHERE old_repo = ? AND old_path = ''`).get(old, old)
103
+ if (!taken) {
104
+ await db.prepare(`INSERT INTO managed_repository_alias (id, old_repo, old_path, repo_id, new_path) VALUES (?, ?, '', ?, '')`)
105
+ .run(randomUUID(), old, repo.repoId)
106
+ }
107
+ return true
108
+ },
75
109
  async getRepositoryImportLocation(github, directory, filePrefix = '') {
76
110
  const alias = matchRepositoryAlias(github, directory, await listRepositoryAliases(), filePrefix)
77
111
  const normalized = normalizeTeamPath(alias?.directory ?? directory)
@@ -1,9 +1,9 @@
1
1
  import { createHash } from 'node:crypto'
2
2
  import type { ManagedConfig } from './config.ts'
3
3
  import type { SelectedRepo } from './db.ts'
4
- import { type GithubIdentity, READ_PERMISSIONS, githubRepoPermission, githubUserIdentity, repoAccessToken } from './github-app.ts'
5
- import { GithubApiError } from './github-errors.ts'
6
- import { encodedPath, githubJson, onTokenRejected, repoApi } from './github-requests.ts'
4
+ import { type GithubIdentity, READ_PERMISSIONS, githubRepoPermission, githubUserIdentity, publicRepositoryName, repoAccessToken } from './github-app.ts'
5
+ import { GithubApiError, isGithubMoved } from './github-errors.ts'
6
+ import { GITHUB_API, encodedPath, githubJson, onTokenRejected, repoApi } from './github-requests.ts'
7
7
  import { SHA } from './github-values.ts'
8
8
  import { MAX_PACKAGE_BYTES, readConfigEntryPoints, readPackageEntryPoints } from './package-entry-points.ts'
9
9
  import { MAX_STASIS_CONFIG_BYTES, STASIS_CONFIG } from './stasis-config.ts'
@@ -41,6 +41,16 @@ export function scopedDirectory(path: string, scopes: (string | null)[]): Reposi
41
41
 
42
42
  interface RepositoryBrowserUser { githubUserId: number | null; token: string | null }
43
43
 
44
+ // Told of a repository GitHub renamed or transferred since it was connected,
45
+ // once a reader has named it as GitHub names it now (`repo`, its `fullName`
46
+ // and `htmlUrl`): its name before (`from`), and whether GitHub still sends
47
+ // that name to it (`redirected`), as it does unless another repository has
48
+ // taken the name since. For the name to be kept (http.ts).
49
+ export type RepositoryRenamed = (repo: SelectedRepo, from: string, redirected: boolean) => Promise<void>
50
+
51
+ // A repository's page on GitHub, by its name.
52
+ export const githubRepositoryUrl = (fullName: string) => `https://github.com/${fullName}`
53
+
44
54
  function credentialFailure(err: unknown): err is GithubApiError {
45
55
  return err instanceof GithubApiError && ([401, 404].includes(err.status) || err.message === 'github-status-403')
46
56
  }
@@ -74,16 +84,20 @@ function verdictCache(config: ManagedConfig, user: RepositoryBrowserUser, repo:
74
84
  if (!(keepMs > 0)) return null
75
85
  const kept = accessVerdicts.get(fetchImpl) ?? new Map<string, AccessVerdict>()
76
86
  accessVerdicts.set(fetchImpl, kept)
77
- // The token hashed with the rest, never kept as it is.
78
- const key = createHash('sha256').update(JSON.stringify([user.githubUserId, user.token, repo.repoId, repo.fullName.toLowerCase(), repo.installationId, config.githubAppId])).digest('hex')
87
+ // The token hashed with the rest, never kept as it is; the repository by
88
+ // its name as the reader names it now (currentMetadata).
89
+ const keyed = () => createHash('sha256').update(JSON.stringify([user.githubUserId, user.token, repo.repoId, repo.fullName.toLowerCase(), repo.installationId,
90
+ config.githubAppId])).digest('hex')
79
91
  return {
80
92
  get() {
93
+ const key = keyed()
81
94
  const verdict = kept.get(key)
82
95
  if (verdict && verdict.until > Date.now()) return verdict
83
96
  kept.delete(key)
84
97
  return undefined
85
98
  },
86
99
  set(verdict) {
100
+ const key = keyed()
87
101
  kept.delete(key)
88
102
  kept.set(key, { ...verdict, until: Date.now() + keepMs, userToken: user.token ? hashed(user.token) : null })
89
103
  while (kept.size > MAX_ACCESS_VERDICTS) kept.delete(kept.keys().next().value!)
@@ -93,8 +107,11 @@ function verdictCache(config: ManagedConfig, user: RepositoryBrowserUser, repo:
93
107
 
94
108
  // Create once per HTTP request. Coalesce concurrent credential lookups, and
95
109
  // keep GitHub's answer on each user's access to each repository a while
96
- // (verdictCache), never sharing credentials or answers across users.
97
- export function createRepositoryBrowser(config: ManagedConfig, user: RepositoryBrowserUser, fetchImpl: typeof fetch = globalThis.fetch) {
110
+ // (verdictCache), never sharing credentials or answers across users. A
111
+ // repository GitHub renamed or transferred is read by the name GitHub gives
112
+ // it now, `renamed` told (currentMetadata).
113
+ export function createRepositoryBrowser(config: ManagedConfig, user: RepositoryBrowserUser, fetchImpl: typeof fetch = globalThis.fetch,
114
+ renamed?: RepositoryRenamed) {
98
115
  const tokens = new Map<number, Promise<string | null>>()
99
116
  let identity: Promise<GithubIdentity> | undefined
100
117
  // The user as GitHub tells them, asked once a request.
@@ -109,6 +126,9 @@ export function createRepositoryBrowser(config: ManagedConfig, user: RepositoryB
109
126
  return identity
110
127
  }
111
128
  return {
129
+ // A reader of `repo`, which, where GitHub renamed or transferred it,
130
+ // names `repo` as GitHub does now (its `fullName` and `htmlUrl`), for the
131
+ // reads a request makes of it beside the reader's.
112
132
  reader(repo: SelectedRepo) {
113
133
  const installationToken = () => {
114
134
  if (repo.installationId == null) return Promise.resolve(null)
@@ -124,7 +144,7 @@ export function createRepositoryBrowser(config: ManagedConfig, user: RepositoryB
124
144
  // Its Dependabot alerts, with the token of the installation GitHub tells
125
145
  // covers it, where the user's own access lets them see them
126
146
  // (dependabot-access.ts).
127
- return repositoryReader(repo, user.token, installationToken, getIdentity, fetchImpl, verdictCache(config, user, repo, fetchImpl)).then(reader => ({ ...reader,
147
+ return repositoryReader(repo, user.token, installationToken, getIdentity, fetchImpl, verdictCache(config, user, repo, fetchImpl), renamed).then(reader => ({ ...reader,
128
148
  dependabotAlerts: () => appDependabotAlerts(config, repo, { identity: getIdentity, permission: reader.permission }, fetchImpl) }))
129
149
  },
130
150
  }
@@ -151,27 +171,51 @@ export async function repositoryTreeFiles(fullName: string, token: string | null
151
171
 
152
172
  type Access = { data: RepoMetadata; token: string | null; level: string | null }
153
173
 
174
+ // The metadata of `repo` as GitHub has it now (`metadata`, of a URL): asked by
175
+ // its name, else, where GitHub moved that name (a rename or a transfer:
176
+ // github-moved) or names another repository by it since, by its id,
177
+ // which neither changes. Where GitHub names it otherwise now, `repo` is named
178
+ // so, and `renamed` told. Throws where GitHub tells of no repository of its id.
179
+ async function currentMetadata(repo: SelectedRepo, metadata: (url: string) => Promise<unknown>, renamed: RepositoryRenamed | undefined): Promise<RepoMetadata> {
180
+ let movedTo: number | null = null, named: RepoMetadata | null = null
181
+ try { named = await metadata(repoApi(repo.fullName)) as RepoMetadata } catch (err) {
182
+ if (!isGithubMoved(err)) throw err
183
+ movedTo = err.movedTo
184
+ }
185
+ const data = named?.id === repo.repoId ? named : await metadata(`${GITHUB_API}/repositories/${repo.repoId}`) as RepoMetadata
186
+ if (data?.id !== repo.repoId || typeof data.full_name !== 'string') throw new GithubApiError(404, 'no-repository')
187
+ if (data.full_name !== repo.fullName) {
188
+ // Only a name of GitHub's form is ever read by, or kept.
189
+ if (publicRepositoryName(data.full_name) !== data.full_name) throw new GithubApiError(502, 'github-malformed')
190
+ const from = repo.fullName
191
+ repo.fullName = data.full_name
192
+ repo.htmlUrl = githubRepositoryUrl(data.full_name)
193
+ await renamed?.(repo, from, movedTo === repo.repoId || named?.id === repo.repoId)
194
+ }
195
+ return data
196
+ }
197
+
154
198
  // GitHub asked whether the user may read `repo`: its metadata, read with
155
199
  // `token` (the reader's credential so far), else the installation's, else
156
- // none; and of one not public, the user's permission, read with the
157
- // installation's. What it told, the token reading it, and the level asked.
200
+ // none (currentMetadata, `repo` named as GitHub names it now); and of one not
201
+ // public, the user's permission, read with the installation's. What it told,
202
+ // the token reading it, and the level asked.
158
203
  async function askAccess(repo: SelectedRepo, start: string | null, userToken: string | null, installationToken: () => Promise<string | null>,
159
- getIdentity: () => Promise<GithubIdentity>, fetchImpl: typeof fetch): Promise<Access> {
160
- const base = repoApi(repo.fullName)
204
+ getIdentity: () => Promise<GithubIdentity>, fetchImpl: typeof fetch, renamed: RepositoryRenamed | undefined): Promise<Access> {
161
205
  let token = start
162
- const metadata = async () => {
163
- try { return await githubJson(base, token, fetchImpl) }
206
+ const metadata = async (url: string) => {
207
+ try { return await githubJson(url, token, fetchImpl) }
164
208
  catch (err) {
165
209
  if (!token || !credentialFailure(err)) throw err
166
210
  const fallback = await installationToken()
167
211
  if (fallback && fallback !== token) {
168
212
  token = fallback
169
- try { return await githubJson(base, token, fetchImpl) } catch (fallbackError) { if (!credentialFailure(fallbackError)) throw fallbackError }
213
+ try { return await githubJson(url, token, fetchImpl) } catch (fallbackError) { if (!credentialFailure(fallbackError)) throw fallbackError }
170
214
  }
171
215
  // Anonymous fallback is only for unavailable credentials, never rate
172
216
  // limits, network errors, or GitHub outages.
173
217
  token = null
174
- return githubJson(base, token, fetchImpl)
218
+ return githubJson(url, token, fetchImpl)
175
219
  }
176
220
  }
177
221
  // A repository last known private asks who the user is, and mints the
@@ -186,10 +230,7 @@ async function askAccess(repo: SelectedRepo, start: string | null, userToken: st
186
230
  }
187
231
  // Stored visibility can be stale (or internal with private=false). Require
188
232
  // current, explicit public visibility or the caller's effective permission.
189
- const data = await metadata() as RepoMetadata
190
- if (data?.id !== repo.repoId || typeof data.full_name !== 'string' || data.full_name.toLowerCase() !== repo.fullName.toLowerCase()) {
191
- throw new GithubApiError(404, 'no-repository')
192
- }
233
+ const data = await currentMetadata(repo, metadata, renamed)
193
234
  if (data.private === false && data.visibility === 'public') return { data, token, level: null }
194
235
  if (!token) throw new GithubApiError(404, 'no-repository')
195
236
  const appToken = await installationToken()
@@ -200,11 +241,11 @@ async function askAccess(repo: SelectedRepo, start: string | null, userToken: st
200
241
  }
201
242
 
202
243
  // GitHub's answer as kept (verdictCache), with the credential it chose,
203
- // where that credential is still had; else asked (`ask`), and kept where it
204
- // grants access.
244
+ // where that credential is still had, and not asked afresh (`fresh`); else
245
+ // asked (`ask`), and kept where it grants access.
205
246
  async function keptAccess(verdicts: VerdictCache | null, userToken: string | null, installationToken: () => Promise<string | null>,
206
- ask: () => Promise<Access>): Promise<Access> {
207
- const kept = verdicts?.get()
247
+ ask: () => Promise<Access>, fresh = false): Promise<Access> {
248
+ const kept = fresh ? undefined : verdicts?.get()
208
249
  if (kept) {
209
250
  const credential = kept.credential === 'user' ? userToken : kept.credential === 'app' ? await installationToken() : null
210
251
  if (kept.credential === 'none' || credential) return { data: kept.data, token: credential, level: kept.level }
@@ -217,25 +258,38 @@ async function keptAccess(verdicts: VerdictCache | null, userToken: string | nul
217
258
  }
218
259
 
219
260
  async function repositoryReader(repo: SelectedRepo, userToken: string | null, installationToken: () => Promise<string | null>, getIdentity: () => Promise<GithubIdentity>, fetchImpl: typeof fetch,
220
- verdicts: VerdictCache | null) {
221
- const base = repoApi(repo.fullName)
261
+ verdicts: VerdictCache | null, renamed: RepositoryRenamed | undefined) {
222
262
  // Public reads can use the signed-in user's quota without repository grants.
223
263
  // Nonpublic reads still require the repository App and the effective-user gate,
224
264
  // whose permission level is kept (`level`).
225
265
  let level: string | null = null, token = userToken ?? await installationToken()
226
- const read = (suffix: string) => githubJson(base + suffix, token, fetchImpl)
227
- const checkAccess = async (): Promise<RepoMetadata> => {
228
- const access = await keptAccess(verdicts, userToken, installationToken, () => askAccess(repo, token, userToken, installationToken, getIdentity, fetchImpl))
266
+ const checkAccess = async (fresh = false): Promise<RepoMetadata> => {
267
+ const access = await keptAccess(verdicts, userToken, installationToken, () => askAccess(repo, token, userToken, installationToken, getIdentity, fetchImpl, renamed),
268
+ fresh)
229
269
  token = access.token
230
270
  level = access.level
231
271
  return access.data
232
272
  }
273
+ // Each read by the name GitHub gives the repository now. Access kept from
274
+ // before GitHub moved that name (verdictCache) is asked again where a read
275
+ // finds it moved, once a reader, which finds the name it has now
276
+ // (currentMetadata); the read is made again by that name.
277
+ let asking: Promise<unknown> | undefined
278
+ const read = async (suffix: string) => {
279
+ const name = repo.fullName
280
+ try { return await githubJson(repoApi(name) + suffix, token, fetchImpl) } catch (err) {
281
+ if (!isGithubMoved(err)) throw err
282
+ await (asking ??= checkAccess(true))
283
+ if (repo.fullName === name) throw err
284
+ return githubJson(repoApi(repo.fullName) + suffix, token, fetchImpl)
285
+ }
286
+ }
233
287
  const current = await checkAccess()
234
288
  const defaultBranch = typeof current.default_branch === 'string' ? current.default_branch : ''
235
289
  return {
236
290
  // Its visibility and the user's permission asked again, the user as
237
291
  // GitHub told them earlier in the request, not asked again.
238
- recheckAccess: checkAccess,
292
+ recheckAccess: () => checkAccess(),
239
293
  // Server-only credential, selected by the same live visibility/permission
240
294
  // gate as directory browsing. Never included in an HTTP response.
241
295
  readToken: () => token,
@@ -286,9 +340,10 @@ async function repositoryReader(repo: SelectedRepo, userToken: string | null, in
286
340
  && item.type === 'file' && !item.submodule_git_url && typeof item.size === 'number' && item.size >= 0 && item.size <= maxBytes
287
341
  && typeof item.sha === 'string' && /^[a-f\d]{40}$/iu.test(item.sha))
288
342
  // The entries stasis.config.json lists are suggested before any guess:
289
- // a build takes them alone, with their options there.
343
+ // a build takes them alone, with their options there. Its patterns
344
+ // are matched in this listing, and the trees it names.
290
345
  const config = listed(STASIS_CONFIG, MAX_STASIS_CONFIG_BYTES)
291
- const configEntryPoints = config ? await readConfigEntryPoints(config.sha, path, read) : []
346
+ const configEntryPoints = config ? await readConfigEntryPoints(config.sha, path, read, data) : []
292
347
  if (configEntryPoints.length > 0) return { entries, limited: data.length >= 1000, configEntryPoints }
293
348
  const manifest = listed('package.json', MAX_PACKAGE_BYTES)
294
349
  // Both optional suggestions, read together: neither fails, each
@@ -13,7 +13,7 @@ import { CacheMissError, type CacheStorage } from './cache-storage.ts'
13
13
  import { SHA } from './github-values.ts'
14
14
  import type { KeptStore } from './npm-kept.ts'
15
15
  import { plainObject } from './npm-manifest.ts'
16
- import { MAX_NPM_JSON_LENGTH, NpmPackageError, npmFileRows } from './npm-packages.ts'
16
+ import { MAX_NPM_JSON_LENGTH, NpmPackageError, npmExecutablePaths, npmFileRows } from './npm-packages.ts'
17
17
  import { type NpmLoad, loadPlaces, readTarballFiles, sharedLoad } from './npm-loads.ts'
18
18
 
19
19
  // What a directory may hold, bounded apart from a package's (npm-packages.ts),
@@ -46,8 +46,11 @@ interface RepositoryCodeInput { repoId: number; repo: string; commit: string; pa
46
46
 
47
47
  // A package's refusals, as a directory's: past the bounds, or an archive
48
48
  // @preventive/archive refuses, as it does one holding a symlink that climbs
49
- // past the repository's root, or an absolute one.
50
- const DIRECTORY_ERRORS: Record<string, [number, string]> = { 'package-too-large': [413, 'directory-too-large'], 'bad-tarball': [422, 'directory-unreadable'] }
49
+ // past the repository's root, or an absolute one, or one readNpmTar does as
50
+ // installers would lay it out other than as one set of files, which GitHub's
51
+ // archives, under one top directory with no hard links, never are.
52
+ const DIRECTORY_ERRORS: Record<string, [number, string]> = { 'package-too-large': [413, 'directory-too-large'], 'bad-tarball': [422, 'directory-unreadable'],
53
+ 'tarball-conflict': [422, 'directory-unreadable'] }
51
54
  const directoryError = (err: unknown) => {
52
55
  const as = err instanceof NpmPackageError ? DIRECTORY_ERRORS[err.message] : undefined
53
56
  return as ? new NpmPackageError(...as) : err
@@ -69,16 +72,19 @@ export function loadRepositoryCodeBody(input: RepositoryCodeInput, tarball: (sym
69
72
  const places = loadPlaces(listed)
70
73
  const maxLength = Math.min(MAX_REPOSITORY_CODE_JSON_LENGTH, places * MAX_NPM_JSON_LENGTH)
71
74
  return sharedLoad(`repository ${repoId} ${repo} ${commit} ${path} ${tree}`, async () => {
72
- let files
73
- try { files = npmFileRows(await readTarballFiles(await tarball(symlinksAbove), { ...REPOSITORY_TAR, symlinksAbove }), maxLength) }
74
- catch (err) { throw directoryError(err) }
75
- return encodeBrotli(Buffer.from(JSON.stringify({ repoId, repo, commit, path, tree, files })))
75
+ let executable, files
76
+ try {
77
+ const read = await readTarballFiles(await tarball(symlinksAbove), { ...REPOSITORY_TAR, symlinksAbove })
78
+ files = npmFileRows(read, maxLength)
79
+ executable = npmExecutablePaths(read)
80
+ } catch (err) { throw directoryError(err) }
81
+ return encodeBrotli(Buffer.from(JSON.stringify({ repoId, repo, commit, path, tree, files, executable })))
76
82
  }, 'repository-busy', { places })
77
83
  }
78
84
 
79
85
  // The form of the bodies kept, bumped as what a body holds changes
80
86
  // (npmFileRows): one kept in another is none to read.
81
- const KEPT_CODE_VERSION = 1
87
+ const KEPT_CODE_VERSION = 3
82
88
  // The largest body kept. Source text runs, as brotli's JSON, to a third of
83
89
  // its bytes or less, and a directory's binary files are named, not held, so
84
90
  // this keeps one of some 200 MiB of text: nearly every directory that opens
@@ -62,6 +62,10 @@ export interface RepositoryDependencyReviewStore {
62
62
  // Which of `users` publish reviews to a team counting for repository
63
63
  // `repoId`, whose reviews its pull requests' comments make count.
64
64
  listRepoReviewers(repoId: number, users: string[]): Promise<Set<string>>
65
+ // Those of `versions` whose reviews published to a team counting for any of
66
+ // `repoIds` were published, to it or to one more team, or revoked, at
67
+ // `since` or after, each once.
68
+ changedReviewVersions(repoIds: number[], since: number, versions: ReviewedVersionKey[]): Promise<ReviewedVersionKey[]>
65
69
  }
66
70
 
67
71
  type SettingRow = { repoId: number; enabled: number; required: number; since: string | null; lockfiles: string | null }
@@ -148,6 +152,23 @@ export function repositoryDependencyReviewMethods(db: ManagedSql): RepositoryDep
148
152
  WHERE u.id IN (${users.map(() => '?').join(',')}) AND ${reviewsIn(true)} AND ${COUNTING_TEAM}`).all(...users, repoId) as { id: string }[]
149
153
  return new Set(rows.map(row => row.id))
150
154
  },
155
+ async changedReviewVersions(repoIds, since, versions) {
156
+ if (repoIds.length === 0) return []
157
+ const found = new Map<string, ReviewedVersionKey>()
158
+ for (let at = 0; at < versions.length; at += VERSIONS_AT_ONCE) {
159
+ const asked = versions.slice(at, at + VERSIONS_AT_ONCE)
160
+ const keys = new Set(asked.map(({ name, version }) => `${name}@${version}`))
161
+ const [names, numbers] = [[...new Set(asked.map(({ name }) => name))], [...new Set(asked.map(({ version }) => version))]]
162
+ const rows = await db.prepare(`SELECT DISTINCT r.package AS name, r.version FROM managed_dependency_review r
163
+ WHERE r.ecosystem = 'npm' AND r.published_at IS NOT NULL AND (r.published_at >= ? OR r.shared_at >= ? OR r.revoked_at >= ?)
164
+ AND r.package IN (${names.map(() => '?').join(',')}) AND r.version IN (${numbers.map(() => '?').join(',')})
165
+ AND EXISTS (SELECT 1 FROM managed_dependency_review_team rt JOIN managed_team t ON t.id = rt.team_id JOIN managed_team_repo tr ON tr.team_id = t.id
166
+ WHERE rt.review_id = r.id AND t.hidden = 0 AND t.dependency_review = 1 AND tr.repo_id IN (${repoIds.map(() => '?').join(',')}))`)
167
+ .all(since, since, since, ...names, ...numbers, ...repoIds) as ReviewedVersionKey[]
168
+ for (const row of rows) if (keys.has(`${row.name}@${row.version}`)) found.set(`${row.name}@${row.version}`, row)
169
+ }
170
+ return [...found.values()]
171
+ },
151
172
  async repoDependencyReviewState(repoId, user, versions, read) {
152
173
  const now = read === undefined ? await readSetting(repoId) : read
153
174
  if (!now?.enabled) return null
@@ -4,8 +4,10 @@
4
4
  // each read for its packages (@preventive/lockfile), and access to it checked
5
5
  // again before they are told (`recheck`); and its Dependabot alerts, open or dismissed, of
6
6
  // npm's, where the source asks them (dependabot-alerts.ts), asked meanwhile
7
- // and never kept, a failure to have them its own, and its GitHub Actions
8
- // (repository-actions.ts). A listing is kept by the commit it was listed at,
7
+ // and never kept, a failure to have them its own, its GitHub Actions
8
+ // (repository-actions.ts), and what Stasis reaches of each of its
9
+ // stasis.config.json files, where the source reads them
10
+ // (StasisConfigsRead). A listing is kept by the commit it was listed at,
9
11
  // its Actions' files too, and a lockfile's packages by its blob: in the
10
12
  // instance's memory, and the source's `listings`, `actionFiles` and
11
13
  // `lockfiles` for SCAN_READ_KEPT_MS, so that only opening a repository and
@@ -20,6 +22,9 @@ import { inTurns } from './queue.ts'
20
22
  import { type WorkflowsRead, lastingRead, readActions } from './repository-actions.ts'
21
23
  import { type RiskFailure, failureOf } from './repository-risk-assess.ts'
22
24
  import type { LockfileLine, RepositoryRiskLine, RepositoryRiskRepo } from './repository-risk.ts'
25
+ import type { StasisDependency } from './bundle-build.ts'
26
+ import { isStasisConfig } from './lockfile-scope.ts'
27
+ import type { StasisRead } from './stasis-dependencies.ts'
23
28
 
24
29
  // The formats of npm's ecosystem, as findRepoLockfiles names them, and those
25
30
  // of them read here.
@@ -40,6 +45,22 @@ export type LockfileRead = { packages: LockedPackage[] } | RiskFailure
40
45
  // be had.
41
46
  export type DependabotRead = { alerts: DependabotAlert[]; recheck?(): Promise<void> } | RiskFailure
42
47
  export type RepositoryFailure = Extract<RepositoryRiskLine, { type: 'repo'; error: string }>
48
+ // What Stasis reaches of a stasis.config.json, as a dependency review's
49
+ // build of it tells (stasis-dependencies.ts): the versions it installs
50
+ // (`dependencies`), that its build is still to be made (`pending`), or why it
51
+ // failed.
52
+ // `lockfiles`, those its `lockfiles` names, from the repository's root,
53
+ // where it names some: those its builds install from (namedLockfiles).
54
+ export type StasisConfigRow = { path: string; lockfiles?: string[] } & ({ dependencies: StasisDependency[] } | { pending: true } | RiskFailure)
55
+ // A repository's stasis.config.json files, those of its `paths` alone, each
56
+ // what Stasis reaches of it, or why they couldn't be listed.
57
+ export type StasisConfigsRead = { configs: StasisConfigRow[] } | RiskFailure
58
+
59
+ // A config's row of its read: a failed build told by its code (`detail`).
60
+ export function stasisConfigRow(path: string, read: StasisRead): StasisConfigRow {
61
+ if (read.status === 'ready') return { path, dependencies: read.dependencies }
62
+ return read.status === 'pending' ? { path, pending: true } : { path, error: 'stasis-failed', detail: read.error }
63
+ }
43
64
 
44
65
  // A repository opened at its default branch's head (`commit`): its lockfiles,
45
66
  // as findRepoLockfiles lists them, each with its blob's id, and a file's
@@ -54,6 +75,12 @@ export interface OpenedRepository {
54
75
  dependabot?(): Promise<AlertsRead>
55
76
  // Its workflows' paths, none where it has none.
56
77
  workflows?(): Promise<string[]>
78
+ // Its files' paths at `commit`, of which its stasis.config.json files are
79
+ // told (isStasisConfig); and what Stasis reaches of the one at `config`,
80
+ // as a dependency review's reader has it (stasis-dependencies.ts), its
81
+ // build asked for where none is kept yet, never waited for.
82
+ files?(): Promise<string[]>
83
+ stasis?(config: string): Promise<StasisRead>
57
84
  }
58
85
 
59
86
  // What a repository is read with: the scan's source and caches, and its
@@ -74,6 +101,8 @@ export interface RepositoryRead {
74
101
  dependabot: DependabotRead | null
75
102
  // Its Actions' files, where it lists its workflows.
76
103
  actions: WorkflowsRead | null
104
+ // Its stasis.config.json files, where it has some and the source reads them.
105
+ stasis: StasisConfigsRead | null
77
106
  recheck(): Promise<void>
78
107
  }
79
108
 
@@ -143,8 +172,44 @@ async function readDependabot(opened: OpenedRepository, paths: readonly string[]
143
172
  }
144
173
  }
145
174
 
175
+ // A repository's stasis.config.json files of its `paths` (RepositoryRiskRepo),
176
+ // as its lockfiles are, each what Stasis reaches of it; or why they couldn't
177
+ // be listed; null where it has none, or the source reads none.
178
+ async function readStasis(opened: OpenedRepository, paths: readonly string[] | undefined): Promise<StasisConfigsRead | null> {
179
+ const { files, stasis } = opened
180
+ if (!files || !stasis) return null
181
+ let configs
182
+ try { configs = (await files()).filter(path => isStasisConfig(path) && lockfileOf(path, paths)) } catch (error) {
183
+ return failureOf(error, 'listing its stasis.config.json files')
184
+ }
185
+ if (configs.length === 0) return null
186
+ return { configs: await Promise.all(configs.map(async path => {
187
+ const lockfiles = await opened.file(path).then(namedLockfiles(path), () => null)
188
+ try { return { ...stasisConfigRow(path, await stasis(path)), ...lockfiles && { lockfiles } } } catch (error) { return { path, ...failureOf(error) } }
189
+ })) }
190
+ }
191
+
192
+ // The lockfiles a stasis.config.json at `path` names (`lockfiles`), from its
193
+ // directory, as Stasis installs from those alone, each from the repository's
194
+ // root; null where it names none, or isn't JSON, or one is out of the
195
+ // repository.
196
+ export const namedLockfiles = (path: string) => (text: string): string[] | null => {
197
+ let named: unknown
198
+ try { named = (JSON.parse(text) as { lockfiles?: unknown } | null)?.lockfiles } catch { return null }
199
+ if (!Array.isArray(named) || named.length === 0 || !named.every(each => typeof each === 'string' && each !== '')) return null
200
+ const resolved = (named as string[]).map(each => {
201
+ const parts = path.split('/').slice(0, -1)
202
+ for (const part of each.split('/')) {
203
+ if (part === '..') { if (parts.pop() === undefined) return null } else if (part !== '' && part !== '.') parts.push(part)
204
+ }
205
+ return parts.join('/')
206
+ })
207
+ return resolved.every(Boolean) ? resolved as string[] : null
208
+ }
209
+
146
210
  // A repository read: its lockfiles listed and read, a few at once, its
147
- // Dependabot alerts asked and its Actions read meanwhile; its line telling why where listing
211
+ // Dependabot alerts asked, its Actions read and its stasis.config.json files
212
+ // asked meanwhile; its line telling why where listing
148
213
  // failed; null where the scan stopped. A test's
149
214
  // fixture or example its reader refuses (isTestFixture) is left out, as a
150
215
  // test may keep one so on purpose.
@@ -153,6 +218,7 @@ export async function readRepository<R extends RepositoryRiskRepo>(reading: Repo
153
218
  if (!listed || 'type' in listed) return listed
154
219
  const { opened } = listed
155
220
  const alerting = readDependabot(opened, repo.paths)
221
+ const reaching = readStasis(opened, repo.paths)
156
222
  const { workflows } = opened
157
223
  const acting = workflows ? keptRead(reading.caches.actionFiles, reading.source.actionFiles, `${repo.repoId}@${opened.commit}`,
158
224
  () => readActions({ workflows, file: path => opened.file(path) }), lastingRead) : Promise.resolve(null)
@@ -166,5 +232,6 @@ export async function readRepository<R extends RepositoryRiskRepo>(reading: Repo
166
232
  }
167
233
  const dependabot = await alerting
168
234
  const actions = await acting
169
- return reading.signal.aborted ? null : { commit: opened.commit, lockfiles, dependabot, actions, recheck: () => opened.recheck() }
235
+ const stasis = await reaching
236
+ return reading.signal.aborted ? null : { commit: opened.commit, lockfiles, dependabot, actions, stasis, recheck: () => opened.recheck() }
170
237
  }
@@ -25,7 +25,12 @@
25
25
  // lockfile locks that it covers, for the page to blend them into npm's; one
26
26
  // whose alerts couldn't be had tells why, and the scan goes on. Its GitHub
27
27
  // Actions are told once its lockfiles are, the references they make
28
- // resolved as the scan goes on (repository-actions.ts).
28
+ // resolved as the scan goes on (repository-actions.ts). And what Stasis
29
+ // reaches of each of its stasis.config.json files, as its dependency review
30
+ // has a build tell it (stasis-dependencies.ts), told once its lockfiles are:
31
+ // the versions a build installs, or that it is still to be made, which isn't
32
+ // waited for, its page asking for it again (GET
33
+ // /api/admin/repositories/risk/stasis), or why it failed.
29
34
  import type { LockfileFormat } from '@preventive/upstream/github.js'
30
35
  import { type ActionsSource, type Severity, npmMalwareAdvisory } from '../risk/index.js'
31
36
  import { isNpmPackageName, isNpmPackageSpec } from '../common/managed/npm-packages.js'
@@ -38,7 +43,7 @@ import { type DownloadsSource, readyingDownloads } from './scan-downloads.ts'
38
43
  import { type AssessedPackage, type AssessingSource, BUSY_RETRIES, BUSY_WAIT_MS, RISK_KEPT_MS, type RiskFailure, assessPackage, failureOf, isBusy } from './repository-risk-assess.ts'
39
44
  import { type AdvisoryRow, type Audit, type AuditSource, auditLockfiles } from './repository-risk-audit.ts'
40
45
  import { type DependabotRead, type ListedLockfile, type LockfileRead, type OpenedRepository, type RepositoryFailure, type RepositoryRead, SCAN_READ_KEPT_MS,
41
- readRepository } from './repository-risk-read.ts'
46
+ type StasisConfigsRead, readRepository } from './repository-risk-read.ts'
42
47
  import { type DependabotAlert, alertVersions } from './dependabot-alerts.ts'
43
48
  import { type ActionAnswers, type ActionLine, type ActionRef, type WorkflowLine, type WorkflowsLine, type WorkflowsRead, actionsLines, answerWeight,
44
49
  lockedNames, resolvingActions } from './repository-actions.ts'
@@ -98,6 +103,7 @@ export type RepositoryRiskLine =
98
103
  & ({ published: string | null; severity: Severity | null; score: number; findings: { id: string; severity: Severity; takenDown?: true }[] } | RiskFailure))
99
104
  | ({ type: 'advisories'; repo: number; path: string } & ({ advisories: AdvisoryRow[] } | RiskFailure))
100
105
  | ({ type: 'dependabot'; repo: number } & ({ alerts: DependabotAlertRow[] } | RiskFailure))
106
+ | ({ type: 'stasis'; repo: number } & StasisConfigsRead)
101
107
  | WorkflowsLine | WorkflowLine | ActionLine
102
108
  | { type: 'done' }
103
109
  // The scan stopped for its part's time (repositoryRiskLines `partMs`), what
@@ -330,6 +336,7 @@ async function tellRepository(scan: Scan, repo: RepositoryRiskRepo, read: Audite
330
336
  scan.lines.add(line)
331
337
  if ('packages' in line) assessLater(scan, line.packages)
332
338
  }
339
+ if (read.stasis) scan.lines.add({ type: 'stasis', repo: repo.repoId, ...read.stasis })
333
340
  const refs = read.actions ? tellActions(scan, repo, read.actions, lockfiles) : []
334
341
  for (const [at, { line }] of lockfiles.entries()) {
335
342
  if (scan.signal.aborted) return