fix(flutter): name a missing or non-file APK selection (#2727)
* fix(flutter): name a missing or non-file APK selection identify_flutter_build and inspect_dart_aot reported a missing path or a directory as "The APK could not be read as a package: <path>: ENOENT ...", which blames the package bytes for a selection mistake. Report "Selected APK does not exist" for ENOENT/ENOTDIR and "Selected APK is not a regular file" for a non-regular selection, matching the SQLite inspector's wording. The issue path and invalid_format reason are unchanged; package format failures keep their existing message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(filesystem): classify unopenable non-regular selections at admission A Unix socket cannot be opened at all: open() fails with ENXIO on Linux and EOPNOTSUPP on macOS (surfaced by libuv as "Unknown system error -102") before openRegularFile can stat the descriptor, so such a selection escaped NonRegularFileReadError and the Flutter provider still blamed the package bytes. When open fails, classify the path by its own metadata (lstat when symlinks are rejected, stat otherwise): an existing non-regular file becomes NonRegularFileReadError. Missing paths, permission failures, regular files, and the O_NOFOLLOW ELOOP rejection keep their original errors. The Flutter selection test now covers a real Unix socket. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(filesystem): reclassify only unopenable file-type errors at admission Checking the path's metadata after any open failure turned EACCES on an unreadable directory into NonRegularFileReadError, so callers reported invalid input instead of access_denied. Reclassify only errors that mean the file type cannot be opened (ENXIO, EOPNOTSUPP, ENOTSUP, matched by errno because libuv has no name for macOS EOPNOTSUPP 102); permission, symlink-rejection and resource failures keep their original errors. Run the Unix socket selection check in its own test, skipped on Windows where listen() takes named pipes, and keep the missing-path and directory checks cross-platform. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(filesystem): keep cancellation that arrives during the non-regular probe A caller abort while the post-open metadata probe ran was replaced by NonRegularFileReadError, so callers such as parseBinaryTarget reported an input-format error instead of cancellation. Recheck the signal before substituting the non-regular classification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c22d7cd756
commit
46f51ee6cc
@@ -1,5 +1,6 @@
|
||||
import { createReadStream } from "node:fs";
|
||||
import { open, readFile, rm, stat, utimes, writeFile } from "node:fs/promises";
|
||||
import { createServer } from "node:net";
|
||||
import { join } from "node:path";
|
||||
import { Readable } from "node:stream";
|
||||
import { Uint8ArrayReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
|
||||
@@ -1171,6 +1172,69 @@ it.each(["identify_flutter_build", "inspect_dart_aot"] as const)(
|
||||
},
|
||||
);
|
||||
|
||||
const expectSelectionIssue = async (
|
||||
provider: FlutterBuildProvider,
|
||||
path: string,
|
||||
message: string,
|
||||
): Promise<void> => {
|
||||
for (const operation of [
|
||||
"identify_flutter_build",
|
||||
"inspect_dart_aot",
|
||||
] as const) {
|
||||
const result = await provider.execute({ operation, input: { path } });
|
||||
if (result.ok) throw new Error("A non-file APK selection must fail");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [
|
||||
{
|
||||
path: ["path"],
|
||||
reason: "invalid_format",
|
||||
message: `${message}: ${path}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
it("names a missing or non-file APK selection instead of blaming package bytes", async () => {
|
||||
const root = await createTestTempDirectory("rea-flutter-selection-");
|
||||
const provider = new FlutterBuildProvider();
|
||||
onTestFinished(() => provider.close());
|
||||
await expectSelectionIssue(
|
||||
provider,
|
||||
join(root, "absent.apk"),
|
||||
"Selected APK does not exist",
|
||||
);
|
||||
await expectSelectionIssue(
|
||||
provider,
|
||||
root,
|
||||
"Selected APK is not a regular file",
|
||||
);
|
||||
});
|
||||
|
||||
// Windows listens on named pipes rather than filesystem sockets.
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"names an unopenable Unix socket APK selection as a non-file",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-flutter-socket-");
|
||||
const socketPath = join(root, "s.sock");
|
||||
const socket = createServer();
|
||||
await new Promise<void>((resolve) => socket.listen(socketPath, resolve));
|
||||
onTestFinished(
|
||||
() => new Promise<void>((resolve) => socket.close(() => resolve())),
|
||||
);
|
||||
const provider = new FlutterBuildProvider();
|
||||
onTestFinished(() => provider.close());
|
||||
await expectSelectionIssue(
|
||||
provider,
|
||||
socketPath,
|
||||
"Selected APK is not a regular file",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["EACCES", "EPERM"] as const)(
|
||||
"preserves %s at the shared source admission boundary",
|
||||
async (code) => {
|
||||
|
||||
Reference in New Issue
Block a user