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
75 changes: 75 additions & 0 deletions .github/workflows/hermes-drift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
# yamllint disable rule:line-length rule:truthy
#
# Early warning that upstream hermes-agent has broken this kit's contract.
#
# This lives in its own workflow rather than as a job in test.yml for two
# reasons. test.yml triggers on push and pull_request, so a job there runs when
# *this* repository changes and never when Hermes moves -- the only event the
# lane exists to detect. And job-level `continue-on-error` renders a failed job
# green in the checks list, so even a run that fired and failed read as a pass.
#
# Nothing here is a required check, so a red run cannot block a merge. That
# keeps the non-blocking property without needing a flag that hides the result.
name: hermes-drift

on:
schedule:
# Daily. The requirement states a 24-hour worst-case detection lag, so the
# cadence is part of the contract rather than an implementation detail.
- cron: "17 6 * * *"
# Scheduled workflows are disabled after 60 days without repository activity
# on a public repo -- exactly the quiet period this alarm guards. A push
# trigger keeps it alive. It does not fully remove the risk.
push:
branches: [main]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: hermes-drift
cancel-in-progress: true

jobs:
upstream-contract:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
repository: NousResearch/hermes-agent
path: .hermes-agent-upstream
- uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
with:
python-version: "3.11"
enable-cache: true
- uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4
with:
just-version: "1.58.0"
- name: Record the upstream revision under test
id: upstream
run: |
rev="$(git -C .hermes-agent-upstream rev-parse HEAD)"
echo "revision=$rev" >> "$GITHUB_OUTPUT"
- name: Run the contract suite against upstream
id: contract
env:
HERMES_AGENT_PATH: ${{ github.workspace }}/.hermes-agent-upstream
run: |
just test-contract-upstream > contract.log 2>&1
echo "EXIT=$?" >> contract.log
continue-on-error: true
# `outcome` is the result before continue-on-error is applied;
# `conclusion` is after. Keying on outcome is what makes this step see a
# failure at all. Without a run-after-failure condition the reporting
# step would be skipped by the very failure it exists to report.
- name: Classify and report drift
if: always()
run: |
uv run python scripts/classify_drift.py contract.log "${{ steps.upstream.outputs.revision }}" \
| tee -a "$GITHUB_STEP_SUMMARY"
new_drift=${PIPESTATUS[0]}
tail -40 contract.log >> "$GITHUB_STEP_SUMMARY" || true
exit "$new_drift"
41 changes: 12 additions & 29 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ jobs:

# Amber admission gates on the exact deployed Hermes fork contract. Keep the
# immutable revision aligned with infra's candidate image/source receipt.
hermes-deployed-context-engine-contract:
# Amber admission gates on the exact deployed Hermes fork contract. The pin
# below is test-enforced against hermes_plugin_kit.testing's constant; the
# workflow cannot read that constant, because actions/checkout consumes the
# ref before setup-uv installs Python.
hermes-deployed-contract:
runs-on: ubuntu-latest
env:
DEPLOYED_HERMES_REVISION: f80f453ae0679347e38abc917c7f94f717bf96c5
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
Expand All @@ -63,35 +69,12 @@ jobs:
- uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4
with:
just-version: "1.58.0"
- name: Run context-engine contract against deployed Hermes revision
# The full suite, not the context-engine module alone. It is green at
# this pin, so widening adds coverage rather than risk.
- name: Run the full contract suite against the deployed Hermes revision
env:
HERMES_AGENT_PATH: ${{ github.workspace }}/.hermes-agent-deployed
run: |
test "$(git -C "$HERMES_AGENT_PATH" rev-parse HEAD)" = \
"f80f453ae0679347e38abc917c7f94f717bf96c5"
just test-context-engine-contract

# Track forward drift against upstream main without making Amber depend on
# APIs that are newer than its exact deployed host.
hermes-contract:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
repository: NousResearch/hermes-agent
path: .hermes-agent
- uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
with:
python-version: "3.11"
enable-cache: true
- uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4
with:
just-version: "1.58.0"
- name: Run hermes contract tests against upstream main
env:
HERMES_AGENT_PATH: ${{ github.workspace }}/.hermes-agent
run: |
git -C "$HERMES_AGENT_PATH" rev-parse HEAD
just test-contract
"$DEPLOYED_HERMES_REVISION"
just test-contract-pinned
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ dist/
.venv/
.eggs/
.hermes-agent/
.hermes-agent-pinned/
.hermes-agent-upstream/
.DS_Store
34 changes: 32 additions & 2 deletions hermes_plugin_kit/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
import inspect
import os
import subprocess
import tempfile
import sys
from pathlib import Path
from dataclasses import dataclass, field
from types import SimpleNamespace
from typing import Any, Callable, Iterable, Mapping, Sequence

__all__ = [
"CACHE_DIR_ENV",
"DEPLOYED_HERMES_REVISION",
"RECEIPT_FIELD_ORDER",
"CheckResult",
Expand Down Expand Up @@ -688,6 +690,34 @@ def resolve_hermes_checkout(
return ResolvedHost(cache, head, f"fetched {revision}")


#: Overrides where a fetched checkout is cached. Set this in any environment
#: where the defaults below are wrong or unwritable -- a container with no home
#: directory, a read-only image, a CI runner with its own cache mount.
CACHE_DIR_ENV = "HERMES_PLUGIN_KIT_CACHE"


def _default_cache_dir() -> Path:
base = os.environ.get("XDG_CACHE_HOME") or (Path.home() / ".cache")
return Path(base) / "hermes-plugin-kit" / "hermes-agent"
"""Where to cache a fetched checkout, without assuming an OS or a layout.

An explicit override wins, then each platform's own convention, then a
temp directory. The last step matters: a home directory is not guaranteed
to exist or be writable in a container, and a library that assumed one
would fail there for a reason the caller cannot act on.
"""
override = (os.environ.get(CACHE_DIR_ENV) or "").strip()
if override:
return Path(override)

for variable in ("XDG_CACHE_HOME", "LOCALAPPDATA"):
base = (os.environ.get(variable) or "").strip()
if base:
return Path(base) / "hermes-plugin-kit" / "hermes-agent"

try:
home = Path.home()
except (RuntimeError, OSError): # no resolvable home, e.g. a bare container
home = None
if home is not None and os.access(home, os.W_OK):
return home / ".cache" / "hermes-plugin-kit" / "hermes-agent"

return Path(tempfile.gettempdir()) / "hermes-plugin-kit" / "hermes-agent"
94 changes: 77 additions & 17 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ uv := env_var_or_default("UV", "uv")
openspec := env_var_or_default("OPENSPEC", "openspec")
openspec_min := "1.13.1"
hermes_agent_repo := env_var_or_default("HERMES_AGENT_REPO", "https://github.com/NousResearch/hermes-agent.git")
hermes_agent_dir := env_var_or_default("HERMES_AGENT_DIR", ".hermes-agent")
hermes_pinned_dir := env_var_or_default("HERMES_PINNED_DIR", ".hermes-agent-pinned")
hermes_upstream_dir := env_var_or_default("HERMES_UPSTREAM_DIR", ".hermes-agent-upstream")

# Show available recipes.
default:
Expand Down Expand Up @@ -37,32 +38,91 @@ release-attach-trigger:
test "$(git branch --show-current)" = "main"
test "$(git rev-parse HEAD)" = "$EXPECTED_SHA"

# Prepare a local Hermes checkout unless the caller supplied one.
# Check out hermes-agent at a given ref, in a directory of its own.
#
# Each ref gets its own directory. Sharing one meant a pinned checkout left a
# detached HEAD behind, and the next upstream run's `pull --ff-only || true`
# swallowed the resulting error -- so it silently re-tested the pin while
# reporting upstream.
[private]
prepare-hermes-agent:
prepare-hermes-ref ref dir:
#!/usr/bin/env bash
set -euo pipefail
if [[ -n "${HERMES_AGENT_PATH:-}" ]]; then
exit 0
elif [[ -d "{{ hermes_agent_dir }}/.git" ]]; then
echo "Updating {{ hermes_agent_dir }}"
git -C "{{ hermes_agent_dir }}" pull --ff-only -q || true
if [[ -d "{{ dir }}/.git" ]]; then
git -C "{{ dir }}" fetch -q --depth 1 origin "{{ ref }}"
else
echo "Cloning hermes-agent into {{ hermes_agent_dir }}"
git clone --depth 1 "{{ hermes_agent_repo }}" "{{ hermes_agent_dir }}"
echo "Cloning hermes-agent into {{ dir }}"
git init -q "{{ dir }}"
git -C "{{ dir }}" remote add origin "{{ hermes_agent_repo }}"
git -C "{{ dir }}" fetch -q --depth 1 origin "{{ ref }}"
fi
git -C "{{ dir }}" checkout -q FETCH_HEAD
echo "hermes-agent at $(git -C "{{ dir }}" rev-parse HEAD)"

# Run contract tests against an existing or locally managed Hermes checkout.
test-contract: prepare-hermes-agent
# Run the full contract suite against the deployed pin.
#
# HERMES_EXPECTED_REVISION makes the lane refuse a checkout at any other
# revision, so a stale HERMES_AGENT_PATH cannot receipt the wrong host.
test-contract-pinned:
#!/usr/bin/env bash
set -euo pipefail
hermes_path="${HERMES_AGENT_PATH:-{{ hermes_agent_dir }}}"
HERMES_AGENT_PATH="$(cd "$hermes_path" && pwd)" \
{{ uv }} run python -m unittest tests.test_hermes_contract -v
pin="$({{ uv }} run python -c 'from hermes_plugin_kit.testing import DEPLOYED_HERMES_REVISION as r; print(r)')"
dir="${HERMES_AGENT_PATH:-{{ hermes_pinned_dir }}}"
if [[ -z "${HERMES_AGENT_PATH:-}" ]]; then
just prepare-hermes-ref "$pin" "{{ hermes_pinned_dir }}"
fi
HERMES_CONTRACT_REQUIRED=1 HERMES_EXPECTED_REVISION="$pin" \
HERMES_AGENT_PATH="$(cd "$dir" && pwd)" \
just _run-contract-suite "pinned $pin"

# Run the context-engine contract against HERMES_AGENT_PATH.
# Run the full contract suite against upstream main -- the drift lane.
test-contract-upstream:
#!/usr/bin/env bash
set -euo pipefail
dir="${HERMES_AGENT_PATH:-{{ hermes_upstream_dir }}}"
if [[ -z "${HERMES_AGENT_PATH:-}" ]]; then
just prepare-hermes-ref main "{{ hermes_upstream_dir }}"
fi
rev="$(git -C "$dir" rev-parse HEAD)"
HERMES_CONTRACT_REQUIRED=1 HERMES_AGENT_PATH="$(cd "$dir" && pwd)" \
just _run-contract-suite "upstream $rev"

# Backwards-compatible alias for the upstream lane.
test-contract: test-contract-upstream

# Run both contract modules and prove the run actually executed checks.
#
# The exit status alone cannot say whether anything ran: on Python 3.11 --
# the version CI pins -- unittest exits 0 both when every test skips and when
# zero tests are collected. So the executed count is the evidence.
[private]
_run-contract-suite label:
#!/usr/bin/env bash
set -euo pipefail
log="$(mktemp)"
trap 'rm -f "$log"' EXIT
set +e
{{ uv }} run python -m unittest tests.test_hermes_contract tests.test_context_engine_contract -v \
> "$log" 2>&1
echo "EXIT=$?" >> "$log"
set -e
tail -25 "$log"
grep -qE '^EXIT=0' "$log" || { echo "contract suite failed ({{ label }})" >&2; exit 1; }
ran="$(grep -oE '^Ran [0-9]+' "$log" | grep -oE '[0-9]+' | head -n1)"
test -n "$ran" && [ "$ran" -gt 0 ] \
|| { echo "no contract tests ran ({{ label }}); a lane that checked nothing is not a lane that passed" >&2; exit 1; }
if grep -qE 'OK \(skipped=' "$log"; then
echo "contract suite skipped tests ({{ label }}); expected a host for every case" >&2
exit 1
fi
echo "contract receipt: {{ label }}; executed=$ran"

# Run the context-engine contract. Requires an explicit checkout.
test-context-engine-contract:
{{ uv }} run python -m unittest tests.test_context_engine_contract -v
#!/usr/bin/env bash
set -euo pipefail
: "${HERMES_AGENT_PATH:?set it to a hermes-agent checkout; this lane does not guess}"
HERMES_CONTRACT_REQUIRED=1 {{ uv }} run python -m unittest tests.test_context_engine_contract -v

# Refuse to run when the installed OpenSpec predates the archive-correctness fixes.
[private]
Expand Down
Loading
Loading