refactor: reuse shared filename extraction
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user