Skip to content

Connections refactor, phase C (13/13): enforce the module interface - #2383

Open
mjuarros wants to merge 1 commit into
aws:mainfrom
mjuarros:connections-phase-c-enforce-interface
Open

mjuarros wants to merge 1 commit into
aws:mainfrom
mjuarros:connections-phase-c-enforce-interface

Conversation

@mjuarros

@mjuarros mjuarros commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Final PR of Phase C on #2299, completing the Connections consolidation epic #2296. Follows #2357 (PR 11) and #2361 (PR 12).

What this does

Three parts, all pure refactor — no behavior change, storage-key literals byte-identical, Phase A golden/pinning tests pass unchanged.

Enforce the module interface (the headline)

Adds two scoped oxlint no-restricted-imports rules in .oxlintrc.json:

  • Outside src/connections/: deep imports (@/connections/*) are blocked; the barrel @/connections stays allowed. core/StateProvider/storageAtoms.ts is exempt — it keeps its one sanctioned deep import of @/connections/legacyConnection (the module's top-level-await atom creation requires it; documented at the import site).
  • Inside src/connections/: importing the @/core barrel is blocked; specific core paths (@/core/StateProvider, etc.) stay allowed.

Both directions were verified to actually fire and allow:

  • deep @/connections/* import outside the module → errors
  • storageAtoms.ts deep import → allowed (exemption works)
  • barrel @/connections outside the module → allowed
  • bare @/core inside the module → errors; @/core/StateProvider inside the module → allowed

Add a ConnectionId brander + remove casts

createConnectionId() only generates new ids, so code receiving an existing id string was casting with as ConnectionId. Added a brander matching the repo's createVertexId/createEdgeId convention (the only cast now lives inside the creator) and removed the 5 as ConnectionId casts in defaultConnection.ts, parseConnectionFile.ts, and activeConnectionStorage.ts. No as ConnectionId cast on a plain string remains.

Final config-local sweep

Renamed the remaining deferred config-named locals that hold a SavedConnection/ConnectionId (activeConfigId, configId, etc. in edgeConnectionsQuery/schemaSyncQuery.test/UserPrefixes/AppStatusLoader/CreateConnection/Connect.test). Scope guard held: the inner .connection (ConnectionConfig) field, storage keys, kept-by-design symbols, and the user-facing "Reading configuration..." copy are untouched.

Testing

  • pnpm checks — green (lint/format/types)
  • pnpm test — green (3312 tests)
  • Phase A golden/pinning tests pass unchanged; no __fixtures__ touched.

Epic status

With this merged, epic #2296 is complete: all Connection code lives in src/connections/, the legacy Configuration* names are gone, and the module interface is enforced by lint.

…ith no-restricted-imports and add a ConnectionId brander

Final PR of phase C. Pure refactor, no behavior change: storage-key string
literals are byte-identical, no __fixtures__ edits, golden/pinning tests pass
unchanged.

Part A — ConnectionId brander + remove `as ConnectionId` casts
- `createConnectionId(id: string)` now brands an existing string, mirroring
  `createVertexId(id)`/`createEdgeId(id)` in core/entities/entityIdType.ts
  (the established convention: a function that takes the raw value and returns
  the branded type, with the lone internal cast living inside the creator).
- `createNewConnectionId()` generates a fresh UUID, mirroring the existing
  `createNewConnectionForm` "New" naming for value generation.
- Removed the 5 known `as ConnectionId` casts on existing strings
  (defaultConnection.ts x2, parseConnectionFile.ts x1,
  activeConnectionStorage.ts x2) plus 3 in tests
  (connectionFileGoldenFiles.test.ts x2, AppStatusLoader.test.tsx x1), all now
  via the brander. The only remaining cast is inside the brander itself.
- Updated generation call sites to `createNewConnectionId()`.

Part B — oxlint no-restricted-imports interface enforcement (issue aws#2299 item 13)
Two scoped overrides in .oxlintrc.json:
1. Outside src/connections/: block deep imports `@/connections/*` (barrel
   `@/connections` stays allowed). storageAtoms.ts is exempted via
   `excludeFiles` so its sanctioned `@/connections/legacyConnection` deep import
   keeps working.
2. Inside src/connections/: block the bare `@/core` barrel; specific core paths
   (e.g. `@/core/StateProvider`) stay allowed.

Probe results (throwaway files, all reverted; final tree has only the rule):
  (a) outside file importing `@/connections/defaultConnection` -> ERROR (fires)
  (b) storageAtoms.ts deep import of `@/connections/legacyConnection` -> allowed
  (c) outside file importing barrel `@/connections` -> allowed
  (d) inside file importing bare `@/core` -> ERROR (fires);
      inside file importing `@/core/StateProvider` -> allowed

The rule surfaced one real violation: AppStatusLoader.test.tsx deep-imported
`@/connections/defaultConnection` to spy on `fetchDefaultConnection`. Fixed to
import the barrel namespace `* as connections` and spy on
`connections.fetchDefaultConnection` (6 AppStatusLoader tests pass).

Part C — final sweep of deferred config-named locals
Renamed locals/params that hold a SavedConnection or ConnectionId:
  - UserPrefixes.tsx: `activeConfigId`->`activeConnectionId`, `configId`->`connectionId`
  - AppStatusLoader.tsx: `setActiveConfig`->`setActiveConnectionId`
  - connector/queries/schemaSyncQuery.test.ts: `activeConfigId`->`activeConnectionId`
  - Connect.test.tsx: `inactiveConfig`->`inactiveConnection`
Left untouched per scope guard: user-facing copy ("Reading configuration...",
etc.), the inner `.connection` field, storage-key literals, and kept-by-design
symbols (useConfiguration/MergedConfiguration, type-config locals).

Verification (run from repo root):
- `pnpm check:types` -> green
- `pnpm check:lint` -> clean on this tree (verified via oxlint with nested
  config disabled; the bare `pnpm check:lint` currently errors only on an
  unrelated stray `.worktrees/pr-2145-review/.oxlintrc.json` left by another
  task, which is untracked and not part of this commit)
- `pnpm check:format` -> clean
- `pnpm test` -> 251 files, 3312 tests passed
@mjuarros
mjuarros marked this pull request as ready for review October 8, 2026 00:21

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant