Skip to content

artifact: add MCP context bundle reference example#209

Merged
ProfRandom92 merged 1 commit into
mainfrom
feat/mcp-context-bundle-ref-example
May 22, 2026
Merged

artifact: add MCP context bundle reference example#209
ProfRandom92 merged 1 commit into
mainfrom
feat/mcp-context-bundle-ref-example

Conversation

@ProfRandom92
Copy link
Copy Markdown
Owner

Adds a lightweight deterministic agent artifact bundle example that references MCP context output by repo-relative artifact path.

Validation:

  • python -m compileall -q scripts/agent_artifact_bundle.py scripts/generate_mcp_context_bundle_ref_example.py
  • pytest tests/test_agent_artifact_bundle.py -q
  • python scripts/validate_agent_artifact_bundle.py --bundle artifacts/mcp_context_bundle_ref_example.json

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new artifact bundle example and a generator script, along with associated tests. The review feedback suggests enhancing the test suite by implementing more robust error handling and type validation when loading JSON files, as well as replacing brittle string-based checks with comprehensive key-set validation for the artifact's bundle object.



def test_mcp_context_bundle_ref_example_references_mcp_output_without_dumping_payload() -> None:
artifact = json.loads(MCP_REF_ARTIFACT_PATH.read_text(encoding="utf-8"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When loading JSON files, the repository guidelines require handling FileNotFoundError and JSONDecodeError by raising a RuntimeError that includes the repo-relative path. Additionally, the decoded payload should be validated as the expected type (e.g., a dictionary) using RuntimeError instead of assertions.

    try:
        artifact = json.loads(MCP_REF_ARTIFACT_PATH.read_text(encoding="utf-8"))
    except (FileNotFoundError, json.JSONDecodeError) as exc:
        raise RuntimeError(f"Failed to load {MCP_REF_ARTIFACT_PATH}: {exc}") from exc
    if not isinstance(artifact, dict):
        raise RuntimeError(f"Decoded payload from {MCP_REF_ARTIFACT_PATH} must be a dictionary")
References
  1. When loading JSON files, handle FileNotFoundError and JSONDecodeError by raising a RuntimeError that includes a repo-relative path. Additionally, validate that the decoded payload is of the expected type (e.g., a dictionary) using RuntimeError instead of assertions.

Comment on lines +245 to +255
bundle = artifact["bundle"]
assert bundle["branch"] == "feat/mcp-context-bundle-ref-example"
assert bundle["mcp_context_output_ref"] == MCP_CONTEXT_OUTPUT_REF
assert bundle["ok"] is True
assert bundle["result"] == "PASS"
assert bundle["safe_pr_gate"]["ok"] is True

artifact_text = MCP_REF_ARTIFACT_PATH.read_text(encoding="utf-8")
assert "prompt_context" not in artifact_text
assert "replay_payload" not in artifact_text
assert "dependency_chains" not in artifact_text
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current test uses brittle string-based checks to verify that certain fields are not present in the artifact. A more robust approach is to validate the set of keys in the bundle object. This ensures that only the expected fields are present and provides better coverage by also verifying changed_files.

Suggested change
bundle = artifact["bundle"]
assert bundle["branch"] == "feat/mcp-context-bundle-ref-example"
assert bundle["mcp_context_output_ref"] == MCP_CONTEXT_OUTPUT_REF
assert bundle["ok"] is True
assert bundle["result"] == "PASS"
assert bundle["safe_pr_gate"]["ok"] is True
artifact_text = MCP_REF_ARTIFACT_PATH.read_text(encoding="utf-8")
assert "prompt_context" not in artifact_text
assert "replay_payload" not in artifact_text
assert "dependency_chains" not in artifact_text
bundle = artifact["bundle"]
assert set(bundle) == {
"branch",
"changed_files",
"mcp_context_output_ref",
"ok",
"result",
"safe_pr_gate",
"validation_evidence",
}
assert bundle["branch"] == "feat/mcp-context-bundle-ref-example"
assert bundle["changed_files"] == [
"artifacts/mcp_context_bundle_ref_example.json",
"scripts/generate_mcp_context_bundle_ref_example.py",
"tests/test_agent_artifact_bundle.py",
]
assert bundle["mcp_context_output_ref"] == MCP_CONTEXT_OUTPUT_REF
assert bundle["ok"] is True
assert bundle["result"] == "PASS"
assert bundle["safe_pr_gate"]["ok"] is True

@ProfRandom92 ProfRandom92 merged commit 35cfc2f into main May 22, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant