Files
ss-tools/scripts/full_flow/common.py

35 lines
1.4 KiB
Python

# #region Tooling.FullFlowErrors [C:1] [TYPE Module] [SEMANTICS test,flow,errors]
# @BRIEF Shared fail-closed verifier exception.
from pathlib import Path
# #region Tooling.FullFlowErrors.Blocked [C:2] [TYPE Class]
class Blocked(RuntimeError):
"""A real boundary or falsifiable assertion failed."""
# #endregion Tooling.FullFlowErrors.Blocked
# #region Tooling.FullFlowErrors.ArtifactPath [C:2] [TYPE Function]
# @PRE Explicit destination; repository identity is this actual resolved worktree.
# @POST Only ignored artifacts or an external path is admitted, without creating or changing any file.
# @RATIONALE Resolving symlinks before admission prevents a nominal external/artifacts path from writing into specs.
def artifact_path(value):
try:
root = Path(__file__).resolve().parents[2]
destination = Path(value).resolve()
ancestor = destination
while not ancestor.exists():
if ancestor.is_symlink():
raise OSError("unresolved symlink")
ancestor = ancestor.parent
ancestor.resolve(strict=True)
except (OSError, RuntimeError, TypeError, ValueError):
raise Blocked("EVIDENCE_OUTPUT_PATH_UNAVAILABLE") from None
if destination.is_relative_to(root) and not destination.is_relative_to(root / "artifacts"):
raise Blocked("EVIDENCE_OUTPUT_PATH_FORBIDDEN")
return destination
# #endregion Tooling.FullFlowErrors.ArtifactPath
# #endregion Tooling.FullFlowErrors