@preventive/triage 1.0.0-alpha.71 → 1.0.0-alpha.73

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 (145) hide show
  1. package/common/bundle-sources.d.ts +2 -0
  2. package/common/bundle-sources.js +19 -2
  3. package/common/finding-duplicates.js +5 -0
  4. package/common/finding-filters.js +45 -4
  5. package/common/line-diff.d.ts +2 -2
  6. package/common/line-diff.js +20 -8
  7. package/common/managed/finding-detail.js +1 -1
  8. package/common/managed/review-view-routes.js +23 -0
  9. package/common/managed/risk-routes.js +30 -0
  10. package/common/managed/routes.js +11 -6
  11. package/common/managed/team-app.d.ts +8 -6
  12. package/common/managed/team-app.js +15 -3
  13. package/common/stasis-files.d.ts +5 -0
  14. package/common/stasis-files.js +20 -0
  15. package/common/stasis-tgz.d.ts +6 -0
  16. package/common/stasis-tgz.js +27 -0
  17. package/common/workspace-app.js +20 -0
  18. package/out/activity.js +2 -4
  19. package/out/{chunk-2F3CYNPZ.js → chunk-2IHCVA3Y.js} +1 -1
  20. package/out/{chunk-HAZKDK4M.js → chunk-2V6Q4ZOZ.js} +1 -1
  21. package/out/{chunk-RRBIJL2B.js → chunk-4IW3VD3H.js} +1 -1
  22. package/out/chunk-4YZOXAXR.js +2 -0
  23. package/out/chunk-5NUDNLJA.js +6 -0
  24. package/out/chunk-5YP7P5KA.js +1 -0
  25. package/out/chunk-6VOB5WXX.js +2 -0
  26. package/out/chunk-74JZTGTO.js +11 -0
  27. package/out/chunk-7YFJUT2P.js +1 -0
  28. package/out/chunk-A4BBBHQU.js +1 -0
  29. package/out/{chunk-4ISO5F7Y.js → chunk-ADMVRLNP.js} +1 -1
  30. package/out/chunk-BIWPZT4E.js +52 -0
  31. package/out/{chunk-HETCVNO4.js → chunk-BLPHP4U3.js} +1 -1
  32. package/out/{chunk-Y5ZHFNBD.js → chunk-BXQCCW7F.js} +1 -1
  33. package/out/{chunk-JFL7WLRV.js → chunk-CU3FPB3P.js} +1 -1
  34. package/out/chunk-CXVBTUK3.js +4 -0
  35. package/out/{chunk-M37X4LCF.js → chunk-EXQQ5VQJ.js} +1 -1
  36. package/out/{chunk-NXATZJQ2.js → chunk-GSNSP3EF.js} +1 -1
  37. package/out/chunk-GV5U7OLP.js +40 -0
  38. package/out/{chunk-JOXLZXMI.js → chunk-GX5UXWT4.js} +1 -1
  39. package/out/{chunk-YF4M5OCI.js → chunk-I6UQQKAH.js} +1 -1
  40. package/out/{chunk-UCP3JRE2.js → chunk-LVW7WWV4.js} +1 -1
  41. package/out/chunk-NEFCZAIY.js +11 -0
  42. package/out/{chunk-TOXMUOIW.js → chunk-OQS2USZM.js} +1 -1
  43. package/out/chunk-PQPKHAI5.js +15 -0
  44. package/out/chunk-PX5DLFSD.js +1 -0
  45. package/out/chunk-QBFT2DDR.js +1 -0
  46. package/out/{chunk-GZ46SSTF.js → chunk-RGNF4OH6.js} +1 -1
  47. package/out/chunk-RLLA4GHZ.js +1 -0
  48. package/out/chunk-ROHACH7V.js +3 -0
  49. package/out/chunk-ROWUGPID.js +1 -0
  50. package/out/{chunk-QMVOEBWC.js → chunk-S2ZIKK45.js} +1 -1
  51. package/out/chunk-SSPDMA6D.js +1 -0
  52. package/out/chunk-TD7RVUTT.js +2 -0
  53. package/out/{chunk-4XIH7YTX.js → chunk-UH6NZBSU.js} +1 -1
  54. package/out/{chunk-M3Y6SLC4.js → chunk-UJP4PQJA.js} +1 -1
  55. package/out/{chunk-PAD2JHZT.js → chunk-UJSJMXEG.js} +1 -1
  56. package/out/{chunk-E3LFSUDJ.js → chunk-VYYUMYVW.js} +1 -1
  57. package/out/{chunk-VRX2APNA.js → chunk-XVKDPU4D.js} +1 -1
  58. package/out/chunk-Y2XGV3RC.js +8 -0
  59. package/out/chunk-YCEMQETS.js +255 -0
  60. package/out/client-managed-import.js +3 -3
  61. package/out/client-managed.js +30 -27
  62. package/out/compare.js +16 -25
  63. package/out/dialogs.js +38 -38
  64. package/out/graph.js +14 -14
  65. package/out/index.html +32 -52
  66. package/out/scan.js +2 -2
  67. package/out/terminal.js +239 -240
  68. package/out/view.css +1 -1
  69. package/out/view.js +15 -15
  70. package/package.json +21 -13
  71. package/risk/actions/resolve.js +56 -19
  72. package/risk/actions/uses.js +27 -9
  73. package/risk/actions/workflow.js +75 -2
  74. package/risk/files/characters.js +11 -0
  75. package/risk/files/hosts.js +4 -4
  76. package/risk/files/readability.js +5 -2
  77. package/risk/files/runs-code.js +12 -25
  78. package/risk/files/script.js +141 -19
  79. package/risk/files/source-map-link.js +43 -0
  80. package/risk/index.d.ts +24 -7
  81. package/risk/index.js +1 -0
  82. package/risk/npm/assess.js +1 -1
  83. package/risk/npm/compare.js +9 -30
  84. package/risk/npm/diff.js +1 -1
  85. package/risk/npm/held.js +6 -2
  86. package/risk/npm/registry.js +5 -2
  87. package/risk/npm/tarball.js +79 -22
  88. package/server-managed/bundle-advisories.ts +12 -36
  89. package/server-managed/bundle-build-worker.js +29 -11
  90. package/server-managed/bundle-build.ts +4 -3
  91. package/server-managed/bundle-cache.ts +53 -13
  92. package/server-managed/bundle.ts +45 -13
  93. package/server-managed/comparison.ts +3 -3
  94. package/server-managed/db-methods.ts +54 -17
  95. package/server-managed/db-neon.ts +9 -2
  96. package/server-managed/db-schema.ts +12 -2
  97. package/server-managed/db.ts +4 -1
  98. package/server-managed/dependency-reviews.ts +8 -5
  99. package/server-managed/github-errors.ts +22 -0
  100. package/server-managed/github-requests.ts +4 -2
  101. package/server-managed/http.ts +336 -76
  102. package/server-managed/management.ts +10 -4
  103. package/server-managed/npm-delta.ts +17 -2
  104. package/server-managed/npm-kept.ts +6 -0
  105. package/server-managed/npm-packages.ts +30 -29
  106. package/server-managed/npm-patch.ts +9 -9
  107. package/server-managed/package-entry-points.ts +54 -6
  108. package/server-managed/pull-dependencies.ts +4 -1
  109. package/server-managed/rename-diff-worker.js +11 -7
  110. package/server-managed/rename-diff.ts +5 -4
  111. package/server-managed/report-opening.ts +77 -0
  112. package/server-managed/report-sources.ts +2 -1
  113. package/server-managed/repository-aliases.ts +34 -0
  114. package/server-managed/repository-browser.ts +87 -32
  115. package/server-managed/repository-code.ts +6 -3
  116. package/server-managed/repository-dependency-reviews.ts +21 -0
  117. package/server-managed/repository-issues.ts +15 -9
  118. package/server-managed/repository-risk-read.ts +50 -4
  119. package/server-managed/repository-risk.ts +9 -2
  120. package/server-managed/stasis-config.ts +97 -5
  121. package/server-managed/stasis-dependencies.ts +7 -4
  122. package/server-managed/team-reports.ts +5 -3
  123. package/server-managed/type-only-proof.js +26 -4
  124. package/server-managed/upstream-cache.ts +18 -12
  125. package/server-managed/workspace-shares.ts +4 -4
  126. package/out/chunk-2HGKTQ5Q.js +0 -52
  127. package/out/chunk-45HTR22K.js +0 -4
  128. package/out/chunk-4RS3NDOG.js +0 -1
  129. package/out/chunk-7GJNLCXF.js +0 -15
  130. package/out/chunk-CGRIZ5M5.js +0 -1
  131. package/out/chunk-CQIT5UNK.js +0 -1
  132. package/out/chunk-D6NVKGGG.js +0 -10
  133. package/out/chunk-DTAR2BB6.js +0 -247
  134. package/out/chunk-MPXVKVPF.js +0 -3
  135. package/out/chunk-NB4JBTKK.js +0 -2
  136. package/out/chunk-QPGM3DTI.js +0 -42
  137. package/out/chunk-VFWMQ3LG.js +0 -2
  138. package/out/chunk-VG5RH6KN.js +0 -2
  139. package/out/chunk-WFDXHPT2.js +0 -12
  140. package/out/chunk-WMFDQS2L.js +0 -11
  141. package/out/chunk-WREU7JAG.js +0 -1
  142. /package/out/{chunk-JMG5DXII.js → chunk-7HP2VYIC.js} +0 -0
  143. /package/out/{chunk-HOB3YPS5.js → chunk-K4XJHM2T.js} +0 -0
  144. /package/out/{chunk-4EMM6UCD.js → chunk-QI66YA4F.js} +0 -0
  145. /package/out/{chunk-G3LY2FV4.js → chunk-WCDYSIKG.js} +0 -0
@@ -3,6 +3,8 @@ export function bundleSourcesAsMap(details: BundleDetails): Map<string, string>
3
3
  export function bundleSourceLines(content: string): number
4
4
  export function bundleSourceOrder(sources: Map<string, string>): { paths: string[]; numbers: Map<string, number> }
5
5
  export function bundleFilesAsMap(details: BundleDetails): Map<string, string | { format: 'base64'; data: string }>
6
+ export function bundleFileLink(details: BundleDetails | null | undefined, path: string): string | undefined
7
+ export function symlinkTarget(path: string, link: string): string | null
6
8
  export function bundlePackageDirs(details: BundleDetails): Map<string, string> | null
7
9
  export function bundlePackageRepos(details: BundleDetails, dirs?: ReadonlySet<string> | null): Map<string, { github: string; directory?: string; commit: string }>
8
10
  export function bundlePackageVersions(details: BundleDetails, paths?: Iterable<string> | null, keyOf?: (dir: string, info: { name: string; version: string }) => string): Map<string, Set<string>>
@@ -117,7 +117,8 @@ export function bundleSourceOrder(sources) {
117
117
  // details of `entry` in the shape of a sourcemap carrying its sources: one
118
118
  // source per file, text inline, and every file's size from its bytes, so a
119
119
  // file that is not text still lists with its size. Those carry a digest of
120
- // their bytes instead (`npmBinaries`), which Compare compares them by. An npm
120
+ // their bytes instead (`npmBinaries`), which Compare compares them by, and a
121
+ // symlink its target last (`link`). An npm
121
122
  // version's files come so (view/npm-package.js), and a repository
122
123
  // directory's (view/repository-code.js).
123
124
  export function fileRowDetails(entry, rows) {
@@ -127,10 +128,26 @@ export function fileRowDetails(entry, rows) {
127
128
  json: { version: 3, sources: files.map(([path]) => path), sourcesContent: files.map(([, , text]) => typeof text === 'string' ? text : null) },
128
129
  fileSizes: new Map(files.map(([path, size]) => [path, size])),
129
130
  npmBinaries: new Map(files.filter(([, , text, digest]) => typeof text !== 'string' && typeof digest === 'string')
130
- .map(([path, size, , digest]) => [path, { size, digest }])),
131
+ .map(([path, size, , digest, link]) => [path, { size, digest, ...typeof link === 'string' ? { link } : {} }])),
131
132
  }
132
133
  }
133
134
 
135
+ // The target of the symlink at `path` (fileRowDetails), else undefined.
136
+ export const bundleFileLink = (details, path) => details?.npmBinaries?.get(path)?.link
137
+
138
+ // The package path a symlink at `path` to `link` lands on ('' the package's
139
+ // own directory), or null where it points out of the package.
140
+ export function symlinkTarget(path, link) {
141
+ if (link.startsWith('/')) return null
142
+ const at = path.split('/').slice(0, -1)
143
+ for (const step of link.split('/')) {
144
+ if (step === '' || step === '.') continue
145
+ if (step !== '..') at.push(step)
146
+ else if (at.pop() === undefined) return null
147
+ }
148
+ return at.join('/')
149
+ }
150
+
134
151
  export function bundleFilesAsMap(details) {
135
152
  const key = details?.bundle ?? details?.json
136
153
  if (key && filesCache.has(key)) return filesCache.get(key)
@@ -43,8 +43,13 @@ export function mergeDuplicateFields(survivor, dup) {
43
43
  // The row merger also retains the evidence behind a conflict. This must
44
44
  // run for every duplicate, including agreeing copies and missing-field fills,
45
45
  // so the eventual dialog can name the reports that actually supplied a value.
46
+ //
47
+ // The derived copy is switched to open on Confirmed only where every copy is
48
+ // (finding-filters.js confirmedCoverage): a copy from a report nobody
49
+ // switched is still that report's to lose.
46
50
  export function mergeReportDuplicateFields(survivor, dup, reportName, conflicts) {
47
51
  if (!survivor || !dup || survivor === dup) return
52
+ if (survivor._confirmedDefault === true && dup._confirmedDefault !== true) survivor._confirmedDefault = false
48
53
  if (survivor.correctedSeverity || dup.correctedSeverity) {
49
54
  survivor._correctedByReport ??= {
50
55
  [survivor._reportName ?? '']: { severity: effectiveSeverity(survivor), reason: survivor.correctedSeverityReason },
@@ -37,11 +37,29 @@ export const REVALIDATE_FILTERS = [
37
37
  { value: 'refuted', label: 'Refuted', kinds: ['refuted'] },
38
38
  ]
39
39
 
40
+ // The option that is no answer of the pass's: the rows it never looked
41
+ // at. Kept out of REVALIDATE_FILTERS, which answers "did the pass leave
42
+ // this standing" — this asks whether the pass got to it at all. Offered
43
+ // only while the underlying findings are on screen (format.js
44
+ // reachableRevalidateFilters), and asked of the ROW rather than of a tab:
45
+ // one stamped finding, or the pass's own row, means the pass looked at
46
+ // that issue whichever copy it stamped, so a row qualifies only when NONE
47
+ // of its findings carries an outcome (filters.js matchesOutcomeRow). Its
48
+ // one kind is the "no stamp" '' the per-tab check reads.
49
+ export const NOT_REVALIDATED_FILTER = { value: 'unrevalidated', label: 'Not revalidated', kinds: [''] }
50
+
51
+ const OUTCOME_OPTIONS = [...REVALIDATE_FILTERS, NOT_REVALIDATED_FILTER]
52
+
53
+ // The option one dropdown value names, or undefined.
54
+ export function revalidateFilterOption(value) {
55
+ return OUTCOME_OPTIONS.find((o) => o.value === value)
56
+ }
57
+
40
58
  // The kinds one dropdown value covers, or null when the value names no
41
59
  // option — filters.js reads that as "no filter" rather than hiding
42
60
  // every finding behind a value it can't interpret.
43
61
  export function revalidateFilterKinds(value) {
44
- return REVALIDATE_FILTERS.find((o) => o.value === value)?.kinds ?? null
62
+ return revalidateFilterOption(value)?.kinds ?? null
45
63
  }
46
64
 
47
65
  // How finely Confirmed is drawn, once it has taken the partial rows
@@ -165,6 +183,10 @@ function showsAtConfidence(g, min, kindOf) {
165
183
  // every finding; 0 lets the filter no-op instead, and the toolbar
166
184
  // hides the control anyway (see toolbarHtml in render.js).
167
185
  //
186
+ // The base never sits above the best-scored row: a set scored 5 at most
187
+ // has countAtMin(6) = 0 ≤ 25 too, and opening it at 6 would show an
188
+ // empty list. Step down to the highest step some row clears first.
189
+ //
168
190
  // After picking the base, walk DOWN while each lower step surfaces no
169
191
  // new groups — i.e. there's a "gap" in the confidence distribution
170
192
  // below the chosen floor. Lowering for free puts the slider at the
@@ -189,6 +211,7 @@ export function defaultConfidenceFloor(groups, tabs) {
189
211
  if (countAtMin(6) <= 25) base = 6
190
212
  else if (countAtMin(7) <= 25) base = 7
191
213
  else base = 8
214
+ while (base > 0 && countAtMin(base) === 0) base--
192
215
  while (base > 0 && countAtMin(base - 1) === countAtMin(base)) base--
193
216
  return base
194
217
  }
@@ -214,8 +237,18 @@ function effectiveFloor(groups, confMin) {
214
237
  }
215
238
 
216
239
  // Both the opening default and the dropdown lock use the same coverage:
217
- // findings represented by Confirmed rows, plus findings explicitly ruled out.
240
+ // findings represented by Confirmed rows, plus findings explicitly ruled out,
241
+ // plus those a manager let Confirmed hide (`_confirmedDefault`).
218
242
  // Read the original groups before `tabs` folds away their source members.
243
+ //
244
+ // A managed report switched to Confirmed by default (Manage → Reports) has
245
+ // each of its findings stamped `_confirmedDefault` as it is read, its own
246
+ // value whatever the report wrote (ingest.js, common/managed/team-app.js).
247
+ // A finding Confirmed would hide is then a cost its manager accepted, and
248
+ // counts as covered here, so both the opening outcome and the App lock (a
249
+ // team's App mode) look past it. Only where EVERY copy of it is so stamped:
250
+ // the same finding in a report nobody switched is still that report's to
251
+ // lose, and keeps the view on Confidence.
219
252
  export function confirmedCoverage(groups, tabs, kindOf) {
220
253
  // A workspace may carry an un-stamped source copy from report A while
221
254
  // report B explicitly ruled out the same id. The ruled-out copy is
@@ -225,9 +258,14 @@ export function confirmedCoverage(groups, tabs, kindOf) {
225
258
  // even when the App finding that caused the ruling has no
226
259
  // `revalidateInputs` list of its own.
227
260
  const covered = new Set(groups.ruledOutIds ?? [])
261
+ const waived = new Map()
228
262
  for (const raw of groups) {
229
- for (const f of raw) if (['refuted', 'unreachable'].includes(kindOf(f))) covered.add(tabKey(f))
263
+ for (const f of raw) {
264
+ if (['refuted', 'unreachable'].includes(kindOf(f))) covered.add(tabKey(f))
265
+ waived.set(tabKey(f), waived.get(tabKey(f)) !== false && f._confirmedDefault === true)
266
+ }
230
267
  }
268
+ for (const [key, all] of waived) if (all) covered.add(key)
231
269
  for (const raw of groups) {
232
270
  const g = tabs(raw)
233
271
  if (g.length === 0) continue
@@ -252,10 +290,13 @@ export function confirmedCoverage(groups, tabs, kindOf) {
252
290
  return covered
253
291
  }
254
292
 
293
+ // Whether a set opens on Confirmed: Confirmed reaches something on screen,
294
+ // and hides no finding the opening range `confMin` would show. A range
295
+ // that shows nothing (its ruled-out rows read as 0) hides nothing Confirmed
296
+ // would, so it doesn't hold the view on an empty list.
255
297
  export function confirmedIsDefault(visible, confMin, covered, kindOf) {
256
298
  const floor = effectiveFloor(visible, confMin)
257
299
  const shown = visible.filter((g) => showsAtConfidence(g, floor, kindOf))
258
- if (shown.length === 0) return false
259
300
  const kinds = new Set(activeRevalidateKinds('confirmed', ''))
260
301
  if (!visible.some((g) => g.some((f) => kinds.has(kindOf(f))))) return false
261
302
  return shown.every((g) => g.every((f) => covered.has(tabKey(f))))
@@ -4,5 +4,5 @@
4
4
  export interface ChangeBlock { a0: number; a1: number; b0: number; b1: number }
5
5
 
6
6
  export function textLines(text: string): string[]
7
- export function changeBlocks(before: string, after: string, ignoreWhitespace?: boolean): ChangeBlock[]
8
- export function blocksHold(before: string, after: string, blocks: unknown, ignoreWhitespace?: boolean): boolean
7
+ export function changeBlocks(before: string, after: string, ignoreWhitespace?: boolean | 'leading'): ChangeBlock[]
8
+ export function blocksHold(before: string, after: string, blocks: unknown, ignoreWhitespace?: boolean | 'leading'): boolean
@@ -23,25 +23,37 @@ const endsLine = text => text === '' || text.endsWith('\n')
23
23
  // blanks as one space, and those that end it as none.
24
24
  const spacing = line => line.replace(/[ \t\n\v\f\r]+$/u, '').replaceAll(/[ \t\n\v\f\r]+/gu, ' ')
25
25
 
26
- // Each `a[a0..a1)` replaced by `b[b0..b1)`. `ignoreWhitespace` is diff -b:
27
- // lines differing only in how much whitespace they have pair up as unchanged,
28
- // whitespace added or removed between other characters still a change. Those
29
- // a unified diff with no context shows (horizon 0), found without printing
30
- // one and reading it back.
26
+ // A text as `leading` reads it: a newline after its last line, as diff -b
27
+ // ignores one added or dropped there, then each line's indentation set aside;
28
+ // and a line as it reads one.
29
+ const INDENT = /(?<=^|\n)[ \t\v\f]+/gu
30
+ const unindent = text => (text === '' || text.endsWith('\n') ? text : `${text}\n`).replaceAll(INDENT, '')
31
+ const unindentLine = line => line.replace(/^[ \t\v\f]+/u, '')
32
+
33
+ // Each `a[a0..a1)` replaced by `b[b0..b1)`. `ignoreWhitespace` is diff -b
34
+ // (true): lines differing only in how much whitespace they have pair up as
35
+ // unchanged, whitespace added or removed between other characters still a
36
+ // change; or `leading`: lines differing only in their indentation. Those a
37
+ // unified diff with no context shows (horizon 0), found without printing one
38
+ // and reading it back.
31
39
  export function changeBlocks(before, after, ignoreWhitespace = false) {
32
- return changeSet(before, after, { horizon: 0, whitespace: ignoreWhitespace ? 'change' : 'none' }).map(({ a0, a1, b0, b1 }) => ({ a0, a1, b0, b1 }))
40
+ const leading = ignoreWhitespace === 'leading'
41
+ return changeSet(leading ? unindent(before) : before, leading ? unindent(after) : after, { horizon: 0, whitespace: ignoreWhitespace === true ? 'change' : 'none' })
42
+ .map(({ a0, a1, b0, b1 }) => ({ a0, a1, b0, b1 }))
33
43
  }
34
44
 
35
45
  // Whether `blocks` take `before`'s lines to `after`'s: each in order and apart
36
46
  // from the last, within both texts, and every line between them alike on both
37
47
  // sides (alike but for how much whitespace they have where `ignoreWhitespace`,
38
- // as diff -b has them), the last line in a block where a newline was added or
48
+ // as diff -b has them, or for their indentation where it is `leading`), the
49
+ // last line in a block where a newline was added or
39
50
  // dropped after it, so that a diff drawn from them hides no change. A check on
40
51
  // what changeBlocks found, or on one found apart from the texts drawn.
41
52
  export function blocksHold(before, after, blocks, ignoreWhitespace = false) {
42
53
  if (!Array.isArray(blocks)) return false
43
54
  const a = textLines(before), b = textLines(after)
44
- const alike = ignoreWhitespace ? (x, y) => spacing(x) === spacing(y) : (x, y) => x === y
55
+ const read = ignoreWhitespace === 'leading' ? unindentLine : ignoreWhitespace ? spacing : null
56
+ const alike = read ? (x, y) => read(x) === read(y) : (x, y) => x === y
45
57
  let i = 0, j = 0
46
58
  for (const block of [...blocks, { a0: a.length, a1: a.length, b0: b.length, b1: b.length, last: true }]) {
47
59
  const { a0, a1, b0, b1 } = block ?? {}
@@ -66,7 +66,7 @@ const rows = data => (reportEntries(data) ?? []).flat().length
66
66
  // their App rows (`folded: 'rows'`). Folded, the `lens` the rows left out
67
67
  // tell (team-app.js managedTeamLens). All of it read from `view`, the
68
68
  // workspace's (team-app.js managedTeamView), where its builder has one.
69
- export function liteWorkspace(reports, links, view = managedTeamView(Object.assign(reports.map(({ filename, data }) => ({ filename, data })), { links }))) {
69
+ export function liteWorkspace(reports, links, view = managedTeamView(Object.assign(reports.map(({ filename, data, confirmedDefault }) => ({ filename, data, confirmedDefault })), { links }))) {
70
70
  const shown = view.rows
71
71
  const fold = shown !== null || !view.conflicted()
72
72
  const lite = reports.map(report => ({ ...report, data: liteReportData(report.data, { fold, shown }) }))
@@ -0,0 +1,23 @@
1
+ // How a review's diff is drawn, as its URL names it past what it reviews
2
+ // (routes.js): changes hidden, `hide=whitespace,type-only` (`hideWhitespace`,
3
+ // `hideTypes`), and pretty-printing, `pretty=on`, or for JSON `folded`
4
+ // (`pretty`, as state.bundleSourcePretty has it: `indented` or `folded`).
5
+ // Each setting by its name in the URL and its route field.
6
+ const HIDES = [['whitespace', 'hideWhitespace'], ['type-only', 'hideTypes']]
7
+ const PRETTY = [['on', 'indented'], ['folded', 'folded']]
8
+
9
+ // A review route's query parameters for how its diff is drawn: none where all is off.
10
+ export function reviewViewQuery(route) {
11
+ const hide = HIDES.filter(([, field]) => route[field] === true).map(([name]) => name)
12
+ const pretty = PRETTY.find(([, value]) => value === route.pretty)?.[0]
13
+ return [...hide.length > 0 ? [`hide=${hide.join(',')}`] : [], ...pretty ? [`pretty=${pretty}`] : []]
14
+ }
15
+
16
+ // The route fields a review URL's `search` names, each `hide` read. A
17
+ // setting it doesn't know is left out, not the link refused: it changes how
18
+ // the review is drawn, never what is reviewed.
19
+ export function reviewViewOf(search) {
20
+ const hide = new Set(search.getAll('hide').flatMap(names => names.split(',')))
21
+ const pretty = PRETTY.find(([name]) => name === search.get('pretty'))?.[1]
22
+ return { ...Object.fromEntries(HIDES.filter(([name]) => hide.has(name)).map(([, field]) => [field, true])), ...pretty ? { pretty } : {} }
23
+ }
@@ -0,0 +1,30 @@
1
+ // Risk's pages, each a scope it scans (ui/managed/repository-risk.js): every
2
+ // connected repository, `/manage/risk/all`; a team's, by its slug,
3
+ // `/manage/risk/team/<slug>`; or one repository, by its id,
4
+ // `/manage/risk/repository/<repo id>`; a team or a repository still to
5
+ // choose, without one. A route naming no scope (`riskScope`) is a team's
6
+ // still to choose, Risk's own page, `/manage/risk`, opening there, as links
7
+ // from before Risk left Repositories, `/manage/repositories/risk`, do.
8
+ const RISK_SCOPES = Object.freeze({ all: 'all', team: 'team', repo: 'repository' })
9
+ const isRiskTarget = (scope, target) => scope === 'team' ? typeof target === 'string' && /^[A-Za-z0-9_-]+$/u.test(target)
10
+ : scope === 'repo' && Number.isSafeInteger(target) && target > 0
11
+
12
+ export function riskPath(route) {
13
+ const scope = route.riskScope ?? 'team'
14
+ const target = route.riskTarget ?? null
15
+ if (!Object.hasOwn(RISK_SCOPES, scope) || target != null && !isRiskTarget(scope, target)) return null
16
+ return `/manage/risk/${RISK_SCOPES[scope]}${target == null ? '' : `/${target}`}`
17
+ }
18
+
19
+ // Risk's route of `path` past its own page (MANAGED_PAGES); undefined where
20
+ // it is none of Risk's pages.
21
+ export function parseRiskRoute(path) {
22
+ if (path === '/manage/risk/team' || path === '/manage/repositories/risk') return { view: 'manage-repo-risk' }
23
+ if (!path.startsWith('/manage/risk/')) return undefined
24
+ const match = /^\/manage\/risk\/(?:(all)|(team)\/([A-Za-z0-9_-]+)|repository(?:\/([1-9]\d*))?)$/u.exec(path)
25
+ if (!match) return null
26
+ if (match[1]) return { view: 'manage-repo-risk', riskScope: 'all' }
27
+ const [scope, target] = match[2] ? ['team', match[3]] : ['repo', match[4] == null ? null : Number(match[4])]
28
+ if (target != null && !isRiskTarget(scope, target)) return null
29
+ return { view: 'manage-repo-risk', riskScope: scope, ...(target == null ? {} : { riskTarget: target }) }
30
+ }
@@ -3,6 +3,8 @@ import { BUNDLE_TABS } from '../bundle-tabs.js'
3
3
  import { MAX_FINDING_ID_LENGTH, isLinkableFindingId } from '../finding-id.js'
4
4
  import { isGithubRepoName } from '../github-pr.ts'
5
5
  import { isNpmPackageName, isNpmPackageSpec, isPatchHash, isPatchPath } from './npm-packages.js'
6
+ import { parseRiskRoute, riskPath } from './risk-routes.js'
7
+ import { reviewViewOf, reviewViewQuery } from './review-view-routes.js'
6
8
  import { filtersOf, filtersQuery } from './team-filters.js'
7
9
 
8
10
  // How Compare reviews the changes, past its Overview: `code`, beside the
@@ -21,7 +23,7 @@ export const MANAGED_PAGES = Object.freeze({
21
23
  'manage-scans': '/manage/scans',
22
24
  'manage-reports': '/manage/report',
23
25
  'manage-repos': '/manage/repositories',
24
- 'manage-repo-risk': '/manage/repositories/risk',
26
+ 'manage-repo-risk': '/manage/risk',
25
27
  'admin-users': '/manage/users',
26
28
  'manage-teams': '/manage/team',
27
29
  'manage-import': '/manage/import',
@@ -73,6 +75,7 @@ export function managedRoutePath(route) {
73
75
  ? `/${route.compareSlug}${compareModeSuffix(route.compareMode)}` : ''
74
76
  return `${parent}/bundle/${route.bundleSlug}${tab === 'overview' ? '' : `/${tab}`}${file}${compare}${lines}`
75
77
  }
78
+ if (route.view === 'manage-repo-risk') return riskPath(route)
76
79
  if (Object.hasOwn(MANAGED_PAGES, route.view)) {
77
80
  const path = MANAGED_PAGES[route.view]
78
81
  if (route.view === 'manage-deduplication' && route.linkId) return `${path}?report=${encodeURIComponent(route.linkId)}`
@@ -107,7 +110,8 @@ export function managedRoutePath(route) {
107
110
  // `?patch=<hash>&repo=<repo id or name>&commit=<commit>&path=<path>`, or by
108
111
  // its hash alone, which only one kept answers (`?patch=<hash>`); and,
109
112
  // against a version as a patch changes it, that patch by its hash alone
110
- // (`basePatch`, `&basePatch=<hash>`).
113
+ // (`basePatch`, `&basePatch=<hash>`). Past those, how its diff is drawn
114
+ // (review-view-routes.js).
111
115
  export const NPM_TABS = new Set(['overview', 'code', 'search', 'compare', 'review', 'treemap'])
112
116
  // A patch as the server reads one (server-managed/npm-patch.ts requestedPatch).
113
117
  const isPatch = patch => isPatchHash(patch?.hash) && (patch.repoId == null ? patch.commit == null && patch.path == null
@@ -123,7 +127,7 @@ function npmPackagePath(route) {
123
127
  const base = route.reviewPackage == null ? '' : `/${route.reviewPackage}${route.reviewSpec == null ? '' : `@${route.reviewSpec}`}`
124
128
  const { patch } = route
125
129
  const query = [...patch == null ? [] : [`patch=${patch.hash}`], ...patch?.repoId == null ? [] : [`repo=${patch.repoId}&commit=${patch.commit}`],
126
- ...patch?.path == null ? [] : [`path=${patch.path.split('/').map(encodeURIComponent).join('/')}`], ...route.basePatch == null ? [] : [`basePatch=${route.basePatch}`]].join('&')
130
+ ...patch?.path == null ? [] : [`path=${patch.path.split('/').map(encodeURIComponent).join('/')}`], ...route.basePatch == null ? [] : [`basePatch=${route.basePatch}`], ...reviewViewQuery(route)].join('&')
127
131
  return `/npm/${route.packageName}${route.packageSpec == null ? '' : `@${route.packageSpec}`}/review${base}${query ? `?${query}` : ''}`
128
132
  }
129
133
  const file = tab === 'code' && isLineNumber(route.file) ? `/${route.file}` : ''
@@ -147,7 +151,7 @@ function parseNpmRoute(path, hash, search) {
147
151
  if (patch && !isPatch(patch) || basePatch !== null && (!isPatchHash(basePatch) || !review[3])) return null
148
152
  return { view: 'npm', packageName: review[1], packageSpec: review[2] ?? null, bundleTab: 'review',
149
153
  ...(review[3] ? { reviewPackage: versionOnly ? review[1] : review[3], reviewSpec: versionOnly ? review[3] : review[4] ?? null } : {}), ...(patch ? { patch } : {}),
150
- ...(basePatch ? { basePatch } : {}) }
154
+ ...(basePatch ? { basePatch } : {}), ...reviewViewOf(search) }
151
155
  }
152
156
  const match = /^\/npm(?:\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(?:\/(code|search|compare|treemap)(?:\/([^/]+)(?:\/([a-z]+))?)?)?)?$/u.exec(path)
153
157
  if (!match) return undefined
@@ -289,7 +293,8 @@ export function parseManagedRoute(url) {
289
293
  const dependencies = /^\/team\/([A-Za-z0-9_-]+)\/dependencies\/([a-z]+)$/u.exec(path)
290
294
  if (dependencies) return DEPENDENCY_TABS.has(dependencies[2]) ? { view: 'workspace-dependencies', teamSlug: dependencies[1], dependencyTab: dependencies[2] } : null
291
295
  const match = /^\/team\/([^/]+)(?:\/report\/([^/]+))?(?:\/(files)|\/finding\/([^/]+))?$/u.exec(path)
292
- if (!match) return null
296
+ // Risk's scopes, past its own page (MANAGED_PAGES).
297
+ if (!match) return parseRiskRoute(path) ?? null
293
298
  try {
294
299
  const teamSlug = decodeURIComponent(match[1])
295
300
  const reportSlug = match[2] ? decodeURIComponent(match[2]) : null
@@ -336,7 +341,7 @@ export function resolveManagedRoute(route, teams, adminBundles = []) {
336
341
  // where it was copied, and its reader may hold the finding elsewhere: each
337
342
  // resolves where its slug names one alone, the report in any team, and
338
343
  // else to null, for the finding's lookup to prefer
339
- // (ui/view/managed-finding-link.js). `teamOnly` tells a link to a team's
344
+ // (ui/view/finding-link-route.js). `teamOnly` tells a link to a team's
340
345
  // own findings from one whose report resolved to none.
341
346
  if (rest.finding) return { ...rest, teamId: team?.id ?? null, reportId, teamOnly: reportSlug == null }
342
347
  if (!team) return null
@@ -1,15 +1,17 @@
1
1
  // Set for a team that is not App: `findings`, its rows (with `countFindings`),
2
2
  // and `appReports`, set by the managed catalog: how many reports open in App mode alone.
3
3
  export type TeamAppMetadata = { appMode: true; appFindings: number } | { appMode: false; appReports?: number; findings?: number }
4
- export function managedTeamAppMetadata(workspace: readonly { filename: string; data: unknown }[] & { links?: readonly (readonly string[])[] },
5
- options?: { countFindings?: boolean }): TeamAppMetadata
6
- export function managedTeamRevalidationConflicted(workspace: readonly { filename: string; data: unknown }[] & { links?: readonly (readonly string[])[] }): boolean
7
- export function managedTeamAppRows(workspace: readonly { filename: string; data: unknown }[] & { links?: readonly (readonly string[])[] }): Set<string> | null
8
- export function managedTeamLens(workspace: readonly { filename: string; data: unknown }[] & { links?: readonly (readonly string[])[] }): { drop: boolean; detail: boolean; upstream: boolean }
4
+ // A team's reports, each switched to open on Confirmed or not (`confirmedDefault`), and its links.
5
+ type TeamWorkspace = readonly { filename: string; data: unknown; confirmedDefault?: boolean | undefined }[] & { links?: readonly (readonly string[])[] }
6
+ export function managedTeamAppMetadata(workspace: TeamWorkspace, options?: { countFindings?: boolean }): TeamAppMetadata
7
+ export function managedTeamRevalidationConflicted(workspace: TeamWorkspace): boolean
8
+ export function managedTeamAppRows(workspace: TeamWorkspace): Set<string> | null
9
+ export function managedTeamLens(workspace: TeamWorkspace): { drop: boolean; detail: boolean; upstream: boolean }
10
+ export function managedReportConfirmedDefaultOffered(filename: string, data: unknown): boolean
9
11
  export interface ManagedTeamView {
10
12
  app: TeamAppMetadata
11
13
  rows: Set<string> | null
12
14
  conflicted(): boolean
13
15
  lens(): { drop: boolean; detail: boolean; upstream: boolean }
14
16
  }
15
- export function managedTeamView(workspace: readonly { filename: string; data: unknown }[] & { links?: readonly (readonly string[])[] }): ManagedTeamView
17
+ export function managedTeamView(workspace: TeamWorkspace): ManagedTeamView
@@ -2,7 +2,7 @@ import { inheritReportMeta, isAppFinding, reportEntries, revalidateKindOf } from
2
2
  import { collectDuplicates } from '../../client/linked-findings.js'
3
3
  import { dependencyDirectory, isDependencyFile } from '../../client/dependency-paths.js'
4
4
  import { hasRevalidateStamp } from '../finding-filters.js'
5
- import { workspaceApp, workspaceAppMetadata, workspaceAppRows } from '../workspace-app.js'
5
+ import { confirmedDefaultOffered, workspaceApp, workspaceAppMetadata, workspaceAppRows } from '../workspace-app.js'
6
6
  import { mergeReportGroups } from '../workspace-groups.js'
7
7
 
8
8
  // The same classification as local workspaces, using only the complete,
@@ -74,13 +74,25 @@ function lensOf(reports, groups) {
74
74
  }
75
75
  }
76
76
 
77
+ // Whether one stored report, alone and whole, may be switched to open on
78
+ // Confirmed (common/workspace-app.js confirmedDefaultOffered), asked as it
79
+ // is uploaded and of one uploaded before (server-managed/report-opening.ts).
80
+ // Its findings' IDs are backfilled first, as a team's are.
81
+ export function managedReportConfirmedDefaultOffered(filename, data) {
82
+ const { reports, duplicates } = viewReports([{ filename, data }])
83
+ return confirmedDefaultOffered(reports, id => [...duplicates.get(id) ?? []])
84
+ }
85
+
77
86
  // The workspace's reports as a view holds them (ui/view/ingest.js), with the
78
87
  // duplicates its links name, and those its own `links` name alone (`linked`).
88
+ // A report switched to open on Confirmed (`confirmedDefault`) stamps each of
89
+ // its findings so, and no other finding is, whatever its report wrote
90
+ // (common/finding-filters.js confirmedCoverage).
79
91
  function viewReports(workspace) {
80
92
  const duplicates = new Map(), linked = new Map(), reports = []
81
93
  collectDuplicates(workspace.links ?? [], duplicates)
82
94
  collectDuplicates(workspace.links ?? [], linked)
83
- for (const { filename, data } of workspace) {
95
+ for (const { filename, data, confirmedDefault } of workspace) {
84
96
  if (data.source === 'links' && Array.isArray(data.links)) {
85
97
  collectDuplicates(data.links, duplicates)
86
98
  continue
@@ -88,7 +100,7 @@ function viewReports(workspace) {
88
100
  const entries = (reportEntries(data) ?? []).map(entry => Array.isArray(entry) ? entry : [entry])
89
101
  const judged = new Set(entries.flat().filter(hasRevalidateStamp).map(f => f.source ?? data.source ?? null))
90
102
  const groups = entries.map(group => group.map(f => {
91
- const finding = { ...f, _source: f.source ?? data.source ?? null }
103
+ const finding = { ...f, _source: f.source ?? data.source ?? null, _confirmedDefault: confirmedDefault === true }
92
104
  inheritReportMeta(finding, data)
93
105
  if (!('isApp' in finding)) finding.isApp = isAppFinding(finding, finding._source)
94
106
  finding._sourcePass = judged.has(finding._source)
@@ -0,0 +1,5 @@
1
+ // Type declarations for `common/stasis-files.js`, for its `.ts` callers
2
+ // without `allowJs`.
3
+ export function isStasisBundleName(name: string): boolean
4
+ export function isStasisTgzName(name: string): boolean
5
+ export function isGzip(bytes: Uint8Array): boolean
@@ -0,0 +1,20 @@
1
+ // Stasis bundles as files: a stasis.code.br (brotli'd JSON) or a .stasis.tgz
2
+ // (a gzipped tar of a stasis.lock.json and the files it attests), each
3
+ // named so alone or after `<name>.` (stasis-core's BUNDLE_FILE and TGZ_FILE).
4
+ // Told apart by their names, as Stasis tells them (stasis-core's isTgzName);
5
+ // stasis-tgz.js reads a .stasis.tgz.
6
+ const BUNDLE_FILES = ['stasis.code.br', 'stasis.tgz']
7
+ const named = (name, file) => name === file || name.endsWith(`.${file}`)
8
+
9
+ // Whether `name` (lowercased, as bundleKind compares it) names a Stasis bundle.
10
+ export const isStasisBundleName = name => BUNDLE_FILES.some(file => named(name, file))
11
+
12
+ // Whether a bundle's file name is a .stasis.tgz's, as bundleKind reads it:
13
+ // its case aside, and a browser's duplicate-download counter before its last
14
+ // extension (`app.stasis (1).tgz`).
15
+ export const isStasisTgzName = name => named(name.toLowerCase().replace(/ \(\d+\)(?=\.[^.]*$)/u, ''), 'stasis.tgz')
16
+
17
+ // gzip's magic: a .stasis.tgz's bytes start so, a stasis.code.br's never
18
+ // (stasis-core's isGzip: brotli so would ask for a window Stasis never writes),
19
+ // as a store that gzips what it keeps tells what to gunzip again.
20
+ export const isGzip = bytes => bytes.length >= 2 && bytes[0] === 0x1f && bytes[1] === 0x8b
@@ -0,0 +1,6 @@
1
+ // Type declarations for `common/stasis-tgz.js`, for its `.ts` callers
2
+ // without `allowJs`.
3
+ export const MAX_STASIS_TGZ_BYTES: number
4
+ // An @exodus/stasis-core Bundle, which stasis-core ships no types for.
5
+ export function readStasisTgz(bytes: Uint8Array, options?: { limit?: number }): Promise<{ bundle: unknown; size: number }>
6
+ export function parseStasisTgz(bytes: Uint8Array, options?: { limit?: number }): Promise<unknown>
@@ -0,0 +1,27 @@
1
+ // A .stasis.tgz read the same in the browser and on the server, on the
2
+ // platform's DecompressionStream and WebCrypto (stasis-files.js tells one).
3
+ import { Bundle } from '@exodus/stasis-core/bundle'
4
+ import { decompress } from '@preventive/archive/compression.js'
5
+ import { unpack } from '@preventive/archive/tar.js'
6
+
7
+ // Its tar's bytes at most, as a stasis.code.br's decoded JSON is held to.
8
+ export const MAX_STASIS_TGZ_BYTES = 512 * 1024 * 1024
9
+
10
+ const base64 = bytes => btoa(Array.from(bytes, byte => String.fromCodePoint(byte)).join(''))
11
+
12
+ // The Bundle of a .stasis.tgz's bytes, as Stasis reads one (src/parse.js
13
+ // readStasisTgz): its tar gunzipped, nothing past its gzip but zeros, and
14
+ // unpacked with @preventive/archive, then Bundle.fromTar's, its
15
+ // stasis.lock.json first and every file held to the digest it attests. fromTar asks each file's
16
+ // digest as it reads it, so each is worked out first (SHA-512, as Stasis's
17
+ // sha512integrity). Throws naming what is wrong, as Stasis does. With the
18
+ // bytes its tar takes (`size`), about what holding the bundle takes.
19
+ export async function readStasisTgz(bytes, { limit = MAX_STASIS_TGZ_BYTES } = {}) {
20
+ const tar = await decompress(bytes, 'gzip', { limit })
21
+ const entries = unpack(tar)
22
+ const digests = new Map(await Promise.all(entries.filter(entry => entry.type !== 'directory').map(async ({ data }) =>
23
+ [data, `sha512-${base64(new Uint8Array(await crypto.subtle.digest('SHA-512', data)))}`])))
24
+ return { bundle: Bundle.fromTar(entries, { integrityOf: data => digests.get(data) }), size: tar.length }
25
+ }
26
+
27
+ export const parseStasisTgz = async (bytes, options) => (await readStasisTgz(bytes, options)).bundle
@@ -61,6 +61,26 @@ function rowsOf({ linked, app }) {
61
61
  return ids
62
62
  }
63
63
 
64
+ // Whether a managed report may be switched to open on Confirmed whatever
65
+ // Confirmed hides (Manage → Reports, common/finding-filters.js
66
+ // confirmedCoverage): only where the switch changes something, a set whose
67
+ // pass leaves Confirmed rows of its own to show, but which is no basic App
68
+ // view of its own, as the stricter of the two rules has it (canLockConfirmed):
69
+ // Confirmed would hide a finding the opening range shows, or one not LOW the
70
+ // 6–10 band shows below a floor the opening tuned higher. Asked of the set as
71
+ // the App view merges it, with no copy counted as switched already. A set
72
+ // with contradicting verdicts opens with no App layer, and so with no
73
+ // Confirmed to open on; one of nothing but other analyzers' unjudged findings
74
+ // has no pass to have an answer.
75
+ export function confirmedDefaultOffered(reports, duplicatesOf = () => []) {
76
+ const { groups, conflicts } = mergeReportGroups(reports, { hideRuledOut: true })
77
+ if (conflicts.size > 0) return false
78
+ const linked = mergeLinkedWorkspaceGroups(groups, duplicatesOf, appTabs)
79
+ const kinds = activeRevalidateKinds('confirmed', '')
80
+ if (!linked.map(appTabs).some((g) => g.some((f) => kinds.includes(revalidateKindOf(f))))) return false
81
+ return !canLockConfirmed(linked, { tabs: appTabs, kindOf: revalidateKindOf, severityMode: 'corrected' })
82
+ }
83
+
64
84
  // A workspace's rows as its basic App view merges them, and whether it has one.
65
85
  function appView(reports, duplicatesOf) {
66
86
  const { groups, conflicts } = mergeReportGroups(reports, { hideRuledOut: true })