Maniacal Testing: The Other Chair

In the last post, I tested Maniacal, my reimplementation of the engine behind Maniac Mansion, against the game’s own scripts, against ScummVM and against itself across releases. Every one of those tests had something in common, though. They were all written by someone who could see inside. This post is about the other user: the stranger who installs the package and has nothing but its public API and its documentation.

In an earlier post, Testing Knowledge Isn’t Just a Testing Skill, I talked about developer and tester as roles rather than identities, and about interleaving them: one person switching between the two, deliberately, on the same work. This post shows that idea at the scale of a whole library. I, as a developer, provided an API. Then I, as a tester, sat in the other chair and used it the way anyone else would. And then I went back to the first chair and fixed what the second one found.

Incidentally, I once wrote about the emic and etic in testing and that will have some relevance here, in terms of “insider” / “outsider” or even the use of the term “stranger.”

Two Kinds of User

Maniacal ships as two NuGet packages. One is the tool, maniacal, which you install and play the game with. The other is the library underneath it, Maniacal.Scumm, which is the engine itself: open a game, step it, look at its screen, read its sound, save and load, inspect its rooms and scripts, or run it in a host of your own.

The tests from the last post exercise that library thoroughly. But they do it as insiders. The test project I showed there was allowed to see the library’s internals. It reaches into the script engine’s variables, it calls methods no one outside can call, and it knows how the pieces fit because it was written alongside them. That’s exactly right for testing the engine. It told me almost nothing about whether the library is usable by someone who isn’t me.

Note that I’m asking different questions, and they need different chairs.

  • Does the engine work? That’s the insider’s question, and it’s answered by tests that can see everything. Developer chair.
  • Does the API work? That’s the outsider’s question, and it can only be answered by someone who can’t see inside. Tester chair.

The trouble with the second question is that a developer can’t (easily) unknow what they know. When I read my own API, I read it with the internals in my head. Every gap gets filled in without my noticing. So the chair has to be enforced, not just imagined.

The Developer’s Chair: What the API Promises

Start with what the developer owes the stranger (in this case, the tester, also acting as the user). An API is a set of promises: these types, these members, behaving this way, and staying that way from one release to the next. Maniacal.Scumm keeps those promises with two mechanisms, and the difference between them turned out to be a nice little testing lesson of its own.

The first is an analyzer that keeps a list of the library’s entire public surface in a text file in the repository. Actually, two. A public API shipped list and a public API unshipped list. Add a public member, and the build fails until it’s added to the list. Remove one, and the build fails until it’s taken off. That catches a lot of accidents. But notice the weakness. The list is a file in the repository, and a change can edit it along with the code. Remove a public member, remove its line from the list, and everything is consistent again. The build is green. Every program written against the last release just broke.

The second mechanism closes that gap. When the library is packed, it’s compared with the last release actually published on NuGet. Not a file anyone can edit, but the real package that real programs were built against. A member that was there and isn’t now fails the pack.

I tried it the way you would test any safety mechanism, by deliberately doing the thing it’s supposed to stop. In a scratch copy of the repository, I removed a public property, ManiacMansion.IsDemo, and removed its line from the API list too. It built. The analyzer was happy. And the pack failed:

If that sounds familiar, it’s the same rule as in the last post: an oracle you’re allowed to “fix” stops being an oracle. The API list is an oracle the developer can edit. The published package is one they can’t.

And, as so often happens, testing the mechanism found something else. Looking at IsDemo to break it, I read the documentation I wrote for it: “Whether the release is one of the DOS demos.” Emphasis on DOS. That had been true. Once. Then the C64demo came along, and the property became true for it too, not just the DOS versions, and the comment never caught up. Nothing had failed. Nothing would have. A stranger reading that comment would simply have been told something false.

The Tester’s Chair: The Playground

Now the other chair. As I was developming Maniacal, beside that repository directory sat another directory called maniacal-playground, holding a few small programs.

You can check out a version of the Maniacal Playground if you wish!

Each of those programs takes a folder of the game’s files and does something a person might plausibly want to do with an engine like this:

Program What it does
RoomAtlas Every room as a picture, with its mask, and a web page listing each room’s objects, where they are and what verbs they answer to
ScriptBrowser Every script in the game, decoded into readable listings, one file each
AttractMode Plays the title, picks the kids, and watches the intro, headless, saving frames and the whole soundtrack
Recorder A host of its own: the game run on a virtual clock through the same interface the desktop player uses, written from the documentation alone
SaveRoundTrip Saves, loads, and compares; tries damaged saves, saves from the wrong release, and the game’s own save screen

None of those things is terribly clever. And, I assure you, that’s deliberate. They’re the kind of program someone writes in an afternoon to see what a library can do, and that’s the person I wanted to be.

What makes them tests rather than demos is a set of rules:

  • They use the package from NuGet. Not a reference to the repository, not a local build. The same thing a stranger downloads.
  • They use the public API only. No access to internals, no reflection, no “I happen to know this field is there.”
  • They live outside the repository, in a folder of their own, so nothing in the library’s build can quietly help them.
  • Everything awkward gets written down. The playground has a NOTES.md, and every time a program needed a workaround, a guess, a try-and-catch, or a trip into the library’s source to understand something, that went in it, numbered.

That last rule matters more than it might initially seem. When you’re in the developer’s chair, friction is, to some extent, invisible, because you know the way around it. When you’re in the tester’s chair, friction is the finding. If it took me ten minutes to work out how to open a game, it’ll take a stranger longer, and they won’t have the source open in the next window.

Here’s how a program opens a game today:

It wasn’t always that. That’s the story.

What the Stranger Found

I wrote the first three programs against the second prerelease of the package. The notes from that first pass had eight entries, and later passes added more, twenty in all so far. What’s interesting, however, isn’t the count. It’s that they fall into kinds, and each kind says something different about where an API goes wrong.

Friction

The first finding was that opening a game took four types from four namespaces, assembled in the right order. Nothing was broken. It was just the internal structure of the engine showing through: a container for the files, a detector, a loader, a world. My developer’s chair saw that as a clean design. My tester’s chair saw it as four things to learn before you can do anything.

Others were like it. There was no way to ask which rooms or scripts a game had, so the programs looped over guessed ranges of numbers and caught the exceptions for the numbers that weren’t there. Reading the game’s sound meant the caller doing arithmetic about sample frames that the engine could have done. Picking the kids on the selection screen meant knowing where on the screen they were.

All of those were answered in the next release. ManiacMansion.Open replaced the four types. The inspector gained lists of rooms, scripts and costumes. The world gained ReadAudio, and a way to ask what objects are on screen and click one. The programs got shorter, and their lists of namespaces went from as many as six to two or three. That’s the measurable version of “easier to use.”

Documentation That Wasn’t True

This is the kind I would most encourage anyone to look for, because no insider test will ever find it.

The fourth program, the Recorder, implements its own host: a display, an input driver, an audio driver, a clock. It was written from the documentation alone. And it worked the first time, which was gratifying, but writing it turned up five places where the documentation and the engine disagreed or said nothing:

  • A host property promised the engine would advance its clock by a fixed step when it was set. The engine never read it. A host could set it, and nothing would happen.
  • Every host had to implement a method for reporting the mouse’s state. The engine never called it. It followed the mouse by events instead.
  • The time passed to each tick was documented as the time since the last one. The engine ignored it.
  • The audio volume was “applied to everything the source produces,” which didn’t say who applied it. The answer was the driver, not the engine.
  • Nothing said which input events the engine actually reads. A host had to find out.

The first two had come along with the host layer from another project of mine, where they meant something. (This was my Daventry project, which I’ll get to in these posts eventually.) Here they meant nothing, and every host anyone wrote would have carried code for them. They were removed. The other three were written down.

The same kind turned up again much later, in smaller ways. A property naming the game’s platform was documented as returning “dos” or “c64” long after it could also return “nes”, “atari” and “amiga”. And then there’s IsDemo, from earlier. None of those failed a test. Documentation often drifts silently, and the only test that notices is a reader who believes it or chooses not to.

An insider test checks what the code does. Only an outsider can check what the code says it does. Those are different specifications, and they drift apart quietly.

Real Bugs

Some findings were plain bugs, and they were found because a stranger often does things in an order the insider never thought of.

The save program loaded a save from one release into a different release. A save from the 1988 version on the 1987 version failed while loading, which is fine. But a 1987 save on the 1988 version loaded without complaint, and then the game crashed a few steps later with an index out of range. The insider tests had never tried this, because … well, why would you? The fix was for a save to remember which release made it, as ScummVM’s saves do, and for loading to refuse one from another release by name, before the game is touched.

When the C64 demo arrived, because I finally got my hands on it, the programs ran on it and two of them fell over. The demo’s index of rooms names rooms on a second disk that the demo doesn’t come with, and some of its “rooms” are files that hold only the costumes its actors wear. So the inspector, asked for its rooms, threw an exception. And pressing F5, which opens the save screen in the full C64 game, threw an exception from inside the game loop, because the save screen lives on that missing second disk. Neither would have come up in the engine’s own tests, because those were written for what the demo does, not for what a program might ask of it.

Knowledge the API Doesn’t Say

The last kind is the subtlest. To pick the kids on the selection screen, the AttractMode program finds the objects that are 40 by 48 pixels, left to right, which are the portraits, and the one that’s 40 by 8, which is START.


It works on every release. But “the 40 by 48 objects, left to right” isn’t something the API tells you. It’s knowledge about this game’s screen. And then the NES arrived, whose portraits are 32 by 40, in a different order, with a START button of a different size.

In the earlier post I called this borrowed knowledge: the test needed something that wasn’t in the interface, so it borrowed it from somewhere else. There, it was an algorithm, borrowed from the developer. Here, it’s the game, borrowed from a player. The API is honest about not knowing it, which is right, because it’s the game’s knowledge, not the engine’s. But it’s still a cost the stranger pays, and I wrote it down in the notes as exactly that.

Case Study: The Round Trip That Wasn’t a Bug

This one is from just this week as I was writing this pot, and it’s my favorite, because it repeats the last post’s best lesson from the other chair.

I wanted to make sure I had tests for saving the game. The save program’s main test is a round trip. Play up to a certain point, save, load that save into a fresh game, run both games on for 120 steps, and compare where they end up. If a save holds the game’s state, the two games should be indistinguishable. And, on every release, they were. Then the C64 demo got far enough to be tried, and the test report said:


round trips: 2 DIFFERENT

Now, this gets a little confusing, but what I found was that the demo had played itself and gone back to its menu, and the save was made there. The original game sat at the menu. The loaded game left the menu for the title screen almost at once.

That looks exactly like state the save forgot to keep. And the obvious next step was the same as last time: before blaming the engine, ask the oracle. I wrote the save in ScummVM’s format, loaded it in ScummVM, and captured its window. Half a second after the load, ScummVM had left the menu too. Then I played Maniacal‘s loaded game against those captures, and the title screen also popped up.

Okay, so then I checked the code. From that, it was clear that the menu’s script waits while its tune plays, checking a variable that says whether a sound is running. When the tune finishes, the menu plays it a second time, and after that, goes to the title screen. Loading a save stops every sound, which ScummVM does too, and the C64 doesn’t start the tune again. So a game loaded during the tune’s second time through finds the tune already over, and moves on. The save hadn’t lost anything. It had never held the sound to begin with!

Again, that can be a little confusing but here’s the key takeaway: the round trip assumed that a save carries everything. It doesn’t, and in ScummVM it doesn’t either: whatever sound is currently playing isn’t in the save. Thus, the finding wasn’t a bug in the engine. It was an assumption in the test, now written down: a round trip can differ wherever a script waits on a sound. How this might manifest is if some playing the game decides to save when a sound is playing. Very much an edge case situation that I likely wouldn’t have encountered without some fuzz testing.

All of that is “test the instrument first” from the last post, and it applies just as well when the instrument is a program written in the tester’s chair. The fix was a new test in the repository that pins the behavior, including ScummVM’s behavior, so it can’t change without someone noticing. This also warranted a paragraph in the playground’s notes so someone else (like me in the future!) doesn’t have to rediscover this.

Interleaving, in Practice

Put together, my work on this fell into a loop:

  1. In the developer’s chair: build the API, document it, release it.
  2. In the tester’s chair: write programs against the released package, and write down everything awkward, false or broken.
  3. Back in the developer’s chair: fix what was found, sometimes by breaking the API on purpose, which is what prereleases are for. One release made two such breaks, and I made sure the release notes said so.
  4. In the tester’s chair again: move the programs to the new release, take their workarounds out, and see whether the fixes actually helped.

Step four is the one that’s easy to skip. A fix that was meant to make the API easier hasn’t done so until a program written against it is shorter. Moving the playground to each release, deleting its workarounds, and checking that the result read more simply was how I tested the fixes.

The loop also found a seam, in the earlier post’s sense. Because the programs use the package from NuGet, they can only test what’s already been published. Fix something in the library, and the tester’s chair can’t see it until there’s a release. That’s the point of the rule, but it also meant the playground could only ever find problems after strangers could too!

So the tester (me) asked the developer (also me) a question, which is how seams usually get made: how do I test this before it ships? The answer was a small switch in the playground. One command packs the library from the repository as it is right now and points the programs at it; the same command, told otherwise, puts them back on the released package:


./use-local.ps1              # build against the repository as it is now
./use-local.ps1 -Released    # back to the release on NuGet

The interesting part is the care it takes not to blur the chairs. The local package gets a version of its own, something like 0.4.1-local.20261102070211, so it can never be mistaken for a real release. And it’s kept in a package cache of its own, so it can never stand in for the real one in NuGet’s cache on the machine. The tester gets an early look, and the rule underneath, that the playground tests what strangers get, survives it.

Heuristics for Testing an API from Outside

  • Use the published thing. Build against the package a stranger downloads, not your repository. Anything else lets the developer’s knowledge leak in.
  • Write ordinary programs. Not tests of each method, but the program someone would write in an afternoon. The findings are in the gaps between methods.
  • Treat friction as a finding. Every workaround, guess, try-and-catch and trip into the source goes in the notes, with a number.
  • Write one program from the documentation alone. Whatever you had to look up in the code to finish it is where the documentation is missing or wrong.
  • Do things in the wrong order. Load the wrong release’s save. Ask a demo for its rooms. Press the key for a screen that isn’t there.
  • Run everything on everything. Every program on every release, every time. New data finds what old data couldn’t.
  • Move to each release and delete the workarounds. A fix isn’t done until the program that needed it got simpler.
  • Make the promises checkable by something you can’t edit. Compare each release with the one actually published.
  • Suspect the test program too. A program written in the tester’s chair carries assumptions, and when it disagrees with the engine, check the oracle before blaming either.

Sample Charters

Charter Time box
Explore opening and inspecting each release with only the package and its documentation, to discover what a newcomer must learn before the first useful line 45 min
Explore writing a host from the documentation alone, to discover what the documentation leaves to be guessed 90 min
Explore saves across releases, versions and damage, to discover errors that come late, unclearly or not at all 60 min
Explore each documentation comment against what the member actually does, to discover promises that have drifted 60 min
Explore a new release with programs written for the last one, to discover what broke and whether the release notes said so 30 min

Back to the First Chair

The thing I keep coming back to is how little of this the insider tests could have found, however many of them there were. Four hundred tests can tell you the engine plays the game. Not one of them can tell you it took four types to open it, or that a comment says “DOS demo” where it means “any demo,” or that a property promises something the engine never does. Those findings only exist in the other chair.

And the reverse is true too. The playground could never have found the ladder from the last post, or the mask the original decodes eight bytes further than ScummVM does. It can’t see far enough in. Neither chair is enough on its own. That was the point of the earlier testing knowledge post, and it held at the scale of a whole library: the knowledge has to flow both ways, and someone has to keep switching seats.

Even if, as in this case, it’s the same someone.

What Next?

As I did with Laser Vault, I will do an “Under the Hood” post for this project. Stay tuned!

Share

This article was written by Jeff Nyman

Anything I put here is an approximation of the truth. You're getting a particular view of myself ... and it's the view I'm choosing to present to you. If you've never met me before in person, please realize I'm not the same in person as I am in writing. That's because I can only put part of myself down into words. If you have met me before in person then I'd ask you to consider that the view you've formed that way and the view you come to by reading what I say here may, in fact, both be true. I'd advise that you not automatically discard either viewpoint when they conflict or accept either as truth when they agree.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.