valguard-cli 0.0.1__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.1
2
+ Name: valguard-cli
3
+ Version: 0.1.1
4
+ Summary: ValGuard offline CLI wrapper (downloads platform binary from GitHub Releases)
5
+ Author: ValGuard.ai
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/valguard-ai/valguard
8
+ Project-URL: Documentation, https://www.valguard.ai
9
+ Keywords: llm,validation,agents,cli
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+
17
+ # valguard-cli (PyPI)
18
+
19
+ Thin Python entrypoint for the **ValGuard** Go binary (`valguard`). On first run, downloads
20
+ `valguard` from [GitHub Releases](https://github.com/valguard-ai/valguard/releases) for your
21
+ OS/arch (or uses `VALGUARD_BIN` if set). The archive is verified against the release's
22
+ `checksums.txt` (SHA-256) before it is run, and cached per release tag under `~/.cache/valguard-cli/`.
23
+
24
+ ```bash
25
+ pip install valguard-cli
26
+ valguard version
27
+ valguard check --policy valguard.yaml --output '{"ok":true}'
28
+ ```
29
+
30
+ | | |
31
+ |--|--|
32
+ | PyPI project | **`valguard-cli`** |
33
+ | Console script | **`valguard`** |
34
+ | Default release tag | `v0.1.1` (`VALGUARD_VERSION` env override) |
35
+ | Module / source | `github.com/valguard-ai/valguard` |
36
+
37
+ `pip install valguard` installs an **unrelated** project. Do not use that name for this CLI.
38
+
39
+ **Launch dependency:** downloads fail until `valguard-ai/valguard` publishes release assets for the
40
+ requested tag (the repository must be public). The wrapper never looks `valguard` up on `PATH`
41
+ (its own console script has that name); to use a different binary set `VALGUARD_BIN`.
@@ -0,0 +1,25 @@
1
+ # valguard-cli (PyPI)
2
+
3
+ Thin Python entrypoint for the **ValGuard** Go binary (`valguard`). On first run, downloads
4
+ `valguard` from [GitHub Releases](https://github.com/valguard-ai/valguard/releases) for your
5
+ OS/arch (or uses `VALGUARD_BIN` if set). The archive is verified against the release's
6
+ `checksums.txt` (SHA-256) before it is run, and cached per release tag under `~/.cache/valguard-cli/`.
7
+
8
+ ```bash
9
+ pip install valguard-cli
10
+ valguard version
11
+ valguard check --policy valguard.yaml --output '{"ok":true}'
12
+ ```
13
+
14
+ | | |
15
+ |--|--|
16
+ | PyPI project | **`valguard-cli`** |
17
+ | Console script | **`valguard`** |
18
+ | Default release tag | `v0.1.1` (`VALGUARD_VERSION` env override) |
19
+ | Module / source | `github.com/valguard-ai/valguard` |
20
+
21
+ `pip install valguard` installs an **unrelated** project. Do not use that name for this CLI.
22
+
23
+ **Launch dependency:** downloads fail until `valguard-ai/valguard` publishes release assets for the
24
+ requested tag (the repository must be public). The wrapper never looks `valguard` up on `PATH`
25
+ (its own console script has that name); to use a different binary set `VALGUARD_BIN`.
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "valguard-cli"
7
+ version = "0.1.1"
8
+ description = "ValGuard offline CLI wrapper (downloads platform binary from GitHub Releases)"
9
+ readme = "README.md"
10
+ license = { text = "Apache-2.0" }
11
+ requires-python = ">=3.9"
12
+ authors = [{ name = "ValGuard.ai" }]
13
+ keywords = ["llm", "validation", "agents", "cli"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Environment :: Console",
17
+ "License :: OSI Approved :: Apache Software License",
18
+ "Programming Language :: Python :: 3",
19
+ ]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/valguard-ai/valguard"
23
+ Documentation = "https://www.valguard.ai"
24
+
25
+ [project.scripts]
26
+ valguard = "valguard_cli.runner:main"
27
+
28
+ [tool.setuptools.packages.find]
29
+ where = ["src"]
@@ -0,0 +1 @@
1
+ __version__ = "0.1.1"
@@ -0,0 +1,112 @@
1
+ """Invoke the ValGuard OSS CLI; fetch and verify the release binary on first run."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import os
7
+ import platform
8
+ import stat
9
+ import subprocess
10
+ import sys
11
+ import tarfile
12
+ import tempfile
13
+ import urllib.request
14
+ import zipfile
15
+
16
+ RELEASE_TAG = os.environ.get("VALGUARD_VERSION", "v0.1.1")
17
+ REPO = "valguard-ai/valguard"
18
+ CACHE_ROOT = os.path.join(os.path.expanduser("~"), ".cache", "valguard-cli")
19
+
20
+
21
+ def _platform_asset() -> str:
22
+ sys_map = {"Darwin": "darwin", "Linux": "linux", "Windows": "windows"}
23
+ mach = platform.machine().lower()
24
+ arch = "arm64" if mach in ("arm64", "aarch64") else "amd64"
25
+ goos = sys_map.get(platform.system())
26
+ if not goos:
27
+ raise RuntimeError(f"unsupported OS: {platform.system()}")
28
+ ver = RELEASE_TAG.lstrip("v")
29
+ ext = "zip" if goos == "windows" else "tar.gz"
30
+ return f"valguard_{ver}_{goos}_{arch}.{ext}"
31
+
32
+
33
+ def _fetch(name: str, dest: str) -> None:
34
+ url = f"https://github.com/{REPO}/releases/download/{RELEASE_TAG}/{name}"
35
+ with urllib.request.urlopen(url, timeout=120) as resp, open(dest, "wb") as out:
36
+ while chunk := resp.read(1 << 16):
37
+ out.write(chunk)
38
+
39
+
40
+ def _verify_checksum(archive: str, asset: str, checksums: str) -> None:
41
+ # checksums.txt is GoReleaser's "<sha256> <file>" list. A missing entry is a
42
+ # hard failure: never execute a binary we could not verify.
43
+ want = ""
44
+ with open(checksums, encoding="utf-8") as f:
45
+ for line in f:
46
+ parts = line.split()
47
+ if len(parts) == 2 and parts[1] == asset:
48
+ want = parts[0].lower()
49
+ break
50
+ if not want:
51
+ raise RuntimeError(f"{asset} not listed in checksums.txt")
52
+ h = hashlib.sha256()
53
+ with open(archive, "rb") as f:
54
+ while chunk := f.read(1 << 20):
55
+ h.update(chunk)
56
+ if h.hexdigest() != want:
57
+ raise RuntimeError(f"checksum mismatch for {asset}; refusing to run it")
58
+
59
+
60
+ def _extract_binary(archive: str, exe_name: str, dest: str) -> None:
61
+ # Read exactly one named member instead of extractall(): a crafted archive
62
+ # cannot write outside the cache directory (path traversal).
63
+ if archive.endswith(".zip"):
64
+ with zipfile.ZipFile(archive) as zf:
65
+ data = zf.read(exe_name)
66
+ else:
67
+ with tarfile.open(archive, "r:gz") as tf:
68
+ member = tf.extractfile(exe_name)
69
+ if member is None:
70
+ raise RuntimeError(f"{exe_name} not found in archive")
71
+ data = member.read()
72
+ with open(dest, "wb") as out:
73
+ out.write(data)
74
+ os.chmod(dest, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
75
+
76
+
77
+ def _ensure_binary() -> str:
78
+ override = os.environ.get("VALGUARD_BIN", "").strip()
79
+ if override:
80
+ return override
81
+ # Deliberately no PATH lookup: this package installs a console script named
82
+ # `valguard`, so shutil.which("valguard") finds this wrapper and recurses.
83
+ exe_name = "valguard.exe" if platform.system() == "Windows" else "valguard"
84
+ # Cache is keyed by release tag so upgrading the wrapper never reuses an old binary.
85
+ cache_dir = os.path.join(CACHE_ROOT, RELEASE_TAG)
86
+ dest = os.path.join(cache_dir, exe_name)
87
+ if os.path.isfile(dest) and os.access(dest, os.X_OK):
88
+ return dest
89
+ os.makedirs(cache_dir, exist_ok=True)
90
+ asset = _platform_asset()
91
+ print(f"valguard-cli: downloading {asset} ...", file=sys.stderr)
92
+ with tempfile.TemporaryDirectory() as td:
93
+ archive = os.path.join(td, asset)
94
+ checksums = os.path.join(td, "checksums.txt")
95
+ _fetch(asset, archive)
96
+ _fetch("checksums.txt", checksums)
97
+ _verify_checksum(archive, asset, checksums)
98
+ _extract_binary(archive, exe_name, dest)
99
+ return dest
100
+
101
+
102
+ def main() -> None:
103
+ try:
104
+ bin_path = _ensure_binary()
105
+ except Exception as exc: # network, checksum, unsupported OS
106
+ print(f"valguard-cli: {exc}", file=sys.stderr)
107
+ raise SystemExit(2)
108
+ raise SystemExit(subprocess.call([bin_path, *sys.argv[1:]]))
109
+
110
+
111
+ if __name__ == "__main__":
112
+ main()
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.1
2
+ Name: valguard-cli
3
+ Version: 0.1.1
4
+ Summary: ValGuard offline CLI wrapper (downloads platform binary from GitHub Releases)
5
+ Author: ValGuard.ai
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/valguard-ai/valguard
8
+ Project-URL: Documentation, https://www.valguard.ai
9
+ Keywords: llm,validation,agents,cli
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+
17
+ # valguard-cli (PyPI)
18
+
19
+ Thin Python entrypoint for the **ValGuard** Go binary (`valguard`). On first run, downloads
20
+ `valguard` from [GitHub Releases](https://github.com/valguard-ai/valguard/releases) for your
21
+ OS/arch (or uses `VALGUARD_BIN` if set). The archive is verified against the release's
22
+ `checksums.txt` (SHA-256) before it is run, and cached per release tag under `~/.cache/valguard-cli/`.
23
+
24
+ ```bash
25
+ pip install valguard-cli
26
+ valguard version
27
+ valguard check --policy valguard.yaml --output '{"ok":true}'
28
+ ```
29
+
30
+ | | |
31
+ |--|--|
32
+ | PyPI project | **`valguard-cli`** |
33
+ | Console script | **`valguard`** |
34
+ | Default release tag | `v0.1.1` (`VALGUARD_VERSION` env override) |
35
+ | Module / source | `github.com/valguard-ai/valguard` |
36
+
37
+ `pip install valguard` installs an **unrelated** project. Do not use that name for this CLI.
38
+
39
+ **Launch dependency:** downloads fail until `valguard-ai/valguard` publishes release assets for the
40
+ requested tag (the repository must be public). The wrapper never looks `valguard` up on `PATH`
41
+ (its own console script has that name); to use a different binary set `VALGUARD_BIN`.
@@ -1,7 +1,10 @@
1
1
  README.md
2
2
  pyproject.toml
3
3
  src/valguard_cli/__init__.py
4
+ src/valguard_cli/runner.py
4
5
  src/valguard_cli.egg-info/PKG-INFO
5
6
  src/valguard_cli.egg-info/SOURCES.txt
6
7
  src/valguard_cli.egg-info/dependency_links.txt
7
- src/valguard_cli.egg-info/top_level.txt
8
+ src/valguard_cli.egg-info/entry_points.txt
9
+ src/valguard_cli.egg-info/top_level.txt
10
+ tests/test_runner.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ valguard = valguard_cli.runner:main
@@ -0,0 +1,95 @@
1
+ """Run: cd packaging/pypi/valguard-cli && PYTHONPATH=src python3 -m unittest discover -s tests"""
2
+
3
+ import hashlib
4
+ import io
5
+ import os
6
+ import tarfile
7
+ import tempfile
8
+ import unittest
9
+ import zipfile
10
+ from unittest import mock
11
+
12
+ from valguard_cli import runner
13
+
14
+
15
+ def _sha(path: str) -> str:
16
+ with open(path, "rb") as f:
17
+ return hashlib.sha256(f.read()).hexdigest()
18
+
19
+
20
+ class RunnerTest(unittest.TestCase):
21
+ def setUp(self):
22
+ self.td = tempfile.TemporaryDirectory()
23
+ self.addCleanup(self.td.cleanup)
24
+
25
+ def _tar(self, members: dict) -> str:
26
+ path = os.path.join(self.td.name, "a.tar.gz")
27
+ with tarfile.open(path, "w:gz") as tf:
28
+ for name, data in members.items():
29
+ info = tarfile.TarInfo(name)
30
+ info.size = len(data)
31
+ tf.addfile(info, io.BytesIO(data))
32
+ return path
33
+
34
+ def test_checksum_ok_mismatch_and_missing(self):
35
+ archive = self._tar({"valguard": b"bin"})
36
+ sums = os.path.join(self.td.name, "checksums.txt")
37
+ with open(sums, "w") as f:
38
+ f.write(f"{_sha(archive)} a.tar.gz\n")
39
+ runner._verify_checksum(archive, "a.tar.gz", sums)
40
+
41
+ with open(sums, "w") as f:
42
+ f.write(f"{'0' * 64} a.tar.gz\n")
43
+ with self.assertRaisesRegex(RuntimeError, "checksum mismatch"):
44
+ runner._verify_checksum(archive, "a.tar.gz", sums)
45
+
46
+ # An asset absent from checksums.txt must fail closed, not run unverified.
47
+ with self.assertRaisesRegex(RuntimeError, "not listed"):
48
+ runner._verify_checksum(archive, "other.tar.gz", sums)
49
+
50
+ def test_extract_reads_only_named_member(self):
51
+ # A traversal member next to the real binary must never be written.
52
+ archive = self._tar({"../evil": b"x", "valguard": b"real"})
53
+ dest = os.path.join(self.td.name, "out", "valguard")
54
+ os.makedirs(os.path.dirname(dest))
55
+ runner._extract_binary(archive, "valguard", dest)
56
+ with open(dest, "rb") as f:
57
+ self.assertEqual(f.read(), b"real")
58
+ self.assertFalse(os.path.exists(os.path.join(self.td.name, "evil")))
59
+
60
+ def test_extract_zip(self):
61
+ path = os.path.join(self.td.name, "a.zip")
62
+ with zipfile.ZipFile(path, "w") as zf:
63
+ zf.writestr("valguard.exe", b"win")
64
+ dest = os.path.join(self.td.name, "valguard.exe")
65
+ runner._extract_binary(path, "valguard.exe", dest)
66
+ with open(dest, "rb") as f:
67
+ self.assertEqual(f.read(), b"win")
68
+
69
+ def test_no_path_lookup_so_wrapper_cannot_recurse(self):
70
+ # The console script is also named `valguard`; resolving it from PATH
71
+ # would exec this wrapper again. The binary must come from the cache.
72
+ with mock.patch.object(runner, "CACHE_ROOT", self.td.name), mock.patch.dict(
73
+ os.environ, {"VALGUARD_BIN": ""}
74
+ ), mock.patch("shutil.which", return_value="/usr/bin/valguard") as which, mock.patch.object(
75
+ runner, "_fetch", side_effect=RuntimeError("offline")
76
+ ):
77
+ with self.assertRaisesRegex(RuntimeError, "offline"):
78
+ runner._ensure_binary()
79
+ which.assert_not_called()
80
+
81
+ def test_cache_is_versioned(self):
82
+ with mock.patch.object(runner, "CACHE_ROOT", self.td.name), mock.patch.object(
83
+ runner, "RELEASE_TAG", "v9.9.9"
84
+ ), mock.patch.dict(os.environ, {"VALGUARD_BIN": ""}):
85
+ exe = "valguard.exe" if os.name == "nt" else "valguard"
86
+ cached = os.path.join(self.td.name, "v9.9.9", exe)
87
+ os.makedirs(os.path.dirname(cached))
88
+ with open(cached, "wb") as f:
89
+ f.write(b"x")
90
+ os.chmod(cached, 0o755)
91
+ self.assertEqual(runner._ensure_binary(), cached)
92
+
93
+
94
+ if __name__ == "__main__":
95
+ unittest.main()
@@ -1,10 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: valguard-cli
3
- Version: 0.0.1
4
- Summary: Reserved namespace for the ValGuard local validation CLI (release forthcoming). https://valguard.ai
5
- Author: ValGuard.ai
6
- License: Apache-2.0
7
- Requires-Python: >=3.9
8
- Description-Content-Type: text/markdown
9
-
10
- Reserved for ValGuard CLI. See https://github.com/valguard-ai/valguard
@@ -1 +0,0 @@
1
- Reserved for ValGuard CLI. See https://github.com/valguard-ai/valguard
@@ -1,15 +0,0 @@
1
- [project]
2
- name = "valguard-cli"
3
- version = "0.0.1"
4
- description = "Reserved namespace for the ValGuard local validation CLI (release forthcoming). https://valguard.ai"
5
- readme = "README.md"
6
- requires-python = ">=3.9"
7
- license = { text = "Apache-2.0" }
8
- authors = [{ name = "ValGuard.ai" }]
9
-
10
- [build-system]
11
- requires = ["setuptools>=61"]
12
- build-backend = "setuptools.build_meta"
13
-
14
- [tool.setuptools.packages.find]
15
- where = ["src"]
@@ -1 +0,0 @@
1
- __version__ = "0.0.1"
@@ -1,10 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: valguard-cli
3
- Version: 0.0.1
4
- Summary: Reserved namespace for the ValGuard local validation CLI (release forthcoming). https://valguard.ai
5
- Author: ValGuard.ai
6
- License: Apache-2.0
7
- Requires-Python: >=3.9
8
- Description-Content-Type: text/markdown
9
-
10
- Reserved for ValGuard CLI. See https://github.com/valguard-ai/valguard
File without changes