Writing / Kalix, part 4 of 8

Passing Tests Are Not the Same as Looking

Kalix has two kinds of automated check. Tests run the engine’s code and compare what it produced with what it should produce. A second, cheaper set searches the source for things that must or must never appear, nearly two thousand of them. Every change has to pass both before it counts.

They are worth having. They also kept passing while the thing on screen was wrong. Here are eight times that happened, roughly in the order I learned from them.

1. Text that would not go behind anything

Until August 19, the interface drew all of its shapes first and all of its text afterwards. So a dark, see-through panel laid over a menu, the usual way to dim a menu behind a pop-up, dimmed the menu’s boxes and left its words at full brightness on top.

This was not hidden. It was described in one comment in the code, as a feature, and it survived five rounds of interface work. No test asked what order things were drawn in. Now they are drawn in the order they were written. Measured after the fix, labels under the dark panel read 119.6 and 118.3 in brightness, and a label drawn after it reads 240.9.

A grey see-through panel in the top left. The words UNDER THE SCRIM and ALSO UNDER are dimmed by it; the words OVER THE SCRIM, drawn after the panel, are bright white.
After the fix: two labels drawn before the dark panel are dimmed by it, and one drawn after it is not.

2. A grey that came out pale

The interface’s colours are typed as numbers between 0 and 1. A screen takes colours in a slightly different form from the one the engine calculates in, and the interface was treating typed colours as if they were already in the engine’s form. A grey typed as 0.5 showed up as 188 out of 255 instead of 128.

Every test passed, because every test checked the number that was typed, not the colour that appeared. It was found when a game’s whole palette looked washed out. A setting now makes the interface read typed colours the way a person means them. It is a setting rather than a change to every existing screen at once, so screens tuned the old way keep their look.

A light grey rectangle on black, labelled: swatch, colors_srgb = FALSE (authored 0.5 grey).
A grey typed as 0.5, drawn the old way. It should be a middle grey; it is much paler.

3. The animation preview that crashed every time it drew

On August 3, a change to the renderer moved where each object’s position is stored on the graphics card. The animation studio’s 3D preview kept its own copy of the old description of that data. From then on, the preview crashed on every frame it tried to draw.

Nobody noticed for six days, because no test opens that preview and nobody happened to. It was found on August 9, when the combat editor’s new preview, built on the same drawing code, was opened for the first time and crashed. The fix was to delete the copy and use the engine’s own.

4. A character drawn as one piece of eight

Characters bought from asset stores are usually made of several pieces: a body, a head, hands, shoes. In August one such fighter appeared in the engine as a pair of shoes and a few fragments, and it looked like a broken import.

The importer was fine. The engine drew one piece of each animated character, and only the first: one of eight for that fighter, one of eighteen for another. The piece it did draw was animated correctly, which is exactly why it looked like a problem with the file. Fixed on August 29, with a search check over every place that draws a character so that a missed one cannot come back quietly.

5. A toggle that took two clicks

In August the interface gained clickable buttons, toggles and sliders. The agent tested them by sending clicks to a running game and capturing the screen, and found that a toggle set to start switched on took two clicks to switch off.

Two pieces of code answered “is this toggle on?” differently: the code that drew it used the starting value, and the code that flipped it assumed off. The worst part was the test. It asserted that a click must flip the toggle, which was exactly the behaviour that was wrong, so the test was holding the bug in place. A test can lock in a defect as firmly as a feature.

6. Bought buildings

In August I imported a pack of medieval buildings bought from an asset store. The import’s tests passed. Looking at the result found four defects in two sessions, and no test could have reached any of them:

  • a building dragged into the scene never had its materials applied, because the step that applies them was never asked to run for things added that way;
  • each building’s top-level object drew as a stray cube;
  • the pack’s own material files pointed some slots at the wrong texture, a mask where the colour should be, and the importer trusted them;
  • deleting a building removed its top object and left 13 of its 14 pieces on screen.

Looking also checked the numbers that mattered. These meshes carried their textures inside each file, and the same textures were copied into many files. Stripping them out took the library from 6.9 GB to 42 MB, with every vertex unchanged, checked against a fingerprint of the geometry taken before. To be sure the stripped copy looked the same, the agent rendered both versions from the same camera: the two pictures were identical to the byte. That kind of result is also what a stale picture gives you, so it nudged the building 15 centimetres and confirmed the picture changed.

Sharing identical textures in graphics memory was measured the same way. For twelve buildings, 518 texture loads became 29, and 5,744 MB became 393 MB, 17.86 times less.

The packs taught one more rule. Texture files are named for what they hold, and the names are not always right. One common layout stores three values in one image as occlusion, roughness and metal; another stores them as metal, roughness and occlusion. Read one as the other and every building looks like tarnished metal, which looks like a lighting bug. The importer now has a mode that opens the images and checks. A name is a hint, a material file is evidence, and the pixels are proof.

7. The button below the bottom of the window

In September a combat editor gained a way to author how far a fighter travels during a move. The only way to start was a row you click to open. That row was drawn just below the bottom edge of the window, where nobody could click it.

The layout had four tests. All four ran with that row already open, on a tall screen, the one arrangement where the problem cannot happen. A test fixes its setup as firmly as its checks, and these had picked the only setup that hid the bug. It was found by taking the first screenshot of the feature.

8. Checks that never ran

In August it turned out that six of the source-search checks had never been running. The search program they used was not installed where the checks ran, so each one failed with “command not found”, and a check that looks for something forbidden reads “found nothing” as a pass. Among them was the check guarding what the interface code is allowed to depend on.

A check that something is absent cannot tell “nothing is wrong” from “I did not run”. The check script now fails loudly if its tools are missing.

What I changed

  • Prove a check can fail. Before trusting a new test, break the code on purpose and watch the test fail. Several of the tests in this list would have passed a broken version.
  • Capture the result and look at it. For anything on screen, a picture is part of the evidence, and the agent can take its own (see part 3).
  • Say which kind of “done” it is. In the engine’s records, “checked by tests” and “seen working” are different words, and a sign-off that was skipped says so.

That last one matters, because I skipped some. On September 9 I closed 37 outstanding sign-off checks without running them, to move on to other work. They are recorded as closed unrun, not as reviewed. Some of what they cover has never been looked at by a person. The next article is about a defect that every check passed and one look found.