@agent-teams/engineering-foundation 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/capabilities/contract-json-schema-releases/module.d.ts.map +1 -1
- package/dist/capabilities/contract-json-schema-releases/module.js +4 -17
- package/dist/capabilities/contract-json-schema-releases/module.js.map +1 -1
- package/dist/capabilities/contract-protobuf-evolution/module.d.ts.map +1 -1
- package/dist/capabilities/contract-protobuf-evolution/module.js +4 -17
- package/dist/capabilities/contract-protobuf-evolution/module.js.map +1 -1
- package/dist/capabilities/documentation-local-references/module.d.ts.map +1 -1
- package/dist/capabilities/documentation-local-references/module.js +4 -17
- package/dist/capabilities/documentation-local-references/module.js.map +1 -1
- package/dist/capabilities/executable-specifications/module.d.ts.map +1 -1
- package/dist/capabilities/executable-specifications/module.js +4 -17
- package/dist/capabilities/executable-specifications/module.js.map +1 -1
- package/dist/capabilities/governance-architecture-decisions/module.d.ts.map +1 -1
- package/dist/capabilities/governance-architecture-decisions/module.js +4 -17
- package/dist/capabilities/governance-architecture-decisions/module.js.map +1 -1
- package/dist/capabilities/public-api-compatibility/module.d.ts.map +1 -1
- package/dist/capabilities/public-api-compatibility/module.js +4 -19
- package/dist/capabilities/public-api-compatibility/module.js.map +1 -1
- package/dist/capabilities/quality-gate-runner/module.d.ts.map +1 -1
- package/dist/capabilities/quality-gate-runner/module.js +4 -17
- package/dist/capabilities/quality-gate-runner/module.js.map +1 -1
- package/dist/capabilities/repository-agent-workflow/module.d.ts.map +1 -1
- package/dist/capabilities/repository-agent-workflow/module.js +4 -17
- package/dist/capabilities/repository-agent-workflow/module.js.map +1 -1
- package/dist/capabilities/repository-security-baseline/adapters/outbound/filesystem/workflow-evidence-parser.d.ts.map +1 -1
- package/dist/capabilities/repository-security-baseline/adapters/outbound/filesystem/workflow-evidence-parser.js +33 -0
- package/dist/capabilities/repository-security-baseline/adapters/outbound/filesystem/workflow-evidence-parser.js.map +1 -1
- package/dist/capabilities/repository-security-baseline/application/model/repository-security.d.ts +1 -0
- package/dist/capabilities/repository-security-baseline/application/model/repository-security.d.ts.map +1 -1
- package/dist/capabilities/repository-security-baseline/application/model/repository-security.js.map +1 -1
- package/dist/capabilities/repository-security-baseline/application/policies/dependency-review-ordering.js +1 -1
- package/dist/capabilities/repository-security-baseline/application/policies/dependency-review-ordering.js.map +1 -1
- package/dist/capabilities/repository-security-baseline/application/policies/evaluate-repository-security-tools.js +1 -1
- package/dist/capabilities/repository-security-baseline/application/policies/evaluate-repository-security-tools.js.map +1 -1
- package/dist/capabilities/repository-security-baseline/application/policies/evaluate-repository-security.js +1 -1
- package/dist/capabilities/repository-security-baseline/application/policies/evaluate-repository-security.js.map +1 -1
- package/dist/capabilities/repository-security-baseline/module.d.ts.map +1 -1
- package/dist/capabilities/repository-security-baseline/module.js +4 -17
- package/dist/capabilities/repository-security-baseline/module.js.map +1 -1
- package/dist/capabilities/source-dependencies/module.d.ts.map +1 -1
- package/dist/capabilities/source-dependencies/module.js +4 -19
- package/dist/capabilities/source-dependencies/module.js.map +1 -1
- package/dist/capabilities/suppression-governance/module.d.ts.map +1 -1
- package/dist/capabilities/suppression-governance/module.js +4 -19
- package/dist/capabilities/suppression-governance/module.js.map +1 -1
- package/dist/capabilities/workspace-dependency-declarations/module.d.ts.map +1 -1
- package/dist/capabilities/workspace-dependency-declarations/module.js +4 -18
- package/dist/capabilities/workspace-dependency-declarations/module.js.map +1 -1
- package/dist/capability-runtime.d.ts +8 -0
- package/dist/capability-runtime.d.ts.map +1 -1
- package/dist/capability-runtime.js +66 -0
- package/dist/capability-runtime.js.map +1 -1
- package/dist/check-runner.d.ts.map +1 -1
- package/dist/check-runner.js +16 -10
- package/dist/check-runner.js.map +1 -1
- package/dist/document-authoring/index.d.ts +6 -1
- package/dist/document-authoring/index.d.ts.map +1 -1
- package/dist/document-authoring/index.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/local-mode/index.d.ts +5 -0
- package/dist/local-mode/index.d.ts.map +1 -1
- package/dist/local-mode/index.js +5 -0
- package/dist/local-mode/index.js.map +1 -1
- package/dist/mutation/index.d.ts +8 -0
- package/dist/mutation/index.d.ts.map +1 -1
- package/dist/mutation/index.js.map +1 -1
- package/dist/mutation/qualification/index.d.ts +10 -0
- package/dist/mutation/qualification/index.d.ts.map +1 -0
- package/dist/mutation/qualification/index.js +6 -0
- package/dist/mutation/qualification/index.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-effects.d.ts +84 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-effects.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-effects.js +232 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-effects.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-faults.d.ts +9 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-faults.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-faults.js +2 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-faults.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-observation.d.ts +6 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-observation.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-observation.js +30 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-observation.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-operation.d.ts +11 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-operation.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-operation.js +159 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-operation.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-state.d.ts +9 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-state.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-state.js +21 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-state.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-cleanup.d.ts +9 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-cleanup.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-cleanup.js +203 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-cleanup.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-executor.d.ts +17 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-executor.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-executor.js +22 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-executor.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-observation.d.ts +15 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-observation.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-observation.js +47 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-observation.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured-cleanup.d.ts +29 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured-cleanup.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured-cleanup.js +72 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured-cleanup.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.d.ts +31 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.js +254 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage.d.ts +13 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage.js +210 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-retirement.d.ts +15 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-retirement.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-retirement.js +172 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-retirement.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-state.d.ts +12 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-state.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-state.js +17 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-state.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-recovery.d.ts +2 -5
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-recovery.d.ts.map +1 -1
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-recovery.js +18 -860
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-recovery.js.map +1 -1
- package/dist/repository-mutation/adapters/node/node-known-file-transaction.d.ts +3 -9
- package/dist/repository-mutation/adapters/node/node-known-file-transaction.d.ts.map +1 -1
- package/dist/repository-mutation/adapters/node/node-known-file-transaction.js +35 -451
- package/dist/repository-mutation/adapters/node/node-known-file-transaction.js.map +1 -1
- package/dist/repository-mutation/application/policies/classify-known-file-recovery-transition.d.ts +25 -0
- package/dist/repository-mutation/application/policies/classify-known-file-recovery-transition.d.ts.map +1 -0
- package/dist/repository-mutation/application/policies/classify-known-file-recovery-transition.js +19 -0
- package/dist/repository-mutation/application/policies/classify-known-file-recovery-transition.js.map +1 -0
- package/dist/unexpected-failure.d.ts +9 -0
- package/dist/unexpected-failure.d.ts.map +1 -0
- package/dist/unexpected-failure.js +105 -0
- package/dist/unexpected-failure.js.map +1 -0
- package/package.json +5 -1
package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured-cleanup.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { lstat, rmdir, unlink } from "node:fs/promises";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
import { deserializeKnownFileIdentity } from "../../application/model/known-file-transaction-journal.js";
|
|
4
|
+
import { syncDirectoryStrictly } from "./node-directory-durability.js";
|
|
5
|
+
import { knownFileErrorCode, KnownFileTransactionError, matchesKnownFileImage, sameKnownFileIdentity } from "./node-known-file-transaction-filesystem.js";
|
|
6
|
+
import { observeRecoveryFile } from "./node-known-file-recovery-filesystem.js";
|
|
7
|
+
function matchesRollbackCopy(observed, expected, preimage) {
|
|
8
|
+
return observed.state === "file" && observed.identity !== undefined &&
|
|
9
|
+
sameKnownFileIdentity(observed.identity, expected) &&
|
|
10
|
+
matchesKnownFileImage(observed, preimage);
|
|
11
|
+
}
|
|
12
|
+
export async function cleanupRestoredCapturedPreimage(options) {
|
|
13
|
+
const matched = options.journalOperation.matchedPreimage;
|
|
14
|
+
if (matched === undefined) {
|
|
15
|
+
throw new KnownFileTransactionError("KNOWN_FILE_JOURNAL_INVALID", `Restored replacement lacks exact preimage authority: ${options.operation.path}.`);
|
|
16
|
+
}
|
|
17
|
+
const preimage = options.operation.precondition.acceptedPreimages[matched];
|
|
18
|
+
const destinationObserved = await observeRecoveryFile(options.destination, options.recoveryMaximumBytes);
|
|
19
|
+
if (!matchesKnownFileImage(destinationObserved, preimage)) {
|
|
20
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Restored destination changed during cleanup: ${options.operation.path}.`);
|
|
21
|
+
}
|
|
22
|
+
const rollbackPath = join(options.parent, `.${basename(options.operation.path)}.agent-teams.rollback.${options.operationIndex}.tmp`);
|
|
23
|
+
if (options.journalOperation.rollbackTemporaryIdentity !== undefined) {
|
|
24
|
+
const rollbackObserved = await observeRecoveryFile(rollbackPath, preimage.size);
|
|
25
|
+
if (rollbackObserved.state === "file") {
|
|
26
|
+
const expectedRollback = deserializeKnownFileIdentity(options.journalOperation.rollbackTemporaryIdentity);
|
|
27
|
+
if (!matchesRollbackCopy(rollbackObserved, expectedRollback, preimage)) {
|
|
28
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Rollback copy changed during cleanup: ${options.operation.path}.`);
|
|
29
|
+
}
|
|
30
|
+
await unlink(rollbackPath);
|
|
31
|
+
await syncDirectoryStrictly(options.parent);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const directory = await lstat(options.paths.directory, { bigint: true }).catch((error) => {
|
|
35
|
+
if (knownFileErrorCode(error) === "ENOENT") {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
throw error;
|
|
39
|
+
});
|
|
40
|
+
if (directory === null) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const expectedDirectory = deserializeKnownFileIdentity(options.journalOperation.captureDirectoryIdentity);
|
|
44
|
+
if (!directory.isDirectory() || directory.isSymbolicLink() ||
|
|
45
|
+
directory.birthtimeNs !== expectedDirectory.birthtimeNs ||
|
|
46
|
+
directory.dev !== expectedDirectory.dev || directory.ino !== expectedDirectory.ino) {
|
|
47
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Rollback capture directory changed during cleanup: ${options.operation.path}.`);
|
|
48
|
+
}
|
|
49
|
+
const capturedObserved = await observeRecoveryFile(options.paths.captured, options.recoveryMaximumBytes);
|
|
50
|
+
if (capturedObserved.state === "file") {
|
|
51
|
+
const expectedCaptured = options.journalOperation.capturedPreimageIdentity;
|
|
52
|
+
if (expectedCaptured === undefined || capturedObserved.identity === undefined ||
|
|
53
|
+
!sameKnownFileIdentity(capturedObserved.identity, deserializeKnownFileIdentity(expectedCaptured)) ||
|
|
54
|
+
!matchesKnownFileImage(capturedObserved, preimage)) {
|
|
55
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Rollback capture changed during cleanup: ${options.operation.path}.`);
|
|
56
|
+
}
|
|
57
|
+
await unlink(options.paths.captured);
|
|
58
|
+
await syncDirectoryStrictly(options.paths.directory);
|
|
59
|
+
await options.faultInjector?.({
|
|
60
|
+
phase: "after-rollback-capture-unlinked",
|
|
61
|
+
operationIndex: options.operationIndex,
|
|
62
|
+
path: options.operation.path
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const retiredObserved = await observeRecoveryFile(options.paths.retired, options.recoveryMaximumBytes);
|
|
66
|
+
if (retiredObserved.state !== "absent") {
|
|
67
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Rollback capture retains foreign retired evidence: ${options.operation.path}.`);
|
|
68
|
+
}
|
|
69
|
+
await rmdir(options.paths.directory);
|
|
70
|
+
await syncDirectoryStrictly(options.parent);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=node-known-file-recovery-preimage-captured-cleanup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-known-file-recovery-preimage-captured-cleanup.js","sourceRoot":"","sources":["../../../../src/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured-cleanup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAI3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,2DAA2D,CAAC;AACzG,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAG/E,SAAS,mBAAmB,CAC1B,QAAyD,EACzD,QAAyD,EACzD,QAAuE;IAEvE,O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SAAS,CAAC,CAAC;IACrC,MAAM,qBAAqB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAC9C,CAAC"}
|
package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { KnownFileTransactionPlanV1 } from "../../application/model/known-file-transaction.js";
|
|
2
|
+
import type { KnownFileTransactionJournalV1 } from "../../application/model/known-file-transaction-journal.js";
|
|
3
|
+
import { type KnownFileRecoveryFaultInjector, type StoredRecoveryJournal } from "./node-known-file-recovery-state.js";
|
|
4
|
+
import type { NodeKnownFileTransactionJournalStore } from "./node-known-file-transaction-journal-store.js";
|
|
5
|
+
interface CapturedPreimageOptions {
|
|
6
|
+
readonly faultInjector?: KnownFileRecoveryFaultInjector;
|
|
7
|
+
readonly journalOperation: KnownFileTransactionJournalV1["operations"][number] & {
|
|
8
|
+
readonly captureDirectoryIdentity: NonNullable<Extract<KnownFileTransactionJournalV1["operations"][number], {
|
|
9
|
+
readonly temporaryIdentity: unknown;
|
|
10
|
+
}>["captureDirectoryIdentity"]>;
|
|
11
|
+
readonly temporaryIdentity: NonNullable<Extract<KnownFileTransactionJournalV1["operations"][number], {
|
|
12
|
+
readonly temporaryIdentity: unknown;
|
|
13
|
+
}>["temporaryIdentity"]>;
|
|
14
|
+
readonly capturedPreimageIdentity?: NonNullable<Extract<KnownFileTransactionJournalV1["operations"][number], {
|
|
15
|
+
readonly temporaryIdentity: unknown;
|
|
16
|
+
}>["capturedPreimageIdentity"]>;
|
|
17
|
+
};
|
|
18
|
+
readonly operation: KnownFileTransactionPlanV1["operations"][number] & {
|
|
19
|
+
readonly precondition: Extract<KnownFileTransactionPlanV1["operations"][number]["precondition"], {
|
|
20
|
+
readonly state: "known-file";
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
readonly operationIndex: number;
|
|
24
|
+
readonly planDigest: string;
|
|
25
|
+
readonly root: string;
|
|
26
|
+
readonly store: NodeKnownFileTransactionJournalStore;
|
|
27
|
+
readonly stored: StoredRecoveryJournal;
|
|
28
|
+
}
|
|
29
|
+
export declare function restoreCapturedPreimage(options: CapturedPreimageOptions): Promise<void>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=node-known-file-recovery-preimage-captured.d.ts.map
|
package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-known-file-recovery-preimage-captured.d.ts","sourceRoot":"","sources":["../../../../src/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAoB,0BAA0B,EAAE,MAAM,mDAAmD,CAAC;AACtH,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2DAA2D,CAAC;AAc/G,OAAO,EACL,KAAK,8BAA8B,EAGnC,KAAK,qBAAqB,EAC3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,gDAAgD,CAAC;AAM3G,UAAU,uBAAuB;IAC/B,QAAQ,CAAC,aAAa,CAAC,EAAE,8BAA8B,CAAC;IACxD,QAAQ,CAAC,gBAAgB,EAAE,6BAA6B,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,GAAG;QAC/E,QAAQ,CAAC,wBAAwB,EAAE,WAAW,CAAC,OAAO,CACpD,6BAA6B,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EACnD;YAAE,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAA;SAAE,CACxC,CAAC,0BAA0B,CAAC,CAAC,CAAC;QAC/B,QAAQ,CAAC,iBAAiB,EAAE,WAAW,CAAC,OAAO,CAC7C,6BAA6B,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EACnD;YAAE,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAA;SAAE,CACxC,CAAC,mBAAmB,CAAC,CAAC,CAAC;QACxB,QAAQ,CAAC,wBAAwB,CAAC,EAAE,WAAW,CAAC,OAAO,CACrD,6BAA6B,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EACnD;YAAE,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAA;SAAE,CACxC,CAAC,0BAA0B,CAAC,CAAC,CAAC;KAChC,CAAC;IACF,QAAQ,CAAC,SAAS,EAAE,0BAA0B,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,GAAG;QACrE,QAAQ,CAAC,YAAY,EAAE,OAAO,CAC5B,0BAA0B,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,EAChE;YAAE,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;SAAE,CACjC,CAAC;KACH,CAAC;IACF,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,oCAAoC,CAAC;IACrD,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;CACxC;AAsSD,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgF7F"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { link, lstat, rmdir, unlink } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
|
+
import { deserializeKnownFileIdentity } from "../../application/model/known-file-transaction-journal.js";
|
|
4
|
+
import { readBoundedRegularFile } from "./node-bounded-regular-file.js";
|
|
5
|
+
import { syncDirectoryStrictly } from "./node-directory-durability.js";
|
|
6
|
+
import { knownFileErrorCode, KnownFileTransactionError, matchesKnownFileImage, maximumKnownFileEvidenceBytes, sameKnownFileIdentity } from "./node-known-file-transaction-filesystem.js";
|
|
7
|
+
import { knownFileCapturePaths, observeRecoveryFile } from "./node-known-file-recovery-filesystem.js";
|
|
8
|
+
import { cleanupRestoredCapturedPreimage } from "./node-known-file-recovery-preimage-captured-cleanup.js";
|
|
9
|
+
import { retireJournalBoundPath } from "./node-known-file-recovery-retirement.js";
|
|
10
|
+
import { persistRecoveryJournal, replaceRecoveryOperation } from "./node-known-file-recovery-state.js";
|
|
11
|
+
async function assertCaptureDirectory(options, paths) {
|
|
12
|
+
const expectedDirectory = deserializeKnownFileIdentity(options.journalOperation.captureDirectoryIdentity);
|
|
13
|
+
const directory = await lstat(paths.directory, { bigint: true }).catch((error) => {
|
|
14
|
+
if (knownFileErrorCode(error) === "ENOENT") {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
throw error;
|
|
18
|
+
});
|
|
19
|
+
if (directory === null || !directory.isDirectory() || directory.isSymbolicLink() ||
|
|
20
|
+
directory.birthtimeNs !== expectedDirectory.birthtimeNs ||
|
|
21
|
+
directory.dev !== expectedDirectory.dev || directory.ino !== expectedDirectory.ino) {
|
|
22
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Replacement capture directory changed: ${options.operation.path}.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function restoreUnboundCapturedPreimage(options, context, captured, retired) {
|
|
26
|
+
if (retired.state !== "absent" || captured.state !== "absent") {
|
|
27
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Replacement capture contains bytes without durable identity authority: ${options.operation.path}.`);
|
|
28
|
+
}
|
|
29
|
+
const stableDestination = await readBoundedRegularFile(context.destination, context.preimage.size);
|
|
30
|
+
if (stableDestination.outcome !== "read" || stableDestination.linkCount !== 1n ||
|
|
31
|
+
!matchesKnownFileImage({
|
|
32
|
+
state: "file",
|
|
33
|
+
bytes: stableDestination.bytes,
|
|
34
|
+
identity: stableDestination.identity,
|
|
35
|
+
mode: stableDestination.mode & 0o777
|
|
36
|
+
}, context.preimage)) {
|
|
37
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Uncaptured replacement preimage is not an exclusive exact file: ${options.operation.path}.`);
|
|
38
|
+
}
|
|
39
|
+
const restoredOperation = Object.freeze({
|
|
40
|
+
...options.journalOperation,
|
|
41
|
+
state: "rollback-restored"
|
|
42
|
+
});
|
|
43
|
+
await persistRecoveryJournal(options.store, options.stored, replaceRecoveryOperation(options.stored.envelope.journal, options.operationIndex, restoredOperation));
|
|
44
|
+
await rmdir(context.paths.directory);
|
|
45
|
+
await syncDirectoryStrictly(context.parent);
|
|
46
|
+
}
|
|
47
|
+
function capturedRollbackAuthority(options, context, captured, rollbackObserved, rollbackIdentity) {
|
|
48
|
+
const capturedIdentity = deserializeKnownFileIdentity(options.journalOperation.capturedPreimageIdentity);
|
|
49
|
+
if (captured.state !== "file" || captured.identity === undefined ||
|
|
50
|
+
!sameKnownFileIdentity(captured.identity, capturedIdentity)) {
|
|
51
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Captured replacement identity changed: ${options.operation.path}.`);
|
|
52
|
+
}
|
|
53
|
+
const captureBytesStable = matchesKnownFileImage(captured, context.preimage);
|
|
54
|
+
if (rollbackIdentity !== undefined &&
|
|
55
|
+
(rollbackObserved.state !== "file" || rollbackObserved.identity === undefined ||
|
|
56
|
+
!sameKnownFileIdentity(rollbackObserved.identity, rollbackIdentity) ||
|
|
57
|
+
!matchesKnownFileImage(rollbackObserved, context.preimage))) {
|
|
58
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Rollback preimage copy changed: ${options.operation.path}.`);
|
|
59
|
+
}
|
|
60
|
+
if (rollbackIdentity === undefined && !captureBytesStable) {
|
|
61
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Captured preimage changed before a stable rollback copy existed: ${options.operation.path}.`);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
captureBytesStable,
|
|
65
|
+
capturedIdentity,
|
|
66
|
+
rollbackSource: rollbackIdentity === undefined ? context.paths.captured : join(context.parent, `.${basename(options.operation.path)}.agent-teams.rollback.${options.operationIndex}.tmp`),
|
|
67
|
+
rollbackSourceIdentity: rollbackIdentity ?? capturedIdentity
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async function reconcileInterruptedRetiredCapture(options, context, retired, destinationBefore, capturedIdentity) {
|
|
71
|
+
if (retired.state !== "file") {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (retired.identity !== undefined && sameKnownFileIdentity(retired.identity, capturedIdentity)) {
|
|
75
|
+
await unlink(context.paths.retired);
|
|
76
|
+
await syncDirectoryStrictly(context.paths.directory);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
if (destinationBefore.state === "absent") {
|
|
80
|
+
await link(context.paths.retired, context.destination);
|
|
81
|
+
await syncDirectoryStrictly(context.parent);
|
|
82
|
+
await unlink(context.paths.retired);
|
|
83
|
+
await syncDirectoryStrictly(context.paths.directory);
|
|
84
|
+
}
|
|
85
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Foreign destination was preserved from an interrupted capture: ${options.operation.path}.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function acceptForeignExactPreimage(options, context, observed, recovery) {
|
|
89
|
+
if (!matchesKnownFileImage(observed, context.preimage) ||
|
|
90
|
+
(observed.identity !== undefined &&
|
|
91
|
+
sameKnownFileIdentity(observed.identity, recovery.rollbackSourceIdentity))) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const restoredJournalOperation = Object.freeze({
|
|
95
|
+
...options.journalOperation,
|
|
96
|
+
state: "rollback-restored"
|
|
97
|
+
});
|
|
98
|
+
await persistRecoveryJournal(options.store, options.stored, Object.freeze({
|
|
99
|
+
...options.stored.envelope.journal,
|
|
100
|
+
operations: Object.freeze(options.stored.envelope.journal.operations.with(options.operationIndex, restoredJournalOperation))
|
|
101
|
+
}));
|
|
102
|
+
if (recovery.rollbackIdentity !== undefined) {
|
|
103
|
+
await unlink(join(context.parent, `.${basename(options.operation.path)}.agent-teams.rollback.${options.operationIndex}.tmp`));
|
|
104
|
+
}
|
|
105
|
+
if (recovery.captureBytesStable) {
|
|
106
|
+
await unlink(context.paths.captured);
|
|
107
|
+
}
|
|
108
|
+
await syncDirectoryStrictly(context.paths.directory);
|
|
109
|
+
if (recovery.captureBytesStable) {
|
|
110
|
+
await options.faultInjector?.({
|
|
111
|
+
phase: "after-rollback-capture-unlinked",
|
|
112
|
+
operationIndex: options.operationIndex,
|
|
113
|
+
path: options.operation.path
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (recovery.captureBytesStable) {
|
|
117
|
+
await rmdir(context.paths.directory);
|
|
118
|
+
}
|
|
119
|
+
await syncDirectoryStrictly(context.parent);
|
|
120
|
+
if (!recovery.captureBytesStable) {
|
|
121
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Edited retired inode was preserved after exact rollback: ${options.operation.path}.`);
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
async function retireCapturedPostimage(options, observed) {
|
|
126
|
+
if (observed.state !== "file") {
|
|
127
|
+
return observed;
|
|
128
|
+
}
|
|
129
|
+
const temporaryIdentity = deserializeKnownFileIdentity(options.journalOperation.temporaryIdentity);
|
|
130
|
+
if (!matchesKnownFileImage(observed, options.operation.postimage) ||
|
|
131
|
+
observed.identity === undefined ||
|
|
132
|
+
!sameKnownFileIdentity(observed.identity, temporaryIdentity)) {
|
|
133
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Destination changed before captured-preimage rollback: ${options.operation.path}.`);
|
|
134
|
+
}
|
|
135
|
+
await retireJournalBoundPath({
|
|
136
|
+
expectedIdentity: temporaryIdentity,
|
|
137
|
+
...(options.faultInjector === undefined ? {} : { faultInjector: options.faultInjector }),
|
|
138
|
+
kind: "destination",
|
|
139
|
+
operationIndex: options.operationIndex,
|
|
140
|
+
root: options.root,
|
|
141
|
+
store: options.store,
|
|
142
|
+
stored: options.stored
|
|
143
|
+
});
|
|
144
|
+
await options.faultInjector?.({
|
|
145
|
+
phase: "after-destination-retired",
|
|
146
|
+
operationIndex: options.operationIndex,
|
|
147
|
+
path: options.operation.path
|
|
148
|
+
});
|
|
149
|
+
return { state: "absent" };
|
|
150
|
+
}
|
|
151
|
+
async function completeCapturedRollback(options, context, observed, recovery) {
|
|
152
|
+
if (observed.state === "absent") {
|
|
153
|
+
await link(recovery.rollbackSource, context.destination).catch((error) => {
|
|
154
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Destination appeared during captured-preimage rollback: ${options.operation.path}.`, { cause: error });
|
|
155
|
+
});
|
|
156
|
+
await options.faultInjector?.({
|
|
157
|
+
phase: "after-rollback-linked",
|
|
158
|
+
operationIndex: options.operationIndex,
|
|
159
|
+
path: options.operation.path
|
|
160
|
+
});
|
|
161
|
+
await syncDirectoryStrictly(context.parent);
|
|
162
|
+
}
|
|
163
|
+
const restored = await observeRecoveryFile(context.destination, context.preimage.size);
|
|
164
|
+
if (!matchesKnownFileImage(restored, context.preimage) || restored.identity === undefined ||
|
|
165
|
+
!sameKnownFileIdentity(restored.identity, recovery.rollbackSourceIdentity)) {
|
|
166
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_FAILED", `Captured preimage restoration failed: ${options.operation.path}.`);
|
|
167
|
+
}
|
|
168
|
+
await persistRecoveryJournal(options.store, options.stored, Object.freeze({
|
|
169
|
+
...options.stored.envelope.journal,
|
|
170
|
+
operations: Object.freeze(options.stored.envelope.journal.operations.with(options.operationIndex, Object.freeze({ ...options.journalOperation, state: "rollback-restored" })))
|
|
171
|
+
}));
|
|
172
|
+
if (recovery.rollbackIdentity !== undefined) {
|
|
173
|
+
await unlink(recovery.rollbackSource);
|
|
174
|
+
}
|
|
175
|
+
if (recovery.captureBytesStable) {
|
|
176
|
+
await unlink(context.paths.captured);
|
|
177
|
+
}
|
|
178
|
+
await syncDirectoryStrictly(context.paths.directory);
|
|
179
|
+
if (recovery.captureBytesStable) {
|
|
180
|
+
await options.faultInjector?.({
|
|
181
|
+
phase: "after-rollback-capture-unlinked",
|
|
182
|
+
operationIndex: options.operationIndex,
|
|
183
|
+
path: options.operation.path
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (recovery.captureBytesStable) {
|
|
187
|
+
await rmdir(context.paths.directory);
|
|
188
|
+
}
|
|
189
|
+
await syncDirectoryStrictly(context.parent);
|
|
190
|
+
if (!recovery.captureBytesStable) {
|
|
191
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Edited retired inode was preserved after exact rollback: ${options.operation.path}.`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
export async function restoreCapturedPreimage(options) {
|
|
195
|
+
const destination = join(options.root, ...options.operation.path.split("/"));
|
|
196
|
+
const parent = dirname(destination);
|
|
197
|
+
const paths = knownFileCapturePaths({
|
|
198
|
+
operationIndex: options.operationIndex,
|
|
199
|
+
operationPath: options.operation.path,
|
|
200
|
+
parent,
|
|
201
|
+
planDigest: options.planDigest
|
|
202
|
+
});
|
|
203
|
+
const recoveryMaximumBytes = Math.max(maximumKnownFileEvidenceBytes(options.operation), 8 * 1024 * 1024);
|
|
204
|
+
if (options.journalOperation.state === "rollback-restored") {
|
|
205
|
+
await cleanupRestoredCapturedPreimage({
|
|
206
|
+
...(options.faultInjector === undefined ? {} : { faultInjector: options.faultInjector }),
|
|
207
|
+
destination,
|
|
208
|
+
journalOperation: options.journalOperation,
|
|
209
|
+
operation: options.operation,
|
|
210
|
+
operationIndex: options.operationIndex,
|
|
211
|
+
parent,
|
|
212
|
+
paths,
|
|
213
|
+
recoveryMaximumBytes
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
await assertCaptureDirectory(options, paths);
|
|
218
|
+
const captured = await observeRecoveryFile(paths.captured, recoveryMaximumBytes);
|
|
219
|
+
const destinationBefore = await observeRecoveryFile(destination, recoveryMaximumBytes);
|
|
220
|
+
const retired = await observeRecoveryFile(paths.retired, recoveryMaximumBytes);
|
|
221
|
+
const matched = options.journalOperation.matchedPreimage;
|
|
222
|
+
if (matched === undefined) {
|
|
223
|
+
throw new KnownFileTransactionError("KNOWN_FILE_JOURNAL_INVALID", `Captured replacement lacks its exact preimage binding: ${options.operation.path}.`);
|
|
224
|
+
}
|
|
225
|
+
const context = {
|
|
226
|
+
destination,
|
|
227
|
+
parent,
|
|
228
|
+
paths,
|
|
229
|
+
preimage: options.operation.precondition.acceptedPreimages[matched],
|
|
230
|
+
recoveryMaximumBytes
|
|
231
|
+
};
|
|
232
|
+
if (options.journalOperation.capturedPreimageIdentity === undefined) {
|
|
233
|
+
await restoreUnboundCapturedPreimage(options, context, captured, retired);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const rollbackPath = join(parent, `.${basename(options.operation.path)}.agent-teams.rollback.${options.operationIndex}.tmp`);
|
|
237
|
+
const rollbackIdentity = options.journalOperation.rollbackTemporaryIdentity === undefined
|
|
238
|
+
? undefined
|
|
239
|
+
: deserializeKnownFileIdentity(options.journalOperation.rollbackTemporaryIdentity);
|
|
240
|
+
const rollbackObserved = rollbackIdentity === undefined
|
|
241
|
+
? { state: "absent" }
|
|
242
|
+
: await observeRecoveryFile(rollbackPath, context.preimage.size);
|
|
243
|
+
const authority = capturedRollbackAuthority(options, context, captured, rollbackObserved, rollbackIdentity);
|
|
244
|
+
await reconcileInterruptedRetiredCapture(options, context, retired, destinationBefore, authority.capturedIdentity);
|
|
245
|
+
let observed = await observeRecoveryFile(destination, recoveryMaximumBytes);
|
|
246
|
+
if (await acceptForeignExactPreimage(options, context, observed, { ...authority, rollbackIdentity })) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (!matchesKnownFileImage(observed, context.preimage)) {
|
|
250
|
+
observed = await retireCapturedPostimage(options, observed);
|
|
251
|
+
}
|
|
252
|
+
await completeCapturedRollback(options, context, observed, { ...authority, rollbackIdentity });
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=node-known-file-recovery-preimage-captured.js.map
|
package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-known-file-recovery-preimage-captured.js","sourceRoot":"","sources":["../../../../src/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,2DAA2D,CAAC;AACzG,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,qBAAqB,EACrB,6BAA6B,EAC7B,qBAAqB,EACtB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AACtG,OAAO,EAAE,+BAA+B,EAAE,MAAM,yDAAyD,CAAC;AAC1G,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,EAEL,sBAAsB,EACtB,wBAAwB,EAEzB,MAAM,qCAAqC,CAAC;AA4C7C,KAAK,UAAU,sBAAsB,CACnC,OAAgC,EAChC,KAAoB;IAEpB,MAAM,iBAAiB,GAAG,4BAA4B,CACpD,OAAO,CAAC,gBAAgB,CAAC,wBAAwB,CAClD,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,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,mBAAmB,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;IAC5E,IAAI,MAAM,0BAA0B,CAClC,OAAO,EACP,OAAO,EACP,QAAQ,EACR,EAAE,GAAG,SAAS,EAAE,gBAAgB,EAAE,CACnC,EAAE,CAAC;QAAA,OAAO;IAAA,CAAC;IACZ,IAAI,CAAC,qBAAqB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvD,QAAQ,GAAG,MAAM,uBAAuB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,wBAAwB,CAC5B,OAAO,EACP,OAAO,EACP,QAAQ,EACR,EAAE,GAAG,SAAS,EAAE,gBAAgB,EAAE,CACnC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { KnownFileTransactionPlanV1 } from "../../application/model/known-file-transaction.js";
|
|
2
|
+
import { type KnownFileRecoveryFaultInjector, type StoredRecoveryJournal } from "./node-known-file-recovery-state.js";
|
|
3
|
+
import type { NodeKnownFileTransactionJournalStore } from "./node-known-file-transaction-journal-store.js";
|
|
4
|
+
export interface RestorePreimageOptions {
|
|
5
|
+
readonly faultInjector?: KnownFileRecoveryFaultInjector;
|
|
6
|
+
readonly operation: KnownFileTransactionPlanV1["operations"][number];
|
|
7
|
+
readonly operationIndex: number;
|
|
8
|
+
readonly root: string;
|
|
9
|
+
readonly store: NodeKnownFileTransactionJournalStore;
|
|
10
|
+
readonly stored: StoredRecoveryJournal;
|
|
11
|
+
}
|
|
12
|
+
export declare function restorePreimage(options: RestorePreimageOptions): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=node-known-file-recovery-preimage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-known-file-recovery-preimage.d.ts","sourceRoot":"","sources":["../../../../src/repository-mutation/adapters/node/node-known-file-recovery-preimage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,0BAA0B,EAC3B,MAAM,mDAAmD,CAAC;AAuB3D,OAAO,EACL,KAAK,8BAA8B,EAEnC,KAAK,qBAAqB,EAC3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,gDAAgD,CAAC;AA0G3G,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,aAAa,CAAC,EAAE,8BAA8B,CAAC;IACxD,QAAQ,CAAC,SAAS,EAAE,0BAA0B,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;IACrE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,oCAAoC,CAAC;IACrD,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;CACxC;AAkJD,wBAAsB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6CpF"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { link } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
|
+
import { deserializeKnownFileIdentity, serializeKnownFileIdentity } from "../../application/model/known-file-transaction-journal.js";
|
|
4
|
+
import { pathMatchesRegularFileIdentity, readBoundedRegularFile } from "./node-bounded-regular-file.js";
|
|
5
|
+
import { syncDirectoryStrictly } from "./node-directory-durability.js";
|
|
6
|
+
import { KnownFileTransactionError, matchesKnownFileImage, maximumKnownFileEvidenceBytes, sameKnownFileIdentity } from "./node-known-file-transaction-filesystem.js";
|
|
7
|
+
import { observeRecoveryFile, prepareRollbackTemporary } from "./node-known-file-recovery-filesystem.js";
|
|
8
|
+
import { restoreCapturedPreimage } from "./node-known-file-recovery-preimage-captured.js";
|
|
9
|
+
import { retireJournalBoundPath } from "./node-known-file-recovery-retirement.js";
|
|
10
|
+
import { persistRecoveryJournal } from "./node-known-file-recovery-state.js";
|
|
11
|
+
async function restoreAbsentPreimage(options) {
|
|
12
|
+
if (options.observed.state === "absent") {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (!matchesKnownFileImage(options.observed, options.operation.postimage) ||
|
|
16
|
+
options.observed.identity === undefined ||
|
|
17
|
+
!("temporaryIdentity" in options.journalOperation) ||
|
|
18
|
+
!sameKnownFileIdentity(options.observed.identity, deserializeKnownFileIdentity(options.journalOperation.temporaryIdentity))) {
|
|
19
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Created destination changed after publication: ${options.operation.path}.`);
|
|
20
|
+
}
|
|
21
|
+
await retireJournalBoundPath({
|
|
22
|
+
expectedIdentity: options.observed.identity,
|
|
23
|
+
...(options.faultInjector === undefined ? {} : { faultInjector: options.faultInjector }),
|
|
24
|
+
kind: "destination",
|
|
25
|
+
operationIndex: options.operationIndex,
|
|
26
|
+
root: options.root,
|
|
27
|
+
store: options.store,
|
|
28
|
+
stored: options.stored
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function acceptRestoredPreimage(options) {
|
|
32
|
+
if (!matchesKnownFileImage(options.observed, options.preimage)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (options.journalOperation.rollbackTemporaryIdentity !== undefined &&
|
|
36
|
+
options.observed.identity !== undefined &&
|
|
37
|
+
sameKnownFileIdentity(options.observed.identity, deserializeKnownFileIdentity(options.journalOperation.rollbackTemporaryIdentity))) {
|
|
38
|
+
await retireJournalBoundPath({
|
|
39
|
+
expectedIdentity: options.observed.identity,
|
|
40
|
+
kind: "rollback-temporary",
|
|
41
|
+
operationIndex: options.operationIndex,
|
|
42
|
+
root: options.root,
|
|
43
|
+
store: options.store,
|
|
44
|
+
stored: options.stored
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
function assertPublishedIdentity(options) {
|
|
50
|
+
if (options.observed.identity === undefined ||
|
|
51
|
+
!sameKnownFileIdentity(options.observed.identity, deserializeKnownFileIdentity(options.journalOperation.temporaryIdentity))) {
|
|
52
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Published destination identity changed before rollback: ${options.operationPath}.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function assertRollbackTemporary(options) {
|
|
56
|
+
if (options.observed.outcome !== "read" ||
|
|
57
|
+
!sameKnownFileIdentity(options.observed.identity, options.identity) ||
|
|
58
|
+
!matchesKnownFileImage({
|
|
59
|
+
state: "file", bytes: options.observed.bytes, identity: options.observed.identity,
|
|
60
|
+
mode: options.observed.mode & 0o777
|
|
61
|
+
}, options.preimage)) {
|
|
62
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Rollback temporary changed before copy: ${options.operationPath}.`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function restoreUncapturedPreimage(options) {
|
|
66
|
+
const operation = options.operation;
|
|
67
|
+
let journalOperation = options.journalOperation;
|
|
68
|
+
const observed = await observeRecoveryFile(options.destination, maximumKnownFileEvidenceBytes(operation));
|
|
69
|
+
const postMatches = matchesKnownFileImage(observed, operation.postimage);
|
|
70
|
+
if (!("temporaryIdentity" in journalOperation)) {
|
|
71
|
+
throw new KnownFileTransactionError("KNOWN_FILE_JOURNAL_INVALID", `Published operation lacks temporary identity authority: ${operation.path}.`);
|
|
72
|
+
}
|
|
73
|
+
const matched = journalOperation.matchedPreimage;
|
|
74
|
+
if (matched === undefined) {
|
|
75
|
+
throw new KnownFileTransactionError("KNOWN_FILE_JOURNAL_INVALID", `Replacement preimage binding is absent: ${operation.path}.`);
|
|
76
|
+
}
|
|
77
|
+
const preimage = operation.precondition.acceptedPreimages[matched];
|
|
78
|
+
if (await acceptRestoredPreimage({
|
|
79
|
+
journalOperation,
|
|
80
|
+
observed,
|
|
81
|
+
operationIndex: options.operationIndex,
|
|
82
|
+
operationPath: operation.path,
|
|
83
|
+
preimage,
|
|
84
|
+
root: options.root,
|
|
85
|
+
store: options.store,
|
|
86
|
+
stored: options.stored
|
|
87
|
+
})) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const resumingAfterRetirement = observed.state === "absent" &&
|
|
91
|
+
journalOperation.rollbackTemporaryIdentity !== undefined;
|
|
92
|
+
if (!postMatches && !resumingAfterRetirement) {
|
|
93
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Published destination changed before rollback: ${operation.path}.`);
|
|
94
|
+
}
|
|
95
|
+
if (postMatches) {
|
|
96
|
+
assertPublishedIdentity({ journalOperation, observed, operationPath: operation.path });
|
|
97
|
+
}
|
|
98
|
+
const rollbackPath = join(options.parent, `.${basename(operation.path)}.agent-teams.rollback.${options.operationIndex}.tmp`);
|
|
99
|
+
const rollbackIdentity = await prepareRollbackTemporary({
|
|
100
|
+
...(journalOperation.rollbackTemporaryIdentity === undefined
|
|
101
|
+
? {}
|
|
102
|
+
: {
|
|
103
|
+
expectedIdentity: deserializeKnownFileIdentity(journalOperation.rollbackTemporaryIdentity)
|
|
104
|
+
}),
|
|
105
|
+
operationPath: operation.path,
|
|
106
|
+
path: rollbackPath,
|
|
107
|
+
preimage
|
|
108
|
+
});
|
|
109
|
+
await syncDirectoryStrictly(options.parent);
|
|
110
|
+
if (await pathMatchesRegularFileIdentity(rollbackPath, rollbackIdentity) !== "match") {
|
|
111
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Rollback temporary changed before durable identity binding: ${operation.path}.`);
|
|
112
|
+
}
|
|
113
|
+
if (journalOperation.rollbackTemporaryIdentity === undefined) {
|
|
114
|
+
journalOperation = Object.freeze({
|
|
115
|
+
...journalOperation,
|
|
116
|
+
rollbackTemporaryIdentity: serializeKnownFileIdentity(rollbackIdentity)
|
|
117
|
+
});
|
|
118
|
+
await persistRecoveryJournal(options.store, options.stored, Object.freeze({
|
|
119
|
+
...options.stored.envelope.journal,
|
|
120
|
+
operations: Object.freeze(options.stored.envelope.journal.operations.with(options.operationIndex, journalOperation))
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
if (!resumingAfterRetirement) {
|
|
124
|
+
await retireJournalBoundPath({
|
|
125
|
+
expectedIdentity: observed.identity,
|
|
126
|
+
...(options.faultInjector === undefined ? {} : { faultInjector: options.faultInjector }),
|
|
127
|
+
kind: "destination",
|
|
128
|
+
operationIndex: options.operationIndex,
|
|
129
|
+
root: options.root,
|
|
130
|
+
store: options.store,
|
|
131
|
+
stored: options.stored
|
|
132
|
+
});
|
|
133
|
+
await options.faultInjector?.({
|
|
134
|
+
phase: "after-destination-retired",
|
|
135
|
+
operationIndex: options.operationIndex,
|
|
136
|
+
path: operation.path
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const prepared = await readBoundedRegularFile(rollbackPath, preimage.size);
|
|
140
|
+
assertRollbackTemporary({
|
|
141
|
+
identity: rollbackIdentity,
|
|
142
|
+
observed: prepared,
|
|
143
|
+
operationPath: operation.path,
|
|
144
|
+
preimage
|
|
145
|
+
});
|
|
146
|
+
await link(rollbackPath, options.destination).catch((error) => {
|
|
147
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Destination appeared during rollback CAS: ${operation.path}.`, { cause: error });
|
|
148
|
+
});
|
|
149
|
+
await options.faultInjector?.({
|
|
150
|
+
phase: "after-rollback-linked",
|
|
151
|
+
operationIndex: options.operationIndex,
|
|
152
|
+
path: operation.path
|
|
153
|
+
});
|
|
154
|
+
await syncDirectoryStrictly(options.parent);
|
|
155
|
+
const restored = await observeRecoveryFile(options.destination, preimage.size);
|
|
156
|
+
if (!matchesKnownFileImage(restored, preimage) || restored.identity === undefined ||
|
|
157
|
+
!sameKnownFileIdentity(restored.identity, rollbackIdentity)) {
|
|
158
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_FAILED", `Preimage restoration failed: ${operation.path}.`);
|
|
159
|
+
}
|
|
160
|
+
await retireJournalBoundPath({
|
|
161
|
+
expectedIdentity: rollbackIdentity,
|
|
162
|
+
...(options.faultInjector === undefined ? {} : { faultInjector: options.faultInjector }),
|
|
163
|
+
kind: "rollback-temporary",
|
|
164
|
+
operationIndex: options.operationIndex,
|
|
165
|
+
root: options.root,
|
|
166
|
+
store: options.store,
|
|
167
|
+
stored: options.stored
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
export async function restorePreimage(options) {
|
|
171
|
+
const operation = options.operation;
|
|
172
|
+
const journalOperation = options.stored.envelope.journal.operations[options.operationIndex];
|
|
173
|
+
const destination = join(options.root, ...operation.path.split("/"));
|
|
174
|
+
const parent = dirname(destination);
|
|
175
|
+
if (operation.precondition.state === "absent") {
|
|
176
|
+
const observed = await observeRecoveryFile(destination, maximumKnownFileEvidenceBytes(operation));
|
|
177
|
+
await restoreAbsentPreimage({
|
|
178
|
+
...(options.faultInjector === undefined ? {} : { faultInjector: options.faultInjector }),
|
|
179
|
+
journalOperation,
|
|
180
|
+
observed,
|
|
181
|
+
operation,
|
|
182
|
+
operationIndex: options.operationIndex,
|
|
183
|
+
root: options.root,
|
|
184
|
+
store: options.store,
|
|
185
|
+
stored: options.stored
|
|
186
|
+
});
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (journalOperation.captureDirectoryIdentity !== undefined) {
|
|
190
|
+
await restoreCapturedPreimage({
|
|
191
|
+
...(options.faultInjector === undefined ? {} : { faultInjector: options.faultInjector }),
|
|
192
|
+
journalOperation: journalOperation,
|
|
193
|
+
operation: { ...operation, precondition: operation.precondition },
|
|
194
|
+
operationIndex: options.operationIndex,
|
|
195
|
+
planDigest: options.stored.envelope.journal.plan.planDigest,
|
|
196
|
+
root: options.root,
|
|
197
|
+
store: options.store,
|
|
198
|
+
stored: options.stored
|
|
199
|
+
});
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
await restoreUncapturedPreimage({
|
|
203
|
+
...options,
|
|
204
|
+
destination,
|
|
205
|
+
journalOperation,
|
|
206
|
+
operation: { ...operation, precondition: operation.precondition },
|
|
207
|
+
parent
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=node-known-file-recovery-preimage.js.map
|