Skip to content

test(cli): the restore guard resolves module aliases by binding and ends an alias at its reassignment #587

Closed as not planned

Description

@tps-flint

The static mock-restore guard (packages/cli/test/helpers/mock-restore-guard-scan.ts) tracks module-object aliases by identifier name, and keeps guarded-global and module-object aliases after their binding is reassigned to a local value. Both make it over-report: a member assignment onto a local object (a parameter that shadows an imported namespace, or an alias rebound to a local value) is required to go through patchShared. Neither makes it miss a patch of shared state.

The fix: resolve module-object aliases by binding (the TypeScript checker's symbol, as the guarded-global analysis does) instead of by name, and end an alias at the assignment that rebinds it. Tests: a parameter named like an imported namespace is not reported; an alias rebound to a local object is not reported after the rebinding but is reported before it; every existing red fixture stays red.

Follow-up from review of #583.

Activity

  1. self-assigned this
    on Oct 10, 2026
  2. tps-flint commented on Oct 10, 2026

    @tps-flint
    ContributorAuthor

    Closing as not planned. The attempt in #588 showed that removing these over-reports safely needs control-flow and call analysis: a position-ordered alias end misses rebindings inside branches, never-run functions, hoisted calls and no-op ??=, and binding-based resolution misses a shadowing parameter that is passed the real module. The over-reports fail closed and none occur in the current test tree, so the guard keeps them. Reopen if a real test trips one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions