repomap: see what your code does when it runs
The big question
When you open code you didn't write, you can read it, but you can't see it run. Which tests use this function? What values did it actually get, and what did it give back? If I change it, what else is affected, and which tests should I run? Today you answer those by reading a lot of code or by running the whole test suite.
repomap answers them by watching your tests run once. Then it shows you what it saw, right next to your code in VS Code, or on a page in your browser that runs on your own computer.
How it works
- Record once. You run
repomap record in a Python project. It runs the project's tests and watches them. For each test it saves which lines ran, which function called which and in what order, and the values that went in and came back. Nothing is sent anywhere: it all goes into a .repomap/ folder in the project.
- Look at it where you work. Open the project in VS Code, or run
repomap serve and open the link it prints.
- Keep it fresh. After you edit code,
repomap refresh re-runs only the tests that touch the files you changed. VS Code can do this each time you save.
A real example, from the small Flask to-do app that comes with repomap: a test fills in the "new task" form with the title " Buy milk ". In the Flow view you follow that request call by call. The route hands the form to read_task_form, which calls clean_title with " Buy milk " and gets back "Buy milk". Then the store saves the task and the page is drawn. Each box is a function, and each arrow shows the values passed in and returned.
What you can do with it
In VS Code
The extension adds a Flow panel next to the terminal, in your editor's own theme and fonts.
- The panel follows your cursor. Put the cursor in a function and the panel jumps to the first time a test called it, with the values it got.
- Lenses above each function. "3 tests run this" lets you pick a test to follow, and "show flow" jumps straight to one.
- Hover a function to see the values its first recorded call took and what came back, or the error it raised.
- Run a function with your own values. "run with values…" above any function, tested or not, asks for its inputs, runs it, and shows every call along the way. You can also start from a real test's call and change one value. These runs never count as tests.
- Refresh on save. When you switch it on, it re-runs only the tests your edit affects, a second after you save.
It runs the repomap command when it needs an answer, so nothing stays running in the background.
In your browser: repomap serve
repomap serve starts a page on your own computer (localhost). It only reads what was recorded, so it opens instantly.
- Flow: the same view as the VS Code panel. Pick a test and press Play to step through its calls, with whole values shown one argument per line. The main path (route, view, form, store, page) is drawn bold, and small helpers are drawn light.
- Overview: every function as a square, laid out by folder and file. The squares stay in place as the code changes, so you learn where things are. You can light up untested code, the most important functions, or the parts that change often.
- Neighborhood: click a function to see what calls it and what it calls.
- Test replay: watch a test's calls light up on the map in the order they ran.
- Change: your uncommitted edits in the middle, the tests that run them on the left, and the code that calls them on the right, with a ready-to-copy command that runs just those tests.
What we learned
- It picks the right tests. On werkzeug, a popular Python web library, it found all 85 tests whose results changed across 54 real commits, while running only 24% of the test suite.
- It catches planted bugs with a tiny slice of the tests. We planted 200 small bugs on purpose. It caught all 171 that any test could catch, usually by running 6 of werkzeug's 1,003 tests (about 0.6%).
- People find functions fast in the Flow view. In a five-question check on the to-do app, every "which function does this" question was answered correctly in about 2 minutes or less. The main problem was that values were cut off too short, which hid an error message and most of a list. Values are now kept up to 300 characters and shown whole.
- It is weaker at saying what else a change affects. On werkzeug, only 5% of the functions a planted bug really changes are callers of the changed code, which is the direction repomap follows today. Most effects travel through values that are saved and read later. Arrows that follow values are on the roadmap.
- It is not a bug finder. Its notes on untested inputs ("this was never empty in any test") almost never pointed at the bugs people reported later. So it is for showing what code does, not for guessing where bugs are.
Other ways to use it