refactor: reuse shared filename extraction

This commit is contained in:
Dariusz L
2026-08-08 22:31:35 +02:00
parent eb2e17f75b
commit e0d5dff0a0
2 changed files with 22 additions and 3 deletions
@@ -5,6 +5,7 @@ import assert from 'node:assert/strict';
import { Window } from 'happy-dom';
import {
html,
getFilenameFromPath,
normalizePathIdentity,
pollBackgroundTask,
safeStorage,
@@ -63,6 +64,7 @@ void normalizeSha256;
void pollBackgroundTask;
void buildLoadedModelTokenStrings;
void groupLoadedModelsByCategory;
void getFilenameFromPath;
const projectRoot = path.resolve(import.meta.dirname, '..');
const getSvgIcon = () => '';
@@ -3617,6 +3619,23 @@ test('model info hash readers preserve field precedence and casing', () => {
assert.equal(getSourceModelDisplayHash({}), '');
});
test('source model comparable filenames preserve basename and trailing separator behavior', () => {
const getSourceModelComparableFilename = eval(
`(${extractMethod(modelInfoMethodsSource, 'getSourceModelComparableFilename')})`
);
assert.equal(
getSourceModelComparableFilename('Models\\Checkpoints\\Model.SAFE TENSORS'),
'model.safe tensors',
);
assert.equal(
getSourceModelComparableFilename('models/checkpoints/model.safetensors/'),
'',
);
assert.equal(getSourceModelComparableFilename(' model.safetensors '), 'model.safetensors');
assert.equal(getSourceModelComparableFilename(''), '');
});
test('model info metadata source labels match the shared source label contract', () => {
const getInfoMetadataSourceLabel = eval(`(${extractMethod(modelInfoMethodsSource, 'getInfoMetadataSourceLabel')})`);
const dialog = {
+3 -3
View File
@@ -2961,9 +2961,9 @@ export const modelInfoMethods = {
},
getSourceModelComparableFilename(value = '') {
return String(value || '')
.split(/[\\/]+/)
.pop()
const normalizedValue = String(value || '');
if (/[\\/]+$/.test(normalizedValue)) return '';
return getFilenameFromPath(normalizedValue)
.trim()
.toLowerCase();
},