@buffcore/cli 0.8.46 → 0.8.47
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 +56 -0
- package/dist/commands/change-merge-remove.d.ts +9 -2
- package/dist/commands/change-merge-remove.js +27 -15
- package/dist/commands/design/check.d.ts +1 -1
- package/dist/commands/design/check.js +2 -1
- package/dist/commands/design/contract-size.d.ts +7 -0
- package/dist/commands/design/contract-size.js +47 -0
- package/dist/commands/design/tells.en.d.ts +2 -0
- package/dist/commands/design/tells.en.js +2 -0
- package/dist/commands/design/tells.es.js +2 -0
- package/dist/commands/extension/places-approval.d.ts +4 -0
- package/dist/commands/process-paths.d.ts +14 -0
- package/dist/commands/process-paths.js +90 -0
- package/dist/commands/prototype/ai-approval.d.ts +27 -0
- package/dist/commands/prototype/ai-approval.js +60 -0
- package/dist/commands/prototype/approver.d.ts +71 -0
- package/dist/commands/prototype/approver.js +168 -0
- package/dist/commands/prototype/critique-gate.d.ts +14 -0
- package/dist/commands/prototype/critique-gate.js +48 -0
- package/dist/commands/prototype/fence.d.ts +1 -0
- package/dist/commands/prototype/fence.js +12 -0
- package/dist/commands/prototype/final-approval-grant.js +18 -0
- package/dist/commands/prototype/final-approval.js +4 -1
- package/dist/commands/prototype/index.js +3 -0
- package/dist/commands/prototype/layout-hints.d.ts +34 -0
- package/dist/commands/prototype/layout-hints.js +194 -0
- package/dist/commands/prototype/layout-measure.d.ts +39 -0
- package/dist/commands/prototype/layout-measure.js +97 -0
- package/dist/commands/prototype/layout-words.d.ts +2 -0
- package/dist/commands/prototype/layout-words.js +11 -0
- package/dist/commands/prototype/layout.en.d.ts +6 -0
- package/dist/commands/prototype/layout.en.js +7 -0
- package/dist/commands/prototype/load-location.js +2 -3
- package/dist/commands/prototype/messages.en.d.ts +14 -0
- package/dist/commands/prototype/messages.en.js +15 -1
- package/dist/commands/prototype/messages.js +15 -1
- package/dist/commands/prototype/milestone-versions.d.ts +4 -0
- package/dist/commands/prototype/prune-command.d.ts +5 -0
- package/dist/commands/prototype/prune-command.js +25 -0
- package/dist/commands/prototype/prune-words.d.ts +1 -0
- package/dist/commands/prototype/prune-words.js +7 -0
- package/dist/commands/prototype/prune.d.ts +16 -0
- package/dist/commands/prototype/prune.en.d.ts +9 -0
- package/dist/commands/prototype/prune.en.js +9 -0
- package/dist/commands/prototype/prune.es.d.ts +2 -0
- package/dist/commands/prototype/prune.es.js +9 -0
- package/dist/commands/prototype/prune.js +140 -0
- package/dist/commands/prototype/reopen-messages.d.ts +9 -0
- package/dist/commands/prototype/reopen-messages.js +19 -0
- package/dist/commands/prototype/report.d.ts +14 -0
- package/dist/commands/prototype/report.js +5 -1
- package/dist/commands/prototype/scene-layout.d.ts +17 -0
- package/dist/commands/prototype/scene-layout.js +57 -0
- package/dist/commands/prototype/scene-ready.js +8 -2
- package/dist/commands/prototype/scene.d.ts +15 -2
- package/dist/commands/prototype/scene.js +54 -42
- package/dist/commands/prototype/selector-answer.d.ts +43 -0
- package/dist/commands/prototype/selector-answer.js +73 -0
- package/dist/commands/prototype/selector-misses.d.ts +19 -0
- package/dist/commands/prototype/selector-misses.js +78 -0
- package/dist/commands/prototype/selector-prompt.d.ts +23 -0
- package/dist/commands/prototype/selector-prompt.js +32 -0
- package/dist/commands/prototype/selector-run.d.ts +13 -0
- package/dist/commands/prototype/selector-run.js +113 -0
- package/dist/commands/prototype/selector.d.ts +54 -0
- package/dist/commands/prototype/selector.js +96 -0
- package/dist/commands/prototype/snapshot-ancestor.js +2 -0
- package/dist/commands/prototype/snapshot-bundle.d.ts +17 -3
- package/dist/commands/prototype/snapshot-bundle.js +69 -7
- package/dist/commands/prototype/snapshot-check-files.d.ts +2 -0
- package/dist/commands/prototype/snapshot-check-files.js +41 -0
- package/dist/commands/prototype/snapshot-command.d.ts +2 -0
- package/dist/commands/prototype/snapshot-command.js +3 -0
- package/dist/commands/prototype/snapshot-completion.d.ts +4 -0
- package/dist/commands/prototype/snapshot-completion.js +30 -2
- package/dist/commands/prototype/snapshot-dependencies.d.ts +23 -2
- package/dist/commands/prototype/snapshot-dependencies.js +120 -14
- package/dist/commands/prototype/snapshot-hashes.d.ts +7 -0
- package/dist/commands/prototype/snapshot-hashes.js +28 -0
- package/dist/commands/prototype/snapshot-inputs.d.ts +15 -6
- package/dist/commands/prototype/snapshot-inputs.js +140 -197
- package/dist/commands/prototype/snapshot-matrix.d.ts +58 -0
- package/dist/commands/prototype/snapshot-matrix.js +95 -0
- package/dist/commands/prototype/snapshot-metro-inputs.d.ts +8 -0
- package/dist/commands/prototype/snapshot-metro-inputs.js +81 -0
- package/dist/commands/prototype/snapshot-owners.d.ts +6 -2
- package/dist/commands/prototype/snapshot-owners.js +12 -3
- package/dist/commands/prototype/snapshot-progress-entry.d.ts +14 -0
- package/dist/commands/prototype/snapshot-progress-entry.js +85 -0
- package/dist/commands/prototype/snapshot-progress.d.ts +19 -2
- package/dist/commands/prototype/snapshot-progress.js +54 -102
- package/dist/commands/prototype/snapshot-registry.d.ts +14 -0
- package/dist/commands/prototype/snapshot-registry.js +121 -0
- package/dist/commands/prototype/snapshot-report.d.ts +4 -0
- package/dist/commands/prototype/snapshot-report.js +77 -12
- package/dist/commands/prototype/snapshot-requests.d.ts +13 -3
- package/dist/commands/prototype/snapshot-requests.js +68 -30
- package/dist/commands/prototype/snapshot-reuse.d.ts +6 -1
- package/dist/commands/prototype/snapshot-reuse.js +17 -7
- package/dist/commands/prototype/snapshot-scene-inputs.d.ts +30 -0
- package/dist/commands/prototype/snapshot-scene-inputs.js +210 -0
- package/dist/commands/prototype/snapshot-served-inputs.d.ts +3 -0
- package/dist/commands/prototype/snapshot-served-inputs.js +12 -0
- package/dist/commands/prototype/snapshot-server-record.d.ts +26 -0
- package/dist/commands/prototype/snapshot-server-record.js +135 -0
- package/dist/commands/prototype/snapshot-servers.d.ts +3 -1
- package/dist/commands/prototype/snapshot-servers.js +50 -2
- package/dist/commands/prototype/snapshot-setup.d.ts +3 -1
- package/dist/commands/prototype/snapshot-setup.js +2 -1
- package/dist/commands/prototype/snapshot-surface-inputs.d.ts +23 -0
- package/dist/commands/prototype/snapshot-surface-inputs.js +161 -0
- package/dist/commands/prototype/snapshot-vite-inputs.d.ts +22 -0
- package/dist/commands/prototype/snapshot-vite-inputs.js +209 -0
- package/dist/commands/prototype/snapshot.d.ts +5 -0
- package/dist/commands/prototype/snapshot.js +72 -10
- package/dist/commands/prototype/version-commands.d.ts +4 -0
- package/dist/commands/prototype/version-commands.js +36 -8
- package/dist/commands/prototype/versions.d.ts +28 -2
- package/dist/commands/prototype/versions.js +25 -1
- package/dist/commands/prototype/vite-fs-path.d.ts +4 -0
- package/dist/commands/prototype/vite-fs-path.js +15 -0
- package/dist/commands/remove-links.d.ts +6 -0
- package/dist/commands/remove-links.js +17 -0
- package/dist/commands/size-docs.d.ts +9 -0
- package/dist/commands/size-docs.en.d.ts +6 -0
- package/dist/commands/size-docs.en.js +6 -0
- package/dist/commands/size-docs.es.d.ts +2 -0
- package/dist/commands/size-docs.es.js +6 -0
- package/dist/commands/size-docs.js +28 -0
- package/dist/commands/size.d.ts +5 -2
- package/dist/commands/size.js +27 -9
- package/dist/commands/ui/approval-authority.d.ts +10 -2
- package/dist/commands/ui/approval-authority.js +1 -0
- package/dist/commands/ui/autopilot-ai-approve.d.ts +18 -0
- package/dist/commands/ui/autopilot-ai-approve.js +68 -0
- package/dist/commands/ui/autopilot-loop.js +5 -6
- package/dist/commands/ui/autopilot-merge.js +3 -0
- package/dist/commands/ui/autopilot.en.d.ts +23 -0
- package/dist/commands/ui/autopilot.en.js +23 -0
- package/dist/commands/ui/autopilot.es.d.ts +23 -0
- package/dist/commands/ui/autopilot.es.js +23 -0
- package/dist/commands/ui/chat/find.d.ts +2 -0
- package/dist/commands/ui/chat/find.js +13 -0
- package/dist/commands/ui/chat/fresh-codex.d.ts +39 -0
- package/dist/commands/ui/chat/fresh-codex.js +175 -0
- package/dist/commands/ui/chat/fresh-critique.js +13 -5
- package/dist/commands/ui/chat/fresh-launch.d.ts +19 -0
- package/dist/commands/ui/chat/fresh-launch.js +67 -11
- package/dist/commands/ui/chat/fresh-prompts.d.ts +2 -0
- package/dist/commands/ui/chat/fresh-prompts.js +2 -0
- package/dist/commands/ui/chat/fresh-secrets.d.ts +6 -0
- package/dist/commands/ui/chat/fresh-secrets.js +172 -0
- package/dist/commands/ui/chat/fresh.en.d.ts +1 -0
- package/dist/commands/ui/chat/fresh.en.js +2 -1
- package/dist/commands/ui/chat/fresh.es.d.ts +1 -0
- package/dist/commands/ui/chat/fresh.es.js +2 -1
- package/dist/commands/ui/chat/worktree.js +25 -5
- package/dist/commands/ui/index.js +3 -0
- package/dist/commands/ui/loop-approve.d.ts +30 -1
- package/dist/commands/ui/loop-approve.js +2 -2
- package/dist/commands/ui/merge-route.js +3 -0
- package/dist/commands/ui/places-change.d.ts +4 -0
- package/dist/commands/ui/prototype-main.d.ts +4 -0
- package/dist/commands/ui/reopen-route.d.ts +117 -0
- package/dist/commands/ui/reopen-route.js +97 -0
- package/dist/commands/ui/save-route.d.ts +2 -0
- package/dist/commands/ui/save-route.js +4 -0
- package/dist/commands/ui/studio-routes.js +2 -0
- package/dist/commands/ui/studio-state.d.ts +33 -0
- package/dist/commands/ui/studio-versions.d.ts +24 -0
- package/dist/commands/ui/worktrees.d.ts +1 -1
- package/dist/commands/ui/worktrees.js +19 -3
- package/dist/commands/worktree-sweep.d.ts +45 -0
- package/dist/commands/worktree-sweep.js +188 -0
- package/dist/commands/worktrees-command.d.ts +32 -0
- package/dist/commands/worktrees-command.en.d.ts +25 -0
- package/dist/commands/worktrees-command.en.js +55 -0
- package/dist/commands/worktrees-command.js +96 -0
- package/dist/main.js +2 -0
- package/dist/ui/page.js +82 -82
- package/docs/PROTOTYPE.md +6 -3
- package/docs/WORKBENCH.md +11 -6
- package/package.json +11 -11
- package/skills/ape-critique/SKILL.md +41 -6
- package/skills/ape-design-system/SKILL.md +3 -0
- package/skills/ape-plan-change/SKILL.md +6 -0
- package/skills/ape-prototype/SKILL.md +8 -4
|
@@ -3,16 +3,34 @@ const origin = (url) => {
|
|
|
3
3
|
? 'localhost'
|
|
4
4
|
: url.hostname;
|
|
5
5
|
const secure = ['https:', 'wss:'].includes(url.protocol);
|
|
6
|
-
return [host, url.port || (secure ? '443' : '80')].join(':');
|
|
6
|
+
return [host, url.port || (secure ? '443' : '80'), secure].join(':');
|
|
7
7
|
};
|
|
8
8
|
const apiPath = (url) => /^\/api(?:\/|$)/i.test(url.pathname);
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/** Every load's coverage check, by the facts it adds to: a scene's facts are a union over its loads. */
|
|
10
|
+
const loads = new WeakMap();
|
|
11
|
+
/** Wait for the coverage of every load that added to these facts, failed loads included. */
|
|
12
|
+
export async function settleRequests(facts) {
|
|
13
|
+
for (const finish of loads.get(facts) ?? [])
|
|
14
|
+
await finish();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Context requests include iframes, workers and requests that fail before receiving a response.
|
|
18
|
+
* `look()` starts a look: more than one navigation of the page within a look is not tracked.
|
|
19
|
+
*/
|
|
20
|
+
export function sceneRequests(page, { urls, coversRequest, requests: found = { apiCalls: false, untrackedRequests: false }, }, scene) {
|
|
11
21
|
const api = urls.api ? origin(new URL(urls.api)) : undefined;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
const surface = origin(new URL(urls[scene.surface]));
|
|
23
|
+
const pending = new Map();
|
|
24
|
+
const validated = new Map();
|
|
25
|
+
const sockets = [];
|
|
26
|
+
const known = async (url, kind, response) => {
|
|
27
|
+
try {
|
|
28
|
+
return (await coversRequest?.(scene, url, kind, response)) === true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
16
34
|
const request = (sent) => {
|
|
17
35
|
const url = new URL(sent.url());
|
|
18
36
|
const host = origin(url);
|
|
@@ -20,43 +38,63 @@ export function sceneRequests(page, { urls, hasAsset, requests: found = { apiCal
|
|
|
20
38
|
if (host === api || apiPath(url))
|
|
21
39
|
found.apiCalls = true;
|
|
22
40
|
// The console reads its own static startup settings. Its public copy is a shared input.
|
|
23
|
-
const settings =
|
|
41
|
+
const settings = host === surface &&
|
|
42
|
+
url.pathname === '/console.json' &&
|
|
43
|
+
!url.search &&
|
|
44
|
+
sent.method() === 'GET';
|
|
24
45
|
if (['fetch', 'xhr', 'eventsource', 'ping'].includes(resource) && !settings)
|
|
25
46
|
found.apiCalls = true;
|
|
26
|
-
if (host
|
|
47
|
+
if (host === api)
|
|
48
|
+
return;
|
|
49
|
+
if (host !== surface ||
|
|
50
|
+
sent.method() !== 'GET' ||
|
|
51
|
+
!['http:', 'https:'].includes(url.protocol)) {
|
|
27
52
|
found.untrackedRequests = true;
|
|
28
|
-
if (host !== api &&
|
|
29
|
-
hasAsset &&
|
|
30
|
-
['http:', 'https:'].includes(url.protocol) &&
|
|
31
|
-
(['image', 'font', 'media', 'stylesheet'].includes(resource) ||
|
|
32
|
-
(resource === 'script' &&
|
|
33
|
-
(/\.css$/i.test(url.pathname) || /^\/[^/]+\.[cm]?js$/.test(url.pathname))))) {
|
|
34
|
-
try {
|
|
35
|
-
if (!hasAsset(scene, url))
|
|
36
|
-
found.untrackedRequests = true;
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
found.untrackedRequests = true;
|
|
40
|
-
}
|
|
41
53
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
found.untrackedRequests = true;
|
|
54
|
+
else
|
|
55
|
+
pending.set(sent, undefined);
|
|
45
56
|
};
|
|
46
57
|
const socket = (opened) => {
|
|
47
58
|
const url = new URL(opened.url());
|
|
48
59
|
const host = origin(url);
|
|
49
60
|
if (host === api || apiPath(url))
|
|
50
61
|
found.apiCalls = true;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (host !== api && (!surfaces.has(host) || !hmr))
|
|
54
|
-
found.untrackedRequests = true;
|
|
62
|
+
if (host !== api)
|
|
63
|
+
sockets.push(host === surface ? known(url, 'websocket') : Promise.resolve(false));
|
|
55
64
|
};
|
|
56
65
|
page.context().on('request', request);
|
|
66
|
+
page.context().on('response', (response) => {
|
|
67
|
+
const sent = response.request();
|
|
68
|
+
if (!pending.has(sent))
|
|
69
|
+
return;
|
|
70
|
+
const url = new URL(sent.url());
|
|
71
|
+
const key = `${sent.resourceType()} ${url.href}`;
|
|
72
|
+
const covered = response.status() === 304 ? validated.get(key) : known(url, sent.resourceType(), response);
|
|
73
|
+
pending.set(sent, covered);
|
|
74
|
+
if (covered)
|
|
75
|
+
validated.set(key, covered);
|
|
76
|
+
});
|
|
57
77
|
page.on('websocket', socket);
|
|
78
|
+
let navigations = 0;
|
|
79
|
+
page.on('request', (sent) => {
|
|
80
|
+
if (sent.isNavigationRequest() && ++navigations > 1)
|
|
81
|
+
found.untrackedRequests = true;
|
|
82
|
+
});
|
|
58
83
|
page.on('frameattached', () => {
|
|
59
84
|
found.untrackedRequests = true;
|
|
60
85
|
});
|
|
61
|
-
|
|
86
|
+
const finish = async () => {
|
|
87
|
+
const total = pending.size + sockets.length;
|
|
88
|
+
const checks = await Promise.all([...pending.values(), ...sockets]);
|
|
89
|
+
if (total !== pending.size + sockets.length || checks.some((covered) => !covered))
|
|
90
|
+
found.untrackedRequests = true;
|
|
91
|
+
};
|
|
92
|
+
loads.set(found, [...(loads.get(found) ?? []), finish]);
|
|
93
|
+
return {
|
|
94
|
+
facts: found,
|
|
95
|
+
finish,
|
|
96
|
+
look: () => {
|
|
97
|
+
navigations = 0;
|
|
98
|
+
},
|
|
99
|
+
};
|
|
62
100
|
}
|
|
@@ -2,6 +2,7 @@ import type { Scene } from '@buffcore/config';
|
|
|
2
2
|
import { type GitRead, type SnapshotReport } from './report.ts';
|
|
3
3
|
import type { Run } from './scene.ts';
|
|
4
4
|
import { type Ancestor } from './snapshot-ancestor.ts';
|
|
5
|
+
import { type Matrix } from './snapshot-matrix.ts';
|
|
5
6
|
/** Report-level findings are run again against the mixed set of scenes. */
|
|
6
7
|
export declare const sceneFacts: (report: SnapshotReport, key: string) => {
|
|
7
8
|
problems: {
|
|
@@ -14,7 +15,7 @@ export declare const sceneFacts: (report: SnapshotReport, key: string) => {
|
|
|
14
15
|
}[];
|
|
15
16
|
hints: import("./report.ts").SnapshotHint[];
|
|
16
17
|
};
|
|
17
|
-
export declare function reuseScenes(root: string, run: Run, picked: readonly Scene[], remaining: readonly Scene[],
|
|
18
|
+
export declare function reuseScenes(root: string, run: Run, picked: readonly Scene[], remaining: readonly Scene[], candidates: ReadonlyMap<string, string>): Promise<{
|
|
18
19
|
scenes: Map<string, {
|
|
19
20
|
key: string;
|
|
20
21
|
title: string;
|
|
@@ -30,6 +31,8 @@ export declare function reuseScenes(root: string, run: Run, picked: readonly Sce
|
|
|
30
31
|
loadFailure?: import("./scene-errors.ts").LoadFailure;
|
|
31
32
|
scriptError?: import("./scene-errors.ts").LoadFailure;
|
|
32
33
|
reusedFrom?: string;
|
|
34
|
+
matrix?: Matrix;
|
|
35
|
+
extraLooks?: string[];
|
|
33
36
|
}>;
|
|
34
37
|
ancestor: undefined;
|
|
35
38
|
} | {
|
|
@@ -48,6 +51,8 @@ export declare function reuseScenes(root: string, run: Run, picked: readonly Sce
|
|
|
48
51
|
loadFailure?: import("./scene-errors.ts").LoadFailure;
|
|
49
52
|
scriptError?: import("./scene-errors.ts").LoadFailure;
|
|
50
53
|
reusedFrom?: string;
|
|
54
|
+
matrix?: Matrix;
|
|
55
|
+
extraLooks?: string[];
|
|
51
56
|
}>;
|
|
52
57
|
ancestor: Ancestor;
|
|
53
58
|
}>;
|
|
@@ -3,6 +3,7 @@ import { t } from './messages.js';
|
|
|
3
3
|
import { snapshotsDir } from './report.js';
|
|
4
4
|
import { findAncestor, readAncestor } from './snapshot-ancestor.js';
|
|
5
5
|
import { sha256Pattern } from './snapshot-hashes.js';
|
|
6
|
+
import { covers, drawnLooks } from './snapshot-matrix.js';
|
|
6
7
|
import { shotSources } from './snapshot-shared-shots.js';
|
|
7
8
|
import { boundShots, copyShots, shotStem, shotsMatch } from './snapshot-shots.js';
|
|
8
9
|
import { lookKey, photographed } from './snapshot-themes.js';
|
|
@@ -17,9 +18,12 @@ const eligible = (scene, fingerprint) => !!scene &&
|
|
|
17
18
|
!!fingerprint &&
|
|
18
19
|
sha256Pattern.test(fingerprint) &&
|
|
19
20
|
scene.fingerprint === fingerprint;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
/** The looks a scene drawn in `matrix` was photographed in. */
|
|
22
|
+
const photoLooks = (run, matrix) => [
|
|
23
|
+
...new Set(drawnLooks({ ...run, matrix })
|
|
24
|
+
.filter(({ theme, mode }) => photographed(theme.key, mode, run.product))
|
|
25
|
+
.map(({ theme, mode }) => lookKey(theme.key, mode))),
|
|
26
|
+
];
|
|
23
27
|
function copiedScene(scene, commit, from) {
|
|
24
28
|
const copied = {
|
|
25
29
|
...scene,
|
|
@@ -33,20 +37,26 @@ function copiedScene(scene, commit, from) {
|
|
|
33
37
|
delete copied.retryError;
|
|
34
38
|
return copied;
|
|
35
39
|
}
|
|
36
|
-
export async function reuseScenes(root, run, picked, remaining,
|
|
40
|
+
export async function reuseScenes(root, run, picked, remaining, candidates) {
|
|
37
41
|
const scenes = new Map();
|
|
38
|
-
const ancestor =
|
|
42
|
+
const ancestor = candidates.size && remaining.length ? findAncestor(root, run.commit) : undefined;
|
|
39
43
|
if (!ancestor)
|
|
40
44
|
return { scenes, ancestor };
|
|
41
45
|
const from = ancestor.report.commit;
|
|
42
46
|
const old = new Map(ancestor.report.scenes.map((scene) => [scene.key, scene]));
|
|
43
|
-
const looks = photoLooks(run);
|
|
44
47
|
const sources = shotSources(root, from, ancestor.hash);
|
|
45
48
|
const stems = picked.map((scene) => shotStem(scene.key).toLowerCase());
|
|
46
49
|
for (const scene of remaining) {
|
|
50
|
+
// A scene the selector picked is drawn again, never copied.
|
|
51
|
+
if (run.redraw?.has(scene.key))
|
|
52
|
+
continue;
|
|
47
53
|
const candidate = old.get(scene.key);
|
|
48
|
-
if (!candidate || !eligible(candidate,
|
|
54
|
+
if (!candidate || !eligible(candidate, candidates.get(scene.key)))
|
|
55
|
+
continue;
|
|
56
|
+
// A floor scene serves a floor run only; a full one serves either.
|
|
57
|
+
if (!covers(candidate.matrix, run.matrix))
|
|
49
58
|
continue;
|
|
59
|
+
const looks = photoLooks(run, candidate.matrix ?? 'full');
|
|
50
60
|
if (candidate.title !== scene.title ||
|
|
51
61
|
candidate.surface !== scene.surface ||
|
|
52
62
|
candidate.frame !== scene.frame ||
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Scene, Surface } from '@buffcore/config';
|
|
2
|
+
import type { Run } from './scene.ts';
|
|
3
|
+
import { type SurfaceEntry } from './snapshot-bundle.ts';
|
|
4
|
+
import { type snapshotDependencies } from './snapshot-dependencies.ts';
|
|
5
|
+
type Dependencies = ReturnType<typeof snapshotDependencies>;
|
|
6
|
+
type Walk = NonNullable<Awaited<ReturnType<Dependencies['walk']>>>;
|
|
7
|
+
type Digests = readonly (readonly [string, string])[];
|
|
8
|
+
/** The page a scene is drawn in: its own frame's size, in one key order. */
|
|
9
|
+
export declare function scenePage(run: Run, scene: Scene): import("playwright-core").BrowserContextOptions;
|
|
10
|
+
export interface SceneGraph {
|
|
11
|
+
topology: unknown;
|
|
12
|
+
files: Digests;
|
|
13
|
+
setup: Digests;
|
|
14
|
+
view(name: string): Digests | undefined;
|
|
15
|
+
}
|
|
16
|
+
export declare function sceneCandidates(root: string, scenes: readonly Scene[], run: Run, deps: Dependencies): {
|
|
17
|
+
reuse: Map<string, string>;
|
|
18
|
+
assets: Map<string, ReadonlySet<string>>;
|
|
19
|
+
signature: string;
|
|
20
|
+
/** F113c's shared inputs: public values and tools, the theme, `design/`, each shell's own parts. */
|
|
21
|
+
parts: string | undefined;
|
|
22
|
+
compare(inputs: ReadonlyMap<Surface, {
|
|
23
|
+
graph: SceneGraph | undefined;
|
|
24
|
+
settings: unknown;
|
|
25
|
+
pageAssets: string[];
|
|
26
|
+
whole?: boolean;
|
|
27
|
+
}>, shared: string): Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
export declare function sceneGraph(root: string, catalog: string, entry: SurfaceEntry, walk: Walk, deps: Dependencies, locales: readonly string[], eager: boolean): Promise<SceneGraph | undefined>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { dirname, extname, relative, resolve } from 'node:path';
|
|
2
|
+
import { pageOptions } from './browser.js';
|
|
3
|
+
import { catalogInput, loaders, moduleEffects, virtualInput, } from './snapshot-bundle.js';
|
|
4
|
+
import { pathIn, resolutionAlternatives, resolutionSettings, runtimeExternal, slash, } from './snapshot-dependencies.js';
|
|
5
|
+
import { plainData, sha256 } from './snapshot-hashes.js';
|
|
6
|
+
import { knownDeferred, registry, registryConsumer } from './snapshot-registry.js';
|
|
7
|
+
import { appBootstrap, snapshotFiles } from './snapshot-report.js';
|
|
8
|
+
const CODE = new Set(['ts', 'tsx', 'js', 'jsx']);
|
|
9
|
+
const editable = (root, file) => pathIn(root, file) && !slash(file).includes('/node_modules/');
|
|
10
|
+
const sharedName = /(?:^|\/)(?:design\/|(?:global|styles|setup|store|shell|rail)(?:[./-]|$))/i;
|
|
11
|
+
function walkFrom(edges, starts) {
|
|
12
|
+
const visited = new Set();
|
|
13
|
+
const pending = [...starts];
|
|
14
|
+
for (const file of pending) {
|
|
15
|
+
if (visited.has(file))
|
|
16
|
+
continue;
|
|
17
|
+
visited.add(file);
|
|
18
|
+
for (const path of edges.get(file) ?? [])
|
|
19
|
+
pending.push(path);
|
|
20
|
+
}
|
|
21
|
+
return visited;
|
|
22
|
+
}
|
|
23
|
+
/** The page a scene is drawn in: its own frame's size, in one key order. */
|
|
24
|
+
export function scenePage(run, scene) {
|
|
25
|
+
const { width, height } = run.frames[scene.frame];
|
|
26
|
+
return pageOptions({ width, height });
|
|
27
|
+
}
|
|
28
|
+
export function sceneCandidates(root, scenes, run, deps) {
|
|
29
|
+
const reuse = new Map();
|
|
30
|
+
const assets = new Map();
|
|
31
|
+
const surfaces = new Set(scenes.map(({ surface }) => surface));
|
|
32
|
+
return {
|
|
33
|
+
reuse,
|
|
34
|
+
assets,
|
|
35
|
+
signature: '',
|
|
36
|
+
/** F113c's shared inputs: public values and tools, the theme, `design/`, each shell's own parts. */
|
|
37
|
+
parts: undefined,
|
|
38
|
+
async compare(inputs, shared) {
|
|
39
|
+
const graphs = [...inputs].flatMap(([name, { graph, settings }]) => graph ? [[name, settings, graph]] : []);
|
|
40
|
+
const design = await snapshotFiles(resolve(root, 'design'))
|
|
41
|
+
.then((files) => Promise.all(files.map(async (file) => [slash(relative(root, file)), await deps.digest(file)])))
|
|
42
|
+
.catch(() => undefined);
|
|
43
|
+
if (!design || graphs.length !== surfaces.size)
|
|
44
|
+
return;
|
|
45
|
+
const setup = sha256(JSON.stringify([
|
|
46
|
+
'snapshot-scene-inputs-v3',
|
|
47
|
+
shared,
|
|
48
|
+
design,
|
|
49
|
+
run.product,
|
|
50
|
+
scenes.map(({ key, surface, view, frame }) => [key, surface, view, frame]),
|
|
51
|
+
graphs.map(([name, settings, graph]) => [name, settings, graph.topology, graph.setup]),
|
|
52
|
+
]));
|
|
53
|
+
const whole = sha256(JSON.stringify(['whole-graphs', setup, graphs.map(([, , g]) => g.files)]));
|
|
54
|
+
this.signature = whole;
|
|
55
|
+
this.parts = sha256(JSON.stringify([shared, design, run.product, graphs.map(([n, s, g]) => [n, s, g.setup])]));
|
|
56
|
+
const commonAssets = graphs.flatMap(([, , graph]) => graph.setup.map(([file]) => resolve(root, file)));
|
|
57
|
+
const viewAssets = new Map();
|
|
58
|
+
for (const scene of scenes) {
|
|
59
|
+
const input = inputs.get(scene.surface);
|
|
60
|
+
if (!input || typeof scene.view !== 'string')
|
|
61
|
+
continue;
|
|
62
|
+
const files = input.whole ? input.graph?.files : input.graph?.view(scene.view);
|
|
63
|
+
const binding = files ? ['view', setup, files] : ['coarse', whole];
|
|
64
|
+
// A scene whose props hold code (handlers) is never reused across commits: a function's
|
|
65
|
+
// text can stay the same while its helpers change. Its requests are still proven for the
|
|
66
|
+
// journal, which keeps a finished scene only for a run of the same source.
|
|
67
|
+
if (plainData(scene))
|
|
68
|
+
reuse.set(scene.key, sha256(JSON.stringify([binding, scene, scenePage(run, scene)])));
|
|
69
|
+
if (!input.graph)
|
|
70
|
+
continue;
|
|
71
|
+
const covered = files ?? input.graph.files;
|
|
72
|
+
const known = viewAssets.get(covered) ??
|
|
73
|
+
new Set([
|
|
74
|
+
...commonAssets,
|
|
75
|
+
...input.pageAssets,
|
|
76
|
+
...covered.map(([file]) => resolve(root, file)),
|
|
77
|
+
]);
|
|
78
|
+
viewAssets.set(covered, known);
|
|
79
|
+
assets.set(scene.key, known);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export async function sceneGraph(root, catalog, entry, walk, deps, locales, eager) {
|
|
85
|
+
try {
|
|
86
|
+
return await readGraph(root, catalog, entry, walk, deps, locales, eager);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function readGraph(root, catalog, entry, walk, deps, locales, eager) {
|
|
93
|
+
const inputs = Object.entries(walk.meta.inputs);
|
|
94
|
+
const names = new Set(inputs.map(([name]) => name));
|
|
95
|
+
const nameOf = (file) => slash(relative(root, file));
|
|
96
|
+
const fileOf = (name) => (name === catalogInput ? catalog : resolve(root, name));
|
|
97
|
+
const registryName = nameOf(entry.registry);
|
|
98
|
+
const importing = inputs.filter(([name, { imports }]) => name !== '<stdin>' && imports.some(({ path }) => path === registryName));
|
|
99
|
+
const routing = await registry(entry.registry, walk.meta.inputs[registryName]?.imports ?? [], deps, eager);
|
|
100
|
+
const consumers = await Promise.all(importing.map(([name, { imports }]) => registryConsumer(entry, fileOf(name), imports, deps)));
|
|
101
|
+
const split = routing && consumers.every(Boolean);
|
|
102
|
+
const full = new Map();
|
|
103
|
+
const common = new Map();
|
|
104
|
+
const onLoad = new Set([registryName, ...entry.roots.map(nameOf)]);
|
|
105
|
+
const routes = new Set(entry.routes.map(nameOf));
|
|
106
|
+
const reexports = new Map();
|
|
107
|
+
const files = new Map();
|
|
108
|
+
const addFile = async (name, file) => {
|
|
109
|
+
files.set(name, [nameOf(file), await deps.digest(file)]);
|
|
110
|
+
};
|
|
111
|
+
if (entry.surface === 'app') {
|
|
112
|
+
const boot = await appBootstrap(entry.dir, deps.read);
|
|
113
|
+
if (boot) {
|
|
114
|
+
onLoad.add(nameOf(boot));
|
|
115
|
+
await addFile(nameOf(boot), boot);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const safe = await Promise.all(inputs.map(async ([name, input]) => {
|
|
119
|
+
const file = fileOf(name);
|
|
120
|
+
const imports = input.imports;
|
|
121
|
+
const virtual = virtualInput(name);
|
|
122
|
+
const local = !virtual && editable(root, file);
|
|
123
|
+
if (imports.some((edge) => !edge.external && !names.has(edge.path)))
|
|
124
|
+
return false;
|
|
125
|
+
const external = imports
|
|
126
|
+
.filter(({ external, kind, path }) => external &&
|
|
127
|
+
!(kind === 'url-token' && /^(data:|#)/.test(path)) &&
|
|
128
|
+
!imports.some((edge) => !edge.external && edge.original === path))
|
|
129
|
+
.map(({ path }) => path);
|
|
130
|
+
if (external.length && (await runtimeExternal(file, external, deps.read)))
|
|
131
|
+
return false;
|
|
132
|
+
const deferred = imports.filter(({ kind }) => kind === 'dynamic-import');
|
|
133
|
+
const planned = name === registryName &&
|
|
134
|
+
deferred.every(({ original }) => original && routing?.lazy.has(original));
|
|
135
|
+
if (local &&
|
|
136
|
+
deferred.length &&
|
|
137
|
+
!planned &&
|
|
138
|
+
!(await knownDeferred(entry, file, deferred, locales, deps)))
|
|
139
|
+
return false;
|
|
140
|
+
const assets = virtual ? [] : await deps.assets(file);
|
|
141
|
+
if (!assets)
|
|
142
|
+
return false;
|
|
143
|
+
const paths = (edges) => edges
|
|
144
|
+
.filter(({ external }) => !external)
|
|
145
|
+
.map(({ path }) => path)
|
|
146
|
+
.concat(assets.map((asset) => nameOf(resolve(dirname(file), asset))));
|
|
147
|
+
full.set(name, paths(imports));
|
|
148
|
+
common.set(name, paths(split && name === registryName ? routing.setup : imports).filter((target) => !split || target !== registryName));
|
|
149
|
+
if (!virtual) {
|
|
150
|
+
if (walk.unproven.has(file))
|
|
151
|
+
return false;
|
|
152
|
+
const loader = loaders[extname(file).toLowerCase()];
|
|
153
|
+
if (local) {
|
|
154
|
+
for (const edge of imports) {
|
|
155
|
+
if (edge.external || virtualInput(edge.path) || edge.path === catalogInput)
|
|
156
|
+
continue;
|
|
157
|
+
const target = fileOf(edge.path);
|
|
158
|
+
if (!editable(root, target))
|
|
159
|
+
continue;
|
|
160
|
+
if (resolutionAlternatives(file, edge.original, target).length)
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
for (const asset of assets) {
|
|
165
|
+
const path = resolve(dirname(file), asset);
|
|
166
|
+
await addFile(nameOf(path), path);
|
|
167
|
+
}
|
|
168
|
+
// Bind the original scene catalog if esbuild retains its initialization.
|
|
169
|
+
if (name !== catalogInput || eager || walk.selected.has(name))
|
|
170
|
+
await addFile(name, file);
|
|
171
|
+
if (name === catalogInput || !local || loader === 'css' || sharedName.test(name)) {
|
|
172
|
+
onLoad.add(name);
|
|
173
|
+
}
|
|
174
|
+
else if (name !== registryName && loader && CODE.has(loader)) {
|
|
175
|
+
const effects = await moduleEffects(file, deps);
|
|
176
|
+
if (!effects || effects.initializes || (routes.has(name) && !effects.defaultOnly))
|
|
177
|
+
onLoad.add(name);
|
|
178
|
+
if (effects?.exports.length)
|
|
179
|
+
reexports.set(name, effects.exports);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}));
|
|
184
|
+
if (safe.includes(false))
|
|
185
|
+
return;
|
|
186
|
+
const entries = [...files].sort(([a], [b]) => a.localeCompare(b));
|
|
187
|
+
const digests = (selected, omit) => entries.flatMap(([name, digest]) => !omit?.has(name) && (!selected || selected.has(name)) ? [digest] : []);
|
|
188
|
+
const shared = walkFrom(common, onLoad);
|
|
189
|
+
for (const route of routes)
|
|
190
|
+
shared.add(route);
|
|
191
|
+
const views = new Map();
|
|
192
|
+
return {
|
|
193
|
+
topology: [
|
|
194
|
+
await resolutionSettings(root, [...files.keys()].map(fileOf), deps),
|
|
195
|
+
inputs
|
|
196
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
197
|
+
.map(([name, { imports }]) => [name, imports, full.get(name), reexports.get(name)]),
|
|
198
|
+
],
|
|
199
|
+
files: digests(),
|
|
200
|
+
setup: digests(shared),
|
|
201
|
+
view(name) {
|
|
202
|
+
const file = split && routing.named.get(name);
|
|
203
|
+
if (!file)
|
|
204
|
+
return;
|
|
205
|
+
const matched = views.get(file) ?? digests(walkFrom(full, [file]), shared);
|
|
206
|
+
views.set(file, matched);
|
|
207
|
+
return matched;
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Response } from 'playwright-core';
|
|
2
|
+
export declare function servedBytes(url: URL, mime: string, timeout?: number): Promise<Buffer<ArrayBuffer> | undefined>;
|
|
3
|
+
export declare function matchesBytes(hash: string | undefined, response?: Response): Promise<boolean>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { sha256 } from './snapshot-hashes.js';
|
|
2
|
+
export async function servedBytes(url, mime, timeout = 110_000) {
|
|
3
|
+
if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname))
|
|
4
|
+
return;
|
|
5
|
+
const response = await fetch(url, { redirect: 'error', signal: AbortSignal.timeout(timeout) });
|
|
6
|
+
if (!response.ok || !response.headers.get('content-type')?.includes(mime))
|
|
7
|
+
return;
|
|
8
|
+
return Buffer.from(await response.arrayBuffer());
|
|
9
|
+
}
|
|
10
|
+
export async function matchesBytes(hash, response) {
|
|
11
|
+
return !!hash && !!response?.ok() && sha256(await response.body()) === hash;
|
|
12
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface ServerProcess {
|
|
2
|
+
pid: number;
|
|
3
|
+
parent: number;
|
|
4
|
+
start: string;
|
|
5
|
+
command: string;
|
|
6
|
+
}
|
|
7
|
+
/** Every process now, with its start time and command line. */
|
|
8
|
+
export declare function processTable(): Promise<ServerProcess[]>;
|
|
9
|
+
/** A start in epoch milliseconds: Windows gives a FILETIME (100 ns since 1601), `ps` a date. */
|
|
10
|
+
export declare function startTime(start: string): number | undefined;
|
|
11
|
+
/** The trees below `roots`, each child started at or after its parent (see `descendants`). */
|
|
12
|
+
export declare function processTrees(table: readonly ServerProcess[], roots: readonly number[]): Set<number>;
|
|
13
|
+
/** Whether a command line holds `path` itself: a separator, a quote, a space or the end follows. */
|
|
14
|
+
export declare function holdsPath(command: string, path: string): boolean;
|
|
15
|
+
/** The servers' process trees, from their own processes down. */
|
|
16
|
+
export declare function serverTrees(table: readonly ServerProcess[], roots: readonly number[]): ServerProcess[];
|
|
17
|
+
/** The recorded processes that are still the very same ones, and this checkout's. */
|
|
18
|
+
export declare function reapable(recorded: readonly ServerProcess[], table: readonly ServerProcess[], checkout: string): number[];
|
|
19
|
+
export declare function recordServers(file: string, entries: readonly ServerProcess[]): void;
|
|
20
|
+
export declare function forgetServers(file: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Stop what an earlier run of this worktree left running, then forget the record. Called with the
|
|
23
|
+
* worktree's lock held, so the run that wrote it is over. A table that cannot be read keeps the
|
|
24
|
+
* record for the next run.
|
|
25
|
+
*/
|
|
26
|
+
export declare function reapServers(file: string, checkout: string, table?: () => Promise<ServerProcess[]>, kill?: (pid: number) => void): Promise<number[]>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// The dev servers a linked worktree's snapshot started, recorded beside its lock so that the next run
|
|
2
|
+
// of the same worktree can stop what a hard kill (a crash, a closed terminal) left running. A process
|
|
3
|
+
// is stopped only when its id, its start time and its whole command line all still match the record
|
|
4
|
+
// and that line holds this checkout's own path: an id the system gave to another process is never hit.
|
|
5
|
+
import { execFile } from 'node:child_process';
|
|
6
|
+
import { readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
8
|
+
import { descendants } from './snapshot-owners.js';
|
|
9
|
+
const run = promisify(execFile);
|
|
10
|
+
const options = {
|
|
11
|
+
encoding: 'utf8',
|
|
12
|
+
windowsHide: true,
|
|
13
|
+
timeout: 30_000,
|
|
14
|
+
maxBuffer: 64 << 20,
|
|
15
|
+
};
|
|
16
|
+
const WINDOWS = 'Get-CimInstance Win32_Process | ForEach-Object { "$($_.ProcessId)`t$($_.ParentProcessId)`t$(if ($_.CreationDate) { $_.CreationDate.ToFileTimeUtc() })`t$($_.CommandLine)" }';
|
|
17
|
+
const POSIX = /^\s*(\d+)\s+(\d+)\s+(\S+\s+\S+\s+\d+\s+[\d:]+\s+\d+)\s+(.*)$/;
|
|
18
|
+
/** Every process now, with its start time and command line. */
|
|
19
|
+
export async function processTable() {
|
|
20
|
+
if (process.platform === 'win32') {
|
|
21
|
+
const { stdout } = await run('powershell', ['-NoProfile', '-Command', WINDOWS], options);
|
|
22
|
+
return stdout.split(/\r?\n/).flatMap((line) => {
|
|
23
|
+
const [pid, parent, start = '', ...command] = line.split('\t');
|
|
24
|
+
return pid && parent
|
|
25
|
+
? [{ pid: Number(pid), parent: Number(parent), start, command: command.join('\t') }]
|
|
26
|
+
: [];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const { stdout } = await run('ps', ['-A', '-o', 'pid=,ppid=,lstart=,args='], {
|
|
30
|
+
...options,
|
|
31
|
+
env: { ...process.env, LC_ALL: 'C' },
|
|
32
|
+
});
|
|
33
|
+
return stdout.split('\n').flatMap((line) => {
|
|
34
|
+
const cells = POSIX.exec(line);
|
|
35
|
+
return cells
|
|
36
|
+
? [
|
|
37
|
+
{
|
|
38
|
+
pid: Number(cells[1]),
|
|
39
|
+
parent: Number(cells[2]),
|
|
40
|
+
start: cells[3],
|
|
41
|
+
command: cells[4],
|
|
42
|
+
},
|
|
43
|
+
]
|
|
44
|
+
: [];
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** A start in epoch milliseconds: Windows gives a FILETIME (100 ns since 1601), `ps` a date. */
|
|
48
|
+
export function startTime(start) {
|
|
49
|
+
const time = /^\d+$/.test(start)
|
|
50
|
+
? Number(start) / 10_000 - 11_644_473_600_000
|
|
51
|
+
: Date.parse(start);
|
|
52
|
+
return Number.isFinite(time) ? time : undefined;
|
|
53
|
+
}
|
|
54
|
+
/** The trees below `roots`, each child started at or after its parent (see `descendants`). */
|
|
55
|
+
export function processTrees(table, roots) {
|
|
56
|
+
const pairs = table.map(({ pid, parent }) => `${pid} ${parent}`).join('\n');
|
|
57
|
+
const starts = new Map();
|
|
58
|
+
for (const { pid, start } of table) {
|
|
59
|
+
const time = startTime(start);
|
|
60
|
+
if (time !== undefined)
|
|
61
|
+
starts.set(pid, time);
|
|
62
|
+
}
|
|
63
|
+
return new Set(roots.flatMap((root) => [...descendants(pairs, root, starts)]));
|
|
64
|
+
}
|
|
65
|
+
/** Whether a command line holds `path` itself: a separator, a quote, a space or the end follows. */
|
|
66
|
+
export function holdsPath(command, path) {
|
|
67
|
+
for (const form of new Set([path, path.replaceAll('\\', '/')]))
|
|
68
|
+
for (let at = command.indexOf(form); at >= 0; at = command.indexOf(form, at + 1))
|
|
69
|
+
if (/^($|[\\/"' ])/.test(command.slice(at + form.length)))
|
|
70
|
+
return true;
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
/** The servers' process trees, from their own processes down. */
|
|
74
|
+
export function serverTrees(table, roots) {
|
|
75
|
+
const tree = processTrees(table, roots);
|
|
76
|
+
return table.filter((entry) => tree.has(entry.pid) && entry.start !== '');
|
|
77
|
+
}
|
|
78
|
+
/** The recorded processes that are still the very same ones, and this checkout's. */
|
|
79
|
+
export function reapable(recorded, table, checkout) {
|
|
80
|
+
const now = new Map(table.map((entry) => [entry.pid, entry]));
|
|
81
|
+
return recorded
|
|
82
|
+
.filter((entry) => {
|
|
83
|
+
const current = now.get(entry.pid);
|
|
84
|
+
return (!!current &&
|
|
85
|
+
entry.start !== '' &&
|
|
86
|
+
current.start === entry.start &&
|
|
87
|
+
current.command === entry.command &&
|
|
88
|
+
holdsPath(entry.command, checkout));
|
|
89
|
+
})
|
|
90
|
+
.map((entry) => entry.pid);
|
|
91
|
+
}
|
|
92
|
+
export function recordServers(file, entries) {
|
|
93
|
+
writeFileSync(`${file}.tmp`, JSON.stringify(entries));
|
|
94
|
+
renameSync(`${file}.tmp`, file);
|
|
95
|
+
}
|
|
96
|
+
export function forgetServers(file) {
|
|
97
|
+
rmSync(file, { force: true });
|
|
98
|
+
}
|
|
99
|
+
function recorded(file) {
|
|
100
|
+
try {
|
|
101
|
+
const value = JSON.parse(readFileSync(file, 'utf8'));
|
|
102
|
+
if (!Array.isArray(value))
|
|
103
|
+
return [];
|
|
104
|
+
return value.filter((entry) => Number.isSafeInteger(entry?.pid) &&
|
|
105
|
+
entry.pid > 0 &&
|
|
106
|
+
typeof entry.start === 'string' &&
|
|
107
|
+
typeof entry.command === 'string');
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
return error.code === 'ENOENT' ? undefined : [];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Stop what an earlier run of this worktree left running, then forget the record. Called with the
|
|
115
|
+
* worktree's lock held, so the run that wrote it is over. A table that cannot be read keeps the
|
|
116
|
+
* record for the next run.
|
|
117
|
+
*/
|
|
118
|
+
export async function reapServers(file, checkout, table = processTable, kill = (pid) => process.kill(pid, 'SIGKILL')) {
|
|
119
|
+
const entries = recorded(file);
|
|
120
|
+
if (entries === undefined)
|
|
121
|
+
return [];
|
|
122
|
+
const now = await table().catch(() => undefined);
|
|
123
|
+
if (!now)
|
|
124
|
+
return [];
|
|
125
|
+
const pids = reapable(entries, now, checkout);
|
|
126
|
+
for (const pid of pids)
|
|
127
|
+
try {
|
|
128
|
+
kill(pid);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// Gone between the lookup and the kill.
|
|
132
|
+
}
|
|
133
|
+
forgetServers(file);
|
|
134
|
+
return pids;
|
|
135
|
+
}
|
|
@@ -14,6 +14,8 @@ export interface Dependencies {
|
|
|
14
14
|
owners?: Owners;
|
|
15
15
|
listen?: Listen;
|
|
16
16
|
readyMs?: number;
|
|
17
|
+
/** Where the servers' processes are recorded; by default beside the worktree's snapshot lock. */
|
|
18
|
+
record?: string | undefined;
|
|
17
19
|
}
|
|
18
20
|
/** What the command asks of a run's servers. */
|
|
19
21
|
export interface SnapshotServers {
|
|
@@ -28,5 +30,5 @@ export interface SnapshotServers {
|
|
|
28
30
|
exit: NonNullable<Run['serverExit']>;
|
|
29
31
|
stop(): Promise<void>;
|
|
30
32
|
}
|
|
31
|
-
export declare function snapshotServers(root: string, environment: SnapshotEnvironment, urls: Run['urls'], { owners, listen, readyMs }?: Dependencies): SnapshotServers;
|
|
33
|
+
export declare function snapshotServers(root: string, environment: SnapshotEnvironment, urls: Run['urls'], { owners, listen, readyMs, record, }?: Dependencies): SnapshotServers;
|
|
32
34
|
export {};
|