Skip to content

Commit 661f15c

Browse files
vrasparCopilot
andauthored
fix: replace hardcoded dates in MCP tests with relative dates (#69)
Tests used fixed 2026-03 dates that fall outside the 7-day window as time passes. Now uses daysAgo() helper for dates relative to test execution time. Tests work regardless of when they're run. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 93129bc commit 661f15c

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

test/mcp.test.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ let db: Database.Database;
2828
let server: McpServer;
2929
let context: BrainMcpContext;
3030

31+
// Relative dates so tests work regardless of when they run
32+
const now = new Date();
33+
const daysAgo = (n: number) => new Date(now.getTime() - n * 24 * 60 * 60 * 1000).toISOString();
34+
3135
function makeEntry(overrides: Partial<Entry> = {}): Entry {
3236
return {
3337
id: 'test-entry',
3438
title: 'Test Entry',
3539
type: 'guide',
3640
author: 'alice',
37-
created: '2026-03-20T10:00:00Z',
38-
updated: '2026-03-20T10:00:00Z',
41+
created: daysAgo(1),
42+
updated: daysAgo(1),
3943
tags: ['testing'],
4044
status: 'active',
4145
content: 'This is test content.',
@@ -54,8 +58,8 @@ const sampleEntries: Entry[] = [
5458
content: 'How to deploy applications to Kubernetes clusters.',
5559
filePath: 'guides/k8s-deployment.md',
5660
summary: 'Step-by-step K8s deployment',
57-
created: '2026-03-18T10:00:00Z',
58-
updated: '2026-03-20T14:00:00Z',
61+
created: daysAgo(3),
62+
updated: daysAgo(1),
5963
}),
6064
makeEntry({
6165
id: 'react-testing',
@@ -66,8 +70,8 @@ const sampleEntries: Entry[] = [
6670
content: 'Best practices for testing React components.',
6771
filePath: 'skills/react-testing.md',
6872
summary: 'React testing patterns',
69-
created: '2026-03-19T08:00:00Z',
70-
updated: '2026-03-21T12:00:00Z',
73+
created: daysAgo(2),
74+
updated: daysAgo(0),
7175
}),
7276
makeEntry({
7377
id: 'ci-pipeline',
@@ -78,8 +82,8 @@ const sampleEntries: Entry[] = [
7882
content: 'Setting up CI pipelines with GitHub Actions.',
7983
filePath: 'skills/ci-pipeline.md',
8084
summary: 'CI pipeline automation',
81-
created: '2026-03-21T09:00:00Z',
82-
updated: '2026-03-21T09:00:00Z',
85+
created: daysAgo(0),
86+
updated: daysAgo(0),
8387
}),
8488
];
8589

@@ -97,7 +101,7 @@ beforeEach(() => {
97101
remote: 'https://github.com/team/brain.git',
98102
local: tempDir,
99103
author: 'alice',
100-
lastSync: '2026-03-21T00:00:00Z',
104+
lastSync: daysAgo(0),
101105
};
102106

103107
context = { config, db };

0 commit comments

Comments
 (0)