mirror of
https://github.com/affaan-m/ECC.git
synced 2026-10-26 18:35:05 +00:00
fix: normalize trailing Windows paths and spaced filenames
(cherry picked from commit c31b1dd80c)
This commit is contained in:
1 parent
0931f66775
commit
58b191c25d
2 files changed
+20
-5
No files matched your search
@@ -21,10 +21,11 @@ function normalizeFailureReason(reason) {
|
||||
.replace(/\d{4}-\d{2}-\d{2}[t ]\d{2}:\d{2}:\d{2}[.\dz]*/g, '<timestamp>')
|
||||
// Strip UUIDs (already lowercased)
|
||||
.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/g, '<uuid>')
|
||||
// Quoting disambiguates spaces in the final Windows path component.
|
||||
// Quoted Windows paths preserve spaces in the final path component.
|
||||
.replace(/(["'])(?:[a-z]:[\\/]|\\\\)[^\r\n]*?\1/gu, '$1<path>$1')
|
||||
// Directories may contain spaces, but trailing whitespace separates diagnostic prose.
|
||||
.replace(/(?:\b[a-z]:|\\)[\\/](?:[^\\/:*?"<>|\r\n]*[^\s\\/:*?"<>|][\\/])*[^\s\\/:*?"<>|(),;]+/gu, '<path>')
|
||||
// A colon delimits spaced leaves; trailing separators belong to the path.
|
||||
.replace(/(?:\b[a-z]:|\\)[\\/](?:[^\\/:*?"<>|\r\n]*[^\s\\/:*?"<>|][\\/])*[^\s\\/:*?"<>|(),;]+(?: [^\\/:*?"<>|\r\n]+(?=:))?[\\/]*/gu, '<path>')
|
||||
// Strip remaining file paths
|
||||
.replace(/(?:\b[a-z]:)?[\\/][\w./\\-]+/g, '<path>')
|
||||
// Collapse whitespace
|
||||
|
||||
@@ -66,6 +66,9 @@ async function runTests() {
|
||||
String.raw`File not found: \\server\share\three.js`,
|
||||
String.raw`File not found: C:/project-a\src\one.js`,
|
||||
String.raw`File not found: D:\project-b/src/two.js`,
|
||||
'File not found: C:\\project-a\\',
|
||||
'File not found: D:/project-b/',
|
||||
'File not found: \\\\server\\share\\',
|
||||
]) {
|
||||
assert.strictEqual(normalizeFailureReason(reason), 'file not found: <path>');
|
||||
}
|
||||
@@ -97,6 +100,9 @@ async function runTests() {
|
||||
String.raw`C:\Program Files\node`,
|
||||
'D:/Program Files/node',
|
||||
String.raw`\\server\shared files\node`,
|
||||
String.raw`C:\Users\Alice Smith\my file.js`,
|
||||
'D:/Users/Bob Jones/your script.js',
|
||||
String.raw`\\server\shared files\other task.js`,
|
||||
]) {
|
||||
assert.strictEqual(normalizeFailureReason(`${filePath}: permission denied`), '<path>: permission denied');
|
||||
}
|
||||
@@ -108,6 +114,8 @@ async function runTests() {
|
||||
'cannot run <path> failed to open <path>');
|
||||
assert.strictEqual(normalizeFailureReason('D:/Program Files/node permission denied in /tmp/log'),
|
||||
'<path> permission denied in <path>');
|
||||
assert.strictEqual(normalizeFailureReason('Cannot run C:/tools/node failed to open /tmp/log: permission denied'),
|
||||
'cannot run <path> failed to open <path>: permission denied');
|
||||
})) passed += 1; else failed += 1;
|
||||
|
||||
if (await test('groupFailures groups by skillId and normalized reason', async () => {
|
||||
@@ -214,15 +222,21 @@ async function runTests() {
|
||||
|
||||
if (await test('detectPatterns groups failures from different Windows paths', async () => {
|
||||
const runs = [
|
||||
makeSkillRun({ id: 'r1', failureReason: String.raw`Cannot open C:\Users\Alice Smith\one.js: permission denied` }),
|
||||
makeSkillRun({ id: 'r2', failureReason: 'Cannot open D:/Users/Bob Jones/two.js: permission denied' }),
|
||||
makeSkillRun({ id: 'r3', failureReason: String.raw`Cannot open E:\Users\Carol White\three.js: permission denied` }),
|
||||
makeSkillRun({ id: 'r1', failureReason: String.raw`Cannot open C:\Users\Alice Smith\my file.js: permission denied` }),
|
||||
makeSkillRun({ id: 'r2', failureReason: 'Cannot open D:/Users/Bob Jones/your script.js: permission denied' }),
|
||||
makeSkillRun({ id: 'r3', failureReason: String.raw`Cannot open E:\Users\Carol White\other task.js: permission denied` }),
|
||||
];
|
||||
const patterns = detectPatterns(runs);
|
||||
assert.strictEqual(patterns.length, 1);
|
||||
assert.strictEqual(patterns[0].count, 3);
|
||||
assert.strictEqual(patterns[0].normalizedReason, 'cannot open <path>: permission denied');
|
||||
assert.strictEqual(inspect({ getStatus: () => ({ skillRuns: { recent: runs } }) }).status, 'attention_needed');
|
||||
const directoryRuns = ['C:\\project-a\\', 'D:/project-b/', '\\\\server\\share\\'].map((filePath, index) =>
|
||||
makeSkillRun({ id: `directory-${index}`, failureReason: `Cannot open ${filePath}` }));
|
||||
const directoryPatterns = detectPatterns(directoryRuns);
|
||||
assert.strictEqual(directoryPatterns.length, 1);
|
||||
assert.strictEqual(directoryPatterns[0].count, 3);
|
||||
assert.strictEqual(generateReport(directoryPatterns).status, 'attention_needed');
|
||||
})) passed += 1; else failed += 1;
|
||||
|
||||
if (await test('detectPatterns tracks unique session IDs and versions', async () => {
|
||||
|
||||
Reference in new issue
Block a user