assert-what-the-generator-found
Un generador que se cae te dice que falló; uno que emite salida plausible no te dice nada. Prueba lo que encontró, nunca que se ejecutó.
El resumen de arriba es una traducción. La tarjeta en sí es el original en inglés: es lo que lee el agente y lo que atestigua el hash de abajo.
Conferida por quien revisó y leyó la tarjeta, no reclamada por el propio archivo. Una tarjeta que el agente destila durante una ejecución que consumió contenido no confiable nace contaminada y queda retenida para revisión antes de ser recuperada.
Cuándo viene a la mente
- wrote a code generator
- testing a schema dump
- the output looks fine
- extracting structure from a library
Evita y Comprueba es donde suele estar el valor. Haz es la sección que todo el mundo escribe.
Disparador
You have written something that reads one representation and emits another: a schema dump, a reference extractor, a migration, a scraper, an index builder. Anything whose output nobody reads in full because there is too much of it.
It does not apply to a function returning one value you can eyeball. The risk here is specific to output that is large enough that "it looks right" is the only review it will ever get.
Haz
- Before writing the test, name the count. How many commands, rows, files, or fields should come out? Get that number from somewhere other than the generator — the source, the docs, a manual count.
- Assert the count, or a floor on it.
assert len(groups) >= 10, notassert result. - Assert the presence of specific, named items you know must exist. Three or four is enough, and pick ones from different shapes of input.
- If the generator classifies things, assert that each class is non-empty. A classifier that puts everything in one bucket is the failure this catches.
Evita
assert build() — it passes when the generator returns an empty list, a partial list, or a list
where every item is subtly the wrong kind.
Also avoid trusting isinstance when walking a third-party structure. Libraries vendor their
dependencies: a TyperGroup is not an instance of the click.Group your file imported, because
Typer ships its own copy of Click. Ask whether the object has the thing you need — a commands
mapping, an items method — rather than what class it claims to be. Duck-typing survives a
vendored dependency and a major version bump; a class check survives neither, and fails by
misclassifying rather than by raising.
Comprueba
Break the generator on purpose and watch the test fail. Comment out the recursion into subcommands, or make the type check reject everything, and run the suite.
If the suite still passes, the test asserts that the generator ran, and you have written the test that this skill exists to prevent.
Riesgo
Hard-coding an exact count makes the test a maintenance chore: every legitimately added command
turns it red. Prefer a floor (>= 10) plus named items, and reserve exact counts for things that
genuinely should not change without a decision.
There is also a limit. These assertions catch a generator that dropped a whole category. They do not catch one that gets a single field wrong on one item, and pretending otherwise is its own kind of false confidence.
Cómo usarla
La tarjeta es un dato. Clona el repositorio e impórtala por ruta: lo que llega por la red se trata como contaminado y queda retenido a la espera de aprobación, que es el comportamiento deseable y la razón por la que aquí no hay un instalador de una línea.
git clone https://github.com/brcampidelli/chimera-agent.gitchimera skills-import chimera-agent/skills/assert-what-the-generator-found/SKILL.mdIntegridad
SHA-256 del archivo tal como se publicó. Quien lo importe puede comprobar que lo que recibió es lo que mostró esta página.
c237a831782562ab7a2fc672af9a3a82ef12965dc45bcf58eddd924fab6e5f3e