Commit graph

30 commits

Author SHA1 Message Date
Claude
b12db10680
ax(batch): expand abbreviated parameter and local variable names across all packages
Applies AX principle 1 (Predictable Names Over Short Names) to function
signatures and local variables: s->input/raw, v->target/value, d->duration,
a,b->left,right, w->writer, r->reader, l->logger, p->part/databasePoint,
fn parameter names left as-is where they are callback conventions.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 18:27:21 +01:00
Claude
c67dca2a97
ax(batch): apply Good/Bad/Ugly test naming to remaining test files
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Second pass of test naming convention across xmrig_test.go,
xmrig_gpu_test.go, stats_collector_test.go, manager_race_test.go,
throttle_test.go, service_test.go, interface_test.go,
database_race_test.go. 30 additional tests renamed.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 18:23:59 +01:00
Claude
14cf520778
ax(batch): apply Good/Bad/Ugly test naming convention across all packages
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Renames test functions to follow TestFilename_Function_{Good,Bad,Ugly}
convention per AX test naming rules. Covers profile_manager_test.go
(11 tests), events_test.go (9 tests), container_test.go (8 tests),
logger_test.go (9 tests), database_test.go (10 tests).

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 18:20:32 +01:00
Claude
3673757d2a
ax(batch): replace prose comments with usage examples across all packages
Converts comments that restate function signatures into concrete usage
examples per AX Principle 2. Affected files: database_race_test.go,
interface_test.go, errors_test.go, xmrig_test.go, service_test.go,
manager_test.go.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 18:16:56 +01:00
Claude
fcae672dbc
ax(batch): expand abbreviated local variable names across all packages
Renames 2-3 letter abbreviated locals to predictable names per AX
Principle 1: pm→profileManager, sm→settingsManager, rl→rateLimiter,
cb→breaker, hr→rate, wg→waitGroup, pm1/pm2→firstProfileManager/
secondProfileManager, cb1/cb2→firstBreaker/secondBreaker.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 18:15:15 +01:00
Claude
43e4b447ac
ax(batch): remove banned import references from comment examples
Replace all fmt.Println, fmt.Sprintf, log.Printf, log.Println, and
json.Unmarshal references in doc comments with logging.Info/logging.Warn
or direct value access patterns. Comments are examples that agents
learn from -- they must not demonstrate banned imports.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 18:07:35 +01:00
Claude
132b69426a
ax(batch): replace prose comments with usage examples (AX Principle 2)
Convert "X returns the Y" / "X holds Y" / "X represents Y" style
comments to concrete usage examples across database/, logging/, and
mining/ packages. Comments now show how to call the function with
realistic values instead of restating what the signature already says.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 18:03:43 +01:00
Claude
c703bd9050
ax(batch): remove banned fmt import from all non-test source files
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Replace fmt.Sprintf with string concatenation + strconv.Itoa/FormatInt.
Replace fmt.Errorf with project MiningError constructors (ErrStartFailed,
ErrInstallFailed, ErrInternal) and a new databaseError helper in pkg/database.
Leaves fmt in pkg/logging (it IS the logging package) and test files.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 18:00:44 +01:00
Claude
8b22e9dda6
ax(database): replace prose interface comments with usage examples
AX Principle 2: comments must show how to call the function with real
values, not restate what the type signature already says. All six
HashrateStore interface methods now carry concrete call-site examples.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:22:42 +01:00
Claude
d44cfa3790
ax(database): replace prose comment with usage example on GetAllMinerStats
Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:21:17 +01:00
Claude
bac107b377
ax(database): rename TestInitialize_Disabled to TestDatabase_Initialize_Bad
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Test naming must follow TestFilename_Function_{Good,Bad,Ugly}. The disabled
path test was named freeform, breaking the mandatory pattern. Renamed to
TestDatabase_Initialize_Bad so it joins the existing TestDatabase_Initialize_Good
and forms a correctly named pair.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:20:08 +01:00
Claude
2bfa958cfa
ax(database): replace prose comment with usage example on isInitialized
AX Principle 2: comments show HOW with real values, not restate what
the signature already says.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:19:01 +01:00
Claude
8a23b0efca
ax(database): add usage-example comment to GetHashrateStats
GetHashrateStats had no comment at all — bare exported function.
AX Principle 2 requires comments as usage examples, not prose.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:17:46 +01:00
Claude
fbe40d2c53
ax(database): rename TestInitialize to follow TestFilename_Function_Good convention
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:16:25 +01:00
Claude
02ffd28eaf
ax(database): replace signature-restatement comment with usage example on HashrateStats
Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:15:15 +01:00
Claude
18ac5e1c94
ax(database): replace prose comment with usage example on GetHashrateHistory
AX Principle 2 — comments must show a concrete call, not restate the signature.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:14:18 +01:00
Claude
0f2c25f7ef
ax(database): replace prose comment on Initialize with usage example
AX Principle 2: comments must show concrete usage, not restate the
function name. "Initialize opens the database connection and creates
tables" restated the signature — replaced with a callable example.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:13:01 +01:00
Claude
036819e4eb
ax(database): rename db/dbMu to globalDatabase/databaseMutex
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Abbreviated names `db` and `dbMu` require a comment to understand their
scope and purpose, violating AX Principle 1 (Predictable Names Over Short
Names). Renamed to `globalDatabase` and `databaseMutex` throughout all
source and test files.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:11:10 +01:00
Claude
140f038f37
chore: migrate module path from github.com to forge.lthn.ai
Some checks failed
E2E Tests / E2E Tests (push) Failing after 1m23s
Tests / Go Tests (push) Failing after 39s
Desktop Release / Build linux (push) Failing after 46s
Release / Test (push) Failing after 2s
Tests / C++ Tests (push) Failing after 1m12s
Release / Release (push) Has been cancelled
Desktop Release / Build darwin (push) Has been cancelled
Desktop Release / Build windows (push) Has been cancelled
Desktop Release / Create Release (push) Has been cancelled
Move module declaration and all internal imports from
github.com/Snider/Mining to forge.lthn.ai/Snider/Mining. Also updates
Borg, Enchantrix, and Poindexter dependency paths to forge.lthn.ai.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 21:39:01 +00:00
snider
3d8247c757 feat: Add database migration tests and task supervisor
- TEST-HIGH-5: Add comprehensive database tests for schema, migrations,
  re-initialization, and concurrent access
- RESIL-MED-6: Add TaskSupervisor for background task monitoring with
  automatic restart on failure

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 15:50:17 +00:00
snider
185bfd13dd test: Add error path unit tests for context cancellation and cleanup
- Add context cancellation tests for database InsertHashratePoint
- Add context timeout tests for database operations
- Add NopStore context handling tests
- Add container shutdown timeout and double-shutdown tests
- Add repository concurrent update, corrupt file, and permission tests
- Verify all error paths handle edge cases gracefully

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 13:04:20 +00:00
snider
34f860309f refactor: Add reliability fixes and architecture improvements
Reliability fixes:
- Fix HTTP response body drainage in xmrig, ttminer, miner
- Fix database init race condition (nil before close)
- Fix empty minerType bug in P2P StartMinerPayload
- Add context timeout to InsertHashratePoint (5s default)

Architecture improvements:
- Extract HashrateStore interface with DefaultStore/NopStore
- Create ServiceContainer for centralized initialization
- Extract protocol response handler (ValidateResponse, ParseResponse)
- Create generic FileRepository[T] with atomic writes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 12:43:46 +00:00
snider
89f74aebff refactor: Replace log.Printf with structured logging
Migrate all log.Printf/Println calls across the codebase to use the
new pkg/logging structured logging package. This provides consistent
log formatting with levels, timestamps, and structured key-value fields.

Files updated:
- pkg/mining/manager.go, service.go, events.go, miner.go
- pkg/mining/xmrig_start.go, ttminer_start.go
- pkg/mining/syslog_unix.go, syslog_windows.go
- pkg/database/hashrate.go
- pkg/node/worker.go, transport.go, peer.go

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 11:48:45 +00:00
snider
2a30744a08 test: Add race condition tests and fix AVG float64 scan bug
- Add pkg/mining/manager_race_test.go with concurrent miner tests
- Add pkg/database/database_race_test.go with concurrent DB tests
- Add TestCleanupRetention, TestGetHashrateHistoryTimeRange tests
- Add TestMultipleMinerStats, TestIsInitialized tests
- Fix AVG() float64 to int scan error in GetHashrateStats
- Fix AVG() float64 to int scan error in GetAllMinerStats
- Fix throttle tests to use NewManagerForSimulation to avoid
  autostart conflicts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 11:07:29 +00:00
snider
b454bbd6d6 feat: Add context propagation, state sync, and tests
- Add context.Context to ManagerInterface methods (StartMiner, StopMiner, UninstallMiner)
- Add WebSocket state sync on client connect (sends current miner states)
- Add EventStateSync event type and SetStateProvider method
- Add manager lifecycle tests (idempotent stop, context cancellation, shutdown timeout)
- Add database tests (initialization, hashrate storage, stats)
- Add EventHub tests (creation, broadcast, client count, state provider)
- Update all test files for new context-aware API

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 10:10:39 +00:00
snider
d61a8aff8b refactor: Remove unused code and fix nil dereference issues
- Remove unused exported functions from pkg/database (session tracking,
  bulk hashrate inserts, various query helpers)
- Remove unused exported functions from pkg/node (identity management,
  bundle operations, controller methods)
- Make internal-only functions unexported in config_manager.go and database.go
- Remove unused EventProfile* constants from events.go
- Add GetCommit() and GetBuildDate() to expose version.go variables
- Fix potential nil dereference issues flagged by Qodana:
  - Add nil checks for GetIdentity() in controller.go, transport.go, worker.go
  - Add nil checks for GetPeer() in peer_test.go
  - Add nil checks in worker_test.go

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 09:24:12 +00:00
snider
0735445eb0 fix: Address code review issues and fix miner start deadlock
- Remove deprecated GetDB() function that exposed raw DB pointer
- Fix GetLatestHashrate to distinguish sql.ErrNoRows from real errors
- Document async saves in PeerRegistry mutation methods
- Fix deadlock in XMRig/TTMiner Start() by moving CheckInstallation
  call before acquiring the main lock (Go RWMutex doesn't allow
  recursive locking)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 03:51:05 +00:00
snider
b24a3f00d6 fix: Add timeouts, atomic writes, and thread safety improvements
- Add 30s context timeout for database transactions in hashrate.go
- Add helper function for parsing SQLite timestamps with error logging
- Implement atomic file writes (temp + rename) for profile_manager.go,
  config_manager.go, and peer.go to prevent corruption on crash
- Add 5s timeout for stats collection per miner in manager.go
- Add 5s timeout for stdin writes in miner.go
- Clean up config file on failed miner start in xmrig_start.go
- Implement debounced saves (5s) for peer registry to reduce disk I/O
- Fix CheckInstallation data race in xmrig.go and ttminer.go by adding
  proper mutex protection around shared field updates
- Add 10s handshake timeout for WebSocket connections in transport.go
- Update peer_test.go to call Close() before reload to flush changes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 02:55:30 +00:00
snider
8b5d446ffe fix: Complete race condition fixes and add config synchronization
- Add sync.RWMutex to config_manager.go for file operation synchronization
- Add deprecation warning to unsafe GetDB() function in database.go
- Fix UninstallMiner map modification during iteration in manager.go
- Add server readiness verification via TCP dial in service.go
- Add mutex-protected httpClient getter/setter in xmrig.go
- Update GetLatestVersion to use synchronized HTTP client in ttminer.go
- Update MockMiner in service_test.go to match context-aware GetStats interface

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 02:02:57 +00:00
snider
e0c9c92244 feat: Implement logging functionality for miners with log buffer and retrieval endpoint 2025-12-29 22:10:45 +00:00