Skip to content

test(ci): probe evidence payload bounds, context gating, and custom path (Unit 10)#53

Open
0xjgv wants to merge 2 commits into
mainfrom
unit10-ci-evidence-probes
Open

test(ci): probe evidence payload bounds, context gating, and custom path (Unit 10)#53
0xjgv wants to merge 2 commits into
mainfrom
unit10-ci-evidence-probes

Conversation

@0xjgv

@0xjgv 0xjgv commented May 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds 3 focused tests in tests/stages/test_ci.py proving interlocks ci writes bounded, non-sensitive timing evidence:
    • payload bounded: asserts _write_ci_evidence produces exactly {command, elapsed_seconds, created_at, passed, budget_seconds} — no extra fields
    • context gating: context key present only when INTERLOCKS_CI_CONTEXT was captured; absent otherwise
    • custom path: cmd_ci() driven in-process with task stubs; evidence lands at [tool.interlocks] ci_evidence_path override
  • Adds 2 test_config.py probes for ci_evidence_path resolution (default and override)
  • Clean rebuild from origin/main on a fresh worktree; no stash applied

Test plan

  • uv run pytest -q tests/stages tests/test_config.py → 98 passed
  • uv run interlocks check --changed → all gates ok
  • Pre-commit hook passes on commit

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.

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

Copy link
Copy Markdown

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 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.

Comment thread tests/stages/test_ci.py Outdated
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"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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"))

Comment thread tests/stages/test_ci.py Outdated
monkeypatch.chdir(tmp_path)

cfg = load_config()
evidence = tmp_path / ".interlocks" / "ci.json"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Instead of hardcoding the expected path, leverage the configuration object which already contains the resolved path.

Suggested change
evidence = tmp_path / ".interlocks" / "ci.json"
evidence = cfg.ci_evidence_path

Comment thread tests/test_config.py Outdated
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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Use the source of truth for the default path from InterlockConfig instead of a hardcoded string literal.

Suggested change
assert cfg.ci_evidence_path == (tmp_project / ".interlocks" / "ci.json").resolve()
assert cfg.ci_evidence_path == (tmp_project / InterlockConfig.ci_evidence_path).resolve()

…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.
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