From 7b123a215343c07518128af288471fe2aed3cadf Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 12 Aug 2025 17:10:09 +0200 Subject: [PATCH] scaffolder-backend: add parameter truncation with more configuration values Signed-off-by: Patrik Oldsberg --- .../src/scaffolder/tasks/TaskWorker.test.ts | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.test.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.test.ts index 4b28eb8729..7fe0618af2 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.test.ts @@ -448,4 +448,70 @@ describe('createParameterTruncator', () => { }, }); }); + + it('should not truncate if max length is -1', async () => { + const params = { + test: 'short', + test2: 'thisisaverylongstring', + nested: { + test3: 'anotherlongstringhere', + test4: ['ok', 'toolongstring', { prop: 'thisisaverylongstring' }], + }, + }; + + const result = createParameterTruncator( + mockServices.rootConfig({ + data: { + scaffolder: { + auditor: { + taskParameterMaxLength: -1, + }, + }, + }, + }), + )(params); + + expect(result).toEqual({ + test: 'short', + test2: 'thisisaverylongstring', + nested: { + test3: 'anotherlongstringhere', + test4: ['ok', 'toolongstring', { prop: 'thisisaverylongstring' }], + }, + }); + }); + + it('should throw on invalid max length', async () => { + expect(() => + createParameterTruncator( + mockServices.rootConfig({ + data: { + scaffolder: { + auditor: { + taskParameterMaxLength: -2, + }, + }, + }, + }), + ), + ).toThrowErrorMatchingInlineSnapshot( + `"Invalid configuration for 'scaffolder.auditor.taskParameterMaxLength', got -2. Must be a positive integer or -1 to disable truncation."`, + ); + + expect(() => + createParameterTruncator( + mockServices.rootConfig({ + data: { + scaffolder: { + auditor: { + taskParameterMaxLength: 1.5, + }, + }, + }, + }), + ), + ).toThrowErrorMatchingInlineSnapshot( + `"Invalid configuration for 'scaffolder.auditor.taskParameterMaxLength', got 1.5. Must be a positive integer or -1 to disable truncation."`, + ); + }); });