Files
rea/src/artifacts/hostExecutableMarking.ts
T
Kaoru0822andClaude Opus 5.5 91f843bf38 fix(artifacts): mark Windows host executables by extension (#1823)
Windows has no POSIX execute bit; Node reports file modes from the
read-only attribute alone, so every host file, including PE images,
reported `executable: false` while the same occurrence reported
`artifact_kind: executable`. Derive the host executable marking once:
POSIX permission bits stay authoritative, and Windows marks regular
files with the CreateProcess/cmd launchable extensions.

Fixes #1819

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 06:26:30 -07:00

23 lines
836 B
TypeScript

import type { Stats } from "node:fs";
import { extname } from "node:path";
/** Extensions Windows launches directly through CreateProcess or cmd.exe. */
const windowsLaunchableExtensions = new Set([".bat", ".cmd", ".com", ".exe"]);
/**
* Whether a host filesystem entry carries the host's executable marking.
*
* POSIX hosts mark executability with permission bits. Windows has no execute
* bit (Node reports file modes from the read-only attribute alone), so it marks
* launchable files by extension instead.
*/
export const hostExecutableMarking = (
path: string,
metadata: Pick<Stats, "mode" | "isFile">,
platform: NodeJS.Platform = process.platform,
): boolean =>
platform === "win32"
? metadata.isFile() &&
windowsLaunchableExtensions.has(extname(path).toLowerCase())
: (metadata.mode & 0o111) !== 0;