Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/portfolio_decision_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@
import argparse
import hashlib
import json
import sys
from datetime import datetime, timedelta, timezone
from pathlib import Path
from typing import Any

# Keep the documented absolute-path entrypoint portable. When Python executes
# this file directly it puts ``src/`` on sys.path, which otherwise makes the
# package-qualified ``src.security_admission`` import impossible outside the
# repository root. Module and test imports already have the repository root.
if __package__ in {None, ""}:
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from src.security_admission import derive_security_admission

CONTRACT_VERSION = "decision_queue_v2"
Expand Down
47 changes: 47 additions & 0 deletions tests/test_portfolio_decision_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import copy
import json
import subprocess
import sys
from pathlib import Path

import pytest
Expand Down Expand Up @@ -469,3 +471,48 @@ def test_cli_json_and_markdown_are_deterministic(
markdown = capsys.readouterr().out
assert "## Portfolio Decision Digest — 2026-08-05" in markdown
assert "**MCPAudit** [security follow-up]" in markdown


def test_absolute_cli_entrypoint_runs_from_arbitrary_cwd(tmp_path: Path) -> None:
truth_path = tmp_path / "portfolio-truth.json"
truth_path.write_text(
json.dumps(
_truth(
[
_project(
"MCPAudit",
attention_state="decision-needed",
security_risk=True,
code_scanning_high=1,
)
]
)
),
encoding="utf-8",
)
script = Path(__file__).resolve().parents[1] / "src" / "portfolio_decision_queue.py"
unrelated_cwd = tmp_path / "unrelated-cwd"
unrelated_cwd.mkdir()

run = subprocess.run(
[
sys.executable,
"-B",
str(script),
"--truth",
str(truth_path),
"--format",
"json",
],
cwd=unrelated_cwd,
check=False,
capture_output=True,
text=True,
)

assert run.returncode == 0, run.stderr
digest = json.loads(run.stdout)
assert digest["contract_version"] == DIGEST_CONTRACT_VERSION
assert digest["decision_queue"][0]["evidence_reference"]["provider"] == (
"github_security_combined"
)