Repository navigation
refactor(node): one isLoopback, Retry-After reader and network code lookup in pivotkit-node/net - #737
Merged
Merged
Conversation
…votkit-node/net pivotkit-server and pivotkit-cli each read IP addresses, loopback, Retry-After headers and the code of a failed connection with copies of their own. pivotkit-node/net is now the one copy; each front end passes options where it needs another result and keeps its own error class, words and caps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…puts it Keeps each caller's lookup order exact (review), names the loopback option address, and tolerates a missing options object. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Step 2 of the layering rework after #736: one
isLoopback, one Retry-After reader and one lookup of a failed connection's code.What changed
pivotkit-node/net(packages/pivotkit-node/src/net.js) is the one copy of:ipBytes, moved from pivotkit-server'ssources/fetch.js.isLoopback. The copy inpivotkit-node/restand the one insources/fetch.jsare now this function.pivotkit-node/restre-exports it, sopivotkit-cli/restand the server entries keep the same function.retryAfterSeconds, the core of the tworetryAfterOf(serversources/http.js, CLIremote.js).networkCodeOf, the core of the twonetworkError(serversources/fetch.js, CLIremote.js).Each front end keeps its own error class, words and caps. Step 4 unifies the error classes.
Behaviour: no change
I copied the old functions into a scratch harness and compared them with the new ones on every input I could think of: spellings, zones, IPv4-mapped forms, empty values, 11-digit and 400-digit numbers, past and future dates, AggregateErrors and fetch-style causes. No differences.
test/net.test.jspins these tables.Differences that stay, as options
localhost, dotted 127/8,::1. This applies to the CLI's URL hosts,http.host, publicUrl, and socket addresses after::ffff:is stripped.{ address: true }is guardedFetch's reading: any spelling of an IP address, a zone dropped, IPv4-mapped::ffff:127.x(also[::ffff:7f00:1]as a URL writes it) counts.files.test.jspins[::ffff:7f00:1]as not loopback. A free-texthttp.hostsuch as0::1would otherwise drop the auth requirement.null, notundefined, which shows in--json. Both callers keep their own caps.retryAfterSeconds(value, { maxDigits: 10 })keeps the server's^\d{1,10}$. See the possible bug below.networkCodeOf(e, { client: "node" | "fetch" }).e.code, thene.errors[0].code.e.cause.code,e.code, thene.cause.cause.code. It also accepts only code-shaped strings, because the code becomes its--jsonerror code.Looks like a bug, not fixed here (for an issue)
Date.parse,"00000000001"becomes a date in 2001, which gives 0 s. Other values give nothing. The CLI reads the same text as 1 s. RFC 9110's delay-seconds is1*DIGIT.networkErrortext slices the code to 40 characters. The CLI refuses a code longer than 41 characters and says "no answer". One OpenSSL code is longer:ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC.Not part of this change (say what does not fit)
TRANSIENTinsources/fetch.jsNETWORK_CODESinsources/run.jsNETWORK_TEXTSin the CLI'sremote.jsplainAddressexist, inlisten.jsandrequest-id.js. One strips every::ffff:, the other only before a dotted IPv4.sign-in.jscall) builds its own NETWORK/TIMEOUT error without a code. Its--jsoncodes differ from remote mode's, so it stays until step 4.runner.js:163andcheck/issuer.js:70read a cause's code by hand for printing only.Growth (scripts/growth.js measures, before → after)
No baseline entry changed: the functions that lost lines are below the limits, and the offenders
createGuardedFetch,guardedandloadHttpkept their numbers.Checks
npm run lint,npm run types,npm test(all workspaces andtests/),npm run growth,npm run pack:check: green locally.npm test.addressPlaces checked for docs:
docs/reference/service-exports.mdneeds no change, because pivotkit-node is internal (docs/versioning.md).🤖 Generated with Claude Code