@git-stunts/git-cas 6.2.0 → 6.4.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/ARCHITECTURE.md +16 -8
- package/CHANGELOG.md +63 -0
- package/README.md +20 -4
- package/UPGRADING.md +74 -0
- package/build-info.json +2 -2
- package/docs/API.md +283 -21
- package/docs/releases/v6.3.0.md +96 -0
- package/docs/releases/v6.4.0.md +128 -0
- package/index.d.ts +286 -2
- package/index.js +28 -0
- package/package.json +3 -1
- package/src/domain/errors/Codes.js +14 -0
- package/src/domain/services/CacheAcquisitionInventory.js +123 -0
- package/src/domain/services/CacheAcquisitionRegistry.js +188 -0
- package/src/domain/services/CacheSet.js +56 -5
- package/src/domain/services/CacheSetRegistry.js +7 -0
- package/src/domain/services/RepositoryDoctor.js +127 -5
- package/src/domain/services/RootSetPersistence.js +34 -2
- package/src/domain/services/StagingWorkspace.js +530 -0
- package/src/domain/services/StagingWorkspaceRegistry.js +545 -0
- package/src/domain/services/WorkspaceDescriptorCodec.js +144 -0
- package/src/domain/value-objects/CacheAcquisition.js +88 -0
- package/src/domain/value-objects/CacheAcquisitionRef.js +129 -0
- package/src/domain/value-objects/RetentionWitness.js +6 -1
- package/src/domain/value-objects/WorkspaceRef.js +151 -0
- package/src/infrastructure/adapters/GitRefAdapter.js +354 -2
- package/src/infrastructure/adapters/GitRepositoryInspectionAdapter.js +28 -10
- package/src/package-version.js +1 -1
- package/src/ports/GitRefPort.js +46 -0
- package/src/ports/RepositoryInspectionPort.js +5 -2
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { ErrorCodes } from '../errors/index.js';
|
|
2
2
|
import createCasError from '../errors/createCasError.js';
|
|
3
|
+
import { CACHE_ACQUISITION_REF_PREFIX } from '../value-objects/CacheAcquisitionRef.js';
|
|
3
4
|
import { CACHE_SET_REF_PREFIX } from '../value-objects/CacheSetRef.js';
|
|
4
5
|
import { EXPIRING_SET_REF_PREFIX } from '../value-objects/ExpiringSetRef.js';
|
|
5
6
|
import { ROOT_SET_REF_PREFIX } from '../value-objects/RootSetRef.js';
|
|
7
|
+
import { WORKSPACE_REF_PREFIX } from '../value-objects/WorkspaceRef.js';
|
|
6
8
|
import { VAULT_REF } from './VaultPersistence.js';
|
|
9
|
+
import {
|
|
10
|
+
cacheAcquisitionGroup,
|
|
11
|
+
createCacheAcquisitionInventory,
|
|
12
|
+
recordCacheAcquisition,
|
|
13
|
+
} from './CacheAcquisitionInventory.js';
|
|
7
14
|
|
|
8
15
|
export const DEFAULT_REPOSITORY_GRACE_PERIOD_MS = 14 * 24 * 60 * 60 * 1_000;
|
|
9
16
|
const DEFAULT_MAX_COLLECTIONS_PER_KIND = 100;
|
|
@@ -11,12 +18,13 @@ const MAX_COLLECTIONS_PER_KIND = 1_000;
|
|
|
11
18
|
|
|
12
19
|
/** Composes bounded, non-mutating repository and managed-collection evidence. */
|
|
13
20
|
export default class RepositoryDoctor {
|
|
14
|
-
constructor({ repository, rootSets, caches, expiringSets, vault, clock }) {
|
|
15
|
-
assertDependencies({ repository, rootSets, caches, expiringSets, vault });
|
|
21
|
+
constructor({ repository, rootSets, caches, expiringSets, workspaces, vault, clock }) {
|
|
22
|
+
assertDependencies({ repository, rootSets, caches, expiringSets, workspaces, vault });
|
|
16
23
|
this.repository = repository;
|
|
17
24
|
this.rootSets = rootSets;
|
|
18
25
|
this.caches = caches;
|
|
19
26
|
this.expiringSets = expiringSets;
|
|
27
|
+
this.workspaces = workspaces;
|
|
20
28
|
this.vault = vault;
|
|
21
29
|
this.clock = clock ?? { now: () => new Date() };
|
|
22
30
|
Object.freeze(this);
|
|
@@ -26,7 +34,11 @@ export default class RepositoryDoctor {
|
|
|
26
34
|
const observedAt = this.#now();
|
|
27
35
|
const policy = inspectionPolicy(options, observedAt);
|
|
28
36
|
const limitations = baseLimitations();
|
|
29
|
-
const { refs, usage } = await this.#inventoryUsage(
|
|
37
|
+
const { refs, usage } = await this.#inventoryUsage(
|
|
38
|
+
policy.maxCollectionsPerKind,
|
|
39
|
+
limitations,
|
|
40
|
+
observedAt,
|
|
41
|
+
);
|
|
30
42
|
const objects = await this.#inventoryObjects(policy.expiresBefore);
|
|
31
43
|
|
|
32
44
|
if (!objects.consistent) {
|
|
@@ -105,11 +117,13 @@ export default class RepositoryDoctor {
|
|
|
105
117
|
};
|
|
106
118
|
}
|
|
107
119
|
|
|
108
|
-
async #inventoryUsage(limit, limitations) {
|
|
120
|
+
async #inventoryUsage(limit, limitations, observedAt) {
|
|
109
121
|
const result = usageInventory(limit);
|
|
110
122
|
for await (const record of this.repository.iterateRefs()) {
|
|
111
123
|
result.refCount += 1;
|
|
112
|
-
if (record.ref.startsWith(
|
|
124
|
+
if (record.ref.startsWith(CACHE_ACQUISITION_REF_PREFIX)) {
|
|
125
|
+
recordCacheAcquisition(result.acquisitions, record, observedAt);
|
|
126
|
+
} else if (record.ref.startsWith(CACHE_SET_REF_PREFIX)) {
|
|
113
127
|
result.caches.observed += 1;
|
|
114
128
|
recordCache(result.caches, await this.#inspectCache(record));
|
|
115
129
|
} else if (record.ref.startsWith(ROOT_SET_REF_PREFIX)) {
|
|
@@ -118,6 +132,9 @@ export default class RepositoryDoctor {
|
|
|
118
132
|
} else if (record.ref.startsWith(EXPIRING_SET_REF_PREFIX)) {
|
|
119
133
|
result.expiringSets.observed += 1;
|
|
120
134
|
recordExpiringSet(result.expiringSets, await this.#inspectExpiringSet(record));
|
|
135
|
+
} else if (record.ref.startsWith(WORKSPACE_REF_PREFIX)) {
|
|
136
|
+
result.workspaces.observed += 1;
|
|
137
|
+
recordWorkspace(result.workspaces, await this.#inspectWorkspace(record));
|
|
121
138
|
} else if (record.ref === VAULT_REF) {
|
|
122
139
|
result.vault = record;
|
|
123
140
|
}
|
|
@@ -125,9 +142,11 @@ export default class RepositoryDoctor {
|
|
|
125
142
|
return {
|
|
126
143
|
refs: result,
|
|
127
144
|
usage: {
|
|
145
|
+
acquisitions: cacheAcquisitionGroup(result.acquisitions),
|
|
128
146
|
caches: collectionGroup(result.caches),
|
|
129
147
|
rootSets: collectionGroup(result.rootSets),
|
|
130
148
|
expiringSets: collectionGroup(result.expiringSets),
|
|
149
|
+
workspaces: collectionGroup(result.workspaces),
|
|
131
150
|
vault: await this.#inspectVault(result.vault, limitations),
|
|
132
151
|
},
|
|
133
152
|
};
|
|
@@ -162,6 +181,23 @@ export default class RepositoryDoctor {
|
|
|
162
181
|
}
|
|
163
182
|
}
|
|
164
183
|
|
|
184
|
+
async #inspectWorkspace(record) {
|
|
185
|
+
if (!this.workspaces) {
|
|
186
|
+
return unhealthyWorkspaceUsage({
|
|
187
|
+
record,
|
|
188
|
+
error: createCasError(
|
|
189
|
+
'Workspace diagnostics are unavailable for this direct RepositoryDoctor construction',
|
|
190
|
+
ErrorCodes.REPOSITORY_INSPECTION_INVALID,
|
|
191
|
+
),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
return workspaceUsage(await this.workspaces.inspectRecord(record));
|
|
196
|
+
} catch (error) {
|
|
197
|
+
return unhealthyWorkspaceUsage({ record, error });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
165
201
|
async #inspectVault(record, limitations) {
|
|
166
202
|
if (record === null) {
|
|
167
203
|
return {
|
|
@@ -379,6 +415,33 @@ function expiringSetUsageWithoutState(record, namespace, report) {
|
|
|
379
415
|
};
|
|
380
416
|
}
|
|
381
417
|
|
|
418
|
+
function workspaceUsage(report) {
|
|
419
|
+
const healthy = report.posture !== 'invalid' && report.issue === null;
|
|
420
|
+
return {
|
|
421
|
+
namespace: report.namespace,
|
|
422
|
+
ref: report.ref,
|
|
423
|
+
generation: report.generation,
|
|
424
|
+
healthy,
|
|
425
|
+
entryCount: report.rootCount,
|
|
426
|
+
logicalBytes: report.logicalBytes,
|
|
427
|
+
rootObjectBytes: report.rootObjectBytes,
|
|
428
|
+
physicalBytes: null,
|
|
429
|
+
retention: report.rootCount === null
|
|
430
|
+
? null
|
|
431
|
+
: { pinnedEntries: 0, evictableEntries: report.rootCount },
|
|
432
|
+
reachability: 'anchored',
|
|
433
|
+
age: {
|
|
434
|
+
createdAt: report.createdAt,
|
|
435
|
+
ageMs: report.ageMs,
|
|
436
|
+
},
|
|
437
|
+
expiry: {
|
|
438
|
+
expiresAt: report.expiresAt,
|
|
439
|
+
posture: report.posture,
|
|
440
|
+
},
|
|
441
|
+
issues: report.issue ? [report.issue] : [],
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
382
445
|
function rootGeneration(report, fallback) {
|
|
383
446
|
return report.root?.headOid ?? fallback;
|
|
384
447
|
}
|
|
@@ -403,6 +466,7 @@ function collectionInventory(totals, detailLimit) {
|
|
|
403
466
|
function usageInventory(detailLimit) {
|
|
404
467
|
return {
|
|
405
468
|
refCount: 0,
|
|
469
|
+
acquisitions: createCacheAcquisitionInventory(detailLimit),
|
|
406
470
|
caches: collectionInventory(
|
|
407
471
|
{
|
|
408
472
|
entryCount: 0,
|
|
@@ -421,6 +485,16 @@ function usageInventory(detailLimit) {
|
|
|
421
485
|
{ entryCount: 0, liveEntries: 0, expiredEntries: 0 },
|
|
422
486
|
detailLimit
|
|
423
487
|
),
|
|
488
|
+
workspaces: collectionInventory(
|
|
489
|
+
{
|
|
490
|
+
entryCount: 0,
|
|
491
|
+
logicalBytes: 0,
|
|
492
|
+
rootObjectBytes: 0,
|
|
493
|
+
activeWorkspaces: 0,
|
|
494
|
+
expiredWorkspaces: 0,
|
|
495
|
+
},
|
|
496
|
+
detailLimit
|
|
497
|
+
),
|
|
424
498
|
vault: null,
|
|
425
499
|
};
|
|
426
500
|
}
|
|
@@ -460,6 +534,16 @@ function recordExpiringSet(inventory, entry) {
|
|
|
460
534
|
});
|
|
461
535
|
}
|
|
462
536
|
|
|
537
|
+
function recordWorkspace(inventory, entry) {
|
|
538
|
+
recordCollection(inventory, entry, {
|
|
539
|
+
entryCount: entry.entryCount,
|
|
540
|
+
logicalBytes: entry.logicalBytes,
|
|
541
|
+
rootObjectBytes: entry.rootObjectBytes,
|
|
542
|
+
activeWorkspaces: entry.expiry?.posture === 'active' ? 1 : 0,
|
|
543
|
+
expiredWorkspaces: entry.expiry?.posture === 'expired' ? 1 : 0,
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
|
|
463
547
|
function recordCollection(inventory, entry, values) {
|
|
464
548
|
inventory.inspected += 1;
|
|
465
549
|
inventory.healthy &&= entry.healthy;
|
|
@@ -505,8 +589,10 @@ function healthyVault(record, { entryCount, privacy }) {
|
|
|
505
589
|
function usageHealthy(usage) {
|
|
506
590
|
return (
|
|
507
591
|
usage.caches.healthy &&
|
|
592
|
+
usage.acquisitions.healthy &&
|
|
508
593
|
usage.rootSets.healthy &&
|
|
509
594
|
usage.expiringSets.healthy &&
|
|
595
|
+
usage.workspaces.healthy &&
|
|
510
596
|
usage.vault.healthy
|
|
511
597
|
);
|
|
512
598
|
}
|
|
@@ -543,6 +629,18 @@ function unhealthyExpiringSetUsage(options) {
|
|
|
543
629
|
return { ...unhealthyBase(options), age: null, expiry: null };
|
|
544
630
|
}
|
|
545
631
|
|
|
632
|
+
function unhealthyWorkspaceUsage(options) {
|
|
633
|
+
return {
|
|
634
|
+
...unhealthyBase(options),
|
|
635
|
+
namespace: options.namespace ?? null,
|
|
636
|
+
logicalBytes: null,
|
|
637
|
+
rootObjectBytes: null,
|
|
638
|
+
retention: null,
|
|
639
|
+
age: null,
|
|
640
|
+
expiry: null,
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
|
|
546
644
|
function publicError(error) {
|
|
547
645
|
return {
|
|
548
646
|
code: error?.code ?? ErrorCodes.REPOSITORY_INSPECTION_INVALID,
|
|
@@ -576,6 +674,18 @@ function baseLimitations() {
|
|
|
576
674
|
}
|
|
577
675
|
|
|
578
676
|
function addTruncationLimitations(refs, limitations) {
|
|
677
|
+
const acquisitions = refs.acquisitions;
|
|
678
|
+
if (acquisitions.observed > acquisitions.entries.length) {
|
|
679
|
+
limitations.push({
|
|
680
|
+
...limitation(
|
|
681
|
+
'CACHE_ACQUISITION_DETAILS_TRUNCATED',
|
|
682
|
+
'Cache acquisition detail exceeded maxCollectionsPerKind.'
|
|
683
|
+
),
|
|
684
|
+
observed: acquisitions.observed,
|
|
685
|
+
inspected: acquisitions.inspected,
|
|
686
|
+
detailed: acquisitions.entries.length,
|
|
687
|
+
});
|
|
688
|
+
}
|
|
579
689
|
for (const [kind, inventory] of [
|
|
580
690
|
['caches', refs.caches],
|
|
581
691
|
['rootSets', refs.rootSets],
|
|
@@ -594,6 +704,18 @@ function addTruncationLimitations(refs, limitations) {
|
|
|
594
704
|
});
|
|
595
705
|
}
|
|
596
706
|
}
|
|
707
|
+
const workspaces = refs.workspaces;
|
|
708
|
+
if (workspaces.observed > workspaces.entries.length) {
|
|
709
|
+
limitations.push({
|
|
710
|
+
...limitation(
|
|
711
|
+
'WORKSPACE_DETAILS_TRUNCATED',
|
|
712
|
+
'Workspace detail exceeded maxCollectionsPerKind.'
|
|
713
|
+
),
|
|
714
|
+
observed: workspaces.observed,
|
|
715
|
+
inspected: workspaces.inspected,
|
|
716
|
+
detailed: workspaces.entries.length,
|
|
717
|
+
});
|
|
718
|
+
}
|
|
597
719
|
}
|
|
598
720
|
|
|
599
721
|
function limitation(code, message) {
|
|
@@ -10,6 +10,30 @@ const UPDATE_REF_CONFLICT_MARKERS = Object.freeze({
|
|
|
10
10
|
cannotLockRef: 'cannot lock ref',
|
|
11
11
|
referenceAlreadyExists: 'reference already exists',
|
|
12
12
|
});
|
|
13
|
+
const GIT_REPOSITORY_LOCKED = 'GIT_REPOSITORY_LOCKED';
|
|
14
|
+
|
|
15
|
+
function classifyStructuredUpdateRefConflict(err, {
|
|
16
|
+
rootSetRef,
|
|
17
|
+
newCommit,
|
|
18
|
+
expectedHeadOid,
|
|
19
|
+
}) {
|
|
20
|
+
const details = err?.details && typeof err.details === 'object' ? err.details : {};
|
|
21
|
+
if (details.code !== GIT_REPOSITORY_LOCKED) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
if (!Array.isArray(details.args)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const expectedArgs = [
|
|
28
|
+
'update-ref',
|
|
29
|
+
'--no-deref',
|
|
30
|
+
rootSetRef,
|
|
31
|
+
newCommit,
|
|
32
|
+
expectedHeadOid ?? '0'.repeat(newCommit.length),
|
|
33
|
+
];
|
|
34
|
+
return details.args.length === expectedArgs.length &&
|
|
35
|
+
expectedArgs.every((arg, index) => details.args[index] === arg);
|
|
36
|
+
}
|
|
13
37
|
|
|
14
38
|
/**
|
|
15
39
|
* Stateless persistence boundary for one root-set ref and snapshot format.
|
|
@@ -214,7 +238,7 @@ export default class RootSetPersistence {
|
|
|
214
238
|
});
|
|
215
239
|
} catch (err) {
|
|
216
240
|
const meta = await this.#updateFailureMeta(err, commitOid, expectedHeadOid);
|
|
217
|
-
if (this.#isConflict(err)) {
|
|
241
|
+
if (this.#isConflict(err, commitOid, expectedHeadOid)) {
|
|
218
242
|
throw new CasError(
|
|
219
243
|
'Concurrent root-set update detected',
|
|
220
244
|
ErrorCodes.ROOT_SET_CONFLICT,
|
|
@@ -248,11 +272,19 @@ export default class RootSetPersistence {
|
|
|
248
272
|
};
|
|
249
273
|
}
|
|
250
274
|
|
|
251
|
-
#isConflict(err) {
|
|
275
|
+
#isConflict(err, newCommit, expectedHeadOid) {
|
|
252
276
|
const meta = err?.meta && typeof err.meta === 'object' ? err.meta : {};
|
|
253
277
|
if (Object.hasOwn(meta, 'expectedOldOid') && Object.hasOwn(meta, 'actualOldOid')) {
|
|
254
278
|
return true;
|
|
255
279
|
}
|
|
280
|
+
const structuredConflict = classifyStructuredUpdateRefConflict(err, {
|
|
281
|
+
rootSetRef: this.rootSetRef,
|
|
282
|
+
newCommit,
|
|
283
|
+
expectedHeadOid,
|
|
284
|
+
});
|
|
285
|
+
if (structuredConflict !== null) {
|
|
286
|
+
return structuredConflict;
|
|
287
|
+
}
|
|
256
288
|
const normalized = errorDetailsText(err).toLowerCase();
|
|
257
289
|
if (!normalized.includes(this.rootSetRef.toLowerCase())) {
|
|
258
290
|
return false;
|