Files
mtc-project-sync-script/verification.md

8.0 KiB

Verification Steps for sync-git-project.sh

This document outlines testing steps and edge cases for verifying the enhanced sync-git-project.sh script.

Prerequisites

Before testing, ensure you have:

  • A test server with SSH access
  • A git repository on the server
  • sshpass installed locally
  • Docker installed and running
  • make available

Test Cases

1. Clone Test

Purpose: Verify git clone works with credentials

Steps:

  1. Run ./sync-project.sh --git
  2. Provide valid server credentials
  3. Verify repository is cloned to LOCAL_FOLDER

Expected: Repository cloned successfully, cd into project works

Edge cases:

  • Wrong SSH credentials → Should show error and exit
  • Repository doesn't exist → Should show clear error message
  • LOCAL_FOLDER already exists → Git will fail with appropriate error

2. .npmrc Check

Purpose: Test with/without .npmrc file

Steps:

  1. Clone a project without .npmrc
  2. Verify script pauses and prompts user
  3. Add .npmrc file
  4. Press Enter to continue

Expected: Script pauses with clear message, continues after file added


3. Docker Env Copy

Purpose: Verify .docker/config/.env.local exists and copies correctly

Steps:

  1. Ensure .docker/config/.env.local exists in repo
  2. Run setup
  3. Verify .env created in project root

Expected: .env copied from .docker/config/.env.local

Edge cases:

  • .docker/config/.env.local missing → Pause and prompt user

4. Clean Docker Volumes

Purpose: Verify Docker volumes are cleaned before setup

Steps:

  1. Have existing Docker containers and volumes running
  2. Run setup
  3. Verify all containers stopped and removed
  4. Verify all volumes removed

Expected:

  • docker ps -a shows no containers
  • docker volume ls shows no volumes

Edge cases:

  • No containers running → Commands succeed silently
  • No volumes exist → Commands succeed silently

5. Docker Setup

Purpose: Test with/without docker-setup.sh present

Steps:

  1. Test with project containing docker-setup.sh
  2. Test with project missing docker-setup.sh

Expected:

  • With script: Runs sh docker-setup.sh
  • Without script: Pauses and notifies user

6. Server .env Copy

Purpose: Verify scp copies .env to .server.env

Steps:

  1. Ensure .env exists on server
  2. Run setup
  3. Verify .server.env created locally
  4. Run git ls-files -v | grep .server.env to verify assume-unchanged

Expected: .server.env copied and marked with 'h' (assume-unchanged)

Edge cases:

  • Server .env missing → Pause and prompt user

7. .env Modification

Purpose: Check APP_NAME/APP_KEY extraction and insertion

Steps:

  1. Verify .server.env contains APP_NAME and APP_KEY
  2. Run setup
  3. Check local .env for updated values

Expected: APP_NAME and APP_KEY from .server.env appear in local .env

Edge cases:

  • APP_NAME missing in .server.env → Yellow warning, continues
  • APP_KEY missing in .server.env → Yellow warning, continues

8. .env.prod.local Creation

Purpose: Verify all 5 variables populated correctly

Steps:

  1. Run setup with valid server credentials
  2. Check .env.prod.local contents

Expected file contents:

PROD_HOST="<extracted from SERVER_HOST>"
PROD_USER="<extracted from SERVER_HOST>"
PROD_DB_NAME="<DB_DATABASE from .server.env>"
PROD_DB_USER="<DB_USERNAME from .server.env>"
PROD_DB_PASS="<DB_PASSWORD from .server.env>"

9. Helper Scripts

Purpose: Verify ssh.sh created correctly

Steps:

  1. Run setup
  2. Check ssh.sh exists with executable permission
  3. Verify ssh.sh contains correct variables
  4. Check .gitignore includes ssh.sh

Expected: ssh.sh created with embedded credentials, added to .gitignore


10. Lazygit Upload

Purpose: Verify upload and assume-unchanged on both server and local

Steps:

  1. Run setup
  2. SSH to server, check lazygit exists in project
  3. On server: git ls-files -v | grep lazygit shows 'h'
  4. Locally: git ls-files -v | grep lazygit shows 'h'

Expected: lazygit uploaded and marked assume-unchanged on both ends


11. SSH Keys - Case A

Purpose: Server with only public key

Setup:

# On server
rm ~/.ssh/id_rsa
# Keep ~/.ssh/id_rsa.pub

Steps:

  1. Run setup
  2. Verify staging.key created locally
  3. Verify both keys uploaded to server
  4. Verify public key added to authorized_keys

Expected: New keypair generated, uploaded, authorized


12. SSH Keys - Case B

Purpose: Server with both keys

Setup:

# Server has both ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub

Steps:

  1. Run setup
  2. Verify staging.key downloaded (matches server's id_rsa)
  3. Verify public key in authorized_keys

Expected: Private key downloaded as staging.key


13. SSH Keys - Case C

Purpose: Server with neither key

Setup:

# On server
rm -rf ~/.ssh/id_rsa ~/.ssh/id_rsa.pub
# or rm -rf ~/.ssh

Steps:

  1. Run setup
  2. Verify ~/.ssh created on server
  3. Verify both keys uploaded
  4. Verify authorized_keys created/updated

Expected: New keypair generated, ~/.ssh created, keys uploaded


14. staging.key Assume-Unchanged

Purpose: Verify git tracking status

Steps:

  1. After setup, run: git ls-files -v | grep staging.key

Expected: Output shows 'h staging.key' (lowercase h = assume-unchanged)


15. SSH-Add

Purpose: Verify key added to agent

Steps:

  1. Ensure ssh-agent is running: eval $(ssh-agent -s)
  2. Run setup
  3. Check: ssh-add -l should show staging.key

Expected: staging.key fingerprint shown in ssh-add -l

Edge cases:

  • ssh-agent not running → Pause with instructions

16. db:wipe

Purpose: Verify database wipe works

Steps:

  1. Ensure mtc-pharmacy-web container is running
  2. Run setup
  3. Verify db:wipe command executes

Expected: Database wiped successfully

Edge cases:

  • Container not running → Pause with instructions

17. db-sync

Purpose: Verify make db-sync runs

Steps:

  1. Ensure Makefile exists with db-sync target
  2. Ensure .env.prod.local has correct values
  3. Run setup

Expected: Database synced from staging

Edge cases:

  • Makefile missing → Error from make
  • db-sync target missing → Error from make
  • Connection fails → Pause with instructions

Edge Cases Summary

Scenario Expected Behavior
Clone fails (wrong credentials) Red error, exit
Clone fails (repo doesn't exist) Red error, exit
.npmrc missing Yellow pause, wait for user
.docker/config/.env.local missing Red error, pause, retry
No Docker containers/volumes Commands succeed silently
docker-setup.sh missing Yellow pause, notify user
Server .env missing Red error, pause, retry
.server.env malformed get_env_value returns empty, yellow warning
~/.ssh doesn't exist on server Create directory (Case C)
authorized_keys doesn't exist Create with public key
staging.key assume-unchanged fails Suppress error, continue
ssh-agent not running Yellow warning, instructions, pause
Docker container not running Yellow warning, pause, retry
make db-sync fails Yellow warning, pause

Manual Verification Checklist

  • Clone test passes
  • .npmrc check pauses correctly
  • Docker env copied
  • Docker volumes cleaned
  • docker-setup.sh runs or notifies
  • Server .env copied to .server.env
  • .server.env marked assume-unchanged
  • APP_NAME/APP_KEY extracted and set
  • .env.prod.local has all 5 variables
  • ssh.sh created with correct variables
  • ssh.sh in .gitignore
  • staging.key in .gitignore
  • lazygit uploaded and assume-unchanged
  • SSH key management works (test appropriate case)
  • staging.key marked assume-unchanged
  • ssh-add succeeds
  • db:wipe runs
  • db-sync runs

Cleanup After Testing

# Remove test project locally
rm -rf LOCAL_FOLDER

# On server, if you modified SSH keys:
# Restore original keys or regenerate

# Remove any test databases