mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-10-31 01:41:55 +00:00
Merge pull request #249 from PR0M3TH3AN/test-lock-utils-error-handling-1774013981640093185
🧪 Add missing error handling test for lock-utils
This commit is contained in:
2 files changed
+69
-513
No files matched your search
@@ -1,403 +0,0 @@
|
||||
[
|
||||
[
|
||||
"638c2d47-3218-42f5-bc2d-e3adeb4626d0",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "638c2d47-3218-42f5-bc2d-e3adeb4626d0",
|
||||
"agent_id": "test-agent",
|
||||
"session_id": "test-run",
|
||||
"type": "batch_window",
|
||||
"content": "Store memory event A for daily :: scheduler memory store\nStore memory event B for daily :: scheduler memory store",
|
||||
"summary": "Store memory event A for daily :: scheduler memory store Store memory event B for daily :: scheduler memory store",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"daily",
|
||||
"store"
|
||||
],
|
||||
"importance": 0.55,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771295950236,
|
||||
"last_seen": 1771295958659,
|
||||
"source": "scheduler-store",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"5c458e0c-8239-46f9-99d1-b61cf05acc34",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "5c458e0c-8239-46f9-99d1-b61cf05acc34",
|
||||
"agent_id": "test-agent",
|
||||
"session_id": "test-run-2",
|
||||
"type": "batch_window",
|
||||
"content": "Memory retrieval seed for daily :: scheduler memory retrieval",
|
||||
"summary": "Memory retrieval seed for daily :: scheduler memory retrieval",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"daily",
|
||||
"retrieve"
|
||||
],
|
||||
"importance": 0.4,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771295958645,
|
||||
"last_seen": 1771295958659,
|
||||
"source": "scheduler-retrieve",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"2e9129bd-c366-4d82-ac2b-7e50574532a9",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "2e9129bd-c366-4d82-ac2b-7e50574532a9",
|
||||
"agent_id": "onboarding-audit-agent",
|
||||
"session_id": "initial-seed",
|
||||
"type": "batch_window",
|
||||
"content": "Store memory event A for daily :: Required startup + artifacts + memory + issue capture\nStore memory event B for daily :: Required startup + artifacts + memory + issue capture",
|
||||
"summary": "Store memory event A for daily :: Required startup + artifacts + memory + issue capture Store memory event B for daily :: Required startup + artifacts + memory + issue capture",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"daily",
|
||||
"store"
|
||||
],
|
||||
"importance": 0.55,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771296574057,
|
||||
"last_seen": 1771296574172,
|
||||
"source": "scheduler-store",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"2612b9ce-1aa7-4731-acb2-c3a852eeaac6",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "2612b9ce-1aa7-4731-acb2-c3a852eeaac6",
|
||||
"agent_id": "onboarding-audit-agent",
|
||||
"session_id": "initial-seed",
|
||||
"type": "batch_window",
|
||||
"content": "Memory retrieval seed for daily :: Required startup + artifacts + memory + issue capture",
|
||||
"summary": "Memory retrieval seed for daily :: Required startup + artifacts + memory + issue capture",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"daily",
|
||||
"retrieve"
|
||||
],
|
||||
"importance": 0.4,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771296574158,
|
||||
"last_seen": 1771296574172,
|
||||
"source": "scheduler-retrieve",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"facf005a-dad0-4066-921c-49a8e408665c",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "facf005a-dad0-4066-921c-49a8e408665c",
|
||||
"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": 1771296636016,
|
||||
"last_seen": 1771301051605,
|
||||
"source": "ingest",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"19ef312e-a725-4544-850e-651713e2d9dc",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "19ef312e-a725-4544-850e-651713e2d9dc",
|
||||
"agent_id": "bug-reproducer-agent",
|
||||
"session_id": "session-mlq2vq5p",
|
||||
"type": "batch_window",
|
||||
"content": "Memory retrieval seed for weekly :: Required startup + artifacts + memory + issue capture",
|
||||
"summary": "Memory retrieval seed for weekly :: Required startup + artifacts + memory + issue capture",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"weekly",
|
||||
"retrieve"
|
||||
],
|
||||
"importance": 0.4,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771300999213,
|
||||
"last_seen": 1771300999222,
|
||||
"source": "scheduler-retrieve",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"bfbb3c6e-095d-4ccd-ad5a-140b6927421c",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "bfbb3c6e-095d-4ccd-ad5a-140b6927421c",
|
||||
"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": 1771301051598,
|
||||
"last_seen": 1771301051605,
|
||||
"source": "ingest",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"d74e3e34-6cf1-465e-b4a8-64acd0a8d803",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "d74e3e34-6cf1-465e-b4a8-64acd0a8d803",
|
||||
"agent_id": "bug-reproducer-agent",
|
||||
"session_id": "session-mlq2ysd2",
|
||||
"type": "batch_window",
|
||||
"content": "Reproduced npm test timeout issue. Created reproduction script in artifacts/reproducers/npm-test-timeout/. Confirmed that `npm test` hangs/times out as expected.",
|
||||
"summary": "Reproduced npm test timeout issue. Created reproduction script in artifacts/reproducers/npm-test-timeout/. Confirmed that `npm test` hangs/times out as expected.",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"weekly",
|
||||
"store",
|
||||
"insight"
|
||||
],
|
||||
"importance": 0.8,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771301142040,
|
||||
"last_seen": 1771301142040,
|
||||
"source": "agent-output",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"3df7bccf-f3f1-45b9-ab15-88a1a30c6453",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "3df7bccf-f3f1-45b9-ab15-88a1a30c6453",
|
||||
"agent_id": "changelog-agent",
|
||||
"session_id": "session-mlq51t0r",
|
||||
"type": "batch_window",
|
||||
"content": "Memory retrieval seed for weekly :: Required startup + artifacts + memory + issue capture",
|
||||
"summary": "Memory retrieval seed for weekly :: Required startup + artifacts + memory + issue capture",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"weekly",
|
||||
"retrieve"
|
||||
],
|
||||
"importance": 0.4,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771304642091,
|
||||
"last_seen": 1771304642101,
|
||||
"source": "scheduler-retrieve",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"5b32be34-78f9-44ac-b7b1-e301e34f04d0",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "5b32be34-78f9-44ac-b7b1-e301e34f04d0",
|
||||
"agent_id": "changelog-agent",
|
||||
"session_id": "session-mlq53the",
|
||||
"type": "batch_window",
|
||||
"content": "# Changelog Update - 2026-02-17\n\nGenerated draft release notes covering 212 commits.\nKey areas:\n- Scheduler automation improvements\n- Memory management features\n- Codebase modularization",
|
||||
"summary": "# Changelog Update - 2026-02-17\n\nGenerated draft release notes covering 212 commits.\nKey areas:\n- Scheduler automation improvements\n- Memory management features\n- Codebase modularization",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"weekly",
|
||||
"store",
|
||||
"insight"
|
||||
],
|
||||
"importance": 0.8,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771304736005,
|
||||
"last_seen": 1771304736005,
|
||||
"source": "agent-output",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"40f6bf1a-9715-4906-82d1-8f68be78eb3f",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "40f6bf1a-9715-4906-82d1-8f68be78eb3f",
|
||||
"agent_id": "dead-code-agent",
|
||||
"session_id": "1771338346",
|
||||
"type": "batch_window",
|
||||
"content": "Memory retrieval seed for weekly :: Required startup + artifacts + memory + issue capture",
|
||||
"summary": "Memory retrieval seed for weekly :: Required startup + artifacts + memory + issue capture",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"weekly",
|
||||
"retrieve"
|
||||
],
|
||||
"importance": 0.4,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771338346815,
|
||||
"last_seen": 1771338346833,
|
||||
"source": "scheduler-retrieve",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"267412f9-9704-4739-8481-8317a89e6769",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "267412f9-9704-4739-8481-8317a89e6769",
|
||||
"agent_id": "dead-code-agent",
|
||||
"session_id": "1771338501",
|
||||
"type": "batch_window",
|
||||
"content": "# Weekly Dead Code Analysis - 2026-02-17\n\n**Agent:** dead-code-agent\n**Cadence:** weekly\n**Status:** Completed\n\n## Summary\nExecuted a safety-first dead-code sweep.\n\n## Findings\n- Identified `scripts/fix-duplication.mjs` as an unused standalone script.\n- Identified `src/services/memory/db-adapter.js` as an unused module (exports `createMemoryRepository` but not imported anywhere).\n\n## Actions\n- Verified zero usage for both files using `grep`.\n- Deleted both files in branch `ai/dead-code-20260217`.\n- Verified deletions with `ls` and ran `npm run lint` and `npm run test:unit:lock-backend`.\n- Artifacts generated in `artifacts/dead-code-20260217/`.",
|
||||
"summary": "# Weekly Dead Code Analysis - 2026-02-17\n\n**Agent:** dead-code-agent\n**Cadence:** weekly\n**Status:** Completed\n\n## Summary\nExecuted a safety-first dead-code sweep.\n\n## Findings\n- Identified `scripts/fix-duplication.mjs` as an unused standalone script.\n- Identified `src/services/…",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"weekly",
|
||||
"store",
|
||||
"insight"
|
||||
],
|
||||
"importance": 0.8,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771338501891,
|
||||
"last_seen": 1771338501891,
|
||||
"source": "agent-output",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"fd852345-c9c5-4c5c-8076-7e16a7b90016",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "fd852345-c9c5-4c5c-8076-7e16a7b90016",
|
||||
"agent_id": "feature-proposer-agent",
|
||||
"session_id": "session-1771346034",
|
||||
"type": "batch_window",
|
||||
"content": "Memory retrieval seed for weekly :: Required startup + artifacts + memory + issue capture",
|
||||
"summary": "Memory retrieval seed for weekly :: Required startup + artifacts + memory + issue capture",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"weekly",
|
||||
"retrieve"
|
||||
],
|
||||
"importance": 0.4,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771346034674,
|
||||
"last_seen": 1771346034684,
|
||||
"source": "scheduler-retrieve",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"abe5bddd-5b7a-4e18-aabf-9d517bd59a8e",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "abe5bddd-5b7a-4e18-aabf-9d517bd59a8e",
|
||||
"agent_id": "feature-proposer-agent",
|
||||
"session_id": "session-1771346112",
|
||||
"type": "batch_window",
|
||||
"content": "# Memory Update - Feature Proposer Agent\n\n**Date**: 2026-02-17T15-00-00Z\n**Agent**: feature-proposer-agent\n\n## Insights\n- The `task-logs` structure is consistent and easy to parse.\n- A simple CLI tool (`features/log-summary.mjs`) was added to visualize this data.\n- This pattern of \"small, standalone utility scripts\" in `features/` is effective for incremental improvement.\n\n## Actions\n- Implemented `features/log-summary.mjs`.\n- Verified with manual execution.\n\n## Recommendations\n- Future agents could enhance this script to filter by status (e.g., show only failed runs).",
|
||||
"summary": "# Memory Update - Feature Proposer Agent\n\n**Date**: 2026-02-17T15-00-00Z\n**Agent**: feature-proposer-agent\n\n## Insights\n- The `task-logs` structure is consistent and easy to parse.\n- A simple CLI tool (`features/log-summary.mjs`) was added to visualize this data.\n- This pattern …",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"weekly",
|
||||
"store",
|
||||
"insight"
|
||||
],
|
||||
"importance": 0.8,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771346112755,
|
||||
"last_seen": 1771346112755,
|
||||
"source": "agent-output",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"9f17b770-803f-401b-8bec-4c8ce413f232",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "9f17b770-803f-401b-8bec-4c8ce413f232",
|
||||
"agent_id": "audit-agent",
|
||||
"session_id": "session-mlqwxsc8",
|
||||
"type": "batch_window",
|
||||
"content": "Memory retrieval seed for daily :: Required startup + artifacts + memory + issue capture",
|
||||
"summary": "Memory retrieval seed for daily :: Required startup + artifacts + memory + issue capture",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"daily",
|
||||
"retrieve"
|
||||
],
|
||||
"importance": 0.4,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771351483834,
|
||||
"last_seen": 1771351483843,
|
||||
"source": "scheduler-retrieve",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
],
|
||||
[
|
||||
"30b53ec3-5d17-4b38-9d80-4f9c15e3cd7e",
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "30b53ec3-5d17-4b38-9d80-4f9c15e3cd7e",
|
||||
"agent_id": "audit-agent",
|
||||
"session_id": "session-mlqwzwl4",
|
||||
"type": "batch_window",
|
||||
"content": "# Audit Agent Report (2026-02-17)\n\n## Metrics\n- Oversized files: 18 (4010 excess lines)\n- InnerHTML assignments: 5\n- Lint failures: 13\n\n## Findings\n- Top oversized: scripts/agent/run-scheduler-cycle.mjs (1092 lines)\n- InnerHTML usage in dashboard/index.html and landing/index.html.\n- Lint warnings mostly unused vars.",
|
||||
"summary": "# Audit Agent Report (2026-02-17)\n\n## Metrics\n- Oversized files: 18 (4010 excess lines)\n- InnerHTML assignments: 5\n- Lint failures: 13\n\n## Findings\n- Top oversized: scripts/agent/run-scheduler-cycle.mjs (1092 lines)\n- InnerHTML usage in dashboard/index.html and landing/index.htm…",
|
||||
"tags": [
|
||||
"scheduler",
|
||||
"daily",
|
||||
"store",
|
||||
"insight"
|
||||
],
|
||||
"importance": 0.8,
|
||||
"embedding_id": null,
|
||||
"created_at": 1771351582653,
|
||||
"last_seen": 1771351582653,
|
||||
"source": "agent-output",
|
||||
"ttl_days": null,
|
||||
"merged_into": null,
|
||||
"pinned": false
|
||||
}
|
||||
]
|
||||
]
|
||||
+69
-110
@@ -1,125 +1,84 @@
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import { describe, it, mock } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { getCompletedAgents } from '../src/lock-utils.mjs';
|
||||
|
||||
describe('getCompletedAgents', () => {
|
||||
it('identifies completed agents for daily cadence today', async () => {
|
||||
const today = '2023-10-27';
|
||||
const files = [
|
||||
`2023-10-27T10-00-00Z__agent1__completed.md`,
|
||||
`2023-10-26T10-00-00Z__agent2__completed.md`, // Yesterday
|
||||
`2023-10-27T11-00-00Z__agent3__started.md`, // Not completed
|
||||
];
|
||||
|
||||
const deps = {
|
||||
readdir: async () => files,
|
||||
getDateStr: () => today,
|
||||
getIsoWeek: () => '2023-W43',
|
||||
};
|
||||
|
||||
const completed = await getCompletedAgents('daily', 'logs', deps);
|
||||
assert.deepStrictEqual([...completed], ['agent1']);
|
||||
});
|
||||
|
||||
it('identifies completed agents for weekly cadence this week', async () => {
|
||||
const today = '2023-10-27';
|
||||
const currentWeek = '2023-W43';
|
||||
|
||||
// agent1: completed this week (today)
|
||||
// agent2: completed this week (yesterday)
|
||||
// agent3: completed last week
|
||||
// agent4: started this week
|
||||
|
||||
const files = [
|
||||
`2023-10-27T10-00-00Z__agent1__completed.md`,
|
||||
`2023-10-26T10-00-00Z__agent2__completed.md`,
|
||||
`2023-10-20T10-00-00Z__agent3__completed.md`,
|
||||
`2023-10-27T11-00-00Z__agent4__started.md`,
|
||||
];
|
||||
|
||||
const deps = {
|
||||
readdir: async () => files,
|
||||
getDateStr: () => today,
|
||||
getIsoWeek: (date) => {
|
||||
if (!date) return currentWeek;
|
||||
if (date === '2023-10-27' || date === '2023-10-26') return '2023-W43';
|
||||
if (date === '2023-10-20') return '2023-W42';
|
||||
return 'unknown';
|
||||
},
|
||||
};
|
||||
|
||||
const completed = await getCompletedAgents('weekly', 'logs', deps);
|
||||
assert.deepStrictEqual([...completed].sort(), ['agent1', 'agent2']);
|
||||
});
|
||||
|
||||
it('handles empty directory gracefully', async () => {
|
||||
const deps = {
|
||||
describe('lock-utils', () => {
|
||||
describe('getCompletedAgents', () => {
|
||||
// Helper to create deps
|
||||
const createDeps = (overrides = {}) => ({
|
||||
readdir: async () => [],
|
||||
getDateStr: () => '2023-10-27',
|
||||
getIsoWeek: () => '2023-W43',
|
||||
};
|
||||
getDateStr: () => '2023-01-01',
|
||||
getIsoWeek: () => '2023-W01',
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const completed = await getCompletedAgents('daily', 'logs', deps);
|
||||
assert.strictEqual(completed.size, 0);
|
||||
});
|
||||
it('returns completed agents for daily cadence', async () => {
|
||||
const deps = createDeps({
|
||||
readdir: async () => [
|
||||
'2023-01-01T10-00-00Z__agent1__completed.md',
|
||||
'2023-01-01T11-00-00Z__agent2__failed.md',
|
||||
'2023-01-02T10-00-00Z__agent3__completed.md', // different day
|
||||
],
|
||||
getDateStr: () => '2023-01-01',
|
||||
});
|
||||
const result = await getCompletedAgents('daily', 'logs', deps);
|
||||
assert.deepEqual([...result], ['agent1']);
|
||||
});
|
||||
|
||||
it('ignores malformed filenames', async () => {
|
||||
const files = [
|
||||
'not-a-valid-log-file.txt',
|
||||
'2023-10-27__agent1__completed.md', // Missing time part
|
||||
];
|
||||
it('returns completed agents for weekly cadence', async () => {
|
||||
const deps = createDeps({
|
||||
readdir: async () => [
|
||||
'2023-01-01T10-00-00Z__agent1__completed.md', // Week 52 of 2022 (Sunday) - assuming mock logic
|
||||
'2023-01-02T10-00-00Z__agent2__completed.md', // Week 01 of 2023 (Monday)
|
||||
],
|
||||
getIsoWeek: (date) => {
|
||||
if (!date) return '2023-W01'; // current week
|
||||
if (date === '2023-01-01') return '2022-W52';
|
||||
if (date === '2023-01-02') return '2023-W01';
|
||||
return 'UNKNOWN';
|
||||
}
|
||||
});
|
||||
// cadence is weekly
|
||||
const result = await getCompletedAgents('weekly', 'logs', deps);
|
||||
assert.deepEqual([...result], ['agent2']);
|
||||
});
|
||||
|
||||
const deps = {
|
||||
readdir: async () => files,
|
||||
getDateStr: () => '2023-10-27',
|
||||
getIsoWeek: () => '2023-W43',
|
||||
};
|
||||
it('handles ENOENT gracefully', async () => {
|
||||
const error = new Error('No such file or directory');
|
||||
error.code = 'ENOENT';
|
||||
const deps = createDeps({
|
||||
readdir: async () => { throw error; }
|
||||
});
|
||||
|
||||
const completed = await getCompletedAgents('daily', 'logs', deps);
|
||||
assert.strictEqual(completed.size, 0);
|
||||
});
|
||||
// Spy on console.error to ensure it is NOT called
|
||||
const consoleError = mock.method(console, 'error');
|
||||
|
||||
it('handles readdir errors (non-ENOENT) by logging and returning empty set', async () => {
|
||||
const originalError = console.error;
|
||||
let errorCalled = false;
|
||||
console.error = (msg) => { errorCalled = true; };
|
||||
const result = await getCompletedAgents('daily', 'logs', deps);
|
||||
|
||||
const deps = {
|
||||
readdir: async () => { throw new Error('Permission denied'); },
|
||||
getDateStr: () => '2023-10-27',
|
||||
getIsoWeek: () => '2023-W43',
|
||||
};
|
||||
assert.equal(consoleError.mock.callCount(), 0);
|
||||
assert.deepEqual([...result], []);
|
||||
consoleError.mock.restore();
|
||||
});
|
||||
|
||||
try {
|
||||
const completed = await getCompletedAgents('daily', 'logs', deps);
|
||||
assert.strictEqual(completed.size, 0);
|
||||
assert.strictEqual(errorCalled, true);
|
||||
} finally {
|
||||
console.error = originalError;
|
||||
}
|
||||
});
|
||||
it('logs error for non-ENOENT errors', async () => {
|
||||
const error = new Error('Permission denied');
|
||||
error.code = 'EACCES';
|
||||
const deps = createDeps({
|
||||
readdir: async () => { throw error; }
|
||||
});
|
||||
|
||||
it('handles ENOENT (directory missing) silently', async () => {
|
||||
const originalError = console.error;
|
||||
let errorCalled = false;
|
||||
console.error = (msg) => { errorCalled = true; };
|
||||
// Spy on console.error to verify it IS called
|
||||
const consoleError = mock.method(console, 'error');
|
||||
|
||||
const deps = {
|
||||
readdir: async () => {
|
||||
const err = new Error('Directory not found');
|
||||
err.code = 'ENOENT';
|
||||
throw err;
|
||||
},
|
||||
getDateStr: () => '2023-10-27',
|
||||
getIsoWeek: () => '2023-W43',
|
||||
};
|
||||
const result = await getCompletedAgents('daily', 'logs', deps);
|
||||
|
||||
try {
|
||||
const completed = await getCompletedAgents('daily', 'logs', deps);
|
||||
assert.strictEqual(completed.size, 0);
|
||||
assert.strictEqual(errorCalled, false);
|
||||
} finally {
|
||||
console.error = originalError;
|
||||
}
|
||||
assert.equal(consoleError.mock.callCount(), 1);
|
||||
const call = consoleError.mock.calls[0];
|
||||
assert.match(call.arguments[0], /Warning: Failed to read log dir/);
|
||||
assert.match(call.arguments[0], /Permission denied/);
|
||||
|
||||
assert.deepEqual([...result], []);
|
||||
consoleError.mock.restore();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user