/** * @module cosmology/web-cosmology-workspace-service.respec * * Respec suite for WebCosmologyWorkspaceService in @ibgib/web-gib. * Tests fail-fast contracts, in-memory ContextModeService binding, * and direct programmatic commitItems mutations in browser contexts. */ import { respecfully, ifWe, ifWeMight, iReckon, // keep both ifWe and ifWeMight per RESPEC_GIB_GUIDANCE.md } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs'; import { createInMemoryTempMetaspaceAndSpace } from '@ibgib/core-gib/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs'; import { GalaxyPresetType } from '@ibgib/core-gib/dist/cosmology/galaxy/galaxy-configs.mjs'; import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs'; import { WebCosmologyWorkspaceService } from './web-cosmology-workspace-service.mjs'; import { WebContextModeService } from '../context/context-mode-service.mjs'; import { CONTEXT_MODE_PLAYGROUND } from '@ibgib/core-gib/dist/context/context-mode-types.mjs'; const lc = `[web-cosmology-workspace-service.respec.mts]`; process.env.KEYSTONE_PROFILE_SOVEREIGN_AUTHOR ??= 'author-profile.dev'; await respecfully(lc, `WebCosmologyWorkspaceService Core Specs`, async () => { await respecfully(lc, `Explicit Spaces Fail-Fast Lifecycle`, async () => { const { metaspace, space: localSpace } = await createInMemoryTempMetaspaceAndSpace(); const webWorkspace = new WebCosmologyWorkspaceService({ metaspace, localSpace, cosmosName: 'web-cosmos-1', galaxyName: 'notes-1', branchName: 'main', }); await ifWe(lc, `initializes a Cosmos and a member Galaxy in browser environment`, async () => { const cosmos = await webWorkspace.initCosmos({ cosmosName: 'web-cosmos-1', description: 'Client-side Web Cosmos', }); iReckon(lc, cosmos).isGonnaBeTruthy(); iReckon(lc, cosmos.data.cosmosName).willEqual('web-cosmos-1'); const galaxyRes = await webWorkspace.initGalaxy({ cosmosName: 'web-cosmos-1', galaxyName: 'notes-1', discriminator: GalaxyPresetType.notes, }); iReckon(lc, galaxyRes.galaxyIbGib.data.galaxyName).willEqual('notes-1'); iReckon(lc, galaxyRes.branchSpace).isGonnaBeTruthy(); }); await ifWe(lc, `ensureGalaxy and ensureBranch resolve existing resources`, async () => { const galaxyRes = await webWorkspace.ensureGalaxy({ cosmosName: 'web-cosmos-1', galaxyName: 'notes-1', }); iReckon(lc, galaxyRes.galaxyIbGib.data.galaxyName).willEqual('notes-1'); const branchRes = await webWorkspace.ensureBranch({ cosmosName: 'web-cosmos-1', galaxyName: 'notes-1', branchName: 'main', }); iReckon(lc, branchRes.branchInfo.branchName).willEqual('main'); iReckon(lc, branchRes.branchSpace).isGonnaBeTruthy(); }); await ifWe(lc, `programmatically commits items in browser without filesystem worktree`, async () => { const commitRes = await webWorkspace.commitItems({ cosmosName: 'web-cosmos-1', galaxyName: 'notes-1', branchName: 'main', items: [ { path: 'quicknote.txt', content: 'Remember the cosmology!' }, ], message: 'First web programmatic commit', author: 'web-user', }); iReckon(lc, commitRes.commitAddr).isGonnaBeTruthy(); iReckon(lc, commitRes.committedPaths).includes('quicknote.txt'); // Verify branch timeline advanced const { branchIbGib } = await webWorkspace.ensureBranch({ cosmosName: 'web-cosmos-1', galaxyName: 'notes-1', branchName: 'main', }); iReckon(lc, getIbGibAddr({ ibGib: branchIbGib })).willEqual(commitRes.commitAddr); }); }); await respecfully(lc, `ContextModeService Integration`, async () => { const contextModeSvc = new WebContextModeService(); await contextModeSvc.activateMode(CONTEXT_MODE_PLAYGROUND); const webWorkspace = new WebCosmologyWorkspaceService({ contextModeSvc, cosmosName: 'playground-cosmos', galaxyName: 'code-1', branchName: 'main', }); await ifWe(lc, `automatically resolves metaspace and rootSpace from active context mode`, async () => { const cosmos = await webWorkspace.initCosmos({ cosmosName: 'playground-cosmos', }); iReckon(lc, cosmos.data.cosmosName).willEqual('playground-cosmos'); const galaxyRes = await webWorkspace.initGalaxy({ cosmosName: 'playground-cosmos', galaxyName: 'code-1', }); iReckon(lc, galaxyRes.galaxyIbGib.data.galaxyName).willEqual('code-1'); const commitRes = await webWorkspace.commitItems({ cosmosName: 'playground-cosmos', galaxyName: 'code-1', branchName: 'main', items: [ { path: 'index.html', content: '

Hello Playground

' }, ], message: 'Playground commit', author: 'playground-agent', }); iReckon(lc, commitRes.committedPaths).includes('index.html'); }); }); });