Skip to content

test(cli): use tests/common's helpers instead of local copies (T55) - #2241

Merged
Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
arch-refactor/1959-test-common-helpers
Nov 25, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
arch-refactor/1959-test-common-helpers

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-opus-5-5

Refs #1959 (T55, first slice). Living document: Part 5, tests.

Why

Suites that already include tests/common kept their own copies of its helpers. This deletes the copies that are byte-for-byte or behaviourally identical to common's and calls common::* instead. It also drops the stderr_chatter filter, which hid stray lines from the silent-mode emptiness checks.

Changes

  • has_command: deleted 6 copies identical to common::has_command (e2e_npm, e2e_gem, e2e_scan, e2e_yarn4_pnpm_linker_build, e2e_yarn4_workspaces_build, e2e_redirect_yarn_berry_build). These kept: the pm_command/go version variants in e2e_hosted_production, e2e_vendored_production and e2e_artifactory_mirror, and the tool_command + .success() variants in e2e_vendor_rush and e2e_redirect_rush_sim, because they behave differently.
  • git_sha256_file: deleted 4 copies (e2e_npm, e2e_gem, e2e_scan, e2e_pypi).
  • sha256_hex: deleted 9 copies (mode_migration_cargo, e2e_redirect_cargo_build, e2e_vex_vendor, repair/repair_vendor_e2e, e2e_vex_lockfile/{maven,uv,poetry,nuget}, vlt_e2e_common, which now re-exports common::sha256_hex). hex::encode and format!("{:x}") produce the same lowercase hex.
  • Double includes: the three yarn suites and e2e_redirect_rush_sim no longer #[path]-include common/cache_env.rs (and, for rush, common/hermetic.rs) a second time beside mod common.
  • Dead code: deleted common::{env_map, npm_run} (0 callers) and update_fixture::{raw_asset, delay_asset} plus the asset_delay field.
  • Tests fixed: deleted 4 stderr_chatter copies (cli_apply_silent, cli_scan_silent, apply/apply_silent_staging_errors, vendor/vendor_silent_errors). The filter dropped any line containing SOCKET_API_TOKEN or Continuing anyway:
    • 5 emptiness checks now assert stderr.is_empty(): scan_silent_no_packages_produces_no_output, scan_silent_apply_flow_produces_no_output_but_still_applies, scan_vendor_silent_gc_prints_nothing, apply_json_offline_missing_source_keeps_stderr_clean and vendor_json_online_fetch_failure_keeps_stderr_clean.
    • The presence checks read stderr directly.
    • Red→green: with a temporary eprintln!("No SOCKET_API_TOKEN set (injected)") at the top of main, all 5 emptiness tests fail. Before this PR the filter hid that line and they passed. They pass again once it is removed.
  • Comments: removed the stale "assertions ignore the token warning" paragraph in cli_scan_silent. The one in cli_apply_silent now gives the real reason: the notice is an info notice, muted under --silent/--json.

Size

git diff --stat: 23 files, +46 / −298, all under crates/socket-patch-cli/tests/. Production: 0.

Behavior change

None in the product. The 5 silent-mode tests are stricter, as described above.

Verification

  • cargo test -p socket-patch-cli --tests --no-run: every test target builds with no new warnings. Two pre-existing unused-import warnings remain, in in_process_vendor_bun_takeover/registry.rs and vendor/e2e_golang_redirect.rs.
  • Green: apply, cli, cli_apply_silent, cli_scan_silent, common_selftests, e2e_vex_lockfile, e2e_vex_vendor, mode_migration_cargo, vendor, update, self_update_e2e, self_update_failures_e2e and e2e_redirect_rush_sim. The toolchain e2e suites (e2e_npm, e2e_gem, e2e_scan, e2e_pypi, the yarn suites) compile but are #[ignore]d or toolchain-gated here.
  • repair: 116 pass. 2 fail only because the sandbox runs as root (repair_cleanup_failure_is_reported_in_json_and_silent_modes, repair_exits_zero_and_stays_quiet_when_lock_file_unremovable); they are chmod tests that pass in CI.
  • cargo clippy --workspace --all-features -- -D warnings: clean.

/code-review high findings not fixed here

Risk

Low: test-only and mechanical. No cfg(windows)/cfg(unix) code changed.

🤖 Generated with Claude Code

https://claude.ai/code/session_011f9aePrALfrCutpZn63ds9

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko Mikola Lysenko (mikolalysenko) added refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code arch-refactor PR opened by the scheduled architecture refactor routine labels Nov 25, 2026
The stderr_chatter filter (4 byte-identical copies) dropped API-token
warning lines that these offline and cached runs never print, so the
emptiness checks now assert on the whole stderr and the presence
checks read it directly.

Assisted-by: Claude Code:claude-opus-5-5
Delete local copies identical to tests/common's: has_command in six
suites, git_sha256_file in four, sha256_hex in nine, and the yarn
suites' second include of common/cache_env.rs. Delete the unused
common::{env_map, npm_run} and update_fixture's raw_asset and
delay_asset.

Assisted-by: Claude Code:claude-opus-5-5
Assisted-by: Claude Code:claude-opus-5-5
Drop the second #[path] include of common/cache_env.rs and
common/hermetic.rs beside mod common, and state why the silent
suites' stderr never holds the proxy notice: it is an info notice,
muted under --silent and --json.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 25, 2026 15:28
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

BugBot review


Generated by Claude Code

@cursor

cursor Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Test-only mechanical refactor with stricter assertions; no production code changes.

Overview
Consolidates CLI integration tests onto shared helpers in tests/common and removes local duplicates of has_command, git_sha256_file, and sha256_hex across many e2e and VEX suites. Yarn/rush tests now import cache_env / hermetic through mod common instead of double #[path]-including the same modules.

Removes unused test utilities (common::npm_run, env_map, and update_fixture::{raw_asset, delay_asset, asset_delay}).

Behavioral change in tests only: deletes the stderr_chatter helper that stripped SOCKET_API_TOKEN / "Continuing anyway" lines from assertions. Silent/--json success-path checks now require stderr.is_empty() outright; error-path checks substring-match stderr directly—so stray info notices can no longer pass vacuously. Module comments in cli_apply_silent / cli_scan_silent were updated to document that the token notice is muted under --silent/--json.

Reviewed by Cursor Bugbot for commit 0d967b7. Configure here.

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Nov 25, 2026
Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does
Test-only cleanup (first slice of #1959): suites that include tests/common drop their private copies of has_command, git_sha256_file and sha256_hex and call the shared ones, and a few dead helpers are deleted. It also removes the stderr_chatter filter, so five silent/JSON-mode tests now assert that stderr is completely empty instead of ignoring token-warning lines.

Risk
Low. Nothing under src/ changes (23 test files, +46/−298). Every deleted copy is identical to the shared helper (hex::encode vs format!("{:x}") give the same lowercase hex). The only behavior change is that five tests are stricter.

Look here

  • cli_scan_silent.rs:155, :211, :374: stderr must now be empty, with no token-warning exemption
  • [apply/apply_silent_staging_errors.rs:140](https://github.com/SocketDev/socket-patch/blob/0d967b7becf8de103d00074b1167c89815475da7/crates/socket-patch-cli/tests/apply/apply_silent_staging_errors.rs#L140) and [vendor/vendor_silent_errors.rs:160](https://github.com/SocketDev/socket-patch/blob/0d967b7becf8de103d00074b1167c89815475da7/crates/socket-patch-cli/tests/vendor/vendor_silent_errors.rs#L160): the same for --json
  • cli_apply_silent.rs:18: the rewritten explanation of why the token notice never shows up here
  • vlt_e2e_common/mod.rs:1281: re-exports common::sha256_hex instead of defining its own
  • common/mod.rs:66: the shared has_command that six suites now use, byte-for-byte the same as the copies

Verified

  • Read the whole diff. Each deleted helper matches its common counterpart, and no caller of the deleted npm_run, env_map, raw_asset, delay_asset or stderr_chatter is left on the branch or on current main.
  • main has moved 12 commits since this branch was cut, and none of them touch the files this PR changes. In a trial merge with current main (not pushed), cli_scan_silent (7), cli_apply_silent (12), apply (178) and vendor (145) all pass, so the stricter empty-stderr checks hold on today's main.
  • CI at 0d967b7: ci-ok and clippy are green. Bugbot left no findings and there are no open review threads. CHANGELOG.md is untouched.

Changes I made
None.

Open questions
None. The follow-ups the description lists (the rollback stderr_chatter, the gem sha256_hex, and folding npm_run) are left out of this slice on purpose because open PRs are changing those files.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 25, 2026

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.

[agent] Reviewed at 0d967b7. The deleted local helpers match the tests/common versions, the removed helpers have no remaining callers, and the silent-mode checks are stricter than before. No findings.

Merged via the queue into main with commit 89adf9d Nov 25, 2026
83 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the arch-refactor/1959-test-common-helpers branch November 25, 2026 20:35
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Nov 25, 2026
#2246 merged as ddf322a, so it moves to Merged, #2253 is unblocked,
and agent:claimed is off #1910, which stays open for L21 and L22.
#2241, the old charter's last PR, merged too.

Assisted-by: Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-refactor PR opened by the scheduled architecture refactor routine Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants