From a6dfa644aac07f4bf679e4c6c025f779c5a308ac Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 2 Dec 2026 18:10:40 +0000 Subject: [PATCH 1/2] fix(ci): validate checks out at depth 1 and fetches history only for a manifest with tasks (#1535) The validate job of repo-eval.yml checked the caller out with fetch-depth: 0 for every manifest, but a guidance-only manifest (no tasks) needs no history: Select tasks exits before its git diff and eval check --schema-only has no task base to open. The first checkout is now depth 1. A new step, after Set up dokimi, reads the manifest with dokimi's own load_manifest (the loader behind eval check --manifest, so "has tasks" is the test Select tasks applies to the manifest's tasks key) and asks for the history only when tasks is set and the checkout is still shallow (git rev-parse --is-shallow-repository). A manifest that cannot be read keeps the shallow checkout and eval check --schema-only reports it as before. The history comes from a second actions/checkout with fetch-depth: 0, not from git fetch --unshallow: the checkouts use persist-credentials: false, which removes the token once the checkout step ends, so a later git fetch has no credentials on a private caller repository. The second checkout has clean: false so it does not delete .dokimi-action, and is pinned to the same SHA as the others. The tasks-check and scan jobs are unchanged. Signed-off-by: Anton Volkov --- .github/workflows/repo-eval.yml | 41 ++++- .../tests/test_repo_eval_validate_history.py | 141 ++++++++++++++++++ 2 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 dokimi/tests/test_repo_eval_validate_history.py diff --git a/.github/workflows/repo-eval.yml b/.github/workflows/repo-eval.yml index d747a2543..45303a3d6 100644 --- a/.github/workflows/repo-eval.yml +++ b/.github/workflows/repo-eval.yml @@ -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 @@ -182,6 +180,43 @@ 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 + shallow = subprocess.run(["git", "rev-parse", "--is-shallow-repository"], capture_output=True, text=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 }} diff --git a/dokimi/tests/test_repo_eval_validate_history.py b/dokimi/tests/test_repo_eval_validate_history.py new file mode 100644 index 000000000..b00e4b94c --- /dev/null +++ b/dokimi/tests/test_repo_eval_validate_history.py @@ -0,0 +1,141 @@ +# 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 +@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 From 4eae9dc0c4fb3c296dae77331bba98fccea9359d Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 2 Dec 2026 19:21:20 +0000 Subject: [PATCH 2/2] fix(ci): the history decision step fails when git cannot say whether the checkout is shallow Settles the review point that the `git rev-parse --is-shallow-repository` call of "Decide whether the history is needed" ignored its exit status, so a git that failed read as a shallow checkout and the step went on to deepen it. The call now uses check=True, and the step fails with git's own message. Signed-off-by: Anton Volkov --- .github/workflows/repo-eval.yml | 3 ++- dokimi/tests/test_repo_eval_validate_history.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/repo-eval.yml b/.github/workflows/repo-eval.yml index 45303a3d6..c9697594b 100644 --- a/.github/workflows/repo-eval.yml +++ b/.github/workflows/repo-eval.yml @@ -198,7 +198,8 @@ jobs: 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 - shallow = subprocess.run(["git", "rev-parse", "--is-shallow-repository"], capture_output=True, text=True).stdout.strip() + # 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": diff --git a/dokimi/tests/test_repo_eval_validate_history.py b/dokimi/tests/test_repo_eval_validate_history.py index b00e4b94c..d3c8b1b0a 100644 --- a/dokimi/tests/test_repo_eval_validate_history.py +++ b/dokimi/tests/test_repo_eval_validate_history.py @@ -129,6 +129,22 @@ def test_a_complete_checkout_is_not_deepened(tmp_path: Path) -> None: 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"])