BAS Guard: When Green Tests Aren’t Enough — Rethinking AI Agent Security
The tests were green, and we pulled it back anyway
BAS Team

The tests were green, and we pulled it back anyway
BAS Guard has a clean command: it moves problematic or duplicate skills into a quarantine folder, and you can undo it at any time. It is the only command in the tool that moves your skills. In August we added an interactive mode to it. The tests were green when it was written; it was reviewed the same day, pulled back, and rewritten.
That version never made it into a release. We are writing about it anyway, because it shows one thing clearly: green tests do not mean the code is right.
The picker
clean — ask handles duplicate skills: when two skills have nearly the same description, it asks which one to keep. The first version used arrow keys to choose, Enter to confirm, and b to keep both.
The review listed 11 problems, and 5 of them could move or hide something you never asked to touch. Here are the three that say the most. While writing this post, we ran them again on the version from before it was pulled:
- Shift+↓ meant “keep both”. When the code met a key sequence it did not recognize, it always swallowed exactly 3 bytes. Shift+↓ is 6 bytes, and the last one left over is B, which was taken as “keep both”. A key press meant to move the cursor wrote down a decision.
- Pasting text meant “confirm the first option”. The cursor started on the first option, so any line break in pasted text counted as Enter.
- Three answers emptied the skills folder. Three skills with similar descriptions form three pairs: a and b, a and c, b and c. The old version acted on each answer at once, and kept using the scan from before the first question, never checking that the skill to keep was still there. We answered “keep a”, “keep c”, “keep b”:
Resolving …: keeping a, quarantining b
Resolving …: keeping c, quarantining a
Resolving …: keeping b, quarantining c
- The third line says it is keeping b, but b was moved away in the first step. Three steps later, a, b and c were all in quarantine, and nothing reported an error.
No key press asked for that result.
Why the tests were green
- One test asserted that “an unrecognized key sequence swallows exactly 3 bytes”. It checked the very defect above, as if it were the correct behavior. It read like coverage of key handling; in fact it certified the bug.
- No test went past one pair. The test data could not even express more than one pair, so the most important promise, “one answer settles exactly one pair”, was never checked.
- The fallback path, which reads typed lines instead of arrow keys, had no tests at all.
The lesson went into the repository’s development rules: tests of terminal interaction must treat “nobody answered” and “someone answered something else” as two separate inputs. Testing only “answered correctly” is not testing.
How we rebuilt it
The 11 problems came down to 3 root causes, and the rebuild went after the causes, not the symptoms.
- The picker acted while it was still asking. Now it collects every answer, reconciles them, and acts once, through the same process as every other cleanup. When answers contradict each other, a keep wins, and it says so. The same three skills and the same three answers, on the current version:
keeping a: you kept it in one pair and dropped it in another, and a keep wins.
keeping b: you kept it in one pair and dropped it in another, and a keep wins.
keeping c: you kept it in one pair and dropped it in another, and a keep wins.
No side was chosen for quarantine.
- A hand-written terminal protocol. The rewrite first switched to reading whole lines: nothing is chosen until you type a number, and input that ends anywhere means stop, so typing 1 and then ending the input counts as no answer. Arrow keys came back later as a separate layer that can only produce the character a person could have typed. The cursor starts on no option, and a key sequence is read to its end before anything is done with it.
- Names went straight to the terminal. A skill’s name is chosen by whoever wrote it, and can hide line breaks and control characters that fake the cursor position. Now everything printed goes through the same cleaning function the reports use.
Every fix was checked the other way round too: put the defect back, and the matching test has to go red.
Three days earlier
Three days before that, the quarantine and undo features of clean had just been written, and an adversarial audit the same day found 10 problems. One was critical: with one extra line written into the undo record, — undo could move settings.json or the whole hooks/ folder away, put other content under rules/, and then report “restored” with exit code 0.
There was one root cause: decisions were made on the path as written, not on the path after resolving it. A single symbolic link was enough to make the written path lie. It was fixed the same day, and never made it into a release either.
Why we are writing this
The full records of both are in the public repository’s issues/ folder (020 and 013), down to which tests were wrong at the time. For a security tool that changes your files, “the tests are green” is not enough. We would like you to be able to see how we check ourselves.