automation_model 1.0.783-dev → 1.0.784-dev
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/lib/file_checker.js +25 -89
- package/lib/file_checker.js.map +1 -1
- package/package.json +1 -1
package/lib/file_checker.js
CHANGED
|
@@ -1,118 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { promises as fsAsync } from "fs"; // async fs
|
|
1
|
+
import fs from "fs";
|
|
3
2
|
import { _commandError, _commandFinally, _preCommand } from "./command_common.js";
|
|
4
3
|
import { Types } from "./stable_browser.js";
|
|
5
4
|
const checkFileAccess = (filePath, accessMode) => {
|
|
6
|
-
return new Promise((resolve) => {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
7
6
|
fs.access(filePath, accessMode, (err) => {
|
|
8
|
-
|
|
7
|
+
if (err) {
|
|
8
|
+
resolve(false);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
resolve(true);
|
|
12
|
+
}
|
|
9
13
|
});
|
|
10
14
|
});
|
|
11
15
|
};
|
|
12
16
|
const getFileName = (filePath) => {
|
|
13
17
|
const platform = process.platform;
|
|
14
|
-
|
|
18
|
+
let fileName = "";
|
|
19
|
+
if (platform === "win32") {
|
|
20
|
+
fileName = filePath.split("\\").pop() || "";
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
fileName = filePath.split("/").pop() || "";
|
|
24
|
+
}
|
|
25
|
+
return fileName;
|
|
15
26
|
};
|
|
16
|
-
// Simplified regex check
|
|
17
|
-
function testForRegex(text) {
|
|
18
|
-
return text.startsWith("regex:");
|
|
19
|
-
}
|
|
20
27
|
export const verifyFileExists = async (filePath, options, context, world) => {
|
|
21
|
-
if
|
|
28
|
+
//First check if the file exists and is accessible
|
|
29
|
+
if (!options) {
|
|
22
30
|
options = {};
|
|
23
|
-
const fileName = getFileName(filePath);
|
|
24
|
-
let isSoft = false;
|
|
25
|
-
const match = filePath.match(/(soft:)?(regex:|exact:|contains:)(.*)/);
|
|
26
|
-
if (match) {
|
|
27
|
-
isSoft = !!match[1]; // true if 'soft:' is present
|
|
28
31
|
}
|
|
32
|
+
const fileName = getFileName(filePath);
|
|
29
33
|
const state = {
|
|
30
34
|
locate: false,
|
|
31
35
|
scroll: false,
|
|
32
36
|
screenshot: false,
|
|
33
37
|
highlight: false,
|
|
34
|
-
throwError:
|
|
38
|
+
throwError: true,
|
|
35
39
|
operation: "verifyFileExists",
|
|
36
40
|
value: filePath,
|
|
37
41
|
text: `Verify file ${fileName} exists`,
|
|
38
42
|
options,
|
|
39
43
|
type: Types.VERIFY_FILE_EXISTS,
|
|
40
|
-
world
|
|
44
|
+
world
|
|
41
45
|
};
|
|
42
46
|
await _preCommand(state, context.web);
|
|
47
|
+
let fileAccessible = false;
|
|
43
48
|
try {
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
let dir;
|
|
49
|
-
let input;
|
|
50
|
-
if (pathToMatch.includes("regex:")) {
|
|
51
|
-
const regexIndex = pathToMatch.indexOf("regex:");
|
|
52
|
-
dir = pathToMatch.substring(0, regexIndex - 1); // remove trailing slash
|
|
53
|
-
input = pathToMatch.substring(regexIndex);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
const lastSlashIndex = pathToMatch.lastIndexOf("/");
|
|
57
|
-
dir = pathToMatch.substring(0, lastSlashIndex);
|
|
58
|
-
input = pathToMatch.substring(lastSlashIndex + 1);
|
|
59
|
-
}
|
|
60
|
-
if (isSoft) {
|
|
61
|
-
dir = dir.slice(0, -5);
|
|
62
|
-
}
|
|
63
|
-
const files = await fsAsync.readdir(dir);
|
|
64
|
-
let found = false;
|
|
65
|
-
if (input.startsWith("exact:")) {
|
|
66
|
-
const target = input.replace("exact:", "");
|
|
67
|
-
found = files.includes(target);
|
|
68
|
-
}
|
|
69
|
-
else if (input.startsWith("contains:")) {
|
|
70
|
-
const target = input.replace("contains:", "");
|
|
71
|
-
found = files.some((f) => f.includes(target));
|
|
72
|
-
}
|
|
73
|
-
else if (input.startsWith("format:")) {
|
|
74
|
-
const extension = input.replace("format:", "");
|
|
75
|
-
found = files.some((f) => f.endsWith(`.${extension}`));
|
|
76
|
-
}
|
|
77
|
-
else if (testForRegex(input)) {
|
|
78
|
-
let raw = input.replace("regex:", "").trim(); // e.g. "/file/i" or "file.*::i"
|
|
79
|
-
let pattern = raw;
|
|
80
|
-
let flags = "";
|
|
81
|
-
if (raw.startsWith("/") && raw.lastIndexOf("/") > 0) {
|
|
82
|
-
const lastSlash = raw.lastIndexOf("/");
|
|
83
|
-
flags = raw.substring(lastSlash + 1);
|
|
84
|
-
pattern = raw.substring(1, lastSlash);
|
|
85
|
-
}
|
|
86
|
-
else if (raw.includes("::")) {
|
|
87
|
-
[pattern, flags] = raw.split("::");
|
|
88
|
-
}
|
|
89
|
-
console.log(`Regex pattern: ${pattern}, flags: ${flags}`);
|
|
90
|
-
try {
|
|
91
|
-
const regex = new RegExp(pattern, flags);
|
|
92
|
-
found = files.some((f) => {
|
|
93
|
-
const matched = regex.test(f);
|
|
94
|
-
return matched;
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
catch (regexError) {
|
|
98
|
-
throw new Error(`Invalid regex pattern: ${pattern}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
// Fallback to exact path check
|
|
103
|
-
found = await checkFileAccess(pathToMatch, fs.constants.F_OK);
|
|
104
|
-
}
|
|
105
|
-
if (!found) {
|
|
106
|
-
console.log(`Available files in '${dir}':`, files);
|
|
107
|
-
if (!isSoft) {
|
|
108
|
-
throw new Error(`No file matched the pattern: ${filePath}`);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
console.warn(`Soft assertion failed for pattern: ${filePath}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
console.log(`File verification successful for pattern: ${input}`);
|
|
49
|
+
fileAccessible = await checkFileAccess(filePath, fs.constants.F_OK);
|
|
50
|
+
if (!fileAccessible) {
|
|
51
|
+
throw new Error(`File ${fileName} does not exist or is not accessible.`);
|
|
116
52
|
}
|
|
117
53
|
}
|
|
118
54
|
catch (err) {
|
package/lib/file_checker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file_checker.js","sourceRoot":"","sources":["../../src/file_checker.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"file_checker.js","sourceRoot":"","sources":["../../src/file_checker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AAEnB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjF,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAG3C,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,UAAkB,EAAoB,EAAE;IAC/E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE;YACpC,IAAI,GAAG,EAAE,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,CAAC;YACnB,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,CAAC;YAClB,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CACA,CAAC;AACN,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,IAAI,QAAQ,GAAG,EAAE,CAAC;IAClB,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACvB,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;IAChD,CAAC;SAAM,CAA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