House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
Build / Build (push) Successful in 30s
Build / Build (push) Successful in 30s
- Services, controllers and jobs take their dependencies through primary constructors and use them directly; where a method already named a local after a dependency, the dependency takes its type's name. - Every async method takes a CancellationToken last and passes it down to MongoDB, HTTP and the job queue. The setup claim is still given back when a request is cancelled. - The federation and media options are read through IOptionsMonitor. - The Mastodon entities keep sending "" for empty strings, and every model field where null means something says so. - The inbox's 503 with Retry-After, which other servers retry, is the one server error left, and says why. - Arasaka.HouseRules.Analyzers checks all of this in every build, here and in PrivaPub.ClientModels as decePubClient builds it. Checked against GoToSocial in the pasture: 64 passed, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
This commit is contained in:
1 parent
f0a14c737f
commit
0f73f69239
176 files changed
+2789
-3974
No files matched your search
@@ -1045,8 +1045,7 @@ client's role route never does.
|
||||
## Code style
|
||||
|
||||
- Tabs, block-scoped namespaces, Allman braces.
|
||||
- New services use `readonly _camel` fields and constructor injection. Older services use PascalCase fields; leave
|
||||
them.
|
||||
- Dependencies come in through primary constructors and are used as parameters (House rules, HR0004).
|
||||
- Services return `WebResult` (`PrivaPub.ClientModels/WebResult.cs`): `result.Invalidate(localizer[...], status)`.
|
||||
Controllers turn it into a status code.
|
||||
- Localised strings go through `IStringLocalizer<GenericRes>`.
|
||||
@@ -1060,6 +1059,45 @@ client's role route never does.
|
||||
- Libraries chosen for the roadmap: HtmlSanitizer, Markdig (`DisableHtml`), NSign (RFC 9421 inbound), OpenIddict +
|
||||
OpenIddict.MongoDb, NetVips, Blurhash.Core, FFMpegCore. No ImageSharp (licence key enforced), no MassTransit.
|
||||
|
||||
## House rules
|
||||
|
||||
The owner's rules for every .NET project (`~/RiderProjects/HouseRules/RULES.md`, repo `Arasaka/HouseRules`) apply
|
||||
here and win over anything else in this file. `Arasaka.HouseRules.Analyzers` (`Directory.Build.props`) reports the
|
||||
checkable ones as `HRxxxx` errors in every build and in Rider; decePubClient builds `PrivaPub.ClientModels` under the
|
||||
same rules. Applied to PrivaPub:
|
||||
|
||||
- **Coding style:**
|
||||
- `var x = default(T)` for a local without a value yet (HR0001).
|
||||
- `IOptionsMonitor<T>.CurrentValue`, never `IOptions<T>` (HR0002).
|
||||
- Primary constructors, using the parameters directly (HR0004). Where a method already names a local after the
|
||||
parameter (`media`, `statuses`, `settings`), the parameter takes its type's name (`IMediaService mediaService`).
|
||||
A private constructor behind static factories stays as it is (`RobotsTxt`, `RequestSignature`, `SafeArchive`).
|
||||
- A `CancellationToken token` last on every async method, passed down to MongoDB, HTTP and the job queue (HR0003).
|
||||
A write that must happen even when the request is cancelled passes `CancellationToken.None` on purpose (the
|
||||
setup claim and its release, the lease renewal). Exempt, with a reason on each: OpenIddict inline handlers (their
|
||||
signature is fixed), `Indexes.Plain` (a `params` array comes last), `JobWorker.KeepLease` (it takes the source it
|
||||
cancels).
|
||||
- **Models:**
|
||||
- Collections start as `= []` (HR0006) and strings have no `= string.Empty` (HR0005), unless null means something.
|
||||
Each exception carries a `[SuppressMessage("HouseRules", …, Justification = …)]` that says what: the Mastodon
|
||||
entities' strings (the API sends `""`, never null), "not stated" (`SearchableBy`, `RemoteInstance.Languages`),
|
||||
"every language" (`Following.Languages`), "fall back" (`Notification.StatusIds`, `ObjectRecord.Extensions`,
|
||||
`ObjectRecord.ContextNamespaces`), "keep the media" (`StatusDraft.MediaIds`), "no focal point" (`Focus`), and the
|
||||
Mastodon fields the API sends as null (`FilterResult` matches, `Poll.OwnVotes`, `Relationship.Languages`).
|
||||
- Request and response types in `PrivaPub.ClientModels` are `View*`, `*Request` and `*Form` (HR0010). The Mastodon
|
||||
entities and ActivityPub documents keep their names and JSON shapes: they are other software's contract.
|
||||
- **APIs:**
|
||||
- **No 5XX** (HR0007). The one exception: the inbox answers 503 with `Retry-After` while a signing key cannot be
|
||||
fetched yet, because ActivityPub servers retry it (`InboxReceiver.Receive`). The Mastodon API's own 4XX codes
|
||||
(422 for a request it refuses, 429 for the rate limits) are part of that API and stay.
|
||||
- Services take the user's id from the controller, never `IHttpContextAccessor` (HR0008).
|
||||
- Services return `WebResult`; a `LocalizedString` stored in it is cast, `(string)localizer[key]`, never `.Value`
|
||||
(HR0009).
|
||||
- Numbers shown to a reader go through formatting helpers (HR0011). The ISO week key (`InstanceDescriber.Week`)
|
||||
and the six-digit email code (`EmailVerificationJob.NewCode`) are identifiers, and say so.
|
||||
- **Still open:** route constants shared with decePubClient (HR0305; the frozen literals above stay their values)
|
||||
and source-generated JSON contexts (HR0306).
|
||||
|
||||
## Verifying
|
||||
|
||||
There is no test project (owner decision 2026-10-17: `PrivaPub.Tests` was removed, with the CI and deploy steps that
|
||||
|
||||
Reference in new issue
Block a user