fix: reset/regenerate memories (#16548)

fix: reset memories
This commit is contained in:
Jason Rasmussen 2025-03-03 23:48:05 -05:00 committed by GitHub
parent c23c53bf6f
commit 1356468c38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 93 additions and 5 deletions

View file

@ -0,0 +1,56 @@
import { serverVersion } from 'src/constants';
import { JobName } from 'src/enum';
import { VersionService } from 'src/services/version.service';
import { TestContext } from 'test/factory';
import { getKyselyDB, newTestService } from 'test/utils';
const setup = async () => {
const db = await getKyselyDB();
const context = await TestContext.from(db).create();
const { sut, mocks } = newTestService(VersionService, context);
return {
context,
sut,
jobMock: mocks.job,
};
};
describe(VersionService.name, () => {
describe.concurrent('onBootstrap', () => {
it('record the current version on startup', async () => {
const { context, sut } = await setup();
const itemsBefore = await context.versionHistoryRepository.getAll();
expect(itemsBefore).toHaveLength(0);
await sut.onBootstrap();
const itemsAfter = await context.versionHistoryRepository.getAll();
expect(itemsAfter).toHaveLength(1);
expect(itemsAfter[0]).toEqual({
createdAt: expect.any(Date),
id: expect.any(String),
version: serverVersion.toString(),
});
});
it('should queue memory creation when upgrading from 1.128.0', async () => {
const { context, jobMock, sut } = await setup();
await context.versionHistoryRepository.create({ version: 'v1.128.0' });
await sut.onBootstrap();
expect(jobMock.queue).toHaveBeenCalledWith({ name: JobName.MEMORIES_CREATE });
});
it('should not queue memory creation when upgrading from 1.129.0', async () => {
const { context, jobMock, sut } = await setup();
await context.versionHistoryRepository.create({ version: 'v1.129.0' });
await sut.onBootstrap();
expect(jobMock.queue).not.toHaveBeenCalled();
});
});
});