From 9a9f93aa048838bbaca3ff454c536e701fa0ea28 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 18 Feb 2026 03:23:18 +0000 Subject: [PATCH] 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 <53631862+PR0M3TH3AN@users.noreply.github.com> --- .scheduler-memory/memory-store.json | 75 ++++++++++- src/cmd-check.mjs | 61 --------- test/cmd-check.test.mjs | 187 ---------------------------- 3 files changed, 72 insertions(+), 251 deletions(-) delete mode 100644 src/cmd-check.mjs delete mode 100644 test/cmd-check.test.mjs diff --git a/.scheduler-memory/memory-store.json b/.scheduler-memory/memory-store.json index 702dd60..7581d77 100644 --- a/.scheduler-memory/memory-store.json +++ b/.scheduler-memory/memory-store.json @@ -117,7 +117,7 @@ "importance": 0.25, "embedding_id": null, "created_at": 1771370050385, - "last_seen": 1771370148086, + "last_seen": 1771384958445, "source": "ingest", "ttl_days": null, "merged_into": null, @@ -140,7 +140,7 @@ "importance": 0.25, "embedding_id": null, "created_at": 1771370084740, - "last_seen": 1771370148086, + "last_seen": 1771384958445, "source": "ingest", "ttl_days": null, "merged_into": null, @@ -163,7 +163,7 @@ "importance": 0.25, "embedding_id": null, "created_at": 1771370148079, - "last_seen": 1771370148086, + "last_seen": 1771384958445, "source": "ingest", "ttl_days": null, "merged_into": null, @@ -244,5 +244,74 @@ "merged_into": null, "pinned": false } + ], + [ + "71791fc3-49a7-40f2-a8e5-c93e8b19f32b", + { + "schema_version": 1, + "id": "71791fc3-49a7-40f2-a8e5-c93e8b19f32b", + "agent_id": "agent-telemetry", + "session_id": "s-telemetry", + "type": "batch_window", + "content": "customer token ABC123 secret", + "summary": "customer token ABC123 secret", + "tags": [ + "incident" + ], + "importance": 0.25, + "embedding_id": null, + "created_at": 1771384842151, + "last_seen": 1771384958445, + "source": "ingest", + "ttl_days": null, + "merged_into": null, + "pinned": false + } + ], + [ + "ca60066d-1d01-43de-a597-573d9826d101", + { + "schema_version": 1, + "id": "ca60066d-1d01-43de-a597-573d9826d101", + "agent_id": "agent-telemetry", + "session_id": "s-telemetry", + "type": "batch_window", + "content": "customer token ABC123 secret", + "summary": "customer token ABC123 secret", + "tags": [ + "incident" + ], + "importance": 0.25, + "embedding_id": null, + "created_at": 1771384870483, + "last_seen": 1771384958445, + "source": "ingest", + "ttl_days": null, + "merged_into": null, + "pinned": false + } + ], + [ + "b95b047e-6bc6-4342-a535-8d311ebc7f1a", + { + "schema_version": 1, + "id": "b95b047e-6bc6-4342-a535-8d311ebc7f1a", + "agent_id": "agent-telemetry", + "session_id": "s-telemetry", + "type": "batch_window", + "content": "customer token ABC123 secret", + "summary": "customer token ABC123 secret", + "tags": [ + "incident" + ], + "importance": 0.25, + "embedding_id": null, + "created_at": 1771384958439, + "last_seen": 1771384958445, + "source": "ingest", + "ttl_days": null, + "merged_into": null, + "pinned": false + } ] ] \ No newline at end of file diff --git a/src/cmd-check.mjs b/src/cmd-check.mjs deleted file mode 100644 index a0d16f4..0000000 --- a/src/cmd-check.mjs +++ /dev/null @@ -1,61 +0,0 @@ -import { - loadTorchConfig, - getRelays, - getNamespace, -} from './torch-config.mjs'; -import { getRoster } from './roster.mjs'; -import { queryLocks } from './lock-ops.mjs'; -import { todayDateStr } from './utils.mjs'; - -export async function cmdCheck(cadence, deps = {}) { - const { - loadTorchConfigFn = loadTorchConfig, - getRelaysFn = getRelays, - getNamespaceFn = getNamespace, - getRosterFn = getRoster, - queryLocksFn = queryLocks, - todayDateStrFn = todayDateStr, - } = deps; - - const relays = await getRelaysFn(); - const namespace = await getNamespaceFn(); - const dateStr = todayDateStrFn(); - const config = await loadTorchConfigFn(); - const pausedAgents = (cadence === 'daily' ? config.scheduler.paused.daily : config.scheduler.paused.weekly) || []; - - console.error(`Checking locks: namespace=${namespace}, cadence=${cadence}, date=${dateStr}`); - console.error(`Relays: ${relays.join(', ')}`); - if (pausedAgents.length > 0) { - console.error(`Paused agents: ${pausedAgents.join(', ')}`); - } - - const locks = await queryLocksFn(relays, cadence, dateStr, namespace); - const lockedAgents = [...new Set(locks.map((l) => l.agent).filter(Boolean))]; - const roster = await getRosterFn(cadence); - - const excludedAgents = [...new Set([...lockedAgents, ...pausedAgents])]; - const unknownLockedAgents = lockedAgents.filter((agent) => !roster.includes(agent)); - const available = roster.filter((a) => !excludedAgents.includes(a)); - - const result = { - namespace, - cadence, - date: dateStr, - locked: lockedAgents.sort(), - paused: pausedAgents.sort(), - excluded: excludedAgents.sort(), - available: available.sort(), - lockCount: locks.length, - unknownLockedAgents: unknownLockedAgents.sort(), - locks: locks.map((l) => ({ - agent: l.agent, - eventId: l.eventId, - createdAt: l.createdAtIso, - expiresAt: l.expiresAtIso, - platform: l.platform, - })), - }; - - console.log(JSON.stringify(result, null, 2)); - return result; -} diff --git a/test/cmd-check.test.mjs b/test/cmd-check.test.mjs deleted file mode 100644 index 287dd7b..0000000 --- a/test/cmd-check.test.mjs +++ /dev/null @@ -1,187 +0,0 @@ -import { describe, it, mock, afterEach, after } from 'node:test'; -import assert from 'node:assert'; -import { cmdCheck } from '../src/cmd-check.mjs'; - -// Mocks -const mockLoadTorchConfig = mock.fn(() => ({ - scheduler: { - paused: { - daily: [], - weekly: [], - }, - }, -})); -const mockGetRelays = mock.fn(() => ['wss://mock-relay']); -const mockGetNamespace = mock.fn(() => 'mock-namespace'); -const mockGetRoster = mock.fn(() => []); -const mockQueryLocks = mock.fn(async () => []); -const mockTodayDateStr = mock.fn(() => '2023-10-27'); - -const deps = { - loadTorchConfigFn: mockLoadTorchConfig, - getRelaysFn: mockGetRelays, - getNamespaceFn: mockGetNamespace, - getRosterFn: mockGetRoster, - queryLocksFn: mockQueryLocks, - todayDateStrFn: mockTodayDateStr, -}; - -describe('cmdCheck', () => { - // Capture console output - const originalConsoleLog = console.log; - const originalConsoleError = console.error; - let consoleLogOutput = []; - let consoleErrorOutput = []; - - const mockConsoleLog = mock.fn((msg) => { - consoleLogOutput.push(msg); - }); - const mockConsoleError = mock.fn((msg) => { - consoleErrorOutput.push(msg); - }); - - // Setup console mocks - console.log = mockConsoleLog; - console.error = mockConsoleError; - - afterEach(() => { - // Reset mocks - mockLoadTorchConfig.mock.resetCalls(); - mockGetRelays.mock.resetCalls(); - mockGetNamespace.mock.resetCalls(); - mockGetRoster.mock.resetCalls(); - mockQueryLocks.mock.resetCalls(); - mockTodayDateStr.mock.resetCalls(); - - // Clear captured output - consoleLogOutput = []; - consoleErrorOutput = []; - }); - - // Restore console after all tests - after(() => { - console.log = originalConsoleLog; - console.error = originalConsoleError; - }); - - it('correctly reports available agents when no locks exist', async () => { - mockGetRoster.mock.mockImplementation(() => ['agent1', 'agent2']); - mockQueryLocks.mock.mockImplementation(async () => []); - mockLoadTorchConfig.mock.mockImplementation(() => ({ - scheduler: { paused: { daily: [] } } - })); - - const result = await cmdCheck('daily', deps); - - assert.strictEqual(result.cadence, 'daily'); - assert.strictEqual(result.namespace, 'mock-namespace'); - assert.strictEqual(result.date, '2023-10-27'); - assert.deepStrictEqual(result.available, ['agent1', 'agent2']); - assert.deepStrictEqual(result.locked, []); - assert.deepStrictEqual(result.paused, []); - assert.deepStrictEqual(result.excluded, []); - assert.strictEqual(result.lockCount, 0); - - // Verify console output was JSON - assert.strictEqual(consoleLogOutput.length, 1); - const logOutput = JSON.parse(consoleLogOutput[0]); - assert.deepStrictEqual(logOutput.available, ['agent1', 'agent2']); - }); - - it('correctly identifies locked agents', async () => { - mockGetRoster.mock.mockImplementation(() => ['agent1', 'agent2', 'agent3']); - mockQueryLocks.mock.mockImplementation(async () => [ - { agent: 'agent1', eventId: 'evt1', createdAtIso: '2023-10-27T00:00:00Z', expiresAtIso: '2023-10-27T01:00:00Z', platform: 'linux' } - ]); - mockLoadTorchConfig.mock.mockImplementation(() => ({ - scheduler: { paused: { daily: [] } } - })); - - const result = await cmdCheck('daily', deps); - - assert.deepStrictEqual(result.available, ['agent2', 'agent3']); - assert.deepStrictEqual(result.locked, ['agent1']); - assert.deepStrictEqual(result.excluded, ['agent1']); - assert.strictEqual(result.lockCount, 1); - assert.strictEqual(result.locks[0].agent, 'agent1'); - }); - - it('correctly identifies paused agents', async () => { - mockGetRoster.mock.mockImplementation(() => ['agent1', 'agent2', 'agent3']); - mockQueryLocks.mock.mockImplementation(async () => []); - mockLoadTorchConfig.mock.mockImplementation(() => ({ - scheduler: { paused: { daily: ['agent2'] } } - })); - - const result = await cmdCheck('daily', deps); - - assert.deepStrictEqual(result.available, ['agent1', 'agent3']); - assert.deepStrictEqual(result.locked, []); - assert.deepStrictEqual(result.paused, ['agent2']); - assert.deepStrictEqual(result.excluded, ['agent2']); - }); - - it('handles agents that are both locked and paused', async () => { - mockGetRoster.mock.mockImplementation(() => ['agent1', 'agent2']); - mockQueryLocks.mock.mockImplementation(async () => [ - { agent: 'agent1', eventId: 'evt1' } - ]); - mockLoadTorchConfig.mock.mockImplementation(() => ({ - scheduler: { paused: { daily: ['agent1'] } } - })); - - const result = await cmdCheck('daily', deps); - - assert.deepStrictEqual(result.available, ['agent2']); - assert.deepStrictEqual(result.locked, ['agent1']); - assert.deepStrictEqual(result.paused, ['agent1']); - // excluded should contain unique agents - assert.deepStrictEqual(result.excluded, ['agent1']); - }); - - it('identifies unknown locked agents (not in roster)', async () => { - mockGetRoster.mock.mockImplementation(() => ['agent1']); - mockQueryLocks.mock.mockImplementation(async () => [ - { agent: 'agent1', eventId: 'evt1' }, - { agent: 'unknown-agent', eventId: 'evt2' } - ]); - mockLoadTorchConfig.mock.mockImplementation(() => ({ - scheduler: { paused: { daily: [] } } - })); - - const result = await cmdCheck('daily', deps); - - assert.deepStrictEqual(result.available, []); - assert.deepStrictEqual(result.locked, ['agent1', 'unknown-agent']); - assert.deepStrictEqual(result.unknownLockedAgents, ['unknown-agent']); - assert.deepStrictEqual(result.excluded, ['agent1', 'unknown-agent']); - }); - - it('handles weekly cadence', async () => { - mockGetRoster.mock.mockImplementation(() => ['weekly1', 'weekly2']); - mockQueryLocks.mock.mockImplementation(async () => []); - mockLoadTorchConfig.mock.mockImplementation(() => ({ - scheduler: { paused: { weekly: ['weekly2'] } } - })); - - const result = await cmdCheck('weekly', deps); - - assert.strictEqual(result.cadence, 'weekly'); - assert.deepStrictEqual(result.available, ['weekly1']); - assert.deepStrictEqual(result.paused, ['weekly2']); - }); - - it('handles empty roster', async () => { - mockGetRoster.mock.mockImplementation(() => []); - mockQueryLocks.mock.mockImplementation(async () => []); - mockLoadTorchConfig.mock.mockImplementation(() => ({ - scheduler: { paused: { daily: [] } } - })); - - const result = await cmdCheck('daily', deps); - - assert.deepStrictEqual(result.available, []); - assert.deepStrictEqual(result.locked, []); - assert.deepStrictEqual(result.paused, []); - }); -});