refactor(scanner): type plist and file-api helpers

Convert the scanner's plist parser and Node-style file shim to TypeScript and add small unit tests so common parser and file-reader failures are caught before we need to lean on Playwright or the higher-level scanner test.

Constraint: Must preserve current scanner behavior while tightening the lowest-level helper surface
Rejected: Jump straight to Mach-O parser conversion | harder to isolate regressions without first proving the smaller helper-test pattern
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Add small module-level regression tests for repeatable scanner breakage before expanding browser coverage
Tested: pnpm run typecheck; pnpm exec vitest run test/scanner/plist.test.ts test/scanner/file-api.test.ts test/scanner/client.test.ts; pnpm run test; pnpm run test:browser
Not-tested: Production deploy behavior prior to push
This commit is contained in:
ThatGuySam 2026-04-04 18:13:32 -05:00
parent 6d858d2a19
commit cd41143f0d
7 changed files with 851 additions and 723 deletions

View file

@ -2,10 +2,11 @@ import { Buffer } from 'buffer/index.js'
import prettyBytes from 'pretty-bytes'
import * as zip from '@zip.js/zip.js'
import * as FileApi from './file-api.js'
import * as FileApi from './file-api'
import type { NodeFile } from './file-api'
import { isNonEmptyString, isString } from '../check-types.js'
import { extractMachoMeta } from './parsers/macho.js'
import { parsePlistBuffer } from './parsers/plist.js'
import { parsePlistBuffer } from './parsers/plist'
zip.configure({
useWebWorkers: !import.meta.env.SSR
@ -89,7 +90,7 @@ interface ScanFileEntry {
interface ScanMachoFileInstance {
blob?: Blob
buffer: Buffer
buffer: NodeFile['buffer']
name: string
type: string
}
@ -390,10 +391,10 @@ export class AppScan {
const bundleExecutableUint8Array = await this.readFileEntryData<InstanceType<typeof zip.Uint8ArrayWriter>>( fileEntry, zip.Uint8ArrayWriter as new () => InstanceType<typeof zip.Uint8ArrayWriter> ) as Uint8Array
const machoFileInstance = new FileApi.File({
buffer: Buffer.from( bundleExecutableUint8Array ),
buffer: Buffer.from( bundleExecutableUint8Array ) as unknown as NodeFile['buffer'],
name: this.bundleExecutable.filename,
type: 'application/x-mach-binary'
}) as ScanMachoFileInstance
}) as unknown as ScanMachoFileInstance
machoFileInstance.blob = await this.readFileEntryData<InstanceType<typeof zip.BlobWriter>>( fileEntry, zip.BlobWriter as new () => InstanceType<typeof zip.BlobWriter> ) as Blob