* fix(lora): detect LoraManager in ComfyUI's extra custom_nodes folders Auto-detection looked only in ComfyUI's main custom_nodes folder (#144). It now also searches every custom_nodes folder ComfyUI registers through folder_paths, main folder first, skipping folders that cannot be read. * fix(lora): stage imports before replacing the collection (#221) The LoRA import deleted the whole lora-manager category first and then saved each record in its own transaction, so a discovery, download or database failure left the previous collection gone or partial. The import now runs in three stages: discover and fingerprint the metadata files, stage every record (CivitAI downloads go into the image cache first, counted), then replace the category in one BEGIN IMMEDIATE transaction (replace_category_prompts). Any failure leaves the previous prompts, tags and image links exactly as they were. Prompts a saved pair uses block the replacement; an empty replacement of a non-empty collection needs a reviewed import. POST /prompt_manager/lora/import/preview reviews an import without writing or requesting anything; POST /lora/import/apply {token} runs it as the Activity job "LoRA reference import" (records admission, cancellable while it downloads, the safety backup policy before the replace, refused with plan-changed when the files changed since the review). The legacy POST /lora/scan runs the same stages with its SSE event shape. * feat(lora): the LoRA save takes the settings revision POST /prompt_manager/lora/enable accepts the optional expected_revision that GET /settings returns, so the System Save row refuses to write over a config.json changed elsewhere (settings-changed, nothing written). The legacy page sends none and still merges into what is on disk. * feat(system): configure ComfyUI and LoRA integrations natively System › Integrations replaces its hand-off with the concept's two surfaces. ComfyUI: only the send destination and renderer the bridge supports can be chosen; the other options and Return to canvas are disabled with the reason, and Host compatibility shows the renderer the open ComfyUI windows report (each bridge destination now carries renderer: classic or nodes2) (D106). LoRA & resources: detection, the enabled setting and the loaded trigger words read as separate facts, the read-only LoraManager path row follows the toggle (D106), and the CivitAI key is never filled in: typing drafts a new key, blank keeps the saved one and Clear saved key drafts its removal (D114). They save through the one Save row (/lora/enable with the settings revision). LoRA reference data → Review import shows the server's read-only review (replacement, what saved pairs block, downloads, backup box) and Start runs the LoRA reference import Activity job (D107), with its own Activity descriptor and Review again into Integrations when the files or pairs overtook it. * test(system): compare Integrations with the concept system-integrations-concept.spec compares System › Integrations (both themes, 1600 and 390 wide) with the concept, mapping only D106 and D114, and the LoRA import review with the concept's record-changing review, mapping D107; each comparison catches a removed row, a renamed label or option, a re-enabled unsupported option and a swapped token. On the real ComfyUI host, each bridge destination reports the renderer its window draws nodes with, before and after switching it, and System › Integrations shows it. * test(coverage): record the Integrations frontend floors coverage:update after the full frontend run: system-integrations.mjs at its measured floor, and the raised maintenance review, job view and maintenance floors. * test(system): wait for the renderer line before clicking Integrations rows CI Firefox (390 wide) clicked the LoraManager toggle while the renderer check's line above it changed text and moved the rows, so the click did not reach the switch. The specs now wait for that line to settle (a visible state) before interacting. * fix(lora): recheck the files before the replace and stop an abandoned scan Review fixes for the staged LoRA import (#221): - The metadata files are listed and fingerprinted again right before the replace transaction, so a file changed, removed or added while the downloads ran aborts the import with nothing deleted (System job: plan-changed, Review again; legacy scan: an error frame in its own words). The tests now change real files behind a held download. - A legacy scan whose page closes stops staging before its next LoRA and keeps its records hold until staging has stopped; CivitAI images are written to a temp file beside the cache entry and moved in place, so a half-written image is never seen as cached. - Start refuses with plan-changed when the integration was turned off or moved to another install since the review. - A failed job keeps the skipped count and the names of the LoRAs that could not be prepared. - The replace binds the category instead of one parameter per prompt (SQLite's variable limit), /lora/status says whether a detected install can be used, and the legacy scan logs expected refusals as warnings. * fix(system): partial saves, key focus and readable selects in Integrations A save that writes the LoRA part but not the settings part now keeps the saved part, adopts the new revision and highlights only what failed, so the next save needs no conflict. The CivitAI key status is a persistent live region, Clear saved key returns focus to the key field, and the key draft is dropped when the section is left. The send-destination and renderer selects keep their width on narrow screens. A detected LoraManager outside custom_nodes says it cannot be enabled. * fix(lora): keep the save outcome, honour the umask and sweep stale downloads Leaving Integrations drops the CivitAI key draft only when a key was typed, so the last Save's outcome survives and Sources still marks a refused source. The key status line is rewritten only when it changes. Cached CivitAI images are opened like a plain save, so they keep the umask's mode, and each import removes .pm-*.part files older than an hour from the image cache. A legacy scan stopped because its page left ends cancelled in Activity, and staging is awaited to the end even if the handler is cancelled again. * fix(lora): the import review takes a lease beside a restore The LoRA import review reads the library, so like the maintenance and restore previews it now runs under a request lease: it is refused with 409 busy while a restore runs, and a restore waits for it before it switches the file. Tests pin that a restore is refused while an import runs and that the review, the reviewed import and the admin page's scan are refused while a restore runs.
211 lines
14 KiB
JavaScript
211 lines
14 KiB
JavaScript
import {test,expect} from '../../tools/vendor/node_modules/@playwright/test/index.mjs';
|
||
import {installHostHooks} from './host-fixture.mjs';
|
||
|
||
const TYPES=['PromptManager','PromptManagerText','PromptManagerFocused','PromptManagerSplit','PromptManagerPair'];
|
||
installHostHooks(test,TYPES);
|
||
|
||
async function addNode(page,type,values={}) {
|
||
return page.evaluate(async({type,values})=>{
|
||
const {app}=await import('/scripts/app.js');
|
||
app.graph.clear();
|
||
const node=LiteGraph.createNode(type);app.graph.add(node);
|
||
node.setSize([type==='PromptManagerSplit'?1000:700,1050]);
|
||
app.canvas.ds.scale=.8;app.canvas.centerOnNode(node);
|
||
for(const [name,value]of Object.entries(values)) {
|
||
const widget=node.widgets.find(widget=>widget.name===name);
|
||
widget.value=value;if(widget.inputEl)widget.inputEl.value=value;
|
||
widget.callback?.(value,app.canvas,node);
|
||
}
|
||
return node.id;
|
||
},{type,values});
|
||
}
|
||
|
||
async function withClient(page,context,run) {
|
||
const clientPage=await context.newPage();const errors=[];
|
||
clientPage.on('pageerror',error=>errors.push(error.message));
|
||
try {
|
||
await clientPage.goto(new URL('/prompt_manager/workspace#/overview',page.url()).href,{waitUntil:'domcontentloaded'});
|
||
await clientPage.evaluate(async()=>{
|
||
const {createBridgeClient}=await import('/prompt_manager/js/shared/toolkit/prompt-bridge.js');
|
||
window.bridgeClient=createBridgeClient({origin:location.origin,namespace:'/'});
|
||
});
|
||
await run(clientPage);
|
||
expect(errors).toEqual([]);
|
||
} finally {
|
||
await clientPage.evaluate(()=>window.bridgeClient?.dispose()).catch(()=>{});
|
||
await clientPage.close();
|
||
}
|
||
}
|
||
|
||
async function destination(clientPage,id) {
|
||
const hosts=await clientPage.evaluate(()=>window.bridgeClient.discover({waitMs:200}));
|
||
const host=hosts.find(host=>host.targets.some(target=>String(target.id)===String(id)));
|
||
expect(host,'independently opened workspace discovers the real host').toBeDefined();
|
||
const target=host.targets.find(target=>String(target.id)===String(id));
|
||
return {hostId:host.hostId,target};
|
||
}
|
||
|
||
async function preview(clientPage,hostId,target,payload) {
|
||
return clientPage.evaluate(async({hostId,target,payload})=>{
|
||
window.bridgePreview=await window.bridgeClient.preview(hostId,target.id,payload);
|
||
return window.bridgePreview;
|
||
},{hostId,target,payload});
|
||
}
|
||
|
||
async function apply(clientPage,hostId) {
|
||
return clientPage.evaluate(hostId=>window.bridgeClient.apply(hostId,window.bridgePreview.ticket),hostId);
|
||
}
|
||
|
||
async function rejection(clientPage,action) {
|
||
return clientPage.evaluate(async action=>{
|
||
try {
|
||
if(action.kind==='preview')await window.bridgeClient.preview(action.hostId,action.targetId,action.payload);
|
||
else await window.bridgeClient.apply(action.hostId,window.bridgePreview.ticket);
|
||
return null;
|
||
} catch(error) {return String(error.message);}
|
||
},action);
|
||
}
|
||
|
||
async function snapshot(page,id) {
|
||
return page.evaluate(async id=>{
|
||
const {app}=await import('/scripts/app.js');const node=app.graph.getNodeById(id);
|
||
const serialized=node.serialize();
|
||
return {
|
||
widgets:Object.fromEntries(node.widgets.map(widget=>[widget.name,widget.value])),
|
||
inputs:Object.fromEntries(node.widgets.filter(widget=>widget.inputEl).map(widget=>[widget.name,widget.inputEl.value])),
|
||
serialized:Object.fromEntries(node.widgets.map((widget,index)=>[widget.name,serialized.widgets_values[index]])),
|
||
prompt:(await app.graphToPrompt()).output[String(id)].inputs,
|
||
};
|
||
},id);
|
||
}
|
||
|
||
async function connect(page,id,field) {
|
||
return page.evaluate(async({id,field})=>{
|
||
const {app}=await import('/scripts/app.js');const {convertToInput}=await import('/extensions/core/widgetInputs.js');
|
||
const node=app.graph.getNodeById(id);const widget=node.widgets.find(widget=>widget.name===field);
|
||
if(!node.inputs.some(input=>input.name===field))convertToInput(node,widget);
|
||
const source=LiteGraph.createNode('PrimitiveString');app.graph.add(source);
|
||
source.widgets.find(widget=>widget.name==='value').value=`Upstream ${field}`;
|
||
source.connect(0,node,node.inputs.findIndex(input=>input.name===field));
|
||
return [String(source.id),0];
|
||
},{id,field});
|
||
}
|
||
|
||
test('independent workspace discovers all Prompt Manager destinations and writes real widgets without executing or loading workflows',async({page,context})=>{
|
||
await withClient(page,context,async clientPage=>{
|
||
for(const type of TYPES) {
|
||
const id=await addNode(page,type,{text:'Before bridge'});
|
||
const draft=`Visible draft ${type}`;
|
||
await page.locator('textarea:visible').first().fill(draft);
|
||
const {hostId,target}=await destination(clientPage,id);
|
||
expect(target.type).toBe(type);expect(target.label).toBeTruthy();expect(target.roles).toContain('positive');
|
||
expect(target.roles.includes('negative')).toBe(type==='PromptManagerPair');
|
||
await page.evaluate(async()=>{
|
||
const {app}=await import('/scripts/app.js');window.bridgeSideEffects={queue:0,load:0};
|
||
for(const [method,key]of [['queuePrompt','queue'],['loadGraphData','load']]) {
|
||
const original=app[method];app[method]=function(...args){window.bridgeSideEffects[key]++;return original.apply(this,args);};
|
||
}
|
||
});
|
||
const text=`Bridge sent to ${type}`;const proposed=await preview(clientPage,hostId,target,{positive:text});
|
||
expect(proposed.ticket).toBeTruthy();expect(proposed.fields).toContainEqual({role:'positive',before:draft,after:text});
|
||
expect((await snapshot(page,id)).widgets.text).toBe(draft);
|
||
expect(await apply(clientPage,hostId)).toMatchObject({targetId:target.id,values:{positive:text}});
|
||
await expect.poll(()=>page.locator('textarea:visible').evaluateAll(inputs=>inputs.map(input=>input.value))).toContain(text);
|
||
const state=await snapshot(page,id);
|
||
for(const name of ['widgets','inputs','serialized','prompt'])expect(state[name].text).toBe(text);
|
||
expect(await page.evaluate(()=>window.bridgeSideEffects)).toEqual({queue:0,load:0});
|
||
}
|
||
});
|
||
});
|
||
|
||
test('pair sends preserve omitted negatives, accept an empty negative and synchronize visible editors and composition',async({page,context})=>{
|
||
const id=await addNode(page,'PromptManagerPair',{text:'Old positive',negative_text:'Keep negative',prepend_text:'LoRA trigger',append_text:'fine detail'});
|
||
await withClient(page,context,async clientPage=>{
|
||
const {hostId,target}=await destination(clientPage,id);
|
||
const proposed=await preview(clientPage,hostId,target,{positive:'New positive'});
|
||
expect(proposed.composition).toMatchObject({prepend:'LoRA trigger',append:'fine detail',prependConnected:false,appendConnected:false,before:'LoRA trigger Old positive fine detail',after:'LoRA trigger New positive fine detail'});
|
||
await apply(clientPage,hostId);
|
||
expect((await snapshot(page,id)).widgets).toMatchObject({text:'New positive',negative_text:'Keep negative',prepend_text:'LoRA trigger',append_text:'fine detail'});
|
||
const root=page.locator('.pm-pair');
|
||
await expect(root.getByRole('textbox',{name:'Positive prompt',exact:true})).toHaveValue('New positive');
|
||
await expect(root.getByRole('textbox',{name:'Negative prompt',exact:true})).toHaveValue('Keep negative');
|
||
await root.getByText('Composed text preview',{exact:true}).click();
|
||
await expect(root.locator('[data-composed-preview]')).toHaveText('LoRA trigger New positive fine detail');
|
||
await preview(clientPage,hostId,target,{positive:'Paired positive',negative:''});
|
||
await apply(clientPage,hostId);
|
||
await expect(root.getByRole('textbox',{name:'Negative prompt',exact:true})).toHaveValue('');
|
||
const state=await snapshot(page,id);
|
||
for(const name of ['widgets','inputs','serialized','prompt'])expect(state[name]).toMatchObject({text:'Paired positive',negative_text:''});
|
||
});
|
||
});
|
||
|
||
test('connected requested fields reject atomically while connected composition remains linked',async({page,context})=>{
|
||
const id=await addNode(page,'PromptManagerPair',{text:'Keep positive',negative_text:'Keep negative',prepend_text:'Local prepend'});
|
||
const negativeLink=await connect(page,id,'negative_text');const prependLink=await connect(page,id,'prepend_text');
|
||
await withClient(page,context,async clientPage=>{
|
||
const {hostId,target}=await destination(clientPage,id);
|
||
expect(await rejection(clientPage,{kind:'preview',hostId,targetId:target.id,payload:{positive:'Must not apply',negative:'Blocked'}})).toMatch(/connected/i);
|
||
expect((await snapshot(page,id)).widgets).toMatchObject({text:'Keep positive',negative_text:'Keep negative'});
|
||
const proposed=await preview(clientPage,hostId,target,{positive:'Allowed positive'});
|
||
expect(proposed.composition.prependConnected).toBe(true);
|
||
await apply(clientPage,hostId);
|
||
expect((await snapshot(page,id)).prompt).toMatchObject({text:'Allowed positive',negative_text:negativeLink,prepend_text:prependLink});
|
||
const positiveLink=await connect(page,id,'text');
|
||
expect(await rejection(clientPage,{kind:'preview',hostId,targetId:target.id,payload:{positive:'Blocked positive'}})).toMatch(/connected/i);
|
||
expect((await snapshot(page,id)).prompt.text).toEqual(positiveLink);
|
||
});
|
||
});
|
||
|
||
test('user edits and workflow replacement invalidate acknowledged previews without overwriting changes',async({page,context})=>{
|
||
const id=await addNode(page,'PromptManagerFocused',{text:'Original draft'});
|
||
await withClient(page,context,async clientPage=>{
|
||
let {hostId,target}=await destination(clientPage,id);
|
||
await preview(clientPage,hostId,target,{positive:'Pending change'});
|
||
await page.locator('.pm-focused').getByRole('textbox',{name:'Main prompt',exact:true}).fill('User edited draft');
|
||
expect(await rejection(clientPage,{kind:'apply',hostId})).toMatch(/changed|stale|workflow/i);
|
||
expect((await snapshot(page,id)).widgets.text).toBe('User edited draft');
|
||
({hostId,target}=await destination(clientPage,id));
|
||
await preview(clientPage,hostId,target,{positive:'Pending after replacement'});
|
||
await page.evaluate(async()=>{const {app}=await import('/scripts/app.js');await app.loadGraphData(app.graph.serialize());});
|
||
expect(await rejection(clientPage,{kind:'apply',hostId})).toMatch(/changed|stale|workflow/i);
|
||
expect((await snapshot(page,id)).widgets.text).toBe('User edited draft');
|
||
});
|
||
});
|
||
|
||
test('bridge remains live through both renderer switches and workflow reload with synchronized Focused controls',async({page,context},testInfo)=>{
|
||
const id=await addNode(page,'PromptManagerFocused',{text:'Initial',prepend_text:'trigger',append_text:'detail'});
|
||
await withClient(page,context,async clientPage=>{
|
||
for(const renderer of [!testInfo.project.metadata.initialRenderer,testInfo.project.metadata.initialRenderer]) {
|
||
await page.evaluate(async renderer=>{const {app}=await import('/scripts/app.js');await app.ui.settings.setSettingValue('Comfy.VueNodes.Enabled',renderer);app.canvas.centerOnNode(app.graph._nodes[0]);},renderer);
|
||
await expect.poll(()=>page.evaluate(()=>LiteGraph.vueNodesMode)).toBe(renderer);
|
||
const {hostId,target}=await destination(clientPage,id);const text=`Renderer ${renderer}`;
|
||
await preview(clientPage,hostId,target,{positive:text});await apply(clientPage,hostId);
|
||
await expect(page.locator('.pm-focused').getByRole('textbox',{name:'Main prompt',exact:true})).toHaveValue(text);
|
||
await page.evaluate(async()=>{const {app}=await import('/scripts/app.js');await app.loadGraphData(app.graph.serialize());});
|
||
const state=await snapshot(page,id);
|
||
for(const name of ['widgets','inputs','serialized','prompt'])expect(state[name].text).toBe(text);
|
||
}
|
||
const {hostId,target}=await destination(clientPage,id);
|
||
await preview(clientPage,hostId,target,{positive:'After reload'});await apply(clientPage,hostId);
|
||
await expect(page.locator('.pm-focused').getByRole('textbox',{name:'Main prompt',exact:true})).toHaveValue('After reload');
|
||
});
|
||
});
|
||
|
||
test('each destination reports its window renderer, and System › Integrations shows it (S10)',async({page,context},testInfo)=>{
|
||
const initial=testInfo.project.metadata.initialRenderer;
|
||
const id=await addNode(page,'PromptManager',{text:'Renderer check'});
|
||
await withClient(page,context,async clientPage=>{
|
||
const name=renderer=>renderer?'Nodes 2.0':'Classic';
|
||
const status=clientPage.locator('#workspace-main #renderer-status');
|
||
expect((await destination(clientPage,id)).target.renderer).toBe(initial?'nodes2':'classic');
|
||
await clientPage.evaluate(()=>{location.hash='#/system/integrations';});
|
||
await expect(status).toHaveText(`Detected: ${name(initial)} (1 ComfyUI window).`);
|
||
// Switching the renderer in ComfyUI is what the next check reports; nothing is sent or queued.
|
||
await page.evaluate(async renderer=>{const {app}=await import('/scripts/app.js');await app.ui.settings.setSettingValue('Comfy.VueNodes.Enabled',renderer);await app.loadGraphData(app.graph.serialize());},!initial);
|
||
await expect.poll(()=>page.evaluate(()=>LiteGraph.vueNodesMode)).toBe(!initial);
|
||
expect((await destination(clientPage,id)).target.renderer).toBe(initial?'classic':'nodes2');
|
||
await clientPage.reload();
|
||
await expect(status).toHaveText(`Detected: ${name(!initial)} (1 ComfyUI window).`);
|
||
});
|
||
});
|