Makelore 2.0 initial clean snapshot
This commit is contained in:
75
tests/unit/branding-copy.test.ts
Normal file
75
tests/unit/branding-copy.test.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { readdirSync, readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const displayCopyFiles = [
|
||||
'index.html',
|
||||
'package.json',
|
||||
'electron-builder.yml',
|
||||
'electron/main/launch-at-startup.ts',
|
||||
'electron/main/menu.ts',
|
||||
'electron/main/tray.ts',
|
||||
'src/App.tsx',
|
||||
'src/pages/Chat/OpencodeChatPanel.tsx',
|
||||
'src/pages/Login/index.tsx',
|
||||
'src/pages/Models/OpencodeRuntimePanel.tsx',
|
||||
'src/pages/NiTu/index.tsx',
|
||||
];
|
||||
|
||||
function collectStrings(value: unknown): string[] {
|
||||
if (typeof value === 'string') return [value];
|
||||
if (Array.isArray(value)) return value.flatMap(collectStrings);
|
||||
if (value && typeof value === 'object') {
|
||||
return Object.values(value as Record<string, unknown>).flatMap(collectStrings);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function localeJsonFiles(dir: string): string[] {
|
||||
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
||||
const path = join(dir, entry.name);
|
||||
if (entry.isDirectory()) return localeJsonFiles(path);
|
||||
return entry.isFile() && entry.name.endsWith('.json') ? [path] : [];
|
||||
});
|
||||
}
|
||||
|
||||
function isNonDisplayOldBrandLine(line: string): boolean {
|
||||
const trimmed = line.trim();
|
||||
return trimmed.startsWith('//')
|
||||
|| trimmed.startsWith('*');
|
||||
}
|
||||
|
||||
describe('GUI branding copy', () => {
|
||||
it('does not expose the old NianCode brand in app display copy', () => {
|
||||
const offenders = [
|
||||
...localeJsonFiles(join(process.cwd(), 'src', 'i18n', 'locales')).flatMap((file) => {
|
||||
const json = JSON.parse(readFileSync(file, 'utf8')) as unknown;
|
||||
return collectStrings(json)
|
||||
.filter((value) => /\bNianCode\b/.test(value))
|
||||
.map((value) => `${file}: ${value}`);
|
||||
}),
|
||||
...displayCopyFiles.flatMap((file) => {
|
||||
const path = join(process.cwd(), file);
|
||||
return readFileSync(path, 'utf8')
|
||||
.split(/\r?\n/)
|
||||
.flatMap((line, index) => /\bNianCode\b/.test(line) && !isNonDisplayOldBrandLine(line)
|
||||
? [`${path}:${index + 1}: ${line.trim()}`]
|
||||
: []);
|
||||
}),
|
||||
];
|
||||
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
|
||||
it('does not expose opencode in localized UI strings', () => {
|
||||
const localeDir = join(process.cwd(), 'src', 'i18n', 'locales');
|
||||
const offenders = localeJsonFiles(localeDir).flatMap((file) => {
|
||||
const json = JSON.parse(readFileSync(file, 'utf8')) as unknown;
|
||||
return collectStrings(json)
|
||||
.filter((value) => /opencode/i.test(value))
|
||||
.map((value) => `${file}: ${value}`);
|
||||
});
|
||||
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user