Skip to content

core aliases 189 internal/driver types, protocol messages such as WindowCommand and ShareRequest included, so a protocol change is a public API change #181

Open

Description

@houko

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:417 ShareRequest = driver.ShareRequest ("a share as the platform carries it out, ShareOptions resolved", struct at internal/driver/files.go:191) and core/shared.go:419 WindowCommand = driver.WindowCommand ("an ItemWindow's request", struct at internal/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 how ShareRequest carries resolved options is a breaking change for every app test that reads nsgotest.App.Window or Shares, 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 WindowCommand encoding 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:

  1. Classify the aliases. Add an allowlist to api_test.go of the driver types 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.
  2. Give nsgotest its own records. Replace raw protocol fields on nsgotest.App with record types of its own (for example nsgotest.WindowAction, nsgotest.Share) that carry what a test asserts on, converted from the protocol where the test host receives it. Migrate examples/gallery/app_test.go and ui/shells_test.go to them.
  3. Move the protocol messages off the public set. Once nothing public reaches them, drop the WindowCommand, ShareRequest and similar aliases from core/shared.go. For value types both sides need, keep them declared once in a leaf package that driver imports, so the dependency still points from protocol to vocabulary.

Acceptance

  • api_test.go fails when a public package reaches a driver type that is not on the allowlist.
  • nsgotest.App exposes no driver.* protocol message type; the gallery and ui tests assert through nsgotest's own records.
  • core/shared.go no longer aliases WindowCommand or ShareRequest, and a change to either struct does not change any public package's API.

Activity

  1. added
    enhancement
    on Nov 15, 2026
  2. houko commented on Nov 15, 2026

    @houko
    CollaboratorAuthor

    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.

    core aliases the WindowAction constants that reach the main surface's ItemWindow, WindowSetTitleBar through WindowSetMaterial (core/shared.go:865-877), but not WindowSetConstraints (internal/driver/services.go:158-160). Scope.SetWindowConstraints sends it as driver.WindowSetConstraints (core/desktop.go:48-51), and headless it lands in nsgotest.App.Window like the others. A test that asserts on it, the way examples/gallery/app_test.go matches c.Action == core.WindowToggleFullScreen, cannot name the action from outside the module. It has to fall back to "the last command whose Constraints is set".

    TestPublicAPINamesNoInternalType does not notice, because it checks types (api_test.go:26-139), and the WindowAction type 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 of nsgotest's own (point 2), for example a WindowConstraints entry, would remove the need for the constant. Until then, adding the missing alias is a one-line fix.

  3. self-assigned this
    on Nov 21, 2026
  4. houko commented on Nov 22, 2026

    @houko
    CollaboratorAuthor

    PR #1862 moves mounted image, input, modal, screen, scroll, video, Picture in Picture and sticky-cell snapshots into owned nsgotest records, 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, and WebConfig (the separate #1811).

  5. houko commented on Nov 22, 2026

    @houko
    CollaboratorAuthor

    PR #1866 gives hosts an owned core.StorageBackend contract for core.NewStore, with core.StorageChange, core.StorageOp and operation constants defined in core. The engine adapts those changes to existing platform backends. Both storage protocol records leave the public API allowlist, and core.NewStore is 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions