|
| 1 | +name: bughunt poetry probe |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ['bughunt/poetry/**'] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + |
| 10 | +jobs: |
| 11 | + probe: |
| 12 | + strategy: |
| 13 | + fail-fast: false |
| 14 | + matrix: |
| 15 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 16 | + poetry: ['1.8.5', '2.0.1', '2.4.3'] |
| 17 | + runs-on: ${{ matrix.os }} |
| 18 | + timeout-minutes: 45 |
| 19 | + env: |
| 20 | + SOCKET_NO_CONFIG: '1' |
| 21 | + SOCKET_NO_UPDATE_CHECK: '1' |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 24 | + with: |
| 25 | + persist-credentials: false |
| 26 | + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 |
| 27 | + with: |
| 28 | + python-version: '3.12' |
| 29 | + - uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1 |
| 30 | + with: |
| 31 | + key: bughunt-poetry |
| 32 | + save-if: false |
| 33 | + - run: cargo build --locked -p socket-patch-cli |
| 34 | + - name: Install Poetry |
| 35 | + shell: bash |
| 36 | + run: | |
| 37 | + python -m venv "$RUNNER_TEMP/poetry-venv" |
| 38 | + if [ -x "$RUNNER_TEMP/poetry-venv/Scripts/python.exe" ]; then PY="$RUNNER_TEMP/poetry-venv/Scripts/python.exe"; P="$RUNNER_TEMP/poetry-venv/Scripts/poetry.exe"; else PY="$RUNNER_TEMP/poetry-venv/bin/python"; P="$RUNNER_TEMP/poetry-venv/bin/poetry"; fi |
| 39 | + "$PY" -m pip install -q "poetry==${{ matrix.poetry }}" |
| 40 | + echo "POETRY_BIN=$P" >> "$GITHUB_ENV" |
| 41 | + - name: Probe agent-mode Poetry venv discovery |
| 42 | + shell: bash |
| 43 | + run: | |
| 44 | + cat > "$RUNNER_TEMP/probe.py" <<'PROBE_EOF' |
| 45 | + import base64, hashlib, io, json, os, re, shutil, subprocess, sys, tempfile, threading, urllib.request, zipfile |
| 46 | + from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer |
| 47 | +
|
| 48 | + CLI = os.path.abspath(sys.argv[1]); POETRY = sys.argv[2] |
| 49 | + UUID = "3c5e7a9b-1d3f-4b5d-8f7a-9b1d3f5a7c9e" |
| 50 | + WHL = "https://files.pythonhosted.org/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl" |
| 51 | + before = zipfile.ZipFile(io.BytesIO(urllib.request.urlopen(WHL).read())).read("six.py") |
| 52 | + after = before + b"\n# SOCKET-PATCHED\nSOCKET_PATCHED = 1\n" |
| 53 | + g = lambda b: hashlib.sha256(b"blob %d\0" % len(b) + b).hexdigest() |
| 54 | + API_PURL = "pkg:pypi/six@1.16.0?artifact_id=py2-py3-none-any-whl" |
| 55 | + VIEW = {"uuid": UUID, "purl": API_PURL, "publishedAt": "2026-09-01T00:00:00Z", |
| 56 | + "files": {"six.py": {"beforeHash": g(before), "afterHash": g(after), "blobContent": base64.b64encode(after).decode()}}, |
| 57 | + "vulnerabilities": {"GHSA-aaaa-bbbb-cccc": {"cves": ["CVE-2026-0001"], "summary": "s", "severity": "high", "description": "d"}}, |
| 58 | + "description": "x", "license": "MIT", "tier": "free"} |
| 59 | + PATCH = {"uuid": UUID, "purl": API_PURL, "tier": "free", "cveIds": ["CVE-2026-0001"], "ghsaIds": ["GHSA-aaaa-bbbb-cccc"], "severity": "HIGH", "title": "t"} |
| 60 | +
|
| 61 | +
|
| 62 | + class H(BaseHTTPRequestHandler): |
| 63 | + def log_message(self, *a): pass |
| 64 | + def out(self, obj): |
| 65 | + b = json.dumps(obj).encode(); self.send_response(200); self.send_header("Content-Type", "application/json") |
| 66 | + self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b) |
| 67 | + def do_GET(self): |
| 68 | + if "/patches/view/" in self.path: return self.out(VIEW) |
| 69 | + if "/by-package/" in self.path: return self.out({"patches": [dict(PATCH, publishedAt="2026-09-01T00:00:00Z", description="x", license="MIT", vulnerabilities={})], "canAccessPaidPatches": False}) |
| 70 | + self.send_response(404); self.end_headers() |
| 71 | + def do_POST(self): |
| 72 | + raw = self.rfile.read(int(self.headers.get("Content-Length") or 0)).decode() |
| 73 | + if self.path.endswith("/patches/batch"): |
| 74 | + has = "pkg:pypi/six@1.16.0" in raw |
| 75 | + return self.out({"packages": [{"purl": "pkg:pypi/six@1.16.0", "patches": [PATCH]}] if has else [], "canAccessPaidPatches": False}) |
| 76 | + self.out({}) |
| 77 | +
|
| 78 | +
|
| 79 | + srv = ThreadingHTTPServer(("127.0.0.1", 0), H); threading.Thread(target=srv.serve_forever, daemon=True).start() |
| 80 | + API = "http://127.0.0.1:%d" % srv.server_address[1] |
| 81 | +
|
| 82 | + NAMED = '[tool.poetry]\nname = "probe-named"\npackage-mode = false\n\n[tool.poetry.dependencies]\npython = ">=3.8"\nsix = "1.16.0"\n' |
| 83 | + NAMELESS = '[tool.poetry]\npackage-mode = false\n\n[tool.poetry.dependencies]\npython = ">=3.8"\nsix = "1.16.0"\n' |
| 84 | + BOTH = '[project]\nname = "pep-name"\nversion = "0.1.0"\nrequires-python = ">=3.8"\ndependencies = ["six==1.16.0"]\n\n[tool.poetry]\nname = "legacy-name"\npackage-mode = false\n' |
| 85 | + CASES = [("named-default", NAMED, None, False), ("nameless-nonpackage", NAMELESS, None, False), |
| 86 | + ("project-and-tool-name", BOTH, None, False), ("inproject-false-stray-venv", NAMED.replace("probe-named", "probe-ipf"), "[virtualenvs]\nin-project = false\n", True)] |
| 87 | +
|
| 88 | + env = {k: v for k, v in os.environ.items() if not k.startswith(("POETRY_", "VIRTUAL_ENV"))} |
| 89 | + env.update(POETRY_NO_INTERACTION="1", SOCKET_API_URL=API, SOCKET_API_TOKEN="fake", SOCKET_ORG_SLUG="test-org", |
| 90 | + SOCKET_NO_CONFIG="1", SOCKET_NO_UPDATE_CHECK="1", SOCKET_TELEMETRY_DISABLED="1") |
| 91 | + ver = subprocess.run([POETRY, "--version"], capture_output=True, text=True).stdout.strip() |
| 92 | + base = tempfile.mkdtemp(prefix="probe dir ") # space in path on purpose |
| 93 | + rows = [] |
| 94 | + for name, pyproject, poetry_toml, stray in CASES: |
| 95 | + d = os.path.join(base, name); os.makedirs(d) |
| 96 | + open(os.path.join(d, "pyproject.toml"), "w").write(pyproject) |
| 97 | + if poetry_toml: open(os.path.join(d, "poetry.toml"), "w").write(poetry_toml) |
| 98 | + if stray: subprocess.run([sys.executable, "-m", "venv", ".venv"], cwd=d, check=True) |
| 99 | + r = subprocess.run([POETRY, "install", "--no-root"], cwd=d, env=env, capture_output=True, text=True) |
| 100 | + if r.returncode != 0: |
| 101 | + rows.append((name, "poetry-install-failed", r.stdout[-300:] + r.stderr[-300:], "", "")); continue |
| 102 | + venv = subprocess.run([POETRY, "env", "info", "-p"], cwd=d, env=env, capture_output=True, text=True).stdout.strip() |
| 103 | + six = subprocess.run([POETRY, "run", "python", "-c", "import six;print(six.__file__)"], cwd=d, env=env, capture_output=True, text=True).stdout.strip() |
| 104 | + s = subprocess.run([CLI, "scan", "--mode", "agent", "--json", "--yes"], cwd=d, env=env, capture_output=True, text=True) |
| 105 | + try: |
| 106 | + j = json.loads(s.stdout[s.stdout.find("{"):]) |
| 107 | + acts = [(p.get("action"), p.get("errorCode")) for p in j.get("apply", {}).get("patches", [])] |
| 108 | + st = "%s scanned=%s" % (j.get("status"), j.get("scannedPackages")) |
| 109 | + except Exception as e: |
| 110 | + acts, st = [], "nojson %s %s" % (e, (s.stdout + s.stderr)[-300:]) |
| 111 | + patched = six and os.path.isfile(six) and b"SOCKET_PATCHED" in open(six, "rb").read() |
| 112 | + rows.append((name, "exit=%d %s" % (s.returncode, st), str(acts), os.path.basename(venv), "PATCHED" if patched else "UNPATCHED")) |
| 113 | + print("== %s | %s | cwd=%s" % (ver, sys.platform, base)) |
| 114 | + for r in rows: print(" | ".join(r)) |
| 115 | + PROBE_EOF |
| 116 | + CLI=target/debug/socket-patch; [ -f "$CLI.exe" ] && CLI="$CLI.exe" |
| 117 | + python "$RUNNER_TEMP/probe.py" "$CLI" "$POETRY_BIN" |
0 commit comments