browser-commander 0.16.1 → 0.17.1
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/.changeset/config.json +2 -1
- package/.jscpd-baseline.json +263 -0
- package/.jscpd.json +1 -3
- package/.prettierignore +1 -0
- package/CHANGELOG.md +19 -0
- package/eslint.config.js +23 -1
- package/package.json +13 -24
- package/scripts/changeset-version.mjs +2 -6
- package/scripts/check-release-format.mjs +80 -0
- package/scripts/create-github-release.mjs +33 -13
- package/scripts/create-manual-changeset.mjs +7 -8
- package/scripts/format-github-release.mjs +6 -7
- package/scripts/format-release-notes.mjs +7 -8
- package/scripts/instant-version-bump.mjs +7 -8
- package/scripts/publish-to-npm.mjs +7 -8
- package/scripts/setup-npm.mjs +2 -6
- package/scripts/version-and-commit.mjs +18 -7
- package/src/browser/browser-cookie-credentials.js +3 -1
- package/src/browser/browser-cookies.js +6 -2
- package/src/browser/browser-profiles.js +1 -1
- package/src/browser/launch-options.js +31 -8
- package/src/browser/launcher.js +16 -0
- package/src/exports.js +34 -0
- package/src/fingerprint/apply.js +116 -0
- package/src/fingerprint/automation-parity.js +224 -0
- package/src/fingerprint/cdp-overrides.js +176 -0
- package/src/fingerprint/derive.js +104 -0
- package/src/fingerprint/init-payload.js +181 -0
- package/src/fingerprint/init-script.js +104 -0
- package/src/fingerprint/limitations.js +107 -0
- package/src/fingerprint/limitations.json +96 -0
- package/src/fingerprint/presets.js +244 -0
- package/src/fingerprint/profile.js +428 -0
- package/src/tests/index.js +2 -1
- package/tests/e2e/fingerprint-parity.e2e.test.js +212 -0
- package/tests/helpers/mocks.js +4 -2
- package/tests/helpers/repo.js +74 -0
- package/tests/unit/browser/launch-options.test.js +9 -1
- package/tests/unit/experiments/fingerprint-parity-harness.test.js +97 -0
- package/tests/unit/fingerprint/apply.test.js +271 -0
- package/tests/unit/fingerprint/automation-parity.test.js +212 -0
- package/tests/unit/fingerprint/cdp-overrides.test.js +227 -0
- package/tests/unit/fingerprint/derive.test.js +105 -0
- package/tests/unit/fingerprint/init-script.test.js +357 -0
- package/tests/unit/fingerprint/limitations.test.js +184 -0
- package/tests/unit/fingerprint/presets.test.js +135 -0
- package/tests/unit/fingerprint/profile.test.js +282 -0
- package/tests/unit/scripts/cargo-lock-sync.test.js +110 -0
- package/tests/unit/scripts/changelog-collection-order.test.js +144 -0
- package/tests/unit/scripts/changeset-formatter.test.js +108 -0
- package/tests/unit/scripts/check-pipeline-status.test.js +133 -0
- package/tests/unit/scripts/check-release-format.test.js +131 -0
- package/tests/unit/scripts/check-web-archive.test.js +191 -0
- package/tests/unit/scripts/ci-timeout-budgets.test.js +311 -0
- package/tests/unit/scripts/ci-workflow-policy.test.js +292 -153
- package/tests/unit/scripts/command-error-text.test.js +83 -0
- package/tests/unit/scripts/command-stream-errexit.test.js +132 -0
- package/tests/unit/scripts/debug-print.test.js +67 -0
- package/tests/unit/scripts/jscpd-config.test.js +141 -0
- package/tests/unit/scripts/pre-commit-config.test.js +214 -0
- package/tests/unit/scripts/read-manifest.test.js +194 -0
- package/tests/unit/scripts/release-tags.test.js +96 -0
- package/tests/unit/scripts/required-docs.test.js +145 -0
- package/tests/unit/scripts/run-with-budget-warning.test.js +115 -0
- package/tests/unit/scripts/rust-changelog.test.js +147 -0
- package/tests/unit/scripts/use-module-adoption.test.js +74 -0
- package/tests/unit/scripts/use-module-integration.test.js +64 -0
- package/tests/unit/scripts/use-module.test.js +182 -0
- package/.husky/pre-commit +0 -1
- package/.prettierrc +0 -10
- package/deno.json +0 -7
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guard for the failure mode that made three release defects invisible.
|
|
3
|
+
*
|
|
4
|
+
* `command-stream` resolves its `$` promise on a non-zero exit code instead of
|
|
5
|
+
* rejecting, so the idiom every release script in this repository is written
|
|
6
|
+
* around —
|
|
7
|
+
*
|
|
8
|
+
* try { await $`some-command`; } catch { process.exit(1); }
|
|
9
|
+
*
|
|
10
|
+
* — is dead code under the library's defaults. On 2026-09-05 that turned a
|
|
11
|
+
* crashed `changeset version` into a green JS release (run 33974450016) and a
|
|
12
|
+
* Rust release that never committed its version bump into a green Rust release
|
|
13
|
+
* (run 33974450069). See dev/log/issues/83/pulls/84/analysis/root-causes.md,
|
|
14
|
+
* RC-B and RC-C.
|
|
15
|
+
*
|
|
16
|
+
* `loadCommandStream()` is the single place every consumer obtains `$` from, so
|
|
17
|
+
* it is the single place the default can be corrected. These tests pin that:
|
|
18
|
+
* a non-zero exit must reject, and the rejection must carry the exit code so a
|
|
19
|
+
* caller can still branch on it.
|
|
20
|
+
*
|
|
21
|
+
* The tests need network access, because use-m is fetched from a CDN. When it
|
|
22
|
+
* is unreachable they skip, matching use-module-integration.test.js.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import assert from 'node:assert/strict';
|
|
26
|
+
import { describe, it } from 'node:test';
|
|
27
|
+
|
|
28
|
+
import {
|
|
29
|
+
loadCommandStream,
|
|
30
|
+
USE_M_URL,
|
|
31
|
+
} from '../../../../scripts/use-module.mjs';
|
|
32
|
+
|
|
33
|
+
async function hasNetwork() {
|
|
34
|
+
try {
|
|
35
|
+
return (await fetch(USE_M_URL, { method: 'HEAD' })).ok;
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Load command-stream, or a reason to skip.
|
|
43
|
+
* @param {import('node:test').TestContext} t
|
|
44
|
+
* @returns {Promise<Record<string, any> | null>}
|
|
45
|
+
*/
|
|
46
|
+
async function load(t) {
|
|
47
|
+
if (process.platform === 'win32') {
|
|
48
|
+
// Same upstream limitation use-module-integration.test.js documents:
|
|
49
|
+
// use-m imports the resolved file by absolute path, which the Windows ESM
|
|
50
|
+
// loader rejects. The Linux and macOS runs cover this.
|
|
51
|
+
t.skip('use-m cannot import absolute paths on Windows');
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
if (!(await hasNetwork())) {
|
|
55
|
+
t.skip(`${USE_M_URL} is unreachable, so use-m cannot be evaluated`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
return await loadCommandStream();
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (
|
|
62
|
+
/fetch|network|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|registry/i.test(
|
|
63
|
+
error.message
|
|
64
|
+
)
|
|
65
|
+
) {
|
|
66
|
+
t.skip(error.message);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe('loadCommandStream makes a failed command fail', () => {
|
|
74
|
+
it('turns errexit on, so the release scripts catch what they try to catch', async (t) => {
|
|
75
|
+
const cs = await load(t);
|
|
76
|
+
if (!cs) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
assert.equal(
|
|
81
|
+
cs.shell.settings().errexit,
|
|
82
|
+
true,
|
|
83
|
+
'errexit must be enabled by loadCommandStream; with the library default ' +
|
|
84
|
+
'of false, every try/catch around $ in the release scripts is unreachable'
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('rejects on a non-zero exit and reports the exit code', async (t) => {
|
|
89
|
+
const cs = await load(t);
|
|
90
|
+
if (!cs) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const { $ } = cs;
|
|
94
|
+
|
|
95
|
+
await assert.rejects(
|
|
96
|
+
() => $`exit 7`,
|
|
97
|
+
(error) => {
|
|
98
|
+
assert.equal(error.code, 7, 'the exit code must survive on the error');
|
|
99
|
+
return true;
|
|
100
|
+
},
|
|
101
|
+
'a command exiting 7 must reject, not resolve'
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('still resolves with stdout on success', async (t) => {
|
|
106
|
+
const cs = await load(t);
|
|
107
|
+
if (!cs) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const { $ } = cs;
|
|
111
|
+
|
|
112
|
+
// errexit must not turn every command into a throw: the success path is
|
|
113
|
+
// what the release scripts read version numbers and git status out of.
|
|
114
|
+
const result = await $`echo errexit-ok`;
|
|
115
|
+
assert.match(String(result.stdout), /errexit-ok/);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('reports a non-zero exit for the exact command that broke the Rust release', async (t) => {
|
|
119
|
+
const cs = await load(t);
|
|
120
|
+
if (!cs) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const { $ } = cs;
|
|
124
|
+
|
|
125
|
+
// `git diff --cached --quiet` exits 1 when there ARE staged changes.
|
|
126
|
+
// rust/scripts/version-and-commit.mjs relied on that becoming a rejection
|
|
127
|
+
// and, because it did not, reported "No changes to commit" after staging
|
|
128
|
+
// two modified files. `false` stands in for it here so the test needs no
|
|
129
|
+
// git fixture; the contract under test is identical.
|
|
130
|
+
await assert.rejects(() => $`false`, 'a command exiting 1 must reject');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { describe, it } from 'node:test';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
debugWith,
|
|
6
|
+
formatDebugLines,
|
|
7
|
+
isDebugEnabled,
|
|
8
|
+
readEnvVar,
|
|
9
|
+
} from '../../../../scripts/debug-print.mjs';
|
|
10
|
+
|
|
11
|
+
describe('debug-print', () => {
|
|
12
|
+
it('stays off by default so release logs are not noisy', () => {
|
|
13
|
+
assert.equal(isDebugEnabled({}), false);
|
|
14
|
+
assert.equal(isDebugEnabled({ CI_SCRIPTS_DEBUG: '0' }), false);
|
|
15
|
+
assert.equal(isDebugEnabled({ CI_SCRIPTS_DEBUG: '' }), false);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('turns on through the local toggle or either Actions debug switch', () => {
|
|
19
|
+
assert.equal(isDebugEnabled({ CI_SCRIPTS_DEBUG: '1' }), true);
|
|
20
|
+
assert.equal(isDebugEnabled({ CI_SCRIPTS_DEBUG: 'true' }), true);
|
|
21
|
+
assert.equal(isDebugEnabled({ RUNNER_DEBUG: '1' }), true);
|
|
22
|
+
assert.equal(isDebugEnabled({ ACTIONS_STEP_DEBUG: 'true' }), true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('prefixes every line so Actions renders it in the debug stream', () => {
|
|
26
|
+
assert.deepEqual(formatDebugLines(['a\nb']), ['::debug::a', '::debug::b']);
|
|
27
|
+
assert.deepEqual(formatDebugLines(['keys', { a: 1 }]), [
|
|
28
|
+
'::debug::keys {',
|
|
29
|
+
'::debug:: "a": 1',
|
|
30
|
+
'::debug::}',
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('prints nothing when debug output is off', () => {
|
|
35
|
+
const printed = [];
|
|
36
|
+
assert.deepEqual(
|
|
37
|
+
debugWith({ env: {}, log: (l) => printed.push(l) }, 'x'),
|
|
38
|
+
[]
|
|
39
|
+
);
|
|
40
|
+
assert.deepEqual(printed, []);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('prints through the injected logger when debug output is on', () => {
|
|
44
|
+
const printed = [];
|
|
45
|
+
debugWith(
|
|
46
|
+
{ env: { CI_SCRIPTS_DEBUG: '1' }, log: (line) => printed.push(line) },
|
|
47
|
+
'loaded',
|
|
48
|
+
{ keys: ['default'] }
|
|
49
|
+
);
|
|
50
|
+
assert.equal(printed[0], '::debug::loaded {');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('treats an unreadable environment as unset instead of throwing', () => {
|
|
54
|
+
// Deno raises NotCapable on the property read when --allow-env is absent;
|
|
55
|
+
// tracing must never be the reason a script fails.
|
|
56
|
+
const hostile = new Proxy(
|
|
57
|
+
{},
|
|
58
|
+
{
|
|
59
|
+
get() {
|
|
60
|
+
throw new Error('NotCapable');
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
assert.equal(readEnvVar('CI_SCRIPTS_DEBUG', hostile), undefined);
|
|
65
|
+
assert.equal(isDebugEnabled(hostile), false);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guard against a duplication gate that reports success without reading code.
|
|
3
|
+
*
|
|
4
|
+
* `.jscpd.json` used to set `"format": "console"`, but jscpd's `format` selects
|
|
5
|
+
* the *file formats* to scan, not the reporter. No file has the extension
|
|
6
|
+
* `console`, so `npm run check:duplication` analysed 0 files, found 0 clones and
|
|
7
|
+
* exited 0 for every commit - a green check that proved nothing. The static
|
|
8
|
+
* assertions below pin the keys that caused it; the end-to-end run proves the
|
|
9
|
+
* shipped config still reaches a real file.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import assert from 'node:assert/strict';
|
|
13
|
+
import { execFileSync } from 'node:child_process';
|
|
14
|
+
import {
|
|
15
|
+
existsSync,
|
|
16
|
+
mkdtempSync,
|
|
17
|
+
readFileSync,
|
|
18
|
+
rmSync,
|
|
19
|
+
writeFileSync,
|
|
20
|
+
} from 'node:fs';
|
|
21
|
+
import { tmpdir } from 'node:os';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import { describe, it } from 'node:test';
|
|
24
|
+
import { fileURLToPath } from 'node:url';
|
|
25
|
+
|
|
26
|
+
const JS_ROOT = path.resolve(
|
|
27
|
+
fileURLToPath(new URL('.', import.meta.url)),
|
|
28
|
+
'../../..'
|
|
29
|
+
);
|
|
30
|
+
const CONFIG_PATH = path.join(JS_ROOT, '.jscpd.json');
|
|
31
|
+
const JSCPD_PACKAGE = path.join(JS_ROOT, 'node_modules', 'jscpd');
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Resolve jscpd's CLI entry point, not its `node_modules/.bin` shim.
|
|
35
|
+
*
|
|
36
|
+
* On Windows npm writes three shims - `jscpd`, `jscpd.cmd` and `jscpd.ps1` -
|
|
37
|
+
* and the extensionless one is a Bourne script that `CreateProcess` cannot
|
|
38
|
+
* execute, so `execFileSync(.bin/jscpd)` fails with ENOENT there while working
|
|
39
|
+
* on Linux and macOS. Reading `bin.jscpd` out of the package manifest gives the
|
|
40
|
+
* same file npm links to, on every platform, and survives an upstream rename.
|
|
41
|
+
*/
|
|
42
|
+
function resolveJscpdCli() {
|
|
43
|
+
const manifest = path.join(JSCPD_PACKAGE, 'package.json');
|
|
44
|
+
if (!existsSync(manifest)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const { bin } = JSON.parse(readFileSync(manifest, 'utf-8'));
|
|
48
|
+
const entry = typeof bin === 'string' ? bin : bin?.jscpd;
|
|
49
|
+
if (!entry) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const cli = path.join(JSCPD_PACKAGE, entry);
|
|
53
|
+
return existsSync(cli) ? cli : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const config = JSON.parse(readFileSync(CONFIG_PATH, 'utf-8'));
|
|
57
|
+
|
|
58
|
+
describe('.jscpd.json', () => {
|
|
59
|
+
it('does not restrict the scan to a format named after a reporter', () => {
|
|
60
|
+
// `format` is a comma-separated list of jscpd language ids ("javascript",
|
|
61
|
+
// "markup", ...). Naming a reporter there silently matches nothing.
|
|
62
|
+
assert.equal(
|
|
63
|
+
config.format,
|
|
64
|
+
undefined,
|
|
65
|
+
'`format` filters which file types are scanned; use `reporters` instead'
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('selects reporters through the `reporters` array', () => {
|
|
70
|
+
assert.ok(Array.isArray(config.reporters), '`reporters` must be an array');
|
|
71
|
+
assert.ok(
|
|
72
|
+
config.reporters.includes('console'),
|
|
73
|
+
'console output is what makes a failing run readable in CI logs'
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('asks to ignore comments through `mode`, not an unknown key', () => {
|
|
78
|
+
// jscpd warns "unknown field 'skipComments'" and carries on; `mode: weak`
|
|
79
|
+
// is the supported spelling of the same intent.
|
|
80
|
+
assert.equal(config.skipComments, undefined);
|
|
81
|
+
assert.equal(config.mode, 'weak');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('the shipped jscpd config scans real files', () => {
|
|
86
|
+
it('reports at least one analysed source for a one-file project', (t) => {
|
|
87
|
+
const jscpdCli = resolveJscpdCli();
|
|
88
|
+
if (!jscpdCli) {
|
|
89
|
+
return t.skip(
|
|
90
|
+
`jscpd is not installed under ${JSCPD_PACKAGE}; run npm ci in js/`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const fixture = mkdtempSync(path.join(tmpdir(), 'jscpd-config-'));
|
|
95
|
+
try {
|
|
96
|
+
// jscpd reads `.jscpd.json` from the directory it is invoked in, so the
|
|
97
|
+
// fixture gets a copy of the real config rather than a --config path.
|
|
98
|
+
writeFileSync(
|
|
99
|
+
path.join(fixture, '.jscpd.json'),
|
|
100
|
+
readFileSync(CONFIG_PATH)
|
|
101
|
+
);
|
|
102
|
+
writeFileSync(
|
|
103
|
+
path.join(fixture, 'sample.js'),
|
|
104
|
+
[
|
|
105
|
+
'export function sample(value) {',
|
|
106
|
+
' return value + 1;',
|
|
107
|
+
'}',
|
|
108
|
+
'',
|
|
109
|
+
].join('\n')
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const output = path.join(fixture, 'report');
|
|
113
|
+
execFileSync(
|
|
114
|
+
process.execPath,
|
|
115
|
+
[
|
|
116
|
+
jscpdCli,
|
|
117
|
+
'.',
|
|
118
|
+
'--reporters',
|
|
119
|
+
'json',
|
|
120
|
+
'--output',
|
|
121
|
+
output,
|
|
122
|
+
'--no-colors',
|
|
123
|
+
],
|
|
124
|
+
{
|
|
125
|
+
cwd: fixture,
|
|
126
|
+
stdio: 'pipe',
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const report = JSON.parse(
|
|
131
|
+
readFileSync(path.join(output, 'jscpd-report.json'), 'utf-8')
|
|
132
|
+
);
|
|
133
|
+
assert.ok(
|
|
134
|
+
report.statistics.total.sources > 0,
|
|
135
|
+
`jscpd analysed ${report.statistics.total.sources} files; the config excludes everything`
|
|
136
|
+
);
|
|
137
|
+
} finally {
|
|
138
|
+
rmSync(fixture, { recursive: true, force: true });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The local quality gate has to be the same gate CI uses.
|
|
3
|
+
*
|
|
4
|
+
* Before this test the repository claimed pre-commit hooks through husky:
|
|
5
|
+
* `js/package.json` ran `"prepare": "husky || true"`, husky refused with
|
|
6
|
+
* `.git can't be found` because npm runs `prepare` inside `js/`, and `|| true`
|
|
7
|
+
* threw the refusal away. `git config --get core.hooksPath` stayed empty, so
|
|
8
|
+
* `js/.husky/pre-commit` never ran for anyone - the same shape of failure as the
|
|
9
|
+
* `|| true` that once hid a Prettier error in the release job.
|
|
10
|
+
*
|
|
11
|
+
* The replacement is a repository-root `.pre-commit-config.yaml` whose local
|
|
12
|
+
* hooks run the exact commands the workflows run. The assertions below pin that
|
|
13
|
+
* correspondence: change a lint command in a workflow without changing the hook
|
|
14
|
+
* (or the other way round) and this test fails.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import assert from 'node:assert/strict';
|
|
18
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
19
|
+
import { describe, it } from 'node:test';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
normalizeNewlines,
|
|
23
|
+
readRepoText,
|
|
24
|
+
repoPath,
|
|
25
|
+
} from '../../helpers/repo.js';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Every local hook, mapped to the workflow step it has to mirror.
|
|
29
|
+
*
|
|
30
|
+
* `command` is matched twice: it must appear inside the hook's `entry`, and the
|
|
31
|
+
* workflow must contain a `run:` step that is exactly that command.
|
|
32
|
+
*/
|
|
33
|
+
const MIRRORED_COMMANDS = [
|
|
34
|
+
{ id: 'js-eslint', workflow: 'js.yml', command: 'npm run lint' },
|
|
35
|
+
{ id: 'js-prettier', workflow: 'js.yml', command: 'npm run format:check' },
|
|
36
|
+
{
|
|
37
|
+
id: 'js-duplication',
|
|
38
|
+
workflow: 'js.yml',
|
|
39
|
+
command: 'npm run check:duplication',
|
|
40
|
+
},
|
|
41
|
+
{ id: 'python-ruff', workflow: 'python.yml', command: 'ruff check .' },
|
|
42
|
+
{
|
|
43
|
+
id: 'python-ruff-format',
|
|
44
|
+
workflow: 'python.yml',
|
|
45
|
+
command: 'ruff format --check .',
|
|
46
|
+
},
|
|
47
|
+
{ id: 'python-mypy', workflow: 'python.yml', command: 'mypy src' },
|
|
48
|
+
{
|
|
49
|
+
id: 'python-mypy-scripts',
|
|
50
|
+
workflow: 'python.yml',
|
|
51
|
+
command: 'mypy --python-version 3.13 scripts tests/unit/scripts',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: 'rust-fmt',
|
|
55
|
+
workflow: 'rust.yml',
|
|
56
|
+
command: 'cargo fmt --all -- --check',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: 'rust-clippy',
|
|
60
|
+
workflow: 'rust.yml',
|
|
61
|
+
command: 'cargo clippy --all-targets --all-features',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'file-line-limits',
|
|
65
|
+
workflow: 'quality.yml',
|
|
66
|
+
command: 'bash scripts/check-file-line-limits.sh',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: 'shared-fingerprint-assets',
|
|
70
|
+
workflow: 'quality.yml',
|
|
71
|
+
command: 'bash scripts/check-shared-fingerprint-assets.sh',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: 'required-docs',
|
|
75
|
+
workflow: 'quality.yml',
|
|
76
|
+
command: 'bash scripts/check-required-docs.sh',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'repo-scripts-lint',
|
|
80
|
+
workflow: 'quality.yml',
|
|
81
|
+
command:
|
|
82
|
+
'node js/node_modules/eslint/bin/eslint.js scripts experiments rust/scripts',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: 'ci-workflow-policy',
|
|
86
|
+
workflow: 'ci-policy.yml',
|
|
87
|
+
command: 'node scripts/check-ci-workflows.mjs',
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Collect the `repo: local` hooks as `id -> lines of that hook`.
|
|
93
|
+
*
|
|
94
|
+
* A regex reader rather than a YAML parser, for the same reason
|
|
95
|
+
* `scripts/check-ci-workflows.mjs` uses one: this repository ships no YAML
|
|
96
|
+
* dependency, and a policy check that needs one is a policy check that stops
|
|
97
|
+
* being run.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} text - contents of .pre-commit-config.yaml
|
|
100
|
+
* @returns {Map<string, string[]>}
|
|
101
|
+
*/
|
|
102
|
+
function readLocalHooks(text) {
|
|
103
|
+
const localSection = text.slice(text.indexOf('- repo: local'));
|
|
104
|
+
const hooks = new Map();
|
|
105
|
+
let current = null;
|
|
106
|
+
|
|
107
|
+
for (const line of localSection.split(/\r?\n/)) {
|
|
108
|
+
const id = line.match(/^\s*-\s+id:\s+(\S+)/);
|
|
109
|
+
if (id) {
|
|
110
|
+
current = [];
|
|
111
|
+
hooks.set(id[1], current);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (current) {
|
|
115
|
+
current.push(line);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return hooks;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @param {string[]} lines - the lines of one hook
|
|
123
|
+
* @returns {string} the hook's `entry` value
|
|
124
|
+
*/
|
|
125
|
+
function entryOf(lines) {
|
|
126
|
+
const entry = lines.find((line) => /^\s*entry:\s/.test(line));
|
|
127
|
+
return entry ? entry.replace(/^\s*entry:\s+/, '').trim() : '';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const localHooks = readLocalHooks(readRepoText('.pre-commit-config.yaml'));
|
|
131
|
+
|
|
132
|
+
const workflow = (name) => readRepoText('.github', 'workflows', name);
|
|
133
|
+
|
|
134
|
+
describe('local hooks run the commands CI runs', () => {
|
|
135
|
+
for (const { id, workflow: file, command } of MIRRORED_COMMANDS) {
|
|
136
|
+
it(`${id} runs \`${command}\`, the same as ${file}`, () => {
|
|
137
|
+
const lines = localHooks.get(id);
|
|
138
|
+
assert.ok(lines, `no \`${id}\` hook in .pre-commit-config.yaml`);
|
|
139
|
+
assert.ok(
|
|
140
|
+
entryOf(lines).includes(command),
|
|
141
|
+
`${id} must run \`${command}\`; its entry is \`${entryOf(lines)}\``
|
|
142
|
+
);
|
|
143
|
+
assert.ok(
|
|
144
|
+
workflow(file).includes(`run: ${command}\n`),
|
|
145
|
+
`${file} no longer has a step running \`${command}\`; the hook and the workflow have drifted apart`
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
it('reads a workflow checked out with Windows line endings', () => {
|
|
151
|
+
// The twelve assertions above match `run: <command>\n`. On windows-latest
|
|
152
|
+
// git checks the repository out with CRLF endings, so every one of them
|
|
153
|
+
// failed there while passing on Linux - run 33963736349, twelve failures,
|
|
154
|
+
// none of them a real drift. Reading through readRepoText() is what makes
|
|
155
|
+
// the assertion about this repository rather than about the runner.
|
|
156
|
+
const crlfWorkflow = normalizeNewlines(
|
|
157
|
+
workflow('js.yml').replaceAll('\n', '\r\n')
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
assert.ok(crlfWorkflow.includes('run: npm run lint\n'));
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('leaves no local hook unpinned', () => {
|
|
164
|
+
const pinned = new Set(MIRRORED_COMMANDS.map((m) => m.id));
|
|
165
|
+
const unpinned = [...localHooks.keys()].filter((id) => !pinned.has(id));
|
|
166
|
+
assert.deepEqual(
|
|
167
|
+
unpinned,
|
|
168
|
+
[],
|
|
169
|
+
'every local hook must be listed in MIRRORED_COMMANDS so it cannot drift from CI'
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('never lets pre-commit append filenames to a `bash -c` entry', () => {
|
|
174
|
+
// `bash -c 'cmd' a.js b.js` passes the files as $0/$1, which bash ignores:
|
|
175
|
+
// the hook would keep passing while checking something else entirely.
|
|
176
|
+
for (const [id, lines] of localHooks) {
|
|
177
|
+
assert.ok(
|
|
178
|
+
lines.some((line) => /^\s*pass_filenames:\s+false\s*$/.test(line)),
|
|
179
|
+
`${id} must set pass_filenames: false`
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('gives clippy the flag that makes a warning fatal in CI', () => {
|
|
185
|
+
// rust.yml sets RUSTFLAGS at workflow level, which is the only reason
|
|
186
|
+
// `cargo clippy` without `-D warnings` is a real gate there.
|
|
187
|
+
assert.ok(entryOf(localHooks.get('rust-clippy')).includes('-Dwarnings'));
|
|
188
|
+
assert.ok(workflow('rust.yml').includes('RUSTFLAGS: -Dwarnings'));
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('the previous hook wiring is gone', () => {
|
|
193
|
+
const manifest = JSON.parse(
|
|
194
|
+
readFileSync(repoPath('js', 'package.json'), 'utf-8')
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
it('installs no git hook through a masked command', () => {
|
|
198
|
+
for (const [name, command] of Object.entries(manifest.scripts)) {
|
|
199
|
+
assert.ok(
|
|
200
|
+
!/\|\|\s*true\s*$/.test(command),
|
|
201
|
+
`npm script \`${name}\` ends in \`|| true\`, which hides its own failure`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('keeps no husky wiring that cannot reach .git from js/', () => {
|
|
207
|
+
// husky refuses any path containing `..` and requires `.git` in the working
|
|
208
|
+
// directory, so it cannot manage a repository-root hook from this package.
|
|
209
|
+
assert.equal(manifest.devDependencies.husky, undefined);
|
|
210
|
+
assert.equal(manifest.devDependencies['lint-staged'], undefined);
|
|
211
|
+
assert.equal(manifest['lint-staged'], undefined);
|
|
212
|
+
assert.ok(!existsSync(repoPath('js', '.husky')));
|
|
213
|
+
});
|
|
214
|
+
});
|