skillhub/cli/test/helpers/inventory-stale-lock-worker.ts
XiaoSeS 3560679793
Some checks failed
Deploy Docs / build (push) Has been cancelled
Security / Dependency Review (push) Has been cancelled
Security / CodeQL (java-kotlin) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Deploy Docs / Deploy (push) Has been cancelled
feat(dsh): add native SkillHub plugin for DeepSeek Harness (#956)
Add the native SkillHub plugin for DeepSeek Harness with a scoped skill center, conversation search/install tools, exact-version installation and protected lifecycle management. Prepare the independently versioned 0.1.0 npm candidate with an empty default Registry and documented compatibility limits.

Keep formal specifications and executable regression tests; remove archived development screenshots and runtime reports from the final tree. Review fixes cover independent scopes, installed references, pre-staging recovery and idempotent discovery.

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-10-16 19:22:26 +08:00

41 lines
1.9 KiB
TypeScript

import { createRequire } from 'node:module'
import type { Stats } from 'node:fs'
import { access, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
import { InventoryStore } from '../../src/stores/inventory-store'
const [home, id] = process.argv.slice(2)
if (!home || !id) throw new Error('Expected isolated home and contender id')
const require = createRequire(import.meta.url)
// Delay only the stale stat callback; every filesystem operation remains real.
const fs = createRequire(require.resolve('proper-lockfile'))('graceful-fs') as {
stat(path: string, callback: (error: NodeJS.ErrnoException | null, stat: Stats) => void): void
}
const stat = fs.stat.bind(fs)
const store = new InventoryStore(home)
async function waitFor(name: string): Promise<void> {
const deadline = Date.now() + 10000
for (;;) {
try { await access(join(home!, name)); return }
catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error }
if (Date.now() >= deadline) throw new Error(`Timed out waiting for ${name}`)
await Bun.sleep(5)
}
}
let paused = false
fs.stat = (path, callback) => stat(path, (error, info) => {
if (path !== `${store.path}.lock` || error) { callback(error, info); return }
if (!paused && info.mtimeMs < Date.now() - 30000) {
paused = true
void writeFile(join(home, `${id}-stale`), '').then(() => waitFor(`${id}-resume`)).then(
() => callback(null, info), failure => callback(failure, info))
} else if (!paused) {
void writeFile(join(home, `${id}-fresh`), '').then(() => callback(null, info), failure => callback(failure, info))
} else callback(null, info)
})
await store.mutateAtomic(inventory => {
inventory.items.push({ registry: 'https://registry.example', namespace: 'global', slug: id, version: '1.0.0', targets: [] })
}, async () => {
await writeFile(join(home, `${id}-entered`), '')
await waitFor(`${id}-commit`)
})