Skip to content

fix(oracles): own object-literal functions reached via dynamic lookup or whole-value reference - #197

Open
schiller-manuel wants to merge 1 commit into
mainfrom
fix/oracle-gaps-object-literal-owners
Open

schiller-manuel wants to merge 1 commit into
mainfrom
fix/oracle-gaps-object-literal-owners

Conversation

@schiller-manuel

Copy link
Copy Markdown

Problem

When an owned function dispatches dynamically through a module-level object literal (e.g. const handlers = { initialize: ..., openProject() {}, transform() {}, closeProject() {} }; handlers[message.method](params)) or passes it as a whole value (dispatch(handlers), Object.values(handlers)), oracle-gaps reported the object literal's methods as unowned warnings.

Findings

Checking owners.mjs and gap-report-static-oracle.property.test.mjs:

  • The existing static oracle laws intentionally keep object-literal methods separate in two cases:
    1. Static property reads (D_FNS.used() leaves spare unowned: a method of read module data that nothing calls unowned).
    2. Direct owns entries naming the variable (owns: ['src/sut.ts#D_FNS'] leaves methods unowned: a method of module data that an entry names unowned).
  • Dynamic lookup (handlers[key]) and whole-value references (dispatch(handlers), Object.values(handlers)) were not excluded by any law — this was an oversight compared to classes, where the existing law already states: "A class passed as a value brings all its methods, because which one is called is unknown statically".
  • Probing also uncovered two related bugs in owners.mjs:
    • referencesOf only skipped ts.isFunctionLike(child), so PropertyAssignment declaration names (initialize: (p) => ...) were accidentally visited as references, pulling arrow/function properties in even on static dot-reads and direct owns entries while missing MethodDeclarations.
    • ShorthandPropertyAssignment (const handlers = { fnA, fnB }) resolved to the shorthand property declaration rather than its value symbol (getShorthandAssignmentValueSymbol).

Changes

  • packages/oracles/oracle-gaps/owners.mjs:
    • When a data declaration (variable, property, export default, or module.exports =) is referenced dynamically (handlers[key]) or as a whole value (dispatch(handlers), Object.values(handlers), etc.), bring every function defined inside its value's span into the caller's ownership tree.
    • Preserve static property access (handlers.openProject(), resolved literal handlers['openProject']()), type-only/typeof positions (keyof typeof handlers), and direct owns: ['src/x.ts#handlers'] entries leaving sibling functions unowned.
    • Skip PropertyAssignment declaration names in referencesOf so arrow/function properties and method declarations behave consistently.
    • Resolve ShorthandPropertyAssignment value symbols via checker.getShorthandAssignmentValueSymbol.
  • packages/oracles/tests/oracle-gaps-owns-through-calls.test.ts:
    • Add regression tests for dynamic dispatch tables, static dot & string-literal reads, keyof typeof type queries, direct data owns entries, whole-value passing, Object.freeze/nested tables, shorthand properties, and cross-file/default/namespace imports.
  • packages/oracles/skills/oracles-design/SKILL.md (Step 6, Ownership):
    • Document static property reads vs dynamic lookup/whole-value references vs direct variable owns entries for object-literal dispatch maps.

Validation

  • pnpm test — passed
  • pnpm --filter @tanstack/oracles test:oracle-gaps:fast — passed (5 test files, 33,899 tests, including all gap-report-static-oracle module-data laws)
  • pnpm --filter @tanstack/oracles test:oracle-gaps:shards — passed (5 shards)
  • pnpm --filter @tanstack/oracles test:pr-shards — passed (7 partitions)
  • pnpm lint:check — passed
  • pnpm format:check — passed
  • pnpm typecheck — passed
  • pnpm build — passed

… or whole-value reference

When an owned function accesses a module-level object literal dynamically
(e.g. handlers[message.method]) or passes it as a whole value (e.g.
Object.values(handlers), dispatch(handlers)), which member is called is
unknown statically, so ownership now brings every function defined inside
the declaration's value into the caller's tree — matching the existing
rule for classes passed as values.

Static property reads (handlers.openProject(), handlers['openProject']())
and direct owns entries naming the data variable (src/x.ts#handlers) still
leave unreferenced sibling methods and function properties unowned. This
also fixes two related reference-resolution issues in owners.mjs:
- skip PropertyAssignment declaration names when walking module-level data
  so arrow/function property assignments behave consistently with methods
- resolve ShorthandPropertyAssignment value symbols ({ fnA, fnB })

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 27 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: acf57c25-a8a6-428f-9ad8-e88680d1e552
Commits

Reviewing files that changed from the base of the PR and between 7b6bae1 and 28283bd.

Files selected for processing: 3

  • packages/oracles/oracle-gaps/owners.mjs
  • packages/oracles/skills/oracles-design/SKILL.md
  • packages/oracles/tests/oracle-gaps-owns-through-calls.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@changeset-bot

changeset-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 28283bd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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