@regressionproof/cli 0.7.4 → 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/build/cli.js +44 -0
- package/build/components/Doctor.d.ts +7 -0
- package/build/components/Doctor.js +49 -0
- package/build/components/Doctor.tsx +75 -0
- package/build/doctor/Doctor.d.ts +7 -0
- package/build/doctor/Doctor.js +23 -0
- package/build/doctor/DoctorContext.d.ts +12 -0
- package/build/doctor/DoctorContext.js +44 -0
- package/build/doctor/DoctorOutput.d.ts +6 -0
- package/build/doctor/DoctorOutput.js +32 -0
- package/build/doctor/DoctorResult.d.ts +8 -0
- package/build/doctor/DoctorResult.js +1 -0
- package/build/doctor/DoctorRunner.d.ts +7 -0
- package/build/doctor/DoctorRunner.js +9 -0
- package/build/doctor/checks/CredentialsCheck.d.ts +6 -0
- package/build/doctor/checks/CredentialsCheck.js +55 -0
- package/build/doctor/checks/JestReporterCheck.d.ts +5 -0
- package/build/doctor/checks/JestReporterCheck.js +35 -0
- package/build/doctor/checks/LocalConfigCheck.d.ts +5 -0
- package/build/doctor/checks/LocalConfigCheck.js +17 -0
- package/build/doctor/checks/MirrorAccessCheck.d.ts +9 -0
- package/build/doctor/checks/MirrorAccessCheck.js +129 -0
- package/build/esm/cli.js +44 -0
- package/build/esm/components/Doctor.d.ts +7 -0
- package/build/esm/components/Doctor.js +49 -0
- package/build/esm/doctor/Doctor.d.ts +7 -0
- package/build/esm/doctor/Doctor.js +33 -0
- package/build/esm/doctor/DoctorContext.d.ts +12 -0
- package/build/esm/doctor/DoctorContext.js +41 -0
- package/build/esm/doctor/DoctorOutput.d.ts +6 -0
- package/build/esm/doctor/DoctorOutput.js +32 -0
- package/build/esm/doctor/DoctorResult.d.ts +8 -0
- package/build/esm/doctor/DoctorResult.js +1 -0
- package/build/esm/doctor/DoctorRunner.d.ts +7 -0
- package/build/esm/doctor/DoctorRunner.js +21 -0
- package/build/esm/doctor/checks/CredentialsCheck.d.ts +6 -0
- package/build/esm/doctor/checks/CredentialsCheck.js +66 -0
- package/build/esm/doctor/checks/JestReporterCheck.d.ts +5 -0
- package/build/esm/doctor/checks/JestReporterCheck.js +46 -0
- package/build/esm/doctor/checks/LocalConfigCheck.d.ts +5 -0
- package/build/esm/doctor/checks/LocalConfigCheck.js +28 -0
- package/build/esm/doctor/checks/MirrorAccessCheck.d.ts +9 -0
- package/build/esm/doctor/checks/MirrorAccessCheck.js +141 -0
- package/build/esm/jest/JestConfigurator.js +9 -0
- package/build/esm/jest/JestReporterConfigInspector.d.ts +13 -0
- package/build/esm/jest/JestReporterConfigInspector.js +60 -0
- package/build/jest/JestConfigurator.js +9 -0
- package/build/jest/JestReporterConfigInspector.d.ts +13 -0
- package/build/jest/JestReporterConfigInspector.js +56 -0
- package/package.json +3 -3
package/build/cli.js
CHANGED
|
@@ -6,7 +6,10 @@ import acceptInvite from './commands/invite/AcceptInvite.js';
|
|
|
6
6
|
import createInvite from './commands/invite/CreateInvite.js';
|
|
7
7
|
import listInvites from './commands/invite/ListInvites.js';
|
|
8
8
|
import revokeInvite from './commands/invite/RevokeInvite.js';
|
|
9
|
+
import Doctor from './components/Doctor.js';
|
|
9
10
|
import Init from './components/Init.js';
|
|
11
|
+
import DoctorOutput from './doctor/DoctorOutput.js';
|
|
12
|
+
import DoctorRunner from './doctor/DoctorRunner.js';
|
|
10
13
|
const command = process.argv[2];
|
|
11
14
|
const projectNameArg = process.argv[3];
|
|
12
15
|
if (command === 'init') {
|
|
@@ -42,11 +45,52 @@ else if (command === 'invite') {
|
|
|
42
45
|
process.exit(1);
|
|
43
46
|
}
|
|
44
47
|
}
|
|
48
|
+
else if (command === 'doctor') {
|
|
49
|
+
const options = parseDoctorArgs(process.argv.slice(3));
|
|
50
|
+
void DoctorRunner.run({ cwd: options.cwd })
|
|
51
|
+
.then((results) => {
|
|
52
|
+
if (options.json) {
|
|
53
|
+
console.log(JSON.stringify(results, null, 2));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const { waitUntilExit } = render(React.createElement(Doctor, { results }));
|
|
57
|
+
void waitUntilExit().then(() => {
|
|
58
|
+
process.exit(DoctorOutput.exitCode(results));
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
process.exit(DoctorOutput.exitCode(results));
|
|
63
|
+
})
|
|
64
|
+
.catch((err) => {
|
|
65
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
66
|
+
console.error(message);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
45
70
|
else {
|
|
46
71
|
console.log('Usage: regressionproof <command>');
|
|
47
72
|
console.log('');
|
|
48
73
|
console.log('Commands:');
|
|
49
74
|
console.log(' init [projectName] Initialize a new project');
|
|
50
75
|
console.log(' invite ... Manage project invites');
|
|
76
|
+
console.log(' doctor Check project configuration');
|
|
51
77
|
process.exit(1);
|
|
52
78
|
}
|
|
79
|
+
function parseDoctorArgs(args) {
|
|
80
|
+
const options = { json: false };
|
|
81
|
+
for (let i = 0; i < args.length; i++) {
|
|
82
|
+
const arg = args[i];
|
|
83
|
+
if (arg === '--json') {
|
|
84
|
+
options.json = true;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (arg === '--cwd') {
|
|
88
|
+
const value = args[i + 1];
|
|
89
|
+
if (value) {
|
|
90
|
+
options.cwd = value;
|
|
91
|
+
i++;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return options;
|
|
96
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Box, Text } from 'ink';
|
|
2
|
+
import BigText from 'ink-big-text';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
class DoctorComponent extends React.Component {
|
|
5
|
+
render() {
|
|
6
|
+
return (React.createElement(Box, { flexDirection: "column" },
|
|
7
|
+
React.createElement(Box, { flexDirection: "column", padding: 1 },
|
|
8
|
+
React.createElement(BigText, { text: "regressionproof.ai", font: "tiny", colors: ['magenta', 'cyan'] }),
|
|
9
|
+
React.createElement(Text, { color: "gray" }, "Teaching LLMs to write better code.")),
|
|
10
|
+
React.createElement(Box, { flexDirection: "column", paddingX: 1, paddingBottom: 1 },
|
|
11
|
+
React.createElement(Text, { bold: true }, "RegressionProof Doctor"),
|
|
12
|
+
this.props.results.map((result) => (React.createElement(Box, { key: result.name, flexDirection: "column" },
|
|
13
|
+
React.createElement(Box, null,
|
|
14
|
+
React.createElement(Text, { color: this.colorFor(result.status) }, this.labelFor(result.status)),
|
|
15
|
+
React.createElement(Text, null,
|
|
16
|
+
" ",
|
|
17
|
+
result.name)),
|
|
18
|
+
result.details.map((detail) => (React.createElement(Text, { key: detail },
|
|
19
|
+
" ",
|
|
20
|
+
detail))),
|
|
21
|
+
result.fix ? (React.createElement(Text, null,
|
|
22
|
+
" Fix: ",
|
|
23
|
+
result.fix)) : null,
|
|
24
|
+
React.createElement(Text, null, " ")))))));
|
|
25
|
+
}
|
|
26
|
+
labelFor(status) {
|
|
27
|
+
switch (status) {
|
|
28
|
+
case 'ok':
|
|
29
|
+
return 'OK';
|
|
30
|
+
case 'warn':
|
|
31
|
+
return 'WARN';
|
|
32
|
+
case 'fail':
|
|
33
|
+
return 'FAIL';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
colorFor(status) {
|
|
37
|
+
switch (status) {
|
|
38
|
+
case 'ok':
|
|
39
|
+
return 'green';
|
|
40
|
+
case 'warn':
|
|
41
|
+
return 'yellow';
|
|
42
|
+
case 'fail':
|
|
43
|
+
return 'red';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export default function Doctor(props) {
|
|
48
|
+
return React.createElement(DoctorComponent, { results: props.results });
|
|
49
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Box, Text } from 'ink'
|
|
2
|
+
import BigText from 'ink-big-text'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import type { DoctorResult } from '../doctor/DoctorResult.js'
|
|
5
|
+
|
|
6
|
+
class DoctorComponent extends React.Component<Props> {
|
|
7
|
+
public render(): React.ReactElement {
|
|
8
|
+
return (
|
|
9
|
+
<Box flexDirection="column">
|
|
10
|
+
<Box flexDirection="column" padding={1}>
|
|
11
|
+
<BigText
|
|
12
|
+
text="regressionproof.ai"
|
|
13
|
+
font="tiny"
|
|
14
|
+
colors={['magenta', 'cyan']}
|
|
15
|
+
/>
|
|
16
|
+
<Text color="gray">
|
|
17
|
+
Teaching LLMs to write better code.
|
|
18
|
+
</Text>
|
|
19
|
+
</Box>
|
|
20
|
+
<Box flexDirection="column" paddingX={1} paddingBottom={1}>
|
|
21
|
+
<Text bold>RegressionProof Doctor</Text>
|
|
22
|
+
{this.props.results.map((result) => (
|
|
23
|
+
<Box key={result.name} flexDirection="column">
|
|
24
|
+
<Box>
|
|
25
|
+
<Text color={this.colorFor(result.status)}>
|
|
26
|
+
{this.labelFor(result.status)}
|
|
27
|
+
</Text>
|
|
28
|
+
<Text> {result.name}</Text>
|
|
29
|
+
</Box>
|
|
30
|
+
{result.details.map((detail) => (
|
|
31
|
+
<Text key={detail}> {detail}</Text>
|
|
32
|
+
))}
|
|
33
|
+
{result.fix ? (
|
|
34
|
+
<Text> Fix: {result.fix}</Text>
|
|
35
|
+
) : null}
|
|
36
|
+
<Text> </Text>
|
|
37
|
+
</Box>
|
|
38
|
+
))}
|
|
39
|
+
</Box>
|
|
40
|
+
</Box>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private labelFor(status: DoctorResult['status']): string {
|
|
45
|
+
switch (status) {
|
|
46
|
+
case 'ok':
|
|
47
|
+
return 'OK'
|
|
48
|
+
case 'warn':
|
|
49
|
+
return 'WARN'
|
|
50
|
+
case 'fail':
|
|
51
|
+
return 'FAIL'
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private colorFor(
|
|
56
|
+
status: DoctorResult['status']
|
|
57
|
+
): 'green' | 'yellow' | 'red' {
|
|
58
|
+
switch (status) {
|
|
59
|
+
case 'ok':
|
|
60
|
+
return 'green'
|
|
61
|
+
case 'warn':
|
|
62
|
+
return 'yellow'
|
|
63
|
+
case 'fail':
|
|
64
|
+
return 'red'
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default function Doctor(props: Props): React.ReactElement {
|
|
70
|
+
return <DoctorComponent results={props.results} />
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface Props {
|
|
74
|
+
results: DoctorResult[]
|
|
75
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import CredentialsCheck from './checks/CredentialsCheck.js';
|
|
2
|
+
import JestReporterCheck from './checks/JestReporterCheck.js';
|
|
3
|
+
import LocalConfigCheck from './checks/LocalConfigCheck.js';
|
|
4
|
+
import MirrorAccessCheck from './checks/MirrorAccessCheck.js';
|
|
5
|
+
export default class Doctor {
|
|
6
|
+
context;
|
|
7
|
+
constructor(context) {
|
|
8
|
+
this.context = context;
|
|
9
|
+
}
|
|
10
|
+
async run() {
|
|
11
|
+
const checks = [
|
|
12
|
+
new LocalConfigCheck(),
|
|
13
|
+
new JestReporterCheck(),
|
|
14
|
+
new CredentialsCheck(),
|
|
15
|
+
new MirrorAccessCheck(),
|
|
16
|
+
];
|
|
17
|
+
const results = [];
|
|
18
|
+
for (const check of checks) {
|
|
19
|
+
results.push(await check.run(this.context));
|
|
20
|
+
}
|
|
21
|
+
return results;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default class DoctorContext {
|
|
2
|
+
cwd: string;
|
|
3
|
+
projectName: string | null;
|
|
4
|
+
localConfigPath: string | null;
|
|
5
|
+
homeConfigDir: string;
|
|
6
|
+
constructor(cwd: string, projectName: string | null, localConfigPath: string | null, homeConfigDir: string);
|
|
7
|
+
static fromCwd(cwd: string): DoctorContext;
|
|
8
|
+
get configDir(): string | null;
|
|
9
|
+
get credentialsPath(): string | null;
|
|
10
|
+
get mirrorPath(): string | null;
|
|
11
|
+
private static readProjectName;
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
export default class DoctorContext {
|
|
5
|
+
cwd;
|
|
6
|
+
projectName;
|
|
7
|
+
localConfigPath;
|
|
8
|
+
homeConfigDir;
|
|
9
|
+
constructor(cwd, projectName, localConfigPath, homeConfigDir) {
|
|
10
|
+
this.cwd = cwd;
|
|
11
|
+
this.projectName = projectName;
|
|
12
|
+
this.localConfigPath = localConfigPath;
|
|
13
|
+
this.homeConfigDir = homeConfigDir;
|
|
14
|
+
}
|
|
15
|
+
static fromCwd(cwd) {
|
|
16
|
+
const localConfigPath = path.join(cwd, '.regressionproof.json');
|
|
17
|
+
const localExists = fs.existsSync(localConfigPath);
|
|
18
|
+
const projectName = localExists
|
|
19
|
+
? DoctorContext.readProjectName(localConfigPath)
|
|
20
|
+
: null;
|
|
21
|
+
const homeConfigDir = path.join(os.homedir(), '.regressionproof');
|
|
22
|
+
return new DoctorContext(cwd, projectName, localExists ? localConfigPath : null, homeConfigDir);
|
|
23
|
+
}
|
|
24
|
+
get configDir() {
|
|
25
|
+
return this.projectName
|
|
26
|
+
? path.join(this.homeConfigDir, this.projectName)
|
|
27
|
+
: null;
|
|
28
|
+
}
|
|
29
|
+
get credentialsPath() {
|
|
30
|
+
return this.configDir ? path.join(this.configDir, 'config.json') : null;
|
|
31
|
+
}
|
|
32
|
+
get mirrorPath() {
|
|
33
|
+
return this.configDir ? path.join(this.configDir, 'mirror') : null;
|
|
34
|
+
}
|
|
35
|
+
static readProjectName(localConfigPath) {
|
|
36
|
+
try {
|
|
37
|
+
const raw = JSON.parse(fs.readFileSync(localConfigPath, 'utf-8'));
|
|
38
|
+
return raw.projectName ?? null;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default class DoctorOutput {
|
|
2
|
+
static print(results) {
|
|
3
|
+
console.log('===================================');
|
|
4
|
+
console.log(' RegressionProof Doctor');
|
|
5
|
+
console.log('===================================');
|
|
6
|
+
console.log('');
|
|
7
|
+
for (const result of results) {
|
|
8
|
+
const label = DoctorOutput.formatStatus(result.status);
|
|
9
|
+
console.log(`${label} ${result.name}`);
|
|
10
|
+
for (const detail of result.details) {
|
|
11
|
+
console.log(` ${detail}`);
|
|
12
|
+
}
|
|
13
|
+
if (result.fix) {
|
|
14
|
+
console.log(` Fix: ${result.fix}`);
|
|
15
|
+
}
|
|
16
|
+
console.log('');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
static exitCode(results) {
|
|
20
|
+
return results.some((result) => result.status === 'fail') ? 1 : 0;
|
|
21
|
+
}
|
|
22
|
+
static formatStatus(status) {
|
|
23
|
+
switch (status) {
|
|
24
|
+
case 'ok':
|
|
25
|
+
return 'OK ';
|
|
26
|
+
case 'warn':
|
|
27
|
+
return 'WARN';
|
|
28
|
+
case 'fail':
|
|
29
|
+
return 'FAIL';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Doctor from './Doctor.js';
|
|
2
|
+
import DoctorContext from './DoctorContext.js';
|
|
3
|
+
export default class DoctorRunner {
|
|
4
|
+
static async run(options) {
|
|
5
|
+
const cwd = options?.cwd ?? process.cwd();
|
|
6
|
+
const context = DoctorContext.fromCwd(cwd);
|
|
7
|
+
return new Doctor(context).run();
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import ConfigManager from '../../config/ConfigManager.js';
|
|
3
|
+
export default class CredentialsCheck {
|
|
4
|
+
async run(context) {
|
|
5
|
+
if (!context.projectName) {
|
|
6
|
+
return {
|
|
7
|
+
name: 'Credentials for project',
|
|
8
|
+
status: 'warn',
|
|
9
|
+
details: [
|
|
10
|
+
'Unable to resolve project name from .regressionproof.json.',
|
|
11
|
+
],
|
|
12
|
+
fix: 'Run `npx regressionproof init` from the project root.',
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const configManager = new ConfigManager();
|
|
16
|
+
const configPath = context.credentialsPath;
|
|
17
|
+
if (!configPath || !fs.existsSync(configPath)) {
|
|
18
|
+
return {
|
|
19
|
+
name: `Credentials for project "${context.projectName}"`,
|
|
20
|
+
status: 'fail',
|
|
21
|
+
details: [
|
|
22
|
+
`Missing credentials at ${configPath ??
|
|
23
|
+
configManager.getConfigDir(context.projectName)}.`,
|
|
24
|
+
],
|
|
25
|
+
fix: 'Run `npx regressionproof invite accept <token>` (teammate) or `npx regressionproof init` (owner).',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const parsed = this.safeReadJson(configPath);
|
|
29
|
+
const url = parsed?.remote?.url;
|
|
30
|
+
const token = parsed?.remote?.token;
|
|
31
|
+
if (!url || !token) {
|
|
32
|
+
return {
|
|
33
|
+
name: `Credentials for project "${context.projectName}"`,
|
|
34
|
+
status: 'fail',
|
|
35
|
+
details: [
|
|
36
|
+
'Credentials file is missing remote.url or remote.token.',
|
|
37
|
+
],
|
|
38
|
+
fix: 'Run `npx regressionproof invite accept <token>` to refresh credentials.',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
name: `Credentials for project "${context.projectName}"`,
|
|
43
|
+
status: 'ok',
|
|
44
|
+
details: [`Credentials found at ${configPath}.`],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
safeReadJson(filePath) {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import JestReporterConfigInspector from '../../jest/JestReporterConfigInspector.js';
|
|
2
|
+
export default class JestReporterCheck {
|
|
3
|
+
async run(context) {
|
|
4
|
+
const inspector = new JestReporterConfigInspector();
|
|
5
|
+
const inspection = inspector.inspect(context.cwd);
|
|
6
|
+
if (!inspection.hasPackageJson) {
|
|
7
|
+
return {
|
|
8
|
+
name: 'Jest reporter configured',
|
|
9
|
+
status: 'warn',
|
|
10
|
+
details: ['No package.json found in the current directory.'],
|
|
11
|
+
fix: 'Run `npx regressionproof init` from the project root.',
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (inspection.isInstalled && inspection.isConfigured) {
|
|
15
|
+
return {
|
|
16
|
+
name: 'Jest reporter configured',
|
|
17
|
+
status: 'ok',
|
|
18
|
+
details: ['Reporter is installed and configured.'],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const details = [];
|
|
22
|
+
if (!inspection.isInstalled) {
|
|
23
|
+
details.push('Reporter package is not installed.');
|
|
24
|
+
}
|
|
25
|
+
if (!inspection.isConfigured) {
|
|
26
|
+
details.push('Jest config does not include the reporter.');
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
name: 'Jest reporter configured',
|
|
30
|
+
status: 'warn',
|
|
31
|
+
details,
|
|
32
|
+
fix: 'Run `npx regressionproof init` or add the reporter to your Jest config.',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default class LocalConfigCheck {
|
|
2
|
+
async run(context) {
|
|
3
|
+
if (!context.localConfigPath) {
|
|
4
|
+
return {
|
|
5
|
+
name: 'Local project config (.regressionproof.json)',
|
|
6
|
+
status: 'warn',
|
|
7
|
+
details: [`Missing .regressionproof.json in ${context.cwd}.`],
|
|
8
|
+
fix: 'Run `npx regressionproof init` from the project root.',
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
name: 'Local project config (.regressionproof.json)',
|
|
13
|
+
status: 'ok',
|
|
14
|
+
details: [`Found at ${context.localConfigPath}.`],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import DoctorContext from '../DoctorContext.js';
|
|
2
|
+
import type { DoctorResult } from '../DoctorResult.js';
|
|
3
|
+
export default class MirrorAccessCheck {
|
|
4
|
+
run(context: DoctorContext): Promise<DoctorResult>;
|
|
5
|
+
private checkPullAccess;
|
|
6
|
+
private checkPushAccess;
|
|
7
|
+
private isNoCommitsError;
|
|
8
|
+
private getErrorMessage;
|
|
9
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import ConfigManager from '../../config/ConfigManager.js';
|
|
4
|
+
export default class MirrorAccessCheck {
|
|
5
|
+
async run(context) {
|
|
6
|
+
if (!context.projectName) {
|
|
7
|
+
return {
|
|
8
|
+
name: 'Mirror directory',
|
|
9
|
+
status: 'warn',
|
|
10
|
+
details: [
|
|
11
|
+
'Unable to resolve project name from .regressionproof.json.',
|
|
12
|
+
],
|
|
13
|
+
fix: 'Run `npx regressionproof init` from the project root.',
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const configManager = new ConfigManager();
|
|
17
|
+
const mirrorPath = context.mirrorPath;
|
|
18
|
+
const credentials = configManager.loadCredentials(context.projectName);
|
|
19
|
+
if (!mirrorPath || !fs.existsSync(mirrorPath)) {
|
|
20
|
+
return {
|
|
21
|
+
name: 'Mirror directory',
|
|
22
|
+
status: 'warn',
|
|
23
|
+
details: [
|
|
24
|
+
`Mirror directory not found at ${mirrorPath ??
|
|
25
|
+
configManager.getConfigDir(context.projectName)}.`,
|
|
26
|
+
'This is normal before the first snapshot is created.',
|
|
27
|
+
],
|
|
28
|
+
fix: 'Run your tests to create the first snapshot.',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (!credentials) {
|
|
32
|
+
return {
|
|
33
|
+
name: 'Mirror directory',
|
|
34
|
+
status: 'warn',
|
|
35
|
+
details: ['Credentials not found; remote access not checked.'],
|
|
36
|
+
fix: 'Run `npx regressionproof invite accept <token>` (teammate) or `npx regressionproof init` (owner).',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const authedUrl = credentials.url.replace('://', `://${credentials.token}@`);
|
|
40
|
+
const pullResult = this.checkPullAccess(authedUrl);
|
|
41
|
+
if (!pullResult.ok) {
|
|
42
|
+
return {
|
|
43
|
+
name: 'Mirror directory',
|
|
44
|
+
status: 'fail',
|
|
45
|
+
details: [
|
|
46
|
+
'Unable to access remote (pull).',
|
|
47
|
+
pullResult.message ?? 'Unknown error.',
|
|
48
|
+
],
|
|
49
|
+
fix: 'Run `npx regressionproof invite accept <token>` to refresh credentials.',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const pushResult = this.checkPushAccess(mirrorPath, authedUrl);
|
|
53
|
+
if (pushResult.status === 'fail') {
|
|
54
|
+
return {
|
|
55
|
+
name: 'Mirror directory',
|
|
56
|
+
status: 'fail',
|
|
57
|
+
details: [
|
|
58
|
+
'Unable to access remote (push).',
|
|
59
|
+
pushResult.message ?? 'Unknown error.',
|
|
60
|
+
],
|
|
61
|
+
fix: 'Run `npx regressionproof invite accept <token>` to refresh credentials.',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (pushResult.status === 'warn') {
|
|
65
|
+
return {
|
|
66
|
+
name: 'Mirror directory',
|
|
67
|
+
status: 'warn',
|
|
68
|
+
details: [
|
|
69
|
+
'Remote access confirmed (pull).',
|
|
70
|
+
pushResult.message ?? 'Unknown error.',
|
|
71
|
+
],
|
|
72
|
+
fix: 'Run your tests to create the first snapshot.',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
name: 'Mirror directory',
|
|
77
|
+
status: 'ok',
|
|
78
|
+
details: [
|
|
79
|
+
`Mirror directory exists at ${mirrorPath}.`,
|
|
80
|
+
'Remote access confirmed (pull/push).',
|
|
81
|
+
],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
checkPullAccess(url) {
|
|
85
|
+
try {
|
|
86
|
+
execSync(`git ls-remote "${url}"`, { stdio: 'pipe' });
|
|
87
|
+
return { ok: true };
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
message: this.getErrorMessage(err),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
checkPushAccess(mirrorPath, url) {
|
|
97
|
+
try {
|
|
98
|
+
execSync(`git -C "${mirrorPath}" push --dry-run "${url}" HEAD`, {
|
|
99
|
+
stdio: 'pipe',
|
|
100
|
+
});
|
|
101
|
+
return { status: 'ok' };
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
const message = this.getErrorMessage(err);
|
|
105
|
+
if (this.isNoCommitsError(message)) {
|
|
106
|
+
return {
|
|
107
|
+
status: 'warn',
|
|
108
|
+
message: 'No commits in mirror; push check skipped.',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return { status: 'fail', message };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
isNoCommitsError(message) {
|
|
115
|
+
const normalized = message.toLowerCase();
|
|
116
|
+
return (normalized.includes('src refspec') ||
|
|
117
|
+
normalized.includes('does not match any') ||
|
|
118
|
+
normalized.includes('no commits'));
|
|
119
|
+
}
|
|
120
|
+
getErrorMessage(err) {
|
|
121
|
+
if (err && typeof err === 'object') {
|
|
122
|
+
const error = err;
|
|
123
|
+
return (error.stderr?.toString().trim() ||
|
|
124
|
+
error.stdout?.toString().trim() ||
|
|
125
|
+
error.message);
|
|
126
|
+
}
|
|
127
|
+
return String(err);
|
|
128
|
+
}
|
|
129
|
+
}
|