webcompy-cli 0.0.14__py3-none-any.whl

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.
Files changed (47) hide show
  1. webcompy_cli/__init__.py +20 -0
  2. webcompy_cli/_argparser.py +232 -0
  3. webcompy_cli/_browser_probes.py +648 -0
  4. webcompy_cli/_browser_test_harness.py +554 -0
  5. webcompy_cli/_build.py +425 -0
  6. webcompy_cli/_console_types.py +15 -0
  7. webcompy_cli/_dependency_resolver.py +301 -0
  8. webcompy_cli/_dualrun_pytest_plugin.py +130 -0
  9. webcompy_cli/_exception.py +9 -0
  10. webcompy_cli/_generate.py +224 -0
  11. webcompy_cli/_init_project.py +54 -0
  12. webcompy_cli/_inspect.py +741 -0
  13. webcompy_cli/_inspect_pyexec.py +244 -0
  14. webcompy_cli/_lock.py +82 -0
  15. webcompy_cli/_lockfile.py +396 -0
  16. webcompy_cli/_lockfile_sync.py +343 -0
  17. webcompy_cli/_output.py +150 -0
  18. webcompy_cli/_prebuild.py +661 -0
  19. webcompy_cli/_pwa.py +474 -0
  20. webcompy_cli/_pyodide_downloader.py +113 -0
  21. webcompy_cli/_pyodide_lock.py +74 -0
  22. webcompy_cli/_runtime_downloader.py +222 -0
  23. webcompy_cli/_server.py +568 -0
  24. webcompy_cli/_static_files.py +27 -0
  25. webcompy_cli/_utils.py +72 -0
  26. webcompy_cli/_version_sweep.py +213 -0
  27. webcompy_cli/_wheel_builder.py +509 -0
  28. webcompy_cli/config/__init__.py +23 -0
  29. webcompy_cli/config/_build_config.py +168 -0
  30. webcompy_cli/config/_pwa_config.py +203 -0
  31. webcompy_cli/config/_server_config.py +53 -0
  32. webcompy_cli/py.typed +0 -0
  33. webcompy_cli/template_data/app/__init__.py +0 -0
  34. webcompy_cli/template_data/app/app.py +22 -0
  35. webcompy_cli/template_data/app/components/__init__.py +0 -0
  36. webcompy_cli/template_data/app/components/fizzbuzz.py +117 -0
  37. webcompy_cli/template_data/app/components/home.py +15 -0
  38. webcompy_cli/template_data/app/components/input.py +34 -0
  39. webcompy_cli/template_data/app/components/navigation.py +36 -0
  40. webcompy_cli/template_data/app/components/not_found.py +22 -0
  41. webcompy_cli/template_data/app/components/root.py +16 -0
  42. webcompy_cli/template_data/app/router.py +17 -0
  43. webcompy_cli/template_data/webcompy_config.py +12 -0
  44. webcompy_cli-0.0.14.dist-info/METADATA +53 -0
  45. webcompy_cli-0.0.14.dist-info/RECORD +47 -0
  46. webcompy_cli-0.0.14.dist-info/WHEEL +4 -0
  47. webcompy_cli-0.0.14.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,213 @@
1
+ """Version-bump sweep: diff probe (and dual-run) outcomes across two PyScript versions.
2
+
3
+ The sweep executes the probe battery twice with the same harness code — once
4
+ against the pinned runtime assets and once against a candidate version's
5
+ assets (downloaded via the existing runtime downloader when
6
+ ``WEBCOMPY_PYSCRIPT_CANDIDATE`` is set) — and buckets each probe id into
7
+ ``only_pinned_pass`` / ``only_candidate_pass`` / ``both_pass`` / ``both_fail``.
8
+ A probe that passes at the pinned version but fails at the candidate is a
9
+ regression and fails the sweep. Candidate assets are never promoted
10
+ automatically; the sweep is informational except for regressions.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import argparse
16
+ import json
17
+ import sys
18
+ from dataclasses import dataclass, field
19
+ from pathlib import Path
20
+
21
+ SWEEP_ARTIFACT_NAME = "browser-version-sweep.json"
22
+
23
+ PROBE_BUCKETS = ("only_pinned_pass", "only_candidate_pass", "both_pass", "both_fail")
24
+
25
+
26
+ @dataclass
27
+ class SweepDiff:
28
+ """Bucketed diff of probe outcomes between two PyScript versions.
29
+
30
+ Attributes:
31
+ pinned_version: Pinned ``PYSCRIPT_VERSION`` string.
32
+ candidate_version: Candidate version string under evaluation.
33
+ probes: Probe-id buckets keyed ``only_pinned_pass``,
34
+ ``only_candidate_pass``, ``both_pass``, and ``both_fail``.
35
+ dualrun: Same bucket shape for the dual-run tier when both runs
36
+ produced dual-run reports; ``None`` otherwise.
37
+
38
+ """
39
+
40
+ pinned_version: str
41
+ candidate_version: str
42
+ probes: dict[str, list[str]] = field(default_factory=dict)
43
+ dualrun: dict[str, list[str]] | None = None
44
+
45
+ @property
46
+ def regressions(self) -> list[str]:
47
+ """Probe ids that passed at the pinned version but fail at the candidate."""
48
+ return list(self.probes.get("only_pinned_pass", []))
49
+
50
+
51
+ def diff_probe_reports(
52
+ pinned_outcomes: dict[str, str],
53
+ candidate_outcomes: dict[str, str],
54
+ ) -> dict[str, list[str]]:
55
+ """Bucket probe ids by pass/fail combination across two versions.
56
+
57
+ Args:
58
+ pinned_outcomes: Probe-id-to-outcome mapping at the pinned version.
59
+ candidate_outcomes: Same-shaped mapping at the candidate version.
60
+
61
+ Returns:
62
+ Buckets keyed ``only_pinned_pass``, ``only_candidate_pass``,
63
+ ``both_pass``, and ``both_fail``; skipped probes are excluded.
64
+
65
+ """
66
+ buckets: dict[str, list[str]] = {name: [] for name in PROBE_BUCKETS}
67
+ for probe_id in sorted(set(pinned_outcomes) & set(candidate_outcomes)):
68
+ pinned_passed = pinned_outcomes[probe_id] == "passed"
69
+ candidate_passed = candidate_outcomes[probe_id] == "passed"
70
+ if pinned_outcomes[probe_id] == "skipped" or candidate_outcomes[probe_id] == "skipped":
71
+ continue
72
+ if pinned_passed and candidate_passed:
73
+ buckets["both_pass"].append(probe_id)
74
+ elif pinned_passed:
75
+ buckets["only_pinned_pass"].append(probe_id)
76
+ elif candidate_passed:
77
+ buckets["only_candidate_pass"].append(probe_id)
78
+ else:
79
+ buckets["both_fail"].append(probe_id)
80
+ return buckets
81
+
82
+
83
+ def build_sweep_diff(
84
+ pinned_version: str,
85
+ candidate_version: str,
86
+ pinned_report: dict,
87
+ candidate_report: dict,
88
+ *,
89
+ pinned_dualrun: dict | None = None,
90
+ candidate_dualrun: dict | None = None,
91
+ ) -> SweepDiff:
92
+ """Assemble a :class:`SweepDiff` from two plugin outcome reports.
93
+
94
+ Args:
95
+ pinned_version: Pinned version identifier.
96
+ candidate_version: Candidate version identifier.
97
+ pinned_report: Plugin report (``outcomes`` mapping) at the pin.
98
+ candidate_report: Plugin report at the candidate version.
99
+ pinned_dualrun: Optional dual-run artifact payload at the pin.
100
+ candidate_dualrun: Optional dual-run artifact payload at the candidate.
101
+
102
+ Returns:
103
+ The assembled diff including dual-run buckets when both payloads are
104
+ present and share test ids.
105
+
106
+ """
107
+ diff = SweepDiff(
108
+ pinned_version=pinned_version,
109
+ candidate_version=candidate_version,
110
+ probes=diff_probe_reports(pinned_report["outcomes"], candidate_report["outcomes"]),
111
+ )
112
+ if pinned_dualrun is not None and candidate_dualrun is not None:
113
+ cpython = pinned_dualrun.get("cpython_map", {})
114
+
115
+ def normalize(outcome: str) -> str:
116
+ return outcome if outcome in ("passed", "failed", "skipped") else "failed"
117
+
118
+ pinned_in_page = {
119
+ test_id: normalize(outcome)
120
+ for test_id, outcome in pinned_dualrun.get("pyscript_map", {}).items()
121
+ if test_id in cpython
122
+ }
123
+ candidate_in_page = {
124
+ test_id: normalize(outcome)
125
+ for test_id, outcome in candidate_dualrun.get("pyscript_map", {}).items()
126
+ if test_id in cpython
127
+ }
128
+ diff.dualrun = diff_probe_reports(pinned_in_page, candidate_in_page)
129
+ return diff
130
+
131
+
132
+ def write_sweep_artifact(diff: SweepDiff, artifacts_dir: Path) -> Path:
133
+ """Persist the sweep diff as ``browser-version-sweep.json``.
134
+
135
+ Args:
136
+ diff: Assembled sweep diff.
137
+ artifacts_dir: Destination directory (created when missing).
138
+
139
+ Returns:
140
+ The path of the written artifact.
141
+
142
+ """
143
+ artifacts_dir.mkdir(parents=True, exist_ok=True)
144
+ path = artifacts_dir / SWEEP_ARTIFACT_NAME
145
+ payload: dict = {
146
+ "pinned_version": diff.pinned_version,
147
+ "candidate_version": diff.candidate_version,
148
+ "probes": {name: sorted(ids) for name, ids in diff.probes.items()},
149
+ "regressions": sorted(diff.regressions),
150
+ }
151
+ if diff.dualrun is not None:
152
+ payload["dualrun"] = {name: sorted(ids) for name, ids in diff.dualrun.items()}
153
+ path.write_text(json.dumps(payload, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
154
+ return path
155
+
156
+
157
+ def main(argv: list[str] | None = None) -> int:
158
+ """CLI entry comparing two outcome reports and writing the sweep artifact.
159
+
160
+ Exits nonzero when any probe regressed (passed at the pinned version but
161
+ failed at the candidate), signaling the CI job to fail.
162
+
163
+ Args:
164
+ argv: Command-line arguments (defaults to ``sys.argv[1:]``).
165
+
166
+ Returns:
167
+ Process exit code: 0 on no regression, 1 on regression or error.
168
+
169
+ Raises:
170
+ ValueError: When a report file lacks the ``outcomes`` mapping
171
+ (reported as a usage error, not propagated to the caller).
172
+
173
+ """
174
+ parser = argparse.ArgumentParser(
175
+ prog="webcompy-cli._version_sweep",
176
+ description="Diff probe outcomes across two PyScript versions.",
177
+ )
178
+ parser.add_argument("pinned_report", type=Path, help="Outcome JSON from the pinned-version run")
179
+ parser.add_argument("candidate_report", type=Path, help="Outcome JSON from the candidate-version run")
180
+ parser.add_argument("--pinned-version", default="pinned", help="Label of the pinned version")
181
+ parser.add_argument("--candidate-version", required=True, help="Label of the candidate version")
182
+ parser.add_argument("--artifacts-dir", type=Path, default=Path("artifacts"))
183
+ args = parser.parse_args(argv)
184
+
185
+ try:
186
+ pinned = json.loads(args.pinned_report.read_text(encoding="utf-8"))
187
+ candidate = json.loads(args.candidate_report.read_text(encoding="utf-8"))
188
+ if not isinstance(pinned.get("outcomes"), dict) or not isinstance(candidate.get("outcomes"), dict):
189
+ raise ValueError("report is missing the 'outcomes' mapping")
190
+ except (OSError, json.JSONDecodeError, ValueError) as e:
191
+ print(f"error reading reports: {e}", file=sys.stderr)
192
+ return 1
193
+
194
+ diff = build_sweep_diff(
195
+ args.pinned_version,
196
+ args.candidate_version,
197
+ pinned,
198
+ candidate,
199
+ )
200
+ artifact = write_sweep_artifact(diff, args.artifacts_dir)
201
+ print(f"sweep artifact: {artifact}")
202
+ for name in PROBE_BUCKETS:
203
+ print(f"{name}: {len(diff.probes[name])}")
204
+ if diff.regressions:
205
+ print(f"REGRESSION: {len(diff.regressions)} probe(s) failed at the candidate version:", file=sys.stderr)
206
+ for probe_id in diff.regressions:
207
+ print(f" - {probe_id}", file=sys.stderr)
208
+ return 1
209
+ return 0
210
+
211
+
212
+ if __name__ == "__main__":
213
+ sys.exit(main())