{ "name": "verify-file-watch", "settings": { "storagePermissions": { "collections": { "watch_cursors": "read-write" } } }, "nodes": [ {"id": "n1", "name": "Trigger", "type": "click-trigger", "position": {"x": 0, "y": 0}, "config": {}}, {"id": "setup", "name": "Setup", "type": "code", "position": {"x": 0, "y": 100}, "config": {"code": "const dir = '/tmp/sb-file-watch-test';\nconst listing = smartbotic.fs.readdir(dir);\nif (listing.success) {\n for (const e of listing.entries) { smartbotic.fs.unlink(e.path); }\n}\nsmartbotic.fs.mkdir(dir);\nsmartbotic.fs.writeFile(dir + '/existing.txt', smartbotic.utils.base64Encode('old'));\nsmartbotic.storage.delete('watch_cursors', context.workflowId + ':first');\nsmartbotic.storage.delete('watch_cursors', context.workflowId + ':second');\nconst before = smartbotic.fs.readdir(dir);\nconst seen = {};\nfor (const e of before.entries) { seen[e.name] = e.modifiedAt + ':' + e.size; }\nsmartbotic.storage.insert('watch_cursors', { seen: seen, updatedAt: Date.now(), directory: dir }, context.workflowId + ':second');\nconst st = smartbotic.fs.stat(dir + '/existing.txt');\nconst statMtimeSane = st.mtime > 1600000000000 && st.mtime < Date.now() + 60000;\nreturn { dir: dir, statMtimeSane: statMtimeSane };"}}, {"id": "first", "name": "First Run", "type": "file-watch", "position": {"x": 0, "y": 200}, "config": {"directory": "/tmp/sb-file-watch-test", "emitOnFirstRun": false}}, {"id": "add", "name": "Add A File", "type": "code", "position": {"x": 0, "y": 300}, "config": {"code": "smartbotic.fs.writeFile('/tmp/sb-file-watch-test/fresh.txt', smartbotic.utils.base64Encode('new'));\nreturn { added: 'fresh.txt' };"}}, {"id": "second", "name": "Second Run", "type": "file-watch", "position": {"x": 0, "y": 400}, "config": {"directory": "/tmp/sb-file-watch-test", "emitOnFirstRun": false}} ], "connections": [ {"sourceNodeId": "n1", "sourceOutput": "main", "targetNodeId": "setup", "targetInput": "data"}, {"sourceNodeId": "setup", "sourceOutput": "main", "targetNodeId": "first", "targetInput": "data"}, {"sourceNodeId": "first", "sourceOutput": "main", "targetNodeId": "add", "targetInput": "data"}, {"sourceNodeId": "add", "sourceOutput": "main", "targetNodeId": "second", "targetInput": "data"} ], "expect": { "setup": {"status": "completed", "output": {"result": {"statMtimeSane": true}}}, "first": {"status": "completed", "output": {"count": 0, "isFirstRun": true}}, "second": {"status": "completed", "output": {"count": 1, "isFirstRun": false, "files": [{"name": "fresh.txt"}]}} } }