Foreman

Case study · Add a feature

Add --json flag to todo.py that prints tasks as a JSON list

add a --json flag to todo.py that prints the tasks as a JSON list, with a test

Add a feature

fm code 'add a --json flag to todo.py that prints the tasks as a JSON list, with a test' --worker claude

fm code tui at the end of this run: Add --json flag to todo.py that prints tasks as a JSON list

Plan FEATURE S · Add --json flag to todo.py that prints tasks as a JSON list

Steps

  1. Write test_todo.py (unittest) that calls main(['--json']) with captured stdout and asserts json.loads(output) == TASKS, plus a check that main([]) still prints the numbered list; confirm it fails
  2. In todo.py add `import json` and, in main, if '--json' in argv print json.dumps(TASKS) and return, leaving the numbered output otherwise unchanged
  3. Run the test and the shell checks to confirm they pass

Checks

  • PASS Running `python todo.py --json` prints TASKS as a JSON list that parses back to the same listpython todo.py --json | python -c "import sys, json; assert json.load(sys.stdin) == ['buy milk', 'write report']" (failed before the work)
  • PASS Running `python todo.py` with no flag still prints the numbered list, and `--json` output is not numbered textpython todo.py | grep -qx '1. buy milk' && ! python todo.py --json | grep -q '^1\. ' && python todo.py --json | grep -q '^\[' (failed before the work)
  • PASS A test in test_todo.py covers the --json output and passespython -m unittest test_todo (failed before the work)

Changed

  • test_todo.py +25
  • todo.py +4

Closed T-0001 closed; committed a1bc78b (2 files). Undo: git revert --no-edit a1bc78b (tokens: 99493 in, 989 out)

3 worker turns · 100k tokens · 1m09s · replay it: fm code tui --events demo/examples/feature.jsonl · the case study

The run, event by event

  1. 19s before fails: python todo.py --json | python -c "import sys, json; assert json.load(sys.stdin) == ['buy milk', 'write report']"
  2. 19s before fails: python todo.py | grep -qx '1. buy milk' && ! python todo.py --json | grep -q '^1\. ' && python todo.py --json | grep -q '^\['
  3. 20s before fails: python -m unittest test_todo
  4. 20s step step 1/3: Write test_todo.py (unittest) that calls main(['--json']) with captured stdout and asserts json.loads(output) == TASKS, plus a check that main([]) still prints the numbered list; confirm it fails
  5. 37s changed test_todo.py
  6. 37s step step 2/3: In todo.py add `import json` and, in main, if '--json' in argv print json.dumps(TASKS) and return, leaving the numbered output otherwise unchanged
  7. 50s changed test_todo.py, todo.py
  8. 50s step step 3/3: Run the test and the shell checks to confirm they pass
  9. 1m06s changed test_todo.py, todo.py
  10. 1m07s check passes: python todo.py --json | python -c "import sys, json; assert json.load(sys.stdin) == ['buy milk', 'write report']"
  11. 1m07s check passes: python todo.py | grep -qx '1. buy milk' && ! python todo.py --json | grep -q '^1\. ' && python todo.py --json | grep -q '^\['
  12. 1m08s check passes: python -m unittest test_todo
  13. 1m09s closed T-0001 closed; committed a1bc78b (2 files). Undo: git revert --no-edit a1bc78b (tokens: 99493 in, 989 out)

Back to fm code