Files
dacli/tests/unit/test_browser_appcode_default.test.ts
sushub f403a7e80e import: ssw/dacli@eea0ebc (2026-08-12) 起点版本
本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的
dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。

- 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12)
- 历史未带 ssw main 整体历史(避免大仓污染)
- 此为新仓基线 commit,未来以本仓历史为主
2026-08-12 15:58:06 +08:00

38 lines
1.4 KiB
TypeScript

/**
* P2-8: test browser --appCode 默认值兜底 (2026-07-25)
* 防止 BS-新10 复现: 硬编码 workSystem 导致假登录
*/
import { describe, expect, it } from 'vitest'
/**
* 复现 options 配置的默认行为
*/
function buildOptions(cmd: { appCode?: string } = {}) {
// 镜像 commands/test/browser.ts:795
const optionDefault = ''
const effective = cmd.appCode || optionDefault
// 模拟 action 里的兜底链: opts.appCode || tokenCtx.appCode || 'workSystem'
const tokenCtx = { appCode: 'tdd3' }
const fallback = effective || tokenCtx.appCode || 'workSystem'
return { optionDefault, optsAppCode: effective, effectiveAppCode: fallback, tokenCtx }
}
describe('test browser --appCode 默认值兜底 (P2-8)', () => {
it('不传 --appCode 时从 token 读 tdd3 (而非 workSystem)', () => {
const r = buildOptions({})
expect(r.optsAppCode).toBe('') // option 默认 ''
expect(r.effectiveAppCode).toBe('tdd3') // 从 token 兜底
expect(r.effectiveAppCode).not.toBe('workSystem') // 不是硬编码
})
it('显式传 --appCode=workSystem 时仍尊重 (向后兼容)', () => {
const r = buildOptions({ appCode: 'workSystem' })
expect(r.effectiveAppCode).toBe('workSystem')
})
it('显式传 --appCode=testspace 时直接用', () => {
const r = buildOptions({ appCode: 'testspace' })
expect(r.effectiveAppCode).toBe('testspace')
})
})