diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c6d282..f8613ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,3 +27,14 @@ repos: entry: scripts/lint-docs.sh language: system pass_filenames: false + - id: eslint + name: ESLint + entry: npx eslint + language: system + types: [typescript] + files: '\.(ts|tsx)$' + - id: prettier + name: Prettier + entry: npx prettier --check + language: system + files: '\.(ts|tsx)$' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e9d4076..bf9f1e3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,6 +41,8 @@ Hooks run on each commit and enforce: - ABI snapshot hygiene (`abis/*.json` must change together with `COMEBACKHERE-contracts/contracts/*/src/`) - Markdown linting +- TypeScript/TSX linting (ESLint) +- TypeScript/TSX formatting (Prettier) - Trailing whitespace detection - End-of-file fixing (ensure files end with a newline) - JSON validation diff --git a/Makefile b/Makefile index e79c7de..9a64ebb 100644 --- a/Makefile +++ b/Makefile @@ -26,3 +26,19 @@ deploy-testnet: abi-snapshot: @$(MAKE) update-abi-snapshots + +verify: + @./scripts/verify.sh + +lint-docs: + @./scripts/lint-docs.sh + +snapshot: + @$(MAKE) update-abi-snapshots + +check-snapshot: + @$(MAKE) check-abi-snapshots + +default: verify + +.PHONY: default snapshot check-snapshot diff --git a/justfile b/justfile index bf1df18..3cd0563 100644 --- a/justfile +++ b/justfile @@ -4,11 +4,17 @@ snapshot: @./scripts/generate_abi_metadata.sh abis +update-abi-snapshots: snapshot + +abi-snapshot: snapshot + # Verify committed ABI snapshots match contract sources (no writes) check-snapshot: @./scripts/generate_abi_metadata.sh /tmp/comebackhere-abis-check @diff -ru abis/ /tmp/comebackhere-abis-check/ +check-abi-snapshots: check-snapshot + # Lint markdown documentation lint-docs: @./scripts/lint-docs.sh @@ -17,5 +23,23 @@ lint-docs: verify: @./scripts/verify.sh +# Start local Docker environment +dev: + docker-compose up -d + +# Run contract tests +test: + cargo test --manifest-path COMEBACKHERE-contracts/Cargo.toml + +# Lint TypeScript, contracts, and documentation +lint: + @./scripts/lint-docs.sh && cargo clippy --manifest-path COMEBACKHERE-contracts/Cargo.toml -- -D warnings && (cd frontend && npx eslint src --ext ts,tsx --report-unused-disable-directives) + +# Deploy to testnet +deploy-testnet: + @test -n "$$STELLAR_NETWORK" || (echo "ERROR: STELLAR_NETWORK is not set" && exit 1) + @test -n "$$DEPLOYER_SECRET" || (echo "ERROR: DEPLOYER_SECRET is not set" && exit 1) + @./scripts/deploy_testnet.sh + # Default target default: verify diff --git a/scripts/check_make_just_parity.sh b/scripts/check_make_just_parity.sh new file mode 100755 index 0000000..c03892f --- /dev/null +++ b/scripts/check_make_just_parity.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# check_make_just_parity.sh — verify Makefile and justfile have equivalent targets +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +# Extract Makefile targets (targets that start at column 0 and end with :) +MAKE_TARGETS=$(grep -E '^[a-zA-Z0-9_-]+:' "$ROOT_DIR/Makefile" | sed 's/:.*//g' | sort) + +# Extract justfile targets (lines with # at start of recipe) +JUST_TARGETS=$(grep -E '^[a-zA-Z0-9_-]+:' "$ROOT_DIR/justfile" | sed 's/:.*//g' | sort) + +# Convert to arrays for comparison +mapfile -t MAKE_ARRAY <<<"$MAKE_TARGETS" +mapfile -t JUST_ARRAY <<<"$JUST_TARGETS" + +# Compare targets +MISSING_IN_JUST=() +MISSING_IN_MAKE=() + +for target in "${MAKE_ARRAY[@]}"; do + if ! grep -q "^$target:" "$ROOT_DIR/justfile"; then + MISSING_IN_JUST+=("$target") + fi +done + +for target in "${JUST_ARRAY[@]}"; do + if ! grep -q "^$target:" "$ROOT_DIR/Makefile"; then + MISSING_IN_MAKE+=("$target") + fi +done + +# Report results +if [[ ${#MISSING_IN_JUST[@]} -gt 0 ]] || [[ ${#MISSING_IN_MAKE[@]} -gt 0 ]]; then + echo "ERROR: Makefile and justfile targets are not in parity" >&2 + if [[ ${#MISSING_IN_JUST[@]} -gt 0 ]]; then + echo "Missing in justfile: ${MISSING_IN_JUST[*]}" >&2 + fi + if [[ ${#MISSING_IN_MAKE[@]} -gt 0 ]]; then + echo "Missing in Makefile: ${MISSING_IN_MAKE[*]}" >&2 + fi + exit 1 +fi + +echo "Makefile and justfile targets are in parity." +exit 0 diff --git a/scripts/coverage.sh b/scripts/coverage.sh index 263014d..9a41f98 100755 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -1,5 +1,5 @@ -#!/bin/bash -set -e +#!/usr/bin/env bash +set -euo pipefail # Generate coverage report for COMEBACKHERE contract tests. # Outputs HTML report to coverage/ directory and prints terminal summary. diff --git a/scripts/deploy_local.sh b/scripts/deploy_local.sh index fe3084f..5d8c0c0 100755 --- a/scripts/deploy_local.sh +++ b/scripts/deploy_local.sh @@ -16,34 +16,39 @@ echo "Building COMEBACKHERE contracts for local standalone network via $SOROBAN_ # Build from the contracts repo (sibling directory) (cd ../COMEBACKHERE-contracts && cargo build --target wasm32-unknown-unknown --release) -cat > abis/deployed.local.json <&2 + exit 1 +fi + +echo "Deploying contracts to $STELLAR_NETWORK…" +# Uncomment and integrate actual soroban contract deploy commands: +# soroban contract deploy --wasm "$INVOICE_WASM" ... > /tmp/invoice_deploy.txt 2>&1 +# soroban contract deploy --wasm "$TREASURY_WASM" ... > /tmp/treasury_deploy.txt 2>&1 +# soroban contract deploy --wasm "$COMPLIANCE_WASM" ... > /tmp/compliance_deploy.txt 2>&1 +# +# Parse output to extract contract IDs: +# INVOICE_CONTRACT_ID=$(grep -oP 'Contract ID: \K[C][A-Z0-9]*' /tmp/invoice_deploy.txt || echo "C...") +# TREASURY_CONTRACT_ID=$(grep -oP 'Contract ID: \K[C][A-Z0-9]*' /tmp/treasury_deploy.txt || echo "C...") +# COMPLIANCE_CONTRACT_ID=$(grep -oP 'Contract ID: \K[C][A-Z0-9]*' /tmp/compliance_deploy.txt || echo "C...") + +if [ -f .env.local ]; then + # shellcheck disable=SC1091 + set -a + source .env.local + set +a +fi export STELLAR_NETWORK="${STELLAR_NETWORK:-standalone}" export INVOICE_CONTRACT_ID="${INVOICE_CONTRACT_ID:-C...}" export TREASURY_CONTRACT_ID="${TREASURY_CONTRACT_ID:-C...}" export COMPLIANCE_CONTRACT_ID="${COMPLIANCE_CONTRACT_ID:-C...}" -scripts/export_deployed_addresses.sh +echo "Running deployment validation…" +"$ROOT_DIR/scripts/export_deployed_addresses.sh" diff --git a/scripts/deploy_testnet.sh b/scripts/deploy_testnet.sh index 0c690fa..c3b850c 100755 --- a/scripts/deploy_testnet.sh +++ b/scripts/deploy_testnet.sh @@ -16,19 +16,27 @@ echo "Building COMEBACKHERE contracts for $STELLAR_NETWORK via $SOROBAN_RPC_URL" # Build from the contracts repo (sibling directory) (cd ../COMEBACKHERE-contracts && cargo build --target wasm32-unknown-unknown --release) -cat > abis/deployed.testnet.json <&2 + exit 1 +fi + +echo "Deploying contracts to $STELLAR_NETWORK…" +# Uncomment and integrate actual soroban contract deploy commands: +# soroban contract deploy --wasm "$INVOICE_WASM" ... > /tmp/invoice_deploy.txt 2>&1 +# soroban contract deploy --wasm "$TREASURY_WASM" ... > /tmp/treasury_deploy.txt 2>&1 +# soroban contract deploy --wasm "$COMPLIANCE_WASM" ... > /tmp/compliance_deploy.txt 2>&1 +# +# Parse output to extract contract IDs: +# INVOICE_CONTRACT_ID=$(grep -oP 'Contract ID: \K[C][A-Z0-9]*' /tmp/invoice_deploy.txt || echo "C...") +# TREASURY_CONTRACT_ID=$(grep -oP 'Contract ID: \K[C][A-Z0-9]*' /tmp/treasury_deploy.txt || echo "C...") +# COMPLIANCE_CONTRACT_ID=$(grep -oP 'Contract ID: \K[C][A-Z0-9]*' /tmp/compliance_deploy.txt || echo "C...") if [ -f .env.testnet ]; then # shellcheck disable=SC1091 @@ -41,4 +49,6 @@ export STELLAR_NETWORK="${STELLAR_NETWORK:-testnet}" export INVOICE_CONTRACT_ID="${INVOICE_CONTRACT_ID:-C...}" export TREASURY_CONTRACT_ID="${TREASURY_CONTRACT_ID:-C...}" export COMPLIANCE_CONTRACT_ID="${COMPLIANCE_CONTRACT_ID:-C...}" -scripts/export_deployed_addresses.sh + +echo "Running deployment validation…" +"$ROOT_DIR/scripts/export_deployed_addresses.sh" diff --git a/scripts/lint-docs.sh b/scripts/lint-docs.sh index 5948576..2ac57ce 100755 --- a/scripts/lint-docs.sh +++ b/scripts/lint-docs.sh @@ -1,14 +1,11 @@ -#!/bin/bash -set -e - -# Lint markdown documentation -# Enforces style rules: no trailing spaces, consistent heading levels, consistent list style +#!/usr/bin/env bash +set -euo pipefail echo "Linting markdown documentation..." npx markdownlint-cli2 "**/*.md" "#node_modules" || { - echo "✗ Markdown linting failed" - echo " Fix issues or run: npx markdownlint-cli2 --fix \"**/*.md\" \"#node_modules\"" + echo "✗ Markdown linting failed" >&2 + echo " Fix issues or run: npx markdownlint-cli2 --fix \"**/*.md\" \"#node_modules\"" >&2 exit 1 }