Files
makelore/tests/unit/branding-copy.test.ts
inman 80e8386fa6
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled
feat: update Makelore modules and conversations
2026-07-31 10:08:41 +08:00

76 lines
2.5 KiB
TypeScript

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/Makelore/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([]);
});
});