Files
reverse-engineering-anything/src/desktop/ProgramLookup.ts
T
8c3dbd99e1 fix(desktop): bind dconf profiles to selected database sources (#11161)
* fix(desktop): bind dconf profiles to selected database sources

* fix(desktop): resolve dconf before changing working directory

* fix(desktop): retain refused dconf lookup diagnostics

* fix(desktop): preserve execution-time dconf search fallback

* fix(desktop): keep host spawn failures outside dconf fallback

* fix(desktop): retain staged reader cleanup through command close

* test(kuna): await eviction boundary events explicitly

* test(kuna): bound lifecycle acknowledgements through shared owner

Cherry-picked shared follow-up from a5761c7545.

* fix(desktop): keep dconf sources independent of wrapper stdin

* test(desktop): restrict procfs command checks to Linux

* fix(desktop): own dconf wrapper cleanup before source retirement

* fix(desktop): retain dconf preparation inspection owners

* fix(desktop): classify dconf read failures by kind and errno

Record the failure kind, host errno, exit status, selected command, and
child stderr on DconfDump, and carry those facts to view_failure. Tests
assert the typed fields instead of error prose, including a PATH refusal
whose executable is not the last candidate.

* test(desktop): gate real dconf diagnostics on Linux

The real reader checks /proc file descriptors before launch, so macOS
reports descriptor-unavailable/ENOENT instead of launch-failed/EACCES.
Keep that launch refusal on Linux and cover the Evidence contract with
a mocked reader on every platform.

Co-authored-by: morluto <morluto@users.noreply.github.com>

---------

Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: morluto <morluto@users.noreply.github.com>
2026-11-19 11:40:08 -05:00

55 lines
1.7 KiB
TypeScript

import { constants } from "node:fs";
import { access, stat } from "node:fs/promises";
import { absoluteCallerPath } from "../filesystem/callerPath.js";
import { posixPathCandidates } from "../process/executableSearch.js";
import type { FoundProgram } from "../ports/DesktopApplicationSession.js";
const isExecutable = async (path: string): Promise<boolean> => {
try {
await access(path, constants.X_OK);
return (await stat(path)).isFile();
} catch {
return false;
}
};
/** Candidate spellings in launch order, anchored without reserializing PATH. */
export function* programCandidates(
program: string,
environment: Readonly<Record<string, string | undefined>>,
startedIn: string,
): IterableIterator<FoundProgram> {
if (program.includes("/")) {
yield {
path: absoluteCallerPath(program, { cwd: startedIn }),
fromRelativeEntry: false,
};
return;
}
if (environment.PATH === undefined) return;
for (const candidate of posixPathCandidates(program, environment.PATH, {
relativeEntries: "resolve",
workingDirectory: startedIn,
}))
yield {
path: candidate.path,
fromRelativeEntry: candidate.relativeEntry,
};
}
/**
* Inspect availability in the original launch context. This does not establish
* that execution will succeed: an executable can have a missing interpreter.
* Callers that launch must retain execution-time PATH fallback themselves.
*/
export const resolveProgram = async (
program: string,
environment: Readonly<Record<string, string | undefined>>,
startedIn: string,
): Promise<FoundProgram | undefined> => {
for (const candidate of programCandidates(program, environment, startedIn))
if (await isExecutable(candidate.path)) return candidate;
return undefined;
};