Removes the banned `strings` import from transport.go by extracting
a `joinVersions` helper into message.go alongside SupportedProtocolVersions,
eliminating the single `strings.Join` call in the handshake rejection path.
Co-Authored-By: Charon <charon@lethean.io>
Replace all fmt.Errorf and fmt.Sprintf calls in transport.go with
ProtocolError{} structs and string concatenation, matching the error
pattern already used throughout the node package.
Co-Authored-By: Charon <charon@lethean.io>
Replace all fmt.Errorf calls in bundle.go with ProtocolError structs,
eliminating the banned fmt import. Error messages are preserved via
string concatenation consistent with the rest of the node package.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1: predictable names over short names. cfg.json →
config.json makes the path self-describing without a comment.
Co-Authored-By: Charon <charon@lethean.io>
Remove banned `encoding/json` import from pkg/mining/version.go; read
response body with io.ReadAll then decode via the package-local
UnmarshalJSON wrapper (bufpool.go). Also complete the partial fmt
removal in pkg/node/identity.go left broken by the previous sweep.
Co-Authored-By: Charon <charon@lethean.io>
Range variables `p` and `k` in peer_test.go require context to decode —
violates AX Principle 1 (predictable names over short names). Renamed to
`peer` and `key` so intent is self-evident without reading the loop body.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — predictable names over short names. Local variables
declared as `msg` in GetRemoteStats, StartRemoteMiner, StopRemoteMiner,
GetRemoteLogs, and PingPeer renamed to `message`.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — predictable names over short names. `tt` is an
abbreviated loop variable; `testCase` states the semantic clearly.
Co-Authored-By: Charon <charon@lethean.io>
ValidateResponse wraps type-mismatch in *ProtocolError (correct behaviour).
The docstring example showed the wrong negation and the assertion fired on
every run. Both the comment (AX §2 — comments as accurate usage examples)
and the guard were inverted; corrected to !IsProtocolError.
Co-Authored-By: Charon <charon@lethean.io>
AX principle 10 requires all three test categories (Good, Bad, Ugly).
lethean_test.go only had Bad variants for the three discovery functions;
added Good (happy-path via httptest.Server) and Ugly (edge-case filtering
and malformed JSON) for each, using a local test server to avoid live daemon dependency.
Co-Authored-By: Charon <charon@lethean.io>
The "path" package uses forward-slash separators and is intended for
URL paths; filesystem paths require "path/filepath" for OS-correct
behaviour. Fixes worker.go handleDeploy to use filepath.Join when
constructing the miners installation directory.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1: predictable names over short names. The `nm` shorthand
in seven comment examples was inconsistent with the full `nodeManager`
name used in actual call-site code and the `manager` receiver name
throughout the file.
Co-Authored-By: Charon <charon@lethean.io>
AX-1: predictable names over short names. The variable `ack` is an
abbreviation for `acknowledgement` — renamed in all six callsites
within handleStartMiner, handleStopMiner, and handleDeploy so the
name is self-describing without a comment.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 2: comments show usage, not prose descriptions. The
ProtocolVersion/MinProtocolVersion block comment and SupportedProtocolVersions
doc comment restated what the names already say; replaced with concrete
call-site examples.
Co-Authored-By: Charon <charon@lethean.io>
All fmt.Errorf calls replaced with &ProtocolError{Code, Message} using
the package-native error type, removing the banned fmt import entirely.
Co-Authored-By: Charon <charon@lethean.io>
worker.go imported encoding/json directly and called json.Unmarshal at two
call sites. bufpool.go already provided MarshalJSON as the package wrapper;
add matching UnmarshalJSON and route both worker.go call sites through it,
removing the encoding/json import from worker.go.
Co-Authored-By: Charon <charon@lethean.io>
Replace all fmt.Errorf calls with typed *ProtocolError values using the
native node error type — consistent with how protocol.go was cleaned up.
Error wrapping cases (failed to create message) now surface the original
error directly, preserving the call chain without fmt.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle #1 — predictable names over short names. The `tt` loop variable
is a two-letter abbreviation with no defined exception in the AX naming rules
(only `i`, `_`, `t`, `c` are acceptable short names). Renamed to `testCase`
throughout TestParseComment_{Good,Bad,Ugly}.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 2: comments show usage examples, not prose descriptions.
Five methods (AddPeer, UpdatePeer, RemovePeer, UpdateMetrics, UpdateScore)
had a redundant "Note: Persistence is debounced..." prose line appended
after the usage example. The usage example already communicates intent;
the prose line restated implementation detail without adding value.
Co-Authored-By: Charon <charon@lethean.io>
Score constants had comments restating the name in prose
("Increment for successful interaction") rather than showing
how they are used. AX Principle 2: comments are usage examples,
not descriptions.
Co-Authored-By: Charon <charon@lethean.io>
Mutex name was singular (allowedPublicKeyMutex) while the field it
protects is plural (allowedPublicKeys). AX Principle 1 requires
predictable names — the mutex name must mirror the field it guards.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — predictable names over short names. `buf` is an
abbreviation that requires a comment to understand; `buffer` is
self-describing.
Co-Authored-By: Charon <charon@lethean.io>
Single-letter parameter names w and r violate AX Principle 1
(predictable names over short names). Only i, _, t, and c are
permitted as single-letter names per the AX spec.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — Predictable names over short names.
The single-letter `p` in `for _, p := range peers` is not listed
in the allowed exceptions (only `i`, `_`, `t`, `c` are permitted).
Rename to `peer` for semantic clarity.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 2: comments show HOW with real values, not WHAT the code does.
The old comment restated the variable name; the new comment shows concrete
validatePeerName calls that demonstrate valid and invalid inputs.
Co-Authored-By: Charon <charon@lethean.io>
AX-2: comments must show concrete usage, not restate what the code does.
The "Register message handler for responses" prose comment was replaced
with a usage-example comment that shows the actual call pattern.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1: pe is an abbreviation requiring a comment to explain.
Renamed to protocolError throughout, including the usage example comment.
Co-Authored-By: Charon <charon@lethean.io>
The field Aliases int was ambiguous — agents and readers expect Aliases
to be a slice, not a count. AliasCount makes the int type self-evident
without requiring a comment (AX Principle 1: predictable names).
Co-Authored-By: Charon <charon@lethean.io>
BundleType, Bundle, and BundleManifest had comments restating what the
type signature already says (AX Principle 2 violation). Replaced with
concrete usage examples showing how each type is constructed and used.
Co-Authored-By: Charon <charon@lethean.io>
path/filepath is a banned import per AX conventions; path is the
correct alternative when core.JoinPath is not available in this repo.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — predictable names over short names.
The field `ttl` requires context to decode; `timeToLive` is
self-describing without a comment.
Co-Authored-By: Charon <charon@lethean.io>
LetheanDefaults comment restated what the constant block name already says (AX
Principle 2). Replaced with concrete call examples showing GetChainInfo and
DiscoverPools usage against both daemon endpoints.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1: predictable names over short names. The variable `u`
in the WebSocket upgrader CheckOrigin closure required context to
understand; `parsedURL` is self-describing.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — predictable names over short names. `pr` requires mapping to
PeerRegistry; `registry` is self-documenting on first read.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1: predictable names over short names.
`ctx` is an abbreviation that requires prior knowledge to decode;
renamed to describe intent at each call site.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 2: comments show HOW with real values, not WHAT the
type signature already says. Converted 8 prose-style comments on
type declarations (Transport, TransportConfig, PeerConnection,
PeerRateLimiter, MessageDeduplicator, DisconnectPayload, NodeRole,
NodeIdentity, Peer) to concrete call-site examples.
Co-Authored-By: Charon <charon@lethean.io>
Replace single-letter receivers (m *Message, e *ProtocolError) and
parameter (v interface{}) with full names (message, protocolError, target)
per AX Principle 1: predictable names over short names.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — predictable names over short names.
`resp` is an abbreviation that requires context to interpret;
`response` is self-describing at any reading distance.
Co-Authored-By: Charon <charon@lethean.io>
'Chan' is an abbreviation; AX Principle 1 requires predictable names
over short names. stopChannel is unambiguous without a comment.
Co-Authored-By: Charon <charon@lethean.io>
Single-letter receiver `t` violates AX Principle 1 (predictable names
over short names). All 15 Transport methods now use `transport` as the
receiver name for unambiguous semantic navigation.
Co-Authored-By: Charon <charon@lethean.io>
AX principle: all three categories (Good, Bad, Ugly) are mandatory per
TestFilename_Function_{Good,Bad,Ugly} convention. Three handler functions
had only _Bad coverage; this pass fills the gap.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1: predictable names over short names. The field `path` on
PeerRegistry is ambiguous — it could be any path. `peersFilePath` is
self-describing and removes the need for a comment to explain its purpose.
Co-Authored-By: Charon <charon@lethean.io>