Commit Graph
125 Commits
Author SHA1 Message Date
thePR0M3TH3AN 845333e980 Merge branch 'main' into dashboard-security-headers-10540095592303062285 2026-02-18 09:47:42 -05:00
thePR0M3TH3AN 30212a6213 Merge pull request #275 from PR0M3TH3AN/fix-install-dir-command-injection-4005485668731201594
🔒 Fix command injection via install directory name
2026-02-18 09:47:23 -05:00
thePR0M3TH3AN 76c1513cfd Merge branch 'main' into jules-tests-utils-9764403852439497661 2026-02-18 09:46:52 -05:00
thePR0M3TH3AN 0c4650e92a Merge pull request #271 from PR0M3TH3AN/jules-3313039613758629393-8f27954c
Enhance test coverage for relay alert thresholds
2026-02-18 09:46:23 -05:00
thePR0M3TH3AN f5dee21b74 Merge branch 'main' into chore/remove-dead-code-cmd-check-6250725036284174249 2026-02-18 09:45:58 -05:00
thePR0M3TH3AN a231ea0784 Merge branch 'main' into jules/testing-relay-health-12520607155456440581 2026-02-18 09:44:14 -05:00
thePR0M3TH3AN b6775cda28 Merge pull request #289 from PR0M3TH3AN/optimize-relay-ranking-1239301882622685923
⚡ Optimize relay ranking with caching
2026-02-17 22:45:08 -05:00
thePR0M3TH3AN 34c20fadd8 Merge pull request #285 from PR0M3TH3AN/fix-dashboard-path-traversal-vulnerability-5749294800748882365
Fix path traversal vulnerability in dashboard.mjs
2026-02-17 22:43:20 -05:00
thePR0M3TH3AN 11c7510b95 Merge pull request #287 from PR0M3TH3AN/perf/optimize-pruner-lifecycle-15735036455677538666
⚡ Parallelize memory lifecycle actions in pruner
2026-02-17 22:41:48 -05:00
thePR0M3TH3AN 0d7f5a250c Merge pull request #278 from PR0M3TH3AN/fix-dashboard-config-exposure-6646545441224592886
fix(dashboard): prevent information disclosure via /torch-config.json
2026-02-17 22:40:08 -05:00
thePR0M3TH3AN ea127b9b2d Merge pull request #274 from PR0M3TH3AN/code-health-ensure-dir-13440231316649260412
Refactor: Centralize `ensureDir` utility
2026-02-17 22:39:11 -05:00
google-labs-jules[bot]andPR0M3TH3AN a9f30f13f9 feat(perf): cache relay ranking in RelayHealthManager
- Implement caching for `rankRelays` to avoid redundant sorting and computations.
- Cache is invalidated on new outcomes or when quarantine status changes.
- Add `_metricsVersion` to track metrics updates.
- Benchmarks show ~3x performance improvement (0.06ms -> 0.02ms per call for 100 relays).
- Add unit tests for caching behavior and invalidation.
- Add `perf/benchmark-lock-ops.mjs`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 03:33:59 +00:00
google-labs-jules[bot]andPR0M3TH3AN 0f29e9126e perf: parallelize applyLifecycleActions for faster pruning
- Use Promise.all to execute memory lifecycle actions concurrently.
- Maintain intra-item dependency order (merged_into before action).
- Update tests to support non-deterministic execution order of independent items.
- Benchmark shows ~65x improvement for 100 items with 10ms latency.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 03:32:03 +00:00
google-labs-jules[bot]andPR0M3TH3AN 5fe9e8a1f9 Fix: Strengthen path traversal protection in dashboard.mjs
- Replaced brittle regex-based sanitization with `path.resolve` relative to `packageRoot`.
- Added `test/dashboard-path-traversal-fix.test.mjs` to verify robust protection against traversal attacks.
- Verified that legitimate access to allowed paths is maintained.
- Verified that access to restricted files (like package.json) is blocked.
- Updated path handling to correctly handle absolute paths and URL-encoded characters.

This change addresses a potential security vulnerability where the previous sanitization logic could be bypassed in certain environments or with specific edge cases. By using standard path resolution and explicitly checking against a canonical root, the implementation is more secure and maintainable.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 03:31:18 +00:00
google-labs-jules[bot]andPR0M3TH3AN aad5e46b31 fix(dashboard): whitelist exposed torch-config.json fields
Restrict the /torch-config.json endpoint to only return fields required by the dashboard frontend (dashboard config excluding auth, and nostrLock namespace/relays). This prevents exposure of sensitive internal configuration such as rosters, scheduler settings, and full relay lists.

- Modify src/dashboard.mjs to sanitize config using an allowlist approach.
- Add test/dashboard-config-exposure.test.mjs to verify sensitive fields are stripped.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 03:29:23 +00:00
google-labs-jules[bot]andPR0M3TH3AN 75c9b669c0 feat(dashboard): add HTTP security headers
Adds standard HTTP security headers (CSP, X-Content-Type-Options, X-Frame-Options, Referrer-Policy) to all dashboard responses to mitigate XSS, clickjacking, and MIME sniffing attacks.

Includes verification tests in test/dashboard-security.test.mjs.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 03:29:21 +00:00
google-labs-jules[bot]andPR0M3TH3AN e12c415f28 feat(test): add unit tests for roster loading logic with dependency injection
- Refactor `src/roster.mjs` to support dependency injection for `fs` and `loadTorchConfig`.
- Add `test/roster.test.mjs` to test roster loading scenarios including file precedence, caching, fallback, and configuration overrides.
- Export `_resetRosterCache` in `src/roster.mjs` for testing purposes.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 03:29:09 +00:00
google-labs-jules[bot]andPR0M3TH3AN b1353cb79b fix: prevent command injection in init scripts by validating install dir
- Added `validateInstallDir` function to `src/ops.mjs` to enforce strict allowlist for directory names (alphanumeric, hyphens, underscores, slashes, periods).
- Integrated validation into `resolveConfiguration` to sanitize both interactive and mock inputs.
- Added comprehensive unit tests in `test/install_dir_validation.test.mjs`.

This fixes a vulnerability where malicious directory names could inject shell commands into `package.json` scripts during initialization.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 03:28:59 +00:00
google-labs-jules[bot]andPR0M3TH3AN ba5d86142c Refactor: Move ensureDir to src/utils.mjs
Moved the `ensureDir` utility function from `src/ops.mjs` to `src/utils.mjs` to promote code reuse and centralization.
Updated `src/ops.mjs` and `src/services/memory/index.js` to use the shared utility.
Added unit tests for `ensureDir` in `test/utils.test.mjs`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 03:28:09 +00:00
google-labs-jules[bot]andPR0M3TH3AN e787247c6f test(utils): add unit tests for todayDateStr and nowUnix
Add comprehensive unit tests for `todayDateStr` and `nowUnix` in `src/utils.mjs`.
These tests use `node:test`'s mock timers to ensure deterministic execution, verifying
that the date formatting and timestamp generation behave as expected.

- `todayDateStr`: verified correct YYYY-MM-DD format
- `nowUnix`: verified correct integer timestamp generation

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 03:27:26 +00:00
google-labs-jules[bot]andPR0M3TH3AN b012ae19da test: enhance coverage for relay alert thresholds
Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 03:27:21 +00:00
google-labs-jules[bot]andPR0M3TH3AN 9a9f93aa04 chore: remove dead code src/cmd-check.mjs
- Remove `src/cmd-check.mjs` as it is not used in the codebase and contains outdated logic.
- Remove `test/cmd-check.test.mjs` as it tests the deleted file.
- Verify that `cmdCheck` in `src/lib.mjs` is covered by `test/lib.test.mjs`.

This improves code health by removing unused and duplicate code.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 03:23:18 +00:00
google-labs-jules[bot]andPR0M3TH3AN 9e993800fa [scheduler] daily/decompose-agent: Decompose scripts/agent/run-scheduler-cycle.mjs
- Executed daily scheduler cycle.
- Selected `decompose-agent` (next in roster).
- Decomposed `scripts/agent/run-scheduler-cycle.mjs` (1127 lines) into `scripts/agent/scheduler-utils.mjs` (195 lines) and `scripts/agent/scheduler-lock.mjs` (173 lines).
- Resulting main file size: 788 lines (339 lines reduction).
- Fixed lint warnings.
- Updated `test/scheduler-preflight-lock.e2e.test.mjs`, `test/run-scheduler-cycle-memory-policy.test.mjs`, `test/scheduler-lock-failure-schema.contract.test.mjs` to copy new modules into test fixtures.
- Updated `test/scheduler-ratchet.test.mjs` to verify moved functions in `scheduler-lock.mjs`.
- Note: `scripts/check-file-size.mjs` was not updated as it lacks the baseline feature referenced in the prompt.
- Created artifacts: `src/context/CONTEXT_...`, `src/decisions/DECISIONS_...`, `src/test_logs/TEST_LOG_...`, `src/todo/TODO_...`.
- Created scheduler log: `task-logs/daily/2026-02-17T22-29-00Z__decompose-agent__completed.md`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 22:41:37 +00:00
thePR0M3TH3AN 058011089d Merge branch 'main' into fix-insecure-random-backoff-15480292305985131336 2026-02-17 14:30:13 -05:00
thePR0M3TH3AN db38fb0e91 Merge pull request #256 from PR0M3TH3AN/refactor-lock-ops-state-3445549076565547288
Refactor lock-ops to encapsulate global state
2026-02-17 14:27:22 -05:00
thePR0M3TH3AN fb558b0b4d Merge branch 'main' into test-improvement-get-relevant-memories-15158310533650216935 2026-02-17 14:26:54 -05:00
thePR0M3TH3AN e355330e5b Merge pull request #253 from PR0M3TH3AN/test-triggerPruneDryRun-12931935296810438248
test: Add tests for triggerPruneDryRun
2026-02-17 14:26:29 -05:00
thePR0M3TH3AN 3502d38431 Merge branch 'main' into jules-perf-async-config-1969443791138192182 2026-02-17 14:26:06 -05:00
thePR0M3TH3AN da2e623b7c Merge pull request #246 from PR0M3TH3AN/test-render-prompt-memory-context-18203619131675777622
test: add comprehensive tests for renderPromptWithMemoryContext
2026-02-17 14:25:39 -05:00
thePR0M3TH3AN 4a59ccd501 Merge branch 'main' into test/ingest-events-coverage-4058176338689655233 2026-02-17 14:25:04 -05:00
thePR0M3TH3AN 26c878bdd9 Merge pull request #245 from PR0M3TH3AN/test-memory-ingest-events-14179486498291680650
Add unit tests for memory ingestEvents
2026-02-17 14:24:33 -05:00
thePR0M3TH3AN f79eae6ae9 Merge pull request #248 from PR0M3TH3AN/test/memory-stats-coverage-2370317382454489346
test: Add comprehensive tests for memoryStats function
2026-02-17 14:24:08 -05:00
thePR0M3TH3AN e9dcfb8c01 Merge pull request #251 from PR0M3TH3AN/test/cmd-check-improvements-4816638132352517865
🧪 Add tests for cmdCheck
2026-02-17 14:23:46 -05:00
thePR0M3TH3AN 4159ce1ad5 Merge pull request #257 from PR0M3TH3AN/jules-memory-prune-tests-5206348108909836817
Add tests for memory pruning cycle
2026-02-17 14:23:00 -05:00
google-labs-jules[bot]andPR0M3TH3AN 50b0cf5a07 perf: Refactor config loading to be non-blocking async
Replaces synchronous `fs.readFileSync` with `fs.promises.readFile` in `loadTorchConfig` to prevent event loop blocking.
Updates all dependent configuration getters and consumers to use async/await.
Includes benchmark proving non-blocking behavior.
Fixes dashboard tests to properly await server listening.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 19:02:46 +00:00
google-labs-jules[bot]andPR0M3TH3AN a940172998 feat(test): add tests for runPruneCycle
- Added `test/memory-run-prune-cycle.test.mjs` to test `runPruneCycle` logic.
- Covered active pruning, dry-run, off mode, telemetry/metrics, and scheduling.
- Utilized environment isolation (temp dir) to prevent side effects on `.scheduler-memory/memory-store.json`.
- Addressed testing gap for `runPruneCycle` in `src/services/memory/index.js`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:55:55 +00:00
google-labs-jules[bot]andPR0M3TH3AN 59fbe1f4b8 Refactor lock-ops to encapsulate global state in RelayHealthManager class
- Replaces module-level mutable state (`metricsByRelay`, `lastSnapshotAt`) with `RelayHealthManager` class.
- Moves state-dependent functions (`ensureRelayMetrics`, `rankRelaysByHealth`, etc.) to class methods.
- Updates `queryLocks` and `publishLock` to support dependency injection for `healthManager`.
- Maintains backward compatibility via `defaultHealthManager` singleton.
- Adds `test/relay-health-manager.test.mjs` to verify state isolation and functionality.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:55:11 +00:00
google-labs-jules[bot]andPR0M3TH3AN 568d37a45c Fix insecure random number generator in backoff logic
Replaced `Math.random` with a cryptographically secure random number generator using `node:crypto.randomInt` in `src/lock-ops.mjs` to prevent potential timing attacks or predictability in backoff delays.

Added `test/secure-random.test.mjs` to verify the secure random generator.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:54:42 +00:00
google-labs-jules[bot]andPR0M3TH3AN 6be1809585 test: Add tests for triggerPruneDryRun
Added unit tests for triggerPruneDryRun in src/services/memory/index.js.
Tests cover database-backed pruning and in-memory fallback pruning using mocked repositories.
Also included validation of output structure.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:54:04 +00:00
google-labs-jules[bot]andPR0M3TH3AN 99bd4ba2a3 test: add unit tests for cmdCheck
Refactor `cmdCheck` in `src/cmd-check.mjs` to support dependency injection for better testability.
Add `test/cmd-check.test.mjs` with comprehensive unit tests for `cmdCheck`, covering happy paths and edge cases.
Verify tests pass with `node --test test/cmd-check.test.mjs`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:53:55 +00:00
google-labs-jules[bot]andPR0M3TH3AN 694afb1462 feat: make getRelevantMemories testable and add tests
- Modified `getRelevantMemories` in `src/services/memory/index.js` to accept optional `ranker` and `cache` parameters for dependency injection.
- Added `test/memory-index.test.mjs` with comprehensive unit tests for `getRelevantMemories` using `node:test` mocks.
- Verified that existing behavior is preserved via default parameters.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:53:52 +00:00
google-labs-jules[bot]andPR0M3TH3AN 1926426b11 test: add missing error handling test for lock-utils
Add a unit test for `getCompletedAgents` in `src/lock-utils.mjs` to verify that:
1. It correctly identifies completed agents.
2. It handles `ENOENT` gracefully (silent).
3. It logs an error for non-`ENOENT` errors (e.g. permission denied).

The `getCompletedAgents` function already supported dependency injection via a `deps` object, which is utilized in this test to mock `fs.readdir` and other dependencies.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:53:34 +00:00
google-labs-jules[bot]andPR0M3TH3AN fde5dbc67d test: Add comprehensive tests for memoryStats function
Adds `test/memory-stats.test.mjs` to validats `memoryStats` behavior including:
- Empty and populated repository states
- Ingest throughput calculation with mocked time
- Deleted rate metrics
- Window parameter handling

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:53:07 +00:00
google-labs-jules[bot]andPR0M3TH3AN e8cad0b42d feat(test): add unit tests for ingestEvents in memory service
Added `test/memory-ingest.test.mjs` to cover `ingestEvents` functionality.
Tests cover:
- Happy path ingestion with mocked repository and telemetry.
- Feature flag handling (skipping ingestion when disabled).
- Cache invalidation after ingestion.
- Deduplication logic.
- Error propagation from repository.

This improves test coverage for the memory service and ensures reliability of the ingestion process.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:53:00 +00:00
google-labs-jules[bot]andPR0M3TH3AN 5f0aefe67e test: add comprehensive tests for renderPromptWithMemoryContext
Adds test cases for `renderPromptWithMemoryContext` in `src/services/memory/formatter.js`, covering:
- Agent context serialization (arrays, objects, primitives)
- Memory usage updates side effects
- Edge cases for empty/null memories
- Feature flag handling (global toggle and allowlist)
- Parameter passing (k, tokenBudget)

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:52:30 +00:00
google-labs-jules[bot]andPR0M3TH3AN 33bde42591 feat(test): add unit tests for memory ingestEvents
Added comprehensive unit tests for `ingestEvents` in `src/services/memory/index.js`.
Tests cover:
- Happy path ingestion with mocked repository and telemetry.
- Feature flag skipping behavior.
- Cache clearing side effects.
- Deduplication logic.
- Error handling.

This improves test coverage and reliability for the memory service.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:52:27 +00:00
google-labs-jules[bot]andPR0M3TH3AN 5bfe5f7c74 test: add comprehensive tests for relay-health summarizeHistory
Added a new test file `test/relay-health.test.mjs` to cover the `summarizeHistory` function in `src/relay-health.mjs`.

Tests cover:
- Basic statistics calculation (success rate, sample count).
- Time window filtering.
- `allDownDurationMinutes` calculation (checking outside window).
- Edge cases: empty history, malformed data, never healthy, always healthy.

Verified that tests pass with `node --test test/relay-health.test.mjs`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:49:30 +00:00
thePR0M3TH3AN 651e5e659f Merge branch 'main' into test-circular-agent-context-2548280250167598137 2026-02-17 13:38:01 -05:00
thePR0M3TH3AN d3926f8a36 Merge pull request #234 from PR0M3TH3AN/test-memory-formatter-circular-context-16916269218151396900
🧪 Add test for circular agentContext in renderPromptWithMemoryContext
2026-02-17 13:37:29 -05:00
thePR0M3TH3AN 88bb2e8fff Merge branch 'main' into test/unpin-memory-coverage-10292270866664076558 2026-02-17 13:37:09 -05:00