From af062e7a2d290fec4307fb9444298a13c2fea630 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:09:17 +0800 Subject: [PATCH] refactor(kernel): eliminate remaining record predicate copies and compose cleanup dependencies through shared owner (#11799) * refactor(kernel): eliminate remaining record predicate copies and compose cleanup dependencies through shared owner * fix(firmware,tests): remove unused cleanup import and align CI shard and CLI registration tests --- scripts/verify/architecture-guards.mjs | 18 ++---------------- .../baselines/cleanup-dependency-binding.json | 16 +++++----------- src/application/binary/BinarySession.ts | 6 ++---- src/browser/PlaywrightElectronActiveActions.ts | 8 ++------ .../PlaywrightElectronActiveProvider.ts | 6 +++--- src/browser/execution/CdpRuntimeInitiator.ts | 3 ++- src/browser/history/CaptureRedaction.ts | 7 +++---- src/cliMcpRegistration.test.ts | 15 +++++++++++++-- src/contracts/compactJsonSchema.ts | 6 ++---- src/contracts/inputSchemaPresentation.ts | 4 +--- .../analysisView/environmentStateRules.ts | 3 ++- src/evm/EvmoleInterfaceProvider.ts | 16 ++++++---------- src/firmware/FirmwareFailures.ts | 14 ++------------ src/ghidra/GhidraFileArtifacts.ts | 11 ++--------- src/jeb/JebProvider.ts | 8 +++----- src/pcap/PcapDnsWire.ts | 3 +-- src/pcap/PcapOutput.ts | 4 +--- src/pcap/PcapProvider.ts | 11 +++++------ src/process/ArtifactAnalysisResources.ts | 12 ++++-------- src/sqlite/SqliteDatabaseWorkerExecution.ts | 14 +++----------- .../boundary/filesystem/ciChangeScope.test.ts | 2 +- 21 files changed, 65 insertions(+), 122 deletions(-) diff --git a/scripts/verify/architecture-guards.mjs b/scripts/verify/architecture-guards.mjs index 838b34f445..a7bd2035c3 100644 --- a/scripts/verify/architecture-guards.mjs +++ b/scripts/verify/architecture-guards.mjs @@ -247,22 +247,8 @@ check( ); // "Non-null object other than an array" has one owner: src/kernel/isRecord.ts. -// A local predicate with that body, under any name, is a copy. The listed files -// still hold one and may only be removed from the list; a listed file that no -// longer matches fails so the list shrinks with the code. -const RECORD_PREDICATE_COPIES = [ - // Exported under a module-specific name; importers still use that name. - "src/browser/history/CaptureRedaction.ts", - "src/contracts/compactJsonSchema.ts", - "src/domain/analysisView/environmentStateRules.ts", - // Owned by the advertised-schema workstream. - "src/contracts/inputSchemaPresentation.ts", - // Narrows a protocol-specific parameter type, not unknown. - "src/browser/execution/CdpRuntimeInitiator.ts", - // Named `object`, which also spells the typeof result in these files. - "src/pcap/PcapDnsWire.ts", - "src/pcap/PcapOutput.ts", -]; +// A local predicate with that body, under any name, is a copy. +const RECORD_PREDICATE_COPIES = []; const mismatchedRecordCopies = files.filter(({ path, content }) => { if (path === "src/kernel/isRecord.ts") return false; const { named, bodies } = recordPredicateCounts(content); diff --git a/scripts/verify/baselines/cleanup-dependency-binding.json b/scripts/verify/baselines/cleanup-dependency-binding.json index 2e3a86f4f5..12a1386fae 100644 --- a/scripts/verify/baselines/cleanup-dependency-binding.json +++ b/scripts/verify/baselines/cleanup-dependency-binding.json @@ -4,7 +4,6 @@ "src/application/JsonFiles.ts": 1, "src/application/SetupCleanupOwner.ts": 2, "src/application/binary/AnalysisProviderRegistry.ts": 2, - "src/application/binary/BinarySession.ts": 1, "src/application/binary/CompositeProvider.ts": 1, "src/application/closeOwnedWebResources.ts": 1, "src/application/desktop/DesktopApplicationExport.ts": 2, @@ -14,21 +13,17 @@ "src/browser/CdpElectronProvider.ts": 1, "src/browser/CdpTargetSessionOwner.ts": 2, "src/browser/PlaywrightBrowserScenarioProvider.ts": 2, - "src/browser/PlaywrightElectronActiveActions.ts": 1, - "src/browser/PlaywrightElectronActiveProvider.ts": 1, "src/browser/WebSourceMapFetcher.ts": 2, "src/browser/history/HistoricalCaptureDecoder.ts": 1, "src/cli/desktopCaptureCommands.ts": 1, "src/cutter/CutterBridgeClient.ts": 1, "src/desktop/ScreenJudgeProcess.ts": 1, "src/domain/explicitSensitiveFailure.ts": 1, - "src/evm/EvmoleInterfaceProvider.ts": 6, - "src/firmware/FirmwareFailures.ts": 1, + "src/evm/EvmoleInterfaceProvider.ts": 3, "src/firmware/FirmwareProvider.ts": 1, "src/flutter/FlutterBuildProvider.ts": 1, "src/frida/FridaInstrumentationManager.ts": 1, "src/gdb/GdbSessionManager.ts": 2, - "src/ghidra/GhidraFileArtifacts.ts": 1, "src/hopper/BridgeLauncher.ts": 3, "src/hopper/HopperAnalysisProfile.ts": 1, "src/hopper/HopperClient.ts": 1, @@ -38,19 +33,18 @@ "src/inspector/V8InspectorProvider.ts": 1, "src/javascript/sourceMaps/SourceMapCommand.ts": 4, "src/jeb/JebMcpConnectionOwner.ts": 1, - "src/jeb/JebProvider.ts": 2, + "src/jeb/JebProvider.ts": 1, "src/kuna/KunaProjectCache.ts": 1, "src/kuna/KunaSessionClient.ts": 1, "src/kuna/KunaTargetCommands.ts": 1, "src/native/LldbCallTracer.ts": 3, "src/native/NativeCommandAnalysisError.ts": 1, "src/native/NativeMacOSProvider.ts": 2, - "src/pcap/PcapProvider.ts": 7, + "src/pcap/PcapProvider.ts": 6, "src/pcap/PcapSnapshot.ts": 1, - "src/process/ArtifactAnalysisResources.ts": 3, + "src/process/ArtifactAnalysisResources.ts": 1, "src/process/OwnedDebuggerSessionRegistry.ts": 1, "src/process/capture/ProcessCaptureError.ts": 3, "src/providers/AnalysisClientFailure.ts": 1, - "src/sqlite/SqliteDatabaseProvider.ts": 8, - "src/sqlite/SqliteDatabaseWorkerExecution.ts": 2 + "src/sqlite/SqliteDatabaseProvider.ts": 8 } diff --git a/src/application/binary/BinarySession.ts b/src/application/binary/BinarySession.ts index a5f877b84e..0f58b154b3 100644 --- a/src/application/binary/BinarySession.ts +++ b/src/application/binary/BinarySession.ts @@ -81,12 +81,10 @@ import { } from "./BinarySessionExecution.js"; import { closeAnalysisClient } from "../../providers/AnalysisClientCleanup.js"; import { - analysisErrorWithCleanupFailure, analysisErrorWithCleanupDependencies, analysisErrorWithCloseRejection, analysisErrorWithCloseRejections, } from "../../domain/analysisErrorCleanup.js"; -import { ConfigurationError } from "../../domain/configurationErrors.js"; import type { AnalysisCleanupRetry } from "../../domain/analysisErrorRecovery.js"; import { analysisErrorWithCancellation } from "../../domain/analysisErrorCancellation.js"; import { ProviderAdapterError } from "../../domain/providerAdapterError.js"; @@ -617,11 +615,11 @@ export class BinarySession this.#clearRuntimeAvailability(); if (isAborted(options.signal)) return err( - analysisErrorWithCleanupFailure( + analysisErrorWithCleanupDependencies( cancelledBy("open_binary", options.signal), closed.error, "open_binary", - ).bindCleanupDependencies([closed.error]), + ), ); return closed; } diff --git a/src/browser/PlaywrightElectronActiveActions.ts b/src/browser/PlaywrightElectronActiveActions.ts index 828b6015c9..99525a8836 100644 --- a/src/browser/PlaywrightElectronActiveActions.ts +++ b/src/browser/PlaywrightElectronActiveActions.ts @@ -13,7 +13,7 @@ import { AnalysisCancelledError, cancelledBy, } from "../domain/analysisErrorCore.js"; -import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js"; +import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js"; import { BrowserObservationError } from "../domain/browserObservationError.js"; import { describeValidationFailure } from "../domain/validationFailure.js"; import { @@ -249,11 +249,7 @@ const releaseActionWindow = async ( const cancellation = cancelledBy(OPERATION, signal); return actionStatus === "failed" ? error.retainSecondaryFailure(cancellation) - : analysisErrorWithCleanupFailure( - cancellation, - error, - OPERATION, - ).bindCleanupDependencies([cancellation, error]); + : analysisErrorWithCleanupDependencies(cancellation, error, OPERATION); }; type RunActionContext = { diff --git a/src/browser/PlaywrightElectronActiveProvider.ts b/src/browser/PlaywrightElectronActiveProvider.ts index a9bc128eda..8719d4e6a4 100644 --- a/src/browser/PlaywrightElectronActiveProvider.ts +++ b/src/browser/PlaywrightElectronActiveProvider.ts @@ -11,7 +11,7 @@ import { } from "../resources/index.js"; import { ProviderCleanupError } from "../domain/providerCleanupError.js"; import { ElectronCaptureCleanup } from "./ElectronCaptureCleanup.js"; -import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js"; +import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js"; import { analysisErrorWithCancellation } from "../domain/analysisErrorCancellation.js"; import { electronFuseFailure } from "../electron/ElectronFuseFailures.js"; import { randomUUID } from "node:crypto"; @@ -351,11 +351,11 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati ); owner.bind(failure); if (outcome.ok) return err(failure); - const composed = analysisErrorWithCleanupFailure( + const composed = analysisErrorWithCleanupDependencies( outcome.error, failure, OPERATION, - ).bindCleanupDependencies([outcome.error, failure]); + ); if (failure.partialObservation !== undefined) composed.partialObservation = failure.partialObservation; return err(composed); diff --git a/src/browser/execution/CdpRuntimeInitiator.ts b/src/browser/execution/CdpRuntimeInitiator.ts index 356955e135..d4607db2a3 100644 --- a/src/browser/execution/CdpRuntimeInitiator.ts +++ b/src/browser/execution/CdpRuntimeInitiator.ts @@ -1,10 +1,11 @@ import type { WebExecution } from "../../domain/webExecution.js"; import { sanitizeBrowserUrl } from "../../domain/browserObservation.js"; +import { isRecord } from "../../kernel/isRecord.js"; import type { CdpRuntimeSources } from "./CdpRuntimeSources.js"; type Initiator = WebExecution["requests"][number]["reported_initiator"]; const isObject = (value: Initiator[string] | undefined): value is Initiator => - typeof value === "object" && value !== null && !Array.isArray(value); + isRecord(value); /** Sanitize known transport fields while retaining declarations and every unknown producer field. */ export const sanitizeRuntimeInitiator = ( diff --git a/src/browser/history/CaptureRedaction.ts b/src/browser/history/CaptureRedaction.ts index ccb5f6edb4..0a4e0cb442 100644 --- a/src/browser/history/CaptureRedaction.ts +++ b/src/browser/history/CaptureRedaction.ts @@ -138,12 +138,11 @@ export class CaptureRedaction { } } +import { isRecord } from "../../kernel/isRecord.js"; + /** Escape a producer property for an RFC 6901 location. */ export const capturePointer = (parent: string, key: string): string => `${parent}/${escapeJsonPointerToken(key)}`; /** Structural record guard does not duck-type number/byte sidecar markers. */ -export const captureObject = ( - value: unknown, -): value is Record => - typeof value === "object" && value !== null && !Array.isArray(value); +export const captureObject = isRecord; diff --git a/src/cliMcpRegistration.test.ts b/src/cliMcpRegistration.test.ts index 6d3cbeb68d..a0baea1607 100644 --- a/src/cliMcpRegistration.test.ts +++ b/src/cliMcpRegistration.test.ts @@ -34,7 +34,9 @@ const CHILD_PROGRAM = ` if (process.platform === 'win32') await writeFile(join(bin, runner + '.cmd'), '@"' + process.execPath + '" "' + witness + '"\\r\\n'); else await writeFile(join(bin, runner), '#!' + process.execPath + '\\nrequire(' + JSON.stringify(witness) + ');\\n', { mode: 0o700 }); } - const { createCli, closeCliResources } = await import(${JSON.stringify(new URL("./cli.ts", import.meta.url).href)}); + const { createCliShell } = await import(${JSON.stringify(new URL("./cli/cliShell.ts", import.meta.url).href)}); + const { closeCliResources } = await import(${JSON.stringify(new URL("./cli/cliResources.ts", import.meta.url).href)}); + await import(${JSON.stringify(new URL("./cli/mcpRegistration.ts", import.meta.url).href)}); const { resolveMcpRegistrationClients } = await import(${JSON.stringify(new URL("./application/McpRegistrationCatalog.ts", import.meta.url).href)}); const { ArtifactResourceScope } = await import(${JSON.stringify(new URL("./resources/ArtifactResourceScope.ts", import.meta.url).href)}); const preflightResources = new ArtifactResourceScope(); @@ -46,9 +48,18 @@ const CHILD_PROGRAM = ` for (const key of ['HOME','USERPROFILE','XDG_CONFIG_HOME','XDG_DATA_HOME','XDG_CACHE_HOME','XDG_STATE_HOME','APPDATA','LOCALAPPDATA']) inside(home, environment[key]); return environment; }; + const clis = new WeakMap(); + const cliFor = (environment) => { + let cli = clis.get(environment); + if (!cli) { + cli = createCliShell({ selectedEnvironment: environment, registrations: [] }); + clis.set(environment, cli); + } + return cli; + }; const serve = async (environment, arguments_) => { let output = '', exitCode = 0; - await createCli(environment).serve(arguments_, { stdout(text) { output += text; }, exit(code) { exitCode = code; } }); + await cliFor(environment).serve(arguments_, { stdout(text) { output += text; }, exit(code) { exitCode = code; } }); const document = JSON.parse(output); if (Array.isArray(document.clients)) for (const client of document.clients) { inside(environment.HOME, client.config_path); if (client.backup_path) inside(environment.HOME, client.backup_path); } return { exitCode, document }; diff --git a/src/contracts/compactJsonSchema.ts b/src/contracts/compactJsonSchema.ts index f14bd2d5ca..3e1b13c7b2 100644 --- a/src/contracts/compactJsonSchema.ts +++ b/src/contracts/compactJsonSchema.ts @@ -1,3 +1,4 @@ +import { isRecord } from "../kernel/isRecord.js"; import { JsonSchemaReferences, type JsonSchemaScope, @@ -41,10 +42,7 @@ const enumValueTypes = (values: readonly unknown[]): readonly string[] => [ ), ]; -export const isSchemaObject = ( - value: unknown, -): value is Record => - typeof value === "object" && value !== null && !Array.isArray(value); +export const isSchemaObject = isRecord; export const serializedBytes = (value: unknown): number => Buffer.byteLength(JSON.stringify(value), "utf8"); diff --git a/src/contracts/inputSchemaPresentation.ts b/src/contracts/inputSchemaPresentation.ts index 8e287375a6..43e9afb33d 100644 --- a/src/contracts/inputSchemaPresentation.ts +++ b/src/contracts/inputSchemaPresentation.ts @@ -5,6 +5,7 @@ import { import { isDeepStrictEqual } from "node:util"; import type { SchemaAnnotations } from "../domain/schemaAnnotations.js"; +import { isRecord as isObject } from "../kernel/isRecord.js"; import { schemaArrays, schemaChildren, @@ -12,9 +13,6 @@ import { schemaPointerSteps, } from "./jsonSchemaKeywords.js"; -const isObject = (value: unknown): value is Readonly> => - typeof value === "object" && value !== null && !Array.isArray(value); - const referencedDescription = ( references: JsonSchemaReferences, schema: Readonly>, diff --git a/src/domain/analysisView/environmentStateRules.ts b/src/domain/analysisView/environmentStateRules.ts index fc979af021..040d28928e 100644 --- a/src/domain/analysisView/environmentStateRules.ts +++ b/src/domain/analysisView/environmentStateRules.ts @@ -1,3 +1,4 @@ +import { isRecord } from "../../kernel/isRecord.js"; import { escapeJsonPointerToken, jsonPointerTokens } from "../jsonPointer.js"; import { iterateUrlQueryParameters, @@ -319,7 +320,7 @@ export const segmentsOf = (path: string): string[] => { export const isParam = (segment: string): boolean => segment.startsWith("{") && segment.endsWith("}"); export const isObject = (value: JsonValue | undefined): value is JsonObject => - typeof value === "object" && value !== null && !Array.isArray(value); + isRecord(value); export const scalarText = (value: JsonValue | undefined): string | undefined => typeof value === "string" ? value diff --git a/src/evm/EvmoleInterfaceProvider.ts b/src/evm/EvmoleInterfaceProvider.ts index 984f07d234..ddbc51786f 100644 --- a/src/evm/EvmoleInterfaceProvider.ts +++ b/src/evm/EvmoleInterfaceProvider.ts @@ -34,7 +34,7 @@ import { AnalysisCleanupLease, AnalysisCleanupLeaseGroup, } from "../resources/index.js"; -import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js"; +import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js"; import { OwnedCommandFailure, ownedCommandResources, @@ -401,11 +401,7 @@ const evmReplyCompletionFailure = ( bindArtifactFileCleanup(cause, cleanup); return cancellation === undefined ? cleanup - : analysisErrorWithCleanupFailure( - cancellation, - cleanup, - OPERATION, - ).bindCleanupDependencies([cancellation, cleanup]); + : analysisErrorWithCleanupDependencies(cancellation, cleanup, OPERATION); }; /** Run unchanged EVMole/WASM in an owned worker; no target, chain or network execution. */ @@ -909,11 +905,11 @@ export class EvmoleInterfaceProvider implements EvmInterfacePort { ); if (markerCleanupFailure !== undefined) { const cleanup = retainedCleanupFailure(markerCleanupFailure); - failure = analysisErrorWithCleanupFailure( + failure = analysisErrorWithCleanupDependencies( failure, cleanup, OPERATION, - ).bindCleanupDependencies([failure, cleanup]); + ); } result = err(failure); } @@ -926,11 +922,11 @@ export class EvmoleInterfaceProvider implements EvmInterfacePort { } else { result = err( replyFinalization.cleanupIncomplete - ? analysisErrorWithCleanupFailure( + ? analysisErrorWithCleanupDependencies( result.error, replyFinalization, OPERATION, - ).bindCleanupDependencies([result.error, replyFinalization]) + ) : result.error.retainSecondaryFailure(replyFinalization, { reply_finalization_error: projectAnalysisErrorWithoutCapturedOutput(replyFinalization), diff --git a/src/firmware/FirmwareFailures.ts b/src/firmware/FirmwareFailures.ts index b8ba860de3..4b60a4351c 100644 --- a/src/firmware/FirmwareFailures.ts +++ b/src/firmware/FirmwareFailures.ts @@ -1,7 +1,6 @@ import { MAX_NODE_TIMER_DELAY_MS } from "../domain/analysisResourceLimits.js"; import { type AnalysisCleanupLease, - ArtifactFileCleanupFailure, bindArtifactFileCleanup, } from "../resources/index.js"; import type { @@ -17,7 +16,7 @@ import { isAborted, type AbortedSignal, } from "../domain/analysisErrorCore.js"; -import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js"; +import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js"; import { ProviderAdapterError } from "../domain/providerAdapterError.js"; import { ProviderCleanupError } from "../domain/providerCleanupError.js"; import type { ProviderFailureDialect } from "../providers/classifyProviderFailure.js"; @@ -214,16 +213,7 @@ export const firmwareFailureDialect = ( if (read.cleanupLeases === undefined) treeCleanupLease?.bindCleanupError(cleanup); if (primary === undefined) return cleanup; - // A file operation's own outcome shares its cleanup; a cancelled read's does not. - return analysisErrorWithCleanupFailure( - primary, - cleanup, - operation, - ).bindCleanupDependencies( - read instanceof ArtifactFileCleanupFailure - ? [primary, cleanup] - : [cleanup], - ); + return analysisErrorWithCleanupDependencies(primary, cleanup, operation); }, unclassified: (cause, details) => new ProviderAdapterError(engine, operation, { diff --git a/src/ghidra/GhidraFileArtifacts.ts b/src/ghidra/GhidraFileArtifacts.ts index f00f3b1879..290cc02dd7 100644 --- a/src/ghidra/GhidraFileArtifacts.ts +++ b/src/ghidra/GhidraFileArtifacts.ts @@ -23,7 +23,7 @@ import { import { RegularFileChangedError } from "../filesystem/RegularFile.js"; import { ProviderAdapterError } from "../domain/providerAdapterError.js"; import { ProviderCleanupError } from "../domain/providerCleanupError.js"; -import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js"; +import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js"; import type { JsonValue } from "../domain/jsonValue.js"; import type { ProviderFailureDialect } from "../providers/classifyProviderFailure.js"; import { errorMessage } from "../kernel/errorMessage.js"; @@ -130,14 +130,7 @@ export const ghidraFileDialect = ( { cause: mapped }, ); bindArtifactFileCleanup(mapped, failure); - return analysisErrorWithCleanupFailure( - primary, - failure, - operation, - ).bindCleanupDependencies([ - ...(primary.cleanupIncomplete ? [primary] : []), - failure, - ]); + return analysisErrorWithCleanupDependencies(primary, failure, operation); }, unclassified: (cause, details) => { const { cause: primary } = artifactFilePrimaryFacts(cause); diff --git a/src/jeb/JebProvider.ts b/src/jeb/JebProvider.ts index 97d85249f4..078cfe7e5c 100644 --- a/src/jeb/JebProvider.ts +++ b/src/jeb/JebProvider.ts @@ -5,7 +5,7 @@ import { } from "./JebMcpConnectionOwner.js"; import { createAnalysisExecutionEvidence } from "../domain/analysisObservation.js"; import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js"; -import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js"; +import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js"; import { z } from "zod"; import type { JebAnalysisPort, @@ -630,7 +630,7 @@ export class JebProvider implements JebAnalysisPort { */ #attributed(operation: JebOperation, failure: AnalysisError): AnalysisError { if (failure instanceof JebMcpCleanupFailure) - return analysisErrorWithCleanupFailure( + return analysisErrorWithCleanupDependencies( this.#attributed( operation, classifyProviderFailure( @@ -640,9 +640,7 @@ export class JebProvider implements JebAnalysisPort { ), failure.cleanupFailure, operation, - ) - .bindCleanupDependencies([failure.cleanupFailure]) - .bindCleanupResourceOwner(failure.cleanupFailure); + ).bindCleanupResourceOwner(failure.cleanupFailure); if ( failure instanceof AnalysisCancelledError || failure instanceof AnalysisTimeoutError diff --git a/src/pcap/PcapDnsWire.ts b/src/pcap/PcapDnsWire.ts index 7028f82500..b54faa7de2 100644 --- a/src/pcap/PcapDnsWire.ts +++ b/src/pcap/PcapDnsWire.ts @@ -1,6 +1,7 @@ import { isIPv4, isIPv6 } from "node:net"; import { err, ok, type Result } from "../domain/result.js"; import { byteToHex } from "../kernel/byteToHex.js"; +import { isRecord as object } from "../kernel/isRecord.js"; interface DnsWireFailure { readonly kind: "invalid_dns_wire"; @@ -21,8 +22,6 @@ export interface DnsMessageFacts { readonly incomplete: boolean; readonly incomplete_reasons?: readonly string[]; } -const object = (value: unknown): value is Record => - typeof value === "object" && value !== null && !Array.isArray(value); /** Read named producer fields, retaining occurrence order within one PDU. */ const fields = (source: unknown): Map => { diff --git a/src/pcap/PcapOutput.ts b/src/pcap/PcapOutput.ts index 4768026f46..2bbd8d58ea 100644 --- a/src/pcap/PcapOutput.ts +++ b/src/pcap/PcapOutput.ts @@ -14,6 +14,7 @@ import { parsePcapHttpUri } from "./PcapHttpUri.js"; import { fixedAllowanceOptions } from "../domain/fixedAllowanceRemediation.js"; import { parseDnsMessageRaw } from "./PcapDnsWire.js"; import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js"; +import { isRecord as object } from "../kernel/isRecord.js"; const OPERATION = "inspect_pcap_capture"; /** Bounds JSON decoding plus its expanded object graph before JSON.parse. */ @@ -166,9 +167,6 @@ export interface TsharkFields { readonly partial: boolean; } -const object = (value: unknown): value is Record => - typeof value === "object" && value !== null && !Array.isArray(value); - /** Map a refused tshark document to the pcap operation's typed failure. */ const decodeTsharkPackets = async ( stdout: string, diff --git a/src/pcap/PcapProvider.ts b/src/pcap/PcapProvider.ts index e94c92d6be..6e7b77cbf6 100644 --- a/src/pcap/PcapProvider.ts +++ b/src/pcap/PcapProvider.ts @@ -32,7 +32,10 @@ import { type AnalysisCleanupReleaseClaim, } from "../domain/analysisErrorBase.js"; import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; -import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js"; +import { + analysisErrorWithCleanupDependencies, + analysisErrorWithCleanupFailure, +} from "../domain/analysisErrorCleanup.js"; import { err, ok, type Result } from "../domain/result.js"; import type { ProviderProcessSupervisor } from "../process/ProviderProcess.js"; import { @@ -457,11 +460,7 @@ export class PcapProvider { cause, this.#failureDialect(operation), ); - throw analysisErrorWithCleanupFailure( - primary, - pending, - operation, - ).bindCleanupDependencies([primary, pending]); + throw analysisErrorWithCleanupDependencies(primary, pending, operation); } throw cause; } diff --git a/src/process/ArtifactAnalysisResources.ts b/src/process/ArtifactAnalysisResources.ts index 2a25cbe1cf..f1362dcbe4 100644 --- a/src/process/ArtifactAnalysisResources.ts +++ b/src/process/ArtifactAnalysisResources.ts @@ -19,7 +19,7 @@ import { cancelledBy, carriedReason, } from "../domain/analysisErrorCore.js"; -import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js"; +import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js"; import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; import { fixedAllowanceOptions, @@ -433,11 +433,7 @@ export class ArtifactAnalysisResources { (primary ?? failure).retainPartialObservation(cause.partialObservation); return primary === undefined ? failure - : analysisErrorWithCleanupFailure( - primary, - failure, - operation, - ).bindCleanupDependencies([primary, failure]); + : analysisErrorWithCleanupDependencies(primary, failure, operation); } commandFailure( @@ -532,11 +528,11 @@ export class ArtifactAnalysisResources { await this.release(); } catch (cause: unknown) { if (descriptorFailure !== undefined && cause instanceof AnalysisError) - throw analysisErrorWithCleanupFailure( + throw analysisErrorWithCleanupDependencies( descriptorFailure, cause, this.#artifacts.operation, - ).bindCleanupDependencies([descriptorFailure, cause]); + ); throw cause; } if (descriptorFailure !== undefined) throw descriptorFailure; diff --git a/src/sqlite/SqliteDatabaseWorkerExecution.ts b/src/sqlite/SqliteDatabaseWorkerExecution.ts index 32e79b1418..8cc3bf1335 100644 --- a/src/sqlite/SqliteDatabaseWorkerExecution.ts +++ b/src/sqlite/SqliteDatabaseWorkerExecution.ts @@ -17,7 +17,7 @@ import type { AnalysisCapturedOutput, AnalysisError, } from "../domain/analysisErrorBase.js"; -import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js"; +import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js"; import { ProviderCleanupError } from "../domain/providerCleanupError.js"; import { AnalysisInputError, @@ -335,11 +335,7 @@ const sqliteReplyCompletionFailure = ( carriedReason(artifactFileCancellationCause(cause)), { capturedOutput }, ); - return analysisErrorWithCleanupFailure( - cancellation, - cleanup, - operation, - ).bindCleanupDependencies([cancellation, cleanup]); + return analysisErrorWithCleanupDependencies(cancellation, cleanup, operation); }; /** A malformed reply or producer refusal stays primary over its later close. */ @@ -350,9 +346,5 @@ export const sqliteReplyFinalizationFailure = ( finalization === undefined ? primary : finalization.cleanupIncomplete - ? analysisErrorWithCleanupFailure( - primary, - finalization, - operation, - ).bindCleanupDependencies([primary, finalization]) + ? analysisErrorWithCleanupDependencies(primary, finalization, operation) : primary.retainSecondaryFailure(finalization); diff --git a/tests/boundary/filesystem/ciChangeScope.test.ts b/tests/boundary/filesystem/ciChangeScope.test.ts index bc30f0753b..3bdd9da4b0 100644 --- a/tests/boundary/filesystem/ciChangeScope.test.ts +++ b/tests/boundary/filesystem/ciChangeScope.test.ts @@ -524,7 +524,7 @@ it("selects the tests a pull request affects and runs everything when it cannot reason: "401 affected test files exceed the 400-file selection cap", }, }); - const capped = await change(directory, many.slice(0, 81), "// edited\n"); + const capped = await change(directory, many.slice(0, 101), "// edited\n"); expect(await classify(directory, wide, capped)).toMatchObject({ testSelection: { mode: "selected" }, testShards: ["1/3", "2/3", "3/3"],