Skip to content

Development

jayjay181818 edited this page Nov 17, 2026 · 1 revision

Development

How to build, test and check Stockbar. The canonical text is Docs/Development.md; contributor etiquette is in CONTRIBUTING.md and the rules the code must keep are in AGENTS.md. For how the code fits together, see Architecture. For branches, release builds and signing, see Branches and Releases.

What you need

  • macOS 15.4 or later and a current Xcode. CI builds on two runners: macos-26 (Xcode 26, the oldest toolchain the project is expected to build with) and xcode-27 (the Xcode used for development).
  • SwiftLint, ripgrep and uv for the checks (CI installs them with Homebrew).
  • For anything that fetches market data, Stockbar's own Python environment: bash script/setup_python_env.sh creates it. The app uses it automatically. Trading 212 and Folync work without it. To use another environment, python3 -m pip install -r Stockbar/Resources/requirements.txt.

The Xcode project holds the deployment and language settings. Strict concurrency is on; do not infer the Swift language mode from the toolchain version.

Commands

Run these from the repository root. script/develop.sh is shared by local work and CI.

Command What it does
bash script/develop.sh build Debug build with signing off. No launch, no process killed.
bash script/develop.sh build-release The same for the Release configuration. CI runs it so the released configuration is always compiled.
bash script/develop.sh test The full XCTest suite.
bash script/develop.sh test StockbarTests/CacheCoordinatorTests One test class. Append /methodName for one method. The filter must look like StockbarTests/ClassName[/methodName]; anything else is refused.
bash script/develop.sh python-tests Compiles the three helper scripts to bytecode outside Resources, then runs the offline unit tests in PythonTests.
bash script/develop.sh checks SwiftLint, the entitlement check, the @unchecked Sendable allowlist check, the code-invariant check and the documentation check.
bash script/develop.sh docs-check Documentation links, duplicate instruction names and advisory size limits only.
bash script/develop.sh coverage A full test run with code coverage; prints overall line coverage and the least-covered files.
bash script/develop.sh acceptance /path/to/manifest.json The isolated Folync acceptance harness (see below).
bash script/develop.sh run A normal signed build and an explicit launch. This starts the real app and may use real app data.

Each run writes its full output to a private log and prints that path and the result. On failure it prints up to 15 error lines and a short tail (or the last 60 lines when no error lines match) and keeps the original exit code. By default logs, the SwiftLint cache and DerivedData are under the git-ignored build/ folder.

Variable Overrides
PYTHON The interpreter for the Python steps. Default: Stockbar's own environment if it exists, else python3.
STOCKBAR_DERIVED_DATA DerivedData folder. Concurrent agents or checkouts need different ones.
STOCKBAR_LOG_DIR Where the per-run logs go.
STOCKBAR_RESULT_DIR Where .xcresult bundles and coverage files go.

Run the smallest affected checks first, and broaden for changes to shared behaviour. A documentation-only change needs docs-check. A tooling change needs shell syntax checks and the fixture tests:

python3 -B -m unittest discover -s Scripts/tests -p 'test_*.py'

What CI runs

ci.yml runs on pushes and pull requests to main and testing on both runners. In order: install the locked Python packages, check the lock file against requirements.txt, python-tests, the tooling fixture tests, checks, build, test, build-release, and a package dry run of the Release build (signed, zipped and started once, nothing published). Failed test results and the logs are kept as workflow artifacts.

Tests

  • Tests must use isolated defaults, temporary or in-memory databases and stub providers. Do not reach live providers.
  • New app Swift files are picked up automatically. New XCTest files must be added to the test target in Xcode.
  • A change should come with a test that would fail without it.
  • Python tests are offline unit tests in PythonTests. The tooling tests in Scripts/tests cover the release feed, the Python setup script, and the backup and restore scripts.

Isolation rules

The build and test commands do not deliberately launch the normal app, but XCTest may launch its configured host. Under XCTest, StockbarRuntimeStorage creates its own temporary root and defaults suite for the process (xctest-…) and removes them at exit, so the suite never reads or writes the real app's defaults, files or Keychain items. Outside XCTest and acceptance it returns the standard defaults. State set through it still carries from one test to the next within a run, so a test that changes a default must restore it or use an injected store.

Keep these rules when you write code:

  • Use StockbarRuntimeStorage for app defaults and writable paths.
  • Gate live network and subprocess paths through StockbarProviderAccessPolicy.
  • Log with Logger, never print, so credentials are redacted.
  • Never include credentials, tokens, private hostnames, personal paths or real portfolio data in a change. Search the diff before publishing. Private notes belong in git-ignored files.

The acceptance harness

bash script/develop.sh acceptance <manifest.json> runs the app in an isolated way for checking behaviour such as Folync (it calls run_folync_acceptance.sh). It requires:

  • an existing manifest file below the operating system's temporary directory;
  • a token file beside it with mode 0600;
  • a loopback HTTP endpoint.

It builds a distinct acceptance bundle (com.stockbar.acceptance), turns live providers off, isolates storage and keeps the preflight and bootstrap evidence. It stays attached while its app runs; its log names the process ID and the evidence folder. A clean start is only a smoke check, so verify the behaviour you are claiming. Never put tokens in reports.

main.swift handles --acceptance-preflight and --acceptance-bootstrap before the app starts, so that code must stay first.

Running the app from a checkout

script/build_and_run.sh (used by develop.sh run) supports run, --debug, --logs, --telemetry and --verify.

  • It signs with the first valid Apple Development identity in the login Keychain, so macOS keeps Keychain access decisions across rebuilds. Set STOCKBAR_SIGNING_IDENTITY to a certificate name or SHA-1 to choose one, or to adhoc to opt out. No team ID is stored in the project.
  • It refuses to run while Stockbar is already running and never kills an existing process.
  • --verify checks start-up only and leaves the normal app running.
  • A normal launch may refresh providers and use real app data.

Dependencies

  • Python packages. Pins are in requirements.txt. requirements.lock holds every package they pull in at an exact version with checksums; Stockbar's own environment and CI install from it. After changing requirements.txt, run bash script/update_python_lock.sh (needs uv) and commit both files; CI fails when they disagree.
  • Weekly lock update. A scheduled workflow (Mondays) moves the locked packages to releases at least a week old and opens a pull request into testing.
  • Dependabot opens weekly, grouped pull requests into testing for GitHub Actions and the pinned helper packages.
  • The pins target Stockbar's own environment (Python 3.13; 3.10 is the minimum). CI runs the Python tests on 3.13; check they pass before merging a helper update.
  • setup_python_env.sh downloads a pinned uv only when there is no uv or Python 3.10+ already. To update it, change UV_VERSION and both UV_SHA256_* values together, and never remove the checksum check.
  • Sparkle is pinned to an exact version in the project, and Package.resolved is tracked so release builds resolve the same sources.
  • Do not install or upgrade packages as part of an unrelated change.

Scripts

Script Purpose
script/develop.sh The shared build, test and check entry point
script/build_and_run.sh Signed local build and launch
script/setup_python_env.sh Builds Stockbar's own Python environment
script/update_python_lock.sh Regenerates or checks requirements.lock
script/release.sh X.Y.Z Sets the version everywhere; see Branches and Releases
script/package_release.sh, sign_release.sh Build, sign and package a release; used by the release workflow
script/run_folync_acceptance.sh The acceptance harness
Scripts/backup_stockbar_data.sh, restore_stockbar_data.sh File backup and restore with the app quit. They do not include Keychain items. See Scripts/README.md.
Scripts/validate_*.sh, validate_agent_docs.py The invariant, entitlement, Sendable and documentation checks
Scripts/measure_performance.sh, Scripts/perf/ Performance measurement; see Performance and Benchmarks

Logs and recovery

Normal logs go to ~/Library/Logs/<bundle-id>/stockbar.log with rotation; acceptance runs log under their temporary root. Diagnostics in the main window shows the same log. File backups do not export broker or Folync Keychain credentials; see Backups, Export and Import.

Before you open a pull request

  1. Branch from testing.
  2. Run build, test, python-tests and checks (CI runs the same ones).
  3. Describe what changed and how you checked it, and say plainly what you did not check.
  4. Open the pull request into testing.

Clone this wiki locally