clean

Correct code carrying no defects. Measures precision: the pass condition is zero comments, and a reviewer that flags anything here fails.

Correct code with nothing wrong in it. It counts false positives: comments on code that needs none. The pass condition is strict: zero comments. A reviewer that flags everything would catch every defect in the other corpora and still be useless. This corpus is what exposes it, which is why every run includes it.

Running it

Nothing here is ever merged. Open a throwaway pull request on a pilot repository already onboarded for this stack, adding this directory and seeded/clean together, wait for the automated review to finish, then score it.

seed-canary.yml does exactly this on a schedule and closes the pull request afterwards, including when the run fails.

terminal
$ GH_TOKEN=... npx redlinegate metrics score-seeds --repo <org>/<repo> --pr <n>

Flags and output are on redline metrics.

Scoring

Zero review comments. Any comment on this corpus is a false positive and fails the canary run outright — there is no threshold to tune, because a reviewer allowed a few false positives on known-correct code cannot be trusted to be quiet on real code.

Adding a defect

Add the code and one marker line above it. The format, and what scripts/validate.mjs checks, are on Seeded corpus.

The full file

seeded/clean/CleanComponent.tsx · 61 lines · 2.0 KB
// Redline precision corpus. This file is deliberately CORRECT.
// Any review comment on it is a false positive. Zero findings is a pass.
//
// It is written to bait the common nitpick failures: unmemoised values, "missing" error
// handling on internal calls, direct index access, an effect that is genuinely necessary.
import { useCallback, useEffect, useRef, useState } from 'react';
import { useQuery } from '@tanstack/react-query';

type Plan = { id: string; label: string; priceMinor: number };

const formatter = new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'GBP' });

async function fetchPlans(signal: AbortSignal): Promise<Plan[]> {
  const res = await fetch('/api/plans', { signal });
  if (!res.ok) throw new Error(`plans: ${res.status}`);
  return res.json();
}

export function PlanPicker({ onSelect }: { onSelect: (plan: Plan) => void }) {
  const [selectedId, setSelectedId] = useState<string | null>(null);
  const listRef = useRef<HTMLUListElement>(null);

  const { data: plans, error } = useQuery({
    queryKey: ['plans'],
    queryFn: ({ signal }) => fetchPlans(signal),
  });

  // Derived during render, not synced through an effect.
  const selected = plans?.find((plan) => plan.id === selectedId) ?? null;

  // A real external-system effect: focus is not derivable from render output.
  useEffect(() => {
    if (!selected) return;
    listRef.current?.focus();
  }, [selected]);

  const handleSelect = useCallback(
    (plan: Plan) => {
      setSelectedId(plan.id);
      onSelect(plan);
    },
    [onSelect]
  );

  if (error) return <p role="alert">Plans are unavailable right now.</p>;
  if (!plans) return <p>Loading plans…</p>;

  return (
    <ul ref={listRef} tabIndex={-1}>
      {plans.map((plan) => (
        <li key={plan.id}>
          <button type="button" onClick={() => handleSelect(plan)}>
            {plan.label} — {formatter.format(plan.priceMinor / 100)}
          </button>
        </li>
      ))}
      {plans.length === 0 ? <li>No plans available.</li> : null}
    </ul>
  );
}
seeded/clean/clean_handler.go · 82 lines · 2.1 KB
// Redline precision corpus. This file is deliberately CORRECT.
// Any review comment on it is a false positive. Zero findings is a pass.
package clean

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"net/http"
	"time"
)

var errUpstream = errors.New("upstream unavailable")

type Client struct {
	http *http.Client
	base string
}

func NewClient(base string) *Client {
	return &Client{
		http: &http.Client{Timeout: 3 * time.Second},
		base: base,
	}
}

type Balance struct {
	AccountID string `json:"accountId"`
	Minor     int64  `json:"minor"`
}

func (c *Client) Balance(ctx context.Context, accountID string) (Balance, error) {
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.base+"/balance/"+accountID, nil)
	if err != nil {
		return Balance{}, fmt.Errorf("build balance request: %w", err)
	}

	resp, err := c.http.Do(req)
	if err != nil {
		return Balance{}, fmt.Errorf("call balance: %w", err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		return Balance{}, fmt.Errorf("balance status %d: %w", resp.StatusCode, errUpstream)
	}

	var balance Balance
	if err := json.NewDecoder(resp.Body).Decode(&balance); err != nil {
		return Balance{}, fmt.Errorf("decode balance: %w", err)
	}
	return balance, nil
}

// Handler is the HTTP boundary: it validates input and maps errors to statuses. The
// internal call above is trusted to return a typed error, so there is no second layer
// of defensive checking here.
func (c *Client) Handler(w http.ResponseWriter, r *http.Request) {
	accountID := r.URL.Query().Get("accountId")
	if accountID == "" {
		http.Error(w, "accountId is required", http.StatusBadRequest)
		return
	}

	balance, err := c.Balance(r.Context(), accountID)
	if errors.Is(err, errUpstream) {
		http.Error(w, "upstream unavailable", http.StatusBadGateway)
		return
	}
	if err != nil {
		http.Error(w, "internal error", http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	if err := json.NewEncoder(w).Encode(balance); err != nil {
		// The response is already partially written; there is nothing left to signal.
		return
	}
}