Cleanup/code cleanup 2026 03 (#45)
* chore: cleanup of unused exports and stuff * fix: media and languages was broken for english media * fix: embedding model load was broken on standalone --------- Co-authored-by: hugo <hugoms@me.com>
This commit is contained in:
@@ -138,6 +138,7 @@ function createMockPipeline(): EmbeddingPipeline {
|
||||
function makeEngine(tmpDir: string): EmbeddingEngine {
|
||||
return new EmbeddingEngine({
|
||||
getIndexPath: (projectId: string) => path.join(tmpDir, `${projectId}.usearch`),
|
||||
modelCacheDir: path.join(tmpDir, 'model-cache'),
|
||||
createPipeline: async () => createMockPipeline(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -339,8 +339,13 @@ vi.mock('fs/promises', () => ({
|
||||
}));
|
||||
|
||||
let mockOfflineMode = false;
|
||||
const mockAutoTranslatePost = vi.fn().mockResolvedValue({ success: true });
|
||||
const mockAutoTranslateMediaMetadata = vi.fn().mockResolvedValue({ success: true });
|
||||
|
||||
vi.mock('../../src/main/ipc/chatHandlers', () => ({
|
||||
isOfflineModeActive: vi.fn(() => mockOfflineMode),
|
||||
autoTranslatePost: (...args: any[]) => mockAutoTranslatePost(...args),
|
||||
autoTranslateMediaMetadata: (...args: any[]) => mockAutoTranslateMediaMetadata(...args),
|
||||
}));
|
||||
|
||||
// Helper to invoke a registered handler
|
||||
@@ -3022,6 +3027,45 @@ describe('IPC Handlers', () => {
|
||||
expect(result).toEqual({ taskStarted: true });
|
||||
expect(onProgress).toHaveBeenCalledWith(100, 'All translations are up to date');
|
||||
});
|
||||
|
||||
it('should use media canonical language, not post language, to determine target languages', async () => {
|
||||
// Scenario: blog has en + de. An English media item is linked to a German post.
|
||||
// The media is missing a German translation, NOT an English one.
|
||||
const mockProject = createMockProject({ id: 'test-project', dataPath: '/mock/data' });
|
||||
mockProjectEngine.getActiveProject.mockResolvedValue(mockProject);
|
||||
mockProjectEngine.getDataDir.mockReturnValue('/mock/data/dir');
|
||||
mockMetaEngine.getProjectMetadata.mockResolvedValue({
|
||||
mainLanguage: 'de',
|
||||
blogLanguages: ['de', 'en'],
|
||||
});
|
||||
|
||||
const post1 = createMockPost({ id: 'post-1', title: 'German Post', language: 'de', status: 'published' });
|
||||
// No posts missing post translations
|
||||
mockPostEngine.getPostsFiltered.mockImplementation(async (filter: any) => {
|
||||
if (filter.missingTranslationLanguage) return [];
|
||||
return [post1]; // all published
|
||||
});
|
||||
|
||||
// Post links to an English-language media item
|
||||
mockPostMediaEngine.getLinkedMediaForPost.mockResolvedValue([{ mediaId: 'media-en-1', sortOrder: 0 }]);
|
||||
mockMediaEngine.getMedia.mockResolvedValue(createMockMedia({ id: 'media-en-1', language: 'en' }));
|
||||
mockMediaEngine.getMediaTranslations.mockResolvedValue([]); // no translations yet
|
||||
|
||||
const onProgress = vi.fn();
|
||||
let taskDone: Promise<void> | undefined;
|
||||
mockTaskManager.runTask.mockImplementation((task: any) => {
|
||||
taskDone = task.execute(onProgress);
|
||||
return taskDone;
|
||||
});
|
||||
|
||||
const result = await invokeHandler('blog:fillMissingTranslations');
|
||||
await taskDone;
|
||||
|
||||
expect(result).toEqual({ taskStarted: true });
|
||||
// Should translate to German (the missing language), NOT to English (the media's own language)
|
||||
expect(mockAutoTranslateMediaMetadata).toHaveBeenCalledTimes(1);
|
||||
expect(mockAutoTranslateMediaMetadata).toHaveBeenCalledWith('media-en-1', 'de');
|
||||
});
|
||||
});
|
||||
|
||||
describe('blog:applyValidation', () => {
|
||||
|
||||
@@ -11,15 +11,6 @@ function read(relativePath: string): string {
|
||||
describe('Phase 1 i18n hardcoded literals', () => {
|
||||
it('does not keep known hardcoded user-facing literals in renderer components', () => {
|
||||
const checks: Array<{ file: string; literals: string[] }> = [
|
||||
{
|
||||
file: 'src/renderer/components/PostSearchModal/PostSearchModal.tsx',
|
||||
literals: [
|
||||
'Search posts by title or content...',
|
||||
'Searching...',
|
||||
'Type at least 2 characters to search',
|
||||
'Use ↑↓ to navigate, Enter to select, Esc to close',
|
||||
],
|
||||
},
|
||||
{
|
||||
file: 'src/renderer/components/StatusBar/StatusBar.tsx',
|
||||
literals: ['<span>{totalPosts} posts</span>', '<span>{media.length} media</span>', 'Theme: {activeTheme}', 'aria-label="UI language"'],
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { clearMacros, getMacro, registerMacro } from '../../../src/renderer/macros/registry';
|
||||
import type { MacroParams, MacroRenderContext } from '../../../src/renderer/macros/types';
|
||||
import photoArchiveMacro from '../../../src/renderer/macros/definitions/photo_archive';
|
||||
import { photoArchiveMacro } from '../../../src/renderer/macros/definitions/photo_archive';
|
||||
|
||||
describe('photo_archive macro', () => {
|
||||
beforeEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user