@git-stunts/git-cas 6.3.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/CHANGELOG.md +26 -0
- package/README.md +11 -4
- package/UPGRADING.md +42 -0
- package/build-info.json +2 -2
- package/docs/API.md +163 -17
- package/docs/releases/v6.4.0.md +128 -0
- package/index.d.ts +191 -0
- package/index.js +28 -0
- package/package.json +2 -1
- package/src/domain/errors/Codes.js +10 -0
- package/src/domain/services/RepositoryDoctor.js +97 -2
- 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/WorkspaceRef.js +151 -0
- package/src/infrastructure/adapters/GitRefAdapter.js +56 -14
- package/src/package-version.js +1 -1
- package/src/ports/GitRefPort.js +1 -0
package/index.d.ts
CHANGED
|
@@ -556,6 +556,8 @@ export declare class GitRefPortBase {
|
|
|
556
556
|
deleteRef?(options: { ref: string; expectedOldOid: string }): Promise<boolean>;
|
|
557
557
|
iterateRefs?(options: {
|
|
558
558
|
prefix?: string;
|
|
559
|
+
/** Exclusive opaque continuation returned by a previous bounded inventory. */
|
|
560
|
+
after?: string | null;
|
|
559
561
|
limit: number;
|
|
560
562
|
}): AsyncIterable<{ ref: string; oid: string; symref: string | null }>;
|
|
561
563
|
}
|
|
@@ -577,6 +579,8 @@ export declare class GitRefAdapter extends GitRefPortBase {
|
|
|
577
579
|
deleteRef(options: { ref: string; expectedOldOid: string }): Promise<boolean>;
|
|
578
580
|
iterateRefs(options: {
|
|
579
581
|
prefix?: string;
|
|
582
|
+
/** Exclusive opaque continuation returned by a previous bounded inventory. */
|
|
583
|
+
after?: string | null;
|
|
580
584
|
limit: number;
|
|
581
585
|
}): AsyncIterable<{ ref: string; oid: string; symref: string | null }>;
|
|
582
586
|
}
|
|
@@ -1241,6 +1245,32 @@ export interface RepositoryExpiringSetUsage {
|
|
|
1241
1245
|
readonly issues: ReadonlyArray<Record<string, unknown>>;
|
|
1242
1246
|
}
|
|
1243
1247
|
|
|
1248
|
+
export interface RepositoryWorkspaceUsage {
|
|
1249
|
+
readonly namespace: string | null;
|
|
1250
|
+
readonly ref: string;
|
|
1251
|
+
readonly generation: string;
|
|
1252
|
+
readonly healthy: boolean;
|
|
1253
|
+
readonly entryCount: number | null;
|
|
1254
|
+
readonly logicalBytes: number | null;
|
|
1255
|
+
/** Sum of unique direct Git root object sizes; excludes transitive support and pack overhead. */
|
|
1256
|
+
readonly rootObjectBytes: number | null;
|
|
1257
|
+
readonly physicalBytes: null;
|
|
1258
|
+
readonly retention: {
|
|
1259
|
+
readonly pinnedEntries: 0;
|
|
1260
|
+
readonly evictableEntries: number;
|
|
1261
|
+
} | null;
|
|
1262
|
+
readonly reachability: 'anchored';
|
|
1263
|
+
readonly age: {
|
|
1264
|
+
readonly createdAt: string | null;
|
|
1265
|
+
readonly ageMs: number | null;
|
|
1266
|
+
} | null;
|
|
1267
|
+
readonly expiry: {
|
|
1268
|
+
readonly expiresAt: string | null;
|
|
1269
|
+
readonly posture: 'active' | 'expired' | 'invalid';
|
|
1270
|
+
} | null;
|
|
1271
|
+
readonly issues: ReadonlyArray<Record<string, unknown>>;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1244
1274
|
export interface RepositoryVaultUsage {
|
|
1245
1275
|
readonly ref: string;
|
|
1246
1276
|
readonly present: boolean;
|
|
@@ -1321,6 +1351,18 @@ export interface RepositoryDoctorReport {
|
|
|
1321
1351
|
};
|
|
1322
1352
|
readonly entries: ReadonlyArray<RepositoryExpiringSetUsage>;
|
|
1323
1353
|
};
|
|
1354
|
+
readonly workspaces: {
|
|
1355
|
+
readonly healthy: boolean;
|
|
1356
|
+
readonly coverage: RepositoryCollectionCoverage;
|
|
1357
|
+
readonly totals: {
|
|
1358
|
+
readonly entryCount: number | null;
|
|
1359
|
+
readonly logicalBytes: number | null;
|
|
1360
|
+
readonly rootObjectBytes: number | null;
|
|
1361
|
+
readonly activeWorkspaces: number | null;
|
|
1362
|
+
readonly expiredWorkspaces: number | null;
|
|
1363
|
+
};
|
|
1364
|
+
readonly entries: ReadonlyArray<RepositoryWorkspaceUsage>;
|
|
1365
|
+
};
|
|
1324
1366
|
readonly vault: RepositoryVaultUsage;
|
|
1325
1367
|
};
|
|
1326
1368
|
readonly limitations: ReadonlyArray<RepositoryDiagnosticLimitation>;
|
|
@@ -1335,6 +1377,14 @@ export declare class RepositoryDoctor {
|
|
|
1335
1377
|
expiringSets: {
|
|
1336
1378
|
open(options: { namespace: string }): ExpiringSet | Promise<ExpiringSet>;
|
|
1337
1379
|
};
|
|
1380
|
+
/** Optional only for backwards-compatible direct construction; workspace refs report unhealthy when absent. */
|
|
1381
|
+
workspaces?: {
|
|
1382
|
+
inspectRecord(record: {
|
|
1383
|
+
ref: string;
|
|
1384
|
+
oid: string;
|
|
1385
|
+
symref: string | null;
|
|
1386
|
+
}): Promise<WorkspaceInspectionRecord>;
|
|
1387
|
+
};
|
|
1338
1388
|
vault: Pick<VaultService, 'getVaultMetadata' | 'readState'>;
|
|
1339
1389
|
clock?: { now(): Date };
|
|
1340
1390
|
});
|
|
@@ -1452,6 +1502,146 @@ export interface ExpiringSetCapability {
|
|
|
1452
1502
|
}): Promise<ExpiringSet>;
|
|
1453
1503
|
}
|
|
1454
1504
|
|
|
1505
|
+
export interface WorkspaceRetention {
|
|
1506
|
+
readonly policy: 'evictable';
|
|
1507
|
+
readonly reachability: 'anchored';
|
|
1508
|
+
readonly protection: 'workspace';
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
export type WorkspaceRetainedData<T> = Omit<T, 'state' | 'retention'> & {
|
|
1512
|
+
state: 'retained';
|
|
1513
|
+
retention: WorkspaceRetention;
|
|
1514
|
+
witness: RetentionWitnessData;
|
|
1515
|
+
};
|
|
1516
|
+
|
|
1517
|
+
export type WorkspaceRetainedAsset = Omit<StagedAsset, 'state' | 'retention' | 'toJSON'> & {
|
|
1518
|
+
readonly state: 'retained';
|
|
1519
|
+
readonly retention: WorkspaceRetention;
|
|
1520
|
+
readonly witness: RetentionWitness;
|
|
1521
|
+
toJSON(): WorkspaceRetainedData<StagedAssetData>;
|
|
1522
|
+
};
|
|
1523
|
+
|
|
1524
|
+
export type WorkspaceRetainedPage = Omit<StagedPage, 'state' | 'retention' | 'toJSON'> & {
|
|
1525
|
+
readonly state: 'retained';
|
|
1526
|
+
readonly retention: WorkspaceRetention;
|
|
1527
|
+
readonly witness: RetentionWitness;
|
|
1528
|
+
toJSON(): WorkspaceRetainedData<StagedPageData>;
|
|
1529
|
+
};
|
|
1530
|
+
|
|
1531
|
+
export type WorkspaceRetainedBundle = Omit<StagedBundle, 'state' | 'retention' | 'toJSON'> & {
|
|
1532
|
+
readonly state: 'retained';
|
|
1533
|
+
readonly retention: WorkspaceRetention;
|
|
1534
|
+
readonly witness: RetentionWitness;
|
|
1535
|
+
toJSON(): WorkspaceRetainedData<StagedBundleData>;
|
|
1536
|
+
};
|
|
1537
|
+
|
|
1538
|
+
export interface WorkspaceCheckpointResult {
|
|
1539
|
+
readonly changed: boolean;
|
|
1540
|
+
readonly ref: string;
|
|
1541
|
+
readonly generation: string;
|
|
1542
|
+
readonly expiresAt: string;
|
|
1543
|
+
readonly handles: ReadonlyArray<ApplicationHandle>;
|
|
1544
|
+
readonly witnesses: ReadonlyArray<RetentionWitness>;
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
export interface WorkspaceReleaseResult {
|
|
1548
|
+
readonly changed: boolean;
|
|
1549
|
+
readonly ref: string;
|
|
1550
|
+
readonly generation: string | null;
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
export interface WorkspaceInspectionRecord {
|
|
1554
|
+
readonly id: string | null;
|
|
1555
|
+
readonly namespace: string | null;
|
|
1556
|
+
readonly ref: string;
|
|
1557
|
+
readonly generation: string;
|
|
1558
|
+
readonly symref: string | null;
|
|
1559
|
+
readonly rootCount: number | null;
|
|
1560
|
+
readonly logicalBytes: number | null;
|
|
1561
|
+
/** Sum of unique direct Git root object sizes; excludes transitive support and pack overhead. */
|
|
1562
|
+
readonly rootObjectBytes: number | null;
|
|
1563
|
+
readonly createdAt: string | null;
|
|
1564
|
+
readonly ageMs: number | null;
|
|
1565
|
+
readonly expiresAt: string | null;
|
|
1566
|
+
readonly posture: 'active' | 'expired' | 'invalid';
|
|
1567
|
+
readonly issue: Readonly<{ code: string; message: string }> | null;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
export interface WorkspaceInspection {
|
|
1571
|
+
readonly namespace: string;
|
|
1572
|
+
readonly returned: number;
|
|
1573
|
+
readonly truncated: boolean;
|
|
1574
|
+
/** Opaque continuation for the next bounded inspect or sweep call. */
|
|
1575
|
+
readonly nextCursor: string | null;
|
|
1576
|
+
readonly workspaces: ReadonlyArray<WorkspaceInspectionRecord>;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
export interface WorkspaceSweepResult {
|
|
1580
|
+
readonly namespace: string;
|
|
1581
|
+
readonly inspected: number;
|
|
1582
|
+
readonly changed: number;
|
|
1583
|
+
readonly conflicted: number;
|
|
1584
|
+
readonly missing: number;
|
|
1585
|
+
readonly truncated: boolean;
|
|
1586
|
+
/** Opaque continuation for the next bounded sweep call. */
|
|
1587
|
+
readonly nextCursor: string | null;
|
|
1588
|
+
readonly results: ReadonlyArray<Readonly<{
|
|
1589
|
+
id: string | null;
|
|
1590
|
+
ref: string;
|
|
1591
|
+
generation: string;
|
|
1592
|
+
changed: boolean;
|
|
1593
|
+
conflict: boolean;
|
|
1594
|
+
}>>;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
/** One renewable, RootSet-backed scope for multi-object staging. */
|
|
1598
|
+
export declare class StagingWorkspace {
|
|
1599
|
+
private constructor();
|
|
1600
|
+
readonly id: string;
|
|
1601
|
+
readonly namespace: string;
|
|
1602
|
+
readonly createdAt: string;
|
|
1603
|
+
readonly expiresAt: string | null;
|
|
1604
|
+
readonly assets: {
|
|
1605
|
+
put(options: AssetPutOptions): Promise<WorkspaceRetainedAsset>;
|
|
1606
|
+
adopt(options: { treeOid: string }): Promise<WorkspaceRetainedAsset>;
|
|
1607
|
+
};
|
|
1608
|
+
readonly pages: {
|
|
1609
|
+
put(options: { source: PageSource; maxBytes?: number }): Promise<WorkspaceRetainedPage>;
|
|
1610
|
+
};
|
|
1611
|
+
readonly bundles: {
|
|
1612
|
+
put(options: Parameters<BundleCapability['put']>[0]): Promise<WorkspaceRetainedBundle>;
|
|
1613
|
+
putOrdered(options: Parameters<BundleCapability['putOrdered']>[0]): Promise<WorkspaceRetainedBundle>;
|
|
1614
|
+
};
|
|
1615
|
+
checkpoint(options: { handles: Iterable<ApplicationHandleInput> }): Promise<WorkspaceCheckpointResult>;
|
|
1616
|
+
renew(): Promise<WorkspaceCheckpointResult>;
|
|
1617
|
+
promoteToCache(options: {
|
|
1618
|
+
cache: CacheSet;
|
|
1619
|
+
key: string;
|
|
1620
|
+
handle: ApplicationHandleInput;
|
|
1621
|
+
options?: CacheEntryOptions;
|
|
1622
|
+
}): Promise<Readonly<{ destination: CacheStoreResult; release: WorkspaceReleaseResult }>>;
|
|
1623
|
+
promoteToPublication(options: {
|
|
1624
|
+
handle: ApplicationHandleInput;
|
|
1625
|
+
commit: { message: string; parents?: string[] };
|
|
1626
|
+
ref: { name: string; expected: string | null };
|
|
1627
|
+
}): Promise<Readonly<{ destination: PublicationResult; release: WorkspaceReleaseResult }>>;
|
|
1628
|
+
release(): Promise<WorkspaceReleaseResult>;
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
export interface WorkspaceCapability {
|
|
1632
|
+
open(options: { namespace: string; ttlMs?: number }): Promise<StagingWorkspace>;
|
|
1633
|
+
inspect(options: {
|
|
1634
|
+
namespace: string;
|
|
1635
|
+
limit?: number;
|
|
1636
|
+
cursor?: string | null;
|
|
1637
|
+
}): Promise<WorkspaceInspection>;
|
|
1638
|
+
sweep(options: {
|
|
1639
|
+
namespace: string;
|
|
1640
|
+
limit?: number;
|
|
1641
|
+
cursor?: string | null;
|
|
1642
|
+
}): Promise<WorkspaceSweepResult>;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1455
1645
|
export interface DiagnosticsCapability {
|
|
1456
1646
|
doctor(options?: RepositoryDoctorOptions): Promise<RepositoryDoctorReport>;
|
|
1457
1647
|
}
|
|
@@ -1505,6 +1695,7 @@ export default class ContentAddressableStore {
|
|
|
1505
1695
|
|
|
1506
1696
|
readonly caches: CacheCapability;
|
|
1507
1697
|
readonly expiringSets: ExpiringSetCapability;
|
|
1698
|
+
readonly workspaces: WorkspaceCapability;
|
|
1508
1699
|
readonly diagnostics: DiagnosticsCapability;
|
|
1509
1700
|
|
|
1510
1701
|
readonly assets: AssetCapability;
|
package/index.js
CHANGED
|
@@ -16,6 +16,8 @@ import CacheSet from './src/domain/services/CacheSet.js';
|
|
|
16
16
|
import CacheSetRegistry from './src/domain/services/CacheSetRegistry.js';
|
|
17
17
|
import ExpiringSet from './src/domain/services/ExpiringSet.js';
|
|
18
18
|
import ExpiringSetRegistry from './src/domain/services/ExpiringSetRegistry.js';
|
|
19
|
+
import StagingWorkspace from './src/domain/services/StagingWorkspace.js';
|
|
20
|
+
import StagingWorkspaceRegistry from './src/domain/services/StagingWorkspaceRegistry.js';
|
|
19
21
|
import RepositoryDoctor from './src/domain/services/RepositoryDoctor.js';
|
|
20
22
|
import PageService from './src/domain/services/PageService.js';
|
|
21
23
|
import PublicationService from './src/domain/services/PublicationService.js';
|
|
@@ -69,6 +71,7 @@ export {
|
|
|
69
71
|
RootSetRegistry,
|
|
70
72
|
CacheSet,
|
|
71
73
|
ExpiringSet,
|
|
74
|
+
StagingWorkspace,
|
|
72
75
|
RepositoryDoctor,
|
|
73
76
|
GitPersistenceAdapter,
|
|
74
77
|
GitRefAdapter,
|
|
@@ -191,6 +194,11 @@ export default class ContentAddressableStore {
|
|
|
191
194
|
this.expiringSets = Object.freeze({
|
|
192
195
|
open: async (options) => (await this.#getExpiringSetRegistry()).open(options),
|
|
193
196
|
});
|
|
197
|
+
this.workspaces = Object.freeze({
|
|
198
|
+
open: async (options) => (await this.#getStagingWorkspaceRegistry()).open(options),
|
|
199
|
+
inspect: async (options) => (await this.#getStagingWorkspaceRegistry()).inspect(options),
|
|
200
|
+
sweep: async (options) => (await this.#getStagingWorkspaceRegistry()).sweep(options),
|
|
201
|
+
});
|
|
194
202
|
this.diagnostics = Object.freeze({
|
|
195
203
|
doctor: async (options) => (await this.#getRepositoryDoctor()).doctor(options),
|
|
196
204
|
});
|
|
@@ -239,6 +247,8 @@ export default class ContentAddressableStore {
|
|
|
239
247
|
#cacheSetRegistry = null;
|
|
240
248
|
/** @type {ExpiringSetRegistry|null} */
|
|
241
249
|
#expiringSetRegistry = null;
|
|
250
|
+
/** @type {StagingWorkspaceRegistry|null} */
|
|
251
|
+
#stagingWorkspaceRegistry = null;
|
|
242
252
|
/** @type {RepositoryDoctor|null} */
|
|
243
253
|
#repositoryDoctor = null;
|
|
244
254
|
#servicePromise = null;
|
|
@@ -313,6 +323,7 @@ export default class ContentAddressableStore {
|
|
|
313
323
|
rootSets: this.#rootSetRegistry,
|
|
314
324
|
caches: this.#cacheSetRegistry,
|
|
315
325
|
expiringSets: this.#expiringSetRegistry,
|
|
326
|
+
workspaces: this.#stagingWorkspaceRegistry,
|
|
316
327
|
vault: this.#vault,
|
|
317
328
|
clock: cfg.clock,
|
|
318
329
|
});
|
|
@@ -336,6 +347,17 @@ export default class ContentAddressableStore {
|
|
|
336
347
|
crypto,
|
|
337
348
|
clock: cfg.clock,
|
|
338
349
|
});
|
|
350
|
+
this.#stagingWorkspaceRegistry = new StagingWorkspaceRegistry({
|
|
351
|
+
persistence,
|
|
352
|
+
ref,
|
|
353
|
+
assets: this.#assetService,
|
|
354
|
+
pages: this.#pageService,
|
|
355
|
+
bundles: this.#bundleService,
|
|
356
|
+
publications: this.#publicationService,
|
|
357
|
+
resolveHandle: (handle) => this.#resolveApplicationRoot(handle),
|
|
358
|
+
crypto,
|
|
359
|
+
clock: cfg.clock,
|
|
360
|
+
});
|
|
339
361
|
}
|
|
340
362
|
|
|
341
363
|
#initApplicationServices({ ref, cfg }) {
|
|
@@ -401,6 +423,12 @@ export default class ContentAddressableStore {
|
|
|
401
423
|
return this.#expiringSetRegistry;
|
|
402
424
|
}
|
|
403
425
|
|
|
426
|
+
/** @returns {Promise<StagingWorkspaceRegistry>} */
|
|
427
|
+
async #getStagingWorkspaceRegistry() {
|
|
428
|
+
await this.#getService();
|
|
429
|
+
return this.#stagingWorkspaceRegistry;
|
|
430
|
+
}
|
|
431
|
+
|
|
404
432
|
/** @returns {Promise<RepositoryDoctor>} */
|
|
405
433
|
async #getRepositoryDoctor() {
|
|
406
434
|
await this.#getService();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@git-stunts/git-cas",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"description": "Content-addressed storage backed by Git's object database, with optional encryption and pluggable codecs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"docs/releases/v6.1.0.md",
|
|
36
36
|
"docs/releases/v6.2.0.md",
|
|
37
37
|
"docs/releases/v6.3.0.md",
|
|
38
|
+
"docs/releases/v6.4.0.md",
|
|
38
39
|
"docs/THREAT_MODEL.md",
|
|
39
40
|
"docs/VAULT_INTERNALS.md",
|
|
40
41
|
"docs/WALKTHROUGH.md",
|
|
@@ -100,6 +100,16 @@ const ErrorCodes = Object.freeze({
|
|
|
100
100
|
VAULT_REF_MISSING: 'VAULT_REF_MISSING',
|
|
101
101
|
VAULT_REF_UPDATE_FAILED: 'VAULT_REF_UPDATE_FAILED',
|
|
102
102
|
VAULT_RETRY_POLICY_INVALID: 'VAULT_RETRY_POLICY_INVALID',
|
|
103
|
+
WORKSPACE_CONFLICT: 'WORKSPACE_CONFLICT',
|
|
104
|
+
WORKSPACE_DESCRIPTOR_INVALID: 'WORKSPACE_DESCRIPTOR_INVALID',
|
|
105
|
+
WORKSPACE_HANDLE_NOT_RETAINED: 'WORKSPACE_HANDLE_NOT_RETAINED',
|
|
106
|
+
WORKSPACE_PROMOTION_CLEANUP_PENDING: 'WORKSPACE_PROMOTION_CLEANUP_PENDING',
|
|
107
|
+
WORKSPACE_PROMOTION_NOT_RETAINED: 'WORKSPACE_PROMOTION_NOT_RETAINED',
|
|
108
|
+
WORKSPACE_REF_INVALID: 'WORKSPACE_REF_INVALID',
|
|
109
|
+
WORKSPACE_RELEASED: 'WORKSPACE_RELEASED',
|
|
110
|
+
WORKSPACE_RETENTION_FAILED: 'WORKSPACE_RETENTION_FAILED',
|
|
111
|
+
WORKSPACE_STATE_INVALID: 'WORKSPACE_STATE_INVALID',
|
|
112
|
+
WORKSPACE_TTL_INVALID: 'WORKSPACE_TTL_INVALID',
|
|
103
113
|
});
|
|
104
114
|
|
|
105
115
|
export { ErrorCodes };
|
|
@@ -4,6 +4,7 @@ import { CACHE_ACQUISITION_REF_PREFIX } from '../value-objects/CacheAcquisitionR
|
|
|
4
4
|
import { CACHE_SET_REF_PREFIX } from '../value-objects/CacheSetRef.js';
|
|
5
5
|
import { EXPIRING_SET_REF_PREFIX } from '../value-objects/ExpiringSetRef.js';
|
|
6
6
|
import { ROOT_SET_REF_PREFIX } from '../value-objects/RootSetRef.js';
|
|
7
|
+
import { WORKSPACE_REF_PREFIX } from '../value-objects/WorkspaceRef.js';
|
|
7
8
|
import { VAULT_REF } from './VaultPersistence.js';
|
|
8
9
|
import {
|
|
9
10
|
cacheAcquisitionGroup,
|
|
@@ -17,12 +18,13 @@ const MAX_COLLECTIONS_PER_KIND = 1_000;
|
|
|
17
18
|
|
|
18
19
|
/** Composes bounded, non-mutating repository and managed-collection evidence. */
|
|
19
20
|
export default class RepositoryDoctor {
|
|
20
|
-
constructor({ repository, rootSets, caches, expiringSets, vault, clock }) {
|
|
21
|
-
assertDependencies({ repository, rootSets, caches, expiringSets, vault });
|
|
21
|
+
constructor({ repository, rootSets, caches, expiringSets, workspaces, vault, clock }) {
|
|
22
|
+
assertDependencies({ repository, rootSets, caches, expiringSets, workspaces, vault });
|
|
22
23
|
this.repository = repository;
|
|
23
24
|
this.rootSets = rootSets;
|
|
24
25
|
this.caches = caches;
|
|
25
26
|
this.expiringSets = expiringSets;
|
|
27
|
+
this.workspaces = workspaces;
|
|
26
28
|
this.vault = vault;
|
|
27
29
|
this.clock = clock ?? { now: () => new Date() };
|
|
28
30
|
Object.freeze(this);
|
|
@@ -130,6 +132,9 @@ export default class RepositoryDoctor {
|
|
|
130
132
|
} else if (record.ref.startsWith(EXPIRING_SET_REF_PREFIX)) {
|
|
131
133
|
result.expiringSets.observed += 1;
|
|
132
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));
|
|
133
138
|
} else if (record.ref === VAULT_REF) {
|
|
134
139
|
result.vault = record;
|
|
135
140
|
}
|
|
@@ -141,6 +146,7 @@ export default class RepositoryDoctor {
|
|
|
141
146
|
caches: collectionGroup(result.caches),
|
|
142
147
|
rootSets: collectionGroup(result.rootSets),
|
|
143
148
|
expiringSets: collectionGroup(result.expiringSets),
|
|
149
|
+
workspaces: collectionGroup(result.workspaces),
|
|
144
150
|
vault: await this.#inspectVault(result.vault, limitations),
|
|
145
151
|
},
|
|
146
152
|
};
|
|
@@ -175,6 +181,23 @@ export default class RepositoryDoctor {
|
|
|
175
181
|
}
|
|
176
182
|
}
|
|
177
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
|
+
|
|
178
201
|
async #inspectVault(record, limitations) {
|
|
179
202
|
if (record === null) {
|
|
180
203
|
return {
|
|
@@ -392,6 +415,33 @@ function expiringSetUsageWithoutState(record, namespace, report) {
|
|
|
392
415
|
};
|
|
393
416
|
}
|
|
394
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
|
+
|
|
395
445
|
function rootGeneration(report, fallback) {
|
|
396
446
|
return report.root?.headOid ?? fallback;
|
|
397
447
|
}
|
|
@@ -435,6 +485,16 @@ function usageInventory(detailLimit) {
|
|
|
435
485
|
{ entryCount: 0, liveEntries: 0, expiredEntries: 0 },
|
|
436
486
|
detailLimit
|
|
437
487
|
),
|
|
488
|
+
workspaces: collectionInventory(
|
|
489
|
+
{
|
|
490
|
+
entryCount: 0,
|
|
491
|
+
logicalBytes: 0,
|
|
492
|
+
rootObjectBytes: 0,
|
|
493
|
+
activeWorkspaces: 0,
|
|
494
|
+
expiredWorkspaces: 0,
|
|
495
|
+
},
|
|
496
|
+
detailLimit
|
|
497
|
+
),
|
|
438
498
|
vault: null,
|
|
439
499
|
};
|
|
440
500
|
}
|
|
@@ -474,6 +534,16 @@ function recordExpiringSet(inventory, entry) {
|
|
|
474
534
|
});
|
|
475
535
|
}
|
|
476
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
|
+
|
|
477
547
|
function recordCollection(inventory, entry, values) {
|
|
478
548
|
inventory.inspected += 1;
|
|
479
549
|
inventory.healthy &&= entry.healthy;
|
|
@@ -522,6 +592,7 @@ function usageHealthy(usage) {
|
|
|
522
592
|
usage.acquisitions.healthy &&
|
|
523
593
|
usage.rootSets.healthy &&
|
|
524
594
|
usage.expiringSets.healthy &&
|
|
595
|
+
usage.workspaces.healthy &&
|
|
525
596
|
usage.vault.healthy
|
|
526
597
|
);
|
|
527
598
|
}
|
|
@@ -558,6 +629,18 @@ function unhealthyExpiringSetUsage(options) {
|
|
|
558
629
|
return { ...unhealthyBase(options), age: null, expiry: null };
|
|
559
630
|
}
|
|
560
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
|
+
|
|
561
644
|
function publicError(error) {
|
|
562
645
|
return {
|
|
563
646
|
code: error?.code ?? ErrorCodes.REPOSITORY_INSPECTION_INVALID,
|
|
@@ -621,6 +704,18 @@ function addTruncationLimitations(refs, limitations) {
|
|
|
621
704
|
});
|
|
622
705
|
}
|
|
623
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
|
+
}
|
|
624
719
|
}
|
|
625
720
|
|
|
626
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;
|