Repository navigation
fix(oracles): own object-literal functions reached via dynamic lookup or whole-value reference - #197
Open
schiller-manuel wants to merge 5 commits into
Open
schiller-manuel wants to merge 5 commits into
schiller-manuel wants to merge 5 commits into
Conversation
… 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>
|
Warning Review limit reachedYou'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 33 minutes. View limit details
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. |
🦋 Changeset detectedLatest commit: 7b23fc3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The maintainer ruled on 2026-11-23 that a function defined in a module object literal is owned when the literal is used dynamically or as a whole value, and that a static property read owns only its member. The rule had only pinned tests. This adds a generated law to the static gap oracle family. The new oracle generates modules with a literal of arrow, method, and shorthand members (names may shadow module functions), one use in run (dynamic lookup, passed, Object.values, spread, static read, or none), and an entry that is run or the literal. Its model is an independent graph over the history, not owners.mjs. The driver reads each unit's ownership through the production analyze and owned.at. Each reach state has a constructed history. Law: a module object literal's functions are owned by how the literal is used (decisions register, M 2026-11-23; ownership law P6, R6, I10; F10). Reach: 120 random histories per seed, plus nine constructed states; generated reach counts 15 to 116 per state (fixed seed 20261123). RED: on main's owners.mjs, 20 of 32 units fail (vitest, this file). GREEN: on head, 32 of 32 pass; the package fast suite passes 33,931 tests. Mutants on head owners.mjs, each killed: whole-value not counted (14 of 32 fail), shorthand value symbol reverted (20), static reads treated as whole values (5), property-name visit restored (15). Co-authored-by: Isaac <no-reply@databricks.com>
The design skill's ownership paragraph now says the dispatch rule is the maintainers' ruling of 2026-11-23 (decisions register, "Object-literal functions used dynamically are owned"), judged by the static gap oracle's dispatch law. A spread of the literal is named as a whole-value use. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
The static shards select tests with a name pattern that matches a suite named oracle-gaps.report-static followed by " > " or a space. The dispatch oracle's suite, oracle-gaps.report-static-dispatch, matches neither, so both shards skipped all of its tests (32 skipped on the shard pattern check). The third job runs its file whole. Co-authored-by: Isaac <no-reply@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-gapsreported the object literal's methods as unowned warnings.Findings
Checking
owners.mjsandgap-report-static-oracle.property.test.mjs:D_FNS.used()leavesspareunowned:a method of read module data that nothing calls unowned).ownsentries naming the variable (owns: ['src/sut.ts#D_FNS']leaves methods unowned:a method of module data that an entry names unowned).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".owners.mjs:referencesOfonly skippedts.isFunctionLike(child), soPropertyAssignmentdeclaration names (initialize: (p) => ...) were accidentally visited as references, pulling arrow/function properties in even on static dot-reads and directownsentries while missingMethodDeclarations.ShorthandPropertyAssignment(const handlers = { fnA, fnB }) resolved to the shorthand property declaration rather than its value symbol (getShorthandAssignmentValueSymbol).Changes
packages/oracles/oracle-gaps/owners.mjs:export default, ormodule.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.handlers.openProject(), resolved literalhandlers['openProject']()), type-only/typeofpositions (keyof typeof handlers), and directowns: ['src/x.ts#handlers']entries leaving sibling functions unowned.PropertyAssignmentdeclaration names inreferencesOfso arrow/function properties and method declarations behave consistently.ShorthandPropertyAssignmentvalue symbols viachecker.getShorthandAssignmentValueSymbol.packages/oracles/tests/oracle-gaps-owns-through-calls.test.ts:keyof typeoftype queries, direct dataownsentries, 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):ownsentries for object-literal dispatch maps.Validation
pnpm test— passedpnpm --filter @tanstack/oracles test:oracle-gaps:fast— passed (5 test files, 33,899 tests, including allgap-report-static-oraclemodule-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— passedpnpm format:check— passedpnpm typecheck— passedpnpm build— passedFollow-up: law, evidence, and limits (commits 86ff3e6, 834795e, c920740, 7b23fc3)
Follows the maintainer's ruling of 2026-11-23 (decisions register, "Object-literal functions used dynamically are owned"). The rule now has an oracle law, not only the skill text and pinned tests.
Law. A function defined in a module-level object literal is owned when the literal is used dynamically (
table[key]()) or as a whole value (passed to a function, spread, or read withObject.values). A static property read owns only its member. A shorthand name in the literal is owned through the literal's initializer (F10). Anownsentry on the literal owns no member. A property name in the literal refers to no binding. Authority: the ruling above, and the ownership law ofowners.mjs(P6, R6, I10: the static call tree ofowns, unioned over oracle files). The model is an independent graph over the generated history, and it does not readowners.mjs.Oracle.
packages/oracles/oracle-gaps/gap-report-static-oracle-dispatch.property.test.mjs, a sibling of the static oracle. It is a new file rather than an append togap-report-static-oracle.property.test.mjs, so it adds no lines to that file.Reach. Each fixed-seed and random-seed campaign runs 120 generated histories. Generated counts (fixed seed 20261123): dynamic lookup 15, passed 25,
Object.values17, spread 19, static read 26, no use 18, owns entry on the literal 36, shorthand member 114, member named like a called function 64. Random seed: 18, 23, 21, 19, 21, 18, 37, 116, 71. Each state also has a constructed history, so every state is required.RED. On main's
owners.mjs(7b6bae16), with the new oracle and the head's test files: 20 of 32 units fail, under both the fixed and random seeds (vitest --run --config oracle-gaps/vitest.config.mjs gap-report-static-oracle-dispatch). The first counterexample is the shorthand bug:fbis named by the literal's initializer, the rule owns it, and main leaves it unowned.GREEN. On head (
7b23fc3f): the new oracle passes 32 of 32.pnpm --filter @tanstack/oracles test:oracle-gaps:fastpasses 6 files and 33,931 tests, including the new 32. The pinned tests (tests/oracle-gaps-owns-through-calls.test.ts, 4 of 4) pass, andtests/gap-report-history-fingerprint.test.tspasses.Mutants. Each is applied to head's
owners.mjsand run against the new oracle, then restored:wholeValue = false): 14 of 32 fail.isPropertyNamedisabled): 15 of 32 fail.CI wiring. The static shards select tests with a name pattern that the new suite name does not match, so both shards would skip its 32 tests (checked: "32 skipped"). The new file runs whole in the third gap-oracle job instead, in
.github/workflows/pr.yml. It is also run bytest:oracle-gaps:fast.Conflicts. I expect no textual conflicts with #99 or #133 in
owners.mjs, the design skill, the new oracle file, or the changeset, because neither PR touches them. Two possible conflicts:.github/workflows/pr.yml(#133 changes that file; a conflict is possible in the third-job block, which this PR edits), andpackages/oracles/oracle-gaps/gap-report-static-oracle.property.test.mjs(not touched here; listed in case the rebase needs it).Limits.
Object.freeze,keyof typeof, imported literals, nested literals, and more than one level of member calls. One use per run.index.mjs) was not run overowners.mjs: no production source changed in this follow-up. The oracle ran through Vitest, as the package scripts do.dynamiccounterexample; the run that failed first haduse: "none"on an entry-on-literal history.This pull request and its description were written by Isaac.