skillhub/cli/test/unit/stores/config-store.test.ts
dongmucat 05177e3085 test(cli): add P0/P1/P2 test coverage for security and error paths
Add 36 test cases covering:
- Path traversal and symlink attack prevention in archive extraction
- SkillHubClient error handling (401/403/404/network) for all endpoints
- Inventory store concurrent writes and stale lock recovery
- Config store read/write round-trip
- Platform utilities (package-manager, updater, paths)
- Output formatting (printResult, humanize)

Tests use cross-platform commands (node) instead of shell builtins
for CI compatibility across macOS/Linux/Windows.
2026-04-29 15:37:05 +08:00

45 lines
1.3 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { mkdtemp } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { ConfigStore } from '../../../src/stores/config-store'
function makeTempHome() {
return mkdtemp(join(tmpdir(), 'skillhub-store-test-'))
}
describe('ConfigStore', () => {
test('read() returns empty object when file missing', async () => {
const home = await makeTempHome()
const store = new ConfigStore(home)
const config = await store.read()
expect(config).toEqual({})
})
test('write() then read() round-trips', async () => {
const home = await makeTempHome()
const store = new ConfigStore(home)
const original = { registry: 'https://example.com', defaultAgent: 'codex' }
await store.write(original)
const config = await store.read()
expect(config).toEqual(original)
})
test('setRegistry() merges into existing config', async () => {
const home = await makeTempHome()
const store = new ConfigStore(home)
// Write initial config with defaultAgent only
await store.write({ defaultAgent: 'codex' })
// setRegistry should merge, not overwrite
await store.setRegistry('https://new.com')
const config = await store.read()
expect(config.registry).toBe('https://new.com')
expect(config.defaultAgent).toBe('codex')
})
})