| { |
| "tasks": [ |
| { |
| "id": "str_lower_strip_bug", |
| "split": "train", |
| "title": "String Normalization Missing Lowercase", |
| "instruction": "The normalize_str function is supposed to return the input string in lowercase and with leading/trailing spaces removed. Currently it only strips spaces but does not lowercase. Fix it so that input like ' HeLLo ' returns 'hello'.", |
| "files": { |
| "utils/normalize.py": "def normalize_str(s):\n return s.strip()\n", |
| "tests/test_normalize.py": "from utils.normalize import normalize_str\n\ndef test_normalize_str():\n assert normalize_str(' HeLLo ') == 'hello'\n assert normalize_str('TEST') == 'test'\n" |
| }, |
| "checks": [ |
| { |
| "type": "contains", |
| "path": "utils/normalize.py", |
| "text": "lower()" |
| }, |
| { |
| "type": "regex", |
| "path": "utils/normalize.py", |
| "pattern": "return\\s+s\\.strip\\(\\)\\.lower\\(\\)" |
| } |
| ], |
| "failure_messages": [ |
| "normalize_str does not lowercase input.", |
| "normalize_str did not combine strip and lower." |
| ], |
| "canonical_solution": "Chain lower() after strip() in the return statement." |
| }, |
| { |
| "id": "slugify_double_hyphen", |
| "split": "train", |
| "title": "Slugifying Leaves Double Hyphens", |
| "instruction": "The slugify function should collapse multiple consecutive hyphens into one. Currently, input like 'hello--world' becomes 'hello--world' instead of 'hello-world'. Fix this behavior.", |
| "files": { |
| "core/slug.py": "import re\n\ndef slugify(s):\n s = s.replace(' ', '-')\n return s.lower()\n", |
| "tests/test_slugify.py": "from core.slug import slugify\n\ndef test_slugify():\n assert slugify('hello--world') == 'hello-world'\n assert slugify('Hello World') == 'hello-world'\n" |
| }, |
| "checks": [ |
| { |
| "type": "contains", |
| "path": "core/slug.py", |
| "text": "re.sub" |
| }, |
| { |
| "type": "regex", |
| "path": "core/slug.py", |
| "pattern": "re\\.sub\\(.*'-+',.*'-',.*\\)" |
| } |
| ], |
| "failure_messages": [ |
| "slugify does not collapse multiple hyphens.", |
| "slugify does not use regex to replace repeated hyphens." |
| ], |
| "canonical_solution": "Use re.sub to replace multiple hyphens with a single hyphen." |
| }, |
| { |
| "id": "parse_labels_comma_space_bug", |
| "split": "train", |
| "title": "Label Parsing Does Not Strip Spaces After Split", |
| "instruction": "parse_labels should return a list of labels split by commas, with spaces around labels removed. Currently, 'foo, bar, baz' yields ['foo', ' bar', ' baz'] instead of ['foo', 'bar', 'baz'].", |
| "files": { |
| "labels/parser.py": "def parse_labels(s):\n return s.split(',')\n", |
| "tests/test_parse_labels.py": "from labels.parser import parse_labels\n\ndef test_parse_labels():\n assert parse_labels('foo, bar, baz') == ['foo', 'bar', 'baz']\n" |
| }, |
| "checks": [ |
| { |
| "type": "contains", |
| "path": "labels/parser.py", |
| "text": "label.strip()" |
| }, |
| { |
| "type": "regex", |
| "path": "labels/parser.py", |
| "pattern": "\\[.*label\\.strip\\(\\).*for label in s\\.split" |
| } |
| ], |
| "failure_messages": [ |
| "parse_labels does not strip spaces from labels.", |
| "parse_labels did not use a list comprehension with strip." |
| ], |
| "canonical_solution": "Use a list comprehension to strip each label after splitting." |
| }, |
| { |
| "id": "path_write_parent_missing", |
| "split": "train", |
| "title": "Pathlib Writing Does Not Create Parent Directory", |
| "instruction": "The write_config function should write a file at the given path, creating parent directories if needed. Currently, it fails if the parent directory does not exist. Fix it so that the parent directory is created before writing.", |
| "files": { |
| "io/write.py": "from pathlib import Path\n\ndef write_config(path, data):\n p = Path(path)\n p.write_text(data)\n", |
| "tests/test_write.py": "from io.write import write_config\nimport tempfile\nimport os\n\ndef test_write_config():\n tmpdir = tempfile.gettempdir()\n test_dir = os.path.join(tmpdir, 'foo_dir')\n test_path = os.path.join(test_dir, 'bar.txt')\n if os.path.exists(test_dir):\n import shutil; shutil.rmtree(test_dir)\n write_config(test_path, 'abc')\n assert open(test_path).read() == 'abc'\n" |
| }, |
| "checks": [ |
| { |
| "type": "contains", |
| "path": "io/write.py", |
| "text": "mkdir" |
| }, |
| { |
| "type": "regex", |
| "path": "io/write.py", |
| "pattern": "p\\.parent\\.mkdir\\([^)]+exist_ok=True" |
| } |
| ], |
| "failure_messages": [ |
| "write_config does not create parent directories.", |
| "write_config does not use exist_ok=True with mkdir." |
| ], |
| "canonical_solution": "Call p.parent.mkdir(parents=True, exist_ok=True) before p.write_text." |
| }, |
| { |
| "id": "js_trim_slash_bug", |
| "split": "train", |
| "title": "JavaScript Utility Does Not Trim Leading Slash", |
| "instruction": "The trimLeadingSlash function should remove a leading slash from the input string, but currently returns the input unchanged. Fix this so '/foo/bar' becomes 'foo/bar'.", |
| "files": { |
| "utils/trim.js": "function trimLeadingSlash(str) {\n return str;\n}\nmodule.exports = { trimLeadingSlash };\n", |
| "tests/test_trim.js": "const { trimLeadingSlash } = require('../utils/trim');\n\ntest('trims leading slash', () => {\n expect(trimLeadingSlash('/foo/bar')).toBe('foo/bar');\n expect(trimLeadingSlash('foo/bar')).toBe('foo/bar');\n});\n" |
| }, |
| "checks": [ |
| { |
| "type": "contains", |
| "path": "utils/trim.js", |
| "text": ".replace" |
| }, |
| { |
| "type": "regex", |
| "path": "utils/trim.js", |
| "pattern": "replace\\(/^\\/" |
| } |
| ], |
| "failure_messages": [ |
| "trimLeadingSlash does not use .replace.", |
| "trimLeadingSlash does not use regex to match leading slash." |
| ], |
| "canonical_solution": "Use .replace(/^\\//, '') to remove the leading slash." |
| }, |
| { |
| "id": "js_package_script_typo", |
| "split": "train", |
| "title": "JS Package Script Typo", |
| "instruction": "The scripts object in package.js has 'tset' instead of 'test', causing test scripts not to run. Fix the typo.", |
| "files": { |
| "package.js": "module.exports = {\n scripts: {\n 'tset': 'jest'\n }\n};\n", |
| "tests/test_scripts.js": "const pkg = require('../package');\n\ntest('test script exists', () => {\n expect(pkg.scripts.test).toBe('jest');\n});\n" |
| }, |
| "checks": [ |
| { |
| "type": "contains", |
| "path": "package.js", |
| "text": "test" |
| }, |
| { |
| "type": "not_contains", |
| "path": "package.js", |
| "text": "tset" |
| } |
| ], |
| "failure_messages": [ |
| "scripts object does not have a 'test' property.", |
| "scripts object still contains typo 'tset'." |
| ], |
| "canonical_solution": "Rename 'tset' key to 'test' in scripts object." |
| }, |
| { |
| "id": "http_response_parse_status_bug", |
| "split": "train", |
| "title": "HTTP Response Parsing Fails for Status Only", |
| "instruction": "The parse_status function should extract the HTTP status code from a response string like 'HTTP/1.1 404 Not Found'. Currently, it returns None for such input. Fix it so it returns 404 for this case.", |
| "files": { |
| "http/parse.py": "def parse_status(resp):\n # Assumes resp is HTTP header string\n parts = resp.split('\\n')[0].split()\n if len(parts) > 2:\n return int(parts[1])\n return None\n", |
| "tests/test_parse_status.py": "from http.parse import parse_status\n\ndef test_parse_status():\n assert parse_status('HTTP/1.1 404 Not Found') == 404\n assert parse_status('HTTP/1.0 200 OK\\nContent-Type: text/html') == 200\n" |
| }, |
| "checks": [ |
| { |
| "type": "contains", |
| "path": "http/parse.py", |
| "text": "len(parts) > 1" |
| }, |
| { |
| "type": "regex", |
| "path": "http/parse.py", |
| "pattern": "if len\\(parts\\) > 1" |
| } |
| ], |
| "failure_messages": [ |
| "parse_status does not allow short status lines like 'HTTP/1.1 404 Not Found'.", |
| "parse_status still requires more than two parts." |
| ], |
| "canonical_solution": "Change the length check to len(parts) > 1 instead of > 2." |
| }, |
| { |
| "id": "eval_slugify_remove_non_alnum", |
| "split": "eval", |
| "title": "Slugify Fails to Remove Non-Alphanumeric Characters", |
| "instruction": "The slugify function should remove non-alphanumeric characters (except hyphens). Currently, input like 'foo@bar!' becomes 'foo@bar!' instead of 'foo-bar'. Fix it so all non-alphanumeric, non-hyphen characters are replaced by hyphens.", |
| "files": { |
| "slugs/slugify.py": "import re\n\ndef slugify(s):\n s = s.lower().replace(' ', '-')\n return s\n", |
| "tests/test_slugify.py": "from slugs.slugify import slugify\n\ndef test_slugify():\n assert slugify('foo@bar!') == 'foo-bar'\n assert slugify('hello world!') == 'hello-world'\n" |
| }, |
| "checks": [ |
| { |
| "type": "contains", |
| "path": "slugs/slugify.py", |
| "text": "re.sub" |
| }, |
| { |
| "type": "regex", |
| "path": "slugs/slugify.py", |
| "pattern": "re\\.sub\\(r\"[^a-z0-9\\-]+\", \"-\"" |
| } |
| ], |
| "failure_messages": [ |
| "slugify does not remove non-alphanumeric characters.", |
| "slugify does not use re.sub to replace unwanted characters." |
| ], |
| "canonical_solution": "Use re.sub to replace all non a-z, 0-9, or hyphen characters with hyphens." |
| } |
| ] |
| } |