Skip to content

fix: resolve CI test failures from env var race and startup HTTP calls#578

Merged
r-near merged 3 commits into
mainfrom
fix/ci-test-env-race
Mar 30, 2026
Merged

fix: resolve CI test failures from env var race and startup HTTP calls#578
r-near merged 3 commits into
mainfrom
fix/ci-test-env-race

Conversation

@r-near

@r-near r-near commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Tests have been failing on main since feat: Improved interactive contract selection option for FT tokens #574 merged — the test_view_account_summary_with_localnet snapshot test gets empty stdout from the near binary subprocess
  • Root cause: prepare_tests() used unsafe { std::env::set_var() } to set HOME/XDG_CONFIG_HOME across parallel test threads (undefined behavior in Rust). Combined with the blocking HTTP calls to api.nearblocks.io added at startup in feat: Improved interactive contract selection option for FT tokens #574, the subprocess reads the wrong config directory and fails silently
  • Pass env vars explicitly to the subprocess Command via .env() instead of relying on process-wide set_var
  • Pre-create ft_contracts.json with [] in test credentials dir to skip the startup HTTP call entirely
  • Simplify is_used_ft_contract_account_list_exist to just check file existence (prevents re-fetching from API on every invocation when the file exists but is empty)
  • Write valid empty JSON ([]) instead of an empty file when the nearblocks API fails

Test plan

  • CI Run Tests job passes (currently failing on main)
  • test_view_account_summary_with_localnet snapshot matches
  • test_view_account_summary_nonexistent passes
  • test_view_near_balance passes

…TTP calls

Tests were failing because prepare_tests() used unsafe set_var() to set
HOME/XDG_CONFIG_HOME across parallel test threads (undefined behavior).
Combined with blocking HTTP calls to nearblocks API added at startup in
#574, the subprocess would read wrong config and produce empty output.

- Pass env vars explicitly to subprocess Command instead of set_var
- Pre-create ft_contracts.json in test setup to skip startup HTTP calls
- Simplify is_used_ft_contract_account_list_exist to just check file existence
- Write valid empty JSON ("[]") instead of empty file on API failure
Copilot AI review requested due to automatic review settings March 27, 2026 20:23
@r-near r-near requested a review from a team as a code owner March 27, 2026 20:23
@github-project-automation github-project-automation Bot moved this to NEW❗ in DevTools Mar 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c75bc90501

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/common/mod.rs Outdated

Copilot AI 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.

Pull request overview

Fixes CI integration test flakiness caused by process-wide environment mutation during parallel tests, and avoids startup-time blocking HTTP calls to nearblocks during test runs.

Changes:

  • Replace global std::env::set_var test setup with per-subprocess environment variables passed via Command::env.
  • Introduce a TestContext to keep the sandbox + tempdir alive and expose the test config home path.
  • Adjust FT contracts cache handling to avoid repeated nearblocks fetches and write valid empty JSON ([]) on fetch failure.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/tokens.rs Uses TestContext and passes config env vars directly to the spawned near subprocess.
tests/common/mod.rs Refactors test harness into TestContext, removes global env mutation, and pre-creates ft_contracts.json with [].
tests/account.rs Updates integration tests to use TestContext and per-process env vars.
src/common.rs Simplifies FT contracts list “existence” check and ensures empty JSON is written on fetch failure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/common/mod.rs Outdated
@r-near r-near marked this pull request as draft March 27, 2026 20:29
nonexistent.near was registered on mainnet, causing the test to fail.
Use a more obscure name that is unlikely to be registered.
@r-near r-near marked this pull request as ready for review March 27, 2026 21:00
Comment thread src/common.rs Outdated
…t config

- Remove else branch that wrote empty [] on fetch failure, so the CLI
  retries on the next run instead of caching an empty list permanently
- Place test config at the correct platform-specific path for macOS
@r-near r-near enabled auto-merge (squash) March 30, 2026 16:45
@r-near r-near merged commit a379665 into main Mar 30, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this from NEW❗ to Shipped 🚀 in DevTools Mar 30, 2026
@r-near r-near deleted the fix/ci-test-env-race branch March 30, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Shipped 🚀

Development

Successfully merging this pull request may close these issues.

4 participants