/** * @module core-commit-cmd.respec * * Respec test suite for executeVcsCommit, executeVcsInit, and executeVcsBranch * snapshot manifest stone generation, provenance tracking, and linear history. */ import { respecfully, ifWe, iReckon, } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs'; import { getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs'; import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs'; import { createInMemoryTempMetaspaceAndSpace } from '../../../witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs'; import { persistTransformResult } from '../../../witness/space/space-helper.mjs'; import { getTjpAddr } from '../../../common/other/ibgib-helper.mjs'; import { KeystoneService_V1 } from '../../../keystone/keystone-service-v1.mjs'; import { createStandardPoolConfig } from '../../../keystone/keystone-config-builder.mjs'; import { KEYSTONE_VERB_AUTHOR, POOL_ID_DEFAULT, POOL_ID_MANAGE, } from '../../../keystone/keystone-constants.mjs'; import { createBinIbGib } from '../../../common/bin/bin-helpers.mjs'; import { createB2tFSItemIbGib } from '../item/item-helpers.mjs'; import { B2tFSItemIbGib_V1, BINARY_REL8N_NAME } from '../item/item-types.mjs'; import { executeVcsInit } from './core-init-cmd.mjs'; import { executeVcsCommit } from './core-commit-cmd.mjs'; import { executeVcsBranch } from './core-branch-cmd.mjs'; const lc = `[core-commit-cmd.respec.mts]`; await respecfully(lc, `VCS Command Snapshot Manifest Integration`, async () => { const { metaspace, space } = await createInMemoryTempMetaspaceAndSpace(); const keystoneService = new KeystoneService_V1(); const parentSecret = "ParentSecret_Alice_VcsCommitTest_12345"; const salt = (await getUUID()).substring(0, 16); const parentDefaultConfig = createStandardPoolConfig({ id: POOL_ID_DEFAULT, salt }); const parentManageConfig = createStandardPoolConfig({ id: POOL_ID_MANAGE, salt: salt + "_manage" }); // 1. Create Parent Identity (Alice) const parentKeystone = await keystoneService.genesis({ masterSecret: parentSecret, configs: [parentDefaultConfig, parentManageConfig], metaspace, space, }); const parentTjp = getTjpAddr({ ibGib: parentKeystone })!; // 2. Create Author Delegate Keystone (Device) const delegateSecret = "DelegateSecret_Device_Author_VcsTest_67890"; const delegateConfig = createStandardPoolConfig({ id: POOL_ID_DEFAULT, salt: salt + "_delegate" }); const delegateKeystone = await keystoneService.genesis({ masterSecret: delegateSecret, configs: [delegateConfig], metaspace, space, }); // 3. Register Delegate under Parent with KEYSTONE_VERB_AUTHOR await keystoneService.registerDelegate({ parentKeystone, delegateKeystone, masterSecret: parentSecret, signingPoolId: POOL_ID_MANAGE, metaspace, space, allowedVerbs: [KEYSTONE_VERB_AUTHOR], }); let currentDelegateKeystone = delegateKeystone; const getDeviceDelegate = () => ({ delegateKeystone: currentDelegateKeystone, delegateSecret, }); await ifWe(lc, `generates genesis snapshot on executeVcsInit and appends commit snapshot on executeVcsCommit`, async () => { // 1. Initialize repository with author identity and delegate const initRes = await executeVcsInit({ metaspace, localSpace: space, cosmosName: 'cosmos-test', galaxyName: 'code-1', branchName: 'main', primaryIdentityTjpAddr: parentTjp, deviceDelegate: getDeviceDelegate(), }); iReckon(lc, initRes.snapshotIbGib).asTo('genesis snapshot defined').isGonnaBeTruthy(); iReckon(lc, initRes.snapshotAddr).asTo('genesis snapshot addr defined').isGonnaBeTruthy(); iReckon(lc, initRes.branchIbGib.data['@snapshot']).asTo('branch has snapshot log').isGonnaBeTruthy(); iReckon(lc, initRes.branchIbGib.data['@snapshot']!.length).asTo('snapshot log count').willEqual(1); iReckon(lc, initRes.branchIbGib.data['@snapshot']![0]).asTo('genesis snapshot recorded').willEqual(initRes.snapshotAddr!); // Advance delegate tip after genesis signing currentDelegateKeystone = initRes.evolvedAuthorDelegateKeystone; // 2. Stage a file in galaxy const bin = await createBinIbGib({ data: 'console.log("hello space-gib!");', space: initRes.branchSpace, metaspace, }); const fileRes = await createB2tFSItemIbGib({ fsType: 'file', name: 'hello.ts', data: { fileHash: bin.binHash }, rel8ns: { [BINARY_REL8N_NAME]: [bin.binAddr] }, }); const fileItem = fileRes.newIbGib as B2tFSItemIbGib_V1; await persistTransformResult({ resTransform: fileRes, space: initRes.branchSpace }); await metaspace.registerNewIbGib({ ibGib: fileItem, space: initRes.branchSpace }); const fileAddr = getIbGibAddr({ ibGib: fileItem }); let galaxyIbGib = initRes.galaxyIbGib; galaxyIbGib.data.stagedPaths = { 'hello.ts': { itemAddr: fileAddr, fsType: 'file', stagedAt: new Date().toISOString(), }, }; // 3. Commit staged changes const commitRes = await executeVcsCommit({ metaspace, localSpace: space, branchName: 'main', activeBranchSpace: initRes.branchSpace, galaxyIbGib, message: 'feat: add hello.ts', b2tfsGalaxyRoot: '/mock/b2tfs-galaxy', primaryIdentityTjpAddr: parentTjp, deviceDelegate: getDeviceDelegate(), }); iReckon(lc, commitRes.snapshotIbGib).asTo('commit snapshot defined').isGonnaBeTruthy(); iReckon(lc, commitRes.snapshotAddr).asTo('commit snapshot addr defined').isGonnaBeTruthy(); // Check snapshot contents const snapshot = commitRes.snapshotIbGib; iReckon(lc, snapshot.data.fileCount).asTo('fileCount').willEqual(1); iReckon(lc, snapshot.data.items['hello.ts']).asTo('hello.ts mapped in items').isGonnaBeTruthy(); iReckon(lc, snapshot.data.items['hello.ts'][0]).asTo('hello.ts addr').willEqual(fileAddr); iReckon(lc, snapshot.data.primaryIdentityTjpAddr).asTo('primaryIdentityTjpAddr').willEqual(parentTjp); iReckon(lc, snapshot.data.commitMessageAddr).asTo('commitMessageAddr defined').isGonnaBeTruthy(); // Check linear branch snapshot sequence const branchSnapshots = commitRes.branchIbGib.data['@snapshot'] || []; iReckon(lc, branchSnapshots.length).asTo('branch has 2 snapshots').willEqual(2); iReckon(lc, branchSnapshots[0]).asTo('first snapshot is genesis').willEqual(initRes.snapshotAddr!); iReckon(lc, branchSnapshots[1]).asTo('second snapshot is commit').willEqual(commitRes.snapshotAddr!); // Advance delegate tip after commit signing currentDelegateKeystone = commitRes.evolvedAuthorDelegateKeystone; // 4. Create a new branch off main and verify provenance in originSnapshotInfos const branchRes = await executeVcsBranch({ metaspace, localSpace: space, galaxyIbGib: commitRes.updatedGalaxy, branchName: 'feature-greeting', sourceBranchName: 'main', primaryIdentityTjpAddr: parentTjp, deviceDelegate: getDeviceDelegate(), }); iReckon(lc, branchRes.createdBranchName).asTo('created branch name').willEqual('feature-greeting'); iReckon(lc, branchRes.snapshotIbGib).asTo('new branch snapshot defined').isGonnaBeTruthy(); const branchSnapshot = branchRes.snapshotIbGib; iReckon(lc, branchSnapshot.data.originSnapshotInfos).asTo('origin snapshot infos defined').isGonnaBeTruthy(); iReckon(lc, branchSnapshot.data.originSnapshotInfos!.length).asTo('origin snapshot info count').willEqual(1); iReckon(lc, branchSnapshot.data.originSnapshotInfos![0].snapshotAddr).asTo('provenance points to main head snapshot').willEqual(commitRes.snapshotAddr!); iReckon(lc, branchSnapshot.data.originSnapshotInfos![0].branchName).asTo('provenance branch name').willEqual('main'); }); });