test(P02): attestations dir scaffolded + empty (REQ-331, backend-engineer)
---ci--- project: acdl phase: 2 milestone: v1.28 status: execute persona: backend-engineer --- tests/test_init_attestations.py: nova init in a tmp_path creates .nova/contract.yml.attestations/ as an empty directory (listdir == []). The existing test_cli_subcommands.py asserts is_dir() but not emptiness; this is the explicit REQ-331 assertion (freshly scaffolded repo has no attestations yet — they are produced later by nova apply --sign-local-review / the JWS attestation flow, REQ-332).
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""REQ-331 test: nova init scaffolds .nova/contract.yml.attestations/ empty.
|
||||
|
||||
P1 (nova/init.py + core/init_scaffold.py) creates the attestations dir
|
||||
during `nova init`. This test explicitly verifies (a) the dir exists and
|
||||
(b) it is EMPTY after init (listdir returns []) — a freshly scaffolded
|
||||
repo has no attestations yet (they are produced later by
|
||||
nova apply --sign-local-review / the JWS attestation flow, REQ-332).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def _nova_help_cmd():
|
||||
"""Return the command list to invoke `nova --help` (prefer installed entry)."""
|
||||
nova = os.path.join(os.path.dirname(sys.executable), "nova")
|
||||
if os.path.isfile(nova):
|
||||
return [nova, "--help"]
|
||||
return [sys.executable, "-m", "nova.cli", "--help"]
|
||||
|
||||
|
||||
def test_init_attestations_dir_exists_and_is_empty(tmp_path):
|
||||
"""nova init creates .nova/contract.yml.attestations/ and it is empty."""
|
||||
cmd = _nova_help_cmd()
|
||||
init_cmd = cmd[:-1] + ["init"]
|
||||
proc = subprocess.run(init_cmd, capture_output=True, text=True, cwd=str(tmp_path))
|
||||
assert proc.returncode == 0, f"nova init failed: {proc.stderr}"
|
||||
attest_dir = tmp_path / ".nova" / "contract.yml.attestations"
|
||||
assert attest_dir.is_dir(), ".nova/contract.yml.attestations/ not created"
|
||||
# REQ-331: the dir is empty after init (no attestations yet).
|
||||
entries = os.listdir(attest_dir)
|
||||
assert entries == [], (
|
||||
f".nova/contract.yml.attestations/ not empty after init: {entries}"
|
||||
)
|
||||
|
||||
|
||||
def test_init_attestations_dir_is_a_directory_not_a_file(tmp_path):
|
||||
"""The attestations path is a directory (not a file), so attestation
|
||||
JWS files can be written into it later (REQ-332 flow)."""
|
||||
cmd = _nova_help_cmd()
|
||||
init_cmd = cmd[:-1] + ["init"]
|
||||
proc = subprocess.run(init_cmd, capture_output=True, text=True, cwd=str(tmp_path))
|
||||
assert proc.returncode == 0, f"nova init failed: {proc.stderr}"
|
||||
attest_path = tmp_path / ".nova" / "contract.yml.attestations"
|
||||
assert attest_path.is_dir(), f"{attest_path} is not a directory"
|
||||
assert not attest_path.is_file(), f"{attest_path} is a file, not a directory"
|
||||
Reference in New Issue
Block a user