muse-chat-api.py upload: verify via Remove-attachment button

This commit is contained in:
operator-main
2026-10-04 01:28:47 +00:00
parent c759ca353f
commit d3c19425e8
+12 -12
View File
@@ -341,26 +341,26 @@ def cmd_upload(ws, filepath, message=None, dry_run=False):
cdp_call(ws, "DOM.setFileInputFiles", cdp_call(ws, "DOM.setFileInputFiles",
{"nodeId": node_id, "files": [os.path.abspath(filepath)]}) {"nodeId": node_id, "files": [os.path.abspath(filepath)]})
time.sleep(2) time.sleep(2)
# Read-back: the attachment chip must appear. Match on the # Read-back: the attachment must be staged. React removes the
# element's OWN text: React swaps the file input after change, so # file input after change, so input.files is unreliable — the
# input.files is unreliable, and innerText on ancestors over-matches. # composer's own signal is the "Remove attachment" button plus the
# chip text beside it.
base = os.path.basename(filepath) base = os.path.basename(filepath)
preview = ev1(ws, """(() => { preview = ev1(ws, """(() => {
const needle = %s; const btns = [...document.querySelectorAll('button')].filter(b =>
const own = e => [...e.childNodes].filter(n => n.nodeType === 3) (b.getAttribute('aria-label') || '') === 'Remove attachment');
.map(n => n.nodeValue).join(''); if (!btns.length) return JSON.stringify([]);
const hits = [...document.querySelectorAll('*')] const chip = btns[0].closest('div');
.filter(e => own(e).includes(needle)) const text = chip ? chip.innerText.slice(0, 120) : '';
.map(e => e.tagName + ': ' + own(e).slice(0, 80)); return JSON.stringify([{button: true, chip: text}]);
return JSON.stringify(hits.slice(0, 5)); })()""")
})()""" % json.dumps(base))
print("preview: %s" % preview) print("preview: %s" % preview)
try: try:
hits = json.loads(preview) if preview else [] hits = json.loads(preview) if preview else []
except Exception: except Exception:
hits = [] hits = []
if not hits: if not hits:
print("ERROR: attachment preview not visible after attach", print("ERROR: attachment not staged (no Remove-attachment button)",
file=sys.stderr) file=sys.stderr)
sys.exit(1) sys.exit(1)
if dry_run: if dry_run: