Skip to content

Commit a4de4d1

Browse files
committed
fix absolute path handling
1 parent 1822a1a commit a4de4d1

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

packages/code-analyzer-core/test/suppressions/bulk-suppression-processor.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ import {
99
} from '../../src/suppressions/bulk-suppression-processor';
1010
import { BulkSuppressionRule } from '../../src/config';
1111
import * as path from 'node:path';
12+
import * as os from 'node:os';
13+
14+
/**
15+
* Helper to create platform-appropriate absolute paths for testing
16+
* On Windows: C:\workspace\...
17+
* On Unix: /workspace/...
18+
*/
19+
function createTestAbsolutePath(...segments: string[]): string {
20+
if (os.platform() === 'win32') {
21+
// Windows: start with C:\ drive
22+
return path.join('C:', path.sep, ...segments);
23+
} else {
24+
// Unix: start with /
25+
return path.join(path.sep, ...segments);
26+
}
27+
}
1228
import { Violation, CodeLocation } from '../../src/results';
1329
import { Rule, SeverityLevel } from '../../src/rules';
1430

@@ -121,7 +137,7 @@ class MockViolation implements Violation {
121137
}
122138

123139
describe('applyBulkSuppressions', () => {
124-
const workspaceRoot = path.join(path.sep, 'workspace');
140+
const workspaceRoot = createTestAbsolutePath('workspace');
125141

126142
describe('Basic suppression scenarios', () => {
127143
it('should suppress violations matching rule selector with no quota limit', () => {

packages/code-analyzer-core/test/suppressions/bulk-suppression-workspace-root.test.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ import {BulkSuppressionRule} from "../../src/config";
33
import {Violation, CodeLocation} from "../../src/results";
44
import {RuleImpl} from "../../src/rules";
55
import * as path from 'node:path';
6+
import * as os from 'node:os';
7+
8+
/**
9+
* Helper to create platform-appropriate absolute paths for testing
10+
* On Windows: C:\Users\...
11+
* On Unix: /Users/...
12+
*/
13+
function createTestAbsolutePath(...segments: string[]): string {
14+
if (os.platform() === 'win32') {
15+
// Windows: start with C:\ drive
16+
return path.join('C:', path.sep, ...segments);
17+
} else {
18+
// Unix: start with /
19+
return path.join(path.sep, ...segments);
20+
}
21+
}
622

723
/**
824
* Tests specifically for Bug #2: Workspace Root vs Config Root inconsistency
@@ -80,7 +96,7 @@ describe('Bulk Suppressions - Workspace Root Path Resolution (Bug #2)', () => {
8096
*/
8197
it('BUG #2: Paths in config are resolved relative to WORKSPACE ROOT, not config file location', () => {
8298
// Workspace root (where -w flag points) - use platform-appropriate paths
83-
const workspaceRoot = path.join(path.sep, 'Users', 'user', 'workspace', 'dreamhouse');
99+
const workspaceRoot = createTestAbsolutePath('Users', 'user', 'workspace', 'dreamhouse');
84100

85101
// Violation file path (absolute) - use platform-appropriate paths
86102
const violationFilePath = path.join(workspaceRoot, 'force-app', 'main', 'default', 'react-components', 'utils.js');
@@ -115,7 +131,7 @@ describe('Bulk Suppressions - Workspace Root Path Resolution (Bug #2)', () => {
115131

116132
it('BUG #2: Same directory level - workspace root equals config directory (worked before bug fix)', () => {
117133
// This case worked even with Bug #2 because workspace root === config root
118-
const workspaceRoot = path.join(path.sep, 'Users', 'user', 'workspace', 'project');
134+
const workspaceRoot = createTestAbsolutePath('Users', 'user', 'workspace', 'project');
119135
const violationFilePath = path.join(workspaceRoot, 'utils.js');
120136

121137
const violation = new MockViolation(
@@ -171,7 +187,7 @@ describe('Bulk Suppressions - Workspace Root Path Resolution (Bug #2)', () => {
171187
});
172188

173189
it('BUG #2: Multiple files at different levels all resolve correctly from workspace root', () => {
174-
const workspaceRoot = path.join(path.sep, 'workspace', 'project');
190+
const workspaceRoot = createTestAbsolutePath('workspace', 'project');
175191

176192
// Violations at different directory levels
177193
const violation1 = new MockViolation(
@@ -219,7 +235,7 @@ describe('Bulk Suppressions - Workspace Root Path Resolution (Bug #2)', () => {
219235
});
220236

221237
it('BUG #2: Folder-level suppression from workspace root matches nested files', () => {
222-
const workspaceRoot = path.join(path.sep, 'workspace', 'project');
238+
const workspaceRoot = createTestAbsolutePath('workspace', 'project');
223239

224240
// Violations in nested folder
225241
const violation1 = new MockViolation(
@@ -256,7 +272,7 @@ describe('Bulk Suppressions - Workspace Root Path Resolution (Bug #2)', () => {
256272

257273
it('Config paths can be relative to workspace root (recommended)', () => {
258274
// This test documents the recommended usage: paths relative to workspace root
259-
const workspaceRoot = path.join(path.sep, 'workspace', 'project');
275+
const workspaceRoot = createTestAbsolutePath('workspace', 'project');
260276
const violationFilePath = path.join(workspaceRoot, 'src', 'file.js');
261277

262278
const violation = new MockViolation(
@@ -287,7 +303,7 @@ describe('Bulk Suppressions - Workspace Root Path Resolution (Bug #2)', () => {
287303
* - Both resolve paths relative to workspace root
288304
* - Both fall back to absolute paths if workspace root is null
289305
*/
290-
const workspaceRoot = path.join(path.sep, 'Users', 'user', 'dreamhouse');
306+
const workspaceRoot = createTestAbsolutePath('Users', 'user', 'dreamhouse');
291307

292308
// Imagine ignores config: ["force-app/test/**"]
293309
// Imagine bulk suppressions: "force-app/main/default/utils.js"

0 commit comments

Comments
 (0)