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
67 changes: 59 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ jobs:
echo "::notice::No release due for this channel."
fi

build:
validate:
needs: plan
if: needs.plan.outputs.release == 'true'
runs-on: ubuntu-latest
timeout-minutes: 25
timeout-minutes: 60
env:
RELEASE_TAG: ${{ needs.plan.outputs.tag }}
RELEASE_COMMIT: ${{ needs.plan.outputs.commit }}
Expand All @@ -109,46 +109,97 @@ jobs:
git tag "$RELEASE_TAG" "$RELEASE_COMMIT"
- name: Run CPU checks before release
run: |
python -m pip install -e ".[dev]" build twine
python -m pip install -e ".[dev]"
ruff check src tests tools plugins/workswarm
pytest
test -z "$(git status --porcelain)"

build:
needs: [plan, validate]
if: needs.plan.outputs.release == 'true' && needs.validate.result == 'success'
runs-on: ubuntu-latest
timeout-minutes: 25
env:
RELEASE_TAG: ${{ needs.plan.outputs.tag }}
RELEASE_COMMIT: ${{ needs.plan.outputs.commit }}
# Multiple reserved tags can share a commit after failed publication.
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_INFERRSI: ${{ needs.plan.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.plan.outputs.commit }}
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Validate source and create the local version tag
shell: bash
run: |
[[ "$(git rev-parse HEAD)" == "$RELEASE_COMMIT" ]]
git tag "$RELEASE_TAG" "$RELEASE_COMMIT"
- name: Install release build dependencies
run: python -m pip install -e ".[skills]" build twine
- name: Prepare the exact release source and Knowledge generation
id: stage
shell: bash
run: |
python tools/stage_release_knowledge.py --commit "$RELEASE_COMMIT" \
--destination "$RUNNER_TEMP/release-source" >> "$GITHUB_OUTPUT"
test -z "$(git status --porcelain)"
- name: Build and check distributables
env:
RELEASE_SOURCE: ${{ steps.stage.outputs.source }}
shell: bash
run: |
python -m build --outdir "$RUNNER_TEMP/release-dist"
python -m build "$RELEASE_SOURCE" --outdir "$RUNNER_TEMP/release-dist"
python -m twine check "$RUNNER_TEMP"/release-dist/*.whl "$RUNNER_TEMP"/release-dist/*.tar.gz
python tools/check_release.py sdist "$RUNNER_TEMP"/release-dist/*.tar.gz
test -z "$(git status --porcelain)"
- name: Check a clean wheel installation outside the checkout
env:
EXPECTED_GENERATION: ${{ steps.stage.outputs.generation }}
RELEASE_SOURCE: ${{ steps.stage.outputs.source }}
shell: bash
run: |
python -m venv "$RUNNER_TEMP/wheel-env"
wheels=("$RUNNER_TEMP"/release-dist/*.whl)
"$RUNNER_TEMP/wheel-env/bin/python" -m pip install "${wheels[0]}[skills]"
cp tests/repository/check_installed.py tools/check_release.py "$RUNNER_TEMP/"
cd "$RUNNER_TEMP"
env -u PYTHONPATH INFERRSI_CHECKOUT_RESOURCES="$GITHUB_WORKSPACE/src/inferrsi" INFERRSI_SESSION_LOCK_PROBE="$GITHUB_WORKSPACE/tests/harness/session_lock_probe.py" INFERRSI_PRE_CHANGE_SESSIONS="$GITHUB_WORKSPACE/tests/fixtures/optimization-session" "$RUNNER_TEMP/wheel-env/bin/python" -I check_installed.py
options=()
if [[ -n "$EXPECTED_GENERATION" ]]; then options+=(--atomic-generation "$EXPECTED_GENERATION"); fi
env -u PYTHONPATH \
INFERRSI_CHECKOUT_RESOURCES="$RELEASE_SOURCE/src/inferrsi" \
INFERRSI_SESSION_LOCK_PROBE="$GITHUB_WORKSPACE/tests/harness/session_lock_probe.py" \
INFERRSI_PRE_CHANGE_SESSIONS="$GITHUB_WORKSPACE/tests/fixtures/optimization-session" \
"$RUNNER_TEMP/wheel-env/bin/python" -I check_installed.py "${options[@]}"
env -u PYTHONPATH "$RUNNER_TEMP/wheel-env/bin/python" -I check_release.py \
installed --tag "$RELEASE_TAG"
- name: Build and validate the installable host plugin ZIPs
env:
RELEASE_SOURCE: ${{ steps.stage.outputs.source }}
EXPECTED_GENERATION: ${{ steps.stage.outputs.generation }}
shell: bash
run: |
for host in codex workswarm; do
python "tools/build_${host}_plugin.py" \
python "$RELEASE_SOURCE/tools/build_${host}_plugin.py" \
--output "$RUNNER_TEMP/plugin-build/inferrsi-$host-plugin-$RELEASE_TAG" \
--release-version "${RELEASE_TAG#v}"
cp "$RUNNER_TEMP/plugin-build/inferrsi-$host-plugin-$RELEASE_TAG.zip" "$RUNNER_TEMP/release-dist/"
python tools/check_release.py plugin \
"$RUNNER_TEMP/release-dist/inferrsi-$host-plugin-$RELEASE_TAG.zip" \
--tag "$RELEASE_TAG" --host "$host"
done
options=()
if [[ -n "$EXPECTED_GENERATION" ]]; then options+=(--expected-generation "$EXPECTED_GENERATION"); fi
"$RUNNER_TEMP/wheel-env/bin/python" -I tools/check_release.py generation \
--source src/inferrsi/_atomic \
--source "$RELEASE_SOURCE/src/inferrsi/_atomic" \
--sdist "$RUNNER_TEMP"/release-dist/*.tar.gz \
--wheel "$RUNNER_TEMP"/release-dist/*.whl \
--codex "$RUNNER_TEMP/release-dist/inferrsi-codex-plugin-$RELEASE_TAG.zip" \
--workswarm "$RUNNER_TEMP/release-dist/inferrsi-workswarm-plugin-$RELEASE_TAG.zip"
--workswarm "$RUNNER_TEMP/release-dist/inferrsi-workswarm-plugin-$RELEASE_TAG.zip" \
"${options[@]}"
test -z "$(git status --porcelain)"
- name: Generate checksums
working-directory: ${{ runner.temp }}/release-dist
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespaces = false

[tool.setuptools.package-data]
inferrsi = [
"_release_intake_generation.txt",
"apps/views/*.html",
"apps/cli/task-input/v1/*.json",
"apps/cli/task-input/v1/*.yaml",
Expand Down Expand Up @@ -52,6 +53,8 @@ tag_regex = '^v(?P<version>[0-9]+\.[0-9]+\.[0-9]+)$'
[tool.inferrsi.release]
initial_version = "0.1.0"
prerelease = true
# Cutover sets knowledge_mode = "atomic" and names a reviewed tracked knowledge_grant.
# The grant pins the exact generation, every Bundle revision and the publication operations.

[project.optional-dependencies]
# PyYAML is a core dependency; the skills extra stays as a compatibility alias.
Expand Down
24 changes: 20 additions & 4 deletions src/inferrsi/apps/cli/atomic_knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
from pathlib import Path, PurePosixPath

from ...knowledge.atomic_composition import select_routes
from ...knowledge.atomic_generation import SEAL, InstalledGeneration, digest, filesystem_root
from ...knowledge.atomic_generation import (
RELEASE_INTAKE_PIN,
SEAL,
InstalledGeneration,
digest,
filesystem_root,
owned_path,
)
from ...knowledge.atomic_reader import AtomicReader, GroupDelivery
from ...knowledge.catalog import _skill_search_source
from ...knowledge.decision_cards import DecisionSource
Expand All @@ -38,14 +45,23 @@ def __init__(self, installed: InstalledGeneration) -> None:
self.findings = InstalledFindings(installed, self.reader)

@classmethod
def installed(cls) -> AtomicKnowledgeCLI | None:
def installed(cls, *, for_intake: bool = False) -> AtomicKnowledgeCLI | None:
expected = os.environ.get(GENERATION_SELECTOR)
package = Path(__file__).resolve().parents[2]
if expected is None and for_intake:
marker = owned_path(filesystem_root(package), RELEASE_INTAKE_PIN)
try:
data = marker.read_bytes()
except FileNotFoundError:
return None
if not re.fullmatch(rb"sha256:[0-9a-f]{64}\n", data):
raise ValueError("Invalid release Intake generation pin")
expected = data[:-1].decode("ascii")
if expected is None:
return None
if not re.fullmatch(r"sha256:[0-9a-f]{64}", expected):
raise ValueError(f"{GENERATION_SELECTOR} requires a full SHA-256 generation")
root = Path(__file__).resolve().parents[2] / "_atomic"
return cls(InstalledGeneration(root, expected=expected))
return cls(InstalledGeneration(package / "_atomic", expected=expected))

@classmethod
def bundled(cls, seal_sha256: str) -> AtomicKnowledgeCLI:
Expand Down
2 changes: 1 addition & 1 deletion src/inferrsi/apps/cli/task_intake.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _sealed_spec(task: str, atomic: AtomicKnowledgeCLI) -> dict:

def load_spec(task: str) -> dict:
try:
atomic = AtomicKnowledgeCLI.installed()
atomic = AtomicKnowledgeCLI.installed(for_intake=True)
except (KeyError, OSError, ValueError) as exc:
raise intake.IntakeError("unavailable_generation", str(exc)) from exc
if atomic is not None:
Expand Down
1 change: 1 addition & 0 deletions src/inferrsi/knowledge/atomic_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"task-derived-engine", "task-independent-engine",
})
SEAL = "knowledge/generation.json"
RELEASE_INTAKE_PIN = "_release_intake_generation.txt"
FORMAT = 2


Expand Down
115 changes: 110 additions & 5 deletions tests/knowledge/test_atomic_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@

import pytest

from inferrsi.apps.cli import atomic_knowledge, task_intake
from inferrsi.apps.cli.intake_contract import IntakeError
from inferrsi.knowledge.atomic_build import build_generation
from inferrsi.knowledge.atomic_generation import PUBLIC_TASKS, SEAL, InstalledGeneration, digest
from inferrsi.knowledge.atomic_generation import (
PUBLIC_TASKS,
RELEASE_INTAKE_PIN,
SEAL,
InstalledGeneration,
digest,
)
from inferrsi.knowledge.atomic_reader import AtomicReader, AtomPin, AtomUse
from inferrsi.knowledge.knowledge_operations import Bundle, UnavailableRevision, _json
from tests.fixtures.atomic_composition import composition, metadata, node
Expand Down Expand Up @@ -278,12 +286,83 @@ def write_zip(archive, prefix, payload):
for name, data in payload.items():
output.writestr(prefix + name, data)

write_zip(wheel, "inferrsi/_atomic/", files)
write_zip(codex, "inferrsi/runtime/inferrsi/_atomic/", files)
payload = {"_atomic/" + name: data for name, data in files.items()}
write_zip(wheel, "inferrsi/", payload)
write_zip(codex, "inferrsi/runtime/inferrsi/", payload)
inner = io.BytesIO()
write_zip(inner, "inferrsi/_atomic/", files)
write_zip(inner, "inferrsi/", payload)
write_zip(workswarm, "inferrsi/runtime/", {"payload.zip": inner.getvalue()})
assert check_generation(staged, sdist, wheel, codex, workswarm) == expected
artifacts = (sdist, wheel, codex, workswarm)
assert check_generation(staged, *artifacts) == expected
with pytest.raises(ValueError, match="Release Intake pin differs"):
check_generation(staged, *artifacts, expected_generation=expected)

pin = (expected + "\n").encode("ascii")
(source / RELEASE_INTAKE_PIN).write_bytes(pin)
bundle_runtime(
source, runtime, plugin_version="test", runtime_version="test", include_generation=True,
)
assert (runtime / "inferrsi" / RELEASE_INTAKE_PIN).read_bytes() == pin
stock_runtime = tmp_path / "stock-runtime"
bundle_runtime(source, stock_runtime, plugin_version="test", runtime_version="test")
assert not (stock_runtime / "inferrsi" / RELEASE_INTAKE_PIN).exists()
with pytest.raises(ValueError, match="Unexpected release Intake generation pin"):
check_generation(staged, *artifacts)
payload[RELEASE_INTAKE_PIN] = pin
with tarfile.open(sdist, "w:gz") as archive:
for name, data in payload.items():
member = tarfile.TarInfo(f"inferrsi-test/src/inferrsi/{name}")
member.size = len(data)
archive.addfile(member, io.BytesIO(data))
with pytest.raises(ValueError, match="Wheel differs"):
check_generation(staged, *artifacts, expected_generation=expected)
misplaced = payload.copy()
misplaced.pop(RELEASE_INTAKE_PIN)
misplaced[f"_atomic/{RELEASE_INTAKE_PIN}"] = pin
write_zip(wheel, "inferrsi/", misplaced)
with pytest.raises(ValueError, match="Wheel differs"):
check_generation(staged, *artifacts, expected_generation=expected)
write_zip(wheel, "inferrsi/", payload)
with pytest.raises(ValueError, match="Codex ZIP differs"):
check_generation(staged, *artifacts, expected_generation=expected)
write_zip(codex, "inferrsi/runtime/inferrsi/", payload)
inner = io.BytesIO()
write_zip(inner, "inferrsi/", payload | {RELEASE_INTAKE_PIN: b"incorrect\n"})
write_zip(workswarm, "inferrsi/runtime/", {"payload.zip": inner.getvalue()})
with pytest.raises(ValueError, match="WorkSwarm ZIP differs"):
check_generation(staged, *artifacts, expected_generation=expected)
inner = io.BytesIO()
write_zip(inner, "inferrsi/", payload)
write_zip(workswarm, "inferrsi/runtime/", {"payload.zip": inner.getvalue()})
assert check_generation(staged, *artifacts, expected_generation=expected) == expected
check_installed_generation(staged, expected)
(source / RELEASE_INTAKE_PIN).unlink()
with pytest.raises(ValueError, match="Release Intake pin differs"):
check_installed_generation(staged, expected)
check_installed_generation(source / "absent", None)
with pytest.raises(ValueError, match="missing the planned Knowledge generation"):
check_generation(source / "absent", *artifacts, expected_generation=expected)

(source / RELEASE_INTAKE_PIN).write_bytes(pin)
with zipfile.ZipFile(wheel, "a") as archive:
archive.writestr("inferrsi/knowledge/data/skill_library/surplus.json", b"{}")
with pytest.raises(ValueError, match="contains legacy Knowledge"):
check_generation(staged, *artifacts, expected_generation=expected)
write_zip(wheel, "inferrsi/", payload)

with tarfile.open(sdist, "w:gz") as archive:
member = tarfile.TarInfo("inferrsi-test/src/inferrsi/data/skill_library")
member.type = tarfile.DIRTYPE
archive.addfile(member)
with pytest.raises(ValueError, match="contains legacy Knowledge"):
check_generation(staged, *artifacts, expected_generation=expected)
(source / RELEASE_INTAKE_PIN).unlink()
with tarfile.open(sdist, "w:gz") as archive:
for name, data in files.items():
member = tarfile.TarInfo(f"inferrsi-test/src/inferrsi/_atomic/{name}")
member.size = len(data)
archive.addfile(member, io.BytesIO(data))
write_zip(wheel, "inferrsi/_atomic/", files)

with pytest.raises(ValueError, match="Source distribution differs"):
check_generation(source / "absent", sdist, wheel, codex, workswarm)
Expand All @@ -309,6 +388,31 @@ def write_zip(archive, prefix, payload):
)


def test_intake_uses_packaged_release_pin_as_its_default(author_root, tmp_path, monkeypatch):
package = tmp_path / "inferrsi"
monkeypatch.setattr(atomic_knowledge, "__file__", str(package / "apps/cli/atomic_knowledge.py"))
monkeypatch.delenv(atomic_knowledge.GENERATION_SELECTOR, raising=False)
staged = package / "_atomic"
generation = build_release(author_root, staged, permits=allow)
marker = package / RELEASE_INTAKE_PIN
# The author fixture has no Intake JSON. Exercise the real installed and pinned
# selection while the existing task schema source has its own tests.
monkeypatch.setattr(task_intake, "_sealed_spec", lambda task, chosen: (task, chosen.generation))
assert task_intake.load_spec("task-day-0")["task"] == "task-day-0"
marker.write_bytes((generation + "\n").encode("ascii"))
assert task_intake.load_spec("task-day-0") == ("task-day-0", generation)
assert atomic_knowledge.AtomicKnowledgeCLI.installed() is None
monkeypatch.setenv(atomic_knowledge.GENERATION_SELECTOR, "sha256:" + "0" * 64)
with pytest.raises(IntakeError, match="Requested generation is unavailable"):
task_intake.load_spec("task-day-0")
marker.write_bytes(b"invalid\n")
monkeypatch.setenv(atomic_knowledge.GENERATION_SELECTOR, generation)
assert task_intake.load_spec("task-day-0") == ("task-day-0", generation)
monkeypatch.delenv(atomic_knowledge.GENERATION_SELECTOR)
with pytest.raises(IntakeError, match="Invalid release Intake generation pin"):
task_intake.load_spec("task-day-0")


@pytest.mark.parametrize("compiler_options", [
pytest.param([], id="default"),
pytest.param(
Expand All @@ -324,6 +428,7 @@ def test_default_wheel_install_verifies_generation(tmp_path, compiler_options):
with zipfile.ZipFile(wheel, "w") as archive:
for name, data in file_bytes(staged).items():
archive.writestr(f"inferrsi/_atomic/{name}", data)
archive.writestr(f"inferrsi/{RELEASE_INTAKE_PIN}", expected + "\n")
dist = "atomic_fixture-0.0.0.dist-info"
archive.writestr(
f"{dist}/METADATA", "Metadata-Version: 2.1\nName: atomic-fixture\nVersion: 0.0.0\n",
Expand Down
Loading
Loading