skillhub/cli/test/fixtures/toggle-crash-child.ts
XiaoSeS 2e82e8ab16 feat(dsh): manage skill activation and simplify installation flows
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-10-28 13:59:58 +08:00

21 lines
1.4 KiB
TypeScript

import { join } from 'node:path'
import { InventoryStore } from '../../src/stores/inventory-store'
import { OperationStore } from '../../src/integrations/operation-store'
import { inspectToggle, executeNativeToggle } from '../../src/integrations/native-toggle'
const [home, operationId, boundary] = process.argv.slice(2)
if (!home || !operationId || !['intent', 'linked', 'moved', 'restore-linked', 'committed'].includes(boundary!)) throw new Error('Invalid fixture arguments')
const inventory = new InventoryStore(home)
const operations = await OperationStore.open(join(home, 'operations'))
const baseline = await inspectToggle(inventory, { registry: 'https://registry.example', namespace: 'demo', slug: 'writer', version: '1.0.0' },
{ root: join(home, 'skills'), scope: 'user' }, 'disabled')
if (baseline.status !== 'ready') throw new Error('Fixture baseline unavailable')
const append = operations.recordToggle.bind(operations)
operations.recordToggle = async (...args) => {
const saved = await append(...args)
if (args[3].stage === boundary) process.kill(process.pid, 'SIGKILL')
return saved
}
if (boundary === 'restore-linked') inventory.mutateAtomic = async () => { throw new Error('Injected CAS rejection') }
await executeNativeToggle(operations, inventory, { operationId, ownerId: 'owner', baseline, authorize: async () => {} })
throw new Error('Crash boundary was not reached')