learnX is a React Native app (iOS, iPadOS, Mac Catalyst, Android, and an Electron build for Windows and Linux) for Tsinghua University's Web Learning, built on @robertying/thu-learn-lib. This file holds what applies everywhere. Folders with more to know have their own AGENTS.md (git ls-files '*AGENTS.md'), and the workflows are skills in .claude/skills. CONTRIBUTING.md is the setup guide for a fresh clone, and patches/README.md says why each dependency is patched.
package.json'sscriptsare the entry points: Metro, the platform builds, the checks, the E2E runs, the Electron app and the release helpers.cd ios && bundle exec pod installinstalls the pods with the CocoaPods version locked inGemfile.lock(runbundle installonce first); run it afterios/Podfile, a native package or a patch changes.pnpm pod:updatealso runspod update, which moves pods to newer versions: use it only when upgrading (the upgrade-dependencies skill). Use the Ruby in.ruby-versionwith a gem folder you can write to, such as Homebrew's.- The Xcode targets' folders are synchronized folders: a file added there joins its target with no project change. Files a target must not copy as resources, and files one target compiles from elsewhere, are in the project's exception sets.
- Run
pnpm format(Oxfmt) after changing files.pnpm checkmust pass before committing; it is what CI'sJS / Checksruns. Lint is type-aware: mark an intentionally unawaited promise withvoid. - User-visible text goes in
src/assets/translations(wording rules in itsAGENTS.md), read witht('key', { param })fromhelpers/i18n. Dates and times are translations too, written out with the formatters in the same file. Thelearnx/no-han-outside-translationslint rule rejects Chinese text elsewhere insrc; disable it per line only for text that must not be translated, with the reason. - Debug builds load JS from Metro; only native changes need a rebuild.
scripts/checks/test-ios.shandscripts/checks/test-android.shrun the native tests (modules/AGENTS.md). .env(git-ignored, see.env.example) is inlined at build time bybabel/inline-env.js, which passes only the keys it lists: add a key there before reading it in the app. Keys it doesn't list (the live test login) never reach a bundle.android/local.properties(git-ignored, see its.example) holds the Android release signing values; debug builds don't need it. The app can be used without a Tsinghua account through the mock login (src/data/AGENTS.md).
scripts/is grouped by purpose (e2e/,checks/,ci/,release/,xcode/,dev/for a developer's own machine, andlib/for what scripts of several groups source), with their Jest tests inscripts/__tests__. Scriptscdto the repo root, so paths inside them start there.- In
srcandjest, a file is named after what it exports: PascalCase for a component, screen or navigator and for a default-exported constant object; camelCase for hooks, helpers, data, services and files with several exports. Folders are lowercase. Tests are<module>.test.ts(x)in the folder's__tests__(<module>.<case>.test.tsfor a case that needs a fresh module); one table of cases over sibling screens is named for the group. - Platform variants use React Native's platform extensions:
Name.tsxfor iOS and Mac,Name.android.tsxfor Android,Name.web.tsxfor the Electron app (a React Native Web build), andName.shared.tsfor what every platform uses. Never put the platform in the name itself (NameAndroid.tsx). - Code lives with its feature, and the platform shows in the file extension: the Electron app's version of a component, hook or service is
Name.web.ts(x)next to the phones'Name.ts(x), which is a no-op where the phones have none, so Metro never puts it in a phone's bundle. An Electron-only module that only.webfiles import is named for the Electron app. A one-off call into Electron-only code from shared code may insteadrequireit inside anisElectron()branch, which release builds fold away (babel/inline-platform.js;scripts/checks/check-bundle-platform.mjschecks).src/webholds only what has no feature to live with, andsrc/web/packagesonly the stand-ins for npm packages thatsrc/web/aliases.jsonnames. The Electron app's names sayelectron, neverdesktop; user-visible text may say desktop. - In code, check the platform with
isApple()(iOS, iPadOS and Mac Catalyst),isAndroid()andisElectron()fromhelpers/platform, notPlatform.OS. Ask for the platform a branch is for (isApple()for an Apple API or design), not for "not Android": a platform added later then takes neither by accident. - Scripts, Maestro flows, mock files and patches are kebab-case. Swift and Kotlin files are PascalCase.
- Names set by something else stay as they are: Android resources and the icons in
src/assets/iconsare snake_case,ios/ExpoWidgetsTarget/index.swiftmatches what the expo-widgets config plugin generates, anddocs/PRIVACY_POLICY_*.mdare linked from the store listings.
babel-plugin-react-compilermemoizes every component and hook undersrc/, so don't adduseMemo,useCallbackorReact.memofor performance.- Don't make an effect depend on a function. A function that an effect only calls goes in
useEffectEvent, and the effect lists the data it reacts to. The compiler's memoization is an optimization, not a guarantee, so an effect shouldn't rerun just because a function fell out of compilation.react-hooks/exhaustive-depsflags the direct cases. useCallback/useMemoare still right where a value has to keep its identity and can't be an effect event: handlers handed tonavigation.setOptionsfrom an effect, values in a context provider, and hook outputs that callers use as effect deps.- The compiler silently skips a function it can't handle and leaves it unmemoized, for example
tryblocks withfinally,throw, or conditional, logical or optional-chaining expressions: compute values before thetryand keep only the awaited calls inside it. Constants nameduse…are taken for hooks, so don't use that prefix for non-hooks.
- The Electron app takes no over-the-air updates: its web build ships inside the installer (
electron/AGENTS.md). The rest of this section is about iOS, iPadOS, Mac and Android. expo-updatesreplaces the JS bundle without a store release, from an update server that speaks the Expo Updates protocol. Release builds bundle withexpo export:embedand Metro uses Expo's config, so a store build's bundle and an update are made the same way.app.jsonholds the update URL, the request headers and the runtime version, andcerts/ota-certificate.pemthe code-signing certificate (the private key is never in the repo). Builds write them into each platform's native config, andscripts/__tests__/otaConfig.test.tskeeps the two platforms in step. The release build lanes refuse the placeholder URL.- A build takes only updates published for its exact runtime version, whatever its build number. The runtime version is the app version of the first release with the current native code: a release that changes only JS keeps it, so one update reaches every version since. Set it to the new app version in any release that changes native code, which is more than Swift and Kotlin: native packages and patches, build settings, Info.plist, String Catalogs, icons, the widgets, and a persisted store's version (
src/data/storeVersions.json). JS that calls a native API an older binary lacks also needs a store release. - The app version on main is the coming release's, on every platform (
package.json, the Xcode project'sMARKETING_VERSION,versionNameinandroid/app/build.gradle; the Electron app readspackage.json), and the runtime version moves with it: the pull request that sets a new runtime version also moves the app version to it (pnpm bump minor, or patch or major). A version moves only once it has shipped to production (itsv<version>tag, which publishing the GitHub release makes): until then every build of the coming release, TestFlight and Play betas included, keeps it, and so does the runtime version. Build numbers are never committed: the release lanes set them per build (the release skill). pnpm ota:checkenforces this against the native fingerprints recorded inota-fingerprint.json(what counts as native is infingerprint.config.js); its header says what it checks, and on a failure it prints the values to record. Record CI's values, from a clean checkout, since a local one can differ. So the first native change after a release sets the runtime version and the app version to the coming release's version, and later ones in that cycle only update the record.- The native side checks on every cold launch and downloads in the background; the update starts at the next launch. Coming back after a long time in the background checks again, or starts an update already downloaded (
updateOnReturninservices/ota), run first byhooks/useReLoginso a reload never cuts off a login or a fetch. Each window opens again at the tab and item it showed:services/windowssaves every window's link just before the reload (keepWindowLinksForReload), andhooks/useLinkTapsopens it once in place of the launch link (takeReloadLink). Debug builds load from Metro and never use updates. Crash reports carry the running update's id, which says which source map decodes them. - E2E builds never ask the real server: they get their own runtime version, a local update server and a test certificate.
scripts/e2e/e2e-ota.shruns the update flow (.maestro/AGENTS.md).
src/helpersholds logic with no side effects beyond thin platform reads, tested without mocks of the server or the system. Code that talks to the system or to a server outsidedata/sourcelives insrc/services.@testing-library/react-native'srender,renderHook,rerenderandactare async: await them.- Mock native modules and the data layer per test file; use the real Zustand stores (
setSetting,resetUserData, …) instead of mocking them. Global mocks and native view stand-ins are set up injest/setup.tsfor the phones andjest/web/setup.tsfor the Electron app, both onjest/common.ts, and injest/mocks/: read them before testing something that renders a native view. Jest clears mocks and restores spies after each test, andjest/setupAfterEnv.tsresets timers, the language and the clock format, so switch platforms withjest.replaceProperty(Platform, 'OS', 'android'), timers withjest.useFakeTimers()and the language withmockLocale.current(test-utils/locale), and don't restore by hand. - A test fails on any
console.errororconsole.warnit doesn't expect (jest/setupAfterEnv.ts), Testing Library's own warnings included: change a store that a rendered component reads insideawait act(...), inafterEachtoo, and lay views out withfireLayoutfromtest-utils/layout. A test that expects a log spies on it. - Test hooks that hold real logic (state, ordering, error paths), not thin wrappers around one call.
- Components and screens are tested with
renderandscreen, one file per component or screen named after it; shared test data goes injest/fixtures/. Tests import fromjest/astest-utils/…, never by a relative path. Query what the user sees (text, role,testID); press throughuserEvent, sincefireEvent.presscan bubble to the test element's ownonPressprop. Screens get their props fromscreenProps(test-utils/screenProps) and mock their data hooks. jest.config.jshas a project per platform, each loading that platform's files, so an Android or Electron variant is tested in an__tests__/android/or__tests__/web/folder; the tooling project runsscripts/__tests__and the Electron main process's tests.- CI fails when coverage drops below
coverageThresholdinjest.config.js(kept just under the current numbers). Cover new code with tests, and raise the thresholds when coverage grows.
- One change per pull request, squash-merged once the required checks pass. The title and description say what the change does compared with
mainand why, for a reader who hasn't seen how it came about: no history of earlier attempts or review rounds. The squash commit message follows the same rule. - Docs and comments say why, and what isn't plain from the code. They don't restate what the code shows, or keep lists (of files, scripts, flows, versions, counts) that a change elsewhere would leave stale: point to where the list lives instead.