rvlib-shipkit 2.23.0 → 2.25.0
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/CHANGELOG.md +45 -0
- package/package.json +1 -1
- package/src/agent-time/live.ts +153 -0
- package/src/agent-time/render.ts +28 -14
- package/src/agent-time/report.ts +46 -25
- package/src/agent-time/store.ts +30 -10
- package/src/agent-time/timeline.ts +43 -15
- package/src/annex/offload.ts +16 -7
- package/src/asks/asks-queue.ts +32 -11
- package/src/check.ts +3 -1
- package/src/checks/SK004-gitignore-policy.check.ts +32 -11
- package/src/checks/SK027-agent-wiki-links.check.ts +1 -1
- package/src/checks/SK033-global-contribution.check.ts +1 -1
- package/src/checks/SK036-draft-media-size.check.ts +1 -1
- package/src/checks/SK040-release-words.check.ts +1 -1
- package/src/checks/SK042-post-kinds.check.ts +1 -1
- package/src/checks/SK044-behind-upstream.check.ts +38 -0
- package/src/cli/cmd_Annex.ts +12 -7
- package/src/cli/cmd_Asks.ts +2 -0
- package/src/cli/cmd_Assets.ts +5 -5
- package/src/cli/cmd_Backup.ts +16 -8
- package/src/cli/cmd_Bump.ts +1 -0
- package/src/cli/cmd_Capacity.ts +30 -0
- package/src/cli/cmd_Check.ts +1 -0
- package/src/cli/cmd_Checks.ts +13 -1
- package/src/cli/cmd_Ci.ts +3 -2
- package/src/cli/cmd_Commands.ts +61 -16
- package/src/cli/cmd_ConfigKeys.ts +17 -0
- package/src/cli/cmd_Home.ts +1 -30
- package/src/cli/cmd_Hooks.ts +1 -0
- package/src/cli/cmd_Keys.ts +4 -1
- package/src/cli/cmd_Lanes.ts +35 -0
- package/src/cli/cmd_Mv.ts +7 -7
- package/src/cli/cmd_Rec.ts +22 -7
- package/src/cli/cmd_Reflect.ts +1 -0
- package/src/cli/cmd_Releases.ts +1 -0
- package/src/cli/cmd_Review.ts +200 -49
- package/src/cli/cmd_Secret.ts +41 -2
- package/src/cli/cmd_Shot.ts +16 -4
- package/src/cli/cmd_Status.ts +7 -5
- package/src/cli/cmd_Time.ts +13 -5
- package/src/cli/cmd_Tmp.ts +82 -0
- package/src/cli/cmd_Veille.ts +10 -6
- package/src/cli/cmd_Wiki.ts +1 -0
- package/src/cli/family-help.ts +136 -0
- package/src/cli/family-pages.ts +0 -19
- package/src/cli/kit/calls.ts +35 -0
- package/src/cli/kit/project-cli.ts +2 -12
- package/src/cli/registry.ts +52 -7
- package/src/cli.ts +8 -4
- package/src/collections/pings.ts +1 -1
- package/src/core/capacity.ts +127 -0
- package/src/core/check-runner.ts +91 -16
- package/src/core/floor-resolve.ts +6 -2
- package/src/core/floor.ts +6 -2
- package/src/core/history-files.ts +18 -0
- package/src/core/jobs.ts +35 -16
- package/src/core/layout.ts +2 -2
- package/src/core/motherhome.ts +67 -9
- package/src/core/nearest.ts +16 -0
- package/src/core/remove-tree.ts +19 -0
- package/src/core/runs.ts +12 -3
- package/src/core/slots.ts +49 -12
- package/src/core/throwaway-worktree.ts +22 -4
- package/src/core/trace-audit.ts +21 -5
- package/src/drill/run.ts +5 -2
- package/src/home/daemon-jobs.ts +41 -4
- package/src/home/gui-app/ShipkitGui.swift +1 -0
- package/src/home/home-launchd.ts +11 -3
- package/src/home/home-routes.ts +11 -4
- package/src/home/machine-host.ts +65 -0
- package/src/home/machine-stores.ts +19 -17
- package/src/home/machine-temp.ts +485 -0
- package/src/home/other-macs.ts +74 -0
- package/src/home/run-daemon.ts +10 -2
- package/src/home/serve-web.ts +2 -2
- package/src/home/via-hub.ts +6 -1
- package/src/init-repo.ts +7 -3
- package/src/ledger/gate-checks.ts +3 -2
- package/src/ledger/git-key.ts +25 -4
- package/src/ledger/git-scan.ts +10 -0
- package/src/ledger/ledger.ts +6 -0
- package/src/ledger/store.ts +6 -0
- package/src/media-store/backup/daemon.ts +92 -20
- package/src/media-store/backup/keys.ts +21 -6
- package/src/media-store/backup/manifest.ts +52 -11
- package/src/media-store/backup/restore.ts +17 -10
- package/src/media-store/backup/run.ts +26 -17
- package/src/media-store/backup/sources.ts +168 -22
- package/src/media-store/backup/watch.ts +106 -0
- package/src/media-store/daemon.ts +36 -8
- package/src/media-store/hand.ts +3 -1
- package/src/mv/mv-md.ts +167 -56
- package/src/pb/run-pb.ts +2 -10
- package/src/plan/repo-source.ts +25 -14
- package/src/recordings/model.ts +1 -1
- package/src/reflect/transcript.ts +56 -11
- package/src/release/run-bump.ts +3 -2
- package/src/release/run-release.ts +12 -4
- package/src/releases/from-card.ts +45 -3
- package/src/releases/model.ts +6 -0
- package/src/releases/store.ts +8 -1
- package/src/repo-config.ts +5 -3
- package/src/review/cells.ts +26 -4
- package/src/review/format.ts +34 -10
- package/src/review/media-kind.ts +14 -11
- package/src/review/media-read.ts +6 -5
- package/src/review/model.ts +85 -4
- package/src/review/paste.ts +2 -1
- package/src/review/previews.ts +123 -36
- package/src/review/routes.ts +29 -18
- package/src/review/store.ts +89 -19
- package/src/review/threads.ts +7 -5
- package/src/review/trailer-model.ts +2 -2
- package/src/secrets/copy.ts +110 -0
- package/src/secrets/list.ts +17 -7
- package/src/serve/hub-app/home-strip.css +5 -0
- package/src/serve/hub-app/home-strip.tsx +18 -0
- package/src/serve/hub-app/hub-app.tsx +2 -1
- package/src/serve/hub-app/hub.css +14 -0
- package/src/serve/hub-app/inbox.css +1 -0
- package/src/serve/hub-app/pull-refresh.tsx +88 -0
- package/src/serve/hub-app/review/review-cells.tsx +52 -13
- package/src/serve/hub-app/review/review-list.tsx +6 -1
- package/src/serve/hub-app/review/review-st.ts +6 -5
- package/src/serve/hub-app/review/review-thread.tsx +3 -1
- package/src/serve/hub-app/review/review-views.tsx +18 -11
- package/src/serve/hub-app/review/thread-st.ts +82 -14
- package/src/serve/hub-app/review.css +15 -2
- package/src/serve/hub-runtime.ts +2 -1
- package/src/serve/run-serve.ts +4 -2
- package/src/serve/serve-hub.ts +9 -2
- package/src/shot/client.ts +4 -2
- package/src/shot/serve-shot.ts +71 -2
- package/src/shot/shooter.ts +65 -11
- package/src/shot/shot-ask.ts +32 -9
- package/src/suite/child-tools.ts +45 -0
- package/src/suite/judge-suites.ts +10 -22
- package/src/suite/select.ts +95 -9
- package/src/suite/suite-cli.ts +38 -14
- package/src/suite/suite-cores.ts +68 -0
- package/src/suite/suite-reads-preload.ts +8 -6
- package/src/suite/test-units.ts +31 -12
- package/src/trailer/graph.ts +2 -1
- package/src/ts/config.ts +21 -0
- package/src/ts/rename.ts +37 -13
- package/src/ts/workspaces.ts +45 -0
- package/src/wiki/run-wiki.ts +7 -2
- package/src/wiki/scan-md.ts +2 -1
- package/src/home/claude-temp.ts +0 -139
package/src/shot/shot-ask.ts
CHANGED
|
@@ -20,8 +20,13 @@ export type ShotAsk = {
|
|
|
20
20
|
/** a still of a stepped page: `window[step](at)` on a fresh load, then its ready mark, then the shot */
|
|
21
21
|
step?: string
|
|
22
22
|
at?: number
|
|
23
|
+
/** the whole page, past the viewport's height (a still only) */
|
|
24
|
+
full?: boolean
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
/** a still of the whole page stops at this many device pixels high: chromium draws no taller surface */
|
|
28
|
+
export const FULL_MAX_PX = 16_384
|
|
29
|
+
|
|
25
30
|
export type ClipAsk = ShotAsk & {
|
|
26
31
|
seconds: number
|
|
27
32
|
fps: number
|
|
@@ -52,17 +57,17 @@ export function parseViewport(s: string): Viewport {
|
|
|
52
57
|
const m = /^\s*(\d+)\s*[,x]\s*(\d+)\s*$/.exec(s)
|
|
53
58
|
const width = Number(m?.[1])
|
|
54
59
|
const height = Number(m?.[2])
|
|
55
|
-
if (!m || width < 16 || height < 16 || width > 7680 || height > 4320) throw new Error(`--viewport '${s}' is not w,h in pixels (16 to 7680 by 4320), like 1280,720`)
|
|
60
|
+
if (!m || width < 16 || height < 16 || width > 7680 || height > 4320) throw new Error(`--viewport '${s}' is not w,h in pixels (16 to 7680 by 4320), like 1280,720; a whole tall page: --full`)
|
|
56
61
|
return { width, height }
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
/** a bare `localhost:5173/x` or `/x` against nothing reads as http */
|
|
64
|
+
/** a bare `localhost:5173/x` or `/x` against nothing reads as http; a `file://` url is kept */
|
|
60
65
|
export function normalizeUrl(s: string): string {
|
|
61
66
|
const t = s.trim()
|
|
62
|
-
if (/^https
|
|
67
|
+
if (/^(https?|file):\/\//.test(t)) return t
|
|
63
68
|
if (/^(localhost|127\.0\.0\.1|\[::1\]|[\w.-]+\.\w+)(:\d+)?(\/|$)/.test(t)) return `http://${t}`
|
|
64
69
|
if (/^:\d+(\/|$)/.test(t)) return `http://localhost${t}`
|
|
65
|
-
throw new Error(`'${s}' is not a url: give http://host:port/path, localhost:5173/path
|
|
70
|
+
throw new Error(`'${s}' is not a url: give http://host:port/path, localhost:5173/path, :5173/path, or the path of a file`)
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
/** a still's quality as webp or jpeg: the page's text stays sharp at about an eighth of the png's bytes (a 1280x800
|
|
@@ -79,7 +84,7 @@ export function stillFormat(out: string): { format: 'webp' | 'jpeg'; quality: nu
|
|
|
79
84
|
* is a webp */
|
|
80
85
|
export function defaultOut(url: string, ext: 'webp' | 'mp4'): string {
|
|
81
86
|
const u = new URL(url)
|
|
82
|
-
const slug = `${u.hostname}-${u.port || (u.protocol === 'https:' ? '443' : '80')}${u.pathname}${u.search}${u.hash}`
|
|
87
|
+
const slug = (u.protocol === 'file:' ? `file-${u.pathname.split('/').pop() ?? ''}` : `${u.hostname}-${u.port || (u.protocol === 'https:' ? '443' : '80')}${u.pathname}${u.search}${u.hash}`)
|
|
83
88
|
.replace(/[^\w.-]+/g, '-')
|
|
84
89
|
.replace(/-+/g, '-')
|
|
85
90
|
.replace(/^-|-$/g, '')
|
|
@@ -100,6 +105,7 @@ export type ShotFlags = {
|
|
|
100
105
|
dom?: boolean
|
|
101
106
|
step?: string
|
|
102
107
|
at?: string
|
|
108
|
+
full?: boolean
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
const positive = (flag: string, s: string, max: number): number => {
|
|
@@ -115,6 +121,7 @@ export function askOf(f: ShotFlags, cwd: string): ShotAsk | ClipAsk {
|
|
|
115
121
|
if (seconds != null && seconds > MAX_CLIP_SECONDS && f.long !== true) throw new Error(`--video ${seconds}: a clip past ${MAX_CLIP_SECONDS} s needs --long (a long clip is a long wait and a big file)`)
|
|
116
122
|
if (seconds == null && f.fps != null) throw new Error('--fps only applies to a clip: add --video <seconds>')
|
|
117
123
|
if (seconds == null && f.dom === true) throw new Error('--dom only applies to a clip: add --video <seconds>')
|
|
124
|
+
if (seconds != null && f.full === true) throw new Error('--full only applies to a still: a clip films the viewport (--viewport w,h)')
|
|
118
125
|
if (f.step != null && !/^[A-Za-z_$][\w$]*$/.test(f.step)) throw new Error(`--step '${f.step}' is not a window function name, like __trailerStep`)
|
|
119
126
|
if (f.at != null && f.step == null) throw new Error('--at only applies to a stepped still: add --step <hook>')
|
|
120
127
|
if (f.at != null && seconds != null) throw new Error('--at only applies to a still: a stepped clip draws every time from 0')
|
|
@@ -129,7 +136,7 @@ export function askOf(f: ShotFlags, cwd: string): ShotAsk | ClipAsk {
|
|
|
129
136
|
waitMs: f.wait == null ? DEFAULT_WAIT_MS : f.wait === '0' ? 0 : positive('--wait', f.wait, 60_000),
|
|
130
137
|
}
|
|
131
138
|
const step = f.step == null ? {} : { step: f.step }
|
|
132
|
-
if (seconds == null) return { ...base, ...step, ...(f.step == null ? {} : { at: at ?? 0 }) }
|
|
139
|
+
if (seconds == null) return { ...base, ...step, ...(f.step == null ? {} : { at: at ?? 0 }), ...(f.full === true ? { full: true } : {}) }
|
|
133
140
|
if (!base.out.endsWith('.mp4')) throw new Error(`--out '${f.out}': a clip is an mp4 (H.264)`)
|
|
134
141
|
return { ...base, seconds, fps: f.fps == null ? DEFAULT_FPS : positive('--fps', f.fps, 60), dom: f.dom === true, ...step }
|
|
135
142
|
}
|
|
@@ -165,12 +172,28 @@ export interface Clock {
|
|
|
165
172
|
sleep(ms: number): Promise<void>
|
|
166
173
|
}
|
|
167
174
|
|
|
175
|
+
/** what a probe answers when the page navigated under it (a sign in that redirects, a dev server's reload): the new
|
|
176
|
+
* page loaded, and its wait starts again */
|
|
177
|
+
export const MOVED: unique symbol = Symbol('moved')
|
|
178
|
+
/** a page that navigates more often than this while it loads never holds still */
|
|
179
|
+
export const MAX_MOVES = 50
|
|
180
|
+
|
|
181
|
+
/** the error playwright throws when the page navigated while it ran something in it */
|
|
182
|
+
export const navigatedUnder = (e: unknown): boolean => /Execution context was destroyed|Cannot find context with specified id|frame was detached/i.test((e as Error)?.message ?? '')
|
|
183
|
+
|
|
168
184
|
/** polls the page until it is ready to shoot: 'ready' once its mark says so, 'fallback' once a page with no mark had
|
|
169
185
|
* its wait. A page whose mark never says ready fails loud at the cap */
|
|
170
|
-
export async function waitReady(probe: () => Promise<string | null>, fallbackMs: number, clock: Clock, capMs = READY_CAP_MS): Promise<'ready' | 'fallback'> {
|
|
171
|
-
|
|
186
|
+
export async function waitReady(probe: () => Promise<string | null | typeof MOVED>, fallbackMs: number, clock: Clock, capMs = READY_CAP_MS): Promise<'ready' | 'fallback'> {
|
|
187
|
+
let t0 = clock.now()
|
|
188
|
+
let moves = 0
|
|
172
189
|
for (;;) {
|
|
173
|
-
const
|
|
190
|
+
const got = await probe()
|
|
191
|
+
if (got === MOVED) {
|
|
192
|
+
if (++moves > MAX_MOVES) throw new Error(`the page navigated ${MAX_MOVES} times while it loaded and never held still`)
|
|
193
|
+
t0 = clock.now()
|
|
194
|
+
continue
|
|
195
|
+
}
|
|
196
|
+
const s = readyOf(got)
|
|
174
197
|
if (s === 'ready') return 'ready'
|
|
175
198
|
const spent = clock.now() - t0
|
|
176
199
|
if (s === 'silent' && spent >= fallbackMs) return 'fallback'
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// what the read recorder may trust of a child process that is not bun: a tool that opens no file whatever its folder,
|
|
2
|
+
// and the folder a git child works in. Imported by the recorder preload, so it imports nothing of the repo
|
|
3
|
+
import { isAbsolute, join } from 'node:path'
|
|
4
|
+
|
|
5
|
+
// they read the kernel's tables, never a file: the process list, the sockets, the tool paths
|
|
6
|
+
const NO_FILE = new Set(['ps', 'pgrep', 'uname', 'sw_vers', 'whoami', 'id', 'hostname', 'vm_stat', 'sysctl'])
|
|
7
|
+
|
|
8
|
+
/** the child opens no file of any repo, whatever its folder and environment */
|
|
9
|
+
export function readsNoFile(argv: readonly string[]): boolean {
|
|
10
|
+
const tool = argv[0]?.split('/').pop()
|
|
11
|
+
if (tool == null || tool === '') return false
|
|
12
|
+
if (NO_FILE.has(tool)) return true
|
|
13
|
+
// a socket query only: every word an option, so no path is listed
|
|
14
|
+
if (tool === 'lsof') return argv.slice(1).every((a) => a.startsWith('-'))
|
|
15
|
+
// an archive unpacked from stdin: it writes where -C points and opens no file
|
|
16
|
+
if (tool === 'tar') return argv.includes('-x') && argv[argv.indexOf('-f') + 1] === '-'
|
|
17
|
+
// a lookup of a tool's path, never a run of it
|
|
18
|
+
if (tool === 'xcrun') return argv.length === 3 && (argv[1] === '--find' || argv[1] === '-f')
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** the folder the child works in: git's leading `-C <dir>` options, tar's leading `-C <dir>` when every other path it
|
|
23
|
+
* names is absolute or `.` (a relative archive name would still resolve in the spawn's folder), else the spawn's own */
|
|
24
|
+
export function childCwd(argv: readonly string[], cwd: string): string {
|
|
25
|
+
const tool = argv[0]?.split('/').pop()
|
|
26
|
+
if (tool === 'tar') {
|
|
27
|
+
const dir = argv[1] === '-C' ? argv[2] : undefined
|
|
28
|
+
if (dir == null || !isAbsolute(dir)) return cwd
|
|
29
|
+
const rest = argv.slice(3).filter((a) => !a.startsWith('-'))
|
|
30
|
+
return rest.every((a) => a === '.' || isAbsolute(a)) && !argv.slice(3).includes('-C') ? dir : cwd
|
|
31
|
+
}
|
|
32
|
+
if (tool !== 'git') return cwd
|
|
33
|
+
let at = cwd
|
|
34
|
+
for (let i = 1; i < argv.length; i++) {
|
|
35
|
+
const a = argv[i]!
|
|
36
|
+
if (!a.startsWith('-')) break
|
|
37
|
+
if (a === '-c') i++
|
|
38
|
+
else if (a === '-C') {
|
|
39
|
+
const d = argv[++i]
|
|
40
|
+
if (d == null) return cwd
|
|
41
|
+
at = isAbsolute(d) ? d : join(at, d)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return at
|
|
45
|
+
}
|
|
@@ -169,22 +169,6 @@ export function planPhases(p: { tests: TestsConfig; tier: 'quick' | 'full'; rawA
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
/** how many `--parallel` workers one suite run takes. Every test check runs
|
|
173
|
-
* on one slot of the machine pool (core/slots.ts), so a run sized to every
|
|
174
|
-
* core while four other checks do the same puts five times the cores to
|
|
175
|
-
* work. A run takes its own slot's share of the cores plus the share of
|
|
176
|
-
* every slot free when it starts, never more than the cores, and never
|
|
177
|
-
* fewer than half of them: the count is fixed for the whole run, and a gate
|
|
178
|
-
* starts it while its first burst of short checks holds the pool, so the
|
|
179
|
-
* share alone left the longest suite on two workers long after that burst
|
|
180
|
-
* ended. Measured on 8 cores: two workers 12.2s, four 7.6s, eight 7.0s */
|
|
181
|
-
export function poolWorkers(p: { cores: number; size: number; held: number }): number {
|
|
182
|
-
const size = Math.max(1, p.size)
|
|
183
|
-
const mine = Math.max(1, size - Math.max(1, p.held) + 1)
|
|
184
|
-
const floor = Math.max(2, Math.floor(p.cores / 2))
|
|
185
|
-
return Math.max(floor, Math.min(p.cores, Math.round((p.cores * mine) / size)))
|
|
186
|
-
}
|
|
187
|
-
|
|
188
172
|
type Timed = { file: string; ms: number }
|
|
189
173
|
|
|
190
174
|
export function judgeSuites(p: { timings: Record<string, number>; tests: TestsConfig; tier: 'quick' | 'full'; red?: string[] }): { over: Timed[]; noLongerSlow: Timed[]; slowest: Timed[] } {
|
|
@@ -246,11 +230,12 @@ export const waitAllowance = (budgetMs: number, load: MachineLoad): number => {
|
|
|
246
230
|
export type SuiteWork = { instructions: number; pInstructions: number; cpuMs: number; pCpuMs: number; otherCpuMs: number; childCpuMs: number }
|
|
247
231
|
/** the main thread's own rate needs this much time on a performance core */
|
|
248
232
|
export const OWN_RATE_MIN_MS = 20
|
|
249
|
-
/** a suite's CPU as if its main thread ran on a performance core
|
|
250
|
-
* there, plus what it retired on an efficiency core
|
|
251
|
-
* it ran on a performance core when it ran long enough
|
|
252
|
-
* than `instrPerMs` (calibrate.ts conversionRate, the low
|
|
253
|
-
* suites),
|
|
233
|
+
/** a suite's CPU as if its main thread ran on a performance core of a quiet
|
|
234
|
+
* machine: its time there, plus what it retired on an efficiency core
|
|
235
|
+
* converted at the rate it ran on a performance core when it ran long enough
|
|
236
|
+
* there, never faster than `instrPerMs` (calibrate.ts conversionRate, the low
|
|
237
|
+
* end of real suites), never more than the main thread's own CPU, and never
|
|
238
|
+
* more than all its instructions at `instrPerMs`. The other threads
|
|
254
239
|
* and the children are charged their CPU as it is: a reaped child or an
|
|
255
240
|
* ended thread has no count left to read, so a suite that spawns keeps the
|
|
256
241
|
* CPU of what it spawned, and a lone run whose figure is mostly its
|
|
@@ -261,7 +246,10 @@ export function coreMs(w: SuiteWork, instrPerMs: number | null): number | null {
|
|
|
261
246
|
const own = w.pCpuMs >= OWN_RATE_MIN_MS ? w.pInstructions / w.pCpuMs : null
|
|
262
247
|
const rate = own != null && instrPerMs != null ? Math.min(own, instrPerMs) : own ?? instrPerMs
|
|
263
248
|
if (eInstructions > 0 && (rate == null || rate <= 0)) return null
|
|
264
|
-
const
|
|
249
|
+
const converted = eInstructions === 0 ? w.pCpuMs : Math.min(w.pCpuMs + eInstructions / rate!, w.cpuMs)
|
|
250
|
+
// a loaded machine runs a performance core slower too (frequency, shared caches, memory bandwidth), so the
|
|
251
|
+
// thread is never charged more than its instructions at the machine's rate, measured quiet
|
|
252
|
+
const main = instrPerMs != null && instrPerMs > 0 ? Math.min(converted, w.instructions / instrPerMs) : converted
|
|
265
253
|
return main + w.otherCpuMs + w.childCpuMs
|
|
266
254
|
}
|
|
267
255
|
|
package/src/suite/select.ts
CHANGED
|
@@ -30,10 +30,10 @@ import { gitBin } from '../core/git-bin.ts'
|
|
|
30
30
|
import { blobOid, listingHash } from '../core/read-set.ts'
|
|
31
31
|
import { shipkitRoot } from '../ledger/db.ts'
|
|
32
32
|
import { extractSpecs, resolveSpec } from '../ts/source-graph.ts'
|
|
33
|
-
import { type RvtConfig } from '../ts/config.ts'
|
|
33
|
+
import { type RvtConfig, workspacePackages } from '../ts/config.ts'
|
|
34
34
|
import { BETWEEN_TESTS, BUN_RULE, inDotDir } from './judge-suites.ts'
|
|
35
35
|
|
|
36
|
-
export const SELECT_VERSION =
|
|
36
|
+
export const SELECT_VERSION = 6
|
|
37
37
|
|
|
38
38
|
/** what the recorder charged to one module, repo-relative: r a file read, d a
|
|
39
39
|
* dir listed, g a tree walked, o a spawn nobody records, l a module loaded at
|
|
@@ -98,8 +98,42 @@ const statSig = (abs: string): string | null => {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
type Workspace = { name: string; dir: string; exports?: unknown }
|
|
102
|
+
|
|
103
|
+
/** a workspace package's specifier through its `exports` (`.`, `./ui`, `./src/*`), repo-relative, or null */
|
|
104
|
+
export function exportTarget(spec: string, ws: readonly Workspace[]): string | null {
|
|
105
|
+
const w = ws.find((p) => spec === p.name || spec.startsWith(`${p.name}/`))
|
|
106
|
+
if (w == null || w.exports == null) return null
|
|
107
|
+
const sub = `.${spec.slice(w.name.length)}`
|
|
108
|
+
const map: Record<string, unknown> = typeof w.exports === 'string' || Array.isArray(w.exports) ? { '.': w.exports } : (w.exports as Record<string, unknown>)
|
|
109
|
+
const pick = (v: unknown): string | null => {
|
|
110
|
+
if (typeof v === 'string') return v
|
|
111
|
+
if (Array.isArray(v)) return v.map(pick).find((x) => x != null) ?? null
|
|
112
|
+
if (v != null && typeof v === 'object') for (const k of ['bun', 'import', 'default', 'require', 'types']) if (k in v) return pick((v as Record<string, unknown>)[k])
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
115
|
+
let to = map[sub] !== undefined ? pick(map[sub]) : null
|
|
116
|
+
if (to == null) {
|
|
117
|
+
for (const [k, v] of Object.entries(map)) {
|
|
118
|
+
const star = k.indexOf('*')
|
|
119
|
+
if (star < 0 || !sub.startsWith(k.slice(0, star)) || !sub.endsWith(k.slice(star + 1))) continue
|
|
120
|
+
const t = pick(v)
|
|
121
|
+
if (t != null) to = t.replace('*', sub.slice(star, sub.length - (k.length - star - 1)))
|
|
122
|
+
break
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return to == null ? null : posix.normalize(posix.join(w.dir, to))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** the walk's config: the source roots' packages, plus each workspace package outside them, imported by its name */
|
|
129
|
+
const graphConfig = (cfg: RvtConfig): { cfg: RvtConfig; ws: Workspace[] } => {
|
|
130
|
+
const ws = workspacePackages(cfg.root, cfg.vendored ?? [])
|
|
131
|
+
const extra = ws.filter((w) => !cfg.packages.some((p) => p.dir === w.dir || p.name === w.name))
|
|
132
|
+
return { cfg: { ...cfg, packages: [...cfg.packages, ...extra.map(({ name, dir }) => ({ name, dir }))].sort((a, b) => b.dir.length - a.dir.length) }, ws }
|
|
133
|
+
}
|
|
134
|
+
|
|
101
135
|
/** parse one file, from the manifest when its stat signature held */
|
|
102
|
-
function entryOf(cfg: RvtConfig, file: string, old: GraphEntry | undefined): GraphEntry | null {
|
|
136
|
+
function entryOf(cfg: RvtConfig, ws: readonly Workspace[], file: string, old: GraphEntry | undefined): GraphEntry | null {
|
|
103
137
|
const abs = join(cfg.root, file)
|
|
104
138
|
const sig = statSig(abs)
|
|
105
139
|
if (sig == null) return null
|
|
@@ -121,7 +155,8 @@ function entryOf(cfg: RvtConfig, file: string, old: GraphEntry | undefined): Gra
|
|
|
121
155
|
// runs when called, and the recorder sees it then, with who called
|
|
122
156
|
for (const raw of extractSpecs(text, { dynamic: false })) {
|
|
123
157
|
const spec = raw.replace(/\?.*$/, '')
|
|
124
|
-
const
|
|
158
|
+
const exported = exportTarget(spec, ws)
|
|
159
|
+
const target = exported != null && has(exported) ? exported : resolveSpec(cfg, file, spec, has)
|
|
125
160
|
if (target != null && target !== file) deps.add(target)
|
|
126
161
|
}
|
|
127
162
|
return { sig, deps: [...new Set([...deps, ...link])].sort() }
|
|
@@ -129,13 +164,14 @@ function entryOf(cfg: RvtConfig, file: string, old: GraphEntry | undefined): Gra
|
|
|
129
164
|
|
|
130
165
|
/** every file the entries reach by import, parsed through the manifest. The
|
|
131
166
|
* returned map is the new manifest: only what this walk reached */
|
|
132
|
-
export function walkGraph(
|
|
167
|
+
export function walkGraph(config: RvtConfig, entries: string[], manifest: Record<string, GraphEntry>): Record<string, GraphEntry> {
|
|
168
|
+
const { cfg, ws } = graphConfig(config)
|
|
133
169
|
const out: Record<string, GraphEntry> = {}
|
|
134
170
|
const todo = [...entries]
|
|
135
171
|
while (todo.length > 0) {
|
|
136
172
|
const f = todo.pop()!
|
|
137
173
|
if (out[f] != null) continue
|
|
138
|
-
const e = entryOf(cfg, f, manifest[f])
|
|
174
|
+
const e = entryOf(cfg, ws, f, manifest[f])
|
|
139
175
|
if (e == null) continue
|
|
140
176
|
out[f] = e
|
|
141
177
|
for (const d of e.deps) if (out[d] == null) todo.push(d)
|
|
@@ -188,6 +224,12 @@ const listing = (abs: string, deep: boolean): string | null => {
|
|
|
188
224
|
* one status, no index write), every recorded read git does not see, and a
|
|
189
225
|
* hash of every recorded listing and walked tree */
|
|
190
226
|
export function snapshot(top: string, modules: Record<string, ModuleReads>): Record<string, string> {
|
|
227
|
+
const tree = treeSnapshot(top)
|
|
228
|
+
return { ...tree, ...extras(top, modules, tree) }
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** what git tracks or would add, as blob ids: the part of a snapshot no read names */
|
|
232
|
+
export function treeSnapshot(top: string): Record<string, string> {
|
|
191
233
|
const snap: Record<string, string> = {}
|
|
192
234
|
for (const line of git(top, ['ls-files', '-s', '-z']).split('\0')) {
|
|
193
235
|
const tab = line.indexOf('\t')
|
|
@@ -207,7 +249,27 @@ export function snapshot(top: string, modules: Record<string, ModuleReads>): Rec
|
|
|
207
249
|
delete snap[path]
|
|
208
250
|
}
|
|
209
251
|
}
|
|
210
|
-
return
|
|
252
|
+
return snap
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** every key a read names: the files read, the listings and the walked trees */
|
|
256
|
+
const readKeys = (modules: Record<string, ModuleReads>): Set<string> => {
|
|
257
|
+
const out = new Set<string>()
|
|
258
|
+
for (const m of Object.values(modules)) {
|
|
259
|
+
for (const r of m.r ?? []) out.add(r)
|
|
260
|
+
for (const d of m.d ?? []) out.add(listKey(d))
|
|
261
|
+
for (const g of m.g ?? []) out.add(treeKey(g))
|
|
262
|
+
}
|
|
263
|
+
return out
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** the snapshot the next run diffs against: the one this run started from, less the keys only a read it no longer
|
|
267
|
+
* records named (a full run replaces the reads, and a file git ignores then leaves every snapshot: kept, it would
|
|
268
|
+
* read as removed), plus what `fresh` adds for the reads first recorded by this run */
|
|
269
|
+
export function baseAfter(tree: Record<string, string>, startedFrom: Record<string, string>, modules: Record<string, ModuleReads>, fresh: (have: Record<string, string>) => Record<string, string>): Record<string, string> {
|
|
270
|
+
const read = readKeys(modules)
|
|
271
|
+
const kept = Object.fromEntries(Object.entries(startedFrom).filter(([k]) => tree[k] != null || read.has(k)))
|
|
272
|
+
return { ...kept, ...fresh(kept) }
|
|
211
273
|
}
|
|
212
274
|
|
|
213
275
|
/** the recorded reads git does not see, and every recorded listing and walked
|
|
@@ -314,6 +376,18 @@ export const isRunConfig = (path: string, envFiles: string[]): boolean =>
|
|
|
314
376
|
/** a file bun's test runner runs: `*.test.*`, `*_test.*`, `*.spec.*`, `*_spec.*` in js or ts */
|
|
315
377
|
export const isBunSuite = (path: string): boolean => /[._](test|spec)\.[cm]?[jt]sx?$/.test(path)
|
|
316
378
|
|
|
379
|
+
const TEXT_FORM = /\.(md|mdx|txt|[cm]?[jt]sx?|json|jsonc|ya?ml|toml|csv|html|css|svg)$/
|
|
380
|
+
|
|
381
|
+
/** a changed file only a hooked read can open, so an unclaimed one was read by no
|
|
382
|
+
* suite: a doc outside the preload dirs (a preload's own load goes unrecorded),
|
|
383
|
+
* or a text file in a dot folder, where bun finds no suite and no import goes
|
|
384
|
+
* unrecorded. a native reader (a database, an image library) is never ruled out */
|
|
385
|
+
export const noUnseenReader = (path: string, preloadDirs: string[]): boolean => {
|
|
386
|
+
if (preloadDirs.some((d) => d === '.' || path.startsWith(`${d}/`))) return false
|
|
387
|
+
if (/\.mdx?$/.test(path)) return true
|
|
388
|
+
return inDotDir(path) && TEXT_FORM.test(path)
|
|
389
|
+
}
|
|
390
|
+
|
|
317
391
|
export function selectSuites(o: {
|
|
318
392
|
suites: string[]
|
|
319
393
|
preloads: string[]
|
|
@@ -327,7 +401,18 @@ export function selectSuites(o: {
|
|
|
327
401
|
* import and no recorded read claims runs every suite */
|
|
328
402
|
roots?: string[]
|
|
329
403
|
}): Selection {
|
|
330
|
-
|
|
404
|
+
// bun finds a module's tsconfig and package.json by walking up from it, so a
|
|
405
|
+
// run config configures the run only in a dir holding one of its modules,
|
|
406
|
+
// or above one: another unit's is no read of this run
|
|
407
|
+
const moduleDirs = new Set<string>(['.'])
|
|
408
|
+
for (const m of [...Object.keys(o.graph), ...o.suites, ...o.preloads]) {
|
|
409
|
+
for (let d = posix.dirname(m); !moduleDirs.has(d); d = posix.dirname(d)) {
|
|
410
|
+
moduleDirs.add(d)
|
|
411
|
+
if (d === posix.dirname(d)) break
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const elsewhere = (c: string): boolean => isRunConfig(c, o.envFiles) && !o.envFiles.includes(c) && !moduleDirs.has(posix.dirname(c))
|
|
415
|
+
for (const c of o.changed) if (isRunConfig(c, o.envFiles) && !elsewhere(c)) return { all: true, why: `${c} changed, and it configures every suite` }
|
|
331
416
|
// the recorder sees only what it hooks (a preload's own load, a tool it
|
|
332
417
|
// does not know, an API it does not wrap go unseen), so a change where
|
|
333
418
|
// suites live that nothing claims is unsure, and unsure runs everything
|
|
@@ -343,7 +428,8 @@ export function selectSuites(o: {
|
|
|
343
428
|
const claimed = (c: string): boolean =>
|
|
344
429
|
c.endsWith('/') || c.endsWith('/**') || o.graph[c] != null || readSet.has(c) || lists.has(posix.dirname(c)) || trees.some((t) => c.startsWith(t))
|
|
345
430
|
const under = (c: string): boolean => (o.roots ?? []).some((r) => r === '' || r === '.' || c.startsWith(`${r}/`))
|
|
346
|
-
|
|
431
|
+
const preloadDirs = o.preloads.map((p) => posix.dirname(p))
|
|
432
|
+
for (const c of o.changed) if (!claimed(c) && under(c) && !elsewhere(c) && !noUnseenReader(c, preloadDirs)) return { all: true, why: `${c} changed, and neither an import nor a recorded read claims it` }
|
|
347
433
|
// a changed file moves every module that loads it with itself, and one a
|
|
348
434
|
// preload loads moves every suite: the preload ran it before any suite
|
|
349
435
|
const importersOf = (withRuntime: boolean): Map<string, string[]> => {
|
package/src/suite/suite-cli.ts
CHANGED
|
@@ -9,20 +9,21 @@
|
|
|
9
9
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs'
|
|
10
10
|
import { availableParallelism, tmpdir } from 'os'
|
|
11
11
|
import { machineLoad } from '../core/budget.ts'
|
|
12
|
-
import { join, posix } from 'path'
|
|
12
|
+
import { basename, join, posix } from 'path'
|
|
13
13
|
import { FULL_TESTS_ENV } from '../ledger/gate-checks.ts'
|
|
14
14
|
import { CHECK_ID_ENV, recordSuites, type SuitePhase } from '../ledger/suite-log.ts'
|
|
15
15
|
import { killTree } from '../core/spawn-timeout.ts'
|
|
16
16
|
import { parallelCap } from '../core/parallel.ts'
|
|
17
|
-
import { poolDir,
|
|
17
|
+
import { poolDir, SLOT_CORES_ENV, SLOT_HELD_ENV, slotsLine, takeFreeSlots } from '../core/slots.ts'
|
|
18
|
+
import { keptWorkMs, mostWorkers, workersFor, workersToStart } from './suite-cores.ts'
|
|
18
19
|
import { keepTimings, seedTimings, timingsHome } from './kept-timings.ts'
|
|
19
20
|
import { SUITE_READS_ENV, SUITE_ROOT_ENV, SUITE_SELECT_ENV } from './reads-env.ts'
|
|
20
|
-
import { changedKeys, dropStaticEdges, extras, isBunSuite, envFilesOf, foldReads, loadErrorModules, loadState, preloadsOf, saveState, selectStatePath, selectSuites,
|
|
21
|
+
import { baseAfter, changedKeys, dropStaticEdges, extras, isBunSuite, envFilesOf, foldReads, loadErrorModules, loadState, preloadsOf, saveState, selectStatePath, selectSuites, suiteFiles, taintedSuites, treeSnapshot, walkGraph, type GraphEntry, type Selection, type SelectState } from './select.ts'
|
|
21
22
|
import { gitRoot } from '../core/git-root.ts'
|
|
22
23
|
import { runReaches, type TestRun } from './test-units.ts'
|
|
23
24
|
import { loadConfig } from '../ts/config.ts'
|
|
24
25
|
import { conversionRate, machineRate } from './calibrate.ts'
|
|
25
|
-
import { aloneRunsNeeded, bunfigTest, coreMs, cpuAllowance, loadShare, type SuiteWork, type BunfigTest, readPhaseCpu, SUITE_CPU_ENV, type AloneRun, type Confirmed, confirmOver, crashedWorkers, interruptedSuites, overWords, ranAs, retryAlone, smallerRun, stallWords, DEFAULT_BUDGET_MS, FULL_CEILING_MS, failedSuites, failLines, judgeSuites, normSuitePath, parseSuiteFlags, planPhases, QUICK_CEILING_MS,
|
|
26
|
+
import { aloneRunsNeeded, bunfigTest, coreMs, cpuAllowance, loadShare, type SuiteWork, type BunfigTest, readPhaseCpu, SUITE_CPU_ENV, type AloneRun, type Confirmed, confirmOver, crashedWorkers, interruptedSuites, overWords, ranAs, retryAlone, smallerRun, stallWords, DEFAULT_BUDGET_MS, FULL_CEILING_MS, failedSuites, failLines, judgeSuites, normSuitePath, parseSuiteFlags, planPhases, QUICK_CEILING_MS, redWords } from './judge-suites.ts'
|
|
26
27
|
|
|
27
28
|
type Phase = { code: number; signal: string | null; stalled: boolean; out: string; timings: Record<string, number>; cpuMs: number | null }
|
|
28
29
|
|
|
@@ -90,6 +91,21 @@ const lastCount = (out: string, re: RegExp): number => Number([...out.matchAll(r
|
|
|
90
91
|
/** what the selection carries from before the run to after it */
|
|
91
92
|
type SelectCtx = { sel: Selecting | null; /** the suites that ran and passed, time included */ ran: string[]; tier: 'quick' | 'full'; /** every suite ran to its end, red or green: no phase stalled or was killed */ complete: boolean; /** what every phase printed */ out: string }
|
|
92
93
|
|
|
94
|
+
/** the workers the parallel phase starts and the slots behind them. Inside a check the runner already holds them
|
|
95
|
+
* (SHIPKIT_SLOT_CORES). A run someone started by hand takes the free ones itself and never waits */
|
|
96
|
+
function coresFor(p: { need: number; who: { repo: string; check: string } }): { workers: number; release: () => void } {
|
|
97
|
+
if (process.env[SLOT_HELD_ENV] === '1') {
|
|
98
|
+
const granted = Number(process.env[SLOT_CORES_ENV])
|
|
99
|
+
const slots = Number.isInteger(granted) && granted >= 1 ? granted : 1
|
|
100
|
+
// the runner sized the slots on the whole unit; this run says what the suites it starts use, and gives
|
|
101
|
+
// the rest back once the phase ended (the serial phase and a lone rerun run one suite at a time)
|
|
102
|
+
if (slots > 1) console.log(slotsLine(Math.min(slots, p.need)))
|
|
103
|
+
return { workers: workersToStart(p.need, slots), release: () => { if (slots > 1) console.log(slotsLine(1)) } }
|
|
104
|
+
}
|
|
105
|
+
const own = takeFreeSlots({ dir: poolDir(), size: parallelCap(), load: machineLoad }, p.who, p.need)
|
|
106
|
+
return { workers: workersToStart(p.need, own.count), release: own.release }
|
|
107
|
+
}
|
|
108
|
+
|
|
93
109
|
export async function suiteCli(argv: string[]): Promise<number> {
|
|
94
110
|
const ctx: SelectCtx = { sel: null, ran: [], tier: 'quick', complete: false, out: '' }
|
|
95
111
|
try {
|
|
@@ -131,12 +147,10 @@ async function runSuites(argv: string[], ctx: SelectCtx): Promise<number> {
|
|
|
131
147
|
// bun drops these the moment any ignore reaches its command line
|
|
132
148
|
const bunfig = bunfigTest(existsSync('bunfig.toml') ? readFileSync('bunfig.toml', 'utf8') : null)
|
|
133
149
|
if (bunfig.error != null) { console.log(`FAIL: ${bunfig.error}`); return 1 }
|
|
134
|
-
// the
|
|
150
|
+
// the plan names the most a run asks for; the count it starts is set once the suites to run are known (coresFor)
|
|
135
151
|
const cores = availableParallelism()
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
const plan = planPhases({ tests, tier, rawArgs, parallel, noIsolate: helpText.includes('--no-isolate'), configIgnores: bunfig.ignores, workers: pool })
|
|
139
|
-
const { workers } = plan
|
|
152
|
+
const plan = planPhases({ tests, tier, rawArgs, parallel, noIsolate: helpText.includes('--no-isolate'), configIgnores: bunfig.ignores, workers: parallel ? mostWorkers(cores) : undefined })
|
|
153
|
+
let workers = plan.workers
|
|
140
154
|
const dir = mkdtempSync(join(tmpdir(), 'shipkit-suite-'))
|
|
141
155
|
const tmp = join(dir, 'temp')
|
|
142
156
|
mkdirSync(tmp)
|
|
@@ -189,8 +203,15 @@ async function runSuites(argv: string[], ctx: SelectCtx): Promise<number> {
|
|
|
189
203
|
return files.length === 0 ? null : [...plan.alone, ...files]
|
|
190
204
|
})()
|
|
191
205
|
const parallelEmpty = pickedSet != null && parallelArgs.length === plan.parallel.length
|
|
206
|
+
// the workers follow the suites this phase starts, and the slots held for them
|
|
207
|
+
const held = plan.workers == null || parallelEmpty ? null : coresFor({
|
|
208
|
+
need: Math.min(plan.workers, workersFor(kept == null ? null : keptWorkMs(join(dir, 'parallel.json'), pickedSet == null ? undefined : new Set([...pickedSet].filter((f) => !serialSet.has(f)))), cores)),
|
|
209
|
+
who: { repo: basename(process.cwd()), check: process.env[CHECK_ID_ENV] ?? (unit === '' ? 'test' : `test:${unit}`) },
|
|
210
|
+
})
|
|
211
|
+
if (held != null) workers = held.workers
|
|
212
|
+
const phaseArgs = held == null ? parallelArgs : parallelArgs.map((a) => (/^--parallel(=\d+)?$/.test(a) ? `--parallel=${held.workers}` : a))
|
|
192
213
|
const p1At = Date.now()
|
|
193
|
-
const p1 = parallelEmpty ? { ...NO_PHASE } : await runPhase(
|
|
214
|
+
const p1 = parallelEmpty ? { ...NO_PHASE } : await runPhase(phaseArgs, timed ? join(dir, 'parallel.json') : null, ceilingMs, tmp, true, cpuFile, rec).finally(() => held?.release())
|
|
194
215
|
const p1Ms = Date.now() - p1At
|
|
195
216
|
// bun merges what it read into what it writes, so a suite deleted since
|
|
196
217
|
// the last run is judged and kept only if the workers say it ran here
|
|
@@ -335,7 +356,7 @@ async function runSuites(argv: string[], ctx: SelectCtx): Promise<number> {
|
|
|
335
356
|
if (fails.length > 0) { console.log(fails[0]); return 1 }
|
|
336
357
|
const serialCount = serialArgs != null ? phaseFiles(serialArgs, rawArgs).length : 0
|
|
337
358
|
const chosen = ctx.sel?.picked != null ? `, the ${ctx.sel.picked.length} of ${ctx.sel.total} a change reaches` : ''
|
|
338
|
-
console.log(`ok: Ran ${ran} tests across ${Object.keys(timings).length || '?'} suites${chosen}, ${parallel ? `parallel on ${workers} workers` : 'one at a time'}${serialCount > 0 ? ` then ${serialCount} serial` : ''}, ${tier} tier, ${ranAs(
|
|
359
|
+
console.log(`ok: Ran ${ran} tests across ${Object.keys(timings).length || '?'} suites${chosen}, ${parallel ? `parallel on ${workers} workers` : 'one at a time'}${serialCount > 0 ? ` then ${serialCount} serial` : ''}, ${tier} tier, ${ranAs(phaseArgs, rawArgs)}${slowest}`)
|
|
339
360
|
return 0
|
|
340
361
|
} finally {
|
|
341
362
|
rmSync(dir, { recursive: true, force: true })
|
|
@@ -349,6 +370,8 @@ type Selecting = {
|
|
|
349
370
|
rec: Recording
|
|
350
371
|
statePath: string
|
|
351
372
|
state: SelectState
|
|
373
|
+
/** what git saw when the run started, the part of `now` no read names */
|
|
374
|
+
tree: Record<string, string>
|
|
352
375
|
now: Record<string, string>
|
|
353
376
|
graph: Record<string, GraphEntry>
|
|
354
377
|
preloads: string[]
|
|
@@ -408,9 +431,10 @@ function prepareSelection(o: { tests: TestsConfigLike; tier: 'quick' | 'full'; r
|
|
|
408
431
|
const loads = Object.values(state.modules).flatMap((m) => m.l ?? [])
|
|
409
432
|
const graph = walkGraph(cfg, [...suites.map(toTop), ...preloads, ...loads], state.graph)
|
|
410
433
|
const started = Date.now()
|
|
411
|
-
const
|
|
434
|
+
const tree = treeSnapshot(top)
|
|
435
|
+
const now = { ...tree, ...extras(top, state.modules, tree) }
|
|
412
436
|
const rec: Recording = { file: join(tmpdir(), `shipkit-reads-${process.pid}-${Date.now()}.tsv`), top }
|
|
413
|
-
const base = { rec, statePath, state, now, started, graph, preloads, cwdRel, allSuites: suites.map(toTop), total: suites.length, notes, changed: 0 }
|
|
437
|
+
const base = { rec, statePath, state, tree, now, started, graph, preloads, cwdRel, allSuites: suites.map(toTop), total: suites.length, notes, changed: 0 }
|
|
414
438
|
if (o.tier !== 'quick') return { ...base, picked: null }
|
|
415
439
|
const pos = positional(o.rawArgs)
|
|
416
440
|
if (pos != null) { notes.push(`note: every suite runs: the test script names ${pos}, which a selection would override`); return { ...base, picked: null } }
|
|
@@ -455,7 +479,7 @@ function finishSelection(sel: Selecting, passed: string[], replace: boolean, out
|
|
|
455
479
|
const dirty = [...new Set([...before, ...picked.filter((s) => !ok.has(s) || tainted.has(s))])].sort()
|
|
456
480
|
// a read first recorded by this run joins the snapshot it started from,
|
|
457
481
|
// unless its path moved since the start
|
|
458
|
-
const base =
|
|
482
|
+
const base = baseAfter(sel.tree, sel.now, modules, (have) => extras(sel.rec.top, modules, have, sel.started))
|
|
459
483
|
saveState(sel.statePath, { ...sel.state, base, dirty, modules, recorded, graph: sel.graph, bun: Bun.version })
|
|
460
484
|
return null
|
|
461
485
|
} catch (e) {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// HOW MANY WORKERS A SUITE RUN STARTS, and how many slots of the machine pool
|
|
2
|
+
// it asks for (core/slots.ts: a slot is one core's worth of work). The count
|
|
3
|
+
// follows the work: the kept durations of the suites the run will start. A
|
|
4
|
+
// worker pays its own start and its own load of the import closure, so a
|
|
5
|
+
// short run on many workers burns more CPU for the same wall.
|
|
6
|
+
//
|
|
7
|
+
// The one constraint a reader breaks first: a run starts the workers it holds
|
|
8
|
+
// slots for, and at least two when its work asks for two. bun fixes the count
|
|
9
|
+
// for the whole run, and a long suite left on one worker sets the gate's time
|
|
10
|
+
// alone (a phase bound by process spawns took 20 to 46s on two workers, 7.6s
|
|
11
|
+
// on four).
|
|
12
|
+
import { readFileSync } from 'fs'
|
|
13
|
+
import { availableParallelism } from 'os'
|
|
14
|
+
import { normSuitePath } from './judge-suites.ts'
|
|
15
|
+
import { timingsHome } from './kept-timings.ts'
|
|
16
|
+
|
|
17
|
+
/** the suite time one worker is worth starting for */
|
|
18
|
+
export const WORKER_WORK_MS = 4000
|
|
19
|
+
|
|
20
|
+
/** the most workers one run asks for: half the cores. Measured on 8 cores: two workers 12.2s, four 7.6s, eight 7.0s */
|
|
21
|
+
export const mostWorkers = (cores: number): number => Math.max(1, Math.floor(cores / 2))
|
|
22
|
+
|
|
23
|
+
/** the workers this much suite time asks for. null: nothing kept yet, so the most */
|
|
24
|
+
export function workersFor(workMs: number | null, cores: number): number {
|
|
25
|
+
const most = mostWorkers(cores)
|
|
26
|
+
return workMs == null ? most : Math.max(1, Math.min(most, Math.ceil(workMs / WORKER_WORK_MS)))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** the workers a run starts: what it holds slots for, never more than its work asks, and two when it asks for two */
|
|
30
|
+
export const workersToStart = (need: number, slots: number): number => Math.max(Math.min(need, Math.max(1, slots)), Math.min(2, need))
|
|
31
|
+
|
|
32
|
+
/** the kept durations summed, over every suite or over `only`. null when nothing readable is kept. A suite of
|
|
33
|
+
* `only` with no kept duration counts as one worker's worth: it is new, and nobody knows what it costs */
|
|
34
|
+
export function keptWorkMs(file: string, only?: ReadonlySet<string>): number | null {
|
|
35
|
+
let files: Record<string, unknown>
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(readFileSync(file, 'utf8')) as { files?: unknown }
|
|
38
|
+
if (parsed?.files == null || typeof parsed.files !== 'object' || Array.isArray(parsed.files)) return null
|
|
39
|
+
files = parsed.files as Record<string, unknown>
|
|
40
|
+
} catch {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
const ms = new Map<string, number>()
|
|
44
|
+
for (const [f, v] of Object.entries(files)) {
|
|
45
|
+
const n = typeof v === 'number' ? v : Number((v as { ms?: unknown } | null)?.ms)
|
|
46
|
+
if (Number.isFinite(n)) ms.set(normSuitePath(f), n)
|
|
47
|
+
}
|
|
48
|
+
if (only == null) return ms.size === 0 ? null : [...ms.values()].reduce((a, b) => a + b, 0)
|
|
49
|
+
let sum = 0
|
|
50
|
+
for (const f of only) sum += ms.get(normSuitePath(f)) ?? WORKER_WORK_MS
|
|
51
|
+
return sum
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** the unit a suite runner command runs (`''` for the root), null when the command is not the suite runner */
|
|
55
|
+
export function suiteUnitOf(cmd: readonly string[] | undefined): string | null {
|
|
56
|
+
if (cmd == null) return null
|
|
57
|
+
const at = cmd.findIndex((a) => /(?:^|\/)suite-cli\.ts$/.test(a))
|
|
58
|
+
if (at < 0) return null
|
|
59
|
+
for (let i = at + 1; i < cmd.length && cmd[i] !== '--'; i++) if (cmd[i] === '--unit') return cmd[i + 1] ?? ''
|
|
60
|
+
return ''
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** the slots a check asks the pool for: the workers its whole unit asks for when it runs the suite runner, else one */
|
|
64
|
+
export function slotsWanted(cmd: readonly string[] | undefined, cwd: string, cores: number = availableParallelism()): number {
|
|
65
|
+
const unit = suiteUnitOf(cmd)
|
|
66
|
+
if (unit == null) return 1
|
|
67
|
+
try { return workersFor(keptWorkMs(timingsHome(cwd, unit)), cores) } catch { return mostWorkers(cores) }
|
|
68
|
+
}
|
|
@@ -29,6 +29,7 @@ import * as cpLive from 'node:child_process'
|
|
|
29
29
|
import { appendFileSync, realpathSync } from 'node:fs'
|
|
30
30
|
import { isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
31
31
|
import { fileURLToPath } from 'node:url'
|
|
32
|
+
import { childCwd, readsNoFile } from './child-tools.ts'
|
|
32
33
|
import { SUITE_OWNER_ENV, SUITE_READS_ENV, SUITE_ROOT_ENV } from './reads-env.ts'
|
|
33
34
|
|
|
34
35
|
const out = process.env[SUITE_READS_ENV]
|
|
@@ -174,7 +175,7 @@ function install(outFile: string, rootDir: string): void {
|
|
|
174
175
|
}
|
|
175
176
|
const SHELLS = new Set(['sh', 'bash', 'zsh', 'dash', 'fish', 'env', 'xargs', 'nice', 'time', 'timeout'])
|
|
176
177
|
// tools that read only the files their arguments name, nothing they find through them
|
|
177
|
-
const FILE_TOOLS = new Set(['true', 'false', 'echo', 'sleep', 'kill', 'rm', 'mkdir', 'touch', 'cwebp', 'dwebp'])
|
|
178
|
+
const FILE_TOOLS = new Set(['true', 'false', 'echo', 'sleep', 'kill', 'rm', 'mkdir', 'touch', 'chmod', 'mkfifo', 'cp', 'cwebp', 'dwebp'])
|
|
178
179
|
const isBun = (bin: unknown): boolean => typeof bin === 'string' && (bin === 'bun' || bin === process.execPath || /(^|\/)bun$/.test(bin))
|
|
179
180
|
const childEnv = (env: unknown): Record<string, string | undefined> => {
|
|
180
181
|
const base = (typeof env === 'object' && env != null ? env : process.env) as Record<string, string | undefined>
|
|
@@ -188,14 +189,15 @@ function install(outFile: string, rootDir: string): void {
|
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
191
|
// a child that is not bun reads what nobody records. It is trusted only
|
|
191
|
-
// when it
|
|
192
|
-
// repo
|
|
193
|
-
//
|
|
192
|
+
// when it opens no file at all (ps, lsof of a port), when it runs outside
|
|
193
|
+
// the repo and names nothing in it (git in a temp repo, or `git -C` one);
|
|
194
|
+
// a tool known to read only the files it names (cwebp) records them; any
|
|
195
|
+
// other child in or about the repo makes its module opaque
|
|
194
196
|
const spawned = (cmd: unknown, cwdOpt: unknown): void => {
|
|
195
197
|
const argv = (Array.isArray(cmd) ? cmd : typeof cmd === 'string' ? [cmd] : []).map(String)
|
|
196
|
-
if (isBun(argv[0])) return
|
|
198
|
+
if (isBun(argv[0]) || readsNoFile(argv)) return
|
|
197
199
|
const tool = (argv[0] ?? '?').split('/').pop() ?? '?'
|
|
198
|
-
const cwd = typeof cwdOpt === 'string' ? resolve(cwdOpt) : cwdOpt instanceof URL ? fileURLToPath(cwdOpt) : process.cwd()
|
|
200
|
+
const cwd = childCwd(argv, typeof cwdOpt === 'string' ? resolve(cwdOpt) : cwdOpt instanceof URL ? fileURLToPath(cwdOpt) : process.cwd())
|
|
199
201
|
const shell = SHELLS.has(tool)
|
|
200
202
|
const words = argv.slice(1).flatMap((a) => (shell ? a.split(/[\s;&|<>()'"`=]+/) : [a.replace(/^--?[\w-]+=/, '')])).filter((w) => w !== '' && !w.startsWith('-'))
|
|
201
203
|
const inRepo: string[] = []
|