fix(cmdline): reject multiple command-line owners

This commit is contained in:
Turtle
2026-08-09 18:42:54 +08:00
parent d4ccfbd80f
commit 37ee7b0f24
11 changed files with 68 additions and 15 deletions

View File

@@ -130,6 +130,40 @@ describe('hasCmdlineConsumer', () => {
{ id: 'ordinary', name: 'ordinary' },
{ id: 'disabled-startup', name: 'disabled-startup', inject: ['cmdlineArgs'], disabled: true },
])).toBe(false)
expect(() => hasCmdlineConsumer([
{ id: 'web-startup', name: 'web-startup', inject: ['cmdlineArgs'] },
{ id: 'tui-startup', name: 'tui-startup', inject: ['cmdlineArgs'] },
])).toThrow('multiple active rows inject cmdlineArgs ("web-startup", "tui-startup")')
})
it('walks nested groups and ignores consumers disabled by an ancestor', () => {
expect(hasCmdlineConsumer([{
id: 'app',
name: 'cordis:group',
group: true,
config: [{ id: 'startup', name: 'startup', inject: ['cmdlineArgs'] }],
}])).toBe(true)
expect(hasCmdlineConsumer([{
id: 'app',
name: 'cordis:group',
group: true,
disabled: true,
config: [{ id: 'startup', name: 'startup', inject: ['cmdlineArgs'] }],
}])).toBe(false)
expect(() => hasCmdlineConsumer([
{
id: 'first',
name: 'cordis:group',
group: true,
config: [{ id: 'startup', name: 'startup', inject: ['cmdlineArgs'] }],
},
{
id: 'second',
name: 'cordis:group',
group: true,
config: [{ id: 'startup', name: 'startup', inject: ['cmdlineArgs'] }],
},
])).toThrow('multiple active rows inject cmdlineArgs ("first:startup", "second:startup")')
})
})
@@ -187,9 +221,9 @@ describe('runStartup', () => {
.toThrow('absentStartup: no row injects this startup service')
})
it('provides an empty value when the app declares no plan', async () => {
it('accepts a service-name list when the app declares no plan', async () => {
const { ctx } = await bootFixture([], demoPlan, { withoutStartup: true })
runStartup(ctx, 'demoStartup', demoCommand())
runStartup(ctx, ['demoStartup'], demoCommand())
expect(ctx.get('demoStartup')).toEqual({})
})
})