-
Notifications
You must be signed in to change notification settings - Fork 537
docs: add contribution baseline and AI use policy, trim agent guides #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+138
−332
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,24 @@ | ||
| # Agent guide | ||
|
|
||
| Solana program examples in three flavors per example: `anchor/`, `native/`, `pinocchio/` (a few have `asm/`). Path convention: `<category>/<example-name>/<framework>`. | ||
| Solana program examples, one per framework flavor (`anchor/`, `native/`, `pinocchio/`, a few `asm/`). Everything below is a decision or trap you cannot see from the files. | ||
|
|
||
| ## Layout rules | ||
| ## Deliberate structure | ||
|
|
||
| - **Not a pnpm workspace, on purpose.** Every example has its own `package.json` and `pnpm-lock.yaml` so it can be copied out and run standalone. Never introduce cross-example imports or shared JS helpers. Align dependency versions with `pnpm sync-package-json` from the root. | ||
| - **Rust is one workspace.** Most program crates are members of the root `Cargo.toml`. Crates that can't be members are listed in `.github/.workspace-ignore` (CI enforces one or the other). `tokens/token-2022/transfer-hook/block-list/pinocchio` and `games/world-cup/pinocchio` have their own workspaces. | ||
| - Toolchain pins: `rust-toolchain.toml`, `.nvmrc`, `packageManager` in the root `package.json`, `anchor_version`/`solana_version` in every `Anchor.toml`. | ||
|
|
||
| ## Build and test | ||
|
|
||
| | Framework | Build + test | | ||
| | ------------------ | --------------------------------------------------------------------------------------------------- | | ||
| | anchor | `anchor test` in the project (`[scripts] test` in `Anchor.toml` runs mocha) | | ||
| | native / pinocchio | `pnpm build-and-test` (cargo build-sbf into `tests/fixtures/`, then `pnpm test`) | | ||
| | asm | same script shape; programs assemble with `sbpf` (rev pinned in `.github/actions/setup/action.yml`) | | ||
| | world-cup | `just setup && just build && just test` — excluded from the pinocchio workflow by design | | ||
|
|
||
| Rust integration tests live in `program/tests/*.rs` (litesvm) and run with `cargo test --manifest-path=./program/Cargo.toml`; CI runs them only when `program/Cargo.toml` exists. | ||
| - **Not a pnpm workspace, on purpose.** Per-example `package.json` + `pnpm-lock.yaml` so an example can be copied out and run standalone. No cross-example imports, no shared JS helpers. Version alignment is `pnpm sync-package-json` from the root, not hoisting. | ||
| - Rust program crates must be root-workspace members or listed in `.github/.workspace-ignore` (CI enforces one or the other). | ||
| - `.github/.ghaignore` lists CI-skipped projects; every entry needs a comment with the real reason, and reasons rot: verify before trusting one. | ||
| - `games/world-cup` is excluded from the pinocchio workflow by design (own workspace, `just` build). | ||
|
|
||
| ## Test stack (do not deviate) | ||
|
|
||
| - Runner: **mocha 11 via tsx** (`mocha --import=tsx …`). Never ts-mocha, ts-node, jest, or `node:test` imports — `node:test` suites under mocha exit 0 even when failing. | ||
| - Runtime: **LiteSVM**. Non-anchor tests use `@solana/kit` + `litesvm` 1.x (pattern: `basics/hello-solana/native/tests/index.test.ts`, full version `tokens/create-token/pinocchio/tests/test.ts`). Anchor tests use `@anchor-lang/core` + `anchor-litesvm` + `litesvm` 0.8 with `@solana/web3.js` — deliberate, anchor's JS client is web3.js-based until it moves to kit. | ||
| - litesvm never throws on a failed transaction: assert `result instanceof FailedTransactionMetadata`. Sending the same bytes twice needs `svm.expireBlockhash()` in between. | ||
| - anchor-litesvm pins its own old litesvm; every anchor project carries `pnpm.overrides { "litesvm": "^0.8.0" }`. Without it, failed transactions pass `instanceof` checks silently. | ||
| - Tests must assert real post-state (account bytes, lamport deltas) and fail loudly — verify by breaking an assertion once. | ||
|
|
||
| ## Formatting and CI | ||
|
|
||
| - TS/MD/JSON: `pnpm format` / `pnpm run check` at the root (prettier, `@solana/prettier-config-solana`). Rust: `cargo fmt` at the root (shared `rustfmt.toml`); clippy runs with `-D warnings` in CI. | ||
| - Workflows discover projects by directory name (`anchor`, `native`, `pinocchio`, `asm`). `.github/.ghaignore` lists CI-skipped projects — every entry needs a comment with the real reason; verify a reason still holds before trusting it. | ||
| - Per-project CI: `pnpm install --frozen-lockfile` (commit lockfiles), `tsc --noEmit` when a `tsconfig.json` exists (keep `skipLibCheck`), build, test. | ||
| - Runner is mocha via tsx. Never `node:test` imports: `node:test` suites under mocha exit 0 even when failing. | ||
| - Non-anchor tests: `@solana/kit` + litesvm 1.x. Anchor tests: `@anchor-lang/core` + `anchor-litesvm` + litesvm **0.8** with `@solana/web3.js`: deliberate, anchor's JS client stays web3.js-based until it moves to kit. | ||
| - anchor-litesvm pins its own old litesvm, so every anchor project carries `pnpm.overrides { "litesvm": "^0.8.0" }`. Without it, failed transactions pass `instanceof` checks silently and tests go green. | ||
| - litesvm never throws on a failed transaction: assert `result instanceof FailedTransactionMetadata`. Resending identical bytes needs `svm.expireBlockhash()` in between. | ||
| - bankrun and the older harnesses were removed deliberately; don't reintroduce them from upstream examples or old tutorials. | ||
|
|
||
| ## Gotchas that have bitten before | ||
| ## Traps | ||
|
|
||
| - **Resolver-2 feature unification:** a crate must declare every feature-gated dependency it uses itself (e.g. `solana-address` with `curve25519`/`decode`). Whole-workspace builds mask missing features that per-crate CI builds expose. | ||
| - **`anchor keys sync` rewrites `declare_id!` and strips Anchor.toml comments.** Don't run it casually; `basics/cross-program-invocation/anchor` has committed keypairs with a drift guard — never resync it. | ||
| - Fixtures under `tests/fixtures/` are gitignored and built on demand; Metaplex `token_metadata.so` is dumped from mainnet by each project's `prepare.mjs` postinstall. The metadata natives build Metaplex instructions by hand in `mpl_util.rs` — there is no mpl crate dependency; keep it that way. | ||
| - Old runtimes (bankrun) and old harnesses were removed deliberately; don't reintroduce them from upstream examples or old tutorials. | ||
| - **Resolver-2 feature unification:** each crate must declare every feature-gated dependency it uses itself (e.g. `solana-address` with `curve25519`/`decode`). Whole-workspace builds mask what per-crate CI builds expose. | ||
| - **`anchor keys sync` rewrites `declare_id!` and strips Anchor.toml comments.** `basics/cross-program-invocation/anchor` has committed keypairs with a drift guard: never resync it. | ||
| - Metaplex `token_metadata.so` is dumped from mainnet by each project's `prepare.mjs` postinstall. The metadata natives hand-build Metaplex instructions in `mpl_util.rs`, with no mpl crate dependency: keep it that way. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.