From 6dadd30fb685e39d9f2f8eaca6d8b3900b7af6a7 Mon Sep 17 00:00:00 2001
From: morluto <76467478+morluto@users.noreply.github.com>
Date: Mon, 23 Nov 2026 18:00:43 -0500
Subject: [PATCH] fix(javascript): route directories by JavaScript input
presence and name directory-capable operations (#14186)
* fix(javascript): refuse directories without JavaScript inputs and name directory-capable operations
`analyze
` routed every non-bundle directory to the static JavaScript
lane, which reported an all-zero Electron summary as success for native
build output. The JavaScript lane now owns that applicability decision from
its complete inventory: when coverage is complete and no JavaScript, HTML,
package.json, source map, or nested ASAR input exists, it returns a typed
unsupported_target refusal naming inspect_desktop_application,
audit_release_exposure, inspect_artifact, and open_binary. Incomplete
coverage or unavailable files of unknown kind stay unknown and proceed.
The directory_requires_file refusal no longer claims to come from
open_binary when another operation (inspect, inspect-artifact) admitted the
target, and it names the directory-capable operations instead of only the
JavaScript lane.
* fix(javascript): keep empty directories analyzable and report routing facts for non-JavaScript ones
Owner decision on #14186: an empty directory is "nothing to analyze", not
"unsupported". The JavaScript lane now classifies application-input
presence once, in the domain owner of its file facts
(javaScriptApplicationInputPresence): present, empty, absent, or unknown.
- empty (complete traversal, no non-directory entries): analysis succeeds
as before and the graph carries an explicit "No JavaScript inputs were
found" limitation naming the next operations.
- absent (complete traversal, entries but no JavaScript, HTML,
package.json, source map, or nested ASAR): the typed unsupported_target
refusal now carries bounded diagnostics from the inventory the lane
already read: inventoried_entries, entries_by_format, json_files and
native_addon_files. No paths are retained.
- unknown (incomplete traversal or unavailable file of unknown kind) and
present: unchanged analysis.
Reverts the fixture edits that added package.json to empty directories.
---
.../JavaScriptArtifactGraphBuilder.ts | 18 ++++-
.../JavaScriptArtifactReconstruction.ts | 17 ++++
src/domain/analysisErrorPresentation.ts | 12 ++-
.../javascript/javascriptArtifactFiles.ts | 81 +++++++++++++++++++
.../cli/analyzeAppBundlePathCli.test.ts | 78 +++++++++++++++++-
tests/boundary/cli/rawBinaryCli.test.ts | 8 +-
...avascriptApplicationInputSelection.test.ts | 66 +++++++++++++++
.../filesystem/targetDiagnostics.test.ts | 8 +-
8 files changed, 281 insertions(+), 7 deletions(-)
diff --git a/src/application/javascript/JavaScriptArtifactGraphBuilder.ts b/src/application/javascript/JavaScriptArtifactGraphBuilder.ts
index 3fbcc1915d2..d4a2167d825 100644
--- a/src/application/javascript/JavaScriptArtifactGraphBuilder.ts
+++ b/src/application/javascript/JavaScriptArtifactGraphBuilder.ts
@@ -15,7 +15,10 @@ import {
type JavaScriptApplicationGraph,
} from "../../domain/javascript/javascriptApplicationGraph.js";
import type { JavaScriptArtifactAnalysis } from "./JavaScriptArtifactAnalysisTypes.js";
-import type { JavaScriptArtifactFileSet } from "../../domain/javascript/javascriptArtifactFiles.js";
+import {
+ javaScriptApplicationInputPresence,
+ type JavaScriptArtifactFileSet,
+} from "../../domain/javascript/javascriptArtifactFiles.js";
import { JavaScriptArtifactGraphAccumulator } from "./JavaScriptArtifactGraphAccumulator.js";
import {
HTML_INLINE_SCRIPT_LOCATION_COVERAGE_LIMIT,
@@ -400,6 +403,18 @@ const semanticResourceLimits = (
...new Set(semanticResourceBounds(context).map(({ limit }) => limit)),
].sort();
+/** Complete traversal found no entries, so there was nothing to analyze. */
+const EMPTY_INPUT_LIMITATION =
+ "No JavaScript inputs were found: the complete inventory contains no files. Select the directory or .asar that holds the application sources; for a desktop installation directory, call inspect_desktop_application or audit_release_exposure.";
+
+const emptyInputLimitations = (
+ context: JavaScriptArtifactGraphContext,
+): readonly string[] =>
+ javaScriptApplicationInputPresence(context.fileSet, context.snapshot) ===
+ "empty"
+ ? [EMPTY_INPUT_LIMITATION]
+ : [];
+
const graphLimitations = (
context: JavaScriptArtifactGraphContext,
coverage: "complete" | "partial" | "unknown" | "unavailable",
@@ -419,6 +434,7 @@ const graphLimitations = (
`Caller-selected source analysis leaves ${String(context.fileSet.source_selection?.unselected_files)} inventoried files outside analysis scope. Inventory identity covers the complete artifact; relationships through unselected sources remain unknown.`,
]),
...context.snapshot.limitations,
+ ...emptyInputLimitations(context),
...context.snapshot.integrity_contradictions.map(
({ logical_path: path }) =>
`Artifact integrity metadata contradicts observed bytes at ${path}; the observed bytes are untrusted.`,
diff --git a/src/application/javascript/JavaScriptArtifactReconstruction.ts b/src/application/javascript/JavaScriptArtifactReconstruction.ts
index 9ab7dacdafc..812e88a051c 100644
--- a/src/application/javascript/JavaScriptArtifactReconstruction.ts
+++ b/src/application/javascript/JavaScriptArtifactReconstruction.ts
@@ -30,6 +30,11 @@ import { createJavaScriptArtifactReader as createReader } from "../../artifacts/
import type { JavaScriptApplicationGraph } from "../../domain/javascript/javascriptApplicationGraph.js";
import type { JavaScriptSemanticGraph } from "../../domain/javascript/javascriptSemanticGraph.js";
import type { JavaScriptSourceSelection } from "../../domain/javascript/javascriptSourceSelection.js";
+import {
+ JAVASCRIPT_ABSENT_INPUT_OPERATIONS,
+ javaScriptAbsentInputDiagnostics,
+ javaScriptApplicationInputPresence,
+} from "../../domain/javascript/javascriptArtifactFiles.js";
import {
parseOwnedJavaScriptApplicationAnalysisSteps,
type AnalyzeJavaScriptApplicationInput,
@@ -170,6 +175,18 @@ export const reconstructJavaScriptArtifact = async (
kind: "artifact-inventory",
inventory: snapshot,
});
+ if (javaScriptApplicationInputPresence(files, snapshot) === "absent")
+ throw new AnalysisUnsupportedTargetError(
+ OPERATION,
+ path,
+ "the complete inventory has entries but no JavaScript, HTML, package.json, source map, or nested ASAR inputs",
+ {
+ diagnostics: javaScriptAbsentInputDiagnostics(files, snapshot),
+ remediationAction:
+ "Route by details.diagnostics.entries_by_format. For a native build or installation directory, call inspect_desktop_application or audit_release_exposure with the directory, or select one member file with inspect_artifact or open_binary.",
+ related: { operations: [...JAVASCRIPT_ABSENT_INPUT_OPERATIONS] },
+ },
+ );
await reportPhase(
"parse_javascript_sources",
`Processing ${String(files.files.length - (files.source_selection?.unselected_files ?? 0))} selected application files`,
diff --git a/src/domain/analysisErrorPresentation.ts b/src/domain/analysisErrorPresentation.ts
index 2ad3810f3f4..6470e4a3ba7 100644
--- a/src/domain/analysisErrorPresentation.ts
+++ b/src/domain/analysisErrorPresentation.ts
@@ -179,7 +179,7 @@ export const analysisErrorRemediationAction = (
error instanceof BinaryTargetError &&
error.constraint === "directory_requires_file"
)
- return `For a JavaScript/Electron application directory, call analyze_javascript_application with input_path. For binary analysis, select its executable file or an Apple bundle directory (${OPENABLE_APPLE_BUNDLE_TYPES_TEXT}).`;
+ return `For a desktop installation or native build directory, call inspect_desktop_application or audit_release_exposure with the directory; for a JavaScript/Electron application directory, call analyze_javascript_application with input_path. To analyze one program, select its file or an Apple bundle directory (${OPENABLE_APPLE_BUNDLE_TYPES_TEXT}).`;
if (
error instanceof BinaryTargetError &&
error.constraint === "bundle_type_unsupported"
@@ -477,7 +477,7 @@ const outcomeUserMessage = (error: AnalysisError): string => {
return `${error.message}. Static WebAssembly inspection uses a separate optional WABT lane, not a native analysis engine.`;
if (error instanceof BinaryTargetError)
return error.constraint === "directory_requires_file"
- ? `open_binary accepts files and Apple bundle directories (${OPENABLE_APPLE_BUNDLE_TYPES_TEXT}). This target is another directory; JavaScript/Electron application directories can be analyzed directly with analyze_javascript_application.`
+ ? `This operation opens a file or an Apple bundle directory (${OPENABLE_APPLE_BUNDLE_TYPES_TEXT}); this target is another directory. Directory-capable operations are inspect_desktop_application, audit_release_exposure, and analyze_javascript_application for JavaScript/Electron applications.`
: error.constraint === undefined
? `${error.message}. Check that the path exists, is readable, and points to a supported file.`
: `${error.message}.`;
@@ -601,7 +601,13 @@ const presentedRelatedInputs = (
): AnalysisRelatedInputs | undefined => {
if (error instanceof BinaryTargetError) {
if (error.constraint === "directory_requires_file")
- return { operations: ["analyze_javascript_application"] };
+ return {
+ operations: [
+ "inspect_desktop_application",
+ "audit_release_exposure",
+ "analyze_javascript_application",
+ ],
+ };
if (error.remediationAction !== undefined) return undefined;
if (
(error.constraint === "bundle_executable_undeclared" ||
diff --git a/src/domain/javascript/javascriptArtifactFiles.ts b/src/domain/javascript/javascriptArtifactFiles.ts
index 10b23756f6b..2153ea84d32 100644
--- a/src/domain/javascript/javascriptArtifactFiles.ts
+++ b/src/domain/javascript/javascriptArtifactFiles.ts
@@ -6,6 +6,8 @@ import type {
ArtifactInventoryCoverage,
ArtifactOccurrence,
} from "../artifactGraph.js";
+import type { ArtifactInventorySnapshot } from "../artifactInventorySnapshot.js";
+import type { JsonValue } from "../jsonValue.js";
/** One physical file occurrence, independent of its graph representations. */
export const javaScriptFileOccurrenceSchema = z.strictObject({
@@ -127,3 +129,82 @@ export interface JavaScriptArtifactFileSet {
readonly invalid_utf8_files: number;
readonly source_selection?: JavaScriptSourceSelection;
}
+
+/** Relevant file kinds that make a target a JavaScript application input. */
+const APPLICATION_INPUT_KINDS: ReadonlySet =
+ new Set(["javascript", "html", "package-json", "source-map"]);
+
+/**
+ * Whether the inventoried target holds anything the JavaScript lane analyzes.
+ * `empty` and `absent` require complete traversal; an unavailable relevant
+ * file of unknown kind, or incomplete traversal, leaves applicability unknown.
+ */
+export type JavaScriptApplicationInputPresence =
+ | "present"
+ | "empty"
+ | "absent"
+ | "unknown";
+
+/** A non-directory entry beneath the selected root; the root itself is excluded. */
+const isContainedEntry = ({
+ parent_occurrence_id: parent,
+ entry_kind: kind,
+}: ArtifactOccurrence): boolean => parent !== null && kind !== "directory";
+
+/** Classify application-input presence from the lane's own inventory facts. */
+export const javaScriptApplicationInputPresence = (
+ files: JavaScriptArtifactFileSet,
+ snapshot: Pick,
+): JavaScriptApplicationInputPresence => {
+ if (
+ files.containers.length > 0 ||
+ files.files.some(({ kind }) => APPLICATION_INPUT_KINDS.has(kind)) ||
+ files.unavailable_relevant_files.some(
+ ({ kind }) => kind !== undefined && APPLICATION_INPUT_KINDS.has(kind),
+ )
+ )
+ return "present";
+ if (
+ snapshot.coverage.status !== "complete" ||
+ files.unavailable_relevant_files.some(({ kind }) => kind === undefined)
+ )
+ return "unknown";
+ return snapshot.occurrences.some(isContainedEntry) ? "absent" : "empty";
+};
+
+/**
+ * Bounded routing facts for a target without application inputs: entry
+ * counts by inventoried format and the JSON and native-addon files the lane
+ * classified. No paths are retained.
+ */
+export const javaScriptAbsentInputDiagnostics = (
+ files: JavaScriptArtifactFileSet,
+ snapshot: Pick,
+): Readonly> => {
+ const byFormat = new Map();
+ let entries = 0;
+ for (const occurrence of snapshot.occurrences) {
+ if (!isContainedEntry(occurrence)) continue;
+ entries += 1;
+ const format = occurrence.artifact_format;
+ byFormat.set(format, (byFormat.get(format) ?? 0) + 1);
+ }
+ return {
+ inventoried_entries: entries,
+ entries_by_format: Object.fromEntries(
+ [...byFormat].sort(([left], [right]) => (left < right ? -1 : 1)),
+ ),
+ json_files: files.files.filter(({ kind }) => kind === "json").length,
+ native_addon_files: files.files.filter(
+ ({ kind }) => kind === "native-addon",
+ ).length,
+ };
+};
+
+/** Directory-capable and per-file operations for a target the lane does not analyze. */
+export const JAVASCRIPT_ABSENT_INPUT_OPERATIONS = [
+ "inspect_desktop_application",
+ "audit_release_exposure",
+ "inspect_artifact",
+ "open_binary",
+] as const;
diff --git a/tests/boundary/cli/analyzeAppBundlePathCli.test.ts b/tests/boundary/cli/analyzeAppBundlePathCli.test.ts
index 12a64cf8f11..21a8ec7a521 100644
--- a/tests/boundary/cli/analyzeAppBundlePathCli.test.ts
+++ b/tests/boundary/cli/analyzeAppBundlePathCli.test.ts
@@ -3,7 +3,7 @@ import { join } from "node:path";
import { describe, expect } from "vitest";
-import { thinMach } from "../../../src/domain/binaryTarget.fixture.js";
+import { pe, thinMach } from "../../../src/domain/binaryTarget.fixture.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
@@ -75,3 +75,79 @@ cliTest(
});
},
);
+
+cliTest(
+ "refuses a native build directory without JavaScript inputs and names the directory-capable operations",
+ async ({ cli }) => {
+ const root = await createTestTempDirectory("rea-analyze-native-dir-");
+ const build = join(root, "build");
+ await mkdir(join(build, "CMakeFiles"), { recursive: true });
+ // Native images only; no JavaScript, HTML, package.json or ASAR.
+ await writeFile(join(build, "tool.exe"), pe(0x8664));
+ await writeFile(join(build, "runtime.dll"), pe(0x8664, 64, 0x2002));
+ await writeFile(join(build, "ctest.json"), '{"tests":[]}');
+ await writeFile(join(build, "CMakeFiles", "cmake.check_cache"), "x\n");
+ const result = await cli.run({
+ arguments: ["analyze", build, "--json"],
+ cwd: root,
+ environment,
+ });
+ expect(result.exitCode).toBe(1);
+ expect(result.json).toMatchObject({
+ code: "unsupported_target",
+ details: {
+ operation: "analyze_javascript_application",
+ related_operations: [
+ "inspect_desktop_application",
+ "audit_release_exposure",
+ "inspect_artifact",
+ "open_binary",
+ ],
+ diagnostics: {
+ inventoried_entries: 4,
+ entries_by_format: { file: 2, pe: 2 },
+ json_files: 1,
+ },
+ },
+ });
+ },
+);
+
+cliTest(
+ "analyzes an empty directory with an explicit no-input limitation",
+ async ({ cli }) => {
+ const root = await createTestTempDirectory("rea-analyze-empty-dir-");
+ const empty = join(root, "empty");
+ await mkdir(empty);
+ const result = await cli.run({
+ arguments: ["analyze", empty, "--json"],
+ cwd: root,
+ environment,
+ });
+ expect(result.exitCode).toBe(0);
+ expect(result.json).toMatchObject({
+ operation: "analyze_javascript_application",
+ });
+ expect(result.stdout).toContain("No JavaScript inputs were found");
+ },
+);
+
+cliTest(
+ "keeps analyzing a directory whose only application input is an HTML page",
+ async ({ cli }) => {
+ const root = await createTestTempDirectory("rea-analyze-html-dir-");
+ const site = join(root, "site");
+ await mkdir(site);
+ await writeFile(join(site, "index.html"), "x
\n");
+ await writeFile(join(site, "data.json"), "{}");
+ const result = await cli.run({
+ arguments: ["analyze", site, "--json"],
+ cwd: root,
+ environment,
+ });
+ expect(result.exitCode).toBe(0);
+ expect(result.json).toMatchObject({
+ operation: "analyze_javascript_application",
+ });
+ },
+);
diff --git a/tests/boundary/cli/rawBinaryCli.test.ts b/tests/boundary/cli/rawBinaryCli.test.ts
index 8a831cb91ae..7d50e93915c 100644
--- a/tests/boundary/cli/rawBinaryCli.test.ts
+++ b/tests/boundary/cli/rawBinaryCli.test.ts
@@ -244,8 +244,14 @@ cliTest(
code: "target_unavailable",
details: {
constraint: "directory_requires_file",
- related_operations: ["analyze_javascript_application"],
+ related_operations: [
+ "inspect_desktop_application",
+ "audit_release_exposure",
+ "analyze_javascript_application",
+ ],
related_cli_commands: {
+ inspect_desktop_application: "rea inspect-desktop-application",
+ audit_release_exposure: "rea audit-release-exposure",
analyze_javascript_application: "rea analyze-javascript-application",
},
},
diff --git a/tests/boundary/filesystem/javascriptApplicationInputSelection.test.ts b/tests/boundary/filesystem/javascriptApplicationInputSelection.test.ts
index 2683f222c25..f74c5aa69b9 100644
--- a/tests/boundary/filesystem/javascriptApplicationInputSelection.test.ts
+++ b/tests/boundary/filesystem/javascriptApplicationInputSelection.test.ts
@@ -7,6 +7,7 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { analyzeJavaScriptApplication } from "../../support/javascriptApplicationScope.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
+import { pe } from "../../../src/domain/binaryTarget.fixture.js";
const analyzeFailure = async (input: Record) => {
const result = await analyzeJavaScriptApplication(input);
@@ -130,6 +131,71 @@ describe("JavaScript application input selection", () => {
});
});
+ it("refuses a directory whose complete inventory has no JavaScript application inputs", async () => {
+ const { root } = await application();
+ const build = join(root, "build");
+ await mkdir(join(build, "CMakeFiles"), { recursive: true });
+ await writeFile(join(build, "tool.exe"), pe(0x8664));
+ await writeFile(join(build, "runtime.dll"), pe(0x8664, 64, 0x2002));
+ await writeFile(join(build, "ctest.json"), '{"tests":[]}');
+ await writeFile(join(build, "CMakeFiles", "cache.txt"), "x\n");
+
+ const projected = await analyzeFailure({ input_path: build });
+ expect(projected).toMatchObject({
+ code: "unsupported_target",
+ details: {
+ operation: "analyze_javascript_application",
+ related_operations: [
+ "inspect_desktop_application",
+ "audit_release_exposure",
+ "inspect_artifact",
+ "open_binary",
+ ],
+ diagnostics: {
+ inventoried_entries: 4,
+ entries_by_format: { file: 2, pe: 2 },
+ json_files: 1,
+ native_addon_files: 0,
+ },
+ },
+ });
+ expect(projected.remediation.action).toContain("entries_by_format");
+ expect(JSON.stringify(projected)).not.toContain("tool.exe");
+ });
+
+ it("analyzes an empty directory with an explicit no-input limitation", async () => {
+ const { root } = await application();
+ const empty = join(root, "empty");
+ await mkdir(join(empty, "nested"), { recursive: true });
+
+ const result = await analyzeJavaScriptApplication({ input_path: empty });
+ if (!result.ok) throw result.error;
+ expect(result.value.limitations).toContainEqual(
+ expect.stringContaining("No JavaScript inputs were found"),
+ );
+ expect(result.value.limitations).toContainEqual(
+ expect.stringContaining("inspect_desktop_application"),
+ );
+ });
+
+ it.each([
+ ["an HTML page", "index.html", "x
\n"],
+ ["a package manifest", "package.json", '{"name":"app"}'],
+ ["a source map", "app.js.map", '{"version":3,"sources":[],"mappings":""}'],
+ ])(
+ "analyzes a directory whose only application input is %s",
+ async (_label, name, text) => {
+ const { root } = await application();
+ const directory = join(root, "only");
+ await mkdir(directory);
+ await writeFile(join(directory, name), text);
+ await writeFile(join(directory, "data.json"), "{}");
+ expect(
+ (await analyzeJavaScriptApplication({ input_path: directory })).ok,
+ ).toBe(true);
+ },
+ );
+
it.each([
["a directory", "directory", "asar"],
["an .asar file", "asar", "directory"],
diff --git a/tests/boundary/filesystem/targetDiagnostics.test.ts b/tests/boundary/filesystem/targetDiagnostics.test.ts
index 60e5bdb5cd3..e341adcb561 100644
--- a/tests/boundary/filesystem/targetDiagnostics.test.ts
+++ b/tests/boundary/filesystem/targetDiagnostics.test.ts
@@ -86,10 +86,16 @@ it("identifies the directory opening constraint and gives the direct analysis ro
details: {
path: await realpath(directory),
constraint: "directory_requires_file",
- related_operations: ["analyze_javascript_application"],
+ related_operations: [
+ "inspect_desktop_application",
+ "audit_release_exposure",
+ "analyze_javascript_application",
+ ],
},
});
expect(projected.message).toContain("analyze_javascript_application");
+ expect(projected.message).toContain("inspect_desktop_application");
+ expect(projected.message).not.toContain("open_binary");
expect(projected.message).not.toContain("rea analyze");
expect(projected.remediation.action).toContain("input_path");
expect(projected.remediation.action).not.toContain("rea analyze");