plumbing: add some unit tests, and correct some bugs in Stream and TagManager.