Give atomic Evidence and snapshot writes an explicit resource owner, preserve primary failures and completed publication receipts, and retry retained staging cleanup at the owning lifecycle. Verify inode identity before publishing or deleting; unknown path disappearance remains a cleanup failure. Keep snapshot admission reusable when a session closes and reopens. Consolidate JavaScript source-scope classification so cancellation cannot fabricate failures for unselected files. Classify configuration failures as invalid input. Remove stale assertions and reuse shared test cleanup ownership. Validation: 266 focused tests before final ownership tightening, 108 affected tests afterward, static and documentation checks, actual invalid-configuration CLI behavior, and isolated test temporary-directory hygiene. Refs #1968
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import {
|
|
AnalysisError,
|
|
type AnalysisErrorOptions,
|
|
} from "./analysisErrorBase.js";
|
|
|
|
/** Receipt retained when publication succeeded but staging cleanup did not. */
|
|
export interface PublishedEvidenceFile {
|
|
readonly path: string;
|
|
readonly bytes: number;
|
|
}
|
|
|
|
/** Evidence identity, schema, or bundle manifests failed integrity checks. */
|
|
export class EvidenceIntegrityError extends AnalysisError {
|
|
readonly _tag = "EvidenceIntegrityError";
|
|
override readonly userMessage: string | undefined;
|
|
|
|
constructor(
|
|
message: string,
|
|
options?: AnalysisErrorOptions & { readonly userMessage?: string },
|
|
) {
|
|
super(message, options);
|
|
this.userMessage = options?.userMessage;
|
|
}
|
|
}
|
|
|
|
/** A valid snapshot belongs to a different target, provider, or analysis profile. */
|
|
export class AnalysisSnapshotMismatchError extends EvidenceIntegrityError {}
|
|
|
|
/** A session Evidence reference is missing or has the wrong semantic identity. */
|
|
export class EvidenceReferenceError extends EvidenceIntegrityError {
|
|
constructor(
|
|
readonly evidenceId: string,
|
|
readonly reason:
|
|
| "missing"
|
|
| "wrong_operation"
|
|
| "wrong_predicate"
|
|
| "identity_mismatch",
|
|
readonly expected: string,
|
|
readonly actual: string | null,
|
|
) {
|
|
super(`Evidence reference ${reason}: ${evidenceId}`);
|
|
}
|
|
}
|
|
|
|
/** Evidence bundle filesystem access failed within the configured policy. */
|
|
export class EvidenceFileError extends AnalysisError {
|
|
readonly _tag = "EvidenceFileError";
|
|
|
|
/** Caller-selected path that failed, resolved against the working directory. */
|
|
readonly path: string | undefined;
|
|
/** Present only when a write committed before cleanup failed. */
|
|
readonly published: PublishedEvidenceFile | undefined;
|
|
|
|
constructor(
|
|
readonly operation: "read" | "write",
|
|
readonly reason: "not-file" | "exists" | "invalid-json" | "missing" | "io",
|
|
options?: AnalysisErrorOptions & {
|
|
readonly path?: string;
|
|
readonly published?: PublishedEvidenceFile;
|
|
},
|
|
) {
|
|
super(`Evidence bundle ${operation} failed: ${reason}`, options);
|
|
this.path = options?.path;
|
|
this.published = options?.published;
|
|
}
|
|
}
|