From f10c38940686f78611656ac6e1bd03e76291837f Mon Sep 17 00:00:00 2001 From: jwsong98 Date: Thu, 22 May 2025 02:29:05 +0900 Subject: [PATCH] test: add test cases for YAML block scalar with inconsistent and insufficient indentation --- tests/unittest/test_try_fix_yaml.py | 79 +++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/tests/unittest/test_try_fix_yaml.py b/tests/unittest/test_try_fix_yaml.py index 2d64b755..09bdbff8 100644 --- a/tests/unittest/test_try_fix_yaml.py +++ b/tests/unittest/test_try_fix_yaml.py @@ -139,3 +139,82 @@ code_suggestions: 'improved_code': 'const router = createBrowserRouter([\n' }]} assert try_fix_yaml(review_text, first_key='code_suggestions', last_key='improved_code') == expected_output + + + def test_inconsistent_indentation_in_block_scalar_yaml(self): + """ + This test case represents a situation where the AI outputs the opening '{' with 5 spaces + (resulting in an inferred indent level of 5), while the closing '}' is output with only 4 spaces. + This inconsistency makes it impossible for the YAML parser to automatically determine the correct + indent level, causing a parsing failure. + + The root cause may be the LLM miscounting spaces or misunderstanding the active block scalar context + while generating YAML output. + """ + + review_text = '''\ +code_suggestions: +- relevant_file: | + tsconfig.json + existing_code: | + { + "key1": "value1", + "key2": { + "subkey": "value" + } + } +''' + expected_json = '''\ + { + "key1": "value1", + "key2": { + "subkey": "value" + } +} +''' + expected_output = { + 'code_suggestions': [{ + 'relevant_file': 'tsconfig.json\n', + 'existing_code': expected_json + }] + } + assert try_fix_yaml(review_text, first_key='code_suggestions', last_key='existing_code') == expected_output + + + def test_inconsistent_and_insufficient_indentation_in_block_scalar_yaml(self): + """ + This test case reproduces a YAML parsing failure where the block scalar content + generated by the AI includes inconsistent and insufficient indentation levels. + + The root cause may be the LLM miscounting spaces or misunderstanding the active block scalar context + while generating YAML output. + """ + + review_text = '''\ +code_suggestions: +- relevant_file: | + tsconfig.json + existing_code: | + { + "key1": "value1", + "key2": { + "subkey": "value" + } + } +''' + expected_json = '''\ +{ + "key1": "value1", + "key2": { + "subkey": "value" + } +} +''' + expected_output = { + 'code_suggestions': [{ + 'relevant_file': 'tsconfig.json\n', + 'existing_code': expected_json + }] + } + assert try_fix_yaml(review_text, first_key='code_suggestions', last_key='existing_code') == expected_output +