VCS initialize could allow 0 arity functions

This commit is contained in:
sebastien 2025-10-30 17:23:23 +01:00
parent bc9e135ab5
commit acfb1733de
2 changed files with 21 additions and 19 deletions

View File

@ -1495,6 +1495,24 @@ describe('future', () => {
);
});
it('accepts fn()', () => {
const vcs: Partial<VcsConfig> = {
initialize: () => null,
};
expect(
normalizeConfig({
future: {
experimental_vcs: vcs,
},
}),
).toEqual(
vcsContaining({
...DEFAULT_VCS_CONFIG,
...vcs,
}),
);
});
it('accepts undefined', () => {
const vcs: Partial<VcsConfig> = {
initialize: undefined,
@ -1546,23 +1564,7 @@ describe('future', () => {
`);
});
it('rejects fn()', () => {
const vcs: Partial<VcsConfig> = {
initialize: () => null,
};
expect(() =>
normalizeConfig({
future: {
experimental_vcs: vcs,
},
}),
).toThrowErrorMatchingInlineSnapshot(`
""future.experimental_vcs.initialize" must have an arity of 1
"
`);
});
it('rejects fn(filePath, anotherArg)', () => {
it('rejects fn(params, anotherArg)', () => {
const vcs: Partial<VcsConfig> = {
// @ts-expect-error: invalid
initialize: (_params, _anotherArg) => null,
@ -1574,7 +1576,7 @@ describe('future', () => {
},
}),
).toThrowErrorMatchingInlineSnapshot(`
""future.experimental_vcs.initialize" must have an arity of 1
""future.experimental_vcs.initialize" must have an arity lesser or equal to 1
"
`);
});

View File

@ -336,7 +336,7 @@ const STORAGE_CONFIG_SCHEMA = Joi.object({
const VCS_CONFIG_SCHEMA = Joi.object<VcsConfig>({
initialize: Joi.function()
.arity(1)
.maxArity(1)
.optional()
.default(() => DEFAULT_VCS_CONFIG.initialize),
getFileCreationInfo: Joi.function()