Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions .github/workflows/repo-eval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ jobs:
id: ${{ steps.select.outputs.id }}
tasks: ${{ steps.select.outputs.tasks }}
steps:
# Full history: `validate` resolves every task base, and `changed` diffs
# against the base branch.
# Depth 1: a guidance-only manifest needs no history. A manifest with tasks gets it in "Fetch the history" below.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
# The setup action's commit, resolved before any checkout: actions/checkout takes a branch that shares a
# tag's name, so the ref goes in as a commit. A branch is refused here, before the action's code runs.
- name: Resolve the setup action commit
Expand Down Expand Up @@ -182,6 +180,44 @@ jobs:
dokimi-ref: ${{ steps.action-ref.outputs.package-repository == steps.action-ref.outputs.action-repository && steps.action-ref.outputs.sha || steps.action-ref.outputs.ref }}
dokimi-repository: ${{ steps.action-ref.outputs.package-repository }}
python-version: '3.13'
# The manifest is read by dokimi's own loader, as `eval check` reads it, so "has tasks" means what `Select tasks` tests.
# A manifest that cannot be read keeps the shallow checkout: `eval check --schema-only` reports it.
- name: Decide whether the history is needed
id: history
env:
MANIFEST: ${{ inputs.manifest }}
run: |
python - <<'PY'
import os, subprocess

from dokimi.repos import load_manifest
from dokimi.repos.source import WorkTree

try:
tasks = load_manifest(WorkTree("."), os.environ["MANIFEST"]).tasks
except Exception as exc: # whatever is wrong with the manifest is for `eval check` to say
print(f"manifest not read ({type(exc).__name__}): keeping the shallow checkout")
tasks = None
# check=True: a git that cannot answer fails the step with its own message, not a silent "shallow"
shallow = subprocess.run(["git", "rev-parse", "--is-shallow-repository"], stdout=subprocess.PIPE, text=True, check=True).stdout.strip()
if not tasks:
print("no tasks in the manifest: no history needed")
elif shallow == "false":
print("the checkout is complete already")
else:
print("the manifest has tasks: fetching the history")
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f:
f.write("deepen=true\n")
PY
# `actions/checkout` fetches with the token and drops it (persist-credentials: false), so a later `git fetch --unshallow`
# would fail on a private repository. clean: false keeps `.dokimi-action`.
- name: Fetch the history
if: steps.history.outputs.deepen == 'true'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
clean: false
- name: eval check --schema-only
env:
MANIFEST: ${{ inputs.manifest }}
Expand Down
157 changes: 157 additions & 0 deletions dokimi/tests/test_repo_eval_validate_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""repo-eval.yml: `validate` checks out at depth 1 and fetches the history only for a manifest with tasks (#1535).

The step that decides is lifted out of the workflow and run on a manifest of each kind, as
``test_repo_eval_task_selection.py`` does for ``Select tasks``.
"""

from __future__ import annotations

import re
import shutil
import subprocess
import sys
from pathlib import Path
from typing import Any

import pytest
import yaml

WORKFLOW = Path(__file__).resolve().parents[2] / ".github" / "workflows" / "repo-eval.yml"
MANIFEST = ".agent-eval/repo-eval.yaml"
GUIDANCE_ONLY = "schema: repo_manifest.v1\nid: demo\nguidance:\n globs: [AGENTS.md]\n"
WITH_TASKS = GUIDANCE_ONLY + "eval_dir: .agent-eval\ntasks: .agent-eval/tasks\nentry_points:\n grade: ./grade.sh\n"

needs_git = pytest.mark.skipif(shutil.which("git") is None, reason="needs git")


def _steps(job: str) -> list[dict[str, Any]]:
return yaml.safe_load(WORKFLOW.read_text(encoding="utf-8"))["jobs"][job]["steps"]


def _checkouts(job: str) -> list[dict[str, Any]]:
return [s for s in _steps(job) if str(s.get("uses", "")).startswith("actions/checkout@")]


def _caller_checkouts(job: str) -> list[dict[str, Any]]:
return [s for s in _checkouts(job) if "path" not in s.get("with", {})]


def test_the_first_validate_checkout_is_shallow_and_the_second_deepens_for_a_manifest_with_tasks() -> None:
first, *rest = _caller_checkouts("validate")
assert "fetch-depth" not in first["with"]
(second,) = rest
assert second["with"]["fetch-depth"] == 0
assert second["if"] == "steps.history.outputs.deepen == 'true'"
assert second["uses"] == first["uses"]
# clean: false keeps `.dokimi-action`, the setup action's own checkout inside this workspace
assert second["with"]["clean"] is False
# the deepening is a checkout, not a `git fetch`: persist-credentials: false leaves a later fetch no token
assert second["with"]["persist-credentials"] is False
assert not any("--unshallow" in str(s.get("run", "")) for s in _steps("validate"))


def test_the_deepening_comes_after_the_setup_and_before_the_checks_that_need_the_history() -> None:
steps = _steps("validate")
names = [s.get("name") for s in steps]
order = [names.index(n) for n in ("Set up dokimi", "Decide whether the history is needed", "Fetch the history",
"eval check --schema-only", "Select tasks")]
assert order == sorted(order)


def test_tasks_check_keeps_its_full_history() -> None:
assert _caller_checkouts("tasks-check")[0]["with"]["fetch-depth"] == 0


def _decide_script() -> str:
run = next(s for s in _steps("validate") if s.get("id") == "history")["run"]
match = re.search(r"python - <<'PY'\n(.*)\nPY\s*$", run, re.S)
assert match, "the history step is no longer a python heredoc"
return match.group(1)


def _git(cwd: Path, *args: str) -> None:
subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True)


def _clone(tmp_path: Path, manifest_text: str | None, *, depth: bool = True) -> Path:
"""A clone of a two-commit repository holding the manifest; shallow unless ``depth`` is false."""
source = tmp_path / "source"
source.mkdir()
_git(source, "init", "-q", "-b", "main")
for name in ("user.email", "user.name"):
_git(source, "config", name, "t")
_git(source, "config", "commit.gpgsign", "false")
if manifest_text is not None:
(source / MANIFEST).parent.mkdir()
(source / MANIFEST).write_text(manifest_text, encoding="utf-8")
(source / "AGENTS.md").write_text("a\n", encoding="utf-8")
_git(source, "add", "-A")
_git(source, "commit", "-q", "-m", "one")
_git(source, "commit", "-q", "--allow-empty", "-m", "two")
work = tmp_path / "work"
_git(tmp_path, "clone", "-q", *(["--depth", "1"] if depth else []), source.as_uri(), str(work))
return work


def _decide(work: Path, tmp_path: Path) -> tuple[subprocess.CompletedProcess, str]:
out = tmp_path / "output"
out.write_text("", encoding="utf-8")
env = {"PATH": str(Path(shutil.which("git") or "git").parent), "MANIFEST": MANIFEST, "GITHUB_OUTPUT": str(out),
"PYTHONPATH": str(Path(__file__).resolve().parents[1])}
result = subprocess.run([sys.executable, "-c", _decide_script()], cwd=work, env=env,
capture_output=True, text=True, check=False)
return result, out.read_text(encoding="utf-8")


@needs_git
def test_a_guidance_only_manifest_fetches_nothing(tmp_path: Path) -> None:
result, written = _decide(_clone(tmp_path, GUIDANCE_ONLY), tmp_path)
assert result.returncode == 0, result.stderr
assert written == ""
assert "no history needed" in result.stdout


@needs_git
def test_a_manifest_with_tasks_deepens_a_shallow_checkout(tmp_path: Path) -> None:
result, written = _decide(_clone(tmp_path, WITH_TASKS), tmp_path)
assert result.returncode == 0, result.stderr
assert written == "deepen=true\n"


@needs_git
def test_a_complete_checkout_is_not_deepened(tmp_path: Path) -> None:
result, written = _decide(_clone(tmp_path, WITH_TASKS, depth=False), tmp_path)
assert result.returncode == 0, result.stderr
assert written == ""
assert "complete already" in result.stdout


@needs_git
def test_a_git_that_cannot_answer_fails_the_step_and_deepens_nothing(tmp_path: Path) -> None:
work = tmp_path / "plain"
(work / MANIFEST).parent.mkdir(parents=True)
(work / MANIFEST).write_text(WITH_TASKS, encoding="utf-8")
out = tmp_path / "output"
out.write_text("", encoding="utf-8")
env = {"PATH": str(Path(shutil.which("git") or "git").parent), "MANIFEST": MANIFEST, "GITHUB_OUTPUT": str(out),
"GIT_CEILING_DIRECTORIES": str(tmp_path), "PYTHONPATH": str(Path(__file__).resolve().parents[1])}
result = subprocess.run([sys.executable, "-c", _decide_script()], cwd=work, env=env,
capture_output=True, text=True, check=False)
assert result.returncode != 0
assert "CalledProcessError" in result.stderr
assert out.read_text(encoding="utf-8") == ""


@needs_git
@pytest.mark.parametrize("text", [None, "{unclosed: [\n", "- just\n- a list\n", "schema: repo_manifest.v1\n"],
ids=["missing", "not-yaml", "wrong-shape", "no-guidance"])
def test_a_manifest_that_cannot_be_read_keeps_the_shallow_checkout_without_a_traceback(
tmp_path: Path, text: str | None) -> None:
result, written = _decide(_clone(tmp_path, text), tmp_path)
assert result.returncode == 0, result.stderr
assert written == ""
assert "Traceback" not in result.stderr + result.stdout
assert "keeping the shallow checkout" in result.stdout
Loading