Repository navigation
Description
Context
core re-exports the platform protocol's types by alias so apps import core alone. core/shared.go:5-6: "The values apps share with the platforms. core/driver, the platform protocol, defines them; core aliases them so apps import core alone." The architecture docs record this as the design: docs/architecture/core.md:3 ("core aliases those its app API reaches in shared.go, and TestPublicAPINamesNoInternalType fails when one is missing") and docs/architecture/layers.md:126 ("core and nsgotest alias the internal types their API reaches").
Measured on main, core declares 189 type aliases of driver types (166 of them in core/shared.go, the rest in two other files) and re-declares 539 driver constants and 12 variables, 740 alias declarations in all. The types mix two kinds:
- Values apps build and read: colors, points, edges, alert configs.
- Protocol messages the platform carries out:
core/shared.go:417ShareRequest = driver.ShareRequest("a share as the platform carries it out, ShareOptions resolved", struct atinternal/driver/files.go:191) andcore/shared.go:419WindowCommand = driver.WindowCommand("an ItemWindow's request", struct atinternal/driver/services.go:229).
nsgotest's public App struct (nsgotest/nsgotest.go:146) exposes the protocol directly in 25 exported fields, for example Window []driver.WindowCommand (:280), Shares []driver.ShareRequest (:216), Picks []driver.PickRequest (:184) and Menu []driver.MenuEntry (:279). App tests then assert on protocol fields: examples/gallery/app_test.go:836 checks c.Action == core.WindowToggleFullScreen over app.Window, and ui/shells_test.go:280 declares var bar *core.WindowCommand.
The only guard is api_test.go:24-27, TestPublicAPINamesNoInternalType: it checks that every internal type a public package reaches has an alias. It does not check whether a type should be public, so making a protocol message reachable from nsgotest is enough to make it API.
Why it matters
- Protocol and API cannot change separately. Renaming a field of
WindowCommand, splitting an action into two items, or changing howShareRequestcarries resolved options is a breaking change for every app test that readsnsgotest.App.WindoworShares, although apps never send these messages themselves. - The test pushes toward more aliases. When a new protocol type becomes reachable, the test's fix is always to add an alias, so the public surface grows with the protocol.
- Tests assert on the wire format, not on the behavior. A test that wants "the app went full screen" has to match the
WindowCommandencoding of it, so the encoding becomes part of what tests pin.
Proposal
Keep the documented "apps import core alone" design, and narrow what the aliases cover:
- Classify the aliases. Add an allowlist to
api_test.goof thedrivertypes that may be aliased publicly (value types apps build and read). The test fails when a type outside it becomes reachable, so making a protocol message public is a decision, not a side effect. - Give
nsgotestits own records. Replace raw protocol fields onnsgotest.Appwith record types of its own (for examplensgotest.WindowAction,nsgotest.Share) that carry what a test asserts on, converted from the protocol where the test host receives it. Migrateexamples/gallery/app_test.goandui/shells_test.goto them. - Move the protocol messages off the public set. Once nothing public reaches them, drop the
WindowCommand,ShareRequestand similar aliases fromcore/shared.go. For value types both sides need, keep them declared once in a leaf package thatdriverimports, so the dependency still points from protocol to vocabulary.
Acceptance
api_test.gofails when a public package reaches adrivertype that is not on the allowlist.nsgotest.Appexposes nodriver.*protocol message type; the gallery anduitests assert throughnsgotest's own records.core/shared.gono longer aliasesWindowCommandorShareRequest, and a change to either struct does not change any public package's API.
Activity
houko commentedon Nov 15, 2026
A missing constant the API test cannot catch
A small data point for point 1, checked at aadbe7e and still true on main at 330763d.
corealiases theWindowActionconstants that reach the main surface'sItemWindow,WindowSetTitleBarthroughWindowSetMaterial(core/shared.go:865-877), but notWindowSetConstraints(internal/driver/services.go:158-160).Scope.SetWindowConstraintssends it asdriver.WindowSetConstraints(core/desktop.go:48-51), and headless it lands innsgotest.App.Windowlike the others. A test that asserts on it, the wayexamples/gallery/app_test.gomatchesc.Action == core.WindowToggleFullScreen, cannot name the action from outside the module. It has to fall back to "the last command whoseConstraintsis set".TestPublicAPINamesNoInternalTypedoes not notice, because it checks types (api_test.go:26-139), and theWindowActiontype is aliased. Only its constants are missing. This is the drift the issue describes: what tests can assert on depends on which constants someone remembered to re-declare. Test records ofnsgotest's own (point 2), for example aWindowConstraintsentry, would remove the need for the constant. Until then, adding the missing alias is a one-line fix.test(api): prevent retired service records from leaking again
test(api): prevent retired service records from leaking again
houko commentedon Nov 22, 2026
PR #1862 moves mounted image, input, modal, screen, scroll, video, Picture in Picture and sticky-cell snapshots into owned
nsgotestrecords, removing those eight protocol records from the public API allowlist. Mutable maps and lists are copied while resource identities and existing policy helpers are preserved.Verification: core 813 passed; nsgotest 162 passed and one skipped; list/sticky regressions 49 passed; public API, all layering variants and skills passed. Combined macOS, Linux, Windows, Android arm64 and web checks passed.
The remaining legacy protocol allowlist entries are
Event,EventKind,EventMask,StorageChange,StorageOp,SurfaceKind,TouchGeometry,ViewKind,ViewProps,ViewStyle, andWebConfig(the separate #1811).houko commentedon Nov 22, 2026
PR #1866 gives hosts an owned
core.StorageBackendcontract forcore.NewStore, withcore.StorageChange,core.StorageOpand operation constants defined incore. The engine adapts those changes to existing platform backends. Both storage protocol records leave the public API allowlist, andcore.NewStoreis checked as public API.Verification passed for the seven storage/partition regressions, four engine persistence regressions (including the new adapter), the full nsgotest suite (158 passed, one skipped), the public API guard, all 26 layering variants and skill checks. The combined macOS, iOS, Windows, Linux, Android arm64 and web matrix passed remotely, including both desktop architectures; CI Build and vet also passed.
The full CI test run reports 3464 passed, one failed and 50 skipped. Its sole failure,
TestMinimalAppLinks(macOS: net/http, crypto/tls, crypto/x509; Linux: net/http), reproduces identically on clean main 0919846 and predates this PR.Follow-up slices include #1862 (mounted configs), #1811 (WebConfig), #1869 (owned events, stacked on #1811), #1873 (owned view kinds), #1876 (owned view props) and #1880 (owned styles and animation values). These advance the cleanup without closing the broader issue. After the pending contracts combine, event kinds and event masks still need ownership; no mixed dependency branch was created.