
Summary
Key points of this document
- Even if tests are green, the accuracy of automated quality assurance is not determined.
- Datafying the correctness of expected values as an authority
- Connecting the three catalogs: Requirement, Test, and Environment
Overview
For an automated correction platform, testing is not just a pass/fail judgment. It is a specification, a sensor for observing defects, evidence explaining the completion of corrections, and a condition to stop dangerous iterations. If the sensors are weak, unstable, or calibrated with incorrect expected values, AI may optimize for green results, but it cannot achieve true quality.
Even if tests are green, the accuracy of automated quality assurance is not determined.
In AI-driven defect exploration, the success of the quality gate becomes the completion condition for the campaign. However, if critical business scenarios are not tested, failures are hidden by retries, expected values are inferred from implementation code, or tests themselves are weakened simultaneously with corrections, green results do not serve as evidence of correction completion.
Increasing coverage rates does not solve this problem. An increase in executed lines is different from the verification of critical branches, permission boundaries, concurrency, and abnormal cases of requirements. To improve the accuracy of automation, it is necessary to manage not only the test results but also what evidence, in which environment, with what strength of assertion, and which requirements were verified.
Therefore, we treat tests as having four roles: specification, sensor, evidence, and stop condition. The purpose of this quality management platform is not to increase test code, but to define what tests can observe, under what conditions they are reliable, and when they cannot be used as evidence.
- Test success does not imply complete requirement coverage or the absence of unknown bugs.
- Do not use test count and Line Coverage as sole quality KPIs.
- Separate the scope that AI can correct from the scope that AI can determine expected values.
Datafying the correctness of expected values as an authority
AI can infer plausible expected behaviors from existing code, screens, and documents. However, the current implementation may not always be according to specifications. If tests generated by reading the implementation fix the same errors as expected values, a strong Regression Test that protects incorrect behavior will be completed.
We classify the basis of expected values into approved requirements, confirmed defects and expected behaviors, existing authoritative tests, provisional AI inference, and unknown basis. Tests designed by AI are initially set to provisionalaiinference, and present the basis and expected values in a Draft PR. They are not used as formal evidence for Critical Gates until human confirmation.
This classification is not to prohibit AI-generated tests. AI can widely enumerate candidates for boundary values, state transitions, and abnormal cases. The boundary is to use that capability while leaving the authority to determine business correctness to humans.
- approved_requirement: Based on approved requirements, specifications, and acceptance criteria.
- approved_regression: Based on confirmed defects and approved expected behaviors.
- existingauthoritativetest: Based on existing approved tests.
- provisionalaiinference・unknown: Do not automatically promote to critical gate.
Connecting the three catalogs: Requirement, Test, and Environment
To track evidence quality, we maintain separate Requirement Catalog, Test Catalog, and Test Environment Catalog. The Requirement catalog records importance, approval status, and acceptance criteria. The Test catalog records stable Test IDs, target requirements, level, owner, determinism, execution commands, and quality gates. The Environment catalog records time, timezone, random seed, DB isolation, external communication, and execution version.
Test IDs are stable identifiers combining target area, operation, behavior, and conditions, rather than filenames or line numbers. This is because if IDs change due to file movement or test splitting, historical flaky records, failure fingerprints, and links to Requirements would be lost.
It is not necessary to manually register all existing tests from scratch. Provisional entries are automatically generated from files, packages, and test titles, with their status set to 'discovered'. AI can suggest candidates for domain, severity, and Requirement mapping, but only tests promoted to 'approved' by humans are used as evidence in Critical Gates.
- Requirement Catalog: What is guaranteed and the basis for its approval.
- Test Catalog: Which test verifies which requirement at which gate.
- Environment Catalog: Execution conditions for reproducing the same results.
- Visualize existing debt as 'discovered' and gradually approve from critical areas.
Normalizing different test results into Canonical Test Result
Vitest, Playwright, Shell Script, Integration Test, Security Scan, Coverage, and Mutation Testing each produce results in different formats. If quality gates directly read framework-specific logs, failure classification and evidence items become inconsistent. We normalize to a common format using a Reporter or post-processing Adapter, without heavily intruding on existing Runners.
The Canonical Test Result includes run ID, commit SHA, Test ID, Requirement ID, attempt, status, duration, environment fingerprint, failure fingerprint, expected, actual, error type, sanitized stack, related files, and artifacts. Converting to this format before passing to AI allows for root cause analysis using only necessary evidence, without sending the entire log.
States are not limited to PASS and FAIL. We distinguish between reproducible failures, Flaky, Environment, Dependency Service, Timeout, Assertion, Setup, Unapproved Skip, Quarantine, and Not Run. Only FAIL_REPRODUCIBLE is generally sent for automatic correction. This prevents misclassifying environmental failures as code defects.
- FAIL_REPRODUCIBLE: The same failure reproduces under the same conditions, making it a candidate for automatic correction.
- FAIL_FLAKY: Success and failure are mixed, requiring improvement in determinism first.
- FAILENVIRONMENT / FAILDEPENDENCY: Treated as an execution environment issue, not a source code fix.
- SKIPPEDUNAPPROVED / QUARANTINED / NOTRUN: Not counted as evidence of success.
Use retries for reproducibility diagnosis, not for success conversion
If a retry in Playwright or similar tools results in a PASS (first attempt fails, second succeeds), Flaky Tests are hidden behind green gates. Retries should not be treated as a mechanism to eliminate instability, but as a diagnostic tool to check if the same failure reproduces. If success and failure are mixed, it's FAILFLAKY; if it fails multiple times with the same fingerprint, it's a FAILREPRODUCIBLE candidate.
Failure fingerprints are generated from Test ID, normalized error type, assertion message, expected, actual, main stack frame, HTTP status, DB error code, etc. Timestamps, UUIDs, temporary paths, ports, Runner IDs, request IDs, and minor line number changes are excluded to converge the same cause to the same identifier.
Environmental conditions are also saved as fingerprints. We diagnose up to several times with the same commit, same Test ID, and same environment fingerprint, and see if the same failure repeats. Reproducibility cannot be determined unless the code, environment, and cause of failure are fixed along different axes.
Manage time, random numbers, DB, and external APIs as part of the test scope.
Test flakiness doesn't just come from code. Timezone, locale, current time, random numbers, residual DB data, test file execution order, port conflicts, external APIs, Docker images, Node, browser, and CPU constraints all affect the results. We don't treat these as implicit assumptions, but record them in the Environment Catalog and result fingerprints.
For time-dependent code, use Clock injection to fix the test execution time. When using random inputs, always record the seed so that failures can be reproduced with the same seed. For DBs, break state sharing between tests using methods appropriate for the scale, such as transaction rollback, schema per test file, or database per run.
External APIs are categorized into tiers: Fake or Mock Server for Unit/Normal Integration, OpenAPI or JSON Schema for Contract, limited communication for Sandbox, and explicit approval for Production-like. AI should not be allowed to fix external service outages as application code bugs.
- Record fixed clock, timezone, locale, and random seed in the execution results.
- Isolate DB, temp directory, port, and test data per run.
- Deny external networks by default, allowing communication only for permitted tests.
- Include Node, pnpm, browser, Docker image digest, and feature flags in environmental evidence.
Don't hide Flaky Tests; quarantine them with an expiration date.
Flaky Tests are not just operational noise. They cause AI to misinterpret failure logs as source bugs, leading to meaningless fixes and retries. Detected flaky tests are deduplicated by Test ID and fingerprint, and their success/failure counts, environment, trace, estimated cause, and owner are tracked in a single Issue.
Flaky tests that cannot be fixed immediately can be quarantined, but not ignored. The quarantine reason, evidence Issue, start/end date, owner, and approver are registered, with an initial policy of a maximum 14-day expiration. Quarantined tests are still run infrequently, and if stable successes continue, they are marked as candidates for release.
Critical Tests are prohibited from automatic quarantine, and expired quarantines result in Gate failure. Tests in quarantine, even if successful, are not counted as evidence of zero bugs. Ratchet detects an increase in the number of quarantined items itself as a deterioration in quality.
Simultaneously with code fixes, check if tests have become weaker.
If AI can modify both fixes and tests simultaneously, it creates room for it to relax expectations to pass its own patch. Even unintentionally, changing assertions to partial matches, increasing retries or timeouts, broadening Mocks, or bulk updating Snapshots can create superficially successful but weak tests.
Implement a Test Change Guard that compares the PR's base and head to detect assertion deletion/reduction, skip/todo/only, retry/timeout increase, Coverage/Mutation Score threshold decrease, large Snapshot updates, Mock/network interception expansion, error ignoring, test deletion, exclude additions, and deletion of permission/abnormal case tests.
Detection results are classified into Test Change Risk from LOW to CRITICAL. Test weakening in Critical Scenarios, authentication/authorization, monetary values, and state transitions are Hard Gates, and AI-generated PRs use stricter thresholds than human PRs. HIGH or above moves Draft PRs to 'needs-human' and removes them from the automated correction loop.
- Look not just at the number of changed lines in tests, but whether the meaning of assertions has weakened.
- Detect skips only in CI or circumvention by Feature Flags.
- Calculate Test Change Risk from deterministic inspection using AST and diff, not from AI explanations.
Place Regression Tests before fixes and validate them independently.
When fixing a bug, first create a minimal regression test that reproduces the defect and confirm that it fails with the pre-fix commit. Then, apply the implementation fix and run the same test and affected regression. This is because if you write tests by only looking at the post-fix implementation, the tests tend to merely confirm the current code.
The roles of AI are also divided into Test Architect, Test Implementer, and Independent Verifier. The Architect organizes requirements, boundary values, state transitions, and authority, and does not modify the implementation code. The Implementer generates only tests from approved designs. The Verifier independently confirms the basis of expected values, mocks, flaky factors, and pre-fix failures.
If the detection capability is unknown, use negative controls or Mutation Testing. If a test does not fail after introducing an intentional small mutation into the implementation, that test is not observing important behavior even if it passes the code. It is especially important in AI-generated tests not to place the test creator and verifier in the same judgment context.
- Preserve evidence that it failed before the fix and succeeded after the fix.
- Associate Regression Tests with confirmed bugs and approved expected behavior.
- Separate Fixer, Test Implementer, and Verifier into different jobs and different prompts.
Multidimensionalize coverage and prevent it from deteriorating from its current value.
For quality visualization, we separate not only Line, Branch, and Function but also Requirement, Business Scenario, State Transition, Permission Matrix, Error Path, Contract, and Mutation Score. For example, even if Line Coverage is high, if there are no deny tests or concurrency tests, evidence for authorization or consistency is insufficient.
If you raise all existing low values to the minimum standard at once, all CI will stop at the time of introduction. We use a Ratchet that saves the current value as a Baseline and only rejects when it deteriorates in a PR. In addition to the overall rate, we measure Changed Code Coverage, and if no tests corresponding to changed lines are executed, it is treated as a Test Gap.
Mutation Testing is also not run on every repository every time. For PRs, we focus on changed functions, for nightly runs on affected packages, and for weekly runs on critical components. Surviving mutants are not linked to a massive addition of mechanical tests but are treated as prioritized Test Gaps. Mutation Score is one indicator of detection capability and not a sole pass/fail criterion.
Place the Test Evidence Gate before the zero-bug determination.
Test Quality Score is useful for humans to grasp Requirement correspondence, Critical Scenario, determinism, flakiness, assertion strength, Changed Code Coverage, Mutation, and ownership. However, if you pass the gate with only an average score, a Critical Test failure can be offset by high scores in other categories. Scores and Hard Gates should be separated.
Completion of AI bug exploration requires a Test Evidence Gate in addition to existing Quality Gates. It confirms that the execution target is in the Catalog, Critical Tests are approved, there is correspondence with Critical Requirements, there are no unisolated flaky tests or expired quarantines, Test Change Risk is within acceptable limits, and there is a Regression Test for the fixed bug.
Furthermore, it requires that Canonical Test Results and environment fingerprints are saved, the Final Gate succeeds twice with the same SHA, there are no code, test, or configuration changes in between, and success is not determined solely by provisional tests. If these are insufficient, it is not a failure or zero bugs, but rather an "insufficienttestevidence" state.
- Critical failures, unauthorized skips, and expired quarantines are not offset by scores.
- Make unknown Requirement authority, unexecuted Critical Scenarios, and insufficient reproduction confirmation into Hard Gates.
- Distinguish insufficient evidence from source bugs and return it to test design or human approval.
Even if there are zero bugs, do not reduce the execution frequency too much if the evidence is weak.
If an adaptive scheduler only looks at the number of new bugs, it will mistakenly identify a state where nothing can be detected due to weak tests as "stable." We add approved Critical Coverage, unaddressed Requirements, number of Flaky tests, expired Quarantine, Evidence Gate, number of provisional tests, and Test Change Risk to the frequency judgment.
If there are reproducible bugs, transition to ACTIVE; if there are no bugs but insufficient evidence, transition to TEST.*Transition to EVIDENCE and then IMPROVEMENT. If there are improvable Test Gaps, improve Catalog, Regression Test, and determinism at 15-45 minute intervals. If the expected value of a Critical Requirement is unknown, move it to needs-human or a test design Draft PR.*Spot Runner is not launched when there are no evidence improvement tasks. Only after passing the Test Evidence Gate does it proceed to FINAL_VERIFY for final verification of the same SHA after a period of time. We do not compensate for low test quality by launching a large number of Runners; instead, we express what evidence is needed as a state.
Introduce in three stages: Observe, Ratchet, and Enforce.
If mandatory rules are applied to existing tests from the beginning, CI will stop due to existing debt, and the quality improvement foundation itself will likely be removed. The initial value is Observe, automatically discovering tests and recording Catalog, Flaky candidates, unaddressed Requirements, and Test Change Risk. In principle, CI will not fail at this stage.
In the next Ratchet stage, the current state is set as the Baseline, and only quality degradation such as coverage reduction, increased skips, and increased Flaky/Quarantine is rejected. Even if approved Requirements and Scenario Tests are required for new Critical features, existing debt is not corrected all at once. The scope of protection is gradually expanded while accumulating improvements.
Enforce is selectively enabled from Critical areas where Catalog and ownership are established. It enforces approved Requirements, Critical Scenarios, Flaky policy, Test Change Guard, and Test Evidence Gate, and requires a Full Test Quality Gate for Releases. The mode can be switched in settings, allowing for migration component by component.
Observe: Measurement and debt visualization. Do not stop existing CI.
- Ratchet: Based on current values, prohibit only degradation.
- Enforce: Enforce from Critical areas where evidence is complete.
- Verify that this quality foundation itself does not make incorrect judgments.
Unit Tests verify Schema, test discovery, stable Test ID, result normalization, fingerprint, Flaky classification, Quarantine expiration, traceability, Coverage ratchet, Test Change Risk, Evidence Gate, and Secret redact. Specifically, it is fixed that deletion of assertions, addition of skips, increase in retries/timeouts, and bulk updates of Snapshots can be detected.
Integration Tests confirm that Playwright's post-retry success becomes FLAKY, provisional tests alone result in insufficient Evidence, automatic Quarantine of Critical Tests is rejected, Bug Fixes without Regression Tests are stopped, and tests weakened by AI are rejected by the PR Gate.
Implementation proceeds in the order of test discovery, Canonical Result, Observe report, Flaky diagnosis for 1 workspace, 1 Requirement registration, neutral Change Guard, limited Ratchet, Evidence Gate connection, and limited Enforce. Since misjudgments by the quality management foundation propagate throughout the AI correction loop, phased verification is required, similar to or even more stringent than production code.
Limitations of this design and operational considerations.
The Requirement Catalog is not a mechanism that automatically generates correctness. Unapproved requirements, expected behaviors with different interpretations across departments, and discrepancies between actual operations and old documents must be resolved by humans. Simply creating a Catalog does not improve requirement quality.
The Requirement Catalog is not a mechanism that automatically generates correctness. Unapproved requirements, expected behaviors interpreted differently across departments, and discrepancies between actual operations and outdated documents must be resolved by humans. Simply creating a Catalog does not improve requirement quality.
Test Change Guard and Mutation Testing also have false positives and false negatives. Even with the same number of assertions, the meaning can be weakened, and a survived mutant is not necessarily a critical Test Gap. Instead of mechanically rejecting all HIGH/CRITICAL findings, a design is needed to escalate to human review based on the target domain and authority.
The more detailed the canonical results and artifacts are, the easier investigation becomes, but the risk of personal information, tokens, secrets, and production data mixing into logs also increases. Common sanitizers, private GCS, retention periods, and redaction before AI transmission should be included in the same design scope as evidence preservation.
AI quality assurance is determined by the system of evidence, not by test code.
In an automated correction platform, tests become the evaluation function that AI aims for. If weak tests, flaky tests, or incorrect expectations are provided, the AI will faithfully optimize in an undesirable direction according to that evaluation function. This is why the authority of expectations, execution environment, reproducibility, requirement compliance, and change risk must be managed outside the test code.
What is important is not the number of tests added. It is which requirements were verified, with what basis, in what environment, with what strength, and whether the differences before and after the fix could be reproduced. The Test Evidence Gate is a boundary to prevent AI from declaring completion unless it can answer these questions in a machine-readable format.
The faster AI can generate implementations and tests, the more human work shifts to approving expectations and evidence. The reliability of automation is determined not by how many tests a model can write, but by whether a system can be designed where machines cannot create self-serving passing conditions.


