/*
* Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

syntax = "proto3";

package luci.resultdb.v1;

import public "tools/tradefederation/core/proto/resultdb/common.proto";
import public "tools/tradefederation/core/proto/resultdb/test_metadata.proto";
import public "tools/tradefederation/core/proto/resultdb/test_result.proto";

option go_package = "go.chromium.org/luci/resultdb/proto/v1;resultpb";
option java_package = "com.android.resultdb.proto";
option java_multiple_files = true;

// A test verdict. The outcome of a test variant in an invocation.
// As each test variant may be attempted multiple times within an invocation,
// a test verdict can encapsulate multiple test results.
message TestVerdict {
  // The structured test variant identifier.
  TestIdentifier test_id_structured = 1;

  // The flat test id, a unique identifier of the test in a LUCI project.
  // Regex: ^[[::print::]]{1,512}$
  //
  // This is the flat-form encoding of the test component of the structured test variant ID above.
  // See TestVariantIdentifier for details how a structured test identifier is converted
  // to flat test ID.
  string test_id = 2;

  // Reserved for variant, variant_hash if we want to add these in future.
  // Currently not included as they duplicate test_id_structured.module_variant(_hash).
  reserved 3,4;

  // Status of a test verdict.
  // References to test statuses (passed, failed, skipped, execution_error, precluded) in
  // the enum descriptions refer to TestResult.Status values.
  // Values are sorted with the most interesting verdict statuses first.
  enum Status {
    STATUS_UNSPECIFIED = 0;

    // The test has failing results and no passing results.
    FAILED = 10;

    // The test has execution errored results and no
    // passing, failing or skipped results.
    EXECUTION_ERRORED = 20;

    // The test has only precluded results.
    PRECLUDED = 30;

    // The test has both passing and failing results.
    FLAKY = 40;

    // The test skipped results and no passing or
    // failing results.
    SKIPPED = 50;

    // The test has passing results and no failing results.
    PASSED = 60;
  }

  // Overrides applying to the test verdict.
  // Open to extension.
  enum StatusOverride {
    STATUS_OVERRIDE_UNSPECIFIED = 0;

    // The test verdict is not overridden.
    //
    // To confirm a test is not exonerated prefer to check it is not EXONERATED
    // rather than check it is NOT_OVERRIDDEN, as this is safe in case of
    // extensions to this enum.
    NOT_OVERRIDDEN = 1;

    // The test variant has one or more exonerations, and the
    // test verdict status was FAILED, EXECUTION_ERRORED OR PRECLUDED.
    // An exoneration absolves the subject of the invocation (e.g. CL)
    // from blame and means means the verdict is no longer blocking.
    EXONERATED = 2;

    // In future other overrides could be added here, e.g. INDICTED
    // for new tests which were not endorsed for submission due to
    // being flaky. (This could make a flaky verdict blocking.)
  }

  // The status of the test verdict, e.g. failed, flaky, skipped.
  Status status = 5;

  // The status override, e.g. exonerated.
  StatusOverride status_override = 6;

  // The test results for the test verdict.
  repeated TestResult results = 7;

  // Test exonerations.
  repeated TestExoneration exonerations = 8;

  // Information about the test at the time of its execution.
  //
  // All test results of the same test variant should report the same test
  // metadata. This RPC relies on this rule and returns test metadata from
  // *arbitrary* result of the test variant.
  TestMetadata test_metadata = 9;
}
