Repository navigation
Reach the engine through one object the hooks module builds - #8
Merged
Merged
Conversation
The plugin directory reads a mod's calls from its hooks module alone and refuses $ handed to a function in another file, even from a hook's body. The developer portal flagged 24 such lines in hooks/register.ts, ten a round. hooks/register.ts now builds ioOf($), each member of which makes one plain call on $, with the variable or program it uses written out (HOME, git, du, rm), and the modules in src take that object (src/io.ts) instead of $. A $.state call takes its plugin and key written out in the hooks module, so stateOf spells out the pad's nine values; read and update in src/state.ts reach them through it. What the mod does is unchanged. scripts/dollar_check.ts applies the directory's rule locally and lists every place that breaks it at once: on e658483 it finds the same 24 lines as the portal, in the same order. just dollar_check runs it, and just check runs its tests.
The check now also refuses $ spread into a call or used as a default
value, the engine held under a name other than $ (a hook's or .catch
handler's first parameter, or anything typed EngineInterface, and the
engine's type named in src outside io.ts), and a registration that isn't
on("event", ...) as a statement of its own line in register's body. It
reads a generic function's $ as its parameter, doesn't read a JSX closing
tag as a regex, and fails when hooks.json names no hooks module. Each new
rule has a test that fails without it.
stateOf passes each value to $.state.set without a cast, and switches on
the contract's keys, so a value added to the contract and not to the
switch fails to type-check; the test's list of keys is held to the
contract the same way.
Four comments that described $ in src are corrected, and the CHANGELOG
and the justfile say the check applies the rule for $ and on rather than
the "whole rule".
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.
The plugin directory's rule for
$still blocked the submission. The finding's own text gives the rule: in the hooks module,$may only be passed, whole, to a function declared at the top of that same file. Every hook that handed$to a module insrcbroke it. That was 24 lines one658483, and the developer portal shows ten a round, so fixing them as they showed up would have taken three more rounds.What changes
hooks/register.tsbuildsioOf($), one object whose members each make one plain call on$. The variable or program each one uses is written out:HOME,USERPROFILE, the config-folder variable,git,du -sk --,rm -f --. Hooks passioOf($)(or a localiobuilt from it) where they passed$. Timers and buttons keep it, as they kept$before.src/io.tsis that object's type: the engine's own methods under the same nouns, cut down to the arguments the mod passes.srctakeioinstead of$. It's a rename in the code, with comments left as they were, plus the six env reads and three program runs moved to their named members. Nothing the mod does changes.stateOfwrites out each of the pad's nine$.statevalues with its key. The validator requires a$.statecall's plugin and key to be written out in the hooks module, or held in a const there, soreadandupdateinsrc/state.tsreach the values through it. A value that isn't the pad's is refused before$is asked.scripts/dollar_check.tschecks the directory's rule locally: in the hooks module, each$must be a parameter, a plain$.noun.method(...)call, or a whole argument to a function declared at the top of that file; eachonmust be register's parameter or the callee ofon(...); and no module insrcholds$.just dollar_checkruns it after the old grep check, andjust checkruns its tests (just script_test).scriptsjoins the format check.How it was checked
e658483's hooks file finds 24 lines, starting with 326, 332 and 336, the three the portal showed, in the same order. On this branch it finds none.ioOf,stateOfand the other functions of the hooks file.tests/io.test.ts: each member's call, the refusals, and optional arguments left out rather than passed asundefined). 19 tests of the check script pass.Review
A reviewer subagent with fresh context read
b478296. It found nothing critical and no change in behavior: every argument,.catchandawaitis as it was, and timers and buttons keep theioof the hook that set them up, as they kept its$. What it found, and what changed in659bf18:stateOf's$.state.set(...)calls are gone, since the rule's text names casts; the value is typedneverinstead.$.process.run(["git", ...args], init)is inside an argument, not around a part of the call. The same shape was already in a module the validator traced.stateOfto the state contract. A tenth value would have compiled and then failed when read. The switch now runs on the contract's keys, so a key left out fails to type-check, and the test's key list is held to the contract the same way. Removing a case, or a key from the test list, fails the type check.$spread into a call or used as a default value, the engine under another name (a hook's or.catchhandler's first parameter, a parameter typedEngineInterface, the engine's type named insrcoutsideio.ts), and a registration that isn'ton("event", ...)as a statement of its own line inregister's body (in a loop or anif, two on a line, assigned, or with a non-string event).$andon" instead of "whole rule".function helper<T>($: E)reported its own parameter. Type parameters are now skipped.src/state.ts,src/git.ts,src/prune.ts, the hooks module's header) described$insrc. Each is corrected in place, and none is removed.hooks.jsonnames no module, where it used to pass silently.state.setsends{}when it's given no options. That's a well-formed options object, notundefined, and onlyupdatecalls it, always withifVersion.scripts/isn't type-checked, because that needs Bun's types as a new dev dependency.Each new rule in the check has a test that fails when the rule is taken out (7 rules tried). The script's tests went from 11 to 19.
Before merging
main.