Skip to content

Latest commit

 

History

History
476 lines (373 loc) · 24.5 KB

CONTRIBUTING.md

File metadata and controls

476 lines (373 loc) · 24.5 KB

Contributing to Heliobond

Thanks for helping build Heliobond — a green-bond investment app on Stellar that opens green investing to everyone, from one dollar. The same values we promise users (transparency, plain language, no dark patterns, accessibility) apply to how we build: in the open, kindly, and to a high bar.

Ways to contribute

There's a lane for most skill sets — pick by what you enjoy:

Lane Examples
Frontend (React / TypeScript) screens, components, the WebGL Helio, tests
Smart contracts (Rust / Soroban) the registry + vault, wiring live reads/writes
Localization (no deep code needed) translate the creator/admin/project surfaces, add a locale
Accessibility WCAG audit passes, keyboard / screen-reader fixes
Design extend the token system, motion, specimen cards
Docs improve guides, examples, this file

Find something to work on

  1. Browse good first issues and help wanted, or this project on GrantFox.
  2. Claim it before you start — comment on the issue (or apply via GrantFox) so it's assigned to you and we avoid duplicate work. Every issue states its scope and acceptance criteria.
  3. No issue for your idea? Open a Feature request first so we can agree on scope before you build.

We don't merge unsolicited PRs that aren't tied to an accepted issue — it keeps the queue clean and your time well spent.

Local setup

Prerequisites: bun 1.4.5 (the package manager / runner) and Node 22+.

git clone https://github.com/Heliobond/frontend.git
cd frontend
bun install
bun run dev        # http://localhost:3000

Useful scripts — run these before opening a PR:

bun run build               # production build (must pass)
bun run typecheck           # tsc --noEmit
bun run lint                # ESLint
bun run format:check        # Prettier — check only
bun run format              # Prettier — rewrite files in place
bun run test                # Bun unit + component test suite
bun run test:coverage       # Bun with the coverage thresholds CI enforces
bun run test:e2e            # Playwright end-to-end tests (dev server)
bun run test:e2e:production # Playwright against a production build with CSP enforced
bun run test:e2e:chain      # Playwright against a local Stellar network (see below)
bun run typecheck:coverage  # fails on any `any` in src/ (local only, not in CI)
bun run bundle:check        # bundle budgets against .next/ (run after build)
bun run start               # serve the production build

Only build, test:coverage and start are used by CI; the rest are the checks you run locally before you open a PR.

Install policy

  • Install with bun only. A preinstall guard (scripts/require-bun.mjs) makes npm, yarn and pnpm installs fail. bun.lock is the only lockfile; CI fails if package-lock.json, yarn.lock or pnpm-lock.yaml is committed.
  • Release-age cooldown. bunfig.toml sets minimumReleaseAge to 3 days, so bun will not install a version published less than 3 days ago. For a hotfix that must ship sooner, add the package to minimumReleaseAgeExcludes in bunfig.toml, with a maintainer's sign-off.
  • Lifecycle scripts are off by default. bun runs a dependency's install scripts only if it is in trustedDependencies. Keep that list empty unless a maintainer has reviewed the script.
  • Supply-chain checks in CI. scripts/lockfile-lint.mjs asserts every bun.lock entry comes from the npm registry with an integrity hash. The audit gate (scripts/audit-gate.mjs) fails on high and critical advisories. Exceptions live in scripts/audit-allowlist.json, each with a reason and an expiry date.

Testing

Unit and component tests

The project uses Bun’s test runner with jsdom and @testing-library/react for component rendering. Runner setup and discovery are configured in bunfig.toml.

bun run test                            # run the full suite
bun run test src/wallet/vault.test.ts   # run a single file

Structure. Unit and component tests are co-located with the code they cover, as <Name>.test.ts / <Name>.test.tsx next to <Name>.ts(x) — e.g. src/components/Button.test.tsx, src/wallet/vault.test.ts, src/hooks/useSessionTimeout.test.ts. Tests that cover cross-cutting behaviour rather than a single module (i18n catalog parity, shared bond math, contrast ratios) live in src/__tests__/. Bun discovers tests under src/ and scripts/. Import test APIs from @/test/bun.

Helpers. A shared render helper lives in src/test/render.tsx. It wraps components in the LocaleProvider (i18n) and ThemeProvider the app uses at runtime, so component tests get a realistic context instead of a bare tree. Import render (and re-exported @testing-library/react utilities like screen, fireEvent) from there instead of from @testing-library/react directly:

import { render, screen, fireEvent } from '@/test/render'

test('renders the primary label', () => {
  render(<Button variant="primary">Continue</Button>)
  expect(screen.getByRole('button', { name: 'Continue' })).toBeVisible()
})

If a test needs next-intl strings, they come from messages/en.json via the helper's LocaleProvider. Add new unit tests next to the code under test.

Coverage thresholds

bun run test:coverage   # run bun test with Istanbul instrumentation and enforce the thresholds

CI runs bun run test:coverage, so an unmet threshold fails the check even when the tests pass.

scripts/test-coverage-config.mjs defines the source scope, exclusions, and thresholds. The report includes eligible files that the tests never import. A doc test checks that each configured threshold is listed below.

Threshold key Minimum
src/lib/api.ts 80% lines / statements / functions
src/wallet/vault.ts 80% lines / statements / functions
src/lib/webauthn.ts 80% lines / statements / functions
src/lib/yieldAlerts.ts 80% lines / statements / functions
src/lib/recurringInvestments.ts 80% lines / statements / functions
src/lib/scrollToError.ts 80% lines / statements / functions
src/lib/errorMessages.ts 80% lines / statements / functions
src/wallet/registry.ts 80% lines
src/lib/** 55% lines
src/wallet/** 55% lines
src/session/** 55% lines
src/hooks/** 55% lines
src/config/** 55% lines
src/alerts/** 50% lines

The global floor for all of src/ is 50% lines / statements / functions and 40% branches. The directory floors exist to stop regressions, so raise them as admin.ts, registry.ts or useVault.ts gain tests.

New code under src/ counts against these thresholds, so run bun run test:coverage (not just bun run test) before pushing. The report lands in coverage/ (text summary in the terminal, HTML in coverage/index.html). Add tests alongside the change rather than lowering a threshold.

End-to-end tests (Playwright)

Playwright drives a real Chromium browser against the running Next.js dev server (config: playwright.config.ts — single Chromium project, dev server started automatically unless one is already running).

bun run test:e2e    # headless Chromium (starts dev server automatically)

Structure. E2E specs live in e2e/ as <flow>.spec.ts (e.g. e2e/deposit.spec.ts), one file per user-facing flow, grouped with test.describe. There's no page-object layer yet — specs query the DOM directly via Testing-Library-style locators (page.getByRole(...), page.getByText(...)).

Helpers. Because the wallet integration needs a real browser extension, specs seed a demo session via page.addInitScript before navigating, so the flow under test never depends on an actual Stellar wallet:

async function seedDemoWallet(page: Page) {
  await page.addInitScript(
    ({ address }) => {
      localStorage.setItem('hb-address', address)
      localStorage.setItem('hb-wallet', 'demo')
    },
    { address: DEMO_ADDRESS },
  )
}

Follow e2e/deposit.spec.ts as the template for a new flow: seed whatever session state the flow needs, page.goto() the route, then assert each step of the flow in order with expect(locator).toBeVisible() / toBeDisabled().

Production CSP and security headers

To test CSP and security headers against an enforce-mode production build without colliding with the backend API on port 3001:

bun run test:e2e:production

This starts a fresh production server on dedicated port 3200 (configurable via E2E_PRODUCTION_PORT), disables server reuse (reuseExistingServer: false), and verifies security headers without interference from .env.local or running backends on port 3001.

The run sets E2E_PRODUCTION=true and targets e2e/security-headers.spec.ts. That flag makes playwright.config.ts build the app and serve it on dedicated port 3200 with CSP_MODE=enforce, so assertions run against the enforcing Content-Security-Policy header instead of the Content-Security-Policy-Report-Only variant: no 'unsafe-eval', no ws: and no http://localhost anywhere in the policy, upgrade-insecure-requests present, and no CSP violations recorded on tested routes.

Run it whenever you touch src/proxy.ts, src/lib/securityHeaders.ts or anything inlined into <head>. It needs a full build, so it is slower than bun run test:e2e, and it is not part of standard CI.

Automated accessibility checks (Axe)

Heliobond includes automated accessibility tests powered by @axe-core/playwright in e2e/a11y.spec.ts. The audit checks all public routes and authenticated flows across both light and dark themes against WCAG 2.0 and 2.1 AA rules.

bun run test:e2e    # runs the full Playwright suite including a11y specs

The test fails on any serious or critical violation. Detailed results and violation objects are attached to the Playwright test report. Known pre-existing issues are tracked in the commented KNOWN_VIOLATIONS allowlist with links to their tracking GitHub issues.

On-chain journey (local Stellar network)

e2e/chain/investor-journey.spec.ts builds, signs and submits real Soroban transactions, so it runs against deployed contracts on a local network and needs a different config: playwright.chain.config.ts (testDir: ./e2e/chain, base URL http://localhost:3100, override with E2E_CHAIN_PORT).

Prerequisites, none of which this repo installs for you:

  • Docker, running quickstart with RPC and Horizon on port 8000:

    docker run -d --rm -p 8000:8000 --name stellar stellar/quickstart:latest \
      --local --enable core,rpc,horizon --limits unlimited
  • The stellar CLI on PATH (CI pins 26.1.0).

  • Rust with the wasm32v1-none target (rustup target add wasm32v1-none), because the setup script builds the contracts unless you point it at prebuilt WASM via CONTRACTS_WASM_DIR.

  • Access to Heliobond/contracts, which the script clones into .e2e/ (gitignored) at CONTRACTS_REF.

  • Playwright Chromium: bunx playwright install --with-deps chromium.

Then, from the repo root:

scripts/e2e/setup-local-network.sh   # fund accounts, deploy contracts, write env
bun run test:e2e:chain               # build + serve on :3100, then run the journey

The setup script writes e2e/chain/.env.chain.local (gitignored, throwaway keys only) and playwright.chain.config.ts loads it automatically; override the path with E2E_CHAIN_ENV. RPC_URL, HORIZON_URL, FRIENDBOT_URL, CONTRACTS_DIR, CONTRACTS_REF, CONTRACTS_WASM_DIR and OUT_ENV are the script's env knobs. It provisions e2e-admin, e2e-issuer and e2e-investor via friendbot, issues and deploys USDC, then deploys ProjectRegistry and InvestmentVault.

The journey itself is one long test (connect -> explore -> project -> deposit -> portfolio -> withdraw -> claim yield) with a 5-minute timeout and 30s expect timeouts, single worker, traces and video retained on failure under test-results/chain and playwright-report/chain. Tear the network down with docker rm -f stellar when you're done.

CI runs this same command nightly and on demand via .github/workflows/e2e-chain.yml (45-minute budget), not on pull requests.

Refreshing contract spec fixtures

When updating Soroban contract interfaces or after a contracts release, refresh the committed fixtures in src/test/fixtures/contracts/ using:

./scripts/contracts/update-specs.sh                                  # uses nearby WASMs or builds contracts@main
CONTRACTS_WASM_DIR=path/to/wasm ./scripts/contracts/update-specs.sh  # use another prebuilt WASM directory

Development workflow

  1. Branch off main: git checkout -b <type>/<short-description> (e.g. feat/withdraw-max-chip, fix/helio-glow, i18n/creator-screens).
  2. Make focused changes — one issue per PR.
  3. Run the checks locally: bun run build (must pass), bun run typecheck, bun run lint, bun run format:check, and bun run test. Add bun run test:coverage whenever you touch src/lib/ or src/wallet/ — CI enforces those thresholds, and bun run test doesn't.
  4. If your change is user-facing or otherwise notable (a feature, a fix, a breaking change), add an entry under [Unreleased] in CHANGELOG.md — see that file's "How entries are added" section for the format. Purely internal changes (refactors, tooling, formatting) don't need one.
  5. Open a PR using the template; link the issue with Closes #123.
  6. CI runs two jobs on every pull request and on pushes to main (.github/workflows/ci.yml): build (bun run build) and unit tests + coverage (bun run test:coverage). There is no CI job for lint, format:check or the Playwright suites, so those are yours to run locally. main must be protected so that green CI and human maintainer review are required before merge (branch protection is tracked in #912).

Review & Security Policy

  • Human Approval Required: No pull request can be merged automatically. At least one human approval from a repository maintainer (or CODEOWNER) is required before code lands on main.
  • Advisory Automated Review: The DeepSeek AI review workflow (auto-review.yml) is strictly advisory. It provides helpful PR summary comments but has no permission to approve PRs or trigger merges.
  • Least-Privilege Workflows: Workflows running on pull_request_target operate with least-privilege GITHUB_TOKEN credentials (read-only repository contents access). Administrative Personal Access Tokens (OWNER_PAT) are strictly prohibited in public workflow runs.
  • Enforced Status Checks: Branch protection on main must require the two CI checks — build and unit tests + coverage — to pass prior to merging. Nothing else is a required check: the DeepSeek auto-review.yml run is advisory, and e2e-chain.yml is nightly/on-demand rather than per-PR.

CODEOWNERS assigns maintainer review for sensitive areas — the wallet integration, design tokens, i18n catalogs, CI, and the supply-chain files (package.json, lockfiles, .husky/, scripts/, lint/build/test configs). Ownership is enforced only once branch protection requires code-owner review (#912).

Reviewing a fork PR safely

Reviewing a fork branch runs its code on your machine, so treat it as untrusted (see the supply-chain policy in SECURITY.md):

  1. Read the diff in raw form before running anything: git diff main...<branch> -- package.json bun.lock .husky .github scripts '*.config.*'. The GitHub diff view hides long whitespace runs, so the hidden-content check and supply-chain review gate checks are the reliable signal.
  2. Check the fork owner and the author match, and that new root-level files are expected.
  3. Do not run an untrusted branch on a machine that holds wallet secret keys or long-lived deploy tokens. Use a container or a Codespace, and make sure .env*.local contains only testnet values.
  4. Install with bun install --frozen-lockfile only after step 1. Lifecycle scripts run during install, so check any new dependency's scripts field first.
  5. Apply the supply-chain-reviewed label only after the changes in the job summary are understood. After a new push, remove and re-add it once the new commits are reviewed.

Internationalization

Heliobond uses next-intl with cookie-based locale selection. Five message catalogs ship, one per locale: messages/ar.json, messages/en.json, messages/es.json, messages/fr.json and messages/pt.json (the list lives in src/i18n/config.ts and is wired up in src/i18n/LocaleProvider.tsx; ar is right-to-left). The request config in src/i18n/request.ts loads the matching catalog for the current locale.

When you add or change user-facing copy:

  1. Pick the namespace that matches the surface using the copy, such as Nav, Footer, Landing, Deposit, or ProjectDetail.
  2. Add the same key path to all five catalogs — ar.json, en.json, es.json, fr.json, pt.json. The catalogs must stay in parity: src/__tests__/catalog-parity.test.ts compares every catalog against en key-for-key in both directions and fails the build on a missing or extra key, and it runs as part of bun run test and CI.
  3. Translate the value in every catalog. Do not leave English placeholder text in the non-English catalogs unless the issue explicitly calls for a temporary fallback.
  4. Read the key from code with useTranslations('<Namespace>'), then call t('<key>'). For example:
import { useTranslations } from 'next-intl'

export function Example() {
  const t = useTranslations('Creator')
  return <h1>{t('title')}</h1>
}

To add a new namespace for a new screen or surface:

  1. Create the namespace object in all five catalogs with identical keys:
{
  "Creator": {
    "title": "Build your project"
  }
}
  1. Add the translated values under the same namespace and key names in ar.json, es.json, fr.json and pt.json.
  2. Use that namespace from the component with useTranslations('Creator').
  3. Run bun run test (which includes the parity test) plus bun run build or bun run typecheck before opening the PR. Note what each one catches: the parity test catches keys missing from any catalog, while typecheck only catches missing or misspelled keys in English — src/i18n/next-intl.d.ts types Messages as typeof en, so tsc cannot see a key that exists only in fr.json (or the other three).

Adding a locale

To add a locale, use a lowercase BCP 47 language code as the catalog filename and update every locale registry in src/i18n/config.ts:

  1. Add the code to LOCALES.
  2. Add its short switcher label to LOCALE_LABELS and its native display name to LOCALE_NAMES.
  3. Add its Open Graph language_TERRITORY value to OG_LOCALES.
  4. If the language is right-to-left, add it to RTL_LOCALES. The root layout reads this set and applies dir="rtl"; otherwise, leave the locale out so it uses left-to-right layout.
  5. Create messages/<code>.json by copying the key structure of messages/en.json, then translate every value. The server request config loads the catalog dynamically, and LocaleProvider.tsx also imports the selected catalog dynamically, so neither file needs a per-locale import.
  6. Update src/__tests__/catalog-parity.test.ts: import the new catalog and add it to NON_EN so key, ICU argument, and translation checks cover it.

Verify the new locale with:

bun run test -- src/__tests__/catalog-parity.test.ts
bun run typecheck
bun run build

For a documentation-only verification, a maintainer should add a throwaway locale using only these steps, run the commands above, and remove the temporary catalog and registry entries afterward.

Quality bar

  • Builds and type-checks clean. bun run build is the gate; no any to paper over types, no @ts-ignore without a comment.
  • Follow the design system. Use the CSS custom properties (var(--ink), var(--solar), …) — never hardcode colours. See README.md and src/styles/tokens/.
  • Brand rules checklist. Every PR touching UI copy or design must meet all of the following:
    • Sentence case — no all-caps headlines.
    • Mono tabular numerals for figures.
    • Every delta carries a +/− sign and arrow; colour is never the sole carrier.
    • Solar is never the sole carrier of meaning (and never text on a light background).
    • No emoji in the product.
    • No exclamation marks on financial copy.
  • User-facing strings are translated. If you add or change copy in the shell or translated screens, add the key to all five catalogs (ar, en, es, fr, pt) — the parity test in src/__tests__/catalog-parity.test.ts fails the build otherwise.
  • Accessibility is not optional. Keyboard operable, visible focus, semantic landmarks, prefers-reduced-motion respected, touch targets ≥ 44px.
  • No secrets in the repo or in client code.

Definition of done

  • The issue's acceptance criteria are met.
  • CI is green; the PR is reviewed and approved.
  • UI changes include before/after screenshots (or a short screencast).
  • Docs/translations updated where relevant.

Reporting bugs & security

  • Bugs: open a Bug report issue with steps to reproduce.
  • Security: please do not open a public issue. Use GitHub's "Report a vulnerability" (Security tab) for a private advisory.

Pre-commit hooks

The project ships a Husky pre-commit hook in .husky/pre-commit, and it is already active on a fresh clone — there is nothing to opt in to. bun install runs the prepare script ("prepare": "husky") in package.json, which points core.hooksPath at .husky/_. Check it with:

git config core.hooksPath   # -> .husky/_

What it actually runs — .husky/pre-commit is two commands:

  1. bunx lint-staged, which per .lintstagedrc.json runs eslint --fix then prettier --write on staged *.{ts,tsx,js,jsx} files, and prettier --write on staged *.{json,md,yml,yaml} files. Only staged files are touched, and because these commands write, their fixes land in your commit — keep unrelated files unstaged so you don't sweep formatting changes into a focused PR.
  2. bun run typecheck (tsc --noEmit) over the whole project.

No tests run on commit. Run bun run test, and bun run test:coverage when you touched src/lib/ or src/wallet/, yourself before pushing — CI runs the unit suite with coverage thresholds but not the Playwright suites.

Opting out, if you need to:

HUSKY=0 bun install                   # skip installing the hook (per install)
git commit --no-verify                # skip the hook for one commit
git config core.hooksPath /dev/null   # disable it for this clone

bun run prepare re-installs it, and git config --unset core.hooksPath undoes the clone-wide opt-out. Contributors who skip the hook are still expected to run the checks in the Development workflow section.

By contributing, you agree to abide by the Code of Conduct.