mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-04-09 16:19:25 -07:00
Address CodeRabbit follow-ups for PR 40
This commit is contained in:
@@ -460,6 +460,18 @@ function withAccessSyncStub(
|
||||
}
|
||||
}
|
||||
|
||||
function withRealpathSyncStub(resolvePath: (filePath: string) => string, run: () => void): void {
|
||||
const originalRealpathSync = fs.realpathSync;
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(fs as any).realpathSync = (filePath: string): string => resolvePath(filePath);
|
||||
run();
|
||||
} finally {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(fs as any).realpathSync = originalRealpathSync;
|
||||
}
|
||||
}
|
||||
|
||||
test('findAppBinary resolves ~/.local/bin/SubMiner.AppImage when it exists', { concurrency: false }, () => {
|
||||
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-test-home-'));
|
||||
const originalHomedir = os.homedir;
|
||||
@@ -527,6 +539,44 @@ test('findAppBinary finds subminer on PATH when AppImage candidates do not exist
|
||||
}
|
||||
});
|
||||
|
||||
test('findAppBinary excludes PATH matches that canonicalize to the launcher path', { concurrency: false }, () => {
|
||||
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-test-realpath-'));
|
||||
const originalHomedir = os.homedir;
|
||||
const originalPath = process.env.PATH;
|
||||
try {
|
||||
os.homedir = () => baseDir;
|
||||
const binDir = path.join(baseDir, 'bin');
|
||||
const wrapperPath = path.join(binDir, 'subminer');
|
||||
const canonicalPath = path.join(baseDir, 'launch', 'subminer');
|
||||
makeExecutable(wrapperPath);
|
||||
process.env.PATH = `${binDir}${path.delimiter}${originalPath ?? ''}`;
|
||||
|
||||
withFindAppBinaryPlatformSandbox('linux', (pathModule) => {
|
||||
withAccessSyncStub(
|
||||
(filePath) => filePath === wrapperPath,
|
||||
() => {
|
||||
withRealpathSyncStub(
|
||||
(filePath) => {
|
||||
if (filePath === canonicalPath || filePath === wrapperPath) {
|
||||
return canonicalPath;
|
||||
}
|
||||
return filePath;
|
||||
},
|
||||
() => {
|
||||
const result = findAppBinary(canonicalPath, pathModule);
|
||||
assert.equal(result, null);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
} finally {
|
||||
os.homedir = originalHomedir;
|
||||
process.env.PATH = originalPath;
|
||||
fs.rmSync(baseDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('findAppBinary resolves Windows install paths when present', { concurrency: false }, () => {
|
||||
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-test-win-'));
|
||||
const originalHomedir = os.homedir;
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
uniqueNormalizedLangCodes,
|
||||
sleep,
|
||||
normalizeLangCode,
|
||||
realpathMaybe,
|
||||
} from './util.js';
|
||||
|
||||
export const state = {
|
||||
@@ -380,8 +381,8 @@ export function findAppBinary(selfPath: string, pathModule: PathModule = path):
|
||||
);
|
||||
|
||||
if (fromPath) {
|
||||
const resolvedSelf = pathModule.resolve(selfPath);
|
||||
const resolvedCandidate = pathModule.resolve(fromPath);
|
||||
const resolvedSelf = realpathMaybe(selfPath);
|
||||
const resolvedCandidate = realpathMaybe(fromPath);
|
||||
if (resolvedSelf !== resolvedCandidate) return fromPath;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user