Files
aigen/tests/image-v2-moss.test.mjs
TowstyandCursor 8602d6ed2e Let MOSS use the same LoRA picker and chain those adapters onto its graph.
The picker was hidden and the API cleared every stack, so a selected MOSS job could not carry a LoRA.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-22 20:28:25 -05:00

99 lines
4.7 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync, writeFileSync, mkdirSync, rmSync } from 'node:fs'
import { join } from 'node:path'
import { tmpdir } from 'node:os'
import { pathToFileURL } from 'node:url'
import ts from 'typescript'
const stub = `
export function filterLoraStackForImageEngine(stack, engine) {
const items = Array.isArray(stack) ? stack : []
if (engine !== 'moss') return items
return items.filter(item => /(^|[\\/_.-])moss/i.test(String(item?.name || '')))
}
export function loraIdentityKey(name) {
return String(name || '').replace(/\\\\/g, '/').split('/').pop().toLowerCase()
}
export function makeLoraStackItem(name, model, clip) {
const value = String(name || '').trim()
return value ? { name: value, strengthModel: model, strengthClip: clip } : null
}
export function normalizeLoraStack(stack) {
return Array.isArray(stack) ? stack : []
}
`
const src = readFileSync(new URL('../utils/imageV2.ts', import.meta.url), 'utf8')
.replace(/from '~\/utils\/loras'/g, "from './loras-stub.mjs'")
const dir = join(tmpdir(), `image-v2-moss-${process.pid}`)
mkdirSync(dir, { recursive: true })
const out = join(dir, 'imageV2.mjs')
writeFileSync(join(dir, 'loras-stub.mjs'), stub)
writeFileSync(out, ts.transpileModule(src, {
compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext }
}).outputText)
const api = await import(pathToFileURL(out).href)
rmSync(dir, { recursive: true, force: true })
const graph = JSON.parse(readFileSync(new URL('../server/assets/moss_v2_generate.json', import.meta.url), 'utf8'))
test('MOSS is a generate engine with its own workflow and sampling defaults', () => {
assert.equal(api.parseImageV2Engine('moss'), 'moss')
assert.equal(api.parseImageV2Engine('moss-image'), 'moss')
assert.equal(api.parseImageV2Engine('nope'), 'flux')
assert.equal(api.imageV2WorkflowFile('generate', 'moss'), 'moss_v2_generate.json')
assert.equal(api.imageV2WorkflowFile('edit', 'flux'), 'klein_v2_edit.json')
assert.equal(api.imageV2WorkflowFile('generate', 'krea'), 'krea_v2_generate.json')
assert.deepEqual(api.imageV2SamplingDefaults('moss'), { steps: 25, cfg: 2.5 })
assert.deepEqual(api.imageV2SamplingDefaults('krea'), { steps: 8, cfg: 1 })
assert.deepEqual(api.imageV2SamplingDefaults('flux'), { steps: 24, cfg: 4 })
assert.deepEqual(api.defaultImageV2LoraStack({ engine: 'moss', mode: 'generate', xaigen: true }), [])
assert.deepEqual(api.mergeLegacyImageV2Loras([
{ name: 'klein.safetensors', strengthModel: 1, strengthClip: 1 },
{ name: 'moss-style.safetensors', strengthModel: 0.8, strengthClip: 0.8 }
], {
engine: 'moss',
mode: 'generate',
xaigen: true
}), [{ name: 'moss-style.safetensors', strengthModel: 0.8, strengthClip: 0.8 }])
})
test('MOSS look settings stay separate from Klein and Krea', () => {
const state = api.readImageV2LookState({
engine: 'moss',
flux: { steps: 30, cfg: 4.5, turbo: true },
krea: { steps: 8, cfg: 1 },
moss: { steps: 40, cfg: 3 }
})
assert.equal(state.engine, 'moss')
assert.deepEqual(state.looks.flux, { steps: 30, cfg: 4.5, turbo: true })
assert.deepEqual(state.looks.krea, { steps: 8, cfg: 1, turbo: false })
assert.deepEqual(state.looks.moss, { steps: 40, cfg: 3, turbo: false })
const fresh = api.readImageV2LookState(null)
assert.equal(fresh.engine, 'flux')
assert.deepEqual(fresh.looks.moss, { steps: 25, cfg: 2.5, turbo: false })
assert.equal(fresh.looks.krea.turbo, false)
})
test('MOSS generate graph uses the INT8 loaders, shift 5, and layer 22', () => {
assert.equal(graph['4'].class_type, 'UNETLoader')
assert.equal(graph['4'].inputs.unet_name, 'moss_image_sft_int8_convrot.safetensors')
assert.equal(graph['5'].class_type, 'CLIPLoader')
assert.equal(graph['5'].inputs.type, 'moss_image')
assert.equal(graph['5'].inputs.clip_name, 'qwen3.5_9b_w4a8_gptq.safetensors')
assert.equal(graph['5'].inputs.device, 'cpu')
assert.equal(graph['6'].inputs.vae_name, 'flux2-vae_small.safetensors')
assert.equal(graph['14'].class_type, 'EmptyFlux2LatentImage')
assert.equal(graph['40'].class_type, 'ModelSamplingAuraFlow')
assert.equal(graph['40'].inputs.shift, 5)
assert.equal(graph['41'].class_type, 'SkipLayerGuidanceDiTSimple')
assert.equal(graph['41'].inputs.single_layers, '22')
assert.equal(graph['41'].inputs.double_layers, '')
assert.equal(graph['15'].class_type, 'KSampler')
assert.equal(graph['15'].inputs.steps, 25)
assert.equal(graph['15'].inputs.cfg, 2.5)
assert.equal(graph['15'].inputs.scheduler, 'sgm_uniform')
assert.deepEqual(graph['15'].inputs.model, ['41', 0])
assert.equal(Object.values(graph).some(node => node.class_type === 'LoadImage' || node.class_type === 'LoraLoader' || node.class_type === 'Flux2Scheduler'), false)
})