Number_guess game tests issue

Hi, I managed somehow to do the script , sometimes some tests pass and sometimes don’t with the same code, however while testing I see some kind of bug that other users are being inserted , my guess this happens when entering something different than an integer

#!/bin/bash
PSQL="psql --username=freecodecamp --dbname=number_guess -t --no-align -c"
echo "Enter your username:"
read USER_NAME

# query get username
YUSER_NAME=$($PSQL "SELECT username FROM users WHERE username='$USER_NAME'")

# generate random number
SECRET_NUMBER=$(( (RANDOM % 1000) + 1 )) 
#echo "$SECRET_NUMBER"
# if user_name not found
if [[ -z $YUSER_NAME ]]
then
  echo "Welcome, $USER_NAME! It looks like this is your first time here."
  INSERT_NAME=$($PSQL "INSERT INTO users(username) VALUES('$USER_NAME')")
  GAMES_PLAYED=0
  BEST_GAME=0
else
 if [[ $YUSER_NAME ]]
 then
  GAMES_PLAYED=$($PSQL "SELECT games_played FROM users WHERE username='$USER_NAME'")
  BEST_GAME=$($PSQL "SELECT best_game FROM users WHERE username='$USER_NAME'")  
  echo "Welcome back, $USER_NAME! You have played $GAMES_PLAYED games, and your best game took $BEST_GAME guesses."
 fi
fi

echo "Guess the secret number between 1 and 1000:"

# looping over the input until user guesses secret_number
# initializing counter to zero, it could be from one maybe better
i=0
while read INPUT
    do
      if [[ ! $INPUT =~ ^[0-9]+$ ]]  
      then 
        echo "That is not an integer, guess again:"
      else  
        if [[ $INPUT -gt $SECRET_NUMBER ]]
        then
          echo "It's lower than that, guess again:" 
          ((i+=1))
        #if the previous input was higher than the secret number
        else
          if [[ $INPUT -lt $SECRET_NUMBER ]]
          then
            echo "It's higher than that, guess again:"
            ((i+=1))
          else
            # if user guesses then update DB table and exit the programm 
            if [[ $INPUT -eq $SECRET_NUMBER ]]
            then
              TRIES=$(($i+1))
              echo "You guessed it in $TRIES tries. The secret number was $SECRET_NUMBER. Nice job!"
              UPDATE_USERS_GAMES_PLAYED=$($PSQL "UPDATE users SET games_played = $(($GAMES_PLAYED+1)) WHERE username='$USER_NAME'")
              BEST_GAME=$($PSQL "SELECT best_game FROM users WHERE username='$USER_NAME'")
              if [[ -z $BEST_GAME ]] 
                then
                UPDATE_USERS_BEST_GAME=$($PSQL "UPDATE users SET best_game = $TRIES WHERE username='$USER_NAME'")
                else
                if [[ $TRIES -lt $BEST_GAME ]]
                then
                  UPDATE_USERS_BEST_GAME=$($PSQL "UPDATE users SET best_game = $TRIES WHERE username='$USER_NAME'")
                fi  
              fi
            exit   
           fi
         fi
       fi   
      fi 
    done
  fi
fi
#!/bin/bash
PSQL="psql --username=freecodecamp --dbname=number_guess -t --no-align -c"
echo "Enter your username:"
read USER_NAME

# query get username
YUSER_NAME=$($PSQL "SELECT username FROM users WHERE username='$USER_NAME'")

# generate random number
SECRET_NUMBER=$(( (RANDOM % 1000) + 1 )) 
#echo "$SECRET_NUMBER"
# if user_name not found
if [[ -z $YUSER_NAME ]]
then
  echo "Welcome, $USER_NAME! It looks like this is your first time here."
  INSERT_NAME=$($PSQL "INSERT INTO users(username) VALUES('$USER_NAME')")
  GAMES_PLAYED=0
  BEST_GAME=0
else
 if [[ $YUSER_NAME ]]
 then
  GAMES_PLAYED=$($PSQL "SELECT games_played FROM users WHERE username='$USER_NAME'")
  BEST_GAME=$($PSQL "SELECT best_game FROM users WHERE username='$USER_NAME'")  
  echo "Welcome back, $USER_NAME! You have played $GAMES_PLAYED games, and your best game took $BEST_GAME guesses."
 fi
fi

echo "Guess the secret number between 1 and 1000:"

# looping over the input until user guesses secret_number
# initializing counter to zero, it could be from one maybe better
i=0
while read INPUT
    do
      if [[ ! $INPUT =~ ^[0-9]+$ ]]  
      then 
        echo "That is not an integer, guess again:"
      else  
        if [[ $INPUT -gt $SECRET_NUMBER ]]
        then
          echo "It's lower than that, guess again:" 
          ((i+=1))
        #if the previous input was higher than the secret number
        else
          if [[ $INPUT -lt $SECRET_NUMBER ]]
          then
            echo "It's higher than that, guess again:"
            ((i+=1))
          else
            # if user guesses then update DB table and exit the programm 
            if [[ $INPUT -eq $SECRET_NUMBER ]]
            then
              TRIES=$(($i+1))
              echo "You guessed it in $TRIES tries. The secret number was $SECRET_NUMBER. Nice job!"
              UPDATE_USERS_GAMES_PLAYED=$($PSQL "UPDATE users SET games_played = $(($GAMES_PLAYED+1)) WHERE username='$USER_NAME'")
              BEST_GAME=$($PSQL "SELECT best_game FROM users WHERE username='$USER_NAME'")
              if [[ -z $BEST_GAME ]] 
                then
                UPDATE_USERS_BEST_GAME=$($PSQL "UPDATE users SET best_game = $TRIES WHERE username='$USER_NAME'")
                else
                if [[ $TRIES -lt $BEST_GAME ]]
                then
                  UPDATE_USERS_BEST_GAME=$($PSQL "UPDATE users SET best_game = $TRIES WHERE username='$USER_NAME'")
                fi  
              fi
            exit   
           fi
         fi
       fi   
      fi 
    done
  fi
fi

here is a dump of the db as well

--
-- PostgreSQL database dump
--

-- Dumped from database version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)
-- Dumped by pg_dump version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

DROP DATABASE number_guess;
--
-- Name: number_guess; Type: DATABASE; Schema: -; Owner: freecodecamp
--

CREATE DATABASE number_guess WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8';


ALTER DATABASE number_guess OWNER TO freecodecamp;

\connect number_guess

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: users; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.users (
    user_id integer NOT NULL,
    username character varying(22) NOT NULL,
    games_played integer,
    best_game integer
);


ALTER TABLE public.users OWNER TO freecodecamp;

--
-- Name: users_user_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.users_user_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.users_user_id_seq OWNER TO freecodecamp;

--
-- Name: users_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.users_user_id_seq OWNED BY public.users.user_id;


--
-- Name: users user_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users ALTER COLUMN user_id SET DEFAULT nextval('public.users_user_id_seq'::regclass);


--
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--



--
-- Name: users_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.users_user_id_seq', 1, false);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);


--
-- Name: users users_username_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_username_key UNIQUE (username);


--
-- PostgreSQL database dump complete
--


It’s not a bug - it is the testing which adds those users.
Can you share the test output please?
With a terminal open, click on the OUTPUT tab and then select CodeRoad(tests) from the dropdown menu on the right.
Then click the Run button to run the tests again and see what you get in the output window.

this is the OUTPUT with CodeRoad(tests)

it is clear for me I have not finished the git part, but what happens with this one?
✘ SUBTASKS 1.1 :12 Your script should print the correct message if users enter a guess other than a number
it should be working

FAILED TEST LOG
  ✘ SUBTASKS 1.1 :5 Your repository should have at least five commits

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

assert(commits.length > 4)

at Context.<anonymous> (test/1.1.test.js:77:5)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
  ✘ SUBTASKS 1.1 :12 Your script should print the correct message if users enter a guess other than a number

Error: Command failed: ./number_guessing_game/number_guess.sh

at ChildProcess.exithandler (child_process.js:383:12)
at maybeClose (internal/child_process.js:1058:16)
at Socket.<anonymous> (internal/child_process.js:443:11)
at Pipe.<anonymous> (net.js:686:12)
  ✘ SUBTASKS 1.1 :16 You should submit your project while on the "main" branch of your repository with a clean working tree

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

assert(/On branch main\s/.test(commandOutput) && /working tree clean/.test(commandOutput))

at Context.<anonymous> (test/1.1.test.js:164:5)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)

It’s a timeout issue because the tests run too slowly.

In the terminal go to the .freeCodeCamp/test folder (from the project folder).
Then nano utils.js
Find the setTimeout function and manually change the timeout value to 100000.

Untitled

Save the file with CTRL+O and ENTER. Then exit with CTRL+X.
Then nano 1.1.test.js and do the same again.

Now run the tests again and check the test ouput.

It did not work. More tests did not pass this time.

  ✘ SUBTASKS 1.1 :5 Your repository should have at least five commits

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

assert(commits.length > 4)

at Context.<anonymous> (test/1.1.test.js:77:5)
at processTicksAndRejections (internal/process/task_queues.js:95:5)

An error occurred running ./number_guessing_game/number_guess.sh
/bin/sh: 1: ./number_guessing_game/number_guess.sh: Text file busy
  ✘ SUBTASKS 1.1 :7 Your script should prompt for a username

Error: Command failed: ./number_guessing_game/number_guess.sh
/bin/sh: 1: ./number_guessing_game/number_guess.sh: Text file busy

at ChildProcess.exithandler (child_process.js:383:12)
at maybeClose (internal/child_process.js:1058:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:293:5)

An error occurred running ./number_guessing_game/number_guess.sh
/bin/sh: 1: ./number_guessing_game/number_guess.sh: Text file busy
  ✘ SUBTASKS 1.1 :8 Your script should print the correct welcome message for returning users

Error: Command failed: ./number_guessing_game/number_guess.sh
/bin/sh: 1: ./number_guessing_game/number_guess.sh: Text file busy

at ChildProcess.exithandler (child_process.js:383:12)
at maybeClose (internal/child_process.js:1058:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:293:5)

An error occurred running ./number_guessing_game/number_guess.sh
/bin/sh: 1: ./number_guessing_game/number_guess.sh: Text file busy
  ✘ SUBTASKS 1.1 :9 Your script should print the correct welcome message for new users

Error: Command failed: ./number_guessing_game/number_guess.sh
/bin/sh: 1: ./number_guessing_game/number_guess.sh: Text file busy

at ChildProcess.exithandler (child_process.js:383:12)
at maybeClose (internal/child_process.js:1058:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:293:5)

An error occurred running ./number_guessing_game/number_guess.sh
/bin/sh: 1: ./number_guessing_game/number_guess.sh: Text file busy
  ✘ SUBTASKS 1.1 :10 Your script should print the correct initial message to prompt a user for a guess

Error: Command failed: ./number_guessing_game/number_guess.sh
/bin/sh: 1: ./number_guessing_game/number_guess.sh: Text file busy

at ChildProcess.exithandler (child_process.js:383:12)
at maybeClose (internal/child_process.js:1058:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:293:5)
  ✘ SUBTASKS 1.1 :12 Your script should print the correct message if users enter a guess other than a number

Error: Command failed: ./number_guessing_game/number_guess.sh

at ChildProcess.exithandler (child_process.js:383:12)
at maybeClose (internal/child_process.js:1058:16)
at Socket.<anonymous> (internal/child_process.js:443:11)
at Pipe.<anonymous> (net.js:686:12)
  ✘ SUBTASKS 1.1 :13 Your script should print the correct message when a game is finished

Error: Command failed: ./number_guessing_game/number_guess.sh

at ChildProcess.exithandler (child_process.js:383:12)
at maybeClose (internal/child_process.js:1058:16)
at Socket.<anonymous> (internal/child_process.js:443:11)
at Pipe.<anonymous> (net.js:686:12)
  ✘ SUBTASKS 1.1 :16 You should submit your project while on the "main" branch of your repository with a clean working tree

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

assert(/On branch main\s/.test(commandOutput) && /working tree clean/.test(commandOutput))

at Context.<anonymous> (test/1.1.test.js:164:5)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)

Exit from your terminal. Open a new one then run the tests again with the test output window open.

I tried again but did not change.

FAILED TEST LOG
  ✘ SUBTASKS 1.1 :5 Your repository should have at least five commits

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

assert(commits.length > 4)

at Context.<anonymous> (test/1.1.test.js:77:5)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
  ✘ SUBTASKS 1.1 :7 Your script should prompt for a username

Error: Command failed: ./number_guessing_game/number_guess.sh

at ChildProcess.exithandler (child_process.js:383:12)
at maybeClose (internal/child_process.js:1058:16)
at Socket.<anonymous> (internal/child_process.js:443:11)
at Pipe.<anonymous> (net.js:686:12)
  ✘ SUBTASKS 1.1 :8 Your script should print the correct welcome message for returning users

Error: Command failed: ./number_guessing_game/number_guess.sh

at ChildProcess.exithandler (child_process.js:383:12)
at maybeClose (internal/child_process.js:1058:16)
at Socket.<anonymous> (internal/child_process.js:443:11)
at Pipe.<anonymous> (net.js:686:12)
  ✘ SUBTASKS 1.1 :9 Your script should print the correct welcome message for new users

Error: Command failed: ./number_guessing_game/number_guess.sh

at ChildProcess.exithandler (child_process.js:383:12)
at maybeClose (internal/child_process.js:1058:16)
at Socket.<anonymous> (internal/child_process.js:443:11)
at Pipe.<anonymous> (net.js:686:12)
  ✘ SUBTASKS 1.1 :16 You should submit your project while on the "main" branch of your repository with a clean working tree

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

assert(/On branch main\s/.test(commandOutput) && /working tree clean/.test(commandOutput))

at Context.<anonymous> (test/1.1.test.js:164:5)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)

It worked not. thanks for your help