@preventive/triage 1.0.0-alpha.60 → 1.0.0-alpha.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/default-scan-models.ts +6 -5
- package/common/managed/comments.ts +9 -0
- package/out/activity.js +3 -3
- package/out/brotli-fallback.js +1 -1
- package/out/chunk-4ISO5F7Y.js +1 -1
- package/out/chunk-65PLAG3I.js +12 -0
- package/out/chunk-6CCSTJWB.js +1 -0
- package/out/chunk-7GJNLCXF.js +15 -0
- package/out/chunk-BZP3CT2V.js +244 -0
- package/out/{chunk-TZS7KERJ.js → chunk-DCBXCBLL.js} +2 -2
- package/out/chunk-E3LFSUDJ.js +1 -1
- package/out/chunk-EQ5EQXV5.js +1 -0
- package/out/chunk-F3UI65ZI.js +42 -0
- package/out/chunk-FAG6E5RC.js +3 -0
- package/out/chunk-HAZKDK4M.js +1 -1
- package/out/chunk-IZ6MYRYB.js +1 -1
- package/out/{chunk-VZJIHHTQ.js → chunk-K2QJLP3E.js} +1 -1
- package/out/chunk-NXATZJQ2.js +1 -1
- package/out/chunk-OBNHCORJ.js +2 -0
- package/out/chunk-OGNTXZYM.js +4 -0
- package/out/chunk-QRKFPLA4.js +2 -2
- package/out/chunk-QVKFY4FA.js +1 -0
- package/out/chunk-TOXMUOIW.js +2 -2
- package/out/chunk-WMFDQS2L.js +2 -2
- package/out/chunk-Y5ZHFNBD.js +1 -1
- package/out/client-managed-import.js +1 -1
- package/out/client-managed.js +7 -7
- package/out/client-sync.js +3 -3
- package/out/compare.js +19 -14
- package/out/dialogs.js +38 -38
- package/out/graph.js +12 -12
- package/out/index.html +5 -5
- package/out/prism.js +2 -2
- package/out/scan.js +2 -2
- package/out/terminal.js +150 -148
- package/out/view.css +1 -1
- package/out/view.js +5 -5
- package/package.json +21 -18
- package/risk/files/runs-code.js +2 -2
- package/server-e2e/static.ts +1 -1
- package/server-managed/activity.ts +23 -43
- package/server-managed/agent-merges.ts +2 -2
- package/server-managed/blob-store.ts +10 -1
- package/server-managed/bundle-advisories.ts +3 -2
- package/server-managed/bundle-advisory-inventory.ts +1 -1
- package/server-managed/bundle-build-worker.js +41 -6
- package/server-managed/bundle-build.ts +26 -14
- package/server-managed/bundle-cache.ts +29 -41
- package/server-managed/bundle-catalog.ts +11 -11
- package/server-managed/bundle-commits.ts +9 -16
- package/server-managed/bundle-dependency-reviews.ts +5 -11
- package/server-managed/bundle-summary-cache.ts +23 -14
- package/server-managed/bundle-validation.ts +2 -1
- package/server-managed/combined.ts +1 -5
- package/server-managed/comments.ts +15 -28
- package/server-managed/commit-coauthors.ts +4 -5
- package/server-managed/commit-lockfiles.ts +6 -5
- package/server-managed/comparison.ts +3 -5
- package/server-managed/config.ts +1 -2
- package/server-managed/db-methods.ts +163 -244
- package/server-managed/db-neon.ts +82 -178
- package/server-managed/db-schema.ts +15 -0
- package/server-managed/db.ts +5 -11
- package/server-managed/dependabot-access.ts +2 -1
- package/server-managed/dependabot-alerts.ts +7 -12
- package/server-managed/dependency-review-comments.ts +7 -13
- package/server-managed/dependency-reviews.ts +14 -15
- package/server-managed/github-accounts.ts +4 -5
- package/server-managed/github-actions.ts +6 -6
- package/server-managed/github-app.ts +19 -48
- package/server-managed/github-graphql.ts +5 -2
- package/server-managed/github-issue-links.ts +62 -42
- package/server-managed/github-issue-oauth.ts +7 -24
- package/server-managed/github-issues.ts +9 -7
- package/server-managed/github-link-oauth.ts +7 -20
- package/server-managed/github-oauth.ts +38 -12
- package/server-managed/github-pulls.ts +37 -26
- package/server-managed/github-requests.ts +21 -8
- package/server-managed/github-values.ts +26 -0
- package/server-managed/history-windows.ts +7 -7
- package/server-managed/http.ts +495 -554
- package/server-managed/index.ts +6 -6
- package/server-managed/link-reports.ts +6 -19
- package/server-managed/lockfile-scope.ts +1 -1
- package/server-managed/management.ts +14 -3
- package/server-managed/npm-delta.ts +22 -57
- package/server-managed/npm-insights.ts +31 -26
- package/server-managed/npm-kept.ts +9 -8
- package/server-managed/npm-loads.ts +2 -7
- package/server-managed/npm-manifest.ts +6 -4
- package/server-managed/npm-packages.ts +17 -9
- package/server-managed/npm-patch.ts +8 -16
- package/server-managed/npm-provenance.ts +12 -8
- package/server-managed/npm-risk.ts +9 -7
- package/server-managed/object-storage-disk.ts +2 -3
- package/server-managed/object-storage-vercel.ts +15 -11
- package/server-managed/object-storage.ts +7 -0
- package/server-managed/pretty-print.ts +8 -19
- package/server-managed/public-workspace.ts +50 -46
- package/server-managed/pull-comment-reviews.ts +2 -2
- package/server-managed/pull-dependencies.ts +20 -31
- package/server-managed/pull-dependency-reviews.ts +17 -24
- package/server-managed/pull-reviews.ts +4 -7
- package/server-managed/queue.ts +14 -0
- package/server-managed/release-commits.ts +9 -8
- package/server-managed/rename-diff.ts +17 -60
- package/server-managed/report-migration.ts +5 -8
- package/server-managed/report-sources.ts +6 -10
- package/server-managed/report-store.ts +2 -10
- package/server-managed/repository-actions.ts +7 -8
- package/server-managed/repository-agents.ts +31 -57
- package/server-managed/repository-aliases.ts +3 -9
- package/server-managed/repository-browser.ts +18 -16
- package/server-managed/repository-changes.ts +33 -37
- package/server-managed/repository-code.ts +5 -5
- package/server-managed/repository-dependency-reviews.ts +6 -13
- package/server-managed/repository-discovery.ts +2 -1
- package/server-managed/repository-history.ts +47 -51
- package/server-managed/repository-issues.ts +59 -30
- package/server-managed/repository-pulls.ts +7 -12
- package/server-managed/repository-pulse.ts +51 -45
- package/server-managed/repository-risk-assess.ts +5 -2
- package/server-managed/repository-risk-audit.ts +1 -1
- package/server-managed/repository-risk-read.ts +6 -6
- package/server-managed/repository-risk.ts +32 -40
- package/server-managed/repository-squashes.ts +7 -15
- package/server-managed/request-timing.ts +1 -1
- package/server-managed/sql.ts +18 -0
- package/server-managed/storage-encryption.ts +5 -7
- package/server-managed/team-app.ts +4 -7
- package/server-managed/team-npm-scopes.ts +5 -8
- package/server-managed/team-reports.ts +15 -15
- package/server-managed/type-only-proof.js +108 -0
- package/server-managed/type-only-worker.js +26 -14
- package/server-managed/type-only.ts +90 -60
- package/server-managed/uploads.ts +3 -3
- package/server-managed/upstream-cache.ts +5 -7
- package/server-managed/worker-turns.ts +76 -0
- package/server-managed/workspace-shares.ts +1 -2
- package/strip-types-loader.js +13 -10
- package/out/chunk-2SY4PYUQ.js +0 -4
- package/out/chunk-4HI2MSAV.js +0 -17
- package/out/chunk-4TQKM3JC.js +0 -42
- package/out/chunk-6VDDCFHT.js +0 -3
- package/out/chunk-EEQHVKR3.js +0 -1
- package/out/chunk-HNQNDNIE.js +0 -12
- package/out/chunk-OFPDMZJF.js +0 -244
- package/out/chunk-OQRSIBSC.js +0 -1
- package/out/chunk-YGRRXC2L.js +0 -1
- package/out/chunk-YTO6AQZM.js +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/triage",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.62",
|
|
4
4
|
"description": "Client & relay server for triaging of automated reports",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -140,6 +140,7 @@
|
|
|
140
140
|
"server-managed/github-link-oauth.ts",
|
|
141
141
|
"server-managed/github-links.ts",
|
|
142
142
|
"server-managed/github-users.ts",
|
|
143
|
+
"server-managed/github-values.ts",
|
|
143
144
|
"server-managed/github-oauth.ts",
|
|
144
145
|
"server-managed/github-pulls.ts",
|
|
145
146
|
"server-managed/github-requests.ts",
|
|
@@ -233,10 +234,12 @@
|
|
|
233
234
|
"server-managed/team-reports.ts",
|
|
234
235
|
"server-managed/triage-response.ts",
|
|
235
236
|
"server-managed/type-only.ts",
|
|
237
|
+
"server-managed/type-only-proof.js",
|
|
236
238
|
"server-managed/type-only-worker.js",
|
|
237
239
|
"server-managed/uploads.ts",
|
|
238
240
|
"server-managed/view-as.ts",
|
|
239
241
|
"server-managed/upstream-cache.ts",
|
|
242
|
+
"server-managed/worker-turns.ts",
|
|
240
243
|
"server-managed/workspace-shares.ts",
|
|
241
244
|
"server-common/database-config.ts",
|
|
242
245
|
"server-common/initialize.ts",
|
|
@@ -405,41 +408,41 @@
|
|
|
405
408
|
"test": "node --js-base-64 --require=./tests/_resource-loader.js --experimental-test-module-mocks --test-timeout=120000 --test-concurrency=$(node -p 'Math.ceil(os.availableParallelism() * 1.5)') --test ./tests/*.test.js"
|
|
406
409
|
},
|
|
407
410
|
"devDependencies": {
|
|
408
|
-
"@electric-sql/pglite": "^0.5.
|
|
411
|
+
"@electric-sql/pglite": "^0.5.15",
|
|
409
412
|
"@noble/ciphers": "^2.4.0",
|
|
410
413
|
"@preventive/terminal": "2.0.0-beta.3",
|
|
411
414
|
"@rray/frontend": "^1.0.0",
|
|
412
|
-
"@stylistic/stylelint-plugin": "^
|
|
413
|
-
"@types/node": "^26.6.
|
|
415
|
+
"@stylistic/stylelint-plugin": "^6.0.0",
|
|
416
|
+
"@types/node": "^26.6.6",
|
|
414
417
|
"@types/ws": "^8.18.2",
|
|
415
|
-
"@vercel/functions": "^3.
|
|
418
|
+
"@vercel/functions": "^3.10.6",
|
|
416
419
|
"brotli": "^1.3.3",
|
|
417
420
|
"esbuild": "^0.28.2",
|
|
418
421
|
"lit": "^3.3.3",
|
|
419
422
|
"minify-html-literals": "^1.3.5",
|
|
420
|
-
"oxlint": "^1.
|
|
423
|
+
"oxlint": "^1.91.0",
|
|
421
424
|
"prismjs": "^1.30.0",
|
|
422
|
-
"stylelint": "^
|
|
423
|
-
"stylelint-config-recommended": "^
|
|
425
|
+
"stylelint": "^18.0.0",
|
|
426
|
+
"stylelint-config-recommended": "^19.0.0",
|
|
424
427
|
"typescript": "^7.0.2"
|
|
425
428
|
},
|
|
426
429
|
"dependencies": {
|
|
427
|
-
"@exodus/stasis": "1.0.0-rc.
|
|
428
|
-
"@exodus/stasis-core": "1.0.0-rc.
|
|
430
|
+
"@exodus/stasis": "1.0.0-rc.4",
|
|
431
|
+
"@exodus/stasis-core": "1.0.0-rc.4",
|
|
429
432
|
"@preventive/archive": "^1.4.1",
|
|
430
|
-
"@preventive/compare": "^1.2.
|
|
431
|
-
"@preventive/diff": "^1.1.
|
|
433
|
+
"@preventive/compare": "^1.2.12",
|
|
434
|
+
"@preventive/diff": "^1.1.1",
|
|
432
435
|
"@preventive/lockfile": "^1.3.0",
|
|
433
436
|
"@preventive/publishers": "^1.1.0",
|
|
434
437
|
"@preventive/report": "^1.0.1",
|
|
435
438
|
"@preventive/sourcemap": "1.0.0-alpha.1",
|
|
436
|
-
"@preventive/upstream": "^1.
|
|
439
|
+
"@preventive/upstream": "^1.8.0",
|
|
437
440
|
"css-tree": "^3.2.1",
|
|
438
|
-
"oxc-minify": "^0.
|
|
441
|
+
"oxc-minify": "^0.157.0",
|
|
439
442
|
"oxc-parser": "^0.152.0",
|
|
440
|
-
"oxfmt": "^0.
|
|
441
|
-
"semver": "^7.8.
|
|
442
|
-
"ws": "^8.22.
|
|
443
|
+
"oxfmt": "^0.76.0",
|
|
444
|
+
"semver": "^7.8.6",
|
|
445
|
+
"ws": "^8.22.1"
|
|
443
446
|
},
|
|
444
447
|
"peerDependencies": {
|
|
445
448
|
"@neondatabase/serverless": "^1.0.2",
|
|
@@ -457,5 +460,5 @@
|
|
|
457
460
|
"optional": true
|
|
458
461
|
}
|
|
459
462
|
},
|
|
460
|
-
"packageManager": "pnpm@
|
|
463
|
+
"packageManager": "pnpm@12.17.0+sha512.b8d223ebec04b580a89ed206daa71d1bccb6a1ee1d52efa95cc3b0db75271561df8f0d8e2c43add39c5ec08018af7a8a95108e7090f95a29f88727b7a40fd53d"
|
|
461
464
|
}
|
package/risk/files/runs-code.js
CHANGED
|
@@ -171,7 +171,7 @@ const KEY_ABSENT = /(?:!|\bdelete\s)[\s(]{0,4}(?:[\p{ID_Continue}$]{1,64}\s{0,4}
|
|
|
171
171
|
const ESCAPE = /\\(?:x([\da-f]{2})|u([\da-f]{4})|u\{([\da-f]{1,6})\}|([0-3][0-7]{0,2}|[4-7][0-7]?)|(\r\n|[^]))/giu
|
|
172
172
|
const CONTROLS = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v']])
|
|
173
173
|
const LINE_ENDS = new Set(['\n', '\r', '\r\n', '\u2028', '\u2029'])
|
|
174
|
-
const unescaped = text => text.
|
|
174
|
+
const unescaped = text => text.replaceAll(ESCAPE, (escape, hex, unit, point, octal, char) => {
|
|
175
175
|
if (char !== undefined) return LINE_ENDS.has(char) ? '' : CONTROLS.get(char) ?? char
|
|
176
176
|
const code = octal === undefined ? Number.parseInt(hex ?? unit ?? point, 16) : Number.parseInt(octal, 8)
|
|
177
177
|
return code <= 0x10_FFFF ? String.fromCodePoint(code) : escape
|
|
@@ -477,7 +477,7 @@ function read(code, base, at) {
|
|
|
477
477
|
// its regular expression each time.
|
|
478
478
|
const held = HOLDS_ANY.test(text) ? HOLDS.flatMap(([kind, holds]) => text.search(holds) === -1 ? [] : [...text.matchAll(holds)].map(({ index: within }) => [kind, within])) : []
|
|
479
479
|
for (const [kind, within] of held) if (kind !== 'tokens' || within > 0 || keyed()) at(kind, base + index + within)
|
|
480
|
-
if (text.includes('registry.') && REGISTRY_URL.test(unescaped(text).
|
|
480
|
+
if (text.includes('registry.') && REGISTRY_URL.test(unescaped(text).replaceAll(URL_STRIPPED, ''))) at('registry', base + index)
|
|
481
481
|
for (const [kind, name] of MODULES) if (name.test(string) && loaded(code, index)) at(kind, base + index)
|
|
482
482
|
if (PROFILE.test(string) && HOME_BEFORE.test(code.slice(Math.max(0, index - 100), index))) at('persistence', base + index)
|
|
483
483
|
for (const [part, dir, file] of PARTS) {
|
package/server-e2e/static.ts
CHANGED
|
@@ -244,7 +244,7 @@ function extractPreloadLinks(html: string): { html: string, link: string | null
|
|
|
244
244
|
// when we keep a non-preload tag the whitespace is restored via
|
|
245
245
|
// `return match` (HTML layout preserved).
|
|
246
246
|
const tagRe = /<link\b[^>]*>\s*/giu
|
|
247
|
-
const stripped = html.
|
|
247
|
+
const stripped = html.replaceAll(tagRe, (match, offset: number) => {
|
|
248
248
|
if (inAnyRange(offset, skip)) return match
|
|
249
249
|
const attrs = parseLinkAttrs(match)
|
|
250
250
|
const rel = (attrs['rel'] ?? '').toLowerCase()
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// legacy entries. Never copy annotation bodies or credentials into this feed.
|
|
4
4
|
import { randomUUID } from 'node:crypto'
|
|
5
5
|
import type { DatabaseSync } from 'node:sqlite'
|
|
6
|
-
import type
|
|
6
|
+
import { type ManagedSql, sqliteTransaction } from './sql.ts'
|
|
7
|
+
import { inUserTeamScope } from './db-schema.ts'
|
|
7
8
|
|
|
8
9
|
export interface ActivityInput {
|
|
9
10
|
kind: 'access' | 'repository' | 'visibility' | 'delete'
|
|
@@ -60,57 +61,45 @@ const triageFields = `'triage:' || e.seq AS id, 'triage' AS kind,
|
|
|
60
61
|
COALESCE(u.login, e.actor_login) AS actor, e.actor_id AS actorId,
|
|
61
62
|
CASE WHEN e.color IS NULL AND e.triage IS NULL AND e.comment IS NULL AND e.fix IS NULL AND e.flagged IS NULL
|
|
62
63
|
THEN 'cleared triage' ELSE 'updated triage' END AS action`
|
|
63
|
-
const triage = `SELECT ${triageFields}, e.repo, e.report_id AS reportId, e.report, e.finding_id AS finding, e.at
|
|
64
|
-
FROM managed_finding_triage_event e LEFT JOIN managed_user u ON u.id = e.actor_id`
|
|
65
64
|
const commentFields = `'comment:' || e.seq AS id, 'triage' AS kind,
|
|
66
65
|
COALESCE(u.login, e.actor_login) AS actor, e.actor_id AS actorId, e.action`
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
66
|
+
// The events of a finding trail (`table`), with `fields` and the context each
|
|
67
|
+
// recorded.
|
|
68
|
+
const recordedEvents = (fields: string, table: string) => `SELECT ${fields}, e.repo, e.report_id AS reportId, e.report, e.finding_id AS finding, e.at
|
|
69
|
+
FROM ${table} e LEFT JOIN managed_user u ON u.id = e.actor_id`
|
|
70
|
+
const adminSource = `${recordedEvents(triageFields, 'managed_finding_triage_event')}
|
|
71
|
+
UNION ALL ${recordedEvents(commentFields, 'managed_finding_comment_event')} UNION ALL
|
|
70
72
|
SELECT id, kind, actor, actor_id AS actorId, action, repo, report_id AS reportId, report, NULL AS finding, at FROM managed_activity`
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
|
|
73
|
+
// The events of the accessible findings in a finding trail (`table`), with
|
|
74
|
+
// `fields` and the context the server gives each finding. Keep the finite
|
|
75
|
+
// set of accessible findings outside the indexed event lookup. Scanning all
|
|
76
|
+
// events against json_each for every row is quadratic.
|
|
77
|
+
const contextEvents = (fields: string, table: string) => `SELECT ${fields},
|
|
74
78
|
json_extract(c.value, '$.repo') AS repo, json_extract(c.value, '$.reportId') AS reportId,
|
|
75
79
|
json_extract(c.value, '$.report') AS report, e.finding_id AS finding, e.at
|
|
76
80
|
FROM json_each(:contexts) c
|
|
77
|
-
CROSS JOIN
|
|
78
|
-
LEFT JOIN managed_user u ON u.id = e.actor_id
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
json_extract(c.value, '$.report') AS report, e.finding_id AS finding, e.at
|
|
82
|
-
FROM json_each(:contexts) c
|
|
83
|
-
CROSS JOIN managed_finding_comment_event e ON e.finding_id = json_extract(c.value, '$.finding')
|
|
84
|
-
LEFT JOIN managed_user u ON u.id = e.actor_id
|
|
81
|
+
CROSS JOIN ${table} e ON e.finding_id = json_extract(c.value, '$.finding')
|
|
82
|
+
LEFT JOIN managed_user u ON u.id = e.actor_id`
|
|
83
|
+
const managerSource = `${contextEvents(triageFields, 'managed_finding_triage_event')}
|
|
84
|
+
UNION ALL ${contextEvents(commentFields, 'managed_finding_comment_event')}
|
|
85
85
|
UNION ALL SELECT a.id, a.kind, a.actor, a.actor_id AS actorId,
|
|
86
86
|
CASE WHEN a.kind = 'repository' THEN 'changed a report repository assignment' ELSE a.action END AS action,
|
|
87
87
|
p.full_name AS repo, r.id AS reportId, r.filename AS report, NULL AS finding, a.at
|
|
88
88
|
FROM managed_activity a JOIN managed_report r ON r.id = a.report_id
|
|
89
89
|
LEFT JOIN managed_selected_repo p ON p.repo_id = r.repo_id
|
|
90
|
-
WHERE
|
|
91
|
-
SELECT 1 FROM managed_team_repo tr JOIN managed_team_user tu ON tu.team_id = tr.team_id
|
|
92
|
-
JOIN managed_team t ON t.id = tu.team_id AND t.hidden = 0
|
|
93
|
-
WHERE tu.user_id = :userId AND tr.repo_id = r.repo_id AND ${withinTeamPath('r.repo_directory')}
|
|
94
|
-
)
|
|
90
|
+
WHERE ${inUserTeamScope(':userId', 'r')}
|
|
95
91
|
UNION ALL SELECT a.id, a.kind, a.actor, a.actor_id AS actorId,
|
|
96
92
|
CASE WHEN a.kind = 'repository' THEN 'changed a bundle repository assignment' ELSE a.action END AS action,
|
|
97
93
|
p.full_name AS repo, NULL AS reportId, b.filename AS report, NULL AS finding, a.at
|
|
98
94
|
FROM managed_activity a JOIN managed_bundle b ON b.id = a.bundle_id
|
|
99
95
|
LEFT JOIN managed_selected_repo p ON p.repo_id = b.repo_id
|
|
100
|
-
WHERE a.report_id IS NULL AND
|
|
101
|
-
SELECT 1 FROM managed_team_repo tr JOIN managed_team_user tu ON tu.team_id = tr.team_id
|
|
102
|
-
JOIN managed_team t ON t.id = tu.team_id AND t.hidden = 0
|
|
103
|
-
WHERE tu.user_id = :userId AND tr.repo_id = b.repo_id AND ${withinTeamPath('b.repo_directory')}
|
|
104
|
-
)
|
|
96
|
+
WHERE a.report_id IS NULL AND ${inUserTeamScope(':userId', 'b')}
|
|
105
97
|
UNION ALL SELECT a.id, a.kind, a.actor, a.actor_id AS actorId, a.action, a.repo, a.report_id AS reportId,
|
|
106
98
|
a.report, NULL AS finding, a.at FROM managed_activity a
|
|
107
99
|
WHERE a.kind = 'delete' AND (a.report_id IS NOT NULL OR a.bundle_id IS NOT NULL)
|
|
108
100
|
AND NOT EXISTS (SELECT 1 FROM managed_report WHERE id = a.report_id)
|
|
109
101
|
AND NOT EXISTS (SELECT 1 FROM managed_bundle WHERE id = a.bundle_id)
|
|
110
|
-
AND
|
|
111
|
-
JOIN managed_team t ON t.id = tu.team_id AND t.hidden = 0
|
|
112
|
-
WHERE tu.user_id = :userId AND tr.repo_id = a.repo_id
|
|
113
|
-
AND ${withinTeamPath('a.repo_directory')})`
|
|
102
|
+
AND ${inUserTeamScope(':userId', 'a')}`
|
|
114
103
|
|
|
115
104
|
export const ACTIVITY_SCHEMA = `
|
|
116
105
|
CREATE TABLE IF NOT EXISTS managed_activity (
|
|
@@ -160,9 +149,7 @@ export function activityMethods(db: ManagedSql): ActivityStore {
|
|
|
160
149
|
const manager = activityStatements(db, managerSource)
|
|
161
150
|
const reports = db.prepare(`SELECT r.id AS reportId, r.filename AS report, p.full_name AS repo
|
|
162
151
|
FROM managed_report r JOIN managed_selected_repo p ON p.repo_id = r.repo_id
|
|
163
|
-
WHERE
|
|
164
|
-
JOIN managed_team t ON t.id = tu.team_id AND t.hidden = 0
|
|
165
|
-
WHERE tu.user_id = ? AND tr.repo_id = r.repo_id AND ${withinTeamPath('r.repo_directory')})
|
|
152
|
+
WHERE ${inUserTeamScope('?', 'r')}
|
|
166
153
|
ORDER BY r.uploaded_at DESC, r.id`)
|
|
167
154
|
return {
|
|
168
155
|
async recordActivity(entry, at) {
|
|
@@ -226,17 +213,11 @@ function activityStatements(db: ManagedSql, source: string) {
|
|
|
226
213
|
}
|
|
227
214
|
}
|
|
228
215
|
|
|
229
|
-
// Literal path comparison preserves separators, case and SQL wildcard chars.
|
|
230
|
-
function withinTeamPath(path: string): string {
|
|
231
|
-
return `(tr.path IS NULL OR tr.path = '' OR ${path} = tr.path OR substr(${path}, 1, length(tr.path) + 1) = tr.path || '/')`
|
|
232
|
-
}
|
|
233
|
-
|
|
234
216
|
function migrateActivityScope(db: DatabaseSync): void {
|
|
235
217
|
const columns = new Set((db.prepare('PRAGMA table_info(managed_activity)').all() as { name: string }[]).map(column => column.name))
|
|
236
218
|
const missing = [['bundle_id', 'TEXT'], ['repo_id', 'INTEGER'], ['repo_directory', 'TEXT'], ['actor_id', 'TEXT']].filter(([name]) => !columns.has(name!))
|
|
237
219
|
if (missing.length === 0) return
|
|
238
|
-
db
|
|
239
|
-
try {
|
|
220
|
+
sqliteTransaction(db, 'BEGIN', () => {
|
|
240
221
|
for (const [name, type] of missing) db.exec(`ALTER TABLE managed_activity ADD COLUMN ${name} ${type}`)
|
|
241
222
|
if (!columns.has('bundle_id') || !columns.has('actor_id')) {
|
|
242
223
|
db.exec('DROP TRIGGER IF EXISTS managed_report_activity; DROP TRIGGER IF EXISTS managed_bundle_activity;')
|
|
@@ -253,6 +234,5 @@ function migrateActivityScope(db: DatabaseSync): void {
|
|
|
253
234
|
}
|
|
254
235
|
// Legacy deletions/assignments without a durable target/scope remain
|
|
255
236
|
// admin-only; neither filenames nor repository names authorize access.
|
|
256
|
-
|
|
257
|
-
} catch (err) { db.exec('ROLLBACK'); throw err }
|
|
237
|
+
})
|
|
258
238
|
}
|
|
@@ -19,8 +19,8 @@ const REBASE_SKEW_MS = 10 * 60_000
|
|
|
19
19
|
// Commits tab tells those squashed too, http.ts pulseMerges; none of one
|
|
20
20
|
// kept before numbers were), and one rebased so (`pullRebases`), for the
|
|
21
21
|
// commits pushed to the branch directly to be told (directCommits).
|
|
22
|
-
export interface AgentMerges { merges: [string, number][]; rebases: Rebase[]
|
|
23
|
-
|
|
22
|
+
export interface AgentMerges extends Pick<PullList, 'through' | 'reach' | 'next'> { merges: [string, number][]; rebases: Rebase[]
|
|
23
|
+
pulls?: [sha: string, at: number, number?: number][]; pullRebases?: Rebase[] }
|
|
24
24
|
// A pull request rebased onto the branch: its last commit there, when it was
|
|
25
25
|
// merged, its latest commits' subjects, the oldest first, and how many more
|
|
26
26
|
// it had than those read (`more`).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Logical upload-store interfaces shared by disk and Vercel storage.
|
|
2
|
-
import
|
|
2
|
+
import { Buffer } from 'node:buffer'
|
|
3
3
|
import type { Readable } from 'node:stream'
|
|
4
4
|
|
|
5
5
|
export interface OpenedBlob {
|
|
@@ -15,3 +15,12 @@ export interface BlobStore {
|
|
|
15
15
|
open(id: string): Promise<OpenedBlob | null>
|
|
16
16
|
delete(id: string): Promise<void>
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
// A blob's bytes whole, its stream closed however the read ends.
|
|
20
|
+
export async function readBytes(stored: OpenedBlob): Promise<Buffer> {
|
|
21
|
+
const parts: Buffer[] = []
|
|
22
|
+
try {
|
|
23
|
+
for await (const part of stored.stream) parts.push(Buffer.from(part))
|
|
24
|
+
return Buffer.concat(parts)
|
|
25
|
+
} finally { stored.stream.destroy() }
|
|
26
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type Advisory, type CacheStore, type Package, advisories } from '@preventive/upstream/advisories.js'
|
|
2
2
|
import { type Client, HttpError, createClient } from '@preventive/upstream/github.js'
|
|
3
|
+
import { USER_AGENT } from './github-requests.ts'
|
|
3
4
|
|
|
4
5
|
export const ADVISORIES_TIMEOUT_MS = 30_000
|
|
5
6
|
|
|
6
7
|
function advisoryGithubClient(token: string | null, signal: AbortSignal): Client {
|
|
7
|
-
const authenticated = createClient({ token, userAgent:
|
|
8
|
+
const authenticated = createClient({ token, userAgent: USER_AGENT })
|
|
8
9
|
let client = authenticated
|
|
9
10
|
// Published advisories, and whether a repository is public, remain
|
|
10
11
|
// readable after a token is revoked. Reuse anonymous access for subsequent
|
|
@@ -14,7 +15,7 @@ function advisoryGithubClient(token: string | null, signal: AbortSignal): Client
|
|
|
14
15
|
try { return await ask(current) } catch (error) {
|
|
15
16
|
if (token === null || current !== authenticated || !(error instanceof HttpError) || error.status !== 401) throw error
|
|
16
17
|
signal.throwIfAborted()
|
|
17
|
-
if (client === authenticated) client = createClient({ token: null, userAgent:
|
|
18
|
+
if (client === authenticated) client = createClient({ token: null, userAgent: USER_AGENT })
|
|
18
19
|
return await ask(client)
|
|
19
20
|
}
|
|
20
21
|
}
|
|
@@ -3,7 +3,7 @@ import { packageRepo } from '@exodus/stasis-core/bundle-util'
|
|
|
3
3
|
import type { Package } from '@preventive/upstream/advisories.js'
|
|
4
4
|
import type { BundleDetails } from '../common/bundle-metadata.js'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
interface SkippedAdvisoryPackage {
|
|
7
7
|
ecosystem: string
|
|
8
8
|
name: string
|
|
9
9
|
version: string
|
|
@@ -86,7 +86,7 @@ async function projectDirectory(input, github, client) {
|
|
|
86
86
|
// Input validation permits either JS/TS entries or Solidity entries, never a mix.
|
|
87
87
|
const manifests = input.entries[0].endsWith('.sol') ? ['foundry.toml', 'soldeer.toml', 'soldeer.lock'] : ['package.json']
|
|
88
88
|
if (!input.directory) return ''
|
|
89
|
-
for (let directory = input.directory; ; directory =
|
|
89
|
+
for (let directory = input.directory; ; directory = parentOf(directory)) {
|
|
90
90
|
const entries = await directoryListing(input, github, client, directory)
|
|
91
91
|
if (entries?.some(entry => manifests.includes(entry.path) && regularFile(entry))) return directory
|
|
92
92
|
if (!directory) return input.directory
|
|
@@ -104,15 +104,24 @@ async function packageName(input, github, project, bundle, client) {
|
|
|
104
104
|
return typeof name === 'string' ? name : null
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
// `note` is told what the build log keeps of a build beside its stages: the
|
|
108
|
+
// directory Stasis builds from (`project`), and each tree it downloads of the
|
|
109
|
+
// repo (`download`), the whole repo's or a directory's, and its bytes.
|
|
110
|
+
export async function buildStasisBundle({ input, github, token, maxBytes, scopes, cacheDir = null }, client = createClient({ token }), progress = () => {}, note = () => {}) {
|
|
108
111
|
const allowed = path => scopes.some(scope => !scope || path === scope || path.startsWith(scope + '/'))
|
|
109
112
|
// Reuse these immutable listings when Stasis discovers the lockfile root.
|
|
110
113
|
const listings = new Map()
|
|
114
|
+
const downloaded = (tree, read) => async options => {
|
|
115
|
+
const bytes = await read(options)
|
|
116
|
+
note('download', { tree, bytes: bytes.length })
|
|
117
|
+
return bytes
|
|
118
|
+
}
|
|
111
119
|
const buildClient = { ...client, listRepoDir(options) {
|
|
112
120
|
const key = JSON.stringify([options.repo, options.sha, options.directory ?? ''])
|
|
113
121
|
if (!listings.has(key)) listings.set(key, client.listRepoDir(options))
|
|
114
122
|
return listings.get(key)
|
|
115
|
-
}
|
|
123
|
+
}, getRepoTarball: downloaded('repo', options => client.getRepoTarball(options)),
|
|
124
|
+
getRepoTreeTarball: downloaded('directory', options => client.getRepoTreeTarball(options)) }
|
|
116
125
|
// Upstream's disk cache keeps the npm tarballs and version documents, and
|
|
117
126
|
// the repo's tree, in `cacheDir`; without one (Vercel), nothing is kept on
|
|
118
127
|
// disk. This fresh worker inherits no application credentials but NPM_TOKEN.
|
|
@@ -134,6 +143,7 @@ export async function buildStasisBundle({ input, github, token, maxBytes, scopes
|
|
|
134
143
|
// config's generatePrisma leaves it.
|
|
135
144
|
const { packageManager, ...options } = input.options
|
|
136
145
|
const named = packageManager !== undefined && !namesLockfiles(await configText(project) ?? '{}')
|
|
146
|
+
note('project', { project, configured: configured !== null, ...(named && { packageManager }) })
|
|
137
147
|
const { bundle } = await buildGitHubBundle({
|
|
138
148
|
github, sha: input.commit, directory: project || undefined,
|
|
139
149
|
entries: input.entries.map(entry => posix.relative(project || '.', entry)),
|
|
@@ -169,7 +179,10 @@ export async function buildStasisBundle({ input, github, token, maxBytes, scopes
|
|
|
169
179
|
// the config's or an entry's, is the policy's; one it can't read, build with
|
|
170
180
|
// its options, or lay out the lockfiles it names of, is the config's. A build
|
|
171
181
|
// the repository's stasis.lock.json disagrees with, or that its lock mode
|
|
172
|
-
// holds to one that isn't there, is the stasis.lock.json's.
|
|
182
|
+
// holds to one that isn't there, is the stasis.lock.json's. A commit Stasis
|
|
183
|
+
// finds in the history of none of the repo's branches or tags (a fork's,
|
|
184
|
+
// which GitHub serves through the repo's name too), or can't tell of past its
|
|
185
|
+
// branches compared, isn't the repo's own.
|
|
173
186
|
export function buildErrorCode(error, message) {
|
|
174
187
|
if (['build-scope', 'too-large', 'bad-conditions', 'config-invalid', 'config-mixed', 'config-conditions'].includes(message)) return message
|
|
175
188
|
if (error instanceof HttpError) return error.status === 429 ? 'github-rate-limited' : 'github-build-failed'
|
|
@@ -178,19 +191,39 @@ export function buildErrorCode(error, message) {
|
|
|
178
191
|
if (/\bstasis\.config\.json(?:: entries .*?)?: (?:allowed|disallowed)(?:Paths|Modules) (?:refuses|does not allow|allows none of) /u.test(message)) return 'config-policy'
|
|
179
192
|
if (/\bstasis\.config\.json(?: is not valid JSON|: |'s lockfiles )/u.test(message)) return 'config-invalid'
|
|
180
193
|
if (/\bstasis\.lock\.json(?::| isn't there,| \(lock = )/u.test(message)) return 'stasis-lock'
|
|
194
|
+
if (/ is in the history of no branch or tag of | is at no tag or branch head of .+ nor in its default branch's history/u.test(message)) return 'commit-not-own'
|
|
181
195
|
return /no packageManager given|lockfile installs|no (?:pnpm-lock\.yaml|yarn\.lock|package-lock\.json|soldeer\.lock) found in /u.test(message) ? 'build-lockfile' : 'build-failed'
|
|
182
196
|
}
|
|
183
197
|
|
|
198
|
+
// The status a failed build answers with, by its code: 422 for any other.
|
|
199
|
+
const FAILED_STATUS = new Map([['too-large', 413], ['build-scope', 403], ['bad-conditions', 400]])
|
|
200
|
+
|
|
201
|
+
// The worker's memory as the build log keeps it, in MiB: the process's
|
|
202
|
+
// resident set (the server's with it), and this worker's own heap, used (what
|
|
203
|
+
// is garbage not yet collected among it) and held, what is bound to its
|
|
204
|
+
// objects outside it, and its ArrayBuffers.
|
|
205
|
+
const MEMORY_EVERY_MS = 5000
|
|
206
|
+
function memoryOf() {
|
|
207
|
+
const { rss, heapUsed, heapTotal, external, arrayBuffers } = process.memoryUsage()
|
|
208
|
+
const mib = bytes => Math.round(bytes / 1024 ** 2)
|
|
209
|
+
return { rssMib: mib(rss), heapUsedMib: mib(heapUsed), heapTotalMib: mib(heapTotal), externalMib: mib(external), arrayBuffersMib: mib(arrayBuffers) }
|
|
210
|
+
}
|
|
211
|
+
|
|
184
212
|
if (parentPort && workerData?.type === 'managed-bundle-build') {
|
|
185
213
|
// Send diagnostics to the request's parent thread, which writes them before
|
|
186
214
|
// returning the HTTP response. Worker stdout can be lost on termination.
|
|
215
|
+
// Its memory too, at each stage and every MEMORY_EVERY_MS, so that the log
|
|
216
|
+
// tells where it grew of a worker terminated past its heap.
|
|
187
217
|
const send = (message, transfer = []) => {
|
|
188
218
|
// Node worker messages have no browser target origin.
|
|
189
219
|
// oxlint-disable-next-line unicorn/require-post-message-target-origin
|
|
190
220
|
parentPort.postMessage(message, transfer)
|
|
191
221
|
}
|
|
222
|
+
const reporting = setInterval(() => send({ type: 'memory', memory: memoryOf() }), MEMORY_EVERY_MS)
|
|
223
|
+
reporting.unref()
|
|
192
224
|
try {
|
|
193
|
-
const built = await buildStasisBundle(workerData, undefined, stage => send({ type: 'progress', stage })
|
|
225
|
+
const built = await buildStasisBundle(workerData, undefined, stage => send({ type: 'progress', stage, memory: memoryOf() }),
|
|
226
|
+
(event, details) => send({ type: 'note', event, details }))
|
|
194
227
|
// The bytes handed over rather than copied, where they alone fill their
|
|
195
228
|
// buffer (a small one may share Node's pool, which can't be moved).
|
|
196
229
|
const { bytes } = built
|
|
@@ -198,6 +231,8 @@ if (parentPort && workerData?.type === 'managed-bundle-build') {
|
|
|
198
231
|
} catch (error) {
|
|
199
232
|
const diagnostic = bundleBuildDiagnostic(error, workerData.token)
|
|
200
233
|
const code = buildErrorCode(error, diagnostic.message)
|
|
201
|
-
send({ error: code, status: code
|
|
234
|
+
send({ error: code, status: FAILED_STATUS.get(code) ?? 422, diagnostic, memory: memoryOf() })
|
|
235
|
+
} finally {
|
|
236
|
+
clearInterval(reporting)
|
|
202
237
|
}
|
|
203
238
|
}
|
|
@@ -13,7 +13,7 @@ export class BundleBuildError extends Error {
|
|
|
13
13
|
constructor(status: number, code: string) { super(code); this.status = status; this.code = code }
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
interface BundleBuildInput {
|
|
17
17
|
repoId: number
|
|
18
18
|
commit: string
|
|
19
19
|
entries: string[]
|
|
@@ -105,11 +105,12 @@ export function githubBundleFilename(github: string, directory: string, commit:
|
|
|
105
105
|
return `${repo}.${dir}${tail}`
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
interface BuiltBundle { bytes: Buffer; directory: string; filename: string }
|
|
109
|
+
interface BuildRequest {
|
|
110
110
|
input: BundleBuildInput; github: string; token: string | null; maxBytes: number; scopes: (string | null)[]
|
|
111
111
|
// Upstream's disk cache for what a build fetches (setCacheDir), or null for
|
|
112
|
-
// none, as on Vercel. Resolved here: the worker's env holds NPM_TOKEN
|
|
112
|
+
// none, as on Vercel. Resolved here: the worker's env holds NPM_TOKEN and
|
|
113
|
+
// VERCEL_ENV alone.
|
|
113
114
|
cacheDir: string | null
|
|
114
115
|
}
|
|
115
116
|
// An extra per-process ceiling, one build at a time, its worker given the heap
|
|
@@ -128,7 +129,8 @@ const MAX_ACTIVE_BUILDS = 1
|
|
|
128
129
|
// terminates the worker (build-memory), not the process.
|
|
129
130
|
const RESERVED_MIB = 512
|
|
130
131
|
const MIN_BUILD_HEAP_MIB = 512
|
|
131
|
-
|
|
132
|
+
const processMemory = () => Math.min(process.constrainedMemory() || Infinity, totalmem())
|
|
133
|
+
export function buildHeapLimitMib(memory = processMemory()): number {
|
|
132
134
|
return Math.max(MIN_BUILD_HEAP_MIB, Math.floor(memory / 1024 ** 2) - RESERVED_MIB)
|
|
133
135
|
}
|
|
134
136
|
|
|
@@ -171,8 +173,11 @@ export async function buildRepositoryBundle(userId: string, request: BuildReques
|
|
|
171
173
|
let stage: BundleBuildStage = 'worker-start'
|
|
172
174
|
const buildId = randomUUID(), started = performance.now()
|
|
173
175
|
const heapLimitMib = buildHeapLimitMib()
|
|
176
|
+
// How this Node was built, as it decides what a heap holds the same objects in.
|
|
177
|
+
const { v8_enable_pointer_compression: pointerCompression, v8_enable_sandbox: v8Sandbox } = process.config.variables as Record<string, unknown>
|
|
174
178
|
const context = { buildId, repoId: request.input.repoId, github: request.github, commit: request.input.commit,
|
|
175
|
-
directory: request.input.directory, entryCount: request.input.entries.length, node: process.version,
|
|
179
|
+
directory: request.input.directory, entryCount: request.input.entries.length, node: process.version, v8: process.versions.v8, pointerCompression, v8Sandbox,
|
|
180
|
+
memoryMib: Math.round(processMemory() / 1024 ** 2), heapLimitMib }
|
|
176
181
|
const log = (event: string, details: Record<string, unknown> = {}) => {
|
|
177
182
|
const write = event === 'failed' ? console.error : console.info
|
|
178
183
|
write('managed-bundle-build:', JSON.stringify({ ...context, workerUrl: workerUrl?.href, event, stage, elapsedMs: Math.round(performance.now() - started), ...details }))
|
|
@@ -181,9 +186,12 @@ export async function buildRepositoryBundle(userId: string, request: BuildReques
|
|
|
181
186
|
workerUrl = new URL('./bundle-build-worker.js', import.meta.url)
|
|
182
187
|
log('started')
|
|
183
188
|
// Upstream reads NPM_TOKEN from the env for scoped packages, which npm
|
|
184
|
-
// answers with 404 when private and asked without it.
|
|
185
|
-
|
|
186
|
-
|
|
189
|
+
// answers with 404 when private and asked without it. Stasis reads
|
|
190
|
+
// VERCEL_ENV, set or not as here, to parse without oxc-parser's raw
|
|
191
|
+
// transfer on Vercel, whose functions can't reserve its 6 GiB buffer.
|
|
192
|
+
// Nothing else passes.
|
|
193
|
+
const npmToken = process.env['NPM_TOKEN'], vercelEnv = process.env['VERCEL_ENV']
|
|
194
|
+
const env = { ...(npmToken ? { NPM_TOKEN: npmToken } : {}), ...(vercelEnv === undefined ? {} : { VERCEL_ENV: vercelEnv }) }
|
|
187
195
|
worker = new Worker(workerUrl, {
|
|
188
196
|
workerData: { ...request, type: 'managed-bundle-build' }, env, execArgv: [], resourceLimits: { maxOldGenerationSizeMb: heapLimitMib },
|
|
189
197
|
})
|
|
@@ -199,13 +207,17 @@ export async function buildRepositoryBundle(userId: string, request: BuildReques
|
|
|
199
207
|
reject(new BundleBuildError(status, code))
|
|
200
208
|
}
|
|
201
209
|
const timer = setTimeout(() => fail(504, 'build-timeout'), BUNDLE_BUILD_TIMEOUT_MS)
|
|
202
|
-
const abort = () =>
|
|
203
|
-
signal.reason instanceof BundleBuildError ? signal.reason.code : 'build-cancelled')
|
|
210
|
+
const abort = () => signal.reason instanceof BundleBuildError ? fail(signal.reason.status, signal.reason.code) : fail(499, 'build-cancelled')
|
|
204
211
|
signal.addEventListener('abort', abort, { once: true })
|
|
205
|
-
|
|
212
|
+
// The worker's memory and notes are the log's alone: the response tells
|
|
213
|
+
// the bundle, or the error's code, and nothing of them.
|
|
214
|
+
running.on('message', (message: Omit<BuiltBundle, 'bytes'> & { bytes: Uint8Array; type?: string; stage?: BundleBuildStage; error?: string; status?: number;
|
|
215
|
+
diagnostic?: BundleBuildDiagnostic; memory?: Record<string, number>; event?: string; details?: Record<string, unknown> }) => {
|
|
206
216
|
if (settled) return
|
|
207
|
-
if (message.type === 'progress' && message.stage) { stage = message.stage; log('progress'); return }
|
|
208
|
-
if (message.
|
|
217
|
+
if (message.type === 'progress' && message.stage) { stage = message.stage; log('progress', { memory: message.memory }); return }
|
|
218
|
+
if (message.type === 'memory') { log('memory', { memory: message.memory }); return }
|
|
219
|
+
if (message.type === 'note' && typeof message.event === 'string') { log(message.event, message.details ?? {}); return }
|
|
220
|
+
if (message.error) { fail(message.status ?? 422, message.error, { diagnostic: message.diagnostic, memory: message.memory }); return }
|
|
209
221
|
settled = true
|
|
210
222
|
cleanup()
|
|
211
223
|
log('completed', { byteSize: message.bytes.length })
|