quality-delta: a Bash test that captures `x=$(cmd)` and never reads the command's exit status passes on a crash (new defect-shape facet, report-only)

Aperta
#876 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
bash, cpp
Ambito
testing, tooling

Direzione di ricerca

Read src/shstatus.h to understand how command status checks are analyzed, then inspect src/defectshape.h, especially Script::unreadRcSites and vacuousJudgmentSites. Add the report-only facet and its coverage in test/defectshapecheck.sh, following the zero-evidence section. Done means the unsafe capture gets one row, the safe variants get none, and the facet is documented across the listed legend and help surfaces with the specified gates passing.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement help wanted

Claim it in this issue first. Size: M. Depends on: nothing. Language: C++ (Bash is the input). You will extend src/defectshape.h. Read src/shstatus.h first: it already answers "does this script test the exit status of each command it runs".

The problem, in user terms

CodeRabbit found the same bug in three of our own test scripts (PRs #808, #819, #825): the test runs the binary inside $( ... ), then passes if the captured text matches. If the binary prints the expected line and then crashes or exits non-zero, the test still prints PASS. --quality-delta is meant to catch defect shapes that review keeps finding by hand, and it says nothing here.

test/statuscheck.sh (unsafe):

#!/usr/bin/env bash
BIN="${BIN:-build/ripwire}"
ok() { echo "ok: $1"; }
no() { echo "FAIL: $1"; FAIL=1; }
out="$( "$BIN" . --legend=compact 2>/dev/null )"
if printf '%s' "$out" | grep -q 'legend'; then ok "legend printed"; else no "legend missing"; fi
exit "${FAIL:-0}"

test/statuscheck_good.sh is the same file with rc=$? read on the capture line and [ "$rc" = 0 ] && in the if.

Actual, with both committed in a scratch repo:

$ ripwire . --quality-delta=HEAD~1..HEAD --no-cache
<quality-delta ... regressions="0" minor="0" ... gating="0" ...></quality-delta>

Expected: a defect-shape row on test/statuscheck.sh for the capture line, and none on statuscheck_good.sh.

The existing vacuous-assert facet does not fire here because it asks what a FAILED run leaves behind (an empty text that an absence-grep reads as PASS). This case is the reverse: the run prints matching text, then fails. The existing zero-evidence facet needs an empty answer too. The three CR threads were measured against the PR ranges on main: 0 rows each.

Where to look

  • src/defectshape.h: enum class Facet (about line 76), kFacetNames, kFacetCount. A new facet adds an entry in each; src/quality.h:1417 has a static_assert that every facet fits the site value's facet bits.
  • src/defectshape.h, Script::unreadRcSites (about line 4190) and vacuousJudgmentSites: the nearest neighbours; copy their scope walk.
  • src/shstatus.h: analyze() gives, per command, whether its status is tested and what consumes it. You should not need to change it. If you do, test/lib/exitstatus.py is its twin and test/gateexitcheck.sh arm (H4) fails when the two disagree.
  • Where an existing facet's name appears (so a new one gets the same coverage): git grep -l zero-evidence lists src/cli.h, src/compactlegend.h, src/verbs_quality.h, docs/COMMANDS.md, docs/EVALS.md, the quality-bar skill pages and about a dozen gates. The commit that added zero-evidence and count-drift (PR #750, changelog.d/cr-qd3-zero-evidence-count-drift.md) is the template for the full set of files.

Suggested approach

  • Shape: a capture x=$( cmd ... ) where cmd is a command under test (shstatus already decides that), the capture's status is read nowhere in its scope (shstatus verdict unchecked, no rc=$?, no || , no if around it, no set -e), and a later judgment reads x positively (grep -q without -v, [ "$x" = ... ], case). That is a site.
  • REPORT-ONLY, like every other facet except format-arity. Many arms ignore status on purpose: precision first, and a missed site is fine.
  • Name it in the style of the others (a short hyphenated noun, for example status-unread). The owner may rename it in review.
  • Stay silent on: a capture followed by a test of $? or rc; a command whose status shstatus says is read; a negative judgment (grep -qv, [ -z "$x" ]), which vacuous-assert already owns; a command that is not under test (shstatus decides).

The test to add (red first)

test/defectshapecheck.sh: a new section in the style of section 4e (zero-evidence) with ds_has_p for the positives and the zero-evidence harness's twin pairs for the negatives (a negative must print no row, and its positive twin must print one, so a vacuous negative arm fails). Positives: the file above, a capture inside a function, a case "$x" in judgment. Negatives: the _good file above, a || no "..." after the capture, a capture read through rc=$? then compared. Run the facet over test/*.sh and put the count of rows in the PR.

Acceptance criteria

  • The unsafe file above prints one defect-shape row with defect="<facet>" and statuscheck_good.sh prints none.
  • The new facet is report-only: gating="0" on every fixture.
  • bash test/defectshapecheck.sh, bash test/qualitykindscheck.sh, bash test/gateexitcheck.sh and the legend gates pass. The legend (--legend=full and compact), --help, docs/COMMANDS.md and the quality-bar skill pages all name the new facet.
  • Precision: run it over test/*.sh on main and list every row. Record how many are real (state the denominator). zero-evidence shipped at 26 of 30; report yours the same way.
  • ripwire . --quality-delta=origin/main..HEAD gates 0.

Size

M: one facet in defectshape.h (about the size of zero-evidence), one gate section, the surface lines in six or seven files.

How to verify locally

cmake -S . -B build && cmake --build build -j      # plain build: no build type
mkdir /tmp/sh-status && cd /tmp/sh-status && git init -q . && mkdir test
# commit a base, then the two scripts above, then:
/path/to/build/ripwire . --quality-delta=HEAD~1..HEAD --no-cache
cd - && bash test/defectshapecheck.sh && bash test/gateexitcheck.sh

Not in scope

Other shells, Python test gates (a different facet), and making the facet gate.


Claiming it only takes a comment here. Contributors are credited by handle in the CHANGELOG entry and the release notes. Thank you!

Lingua principale
C++
Stelle
2.6k
Fork
182
Merge medio
21h 12m
PR unite (30g)
262

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di redhat-et/ripwire

Tutte le issue di redhat-et/ripwire

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.