automation_model 1.0.681-stage → 1.0.682-stage
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 +89 -25
- package/lib/file_checker.js.map +1 -1
- package/package.json +1 -1
package/lib/file_checker.js
CHANGED
|
@@ -1,54 +1,118 @@
|
|
|
1
|
-
import fs from "fs";
|
|
1
|
+
import * as fs from "fs"; // sync fs
|
|
2
|
+
import { promises as fsAsync } from "fs"; // async fs
|
|
2
3
|
import { _commandError, _commandFinally, _preCommand } from "./command_common.js";
|
|
3
4
|
import { Types } from "./stable_browser.js";
|
|
4
5
|
const checkFileAccess = (filePath, accessMode) => {
|
|
5
|
-
return new Promise((resolve
|
|
6
|
+
return new Promise((resolve) => {
|
|
6
7
|
fs.access(filePath, accessMode, (err) => {
|
|
7
|
-
|
|
8
|
-
resolve(false);
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
resolve(true);
|
|
12
|
-
}
|
|
8
|
+
resolve(!err);
|
|
13
9
|
});
|
|
14
10
|
});
|
|
15
11
|
};
|
|
16
12
|
const getFileName = (filePath) => {
|
|
17
13
|
const platform = process.platform;
|
|
18
|
-
|
|
19
|
-
if (platform === "win32") {
|
|
20
|
-
fileName = filePath.split("\\").pop() || "";
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
fileName = filePath.split("/").pop() || "";
|
|
24
|
-
}
|
|
25
|
-
return fileName;
|
|
14
|
+
return platform === "win32" ? filePath.split("\\").pop() || "" : filePath.split("/").pop() || "";
|
|
26
15
|
};
|
|
16
|
+
// Simplified regex check
|
|
17
|
+
function testForRegex(text) {
|
|
18
|
+
return text.startsWith("regex:");
|
|
19
|
+
}
|
|
27
20
|
export const verifyFileExists = async (filePath, options, context, world) => {
|
|
28
|
-
|
|
29
|
-
if (!options) {
|
|
21
|
+
if (!options)
|
|
30
22
|
options = {};
|
|
31
|
-
}
|
|
32
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
|
+
}
|
|
33
29
|
const state = {
|
|
34
30
|
locate: false,
|
|
35
31
|
scroll: false,
|
|
36
32
|
screenshot: false,
|
|
37
33
|
highlight: false,
|
|
38
|
-
throwError:
|
|
34
|
+
throwError: !isSoft, // don't throw error for soft assertions
|
|
39
35
|
operation: "verifyFileExists",
|
|
40
36
|
value: filePath,
|
|
41
37
|
text: `Verify file ${fileName} exists`,
|
|
42
38
|
options,
|
|
43
39
|
type: Types.VERIFY_FILE_EXISTS,
|
|
44
|
-
world
|
|
40
|
+
world,
|
|
45
41
|
};
|
|
46
42
|
await _preCommand(state, context.web);
|
|
47
|
-
let fileAccessible = false;
|
|
48
43
|
try {
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
|
|
44
|
+
let pathToMatch = filePath;
|
|
45
|
+
if (isSoft) {
|
|
46
|
+
pathToMatch = filePath.replace(/^soft:/, ""); // remove soft: prefix for parsing
|
|
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}`);
|
|
52
116
|
}
|
|
53
117
|
}
|
|
54
118
|
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,EAAE,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"file_checker.js","sourceRoot":"","sources":["../../src/file_checker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC,UAAU;AAEpC,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC,WAAW;AACrD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,UAAkB,EAAoB,EAAE;IACjF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE;YACtC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,G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