behave is a small Go tool (MIT) I made for checking whether a rewritten command line tool still behaves like the original.

You point it at the original binary. It reads --help, generates a few hundred cases (each flag, some values, stdin and file inputs, bad arguments), runs them and records stdout, stderr and the exit code into a YAML spec. Then you replay that spec against the new binary and every difference shows up as a failing case. Timestamps, pids and temp paths can be masked with regex rules, and the spec can live in CI.

I mostly used it on the uutils Rust rewrites of GNU coreutils, findutils, sed and procps. That led to 44 upstream bug reports and 51 fix PRs, 34 of them merged.

Install: go install github.com/emirmrkaljevic/behave/cmd/behave@latest (or the Homebrew tap). Feedback welcome.

 

When a command line tool gets rewritten (new language, new version, big refactor), the existing unit tests usually say little about whether it still behaves like the old one. The old binary is the real spec, so I wanted golden master style tests generated from it instead of written by hand.

I built a small open source tool for that, behave (Go, MIT). It reads the tool's --help, generates a few hundred cases (each flag, a few values, some stdin and file inputs), runs them against the original binary and records stdout, stderr, exit code and touched files into plain YAML. Then it replays the same cases against the replacement and groups the differences. Noise like timestamps or paths can be masked with regexes, and the recorded spec can be committed and run in CI.

The main test so far was the Rust rewrites of GNU coreutils, findutils, sed and procps. Most of what it found was not crashes but small contract changes: different exit codes, error message wording, and option parsing corners. That ended up as 44 upstream bug reports and 51 fix PRs, 34 merged.

Two lessons for anyone doing this kind of testing: record from the exact version the rewrite targets (GNU 9.7 and 9.12 differ in a few outputs), and generated cases need a review pass, because some differences are intentional.

I would like to hear how others handle behavioural equivalence testing for rewrites, and where generated characterization tests have bitten you.

[–] [S] 2 points 6 hours ago

Yes, it is not tied to coreutils. I have also used it on findutils, sed and procps, and there are example recordings for jq. uutils does have a big test suite and also runs the GNU tests. The difference is that these cases are generated from each tool's --help and recorded from the GNU binary, so they catch small things nobody thought to write a test for, like the wording of an error or an exit code. The fix PRs I sent add those cases to the uutils suite.

  • source
  • parent
  • context
  • [–] [S] 1 point 6 hours ago (1 child)

    True, for a handful of hand-written cases expect works fine. The part I wanted to automate is before that: generating a few hundred cases from the tool's --help, recording what the original binary does on each, and then grouping the diffs when the same cases run against another binary. Writing that many cases by hand is where I always gave up. For interactive prompts expect is still the right tool, behave only covers non-interactive runs (arguments, stdin and files).

  • source
  • parent
  • context
  •  

    When someone rewrites a command line tool in another language, the hard question is not "does it pass its tests" but "does it still do what the old one did" in all the small corners nobody wrote a test for.

    I built a small open source tool for that, behave (Go, MIT): https://github.com/emirmrkaljevic/behave . It reads a tool's --help, generates a few hundred cases (every flag, a few values each, some stdin and file inputs), records stdout, stderr, exit code and touched files from the original binary, then replays the same cases against the rewrite and groups the diffs. The recording is plain YAML you can read and commit.

    I pointed it at the Rust rewrites of GNU coreutils, findutils, sed and procps. So far that turned into 44 upstream bug reports and 51 fix PRs, 34 of them merged. The linked post is about the second rewrite (findutils and sed) and which kinds of differences kept showing up: error wording, exit codes and option parsing corners rather than crashes.

    Happy to hear where this approach falls short.

     

    I wrote behave in Go to check whether a rewrite of a command line tool really behaves like the original.

    It treats the tool as a black box: it reads --help and the man page, generates cases (flags, flag pairs, odd stdin, missing files, bad values), runs them and records stdout, stderr and the exit code into a spec file. Then it replays the spec against another binary and every difference shows up as a failing case.

    Most of my use so far was comparing GNU coreutils, findutils, sed and procps with the uutils Rust rewrites. That turned into 44 upstream bug reports and 51 fix PRs, 34 of them merged by mid November.

    Some details: every case runs in a fresh temp dir with a fixed environment and its own timeout, cases that change between runs are marked flaky and skipped, and built-in normalizers (plus your own regex rules) strip timestamps, pids and temp paths before comparing. The same binary also runs as an MCP server. Install with go install github.com/emirmrkaljevic/behave/cmd/behave@latest or from the Homebrew tap. MIT licensed.

    Feedback on the spec format or the case generator is welcome.

     

    Ich habe ShrinkWatch EU entwickelt, eine kostenlose Browser-Erweiterung für Firefox und Chrome (Manifest V3). Sie zeigt in rund 70 europäischen Supermarkt-Onlineshops den Grundpreis pro kg oder Liter an und warnt vor Shrinkflation, also wenn eine Packung bei gleichem Preis kleiner wird. Laut README werden unter anderem REWE, Kaufland, Lidl, dm, Netto und Edeka24 unterstützt, die meisten Shops schaltet man einzeln per Klick frei. Alles läuft lokal im Browser: kein Konto, kein Tracking, keine Daten verlassen den Rechner, und der Zugriff wird nur pro Shop erteilt. Der Code steht unter der MIT-Lizenz. Es ist ein frühes Projekt, Feedback und Hinweise auf falsch gelesene Shops sind sehr willkommen.

    Quellcode: https://github.com/emirmrkaljevic/shrinkwatch-eu Firefox: https://addons.mozilla.org/en-US/firefox/addon/shrinkwatch-eu/

     

    When I built my last PC I added one of the cheap 3.5 inch USB sensor panels (the Turing Smart Screen kind), and I wanted something cleaner than the bundled software, so I wrote my own.

    It is a small tray app that starts with Windows and shows CPU and GPU temps, watts, RAM and VRAM, fans and a clock, plus the current song with its cover art from the Windows media controls. There are a few themes in landscape and portrait.

    Full disclosure: the Lite version with the hardware stats is a free download, now playing and the extra themes are in a paid Pro version.

    Feedback welcome, especially if your panel is a different size than 3.5 inch.

     

    I made this add-on for checking whether a sale in an EU online shop is real. EU law requires shops to show the lowest price of the last 30 days next to a discount, and truediscount reads that label on the product page, compares it with the claimed reduction and shows a small badge (real, inflated, or cheaper recently), plus a local price graph.

    Permissions are only for the supported shops by default, you can enable more shops one by one. No account, no server, no analytics. MIT licensed: https://github.com/emirmrkaljevic/truediscount

    Feedback and bug reports are welcome, especially with Black Friday tomorrow.

     

    Since 2022 the Omnibus rule says that when a shop in the EU advertises a price reduction, it has to show the lowest price of the last 30 days. Many shops still put a big crossed-out RRP next to the price and hide the 30-day low in small print, so a -50% badge can be closer to -5% in reality.

    I got tired of scrolling for that line, so I wrote truediscount. On a product page it finds the 30-day lowest price label (German, French, Italian, Spanish, Dutch, Polish and a few more languages), compares it with the claimed discount and shows a small badge: real discount, inflated, or it was cheaper recently. It also keeps a local price graph for pages you visit.

    It is made in Europe, free and MIT licensed. No account, no server, no tracking, all data stays in your browser. It works out of the box on Zalando, MediaMarkt/Saturn, Lidl, Alternate, Notino, About You, Komputronik and others, and you can enable it for any other shop with one click.

    Firefox: https://addons.mozilla.org/en-US/firefox/addon/truediscount/ Source and userscript: https://github.com/emirmrkaljevic/truediscount

    Disclaimer: I am the developer of this add-on.

     

    I wrote this for hardware that only ships a Windows app (case LCDs, RGB controllers, AIO coolers, mice). You record USB traffic while clicking through the vendor app (usbmon on Linux, USBPcap on Windows), note what each click did, and usb-rea infers the command layout: constant bytes, counters, value fields with their scaling, lookup tables, checksums and CRCs, handshakes and image streams. Output is a Markdown report where every claim points at Wireshark frame numbers, plus a standalone pyusb driver.

    A few Python-side details that might interest people here:

    • The pcap and pcapng parsing is plain standard library, so the only runtime dependency besides the optional MCP server is pyusb.
    • Linear field fits have to survive leave-one-out cross-checks before they are reported, so it says "unknown" rather than guessing.
    • usb-rea demo --device fan generates a synthetic capture and runs the whole pipeline, so you can try it with no hardware.

    It is MIT licensed and on PyPI (pip install usb-rea). On known protocols, for example the NZXT Kraken X fan command from liquidctl, it recovers the packet format byte for byte. Feedback on the code or the inference approach is welcome.

     

    I kept buying hardware (case LCDs, RGB controllers, mice) that only ships a Windows app, so I built usb-rea. You capture USB traffic with USBPcap or usbmon while using the vendor app, and it groups the packets, diffs them, infers the command structure and drafts a small open-source Linux driver you can test. It also runs as an MCP server, so an LLM client can drive the analysis step by step. I validated it against public captures of devices whose protocols are already documented (Turing Smart Screen, Thermalright LCD), so the output can be checked against known ground truth. It is MIT licensed, feedback and captures of stubborn devices are welcome.

     

    Since Ubuntu started shipping the Rust rewrite of coreutils by default, I got curious how close it really is to the GNU tools in day to day edge cases.

    So I wrote a small recorder. It runs a CLI on a few hundred cases and saves what it did: stdout, stderr, exit code and the files it touched. Then it replays the same cases against another binary and shows the diffs.

    Pointed at GNU coreutils 9.12 vs uutils, most differences were not crashes. They were error message wording, exit codes, option parsing corners (a bare - being taken as an option value) and a few things that turned out to be GNU version differences rather than bugs.

    I reported what I found upstream: 44 bug reports and 51 small fix PRs so far, 34 merged. The uutils folks have been great to work with.

    The tool is open source (MIT), works on any CLI, not only coreutils: https://github.com/emirmrkaljevic/behave

    Curious if anyone here has run into a uutils difference that broke a script for them.

     

    A lot of small hardware (case LCD screens, RGB controllers, AIO coolers, mice, macro pads) is only configurable through a closed Windows app, so on Linux it either works half way or not at all. I made usb-rea to shorten the reverse engineering part.

    You capture USB traffic (USBPcap on Windows, usbmon on Linux) while clicking through the vendor app, optionally noting what you did ("brightness 50", "colour red"). usb-rea groups the transfers into commands, finds the fields that change, checksums, handshakes and image streams, and writes an evidence report, a Wireshark Lua dissector and a small pyusb driver skeleton that you can turn into a proper open driver.

    It is a plain CLI (it can also run as an MCP server), MIT licensed, on PyPI as usb-rea, and usb-rea demo runs the whole pipeline on a synthetic capture so you can try it without any hardware. It is tested against protocols that open projects already document (liquidctl, rivalcfg) and public Wireshark captures.

    If you have a device stuck behind a Windows app and a capture where it gets things wrong, I would like to hear about it.

    [–] [S] 2 points 1 day ago

    Partly. The capture side is USB specific (it reads usbmon/USBPcap pcapng, endpoints and control setup packets), but the inference part is not: it diffs payloads between labelled actions and looks for constant headers, counters, length fields, checksums and value fields. Network protocols would mostly need a different front end that feeds it TCP/UDP payloads. That isn't built in today. For network protocols Netzob is worth a look, it has been doing that kind of inference for years. File formats are harder because you rarely get clean "I changed exactly one thing" pairs, but the same diffing trick works if you save the file twice with one setting changed.

  • source
  • parent
  • context
  • [–] [S] -3 points 2 days ago

    Yes, I used AI coding tools a lot while building it, both for the Go code and for working through the uutils differences. The part I care about is that everything is checkable: the specs are plain files recorded from the real GNU binaries, every reported difference is a command plus expected and actual output you can rerun yourself, and the upstream fixes went through normal review by the uutils maintainers before they were merged.

  • source
  • parent
  • context
  • view more: next ›