CLI: non-finite threshold values are accepted and NaN silently disables the score gate

Open Beginner friendly
#38 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
cli

Research direction

The threshold is parsed in parse_args in src/crapper/cli.py (around lines 134-142), which calls float(raw) and only catches ValueError. The gate is _threshold_status (around lines 294-304), where max(scored) > options.threshold is false for NaN. Start by running the reproduction script in the issue, then reject NaN and positive infinity during parsing with a nonzero usage error. Done means --threshold nan and --threshold inf fail before analysis, and a finite threshold of 100 still returns status 2 for a score of 1,000,000.

Written by the indexing model from the issue text.

Description

Summary

--threshold nan is accepted as an analysis option. Since every greater-than comparison against NaN is false, even a scored entry of 1,000,000 passes. Positive infinity is also accepted without finite-value validation and passes every finite score.

Verified against default branch master at c757ec79a6c15dc815238bbd9c2f4601eb54d3cc.

Minimal reproduction

Requires Git and Python 3.9+ only. No package installation or project imports. This extracts the named source definitions with the standard-library AST and exercises them directly; it does not run the full CLI or a language parser.

work=$(mktemp -d)
git clone https://github.com/unclebob/crapper.git "$work/crapper"
git -C "$work/crapper" checkout --detach c757ec79a6c15dc815238bbd9c2f4601eb54d3cc
python3 - "$work/crapper" <<'PY'
import ast
import re
import sys
from dataclasses import dataclass, field
from pathlib import Path
from tempfile import TemporaryDirectory
from types import SimpleNamespace

checkout = Path(sys.argv[1])

def extract(relative, names):
    tree = ast.parse((checkout / relative).read_text())
    selected = [node for node in tree.body
                if isinstance(node, (ast.FunctionDef, ast.ClassDef))
                and node.name in names]
    assert {node.name for node in selected} == set(names)
    module = ast.Module(body=[ast.ImportFrom(module='__future__',
        names=[ast.alias(name='annotations')], level=0)] + selected,
        type_ignores=[])
    exec(compile(ast.fix_missing_locations(module), relative, 'exec'), globals())

HELP = ''
extract('src/crapper/cli.py', ['Options', '_take', 'parse_args', '_threshold_status'])
entries = [SimpleNamespace(crap=1000000.0)]
for raw in ['nan', 'NaN', 'inf', 'Infinity', '100']:
    options = parse_args(['--threshold', raw])
    status = _threshold_status(options, entries)
    print(raw, 'action=' + options.action,
          'threshold=' + str(options.threshold), 'gate_status=' + str(status))
    assert options.action == 'analyze'
    assert status == (2 if raw == '100' else 0)
PY

Expected

Reject non-finite threshold values during argument parsing with a nonzero usage/error status. Do not start analysis for NaN or infinity. A finite threshold of 100 should still reject a score of 1,000,000.

Actual

nan, NaN, inf, and Infinity all parse with action analyze and return gate status 0 for the scored entry. The finite control 100 returns status 2.

The assertions in the reproduction confirm the current incorrect behavior, rather than asserting the intended fix.

Cause and source

parse_args converts the raw string with float(raw) and checks only ValueError. _threshold_status uses max(scored) > options.threshold, which is false for NaN. No finite-value check intervenes.

Suggested regression test

Add argument-parser tests requiring an error for case variants of NaN and positive infinity. Keep finite-value and threshold-equality tests. Assert a finite threshold below the sample score still returns status 2. Negative infinity is already rejected by the option-value handling; the demonstrated missing validation concerns accepted non-finite inputs.

Dominant language
Python
Stars
255
Forks
101
Avg merge
7m
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from unclebob/crapper

All issues in unclebob/crapper

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.