Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ All notable changes to SkillEvaluator are documented in this file.

### Fixed

- Retained Tier 3 baselines are invalidated when a staged file's permissions or
kind changes, including a script losing its executable bit with unchanged
contents. The updated task-tree identity requires a fresh baseline for runs
Comment thread
Afloat16 marked this conversation as resolved.
Resolved
that recorded the older digest format.
- `make lint` checks the whole repository, as CI does, instead of only `src` and `tests`, so a
lint error in `scripts/` or `ci/` no longer passes the documented local gate and then fails CI.
- Tier 2 deduplication verdict requests carry the documented output ceiling,
Expand Down
12 changes: 8 additions & 4 deletions src/skillevaluator/tier3/baseline_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
import math
import re
import stat
from collections.abc import Sequence
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -109,8 +110,8 @@ def identity_dataset_digest(task_dirs: Sequence[Path]) -> str:


def baseline_task_tree_digest(task_dirs_by_agent: dict[str, Sequence[Path]]) -> str:
"""Hash the staged without-skill task trees, normalizing arm-specific task names."""
digest = hashlib.sha256()
"""Hash staged file kinds, permissions and contents, normalizing arm-specific task names."""
digest = hashlib.sha256(b"skillevaluator-baseline-task-tree-v2\0")
Comment thread
Afloat16 marked this conversation as resolved.
Resolved
for agent, task_dirs in sorted(task_dirs_by_agent.items()):
for task_dir in sorted(task_dirs, key=lambda path: path.name):
task_name = _ARM_TASK_DIR_SUFFIX.sub("", task_dir.name)
Expand All @@ -121,9 +122,10 @@ def baseline_task_tree_digest(task_dirs_by_agent: dict[str, Sequence[Path]]) ->
relative = path.relative_to(task_dir).as_posix()
if relative == "environment/repo-context.json":
continue
if path.is_symlink():
metadata = path.lstat()
Comment thread
Afloat16 marked this conversation as resolved.
Resolved
if stat.S_ISLNK(metadata.st_mode):
content = b"symlink\0" + path.readlink().as_posix().encode("utf-8")
elif path.is_file():
elif stat.S_ISREG(metadata.st_mode):
content = path.read_bytes()
if relative == "task.toml":
content = _ARM_TASK_NAME_SUFFIX.sub(r"\1\2", content.decode("utf-8"), count=1).encode("utf-8")
Expand All @@ -132,6 +134,8 @@ def baseline_task_tree_digest(task_dirs_by_agent: dict[str, Sequence[Path]]) ->
file_header = relative.encode("utf-8")
digest.update(len(file_header).to_bytes(8, "big"))
digest.update(file_header)
digest.update(stat.S_IFMT(metadata.st_mode).to_bytes(4, "big"))
digest.update(stat.S_IMODE(metadata.st_mode).to_bytes(2, "big"))
Comment thread
Afloat16 marked this conversation as resolved.
Resolved
digest.update(len(content).to_bytes(8, "big"))
digest.update(content)
return "sha256:" + digest.hexdigest()
Expand Down
66 changes: 66 additions & 0 deletions tests/tier3/test_baseline_file_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Staged file metadata that changes execution must invalidate baseline reuse."""

import os
import subprocess
from pathlib import Path

import pytest

from skillevaluator.tier3.baseline_store import baseline_task_tree_digest, comparison_mismatches
from skillevaluator.tier3.harbor.secure_copy import copy_file_secure


@pytest.mark.skipif(os.name != "posix", reason="POSIX executable permission bits")
def test_staged_executable_permission_change_rejects_the_old_baseline(tmp_path: Path) -> None:
source = tmp_path / "authored"
source.mkdir()
script = source / "check.sh"
script.write_text("#!/bin/sh\nprintf ready", encoding="utf-8")
script.chmod(0o755)
task = tmp_path / "case-001"
staged = task / "environment" / "repo" / script.name
staged.parent.mkdir(parents=True)
copy_file_secure(script, staged, allowed_root=source)
before = baseline_task_tree_digest({"codex": [task]})
assert subprocess.run([str(staged)], capture_output=True, text=True, check=True, timeout=5).stdout == "ready"

script.chmod(0o644)
copy_file_secure(script, staged, allowed_root=source)
assert staged.read_bytes() == script.read_bytes()
with pytest.raises(PermissionError):
subprocess.run([str(staged)], capture_output=True, text=True, check=True, timeout=5)
after = baseline_task_tree_digest({"codex": [task]})
assert comparison_mismatches(
{"config": {}, "baseline_task_tree_digest": after},
{"config": {}, "baseline_task_tree_digest": before},
) == ["staged baseline task tree changed"]


@pytest.mark.skipif(os.name != "posix", reason="POSIX file modes and symlinks")
def test_regular_file_cannot_impersonate_a_symlinks_digest_payload(tmp_path: Path) -> None:
task = tmp_path / "case-001"
task.mkdir()
entry = task / "entry"
entry.write_bytes(b"symlink\0target")
entry.chmod(0o777)
regular = baseline_task_tree_digest({"codex": [task]})
entry.unlink()
entry.symlink_to("target")
assert baseline_task_tree_digest({"codex": [task]}) != regular


@pytest.mark.skipif(os.name != "posix", reason="POSIX permission bits")
def test_file_permissions_matter_but_timestamps_do_not(tmp_path: Path) -> None:
task = tmp_path / "case-001"
task.mkdir()
entry = task / "settings.json"
entry.write_text("{}", encoding="utf-8")
entry.chmod(0o644)
original = baseline_task_tree_digest({"codex": [task]})
os.utime(entry, (1_000_000_000, 1_000_000_000))
assert baseline_task_tree_digest({"codex": [task]}) == original
entry.chmod(0o444)
assert baseline_task_tree_digest({"codex": [task]}) != original
Loading