diff --git a/CLAUDE.md b/CLAUDE.md index 4f9ce99a96..3060dcc3d9 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -70,7 +70,7 @@ CoGo depends on three other `appdevforall` repos; ARCHITECTURE.md (Sibling Repos - **Every screen must survive 2x font scale.** Users with low vision run large system fonts, and a screen that clips or hides content at 2.0 is broken for them. Verify any new or changed screen at font scale **1.0 and 2.0** (see Build & test, Emulator / device) and say in the PR that you did. Text grows, so: use `sp` for text and `dp` for spacing — never an `sp` dimen as a margin or padding; don't box text in a fixed `dp` height or width; give content that can grow somewhere to scroll; and reserve `maxLines`/`singleLine`/`ellipsize` for text that is genuinely disposable. - **Plan and size before building.** Prefer one PR per ticket/use case — don't force-split a coherent change (splitting has its own overhead when later edits span the pieces). - **Structure commits within a PR.** Separate mechanical/refactor commits from behavioral ones so reviewers can skim the boring parts and focus on the interesting ones. Treat ~500 LOC / ~10 files as a signal to reach for this discipline. Offer review-by-commit when it helps. -- **Use a PR stack when a single PR won't do.** For staged multi-module refactors (e.g. removing a dependency across many packages), split into a stack of PRs ordered easiest-to-hardest. Each PR in the stack must compile and pass tests independently, so a failure is isolated to the stage that caused it. The LOC ceiling for a single PR rises as LLM-assisted review matures. +- **Use a PR stack when a single PR won't do.** For staged multi-module refactors (e.g. removing a dependency across many packages), split into a stack of PRs ordered easiest-to-hardest. Each PR in the stack must compile and pass tests independently, so a failure is isolated to the stage that caused it. "Independently" means against current `origin/stage`, not the stale base the layer branched from: before merging a layer, merge `origin/stage` into it and compile. A clean `git merge-tree` does not mean it builds, and CI on the old base proves nothing. Land a fix in the lowest PR that has the bug, then merge it up the stack; a fix only in the top PR leaves every layer below it unsafe to merge alone. Squash-merging bottom-up makes each remaining layer conflict: merge the new base in, resolve to the layer's own side only the conflicts that duplicate the squashed PR (reconcile any independent `origin/stage` edit by hand), and prove nothing else changed (`git rev-parse HEAD^{tree}` equal to the pre-merge tree, or differing only by that edit; recipe in `docs/process/learnings.md`). The LOC ceiling for a single PR rises as LLM-assisted review matures. - **Before designing a way to make a costly operation cheaper, ask whether the operation is needed at all.** When a problem's severity scales with how often something happens — connections opened per second, requests issued per page, calls made per frame — eliminating the operations usually beats optimizing each one. Check whether the platform offers a way to do the work without them before writing the plan for the optimized version. ADFA-5172/5176 is the cautionary case: the server opened one TCP connection per documentation request to our own process, and `WebViewClient.shouldInterceptRequest` served the same content with no connection at all, which HTTP keep-alive would only have made cheaper per connection. - **Keep docs in step with code.** When you change code, update the docs that describe it in the same change — a module's `README.md`, `ARCHITECTURE.md`, or an ADR — so a doc never outlives the API it documents (see REVIEW.md, Code quality). If the doc fix is out of scope, file a ticket rather than let it drift. - `.androidide_root` is a sentinel file tests use to locate the project root — don't delete it. @@ -81,8 +81,9 @@ CoGo depends on three other `appdevforall` repos; ARCHITECTURE.md (Sibling Repos Four independent reviews of work already reported as verified each found a real defect in it. Before calling a change done, verified, or behaviour-neutral: - **Sweep the siblings, not just the site in front of you.** After a fix, grep for the other places the same pattern lives — the `UPDATE` beside the `INSERT` you fixed, the third entry point beside the two you guarded, the `Content-Type` *parameters* beside the media type you sanitised. Say in the PR which sites you checked, and which you deliberately left alone. -- **Prove the regression test fails without the fix.** Revert the fix, run the new test, confirm it fails *for the reason it is named for*, then restore. A test that passes against the unfixed code pins nothing. Watch for expectations that all coincide with one boundary value: if every case equals the minimum, a `MIN()` stub passes the whole suite. +- **Prove the regression test fails without the fix.** Revert the fix, run the new test, confirm it fails *for the reason it is named for*, then restore. Check `git diff` is non-empty after reverting: a revert that matched nothing runs the unchanged code and proves nothing. A test that passes against the unfixed code pins nothing. Watch for expectations that all coincide with one boundary value: if every case equals the minimum, a `MIN()` stub passes the whole suite. - **Match the handler to the failure the change exists to fix.** `catch (Exception)` does not catch an `Error`. A guard on two of three call sites is not a guard. +- **Disclose the limitations you accept.** If you notice a gap while designing a fix and judge it acceptable, say so in the PR body or the reply, with the reasoning. A reviewer should not have to discover it. - **Every claim needs its check.** "No behaviour change", "this MIME type has rows in the shipped database", "that tool logs a warning" are all testable — run the query, read the sibling repo's source, diff the commits — or don't write them. Re-read the PR body before pushing: a description that was true at commit 1 is often false by commit 3. Research answers and plans make claims too. A fact about an outside system - what a platform provides, who ships a product, what an APK contains - is a hypothesis until you check it against source, docs, or the artifact itself. Check it before stating it, or label it unverified. diff --git a/docs/process/learnings.md b/docs/process/learnings.md index 63385744b7..c5a9ca4d59 100644 --- a/docs/process/learnings.md +++ b/docs/process/learnings.md @@ -11,6 +11,12 @@ - **An `APPROVED` badge does not mean the current code was approved.** This repo does not dismiss stale reviews on push, so an approval can predate the commits it appears to cover — five PRs at once, in one case, one of them approved two weeks before the code it labelled. Compare the commit each approval points at with the PR head: `gh pr view --json reviews,headRefOid` and check the approving review's `commit.oid` against `headRefOid`. Timestamps are a weaker proxy, and `latestReviews` can come back with an empty `commit.oid`, so use `reviews`. - Before pushing a follow-up commit to a community PR, check `gh pr view --json headRepositoryOwner` — the PR head is usually on the contributor's **fork**, so a same-named push to `origin` doesn't touch the PR and just creates a confusing dead branch that has to be deleted. +## Stacked PRs +- **Squash-merging a stack bottom-up leaves each layer above it conflicting.** The squash is a new commit holding the layer's changes, while the layer carries them as the original commits (seen on ADFA-4930, three times). Recipe: merge the new base into the layer; resolve to the layer's own side (`git checkout --ours -- `) only the conflicts that duplicate the already-squashed lower PR, and reconcile by hand any file `origin/stage` changed independently (`--ours` discards that edit, and a later merge can overwrite it); delete any file git re-added that the layer renamed or removed (the pre-rename names came back); then prove nothing else changed. `git rev-parse HEAD^{tree}` must equal the pre-merge head's, or differ only by an independent stage edit you reconciled; that check shows the layer's own tree is unchanged, not that a stage edit survived. `git diff --stat origin/stage` must also show only the layer's own change, with the same file count as its PR diff. The merge commit then only makes the base an ancestor. +- **A merged branch is deleted on GitHub, so `git fetch origin origin/stage` fails and can leave `origin/stage` stale.** A tree comparison against the stale ref reported a false "differs". Fetch `stage` alone after a merge. +- **A stacked layer can compile against its old base and break on current `stage`.** `git merge-tree` reported no conflict because no one edited the line on both sides, but stage had made `FeatureFlags.isExperimentsEnabled` internal. Merge `origin/stage` into the layer and compile before asking for review. +- **CodeRabbit reports in inline comments and edits its first summary comment in place.** A poll for new reply comments saw only "Review triggered" and timed out while the findings sat inline. Watch inline comments and updated summaries too, and read "No actionable comments" as no new findings in that run, not as a clean stack: before declaring it clean, check every unresolved inline thread at the current head. + ## Android / Kotlin - A config data class whose **default** values call framework APIs (e.g. `ServerConfig`'s paths default to `Environment.getExternalStorageDirectory()`) makes itself unconstructable in a JVM unit test that doesn't stub those APIs — `RuntimeException: Method ... not mocked`, thrown from the constructor before your test body runs. Such a test has to pass *every* framework-backed parameter explicitly (or `mockkStatic` the API, or run under Robolectric), which is easy to miss when copying a config from a test that already does. Prefer lazily-resolved paths in new config types. - `Handler.removeCallbacks(Runnable)` only removes callbacks posted by that *exact* `Handler` instance, not just the same `Looper` — `Handler(Looper.getMainLooper()).removeCallbacks(x)` won't cancel something posted via a *different* `Handler` bound to the same looper. Any post/cancel pair needs to share one `Handler` instance (see `TaskExecutor.mainThreadHandler`, added when replacing blankj's `ThreadUtils.getMainHandler()`).