#!/usr/bin/env python3 """Filesystem and argument safety checks; no real wallpaper service is modified.""" import importlib.util,json,subprocess,sys,tempfile,unittest from pathlib import Path ROOT=Path(__file__).resolve().parents[1] spec=importlib.util.spec_from_file_location('desktop',ROOT/'quickshell/helpers/desktop.py');desktop=importlib.util.module_from_spec(spec);spec.loader.exec_module(desktop) class Providers(unittest.TestCase): def test_scan_and_argument_boundaries(self): with tempfile.TemporaryDirectory(prefix='glassmxrph-provider-') as directory: root=Path(directory);image=root/"a ' quoted ; $(echo nope).png";image.write_bytes(b'fixture') (root/'ignore.txt').write_text('no image') result=desktop.scan({'directories':[directory,directory,str(root/'missing')]}) self.assertEqual(len(result['images']),1);self.assertIn('%20',result['images'][0]['url']);self.assertTrue(result['notice']) record=root/'record.json';helper=root/'record.py';helper.write_text('import json,pathlib,sys\npathlib.Path(sys.argv[1]).write_text(json.dumps(sys.argv[2:]))\n') result=desktop.apply({'backend':'custom','monitor':'TEST-1','path':str(image),'command':[sys.executable,str(helper),str(record),'{path}','{monitor}']}) self.assertEqual(json.loads(record.read_text()),[str(image),'TEST-1']);self.assertEqual(result['path'],str(image)) with self.assertRaises(ValueError):desktop.apply({'backend':'custom','monitor':'TEST-1','path':str(image),'command':['tool']}) with self.assertRaises(ValueError):desktop.apply({'backend':'custom','monitor':'bad; command','path':str(image),'command':[]}) def test_errors_are_json(self): p=subprocess.run([sys.executable,str(ROOT/'quickshell/helpers/desktop.py'),json.dumps({'action':'palette','executable':'/missing/matugen','path':'/missing'})],capture_output=True,text=True,check=True) self.assertFalse(json.loads(p.stdout)['ok']);self.assertEqual(p.stderr,'') if __name__=='__main__':unittest.main()