Publish curated ITWorx_MCP_Hub source from 3237e4d8aec312d63d13b4e80664422a7520b5f9

This commit is contained in:
Public Source Publisher committed 2026-10-14 13:18:45 +00:00
1 parent 867a1b5e3b
commit fdc6d4a0a5
13 files changed
+536 -68

No files matched your search

+61 -1
View File
@@ -23,6 +23,30 @@ def _hash(data: bytes) -> str:
return hashlib.sha256(data).hexdigest()
def _prior_recipe_receipt_hash(data: bytes) -> str:
"""Only this Git LF-normalized historical JSON receipt permits CRLF checkout bytes."""
normalized = data.replace(b"\r\n", b"\n")
if b"\r" in normalized:
raise ValueError("unsupported historical receipt newline")
return _hash(normalized)
def test_prior_recipe_receipt_identity_accepts_only_git_lf_or_crlf_checkout() -> None:
import subprocess
path = "evidence/WP-400/CF_POSTGRES_BINARY_RECIPE.json"
blob = subprocess.check_output(["git", "show", "HEAD:" + path], cwd=ROOT) # noqa: S603,S607 - fixed local Git object
assert b"\r" not in blob
assert (
_prior_recipe_receipt_hash(blob)
== _prior_recipe_receipt_hash(blob.replace(b"\n", b"\r\n"))
== _hash(blob)
)
assert _prior_recipe_receipt_hash(blob + b" ") != _hash(blob)
with pytest.raises(ValueError, match="unsupported historical receipt newline"):
_prior_recipe_receipt_hash(blob.replace(b"\n", b"\r", 1))
def _containerfile_fixture() -> bytes:
return (
b"FROM base\n"
@@ -134,10 +158,38 @@ dev = ["pytest>=8"]
"2026-07-01T00:00:00Z"
)
assert parsed["tool"]["uv"]["exclude-newer-package"]["pyjwt"] == "2026-10-02T00:00:00Z"
for package, version in (
("anyio", "4.14.2"),
("cryptography", "50.0.0"),
("langgraph-sdk", "0.4.4"),
("langgraph", "1.2.3"),
):
assert f"{package}=={version}" in parsed["tool"]["uv"]["constraint-dependencies"]
assert parsed["tool"]["uv"]["exclude-newer-package"][package] == "2026-10-14T00:00:00Z"
assert parsed["dependency-groups"]["build-tools"] == list(recipe.BUILD_TOOLS)
assert "dev" not in parsed["dependency-groups"]
@pytest.mark.parametrize(
"requirement", ["langgraph<=1.2.0", "langgraph==1.2.0", 'langgraph<=1.2.0","langgraph<=1.2.0']
)
def test_runtime_langgraph_compatibility_patch_has_one_exact_source_anchor(
requirement: str,
) -> None:
source = (
'[project.optional-dependencies]\npostgres=["psycopg[c,binary]>=3.3.4"]\n'
f'llmchat=["{requirement}"]\n'
)
if requirement == "langgraph<=1.2.0":
result = recipe.runtime_pyproject(source)
assert 'llmchat=["langgraph==1.2.3"]' in result
assert 'postgres=["psycopg[binary]>=3.3.4"]' in result
assert "langgraph<=1.2.0" in source
else:
with pytest.raises(recipe.CandidateRecipeError, match="LangGraph compatibility"):
recipe.runtime_pyproject(source)
def test_runtime_lock_rejects_source_only_postgres_adapter(monkeypatch) -> None:
manifest = recipe._read_lock_manifest()
original = recipe._require_file
@@ -399,8 +451,16 @@ def test_frozen_base_evidence_matches_candidate_pins_and_repository_inputs() ->
assert delta["historicalInputsSha256"] == {
name: evidence["hubInputsSha256"][name] for name in changed
}
security = json.loads((ROOT / "evidence/WP-400/CF_SECURITY_RECIPE.json").read_text())
assert security["schema"] == "itworx.contextforge-security-recipe/v1"
assert security["priorRecipeEvidenceHashMode"] == "git-blob-lf"
assert security["priorRecipeEvidenceSha256"] == _prior_recipe_receipt_hash(
(ROOT / "evidence/WP-400/CF_POSTGRES_BINARY_RECIPE.json").read_bytes()
)
assert security["historicalInputsSha256"] == delta["candidateInputsSha256"]
assert set(security["candidateInputsSha256"]) == changed
for name, historical_hash in evidence["hubInputsSha256"].items():
expected = delta["candidateInputsSha256"].get(name, historical_hash)
expected = security["candidateInputsSha256"].get(name, historical_hash)
assert _hash((ROOT / name).read_bytes()) == expected
assert delta["finalCandidateBuilt"] is False
assert delta["policy"] == "psycopg[binary]==3.3.4; hash-locked wheels only"
+7 -4
View File
@@ -60,9 +60,12 @@ def test_release_credentials_only_reach_the_bounded_producer() -> None:
command = steps[1]["run"]
assert "set -euo pipefail" in command
assert "set -x" not in command and "docker login" not in command
assert 'python3 scripts/build_mcp_hub_release_images.py --revision "$GITHUB_SHA"' in command
assert (
"python3 scripts/build_mcp_hub_release_images.py --prepare-security-bases "
'--revision "$GITHUB_SHA"' in command
)
assert '--run-id "$GITHUB_RUN_ID"' in command
assert '--output "${RUNNER_TEMP}/hub-release-candidate-${GITHUB_SHA}"' in command
assert '--output "${RUNNER_TEMP}/hub-release-security-bases-${GITHUB_SHA}"' in command
def test_release_artifact_is_pinned_uncompressed_and_cannot_overwrite() -> None:
@@ -70,8 +73,8 @@ def test_release_artifact_is_pinned_uncompressed_and_cannot_overwrite() -> None:
assert upload["uses"] == UPLOAD
assert "if" not in upload
assert upload["with"] == {
"name": "hub-release-candidate-${{ github.sha }}",
"path": "${{ runner.temp }}/hub-release-candidate-${{ github.sha }}/*",
"name": "hub-release-security-bases-${{ github.sha }}",
"path": "${{ runner.temp }}/hub-release-security-bases-${{ github.sha }}/*",
"if-no-files-found": "error",
"retention-days": 90,
"compression-level": 0,
+214
View File
@@ -0,0 +1,214 @@
import copy
import io
import json
import subprocess
import sys
from pathlib import Path
import pytest
from scripts import build_mcp_hub_release_images as producer
from scripts import prepare_release_security_bases as preparation
def test_actual_cli_loader_preserves_closed_exception_identity() -> None:
root = Path(__file__).resolve().parents[1]
program = """import ast,sys,types
from pathlib import Path
root=Path.cwd()
sys.path.insert(0,str(root/'scripts'))
path=root/'scripts/build_mcp_hub_release_images.py'
syntax=ast.parse(path.read_text())
assert isinstance(syntax.body[-1],ast.If)
syntax.body.pop()
module=types.ModuleType('__main__')
module.__file__=str(path)
module.__package__=''
sys.modules['__main__']=module
exec(compile(syntax,str(path),'exec'),module.__dict__)
helper=module._security_preparation_module()
assert helper.producer is module
assert helper.producer.BuildRejected is module.BuildRejected
assert helper.producer.VulnerabilityRejected is module.VulnerabilityRejected
try:
helper.tag('unsupported','a'*40,123,1)
except module.BuildRejected as error:
assert str(error)=='security base publication identity is invalid'
else:
raise AssertionError('closed rejection missing')
print('CLI exception identity PASS')
"""
result = subprocess.run( # noqa: S603 - fixed interpreter and static CLI identity harness
[sys.executable, "-c", program], cwd=root, capture_output=True, text=True, timeout=20
)
assert result.returncode == 0, result.stderr
assert result.stdout.strip() == "CLI exception identity PASS"
def test_fixed_publication_names_bind_exact_protected_attempt() -> None:
assert preparation.tag("postgres", "a" * 40, 123, 2) == (
producer.IMAGE_PREFIX + "/postgres:" + "a" * 40 + "-security-run-123-attempt-2"
)
for args in [
("worker", "a" * 40, 123, 2),
("postgres", "secret", 123, 2),
("postgres", "a" * 40, 0, 2),
("postgres", "a" * 40, 123, 0),
]:
with pytest.raises(producer.BuildRejected):
preparation.tag(*args)
@pytest.mark.parametrize(
"field",
["User", "Entrypoint", "Cmd", "Volumes", "Env", "Healthcheck", "WorkingDir", "StopSignal"],
)
def test_base_lifecycle_cannot_be_changed_or_echoed(field: str) -> None:
base = {"config": {field: "private-value"}}
preparation.verify_lifecycle(base, {"config": dict(base["config"])})
with pytest.raises(producer.BuildRejected) as error:
preparation.verify_lifecycle(base, {"config": {field: "private-new-value"}})
assert str(error.value) == "security base runtime lifecycle differs from its exact parent"
def test_unknown_download_asset_is_denied_before_network(tmp_path: Path) -> None:
with pytest.raises(producer.BuildRejected):
preparation.download_asset(
"secret", tmp_path, opener=lambda *args, **kwargs: pytest.fail("network called")
)
def test_arbitrary_scanner_subset_cannot_replace_full_release(tmp_path: Path) -> None:
with pytest.raises(producer.BuildRejected, match="fixed release or preparation"):
producer._install_and_scan(
images={},
temp_root=tmp_path,
env={},
cwd=tmp_path,
runner=lambda *args, **kwargs: None,
services=("connector-gitea",),
)
@pytest.mark.parametrize("data", [b"bad", b"longer-than-fixed-size"])
def test_corrupt_assets_are_rejected_without_writing(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, data: bytes
) -> None:
monkeypatch.setitem(preparation.ASSETS, "go", ("https://go.dev/fixed", "asset", "a" * 64, 3))
with pytest.raises(producer.BuildRejected) as error:
preparation.download_asset("go", tmp_path, opener=lambda *args, **kwargs: io.BytesIO(data))
assert "bad" not in str(error.value)
assert not list(tmp_path.iterdir())
@pytest.mark.parametrize("failure", [None, "scan", "lifecycle", "pull"])
def test_only_verified_scanned_images_publish_and_no_candidate_is_emitted(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, failure: str | None
) -> None:
root = Path(__file__).resolve().parents[1]
output = tmp_path / "published"
events: list[str] = []
built: dict[str, dict] = {}
parent = {
"imageId": "sha256:" + "b" * 64,
"config": {
"User": "",
"Entrypoint": ["/original"],
"Cmd": ["original"],
"Env": ["STATIC=unchanged"],
"Volumes": {"/original": {}},
},
}
def execute(command: list[str], **kwargs: object) -> None:
stage = str(kwargs["stage"])
events.append(stage)
if stage == "security_base_build":
reference = command[command.index("--tag") + 1]
config = copy.deepcopy(parent)
config["config"]["Labels"] = dict(
command[index + 1].split("=", 1)
for index, value in enumerate(command)
if value == "--label"
)
if failure == "lifecycle":
config["config"]["User"] = "10001"
built[reference] = config
def inspect(reference: str, *args: object, **kwargs: object) -> dict:
if reference in {value[0] for value in producer.EXTERNAL_IMAGES.values()}:
return copy.deepcopy(parent)
result = copy.deepcopy(built[reference.split("@", 1)[0]])
if "@" in reference and failure == "pull":
result["imageId"] = "sha256:" + "c" * 64
return result
def scan(**kwargs: object) -> Path:
events.append("scan-both")
assert kwargs["services"] == producer.SECURITY_BASE_SERVICES
assert set(kwargs["images"]) == set(producer.SECURITY_BASE_SERVICES)
if failure == "scan":
raise producer.BuildRejected("synthetic scan denial")
reports = tmp_path / "reports"
reports.mkdir()
names = {"trivy-db-metadata.json"} | {
f"{kind}-{service}.json"
for service in producer.SECURITY_BASE_SERVICES
for kind in ("vulnerability", "secret")
}
for name in names:
producer._write_new(reports / name, b"{}\n")
return reports
monkeypatch.setattr(producer, "_execute", execute)
monkeypatch.setattr(producer, "_inspect_image", inspect)
monkeypatch.setattr(producer, "_registry_tag_absent", lambda *args, **kwargs: None)
monkeypatch.setattr(
producer,
"_capture",
lambda *args, **kwargs: json.dumps(
{
"digest": "sha256:" + "d" * 64,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"size": 123,
}
),
)
monkeypatch.setattr(producer, "_install_and_scan", scan)
monkeypatch.setattr(preparation, "download_asset", lambda *args, **kwargs: None)
arguments = dict(
root=root,
temp_root=tmp_path,
output=output,
env={},
revision="a" * 40,
tree="e" * 40,
epoch="123",
built_at="2026-10-14T00:00:00Z",
run_id=123,
attempt=1,
runner=lambda *args, **kwargs: None,
)
if failure is not None:
with pytest.raises(producer.BuildRejected):
preparation.prepare(**arguments)
assert not output.exists()
if failure != "pull":
assert "security_base_push" not in events
else:
receipt = preparation.prepare(**arguments)
assert (
events.count("security_base_build") == events.count("security_base_runtime_verify") == 2
)
assert events.count("security_base_push") == 2
assert events.index("scan-both") < events.index("security_base_push")
assert receipt["candidateEmitted"] is False and receipt["reportCount"] == 5
assert [row["service"] for row in receipt["preparedImages"]] == list(
producer.SECURITY_BASE_SERVICES
)
assert all(
row["archiveRef"].endswith("-security-run-123-attempt-1")
for row in receipt["preparedImages"]
)
assert not (output / "candidate.json").exists()
assert not (output / "images.tar").exists()
+47
View File
@@ -0,0 +1,47 @@
import shutil
import subprocess
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[1]
SCRIPT = ROOT / "infrastructure/images/security-bases/ingestion-clamd/verify-pcre2.sh"
@pytest.mark.parametrize(
("inventory", "accepted"),
[
("P:unrelated\nV:1.0\n\nP:pcre2\nV:10.49-r0\nT:normal description\n", True),
("P:pcre2\nV:10.48-r0\n", False),
("P:pcre2\n", False),
("P:pcre2\nV:10.49-r0\nV:10.49-r0\n", False),
("P:pcre2\nV:10.49-r0\n\nP:pcre2\nV:10.49-r0\n", False),
("P:pcre2\nP:pcre2\nV:10.49-r0\n", False),
("P:unrelated\nV:10.49-r0\n", False),
("P:pcre2\nV:private-secret-never-echo\n", False),
(
"pcre2-10.49-r0 description:\nPerl-compatible regular expressions library\n"
"pcre2-10.49-r0 webpage:\nhttps://www.pcre.org/\n"
"pcre2-10.49-r0 installed size:\n1234 B\n",
False,
),
],
)
def test_actual_inventory_query_rejects_ambiguous_or_verbose_apk_output(
inventory: str, accepted: bool
) -> None:
source = SCRIPT.read_text()
assert "apk info" not in source
query = source.split("awk -v RS='' '", 1)[1].split("\n' /lib/apk/db/installed", 1)[0]
binary = shutil.which("awk")
fallback = Path("C:/Program Files/Git/usr/bin/awk.exe")
if binary is None and fallback.is_file():
binary = str(fallback)
if binary is None:
pytest.skip("real awk query runs in required native Linux CI")
result = subprocess.run( # noqa: S603 - exact trusted installed-inventory query
[binary, "-v", "RS=", query], input=inventory, text=True, capture_output=True, timeout=10
)
assert (result.returncode == 0) is accepted
assert result.stdout == ("10.49-r0\n" if accepted else "")
assert "private-secret" not in result.stdout + result.stderr