testdriverai 4.2.10 → 4.2.11
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/agent.js +91 -96
- package/index.js +2 -1
- package/lib/commander.js +18 -18
- package/lib/commands.js +34 -37
- package/lib/config.js +2 -1
- package/lib/focus-application.js +4 -3
- package/lib/history.js +4 -4
- package/lib/init.js +22 -21
- package/lib/logger.js +42 -66
- package/lib/overlay.js +3 -2
- package/lib/redraw.js +7 -7
- package/lib/sdk.js +5 -5
- package/lib/subimage/index.js +3 -2
- package/lib/system.js +3 -1
- package/package.json +1 -1
package/lib/logger.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// central logger for the bot
|
|
2
2
|
const winston = require("winston");
|
|
3
3
|
const os = require("os");
|
|
4
|
-
const stripAnsi = require("@electerm/strip-ansi").default;
|
|
5
|
-
const package = require("../package.json");
|
|
6
4
|
|
|
7
5
|
// simple match for aws instance i-*
|
|
8
6
|
const shouldLog =
|
|
@@ -12,13 +10,40 @@ const shouldLog =
|
|
|
12
10
|
const { marked } = require("marked");
|
|
13
11
|
const { markedTerminal } = require("marked-terminal");
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
const { printf } = winston.format;
|
|
14
|
+
|
|
15
|
+
const logFormat = printf(({ message }) => {
|
|
16
|
+
return `${message}`;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
let interpolationVars = JSON.parse(process.env.TD_INTERPOLATION_VARS || '{}');
|
|
20
|
+
|
|
21
|
+
const censorSensitiveData = (message) => {
|
|
22
|
+
for (let value of Object.values(interpolationVars)) {
|
|
23
|
+
|
|
24
|
+
// Avoid replacing vars that are 0 or 1 character
|
|
25
|
+
if (value.length >= 2) {
|
|
26
|
+
message = message.replaceAll(value, "****");
|
|
27
|
+
}
|
|
20
28
|
}
|
|
21
|
-
|
|
29
|
+
return message;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const logger = winston.createLogger({
|
|
33
|
+
level: shouldLog ? 'debug' : 'info',
|
|
34
|
+
format: winston.format.combine(
|
|
35
|
+
winston.format.splat(),
|
|
36
|
+
winston.format((info) => {
|
|
37
|
+
info.message = censorSensitiveData(info.message);
|
|
38
|
+
return info;
|
|
39
|
+
})(),
|
|
40
|
+
logFormat
|
|
41
|
+
),
|
|
42
|
+
transports: [
|
|
43
|
+
new winston.transports.Console(),
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
|
|
22
47
|
|
|
23
48
|
// marked is a markdown parser
|
|
24
49
|
// markedTerminal allows us to render markdown in CLI
|
|
@@ -57,8 +82,9 @@ const createMarkdownStreamLogger = () => {
|
|
|
57
82
|
|
|
58
83
|
const consoleOutput = markedParsePartial(buffer, 0, -1);
|
|
59
84
|
|
|
60
|
-
|
|
85
|
+
let diff = consoleOutput.replace(previousConsoleOutput, "");
|
|
61
86
|
if (diff) {
|
|
87
|
+
diff = censorSensitiveData(diff);
|
|
62
88
|
process.stdout.write(diff);
|
|
63
89
|
}
|
|
64
90
|
},
|
|
@@ -66,22 +92,22 @@ const createMarkdownStreamLogger = () => {
|
|
|
66
92
|
|
|
67
93
|
const previousConsoleOutput = markedParsePartial(buffer, 0, -1);
|
|
68
94
|
const consoleOutput = markedParsePartial(buffer, 0, Infinity);
|
|
69
|
-
|
|
95
|
+
let diff = consoleOutput.replace(previousConsoleOutput, "");
|
|
70
96
|
|
|
71
97
|
if (diff) {
|
|
98
|
+
diff = censorSensitiveData(diff);
|
|
72
99
|
process.stdout.write(diff);
|
|
73
100
|
}
|
|
74
101
|
process.stdout.write("\n\n");
|
|
75
102
|
buffer = "";
|
|
76
|
-
log("silly", consoleOutput);
|
|
77
103
|
},
|
|
78
104
|
};
|
|
79
105
|
};
|
|
80
106
|
|
|
81
107
|
const prettyMarkdown = (markdown) => {
|
|
82
108
|
if (typeof markdown !== "string") {
|
|
83
|
-
|
|
84
|
-
|
|
109
|
+
logger.error("prettyMarkdown requires a string");
|
|
110
|
+
logger.error(markdown);
|
|
85
111
|
return;
|
|
86
112
|
}
|
|
87
113
|
|
|
@@ -91,62 +117,12 @@ const prettyMarkdown = (markdown) => {
|
|
|
91
117
|
consoleOutput = consoleOutput.replace(/\n$/, "");
|
|
92
118
|
consoleOutput = consoleOutput.replace(/^/gm, spaceChar);
|
|
93
119
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// datadog
|
|
97
|
-
log("silly", consoleOutput);
|
|
98
|
-
|
|
99
|
-
// user terminal
|
|
100
|
-
console.log(consoleOutput);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const logger = winston.createLogger({
|
|
104
|
-
transports: [],
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
if (shouldLog) {
|
|
108
|
-
logger.add(
|
|
109
|
-
new winston.transports.Console({
|
|
110
|
-
format: winston.format.combine(
|
|
111
|
-
winston.format.colorize(),
|
|
112
|
-
winston.format.simple(),
|
|
113
|
-
),
|
|
114
|
-
level: "silly",
|
|
115
|
-
}),
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const log = (level, message, indent = false) => {
|
|
120
|
-
let m = message;
|
|
121
|
-
|
|
122
|
-
if (indent) {
|
|
123
|
-
m = spaceChar + message;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (process.env["DEV"] || (level !== "silly" && level !== "debug")) {
|
|
127
|
-
console.log(m);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (typeof message === "string" || message instanceof String) {
|
|
131
|
-
message = stripAnsi(message);
|
|
132
|
-
} else {
|
|
133
|
-
message = JSON.stringify(message);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (shouldLog) {
|
|
137
|
-
logger.log({
|
|
138
|
-
level,
|
|
139
|
-
message,
|
|
140
|
-
version: package.version,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
120
|
+
logger.info(consoleOutput);
|
|
143
121
|
};
|
|
144
122
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
setDepth,
|
|
123
|
+
module.exports = {
|
|
124
|
+
logger,
|
|
148
125
|
prettyMarkdown,
|
|
149
126
|
createMarkdownStreamLogger,
|
|
150
127
|
};
|
|
151
128
|
|
|
152
|
-
module.exports = loggy;
|
package/lib/overlay.js
CHANGED
|
@@ -3,6 +3,7 @@ const ipc = require("node-ipc").default;
|
|
|
3
3
|
const { fork } = require("child_process");
|
|
4
4
|
|
|
5
5
|
const { emitter, eventsArray } = require("./events.js");
|
|
6
|
+
const { logger } = require("./logger.js");
|
|
6
7
|
|
|
7
8
|
ipc.config.id = "testdriverai";
|
|
8
9
|
ipc.config.retry = 50;
|
|
@@ -10,7 +11,7 @@ ipc.config.silent = true;
|
|
|
10
11
|
|
|
11
12
|
let electronProcess;
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
logger.info("Spawning GUI...");
|
|
14
15
|
|
|
15
16
|
try {
|
|
16
17
|
// Resolve the path to Electron CLI
|
|
@@ -27,7 +28,7 @@ try {
|
|
|
27
28
|
);
|
|
28
29
|
|
|
29
30
|
} catch (error) {
|
|
30
|
-
|
|
31
|
+
logger.error("Failed to locate Electron CLI or start process:", error);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
|
package/lib/redraw.js
CHANGED
|
@@ -2,7 +2,7 @@ const { captureScreenPNG } = require("./system");
|
|
|
2
2
|
const os = require("os");
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const { compare } = require("odiff-bin");
|
|
5
|
-
const logger = require("./logger");
|
|
5
|
+
const logger = require("./logger").logger;
|
|
6
6
|
|
|
7
7
|
// network
|
|
8
8
|
const si = require('systeminformation');
|
|
@@ -66,11 +66,11 @@ async function updateNetwork() {
|
|
|
66
66
|
if (os.platform() === 'win32') {
|
|
67
67
|
exec(`powershell -File ${scriptPath}`, (error, stdout, stderr) => {
|
|
68
68
|
if (error) {
|
|
69
|
-
|
|
69
|
+
logger.error(`Error executing PowerShell script: ${error}`);
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
72
|
if (stderr) {
|
|
73
|
-
|
|
73
|
+
logger.error(`PowerShell error: ${stderr}`);
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -79,7 +79,7 @@ async function updateNetwork() {
|
|
|
79
79
|
const result = JSON.parse(stdout.trim());
|
|
80
80
|
parseNetworkStats(result.totalBytesReceived, result.totalBytesSent);
|
|
81
81
|
} catch (parseError) {
|
|
82
|
-
|
|
82
|
+
logger.error(`Error parsing JSON: ${parseError}`);
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
} else if (os.platform() === 'darwin') {
|
|
@@ -140,10 +140,10 @@ async function checkCondition(resolve, startTime, timeoutMs) {
|
|
|
140
140
|
let networkText = networkSettled ? chalk.green(`y`) : chalk.dim(`${Math.trunc((diffRxBytes + diffTxBytes) / networkUpdateInterval)}b/s`);
|
|
141
141
|
let timeoutText = isTimeout ? chalk.green(`y`) : chalk.dim(`${Math.floor((timeElapsed)/1000)}/${(timeoutMs / 1000)}s`);
|
|
142
142
|
|
|
143
|
-
logger.
|
|
143
|
+
logger.debug(` ` + chalk.dim('redraw=') + redrawText + chalk.dim(' network=') + networkText + chalk.dim(' timeout=') + timeoutText);
|
|
144
144
|
|
|
145
145
|
if ((screenHasRedrawn && networkSettled) || isTimeout) {
|
|
146
|
-
logger.
|
|
146
|
+
logger.debug(` `);
|
|
147
147
|
resolve("true");
|
|
148
148
|
} else {
|
|
149
149
|
checkCondition(resolve, startTime, timeoutMs);
|
|
@@ -151,7 +151,7 @@ async function checkCondition(resolve, startTime, timeoutMs) {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
function wait(timeoutMs) {
|
|
154
|
-
logger.
|
|
154
|
+
logger.debug(` `);
|
|
155
155
|
return new Promise((resolve) => {
|
|
156
156
|
const startTime = Date.now();
|
|
157
157
|
checkCondition(resolve, startTime, timeoutMs);
|
package/lib/sdk.js
CHANGED
|
@@ -6,12 +6,12 @@ const version = 'v4.1.0';
|
|
|
6
6
|
const root = config["TD_API_ROOT"];
|
|
7
7
|
const axios = require('axios');
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const { logger } = require('./logger');
|
|
10
10
|
|
|
11
11
|
// let token = null;
|
|
12
12
|
|
|
13
13
|
const outputError = async (error) => {
|
|
14
|
-
|
|
14
|
+
logger.info(chalk.red(error.status), chalk.red(error.statusText));
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
const parseBody = async (response, body) => {
|
|
@@ -55,7 +55,7 @@ const parseBody = async (response, body) => {
|
|
|
55
55
|
}
|
|
56
56
|
return body;
|
|
57
57
|
} catch (err) {
|
|
58
|
-
|
|
58
|
+
logger.error(chalk.red("Parsing Error", err));
|
|
59
59
|
throw err;
|
|
60
60
|
}
|
|
61
61
|
};
|
|
@@ -64,7 +64,7 @@ let auth = async () => {
|
|
|
64
64
|
// data.apiKey = process.env.DASHCAM_API_KEY; @todo add-auth
|
|
65
65
|
|
|
66
66
|
// if (!data.apiKey) {
|
|
67
|
-
//
|
|
67
|
+
// logger.info(chalk.red('API key not found. Set DASHCAM_API_KEY in your environment.'));
|
|
68
68
|
// process.exit(1);
|
|
69
69
|
// }
|
|
70
70
|
|
|
@@ -98,7 +98,7 @@ const req = async (path, data, onChunk) => {
|
|
|
98
98
|
? [root, path].join("")
|
|
99
99
|
: [root, "api", version, "testdriver", path].join("/");
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
logger.debug(`making request to ${url}`);
|
|
102
102
|
|
|
103
103
|
const config = {
|
|
104
104
|
method: "post",
|
package/lib/subimage/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const Jimp = require("jimp");
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const cv = require("./opencv.js");
|
|
5
|
+
const { logger } = require("../logger");
|
|
5
6
|
|
|
6
7
|
async function findTemplateImage(haystack, needle, threshold) {
|
|
7
8
|
try {
|
|
@@ -54,8 +55,8 @@ async function findTemplateImage(haystack, needle, threshold) {
|
|
|
54
55
|
|
|
55
56
|
return positions;
|
|
56
57
|
} catch (err) {
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
logger.error(err);
|
|
59
|
+
logger.error("OpenCV threw an error");
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
|
package/lib/system.js
CHANGED
|
@@ -8,6 +8,8 @@ const robot = require("robotjs");
|
|
|
8
8
|
const sharp = require("sharp");
|
|
9
9
|
const { emitter, events } = require("./events.js");
|
|
10
10
|
|
|
11
|
+
const { logger } = require("./logger.js");
|
|
12
|
+
|
|
11
13
|
let primaryDisplay = null;
|
|
12
14
|
|
|
13
15
|
// get the primary display
|
|
@@ -126,7 +128,7 @@ const activeWin = async () => {
|
|
|
126
128
|
const activeWindow = await initializeActiveWindow();
|
|
127
129
|
return await activeWindow();
|
|
128
130
|
} catch (error) {
|
|
129
|
-
|
|
131
|
+
logger.error('Error getting active window: %s', error);
|
|
130
132
|
return null;
|
|
131
133
|
}
|
|
132
134
|
};
|