mirror of
https://github.com/iflytek/skillhub.git
synced 2026-12-02 00:37:22 +00:00
`skillhub login` resolved the saved credential for the registry and validated it with `whoami` before any browser flow. When that credential was revoked or its account disabled, whoami failed with 401 and login exited with "authentication failed / Next: run `skillhub login`", which repeats the same failing command. The only recovery was to run `skillhub logout` first, which the CLI never mentioned. Track where the resolved token came from. A rejected saved credential now reports the rejection and continues with Device Flow, storing the new token only after whoami succeeds; the old entry stays on disk until then, so an aborted sign-in keeps the previous state. Tokens supplied by `--token` or `SKILLHUB_TOKEN` still never fall back: the CLI names the rejected input and the command to retry without it, which preserves non-interactive behavior. Update the CLI README and the bilingual guides and operations reference that documented the old one-way token resolution. Signed-off-by: PerryLink <novelnexusai@outlook.com>
47 lines
2.4 KiB
TypeScript
47 lines
2.4 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import { resolveRegistry, resolveToken, resolveTokenWithSource } from '../../../src/services/registry-service'
|
|
|
|
describe('registry-service', () => {
|
|
test('resolves registry by cli arg, env, config, default order', () => {
|
|
expect(resolveRegistry({ registry: 'https://arg.example.com' }, {}, { registry: 'https://config.example.com' }))
|
|
.toBe('https://arg.example.com')
|
|
expect(resolveRegistry({}, { SKILLHUB_REGISTRY: 'https://env.example.com' }, { registry: 'https://config.example.com' }))
|
|
.toBe('https://env.example.com')
|
|
expect(resolveRegistry({}, {}, { registry: 'https://config.example.com' })).toBe('https://config.example.com')
|
|
expect(resolveRegistry({}, {}, {})).toBe('https://skill.xfyun.cn')
|
|
})
|
|
|
|
test('resolves token by cli arg, env, credentials order', () => {
|
|
expect(resolveToken({ token: 'arg' }, {}, 'stored')).toBe('arg')
|
|
expect(resolveToken({}, { SKILLHUB_TOKEN: 'env' }, 'stored')).toBe('env')
|
|
expect(resolveToken({}, {}, 'stored')).toBe('stored')
|
|
})
|
|
|
|
test('resolves the token source by cli arg, env, credentials order', () => {
|
|
expect(resolveTokenWithSource({ token: 'arg' }, { SKILLHUB_TOKEN: 'env' }, 'stored'))
|
|
.toEqual({ token: 'arg', source: 'argument' })
|
|
expect(resolveTokenWithSource({}, { SKILLHUB_TOKEN: 'env' }, 'stored'))
|
|
.toEqual({ token: 'env', source: 'environment' })
|
|
expect(resolveTokenWithSource({}, {}, 'stored')).toEqual({ token: 'stored', source: 'stored' })
|
|
expect(resolveTokenWithSource({}, {}, undefined)).toBeUndefined()
|
|
})
|
|
|
|
test('treats an empty token argument as absent, as resolveToken does', () => {
|
|
expect(resolveTokenWithSource({ token: '' }, { SKILLHUB_TOKEN: 'env' }, 'stored'))
|
|
.toEqual({ token: 'env', source: 'environment' })
|
|
expect(resolveToken({ token: '' }, { SKILLHUB_TOKEN: 'env' }, 'stored')).toBe('env')
|
|
})
|
|
|
|
test('keeps resolveToken equivalent to the source-aware resolver', () => {
|
|
const cases: Array<[{ token?: string }, NodeJS.ProcessEnv, string | undefined]> = [
|
|
[{ token: 'arg' }, { SKILLHUB_TOKEN: 'env' }, 'stored'],
|
|
[{}, { SKILLHUB_TOKEN: 'env' }, 'stored'],
|
|
[{}, {}, 'stored'],
|
|
[{}, {}, undefined]
|
|
]
|
|
|
|
for (const [args, env, stored] of cases) {
|
|
expect(resolveToken(args, env, stored)).toBe(resolveTokenWithSource(args, env, stored)?.token)
|
|
}
|
|
})
|
|
})
|