Chrome DevTools for coding agents
test: skip symlink cases without Windows privileges (#2667)
Wu Shuwen61a9bd2df2f7
diff --git a/tests/utils/files.test.ts b/tests/utils/files.test.tsindex 032064bb..342d42c5 100644--- a/tests/utils/files.test.ts+++ b/tests/utils/files.test.ts@@ -12,6 +12,29 @@ import {afterEach, beforeEach, describe, it} from 'node:test';import {resolveCanonicalPath} from '../../src/utils/files.js';+async function createSymlinkOrSkip(+ t: it.TestContext,+ target: string,+ symlinkPath: string,+ type?: 'dir' | 'file' | 'junction',+): Promise<boolean> {+ try {+ await fs.symlink(target, symlinkPath, type);+ return true;+ } catch (error) {+ if (+ os.platform() === 'win32' &&+ error instanceof Error &&+ 'code' in error &&+ (error.code === 'EPERM' || error.code === 'EACCES')+ ) {+ t.skip('creating symlinks requires additional privileges on Windows');+ return false;+ }+ throw error;+ }+}+describe('resolveCanonicalPath', () => {let tmpDir: string;let canonicalTmpDir: string;@@ -60,14 +83,17 @@ describe('resolveCanonicalPath', () => {);});- it('should resolve existing files with symlinks in path', async () => {+ it('should resolve existing files with symlinks in path', async t => {const targetDir = path.join(tmpDir, 'target');await fs.mkdir(targetDir);const targetFile = path.join(targetDir, 'file.txt');await fs.writeFile(targetFile, 'hello');const symlinkDir = path.join(tmpDir, 'symlink_dir');- await fs.symlink(targetDir, symlinkDir, 'dir');+ const created = await createSymlinkOrSkip(t, targetDir, symlinkDir, 'dir');+ if (!created) {+ return;+ }const filePathWithSymlink = path.join(symlinkDir, 'file.txt');@@ -76,12 +102,15 @@ describe('resolveCanonicalPath', () => {assert.strictEqual(resolved, path.join(canonicalTargetDir, 'file.txt'));});- it('should resolve non-existent files with symlinks in path', async () => {+ it('should resolve non-existent files with symlinks in path', async t => {const targetDir = path.join(tmpDir, 'target');await fs.mkdir(targetDir);const symlinkDir = path.join(tmpDir, 'symlink_dir');- await fs.symlink(targetDir, symlinkDir, 'dir');+ const created = await createSymlinkOrSkip(t, targetDir, symlinkDir, 'dir');+ if (!created) {+ return;+ }const filePathWithSymlink = path.join(symlinkDir, 'non-existent.txt');@@ -93,10 +122,17 @@ describe('resolveCanonicalPath', () => {);});- it('should resolve dangling symlink at the end of path', async () => {+ it('should resolve dangling symlink at the end of path', async t => {const nonExistentTarget = path.join(tmpDir, 'non-existent-target.txt');const danglingSymlink = path.join(tmpDir, 'dangling-symlink.txt');- await fs.symlink(nonExistentTarget, danglingSymlink);+ const created = await createSymlinkOrSkip(+ t,+ nonExistentTarget,+ danglingSymlink,+ );+ if (!created) {+ return;+ }const resolved = await resolveCanonicalPath(danglingSymlink);assert.strictEqual(@@ -105,10 +141,18 @@ describe('resolveCanonicalPath', () => {);});- it('should resolve path with a dangling symlink directory in the middle', async () => {+ it('should resolve path with a dangling symlink directory in the middle', async t => {const nonExistentTargetDir = path.join(tmpDir, 'non-existent-dir');const danglingSymlinkDir = path.join(tmpDir, 'dangling-dir');- await fs.symlink(nonExistentTargetDir, danglingSymlinkDir, 'dir');+ const created = await createSymlinkOrSkip(+ t,+ nonExistentTargetDir,+ danglingSymlinkDir,+ 'dir',+ );+ if (!created) {+ return;+ }const filePath = path.join(danglingSymlinkDir, 'file.txt');const resolved = await resolveCanonicalPath(filePath);