🐛 Accept zero and negative property-test environment seeds

Require an integer seed while retaining positive counts. Seed zero is a
valid test.check replay seed and must behave like the explicit option.

Validation: PENPOT_GEN_SEED=0 schema and runner suites pass,
44 tests / 119 assertions. The regression failed before the fix.

AI-assisted-by: GPT-6
This commit is contained in:
alonso.torres 2026-10-23 09:34:33 +02:00
parent a8bad1c8c8
commit 9083f5e232
2 changed files with 14 additions and 3 deletions

View File

@ -94,9 +94,10 @@
[name]
(when-let [value #?(:clj (System/getenv name)
:cljs (some-> js/globalThis .-process .-env (aget name)))]
(let [number #?(:clj (parse-long value) :cljs (js/Number value))]
(when-not (and (integer? number) (pos? number))
(throw (ex-info (str name " must be a positive integer")
(let [number #?(:clj (parse-long value) :cljs (js/Number value))
seed? (= name "PENPOT_GEN_SEED")]
(when-not (and (integer? number) (or seed? (pos? number)))
(throw (ex-info (str name (if seed? " must be an integer" " must be a positive integer"))
{:variable name :value value})))
number)))

View File

@ -29,3 +29,13 @@
{:type :shrunk :seed 712 :shrunk {:smallest [10]}}))]
(t/is (str/includes? output "712"))
(t/is (str/includes? output ":smallest [10]"))))
(t/deftest check-uses-the-environment-seed
(let [seed (atom nil)
expected #?(:clj (some-> (System/getenv "PENPOT_GEN_SEED") parse-long)
:cljs (some-> js/globalThis .-process .-env .-PENPOT_GEN_SEED js/Number))]
(smt/check! (smt/for [value gen/nat] (<= 0 value))
:num 1
:reporter-fn #(when (= :complete (:type %)) (reset! seed (:seed %))))
(when (some? expected)
(t/is (= expected @seed)))))