@gate-forge/cli 0.7.1 → 0.8.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/README.md +499 -47
- package/dist/adapter-audit.d.ts +154 -0
- package/dist/adapter-audit.d.ts.map +1 -0
- package/dist/adapter-audit.js +531 -0
- package/dist/adapter-audit.js.map +1 -0
- package/dist/adapter-scaffold.d.ts +66 -0
- package/dist/adapter-scaffold.d.ts.map +1 -0
- package/dist/adapter-scaffold.js +353 -0
- package/dist/adapter-scaffold.js.map +1 -0
- package/dist/adopted-baseline.d.ts +10 -0
- package/dist/adopted-baseline.d.ts.map +1 -1
- package/dist/adopted-baseline.js +18 -1
- package/dist/adopted-baseline.js.map +1 -1
- package/dist/args.d.ts +15 -0
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +59 -2
- package/dist/args.js.map +1 -1
- package/dist/behavior-setup.d.ts +239 -0
- package/dist/behavior-setup.d.ts.map +1 -0
- package/dist/behavior-setup.js +738 -0
- package/dist/behavior-setup.js.map +1 -0
- package/dist/broker.d.ts.map +1 -1
- package/dist/broker.js +28 -2
- package/dist/broker.js.map +1 -1
- package/dist/cache-exclusions.d.ts +45 -0
- package/dist/cache-exclusions.d.ts.map +1 -0
- package/dist/cache-exclusions.js +205 -0
- package/dist/cache-exclusions.js.map +1 -0
- package/dist/candidate-tree.d.ts +86 -14
- package/dist/candidate-tree.d.ts.map +1 -1
- package/dist/candidate-tree.js +236 -62
- package/dist/candidate-tree.js.map +1 -1
- package/dist/ci-witnessed-template.d.ts +43 -0
- package/dist/ci-witnessed-template.d.ts.map +1 -0
- package/dist/ci-witnessed-template.js +283 -0
- package/dist/ci-witnessed-template.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +31 -4
- package/dist/cli.js.map +1 -1
- package/dist/commands/adapters.d.ts +15 -0
- package/dist/commands/adapters.d.ts.map +1 -0
- package/dist/commands/adapters.js +284 -0
- package/dist/commands/adapters.js.map +1 -0
- package/dist/commands/adopt.d.ts.map +1 -1
- package/dist/commands/adopt.js +9 -1
- package/dist/commands/adopt.js.map +1 -1
- package/dist/commands/baseline.d.ts.map +1 -1
- package/dist/commands/baseline.js +42 -1
- package/dist/commands/baseline.js.map +1 -1
- package/dist/commands/blocking.d.ts +81 -2
- package/dist/commands/blocking.d.ts.map +1 -1
- package/dist/commands/blocking.js +336 -53
- package/dist/commands/blocking.js.map +1 -1
- package/dist/commands/check.d.ts +36 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +1008 -62
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/classify.d.ts +2 -1
- package/dist/commands/classify.d.ts.map +1 -1
- package/dist/commands/classify.js +143 -5
- package/dist/commands/classify.js.map +1 -1
- package/dist/commands/enforce.d.ts +4 -4
- package/dist/commands/enforce.d.ts.map +1 -1
- package/dist/commands/enforce.js +41 -9
- package/dist/commands/enforce.js.map +1 -1
- package/dist/commands/enforcement.d.ts +13 -1
- package/dist/commands/enforcement.d.ts.map +1 -1
- package/dist/commands/enforcement.js +800 -30
- package/dist/commands/enforcement.js.map +1 -1
- package/dist/commands/history.d.ts +12 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +45 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/init-presets.d.ts +148 -0
- package/dist/commands/init-presets.d.ts.map +1 -0
- package/dist/commands/init-presets.js +194 -0
- package/dist/commands/init-presets.js.map +1 -0
- package/dist/commands/init.d.ts +7 -12
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +610 -69
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/keys.d.ts.map +1 -1
- package/dist/commands/keys.js +29 -13
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/next.d.ts.map +1 -1
- package/dist/commands/next.js +744 -15
- package/dist/commands/next.js.map +1 -1
- package/dist/commands/pre-commit.d.ts +25 -0
- package/dist/commands/pre-commit.d.ts.map +1 -1
- package/dist/commands/pre-commit.js +91 -6
- package/dist/commands/pre-commit.js.map +1 -1
- package/dist/commands/quarantine.d.ts +16 -0
- package/dist/commands/quarantine.d.ts.map +1 -0
- package/dist/commands/quarantine.js +213 -0
- package/dist/commands/quarantine.js.map +1 -0
- package/dist/commands/run.d.ts +39 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +196 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/test-gates.d.ts +284 -2
- package/dist/commands/test-gates.d.ts.map +1 -1
- package/dist/commands/test-gates.js +3619 -186
- package/dist/commands/test-gates.js.map +1 -1
- package/dist/commands/tests.d.ts +1 -1
- package/dist/commands/tests.d.ts.map +1 -1
- package/dist/commands/tests.js +225 -22
- package/dist/commands/tests.js.map +1 -1
- package/dist/endpoint-compiler.d.ts.map +1 -1
- package/dist/endpoint-compiler.js +29 -8
- package/dist/endpoint-compiler.js.map +1 -1
- package/dist/engine-browser.d.ts +183 -0
- package/dist/engine-browser.d.ts.map +1 -0
- package/dist/engine-browser.js +381 -0
- package/dist/engine-browser.js.map +1 -0
- package/dist/engine-identity.d.ts +100 -0
- package/dist/engine-identity.d.ts.map +1 -0
- package/dist/engine-identity.js +182 -0
- package/dist/engine-identity.js.map +1 -0
- package/dist/evaluate.d.ts +89 -0
- package/dist/evaluate.d.ts.map +1 -1
- package/dist/evaluate.js +137 -16
- package/dist/evaluate.js.map +1 -1
- package/dist/execution.d.ts +253 -9
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +309 -12
- package/dist/execution.js.map +1 -1
- package/dist/git-hooks.d.ts +17 -0
- package/dist/git-hooks.d.ts.map +1 -1
- package/dist/git-hooks.js +119 -0
- package/dist/git-hooks.js.map +1 -1
- package/dist/git-objects.d.ts +60 -0
- package/dist/git-objects.d.ts.map +1 -0
- package/dist/git-objects.js +152 -0
- package/dist/git-objects.js.map +1 -0
- package/dist/history.d.ts +52 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +116 -0
- package/dist/history.js.map +1 -0
- package/dist/host-load.d.ts +49 -0
- package/dist/host-load.d.ts.map +1 -0
- package/dist/host-load.js +78 -0
- package/dist/host-load.js.map +1 -0
- package/dist/input-snapshot.d.ts +63 -9
- package/dist/input-snapshot.d.ts.map +1 -1
- package/dist/input-snapshot.js +195 -17
- package/dist/input-snapshot.js.map +1 -1
- package/dist/io.d.ts +36 -0
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +21 -0
- package/dist/io.js.map +1 -1
- package/dist/mapping.d.ts +84 -1
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +276 -5
- package/dist/mapping.js.map +1 -1
- package/dist/native-freeze.d.ts +217 -0
- package/dist/native-freeze.d.ts.map +1 -0
- package/dist/native-freeze.js +332 -0
- package/dist/native-freeze.js.map +1 -0
- package/dist/pipeline.d.ts +52 -1
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +141 -3
- package/dist/pipeline.js.map +1 -1
- package/dist/playwright-browsers.d.ts +210 -0
- package/dist/playwright-browsers.d.ts.map +1 -0
- package/dist/playwright-browsers.js +364 -0
- package/dist/playwright-browsers.js.map +1 -0
- package/dist/plugins.d.ts +15 -5
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +59 -9
- package/dist/plugins.js.map +1 -1
- package/dist/progress.d.ts +148 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +263 -0
- package/dist/progress.js.map +1 -0
- package/dist/providers.d.ts +26 -1
- package/dist/providers.d.ts.map +1 -1
- package/dist/providers.js +39 -0
- package/dist/providers.js.map +1 -1
- package/dist/receipts.d.ts +1 -0
- package/dist/receipts.d.ts.map +1 -1
- package/dist/receipts.js +35 -7
- package/dist/receipts.js.map +1 -1
- package/dist/repo-scan.d.ts +8 -1
- package/dist/repo-scan.d.ts.map +1 -1
- package/dist/repo-scan.js +221 -27
- package/dist/repo-scan.js.map +1 -1
- package/dist/reseal-chain.d.ts +184 -0
- package/dist/reseal-chain.d.ts.map +1 -0
- package/dist/reseal-chain.js +735 -0
- package/dist/reseal-chain.js.map +1 -0
- package/dist/reseal-evidence.d.ts +241 -0
- package/dist/reseal-evidence.d.ts.map +1 -0
- package/dist/reseal-evidence.js +319 -0
- package/dist/reseal-evidence.js.map +1 -0
- package/dist/reseal.d.ts +181 -0
- package/dist/reseal.d.ts.map +1 -0
- package/dist/reseal.js +1620 -0
- package/dist/reseal.js.map +1 -0
- package/dist/response-field-guidance.d.ts +82 -0
- package/dist/response-field-guidance.d.ts.map +1 -0
- package/dist/response-field-guidance.js +184 -0
- package/dist/response-field-guidance.js.map +1 -0
- package/dist/run-cache.d.ts +260 -0
- package/dist/run-cache.d.ts.map +1 -0
- package/dist/run-cache.js +771 -0
- package/dist/run-cache.js.map +1 -0
- package/dist/run-preflight.d.ts +77 -0
- package/dist/run-preflight.d.ts.map +1 -0
- package/dist/run-preflight.js +774 -0
- package/dist/run-preflight.js.map +1 -0
- package/dist/run-recipe.d.ts +107 -0
- package/dist/run-recipe.d.ts.map +1 -0
- package/dist/run-recipe.js +295 -0
- package/dist/run-recipe.js.map +1 -0
- package/dist/run-reliability.d.ts +126 -0
- package/dist/run-reliability.d.ts.map +1 -0
- package/dist/run-reliability.js +221 -0
- package/dist/run-reliability.js.map +1 -0
- package/dist/runtime.d.ts +15 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +11 -1
- package/dist/runtime.js.map +1 -1
- package/dist/secret-guard.d.ts +36 -0
- package/dist/secret-guard.d.ts.map +1 -0
- package/dist/secret-guard.js +63 -0
- package/dist/secret-guard.js.map +1 -0
- package/dist/singleton-guidance.d.ts +73 -0
- package/dist/singleton-guidance.d.ts.map +1 -0
- package/dist/singleton-guidance.js +118 -0
- package/dist/singleton-guidance.js.map +1 -0
- package/dist/staged-candidate.d.ts +17 -0
- package/dist/staged-candidate.d.ts.map +1 -1
- package/dist/staged-candidate.js +50 -0
- package/dist/staged-candidate.js.map +1 -1
- package/dist/state-artifacts.d.ts +70 -0
- package/dist/state-artifacts.d.ts.map +1 -0
- package/dist/state-artifacts.js +215 -0
- package/dist/state-artifacts.js.map +1 -0
- package/dist/state.d.ts +170 -2
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +248 -8
- package/dist/state.js.map +1 -1
- package/dist/verifier-keys.d.ts +33 -2
- package/dist/verifier-keys.d.ts.map +1 -1
- package/dist/verifier-keys.js +95 -9
- package/dist/verifier-keys.js.map +1 -1
- package/guides/CONNECT-YOUR-PROJECT.md +367 -0
- package/guides/QUICKSTART.md +259 -24
- package/guides/RUNNER-NEUTRAL-EVIDENCE.md +199 -0
- package/guides/TEST-ENVIRONMENT.md +1041 -6
- package/guides/UPGRADE-0.6-to-0.7.md +3 -3
- package/guides/UPGRADE-0.7-to-0.8.md +114 -0
- package/package.json +10 -9
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine-owned browser readiness (the engine's OWN Chromium).
|
|
3
|
+
*
|
|
4
|
+
* The consumer's Playwright is not the only browser a supervised run
|
|
5
|
+
* launches. `@gate-forge/pack-playwright` pins its OWN `playwright`
|
|
6
|
+
* dependency, and the engine's browser — the one
|
|
7
|
+
* `EngineBrowserManager` drives for every `engine-browser` channel case,
|
|
8
|
+
* every `ui.action` / `visible.confirm` fixture primitive and every
|
|
9
|
+
* engine surface drive — is that pinned release's Chromium, never the
|
|
10
|
+
* consumer's.
|
|
11
|
+
*
|
|
12
|
+
* A consumer whose Playwright is a DIFFERENT release therefore proves
|
|
13
|
+
* nothing about the engine browser: the consumer's readiness inspection
|
|
14
|
+
* reads the consumer's registry, answers "every pinned build is
|
|
15
|
+
* installed", and the run still dies in the witness with `Executable
|
|
16
|
+
* doesn't exist at .../chromium_headless_shell-<engine-rev>/…`. That is
|
|
17
|
+
* the real consumer this module exists for: `@playwright/test` 1.62.1
|
|
18
|
+
* with Chromium 1234 installed and correct, while the pack's pinned
|
|
19
|
+
* 1.58.2 wants 1208 and the cache never held it. The consumer check said
|
|
20
|
+
* `ok`; the engine check said `Executable doesn't exist`.
|
|
21
|
+
*
|
|
22
|
+
* Two properties this module keeps, both load-bearing:
|
|
23
|
+
*
|
|
24
|
+
* - It NEVER loads the consumer's Playwright. Resolution is a
|
|
25
|
+
* filesystem walk from the INSTALLED engine package (its realpath, so
|
|
26
|
+
* a linked workspace resolves the same release it actually loads at
|
|
27
|
+
* runtime), reading only `package.json` / `browsers.json`. Nothing
|
|
28
|
+
* from the repository is imported into the trusted process.
|
|
29
|
+
* - The remedy is the EXACT installed engine's own CLI, not `npx
|
|
30
|
+
* playwright install`. `npx` resolves whatever Playwright the CWD
|
|
31
|
+
* reaches — the consumer's release — so it installs the very revision
|
|
32
|
+
* the cache already holds and the engine stays broken. The command
|
|
33
|
+
* names the engine's resolved `cli.js` by absolute path instead.
|
|
34
|
+
*
|
|
35
|
+
* The engine's browser requirement is CONSERVATIVE and explicit, and has
|
|
36
|
+
* exactly two producers: the configured runner is `playwright` (its
|
|
37
|
+
* `ui.action` / `visible.confirm` / `persistence.verify` receipts are all
|
|
38
|
+
* served by the engine's own Chromium), or the behavior policy declares a
|
|
39
|
+
* case on the `engine-browser` channel (runner-neutral, so a pytest
|
|
40
|
+
* surface case needs it too). A pytest / API-only repository, and a
|
|
41
|
+
* non-playwright repository whose cases run on `engine-http` /
|
|
42
|
+
* `engine-task`, never need an engine Chromium and are never told to
|
|
43
|
+
* install one.
|
|
44
|
+
*/
|
|
45
|
+
import { BehaviorPolicySchema } from '@gate-forge/core';
|
|
46
|
+
import { parse as parseYaml } from 'yaml';
|
|
47
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
48
|
+
import { dirname, join, resolve } from 'node:path';
|
|
49
|
+
import { fileURLToPath } from 'node:url';
|
|
50
|
+
import { browserDirectoryName, defaultBrowsersPath, findBrowsersRegistry, installArguments, readBrowserBuilds, requiredBuilds, unlaunchableBuilds, } from './playwright-browsers.js';
|
|
51
|
+
/** The behavior-case channel the witness drives through the engine browser. */
|
|
52
|
+
const ENGINE_BROWSER_CHANNEL = 'engine-browser';
|
|
53
|
+
/** The engine package whose pinned Playwright drives the engine browser. */
|
|
54
|
+
const ENGINE_PACKAGE = '@gate-forge/pack-playwright';
|
|
55
|
+
/** Directory levels the engine-package walk covers (npm hoisting depth). */
|
|
56
|
+
const RESOLUTION_DEPTH = 6;
|
|
57
|
+
/**
|
|
58
|
+
* The browsers the engine-owned launcher opens: Chromium, headless
|
|
59
|
+
* (`EngineBrowserManager` launches `{headless: true}`), so its headless
|
|
60
|
+
* shell is required alongside the full build.
|
|
61
|
+
*/
|
|
62
|
+
const ENGINE_BROWSERS = ['chromium'];
|
|
63
|
+
/**
|
|
64
|
+
* Walks up from `start` for `node_modules/<name>/package.json`, the same
|
|
65
|
+
* order Node itself resolves a bare specifier through.
|
|
66
|
+
*/
|
|
67
|
+
function findInstalledPackageManifest(start, name) {
|
|
68
|
+
let cursor = start;
|
|
69
|
+
for (let depth = 0; depth < RESOLUTION_DEPTH; depth += 1) {
|
|
70
|
+
const candidate = join(cursor, 'node_modules', name, 'package.json');
|
|
71
|
+
if (existsSync(candidate))
|
|
72
|
+
return candidate;
|
|
73
|
+
const parent = resolve(cursor, '..');
|
|
74
|
+
if (parent === cursor)
|
|
75
|
+
break;
|
|
76
|
+
cursor = parent;
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Locates the installed engine package and the pinned Playwright release
|
|
82
|
+
* its own browser driver loads.
|
|
83
|
+
*
|
|
84
|
+
* The engine package root is resolved to its REALPATH on purpose: a
|
|
85
|
+
* linked workspace (npm link, a monorepo `file:` install) makes the
|
|
86
|
+
* engine load its sibling `node_modules` beside the real directory, not
|
|
87
|
+
* the consumer's hoisted tree. Reading the link path instead would
|
|
88
|
+
* inspect a release the engine never launches.
|
|
89
|
+
*
|
|
90
|
+
* Args:
|
|
91
|
+
* cwd: repository root.
|
|
92
|
+
*
|
|
93
|
+
* Returns:
|
|
94
|
+
* EngineBrowserResolution: the resolved install, or the honest reason
|
|
95
|
+
* there is none. Never a guess.
|
|
96
|
+
*/
|
|
97
|
+
export function resolveEngineBrowserInstall(cwd) {
|
|
98
|
+
// The repository first, then the RUNNING engine's own tree: a global
|
|
99
|
+
// or dev-linked CLI has no copy under the repository, and the pack it
|
|
100
|
+
// actually loaded is the one whose pin matters.
|
|
101
|
+
const manifest = findInstalledPackageManifest(resolve(cwd), ENGINE_PACKAGE) ??
|
|
102
|
+
findInstalledPackageManifest(dirname(fileURLToPath(import.meta.url)), ENGINE_PACKAGE);
|
|
103
|
+
if (manifest === null)
|
|
104
|
+
return { kind: 'not-installed' };
|
|
105
|
+
let packageRoot;
|
|
106
|
+
try {
|
|
107
|
+
packageRoot = realpathSync(dirname(manifest));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return { kind: 'not-installed' };
|
|
111
|
+
}
|
|
112
|
+
const pinned = findInstalledPackageManifest(packageRoot, 'playwright');
|
|
113
|
+
if (pinned === null)
|
|
114
|
+
return { kind: 'no-pinned-playwright', packageRoot, manifest };
|
|
115
|
+
// The pin is read from the manifest the engine actually resolves;
|
|
116
|
+
// `realpathSync` again so a linked Playwright is inspected where it
|
|
117
|
+
// lives, matching what `import { chromium } from 'playwright'` loads.
|
|
118
|
+
let playwrightManifest;
|
|
119
|
+
try {
|
|
120
|
+
playwrightManifest = realpathSync(pinned);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return { kind: 'no-pinned-playwright', packageRoot, manifest };
|
|
124
|
+
}
|
|
125
|
+
// A manifest the engine resolves but that states no readable version
|
|
126
|
+
// never invents a revision: the caller keeps its historical wording.
|
|
127
|
+
let version = null;
|
|
128
|
+
try {
|
|
129
|
+
const parsed = JSON.parse(readFileSync(playwrightManifest, 'utf8'));
|
|
130
|
+
if (typeof parsed.version === 'string')
|
|
131
|
+
version = parsed.version;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
version = null;
|
|
135
|
+
}
|
|
136
|
+
if (version === null)
|
|
137
|
+
return { kind: 'no-pinned-playwright', packageRoot, manifest };
|
|
138
|
+
const cli = join(dirname(playwrightManifest), 'cli.js');
|
|
139
|
+
return {
|
|
140
|
+
kind: 'resolved',
|
|
141
|
+
install: {
|
|
142
|
+
packageRoot,
|
|
143
|
+
manifest,
|
|
144
|
+
playwrightManifest,
|
|
145
|
+
playwrightVersion: version,
|
|
146
|
+
installCli: existsSync(cli) ? cli : null,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/** The engine-owned Chromium builds an inspected release pins. */
|
|
151
|
+
function engineRequiredBuilds(playwrightManifest) {
|
|
152
|
+
const registry = findBrowsersRegistry(playwrightManifest);
|
|
153
|
+
if (registry === null)
|
|
154
|
+
return [];
|
|
155
|
+
// The engine browser is always headless Chromium and never reads a
|
|
156
|
+
// consumer Playwright config, so the consumer's `browserName` /
|
|
157
|
+
// `headless: false` scan never applies here.
|
|
158
|
+
return requiredBuilds(readBrowserBuilds(registry), [...ENGINE_BROWSERS], true);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Inspects whether the engine-owned Chromium builds are installed in the
|
|
162
|
+
* cache and can start on this machine.
|
|
163
|
+
*
|
|
164
|
+
* Reads `PLAYWRIGHT_BROWSERS_PATH` when configured, otherwise the default
|
|
165
|
+
* browser cache. The supervised witness receives that variable explicitly.
|
|
166
|
+
*
|
|
167
|
+
* Args:
|
|
168
|
+
* install: the resolved engine install.
|
|
169
|
+
* env: operator environment (`PLAYWRIGHT_BROWSERS_PATH`).
|
|
170
|
+
*
|
|
171
|
+
* Returns:
|
|
172
|
+
* EngineBrowserReadiness: required, installed, missing and unlaunchable
|
|
173
|
+
* builds. An empty `required` means the pinned release ships no
|
|
174
|
+
* readable registry — the caller keeps its historical wording rather
|
|
175
|
+
* than inventing revisions.
|
|
176
|
+
*/
|
|
177
|
+
export function inspectEngineBrowserBuilds(install, env = process.env) {
|
|
178
|
+
const browsersPath = defaultBrowsersPath(env);
|
|
179
|
+
const required = engineRequiredBuilds(install.playwrightManifest);
|
|
180
|
+
const installed = [];
|
|
181
|
+
const missing = [];
|
|
182
|
+
for (const build of required) {
|
|
183
|
+
if (existsSync(join(browsersPath, browserDirectoryName(build))))
|
|
184
|
+
installed.push(build);
|
|
185
|
+
else
|
|
186
|
+
missing.push(build);
|
|
187
|
+
}
|
|
188
|
+
const readiness = {
|
|
189
|
+
registry: findBrowsersRegistry(install.playwrightManifest),
|
|
190
|
+
browsersPath,
|
|
191
|
+
required,
|
|
192
|
+
installed,
|
|
193
|
+
missing,
|
|
194
|
+
};
|
|
195
|
+
return {
|
|
196
|
+
install,
|
|
197
|
+
browsersPath,
|
|
198
|
+
required,
|
|
199
|
+
installed,
|
|
200
|
+
missing,
|
|
201
|
+
unlaunchable: unlaunchableBuilds(readiness),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The install command for the engine's OWN pinned release, by absolute
|
|
206
|
+
* path.
|
|
207
|
+
*
|
|
208
|
+
* `npx playwright install chromium` is wrong here and the operator must
|
|
209
|
+
* not be told it: `npx` resolves the Playwright the command's directory
|
|
210
|
+
* reaches — the CONSUMER's release — so it installs the revision the
|
|
211
|
+
* cache already holds and the engine browser stays exactly as broken.
|
|
212
|
+
* Naming the engine's own resolved `cli.js` installs the release the
|
|
213
|
+
* engine actually launches.
|
|
214
|
+
*
|
|
215
|
+
* Two variables ride along, and both are load-bearing:
|
|
216
|
+
*
|
|
217
|
+
* - `PLAYWRIGHT_BROWSERS_PATH` writes into the cache this inspection
|
|
218
|
+
* actually read, so the operator never ends up with the build in one
|
|
219
|
+
* directory and the run looking in another.
|
|
220
|
+
* - `PLAYWRIGHT_SKIP_BROWSER_GC=1` is not optional. Playwright's
|
|
221
|
+
* installer garbage-collects every build its OWN registry does not
|
|
222
|
+
* list, so without it the engine's `install` DELETES the consumer's
|
|
223
|
+
* Chromium 1234 out of the shared default cache and the remedy trades
|
|
224
|
+
* one broken run for another. This was observed, not assumed: running
|
|
225
|
+
* the command without the guard printed
|
|
226
|
+
* `Removing unused browser at <cache>/chromium-1234` and left the
|
|
227
|
+
* consumer's `runner` line failing.
|
|
228
|
+
*
|
|
229
|
+
* Args:
|
|
230
|
+
* install: the resolved engine install.
|
|
231
|
+
* arguments: the install arguments (browser names).
|
|
232
|
+
* browsersPath: the cache the install must write into.
|
|
233
|
+
*
|
|
234
|
+
* Returns:
|
|
235
|
+
* string: the exact command, or '' when the pinned release ships no
|
|
236
|
+
* install CLI to name.
|
|
237
|
+
*/
|
|
238
|
+
export function engineInstallCommand(install, arguments_, browsersPath) {
|
|
239
|
+
if (install.installCli === null)
|
|
240
|
+
return '';
|
|
241
|
+
return (`PLAYWRIGHT_BROWSERS_PATH='${browsersPath}' PLAYWRIGHT_SKIP_BROWSER_GC=1 ` +
|
|
242
|
+
`node '${install.installCli}' install ${arguments_}`);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The `install-deps` command for the engine's own release: the system
|
|
246
|
+
* libraries a bare Linux image lacks.
|
|
247
|
+
*
|
|
248
|
+
* Args:
|
|
249
|
+
* install: the resolved engine install.
|
|
250
|
+
* arguments: the install arguments (browser names).
|
|
251
|
+
*
|
|
252
|
+
* Returns:
|
|
253
|
+
* string: the exact command, or '' when the pinned release ships no
|
|
254
|
+
* install CLI to name.
|
|
255
|
+
*/
|
|
256
|
+
export function engineInstallDepsCommand(install, arguments_) {
|
|
257
|
+
if (install.installCli === null)
|
|
258
|
+
return '';
|
|
259
|
+
return `node '${install.installCli}' install-deps ${arguments_}`;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* The one-line summary for an engine-owned browser that is missing or
|
|
263
|
+
* cannot start, naming the EXACT engine install command.
|
|
264
|
+
*
|
|
265
|
+
* It is deliberately explicit about whose browser it is: the sentence
|
|
266
|
+
* leads with the engine's pinned release, because the consumer's runner
|
|
267
|
+
* line already reported its own builds as installed and the operator
|
|
268
|
+
* would otherwise conclude nothing is wrong.
|
|
269
|
+
*
|
|
270
|
+
* Args:
|
|
271
|
+
* readiness: the engine-owned inspection result.
|
|
272
|
+
*
|
|
273
|
+
* Returns:
|
|
274
|
+
* string: the sentence for the readiness line; '' when nothing was
|
|
275
|
+
* observed, or when the pinned release ships no readable registry.
|
|
276
|
+
*/
|
|
277
|
+
export function engineBrowserSummary(readiness) {
|
|
278
|
+
const install = readiness.install;
|
|
279
|
+
if (install === null)
|
|
280
|
+
return '';
|
|
281
|
+
const who = `the engine-owned browser (playwright ${install.playwrightVersion} pinned by ${ENGINE_PACKAGE})`;
|
|
282
|
+
if (readiness.missing.length > 0) {
|
|
283
|
+
const missing = readiness.missing.map((build) => browserDirectoryName(build)).join(', ');
|
|
284
|
+
const command = engineInstallCommand(install, installArguments(readiness.missing), readiness.browsersPath);
|
|
285
|
+
const remedy = command === ''
|
|
286
|
+
? `install the ${missing} build(s) of playwright ${install.playwrightVersion} into '${readiness.browsersPath}'`
|
|
287
|
+
: `fix: run \`${command}\``;
|
|
288
|
+
return (`${who} is NOT ready: its pinned builds ${missing} are missing from '${readiness.browsersPath}' — ` +
|
|
289
|
+
`your test runner's own Chromium is a different Playwright release and cannot serve it, so every engine-browser ` +
|
|
290
|
+
`case fails with "Executable doesn't exist"; ${remedy}`);
|
|
291
|
+
}
|
|
292
|
+
const launch = readiness.unlaunchable[0];
|
|
293
|
+
if (launch !== undefined) {
|
|
294
|
+
const command = engineInstallDepsCommand(install, installArguments([launch.build]));
|
|
295
|
+
const reason = launch.reason === '' ? '' : `: ${launch.reason}`;
|
|
296
|
+
const remedy = command === '' ? '' : `; fix: run \`${command}\` (needs root or sudo)`;
|
|
297
|
+
return (`${who} is NOT ready: '${launch.directory}' is installed but cannot start on this machine${reason}${remedy}`);
|
|
298
|
+
}
|
|
299
|
+
if (readiness.required.length === 0) {
|
|
300
|
+
return `${who} ships no readable browser registry (nothing to install)`;
|
|
301
|
+
}
|
|
302
|
+
return (`${who} is ready: ${readiness.required.map((build) => browserDirectoryName(build)).join(', ')} ` +
|
|
303
|
+
`installed under '${readiness.browsersPath}'`);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Whether the repository requires ENGINE-controlled browser evidence.
|
|
307
|
+
*
|
|
308
|
+
* Two producers exist, and both are explicit — never inferred from
|
|
309
|
+
* "this project has a browser somewhere":
|
|
310
|
+
*
|
|
311
|
+
* - the CONFIGURED RUNNER is `playwright`. Its evidence primitives
|
|
312
|
+
* (`evidence.ui.action`, `evidence.visible.confirm`,
|
|
313
|
+
* `evidence.persistence.verify`) are Playwright-only — they take the
|
|
314
|
+
* suite's own `Page` — and the witness serves every one of them by
|
|
315
|
+
* driving the ENGINE's Chromium through `EngineBrowserManager`. That
|
|
316
|
+
* is the real consumer this check exists for: a witnessed Playwright
|
|
317
|
+
* suite with no behavior policy at all still opens the engine browser
|
|
318
|
+
* the moment it confirms a receipt.
|
|
319
|
+
* - the behavior policy declares a case on the `engine-browser` channel.
|
|
320
|
+
* That channel is runner-neutral, so a pytest / vitest / cypress
|
|
321
|
+
* repository with a surface case needs the engine browser too.
|
|
322
|
+
*
|
|
323
|
+
* Everything else needs nothing: a pytest or API-only repository, a
|
|
324
|
+
* non-playwright repository whose policy drives only `engine-http` /
|
|
325
|
+
* `engine-task`, and a repository with no policy at all are reported as
|
|
326
|
+
* not requiring it. None of them is ever told to install a Chromium it
|
|
327
|
+
* will never launch.
|
|
328
|
+
*
|
|
329
|
+
* A policy that cannot be read or parsed never manufactures a
|
|
330
|
+
* requirement on its own: the `behavior-profile` doctor line already
|
|
331
|
+
* fails such a document closed.
|
|
332
|
+
*
|
|
333
|
+
* Args:
|
|
334
|
+
* cwd: repository root.
|
|
335
|
+
* runner: the configured runner (`playwright`, `pytest`, …).
|
|
336
|
+
* behaviorPolicy: the configured policy path (undefined when unset).
|
|
337
|
+
*
|
|
338
|
+
* Returns:
|
|
339
|
+
* {required, reason}: whether engine-controlled browser evidence is
|
|
340
|
+
* required, and the honest sentence either way.
|
|
341
|
+
*/
|
|
342
|
+
export function engineBrowserRequirement(cwd, runner, behaviorPolicy) {
|
|
343
|
+
const playwrightReason = `the configured runner 'playwright' serves every ui.action / visible.confirm / persistence.verify ` +
|
|
344
|
+
"receipt through the engine's own browser";
|
|
345
|
+
if (behaviorPolicy !== undefined) {
|
|
346
|
+
try {
|
|
347
|
+
const document = BehaviorPolicySchema.safeParse(JSON.parse(JSON.stringify(parseYaml(readFileSync(resolve(cwd, behaviorPolicy), 'utf8')))));
|
|
348
|
+
if (document.success) {
|
|
349
|
+
const cases = [
|
|
350
|
+
...document.data.endpoints.flatMap((endpoint) => endpoint.cases),
|
|
351
|
+
...document.data.resources.flatMap((resource) => resource.cases),
|
|
352
|
+
];
|
|
353
|
+
const declaring = cases.filter((entry) => entry.channel === ENGINE_BROWSER_CHANNEL).length;
|
|
354
|
+
if (declaring > 0) {
|
|
355
|
+
return {
|
|
356
|
+
required: true,
|
|
357
|
+
reason: `${String(declaring)} declared behavior case(s) drive the 'engine-browser' channel`,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
required: runner === 'playwright',
|
|
362
|
+
reason: runner === 'playwright'
|
|
363
|
+
? playwrightReason
|
|
364
|
+
: `no declared behavior case drives the 'engine-browser' channel (${String(cases.length)} case(s) declared) and the configured runner '${runner}' proves its cases without an engine browser`,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
// Unreadable YAML: fall through to the runner-based answer, which
|
|
370
|
+
// needs no document at all. The behavior-profile check owns that
|
|
371
|
+
// document's own failure.
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return runner === 'playwright'
|
|
375
|
+
? { required: true, reason: playwrightReason }
|
|
376
|
+
: {
|
|
377
|
+
required: false,
|
|
378
|
+
reason: `the configured runner '${runner}' proves its cases without an engine browser, and no declared case drives the 'engine-browser' channel`,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
//# sourceMappingURL=engine-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-browser.js","sourceRoot":"","sources":["../src/engine-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,kBAAkB,GAInB,MAAM,0BAA0B,CAAC;AAElC,+EAA+E;AAC/E,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AAEhD,4EAA4E;AAC5E,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD,4EAA4E;AAC5E,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B;;;;GAIG;AACH,MAAM,eAAe,GAAG,CAAC,UAAU,CAAU,CAAC;AAsB9C;;;GAGG;AACH,SAAS,4BAA4B,CAAC,KAAa,EAAE,IAAY;IAC/D,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,gBAAgB,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACzD,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QACrE,IAAI,UAAU,CAAC,SAAS,CAAC;YA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,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;iBACjE,CAAC;gBACF,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,KAAK,sBAAsB,CAAC,CAAC,MAAM,CAAC;gBAC3F,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;oBAClB,OAAO;wBACL,QAAQ,EAAE,IAAI;wBACd,MAAM,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,+DAA+D;qBAC5F,CAAC;gBACJ,CAAC;gBACD,OAAO;oBACL,QAAQ,EAAE,MAAM,KAAK,YAAY;oBACjC,MAAM,EACJ,MAAM,KAAK,YAAY;wBACrB,CAAC,CAAC,gBAAgB;wBAClB,CAAC,CAAC,kEAAkE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,iDAAiD,MAAM,8CAA8C;iBAClM,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,kEAAkE;YAClE,iEAAiE;YACjE,0BAA0B;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,MAAM,KAAK,YAAY;QAC5B,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE;QAC9C,CAAC,CAAC;YACE,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE,0BAA0B,MAAM,wGAAwG;SACjJ,CAAC;AACR,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** Public identity of the engine installation that produced a report. */
|
|
2
|
+
export interface EngineIdentity {
|
|
3
|
+
/** Package version. */
|
|
4
|
+
version: string;
|
|
5
|
+
/** Registry package or the local package path. */
|
|
6
|
+
source: string;
|
|
7
|
+
/** True when CI will not install the local workspace code automatically. */
|
|
8
|
+
unpublished: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* How the installed engine reached `node_modules`, as far as npm's own
|
|
12
|
+
* install metadata can prove it.
|
|
13
|
+
*
|
|
14
|
+
* - `registry`: the hidden lockfile resolves the package to a registry URL.
|
|
15
|
+
* - `file`: a tarball/directory (`file:`) specifier — an install npm
|
|
16
|
+
* performed from bytes on disk, which a CI `npm install
|
|
17
|
+
* @gate-forge/cli@<version>` would NOT reproduce.
|
|
18
|
+
* - `local-path`: a checkout used directly (no `node_modules` install).
|
|
19
|
+
* - `unknown`: installed, but no install metadata is readable (a package
|
|
20
|
+
* manager that writes no hidden lockfile, a pruned install).
|
|
21
|
+
*/
|
|
22
|
+
export type EngineInstallKind = 'registry' | 'file' | 'local-path' | 'unknown';
|
|
23
|
+
/** Provenance of the installed engine, with the specifier that proves it. */
|
|
24
|
+
export interface EngineInstallProvenance {
|
|
25
|
+
kind: EngineInstallKind;
|
|
26
|
+
specifier: string | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Reads npm's install metadata for the installed engine package.
|
|
30
|
+
*
|
|
31
|
+
* Two sources, in npm's own order of reliability: the hidden
|
|
32
|
+
* `node_modules/.package-lock.json` of the OWNING `node_modules`
|
|
33
|
+
* directory (the one whose key path is this package), then the legacy
|
|
34
|
+
* `_resolved`/`_from` keys npm writes into the installed manifest. No
|
|
35
|
+
* metadata means `unknown`, never an assumed registry.
|
|
36
|
+
*
|
|
37
|
+
* Args:
|
|
38
|
+
* packageRoot: absolute path of the installed `@gate-forge/cli`.
|
|
39
|
+
*
|
|
40
|
+
* Returns:
|
|
41
|
+
* EngineInstallProvenance: the install kind and the proving specifier.
|
|
42
|
+
*/
|
|
43
|
+
export declare function engineInstallProvenance(packageRoot: string | null): EngineInstallProvenance;
|
|
44
|
+
/**
|
|
45
|
+
* Formats the doctor's one engine line, adding ONLY what the install
|
|
46
|
+
* metadata can prove. The receipt's `engine.source` is receipt-bound
|
|
47
|
+
* (a receipt is only valid for the engine that sealed it), so its
|
|
48
|
+
* meaning is unchanged; this is the human-readable line.
|
|
49
|
+
*
|
|
50
|
+
* Args:
|
|
51
|
+
* identity: the receipt-bound engine identity.
|
|
52
|
+
* provenance: the install provenance read from npm's metadata.
|
|
53
|
+
*
|
|
54
|
+
* Returns:
|
|
55
|
+
* string: the printed line.
|
|
56
|
+
*/
|
|
57
|
+
export declare function engineSourceLine(identity: EngineIdentity, provenance: EngineInstallProvenance): string;
|
|
58
|
+
/**
|
|
59
|
+
* Locates the installed engine's package root by walking up from this
|
|
60
|
+
* module to the nearest `@gate-forge/cli` manifest.
|
|
61
|
+
*
|
|
62
|
+
* Args:
|
|
63
|
+
* none.
|
|
64
|
+
*
|
|
65
|
+
* Returns:
|
|
66
|
+
* string | null: the resolved package root, or null when no manifest
|
|
67
|
+
* identifies it.
|
|
68
|
+
*/
|
|
69
|
+
export declare function enginePackageRoot(): string | null;
|
|
70
|
+
/**
|
|
71
|
+
* Identifies the installed engine without executing package code from the project.
|
|
72
|
+
*
|
|
73
|
+
* `source` is receipt-bound (a receipt is only valid for the engine
|
|
74
|
+
* that sealed it) and keeps its exact meaning: a `node_modules`
|
|
75
|
+
* install reads `registry` whether npm fetched it from the registry or
|
|
76
|
+
* unpacked a tarball. The install provenance npm's metadata can prove
|
|
77
|
+
* is reported separately by {@link engineInstallProvenance} and
|
|
78
|
+
* {@link engineSourceLine}.
|
|
79
|
+
*
|
|
80
|
+
* Args:
|
|
81
|
+
* none.
|
|
82
|
+
*
|
|
83
|
+
* Returns:
|
|
84
|
+
* EngineIdentity: version, source, and whether the engine is unpublished.
|
|
85
|
+
*/
|
|
86
|
+
export declare function engineIdentity(): EngineIdentity;
|
|
87
|
+
/**
|
|
88
|
+
* The engine line a human-readable REPORT prints: the same provenance
|
|
89
|
+
* the enforcement doctor's engine line uses, so one install never
|
|
90
|
+
* produces two contradictory claims. The receipt-bound
|
|
91
|
+
* `engine.source` keeps its exact meaning and is untouched.
|
|
92
|
+
*
|
|
93
|
+
* Args:
|
|
94
|
+
* none.
|
|
95
|
+
*
|
|
96
|
+
* Returns:
|
|
97
|
+
* string: the printed line.
|
|
98
|
+
*/
|
|
99
|
+
export declare function reportEngineLine(): string;
|
|
100
|
+
//# sourceMappingURL=engine-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-identity.d.ts","sourceRoot":"","sources":["../src/engine-identity.ts"],"names":[],"mappings":"AAKA,yEAAyE;AACzE,MAAM,WAAW,cAAc;IAC7B,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,MAAM,GAAG,YAAY,GAAG,SAAS,CAAC;AAE/E,6EAA6E;AAC7E,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,iBAAiB,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAsBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,uBAAuB,CA0C3F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,uBAAuB,GAAG,MAAM,CAoBtG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,IAAI,CAkBjD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,IAAI,cAAc,CAU/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { VERSION } from './commands/common.js';
|
|
5
|
+
/**
|
|
6
|
+
* Classifies one npm `resolved` specifier: a registry URL is the
|
|
7
|
+
* registry, everything else that names a local artifact is a file
|
|
8
|
+
* install.
|
|
9
|
+
*
|
|
10
|
+
* Args:
|
|
11
|
+
* resolved: the `resolved` string from the install metadata.
|
|
12
|
+
*
|
|
13
|
+
* Returns:
|
|
14
|
+
* EngineInstallKind: `registry` or `file`.
|
|
15
|
+
*/
|
|
16
|
+
function kindOfResolved(resolved) {
|
|
17
|
+
return /^https?:\/\/registry\./.test(resolved) ? 'registry' : 'file';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Reads npm's install metadata for the installed engine package.
|
|
21
|
+
*
|
|
22
|
+
* Two sources, in npm's own order of reliability: the hidden
|
|
23
|
+
* `node_modules/.package-lock.json` of the OWNING `node_modules`
|
|
24
|
+
* directory (the one whose key path is this package), then the legacy
|
|
25
|
+
* `_resolved`/`_from` keys npm writes into the installed manifest. No
|
|
26
|
+
* metadata means `unknown`, never an assumed registry.
|
|
27
|
+
*
|
|
28
|
+
* Args:
|
|
29
|
+
* packageRoot: absolute path of the installed `@gate-forge/cli`.
|
|
30
|
+
*
|
|
31
|
+
* Returns:
|
|
32
|
+
* EngineInstallProvenance: the install kind and the proving specifier.
|
|
33
|
+
*/
|
|
34
|
+
export function engineInstallProvenance(packageRoot) {
|
|
35
|
+
if (packageRoot === null || !packageRoot.split('\\').join('/').includes('/node_modules/')) {
|
|
36
|
+
return { kind: 'local-path', specifier: null };
|
|
37
|
+
}
|
|
38
|
+
// The hidden lockfile lives in the `node_modules` that OWNS the
|
|
39
|
+
// package: `<...>/node_modules/@gate-forge/cli` is described by
|
|
40
|
+
// `<...>/node_modules/.package-lock.json`. Walk up through nested
|
|
41
|
+
// installs and read the first lockfile that describes this package.
|
|
42
|
+
const normalized = packageRoot.split('\\').join('/');
|
|
43
|
+
const packageKey = normalized.slice(normalized.lastIndexOf('node_modules/') + 'node_modules/'.length);
|
|
44
|
+
for (let current = dirname(packageRoot);; current = dirname(current)) {
|
|
45
|
+
if (basename(current) === 'node_modules') {
|
|
46
|
+
const lock = join(current, '.package-lock.json');
|
|
47
|
+
if (existsSync(lock)) {
|
|
48
|
+
try {
|
|
49
|
+
const parsed = JSON.parse(readFileSync(lock, 'utf8'));
|
|
50
|
+
const packages = parsed.packages ?? {};
|
|
51
|
+
const entry = packages[packageKey] ?? Object.entries(packages).find(([key]) => key.endsWith(packageKey))?.[1];
|
|
52
|
+
if (typeof entry?.resolved === 'string' && entry.resolved !== '') {
|
|
53
|
+
return { kind: kindOfResolved(entry.resolved), specifier: entry.resolved };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Unreadable or foreign lockfile: fall through to the manifest.
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const parent = dirname(current);
|
|
62
|
+
if (parent === current)
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const manifest = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8'));
|
|
67
|
+
const declared = typeof manifest._resolved === 'string' ? manifest._resolved : manifest._from;
|
|
68
|
+
if (typeof declared === 'string' && declared !== '') {
|
|
69
|
+
return { kind: kindOfResolved(declared), specifier: declared };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// No readable manifest metadata: provenance stays unproven.
|
|
74
|
+
}
|
|
75
|
+
return { kind: 'unknown', specifier: null };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Formats the doctor's one engine line, adding ONLY what the install
|
|
79
|
+
* metadata can prove. The receipt's `engine.source` is receipt-bound
|
|
80
|
+
* (a receipt is only valid for the engine that sealed it), so its
|
|
81
|
+
* meaning is unchanged; this is the human-readable line.
|
|
82
|
+
*
|
|
83
|
+
* Args:
|
|
84
|
+
* identity: the receipt-bound engine identity.
|
|
85
|
+
* provenance: the install provenance read from npm's metadata.
|
|
86
|
+
*
|
|
87
|
+
* Returns:
|
|
88
|
+
* string: the printed line.
|
|
89
|
+
*/
|
|
90
|
+
export function engineSourceLine(identity, provenance) {
|
|
91
|
+
// A `node_modules` install is the only case where the receipt-bound
|
|
92
|
+
// `source` says less than the truth: npm unpacks a tarball exactly
|
|
93
|
+
// where it unpacks a registry release, so the line names the
|
|
94
|
+
// directory and lets the install metadata supply the provenance.
|
|
95
|
+
const base = provenance.kind === 'file' || (provenance.kind === 'unknown' && identity.source === 'registry')
|
|
96
|
+
? `engine: ${identity.version} from node_modules`
|
|
97
|
+
: `engine: ${identity.version} from ${identity.source}`;
|
|
98
|
+
if (provenance.kind === 'file') {
|
|
99
|
+
return (`${base} (tarball or directory install: ${provenance.specifier ?? 'file source'} — not the ` +
|
|
100
|
+
`published registry release, so CI installing @gate-forge/cli@${identity.version} would NOT run ` +
|
|
101
|
+
'this code)');
|
|
102
|
+
}
|
|
103
|
+
if (provenance.kind === 'unknown') {
|
|
104
|
+
return `${base} (registry or tarball install — no install metadata found, so the provenance is unproven)`;
|
|
105
|
+
}
|
|
106
|
+
return base;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Locates the installed engine's package root by walking up from this
|
|
110
|
+
* module to the nearest `@gate-forge/cli` manifest.
|
|
111
|
+
*
|
|
112
|
+
* Args:
|
|
113
|
+
* none.
|
|
114
|
+
*
|
|
115
|
+
* Returns:
|
|
116
|
+
* string | null: the resolved package root, or null when no manifest
|
|
117
|
+
* identifies it.
|
|
118
|
+
*/
|
|
119
|
+
export function enginePackageRoot() {
|
|
120
|
+
let current = dirname(fileURLToPath(import.meta.url));
|
|
121
|
+
while (true) {
|
|
122
|
+
const manifest = join(current, 'package.json');
|
|
123
|
+
if (existsSync(manifest)) {
|
|
124
|
+
try {
|
|
125
|
+
const value = JSON.parse(readFileSync(manifest, 'utf8'));
|
|
126
|
+
if (value.name === '@gate-forge/cli') {
|
|
127
|
+
return realpathSync(current);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// Continue upward; a malformed unrelated manifest is not this package's identity.
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const parent = dirname(current);
|
|
135
|
+
if (parent === current)
|
|
136
|
+
return null;
|
|
137
|
+
current = parent;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Identifies the installed engine without executing package code from the project.
|
|
142
|
+
*
|
|
143
|
+
* `source` is receipt-bound (a receipt is only valid for the engine
|
|
144
|
+
* that sealed it) and keeps its exact meaning: a `node_modules`
|
|
145
|
+
* install reads `registry` whether npm fetched it from the registry or
|
|
146
|
+
* unpacked a tarball. The install provenance npm's metadata can prove
|
|
147
|
+
* is reported separately by {@link engineInstallProvenance} and
|
|
148
|
+
* {@link engineSourceLine}.
|
|
149
|
+
*
|
|
150
|
+
* Args:
|
|
151
|
+
* none.
|
|
152
|
+
*
|
|
153
|
+
* Returns:
|
|
154
|
+
* EngineIdentity: version, source, and whether the engine is unpublished.
|
|
155
|
+
*/
|
|
156
|
+
export function engineIdentity() {
|
|
157
|
+
const packageRoot = enginePackageRoot();
|
|
158
|
+
if (packageRoot === null) {
|
|
159
|
+
return { version: VERSION, source: 'registry', unpublished: false };
|
|
160
|
+
}
|
|
161
|
+
const normalized = packageRoot.split('\\').join('/');
|
|
162
|
+
const fromRegistry = normalized.includes('/node_modules/');
|
|
163
|
+
return fromRegistry
|
|
164
|
+
? { version: VERSION, source: 'registry', unpublished: false }
|
|
165
|
+
: { version: VERSION, source: `local path ${packageRoot}`, unpublished: true };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The engine line a human-readable REPORT prints: the same provenance
|
|
169
|
+
* the enforcement doctor's engine line uses, so one install never
|
|
170
|
+
* produces two contradictory claims. The receipt-bound
|
|
171
|
+
* `engine.source` keeps its exact meaning and is untouched.
|
|
172
|
+
*
|
|
173
|
+
* Args:
|
|
174
|
+
* none.
|
|
175
|
+
*
|
|
176
|
+
* Returns:
|
|
177
|
+
* string: the printed line.
|
|
178
|
+
*/
|
|
179
|
+
export function reportEngineLine() {
|
|
180
|
+
return engineSourceLine(engineIdentity(), engineInstallProvenance(enginePackageRoot()));
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=engine-identity.js.map
|