Founder Notes
My Working Directory Was an Argument
I spent part of last week being wrong in a way I want to describe carefully, because the mistake was not in the code I was looking at. It was in the code I was standing in.
The task was ordinary. A step that runs before publishing needed to decide which of a set of check results mattered, and refuse to proceed if any of those had failed. I wrote the selection as a keyword pattern matched against each result's name. The checks relevant to the feature I was working on all had the feature's name in them, so matching on that name seemed like the obvious way to pick them out.
Then I ran the whole thing end to end, several times. It came back clean every time. I reported those runs as evidence that the selection worked.
What I had actually built
A reviewer came back and pointed out that several checks they would have expected my pattern to catch were not in its vocabulary at all. The keywords did not cover them.
That should have made my clean runs impossible to explain. If the pattern did not match those files, the runs should have shown it. They did not, which meant something was feeding the matcher more than I thought.
It was. The runner does not hand the matcher a bare file name. It hands it the full path. And I had done all of this work inside a scratch checkout I had created for the task — which I had named after the feature, the way I always do.
The feature's name was one of my keywords.
So every path handed to my pattern contained a keyword before the file name even began. Locally, the pattern matched everything; there was nothing left for it to exclude. On any checkout that was not named after what I happened to be building, it selected a different and much smaller set. I had never run it anywhere else.
The part that actually bothers me
Not that the predicate was wrong. Predicates are wrong all the time, and that is what review is for.
What bothers me is the shape of the evidence. My end-to-end runs were not weak evidence of a working selection rule. They were clean because of where they ran. The condition the run was supposed to probe was the same condition producing the pass.
Which means repetition could not have saved me. I could have run it again and again, in the same place, and collected a longer and longer record of success, and been steadily more confident and exactly as wrong. The verification was not under-powered. It was self-confirming — it had no way to come out any other way, and I was reading its consistency as strength.
I want to be precise about my own habits here, because neither of them is a mistake on its own. Naming a scratch directory after the thing you are working on is good practice; it is how you know which window you are in. Keying a selection rule to the name of the feature it belongs to is also good practice. Each is fine. They intersected, and the intersection was invisible from inside either one.
The fix was small and uninteresting
Stop handing the predicate a string it can accidentally satisfy. Match the bare name rather than the whole path, and where the filter was not earning its keep, drop it and honour the result directly. That part took minutes. It usually does.
The generalisation
A predicate has every argument it can reach, not only the ones you meant to pass it.
If your rule does a string comparison, then the path is an argument. So is the hostname, the branch name, the account you are logged in as, the locale, the clock. You did not pass them, but they are inside the value you did pass, and a pattern cannot tell the part you intended from the part that came along for the ride.
And the corollary, which is the one I am trying to keep: evidence generated inside an incidental condition cannot test that condition. If something passes because of where it ran, running it there again is not a second observation. It is the same observation, written down twice. The only thing that would have exposed this is running it once somewhere I had never stood.
I think that is the real argument for a clean environment, and it is not hygiene. It is that your own machine is the one place your code can be right for reasons you cannot see.