Skip to content

test(fetchall-guard): add line-shift tolerance and duplicate detection tests (#6872)#7787

Merged
Scottcjn merged 3 commits into
Scottcjn:mainfrom
lequangsang01:fix/6872-fetchall-guard-tests
Jul 1, 2026
Merged

test(fetchall-guard): add line-shift tolerance and duplicate detection tests (#6872)#7787
Scottcjn merged 3 commits into
Scottcjn:mainfrom
lequangsang01:fix/6872-fetchall-guard-tests

Conversation

@lequangsang01

Copy link
Copy Markdown
Contributor

Closes #6872

RTC wallet: RTCfe13452d122263caf633ab1876bd9631133b68b1

Changes

  • Added test_fetchall_guard_ignores_unrelated_line_shifts: verifies adding/removing unrelated lines does NOT trigger the guard
  • Added test_fetchall_guard_catches_new_distinct_call: verifies genuinely new fetchall patterns ARE caught
  • Added test_fetchall_guard_catches_duplicate_content_new_call: verifies additional instances of existing patterns ARE caught
  • All tests validate the line-number-independent normalization already in check_fetchall.sh

Testing

  • All new tests pass
  • Existing tests still pass

@github-actions github-actions Bot added size/S PR: 11-50 lines BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) tests Test suite changes labels Jun 30, 2026

@FakerHideInBush FakerHideInBush left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three concerns before merging:

1. test_fetchall_guard_ignores_unrelated_line_shifts hardcodes PATH=/usr/bin:/bin which will fail on macOS, Windows, and any CI environment where Python is installed outside those paths

result = run_guard(env={"PATH": "/usr/bin:/bin", "FETCHALL_BASELINE": str(TMP_BASELINE)})

This wipes the entire process environment except PATH. If run_guard spawns python3 or the guard script, and Python is in /usr/local/bin (macOS Homebrew) or /home/runner/.local/bin (GitHub Actions), the guard process will fail with command not found or ModuleNotFoundError. Replace with:

env = {**os.environ, "FETCHALL_BASELINE": str(TMP_BASELINE)}
result = run_guard(env=env)

2. The annotation in test_fetchall_guard_ignores_unrelated_line_shifts is on the line BEFORE .fetchall(), not on the same line — if the guard requires inline annotation, this test silently passes a case the guard would actually flag as a violation

The test writes:

def schema_bounded(conn):
    # fetchall-ok: bounded-by-schema
    return conn.execute('SELECT * FROM accounts').fetchall()

The annotation # fetchall-ok is on a separate line, while .fetchall() is at the end of the return statement. If the guard scans for # fetchall-ok annotations on the same line as .fetchall() (which is the pattern used elsewhere in the codebase — e.g. return [dict(r) for r in c.execute(sql, params).fetchall() # fetchall-ok: already-paginated), then the guard would NOT recognize this as annotated, would report it as a new violation, and the test assertion returncode == 0 would fail.

The test should document whether prior-line comments are supported, and if not, the annotation in the test fixture should be placed on the same line as .fetchall().

3. test_fetchall_guard_catches_duplicate_content_new_call does not verify that BOTH violations are reported — a guard that deduplicates by SQL content would pass this test while missing one

result = run_guard()
assert result.returncode == 1
assert "new unannotated .fetchall()" in result.stdout

The assertion only checks that the string appears at least once. If the guard deduplicates by SQL content (SELECT 1) and reports only dup_a, the test passes even though dup_b is silently skipped. Add assertions that both violation sites are reported:

assert "dup_a" in result.stdout
assert "dup_b" in result.stdout

@lequangsang01
lequangsang01 force-pushed the fix/6872-fetchall-guard-tests branch from c3af571 to a2ef121 Compare June 30, 2026 05:05
@github-actions github-actions Bot added size/M PR: 51-200 lines BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) node Node server related api API endpoint related and removed size/S PR: 11-50 lines labels Jun 30, 2026

@jaxint jaxint left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This PR adds comprehensive tests for fetchall guard behavior.

New Tests:

  1. test_fetchall_guard_ignores_unrelated_line_shifts: Verifies adding/removing unrelated lines does NOT trigger the guard
  2. test_fetchall_guard_catches_new_distinct_call: Verifies genuinely new fetchall patterns ARE caught
  3. test_fetchall_guard_catches_duplicate_content_new_call: Verifies additional instances of existing patterns ARE caught

Test Quality:

  • Validates line-number-independent normalization
  • Clear test structure
  • Proper cleanup in finally blocks

APPROVED - Good test coverage for fetchall guard edge cases.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

RTC Reward

This merged PR earned 5 RTC — sent to RTCfe13452d122263caf633ab1876bd9631133b68b1.

RustChain Bounty Program

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api API endpoint related BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) node Node server related size/M PR: 51-200 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the fetchall guard line-number-independent (stop the recurring baseline drift)

4 participants