test(ci): probe evidence payload bounds, context gating, and custom path (Unit 10)#53
Open
0xjgv wants to merge 2 commits into
Open
test(ci): probe evidence payload bounds, context gating, and custom path (Unit 10)#530xjgv wants to merge 2 commits into
0xjgv wants to merge 2 commits into
Conversation
Adds Unit 10 CI evidence invariant tests: - `test_ci_evidence_payload_is_bounded`: asserts the JSON written by `_write_ci_evidence` contains exactly the five allowed keys (command, elapsed_seconds, created_at, passed, budget_seconds); no extra fields. - `test_ci_evidence_context_key_present_only_when_provided`: verifies `context` key appears only when the env-sourced argument is non-None. - `test_ci_evidence_uses_custom_ci_evidence_path`: drives `cmd_ci()` in-process with task stubs and asserts evidence lands at the `[tool.interlocks] ci_evidence_path` override. Also adds two `test_config.py` probes for `ci_evidence_path` resolution: default resolves under project root; override resolves relative to root. All imports lifted to module level; `_make_minimal_project` extended with optional `name`/`tool_interlocks` params to eliminate setup duplication in the custom-path test.
There was a problem hiding this comment.
Code Review
This pull request introduces unit tests for CI evidence generation and configuration path resolution. The new tests verify that the evidence payload contains the expected fields, correctly handles optional context keys, and respects custom file paths defined in the configuration. Review feedback suggests improving test maintainability by using the configuration object's properties instead of hardcoding file paths within the test assertions.
| cfg = load_config() | ||
| _write_ci_evidence(cfg, elapsed_seconds=2.5, passed=True, context=None) | ||
|
|
||
| data = json.loads((tmp_path / ".interlocks" / "ci.json").read_text(encoding="utf-8")) |
There was a problem hiding this comment.
Avoid hardcoding the default evidence path in tests. Using cfg.ci_evidence_path ensures the test remains robust if the default configuration changes in the future.
Suggested change
| data = json.loads((tmp_path / ".interlocks" / "ci.json").read_text(encoding="utf-8")) | |
| data = json.loads(cfg.ci_evidence_path.read_text(encoding="utf-8")) |
| monkeypatch.chdir(tmp_path) | ||
|
|
||
| cfg = load_config() | ||
| evidence = tmp_path / ".interlocks" / "ci.json" |
| def test_ci_evidence_path_default_resolves_under_project_root(tmp_project: Path) -> None: | ||
| """Default ci_evidence_path is .interlocks/ci.json relative to project root.""" | ||
| cfg = load_config() | ||
| assert cfg.ci_evidence_path == (tmp_project / ".interlocks" / "ci.json").resolve() |
There was a problem hiding this comment.
…terals Address gemini-code-assist review: replace hardcoded `.interlocks/ci.json` path strings with `cfg.ci_evidence_path` (instance property) and `InterlockConfig.ci_evidence_path` (class-level default) so tests stay robust when the default configuration changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/stages/test_ci.pyprovinginterlocks ciwrites bounded, non-sensitive timing evidence:_write_ci_evidenceproduces exactly{command, elapsed_seconds, created_at, passed, budget_seconds}— no extra fieldscontextkey present only whenINTERLOCKS_CI_CONTEXTwas captured; absent otherwisecmd_ci()driven in-process with task stubs; evidence lands at[tool.interlocks] ci_evidence_pathoverridetest_config.pyprobes forci_evidence_pathresolution (default and override)origin/mainon a fresh worktree; no stash appliedTest plan
uv run pytest -q tests/stages tests/test_config.py→ 98 passeduv run interlocks check --changed→ all gates ok