From 5291bca108af781214572fac709f9808bb8aa4db Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sat, 10 Oct 2026 04:16:09 +0800 Subject: [PATCH] refactor(artifacts): remove unused root classifier --- src/artifacts/inventory/classify.ts | 15 --------------- src/filesystem/RegularFile.ts | 1 + tests/boundary/filesystem/zipDetection.test.ts | 12 ++++++++---- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/artifacts/inventory/classify.ts b/src/artifacts/inventory/classify.ts index a8baf7a12..18c675921 100644 --- a/src/artifacts/inventory/classify.ts +++ b/src/artifacts/inventory/classify.ts @@ -28,21 +28,6 @@ const classifyContainerExtension = ( return undefined; }; -export const classifyRoot = async ( - path: string, - directory: boolean, -): Promise => { - if (directory) return "directory"; - const extensionFormat = classifyContainerExtension(path); - if (extensionFormat !== undefined) return extensionFormat; - const handle = await openRootFile(path); - try { - return await classifyOpenedRoot(path, handle); - } finally { - await handle.close(); - } -}; - /** Classify and hash one file root through the same stable open descriptor. */ export const classifyAndHashRoot = async ( path: string, diff --git a/src/filesystem/RegularFile.ts b/src/filesystem/RegularFile.ts index e5afac401..13982a896 100644 --- a/src/filesystem/RegularFile.ts +++ b/src/filesystem/RegularFile.ts @@ -2,6 +2,7 @@ import { constants } from "node:fs"; import type { BigIntStats, Stats } from "node:fs"; import { open, type FileHandle } from "node:fs/promises"; +/** Identifies a selected path that cannot be read as one regular file. */ export class NonRegularFileReadError extends Error { readonly code: "EISDIR" | "ENOTFILE"; diff --git a/tests/boundary/filesystem/zipDetection.test.ts b/tests/boundary/filesystem/zipDetection.test.ts index 8ab81112a..3e1878db4 100644 --- a/tests/boundary/filesystem/zipDetection.test.ts +++ b/tests/boundary/filesystem/zipDetection.test.ts @@ -1,9 +1,9 @@ -import { writeFile } from "node:fs/promises"; +import { lstat, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; -import { classifyRoot } from "../../../src/artifacts/inventory/classify.js"; +import { classifyAndHashRoot } from "../../../src/artifacts/inventory/classify.js"; import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; @@ -19,7 +19,9 @@ describe("ZIP signature detection", () => { const root = await createTestTempDirectory("rea-zip-signature-"); const path = join(root, "input"); await writeFile(path, Buffer.from(signature)); - expect(await classifyRoot(path, false)).toBe(archive ? "zip" : "file"); + expect( + (await classifyAndHashRoot(path, false, await lstat(path))).format, + ).toBe(archive ? "zip" : "file"); const target = await parseBinaryTarget(path); if (archive) expect(target).toMatchObject({ ok: true, value: { format: "zip" } }); @@ -37,7 +39,9 @@ describe("ZIP signature detection", () => { const root = await createTestTempDirectory("rea-zip-short-"); const path = join(root, "input"); await writeFile(path, Buffer.from(bytes)); - expect(await classifyRoot(path, false)).toBe("file"); + expect( + (await classifyAndHashRoot(path, false, await lstat(path))).format, + ).toBe("file"); expect((await parseBinaryTarget(path)).ok).toBe(false); }, );