Skip to content

Import-boundary rule misses bare specifiers, so core can reach an adapter through the package's own exports map #579

Done

Description

@ocsi-architect

Problem

test/host/import-boundary.test.ts inspects only relative specifiers, so the boundary it enforces can be crossed by naming the package itself. The rule is the sole enforcement of the core-to-adapter separation — typecheck and lint do not catch a relative violation either — so a hole in the rule is a hole in the invariant, not a style gap.

Reproduction

At the head of the adapter-isolation pull, in a scratch worktree, with package.json exporting "./tui" to ./src/adapters/opencode/tui/panel.tsx:

// src/runtime/setup.ts
import * as probe from "opencode-self-improvement/tui";
void probe;

Both assertions in test/host/import-boundary.test.ts pass and bun run typecheck reports no errors. The same import expressed relatively is caught.

Required

  • Resolve bare specifiers that name this package through its own exports map, and apply the existing deny set to the resolved target.
  • Keep the test's own fail-before fixtures: add the bare-specifier shape alongside the existing ones so the coverage is pinned rather than intended.
  • Run the sweep across every dependency form already handled — static, import type, export *, named re-export, dynamic import(), require, and typeof import() — since the resolution change affects all of them.

Acceptance

The import above fails the boundary test with a message naming the file and the resolved adapter target, while typecheck still passes; a control fixture using an unrelated bare specifier stays clean, so the rule cannot be satisfied by blanket-banning all bare imports.

Activity

  1. added
    test-integrity
    severity:medium
    on Nov 28, 2026
  2. ocsi-architect commented on Nov 28, 2026

    @ocsi-architect
    Author

    Raising the severity now that the adapter isolation has landed: on main at ad176f9 (0.38.2) the bypass resolves straight into shipped adapter code, so this is no longer a latent gap in a rule protecting a future layout.

    Re-measured at that head in a scratch worktree, with the published exports map on main reading "./tui": "./src/adapters/opencode/tui/panel.tsx":

    • Relative violation — src/runtime/setup.ts importing ../adapters/opencode/identity.ts — fails shared source cannot depend on adapters or their entry forwarders. Enforced.
    • Bare self-reference — src/runtime/setup.ts importing opencode-self-improvement/tui — passes both assertions of that test and typecheck reports no errors. Not enforced, and the resolved target is now src/adapters/opencode/tui/panel.tsx.

    The rule's AST walk inspects specifiers that begin with ., so a dependency named after the package itself never enters resolution. Nothing in the tree uses that shape today, which is the only reason this is not a live violation.

  3. added
    severity:high
    verified-on-main
    and removed
    severity:medium
    on Nov 28, 2026
  4. ocsi-architect commented on Dec 2, 2026

    @ocsi-architect
    Author

    Architect

    Already fixed on main. Closing as done — no pull request, because there is nothing left to change.

    Filed 2026-11-28 against 0.38.2 (ad176f9), where the premise was true. It stopped being true with 65a005f feat: route maintained adapters through the public engine API, merged 2026-12-01 through PR #601 and shipped in 0.42.0 (6e6acec). The ticket was never re-run after that merge.

    Measured at three trees in a scratch clone (the live checkout was not touched), current main = 0344d56:

    # Tree + probe Result
    1 ad176f9 + import * as probe from "opencode-self-improvement/tui" 0 fail — premise held at filing
    2 ad176f9 + relative ../adapters/opencode/identity.ts (fail) — the rule the ticket was written against
    3 0344d56 + this ticket's exact example (fail) src/runtime/setup.ts:262: unsupported dependency opencode-self-improvement/tui
    4 0344d56 + opencode-self-improvement/adapters/pi (fail) at setup.ts:264
    5 0344d56 + control import { join } from "node:path" 0 fail — no false positive on real dependencies
    6 0344d56 + ./tui, then bun x tsc --noEmit exit 0: the self-reference compiles, resolving through exports to src/adapters/opencode/tui/panel.tsx; foil opencode-self-improvement/no-such-key-xyz → TS2307, so tsc really evaluated it

    The rule that closes it, on main at test/host/import-boundary.test.ts:8 and :63:

    const publicEngine = new Set(["opencode-self-improvement/host", "opencode-self-improvement/status"])
    // …
    if (specifier === "opencode-self-improvement" || specifier.startsWith("opencode-self-improvement/")) {
      if (!publicEngine.has(specifier)) reject();   // deny by default
      return;
    }

    At filing the only gate was if (!specifier.startsWith(".")) return;, so a bare self-named specifier never entered the check at all. Every import form now routes through the same check() — static, import type, export *, named re-export, import(), require, typeof import(), template literals — and expected-violation fixtures for opencode-self-improvement/{pi,oh-my-pi,tui,""} in core files are pinned (4 tests / 124 expects).

    Answer to the ticket's question. Can core reach an adapter through a bare self-import on main? No — and not via the exports map either: every package-named specifier except the two public-engine keys is rejected before resolution, and both allowed keys resolve to core code (src/host/index.ts, src/status/index.ts).

    The limitation the fix leaves behind, stated rather than glossed. What landed is string enumeration, not resolution: a hardcoded two-key allow-list with no exports-map lookup. There is no live hole today, because the default is deny and both keys point into core. It can rot in the direction this ticket predicted: if ./host or ./status is ever repointed into the adapter layer, the rule waves the edge through without resolving it, and the rejection message names file + specifier rather than the resolved target the acceptance criteria asked for. That is a different change from the one this ticket requested, so it will be filed as its own ticket rather than smuggled into this one as a reason to keep it open.

  5. abogartz commented on Dec 2, 2026

    @abogartz
    Owner

    Closed as done. Already fixed on main by 65a005f (PR #601, shipped 0.42.0). Measured at ad176f9 the bare self-import slipped through (premise true at filing); at 0344d56 test/host/import-boundary.test.ts:63 rejects every package-named specifier outside publicEngine, so opencode-self-improvement/tui fails the boundary rule. Certificate with the six-case measurement table posted above.

    Reopen it whenever the premise comes back; nothing here is deleted and the history stays put.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    severity:hightest-integrityverified-on-main

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions