Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

confidence-gate.md 4.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Confidence Gate
  2. ## Principle
  3. When generating tests, scaffolding fixtures, classifying risk, or proposing any non-trivial test artifact, emit a confidence assessment before writing code. If confidence is below the threshold, stop and ask the user instead of generating plausible-looking output built on guesses.
  4. ## Rationale
  5. The failure mode of LLM-generated tests is rarely "refused to try" — it is "generated something plausible that passes locally and breaks silently in CI." Hallucinated selectors, invented endpoint paths, fabricated risk scores, and reverse-engineered schemas all produce code that looks correct and tests nothing real. A confidence gate makes that failure mode loud by forcing the agent to declare its evidence and its unknowns before any artifact is committed.
  6. ## Required output shape
  7. Every non-trivial test artifact proposal must include:
  8. ```
  9. Confidence: <1-10>
  10. Rationale: <one or two sentences citing concrete evidence from the repo or contract>
  11. Unknowns: <bulleted list of things the agent does not know>
  12. ```
  13. The Rationale must cite a file path, a contract document, an existing pattern, or a captured observation. Vague rationale ("based on standard patterns", "looks similar to other tests") is not evidence and forces the score down.
  14. ## Threshold rule
  15. - **Confidence ≥ 7** — proceed with generation.
  16. - **Confidence 5–6** — proceed but surface the assumptions to the user in the output so they can correct mid-flight.
  17. - **Confidence < 5** — STOP. Do not generate. Ask the user to resolve the most-blocking Unknown first.
  18. ## When to apply
  19. Apply the gate when generating or proposing:
  20. - **Selectors and page objects.** Must have explored the live application via `playwright-cli` or read existing page object patterns. Confidence < 5 if neither.
  21. - **Endpoint paths and request shapes.** Must have read the OpenAPI / Swagger contract or existing endpoint enums. Confidence < 5 if the endpoint is being invented.
  22. - **Risk classification (test-design, NFR).** Must cite probability and impact evidence. Confidence < 5 if scoring is vibes-based.
  23. - **Fixture composition.** Must understand existing `mergeTests` patterns and fixture boundaries in the repo. Confidence < 5 if composing blindly.
  24. - **Schema authoring (Zod, Ajv, JSON Schema).** Must have a documented contract source (OpenAPI, JSON schema, existing schema file). Confidence < 5 if reverse-engineering from a single sample response.
  25. - **Data factories.** Must understand the production data shape and constraints. Confidence < 5 if guessing field validity rules.
  26. ## When NOT to apply
  27. - Mechanical refactors with clear scope (rename a variable, add a tag, update an import).
  28. - Reading or summarizing existing artifacts.
  29. - Producing reports from already-gathered data.
  30. - Trivial test additions that copy an existing pattern exactly.
  31. The gate exists to prevent fabrication, not to bureaucratize obvious work.
  32. ## Anti-patterns
  33. ❌ **Vanity scores.** `Confidence: 9` with no Rationale, or Rationale that does not cite evidence. Score the evidence, not the optimism.
  34. ❌ **Listing then ignoring Unknowns.** Listing unknowns and then proceeding anyway when Confidence is below threshold. If the gate is below threshold, the only valid next action is to ask the user.
  35. ❌ **Asking generically.** Asking "should I proceed?" instead of resolving the most-blocking Unknown with a concrete one-sentence question.
  36. ❌ **Inflating to clear the bar.** Adjusting Confidence upward to avoid the stop rule. If the evidence is weak, the score is weak; resolve the evidence, not the number.
  37. ## Patterns that work
  38. ✅ **Cite the source.** "Confidence: 8 — Rationale: read `src/openapi/users.yaml` line 142-167 and existing schema at `tests/api/users.schema.ts`."
  39. ✅ **One concrete Unknown.** When below threshold, ask one specific question: "Is `POST /users/{id}/role` documented anywhere? I can't find it in the OpenAPI spec and there are no existing tests for it."
  40. ✅ **Promote evidence.** When the user answers the Unknown, the Rationale gets stronger and Confidence rises legitimately. The gate is a feedback loop, not a checkpoint.
  41. ## Related fragments
  42. - `test-quality.md` — Definition of Done for tests; the gate protects DoD compliance.
  43. - `risk-governance.md` — risk scoring discipline that informs Rationale for risk-related gates.
  44. - `probability-impact.md` — scoring scales used in risk-related Rationale.
  45. - `selector-resilience.md` — selector confidence specifically.
  46. - `playwright-cli.md` — the sanctioned exploration tool that promotes selector Confidence.