pywrit 0.2.10__tar.gz → 0.2.11__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pywrit
3
- Version: 0.2.10
3
+ Version: 0.2.11
4
4
  Summary: Python client + CLI for Writ — the gate before the write
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://github.com/withwrit/pywrit
@@ -157,6 +157,12 @@ webpack.config.*) are suppressed by default: the report counts them per
157
157
  class and names every suppressed path instead of listing them as findings.
158
158
  Pass `--include-non-product` to report them like any other finding.
159
159
 
160
+ Every scan report ends with a one-line pointer to the Writ GitHub App
161
+ (install: https://github.com/apps/writ-scanner, guide:
162
+ https://docs.withwrit.com/git-hub-app), which runs the scan on every push
163
+ and pull request; the JSON report (`--format json`) carries the same
164
+ pointer under `github_app`.
165
+
160
166
  TS/JS is **scan-only**: findings are listed with verbs for your policy file,
161
167
  but `writ scan --apply` never rewrites TS/JS files — gate those by hand.
162
168
  Covered patterns: `fetch`/`axios` writes, `fs` writes, SQL through knex-style
@@ -135,6 +135,12 @@ webpack.config.*) are suppressed by default: the report counts them per
135
135
  class and names every suppressed path instead of listing them as findings.
136
136
  Pass `--include-non-product` to report them like any other finding.
137
137
 
138
+ Every scan report ends with a one-line pointer to the Writ GitHub App
139
+ (install: https://github.com/apps/writ-scanner, guide:
140
+ https://docs.withwrit.com/git-hub-app), which runs the scan on every push
141
+ and pull request; the JSON report (`--format json`) carries the same
142
+ pointer under `github_app`.
143
+
138
144
  TS/JS is **scan-only**: findings are listed with verbs for your policy file,
139
145
  but `writ scan --apply` never rewrites TS/JS files — gate those by hand.
140
146
  Covered patterns: `fetch`/`axios` writes, `fs` writes, SQL through knex-style
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pywrit"
7
- version = "0.2.10"
7
+ version = "0.2.11"
8
8
  description = "Python client + CLI for Writ — the gate before the write"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -27,7 +27,7 @@ from .errors import (
27
27
  WritError,
28
28
  )
29
29
 
30
- __version__ = "0.2.10"
30
+ __version__ = "0.2.11"
31
31
 
32
32
  __all__ = [
33
33
  "WritClient",
@@ -591,6 +591,19 @@ _SCORE_GAPS = [
591
591
  "indirect writes through shared HTTP clients several layers down",
592
592
  ]
593
593
 
594
+ # Every scan report closes with a pointer at the GitHub App: the local scan
595
+ # is invisible by design, the app is the visible surface (a scan on every
596
+ # push and pull request, check runs, history in the portal). The same
597
+ # pointer rides the JSON report under `github_app` for machine consumers.
598
+ # Text and JSON share these constants so they cannot drift.
599
+ _GITHUB_APP_INSTALL_URL = "https://github.com/apps/writ-scanner"
600
+ _GITHUB_APP_DOCS_URL = "https://docs.withwrit.com/git-hub-app"
601
+ _GITHUB_APP_NOTE = ("Run this scan on every push and pull request with the "
602
+ "Writ GitHub App: check runs on each change, history in "
603
+ "the portal.")
604
+ _GITHUB_APP_LINE = "%s Install: %s (guide: %s)" % (
605
+ _GITHUB_APP_NOTE, _GITHUB_APP_INSTALL_URL, _GITHUB_APP_DOCS_URL)
606
+
594
607
 
595
608
  def _risk_tier(verb):
596
609
  """Classify an inferred verb (domain.action) into high/medium/low risk.
@@ -1433,6 +1446,11 @@ def print_scan_json(root, files, skipped, sites, gated_funcs, tsjs, ts_sites):
1433
1446
  "files_scanned": len(files) + len(tsjs.get("files", [])),
1434
1447
  "files_skipped": len(skipped) + len(tsjs.get("skipped", [])),
1435
1448
  "tsjs_hint": bool(tsjs.get("missing_extra")),
1449
+ "github_app": {
1450
+ "install_url": _GITHUB_APP_INSTALL_URL,
1451
+ "docs_url": _GITHUB_APP_DOCS_URL,
1452
+ "note": _GITHUB_APP_NOTE,
1453
+ },
1436
1454
  "findings": _scan_findings_json(root, sites, gated_funcs, tsjs,
1437
1455
  ts_sites),
1438
1456
  }
@@ -1616,6 +1634,7 @@ def scan_cmd(args):
1616
1634
 
1617
1635
  if args.score:
1618
1636
  print_score_report(root, sites, gated_funcs)
1637
+ print(_GITHUB_APP_LINE)
1619
1638
  return 0
1620
1639
 
1621
1640
  print("writ scan: %s" % root)
@@ -1675,6 +1694,7 @@ def scan_cmd(args):
1675
1694
  "gate them by hand).")
1676
1695
  else:
1677
1696
  print("nothing to instrument.")
1697
+ print(_GITHUB_APP_LINE)
1678
1698
  return 0
1679
1699
 
1680
1700
  do_apply = args.apply
@@ -1696,7 +1716,10 @@ def scan_cmd(args):
1696
1716
  if not args.key:
1697
1717
  print("error: --push-policy needs --key", file=sys.stderr)
1698
1718
  return 2
1699
- return request("PUT", "/v1/policy", verbs, key=args.key)
1719
+ code = request("PUT", "/v1/policy", verbs, key=args.key)
1720
+ print(_GITHUB_APP_LINE)
1721
+ return code
1722
+ print(_GITHUB_APP_LINE)
1700
1723
  return 0
1701
1724
 
1702
1725
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pywrit
3
- Version: 0.2.10
3
+ Version: 0.2.11
4
4
  Summary: Python client + CLI for Writ — the gate before the write
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://github.com/withwrit/pywrit
@@ -157,6 +157,12 @@ webpack.config.*) are suppressed by default: the report counts them per
157
157
  class and names every suppressed path instead of listing them as findings.
158
158
  Pass `--include-non-product` to report them like any other finding.
159
159
 
160
+ Every scan report ends with a one-line pointer to the Writ GitHub App
161
+ (install: https://github.com/apps/writ-scanner, guide:
162
+ https://docs.withwrit.com/git-hub-app), which runs the scan on every push
163
+ and pull request; the JSON report (`--format json`) carries the same
164
+ pointer under `github_app`.
165
+
160
166
  TS/JS is **scan-only**: findings are listed with verbs for your policy file,
161
167
  but `writ scan --apply` never rewrites TS/JS files — gate those by hand.
162
168
  Covered patterns: `fetch`/`axios` writes, `fs` writes, SQL through knex-style
@@ -380,6 +380,101 @@ class NonProductScanTest(unittest.TestCase):
380
380
  cli._tsjs_non_product_class(root / "lib" / "core.js", root))
381
381
 
382
382
 
383
+ class GitHubAppLineTest(unittest.TestCase):
384
+ """Regression: every scan report ends with the GitHub App line.
385
+
386
+ The local scan is invisible by design; the GitHub App is the visible
387
+ surface. The text report's last line points at it on every outcome
388
+ (findings found, zero findings, suppressed-only, --score), and the
389
+ JSON report carries the same pointer under `github_app`.
390
+ """
391
+
392
+ LINE = ("Run this scan on every push and pull request with the Writ "
393
+ "GitHub App: check runs on each change, history in the portal. "
394
+ "Install: https://github.com/apps/writ-scanner "
395
+ "(guide: https://docs.withwrit.com/git-hub-app)")
396
+
397
+ FINDING_REPO = {
398
+ "app.py": ('import requests\n\n\n'
399
+ 'def send(url):\n'
400
+ ' return requests.post(url, json={})\n'),
401
+ }
402
+ CLEAN_REPO = {
403
+ "app.py": ('def read():\n'
404
+ ' return open("/tmp/x").read()\n'),
405
+ }
406
+
407
+ def _repo(self, root, files):
408
+ for rel, src in files.items():
409
+ p = root / rel
410
+ p.parent.mkdir(parents=True, exist_ok=True)
411
+ p.write_text(src)
412
+
413
+ def _last_line(self, out):
414
+ lines = [ln for ln in out.splitlines() if ln.strip()]
415
+ return lines[-1] if lines else ""
416
+
417
+ def test_findings_found_run_ends_with_app_line(self):
418
+ with tempfile.TemporaryDirectory() as td:
419
+ root = pathlib.Path(td) / "repo"
420
+ root.mkdir()
421
+ self._repo(root, self.FINDING_REPO)
422
+ code, out = _run_scan(root)
423
+ self.assertEqual(code, 0)
424
+ self.assertIn("write sites: 1 in 1 function(s)", out)
425
+ self.assertEqual(self._last_line(out), self.LINE)
426
+
427
+ def test_zero_findings_run_ends_with_app_line(self):
428
+ with tempfile.TemporaryDirectory() as td:
429
+ root = pathlib.Path(td) / "repo"
430
+ root.mkdir()
431
+ self._repo(root, self.CLEAN_REPO)
432
+ code, out = _run_scan(root)
433
+ self.assertEqual(code, 0)
434
+ self.assertIn("write sites: 0 in 0 function(s)", out)
435
+ self.assertEqual(self._last_line(out), self.LINE)
436
+
437
+ def test_score_only_run_ends_with_app_line(self):
438
+ with tempfile.TemporaryDirectory() as td:
439
+ root = pathlib.Path(td) / "repo"
440
+ root.mkdir()
441
+ self._repo(root, self.FINDING_REPO)
442
+ code, out = _run_scan(root, score=True)
443
+ self.assertEqual(code, 0)
444
+ self.assertEqual(self._last_line(out), self.LINE)
445
+
446
+ def test_json_report_carries_github_app_field(self):
447
+ import json as j
448
+ with tempfile.TemporaryDirectory() as td:
449
+ root = pathlib.Path(td) / "repo"
450
+ root.mkdir()
451
+ self._repo(root, self.FINDING_REPO)
452
+ code, out = _run_scan(root, format="json")
453
+ self.assertEqual(code, 0, out)
454
+ app = j.loads(out)["github_app"]
455
+ self.assertEqual(app, {
456
+ "install_url": "https://github.com/apps/writ-scanner",
457
+ "docs_url": "https://docs.withwrit.com/git-hub-app",
458
+ "note": ("Run this scan on every push and pull request with "
459
+ "the Writ GitHub App: check runs on each change, "
460
+ "history in the portal."),
461
+ })
462
+
463
+ @unittest.skipUnless(HAVE_EXTRA, "polyglot extra not installed")
464
+ def test_suppressed_only_run_ends_with_app_line(self):
465
+ with tempfile.TemporaryDirectory() as td:
466
+ root = pathlib.Path(td) / "repo"
467
+ root.mkdir()
468
+ self._repo(root, {
469
+ "docs/scripts/tool.js": NonProductScanTest.WRITE * 3,
470
+ })
471
+ code, out = _run_scan(root)
472
+ self.assertEqual(code, 0)
473
+ self.assertIn("ts/js write sites: 0 in 0 function(s)", out)
474
+ self.assertIn("ts/js non-product: 3 site(s) suppressed", out)
475
+ self.assertEqual(self._last_line(out), self.LINE)
476
+
477
+
383
478
  class CliSyncTest(unittest.TestCase):
384
479
  def test_download_copy_is_byte_identical(self):
385
480
  web = HERE.parent.parent / "gate" / "web" / "writ"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes