Add session handling, waitFor gating, and the Tradeify purchase flow
Step vocabulary gains `waitFor`: block until a selector exists, then continue. Nothing is clicked or typed — it is a gate for conditions something outside the run has to satisfy. Unlike every other step it carries no signed-out guard, because the things worth gating on often sit on the login page, where that guard would abort the run at exactly the wrong moment. Honours the dashboard's Stop button, since a two-minute gate that ignored it would be worse than no gate. Session handling. A run that lands on the login page must not continue: once redirected, every selector resolves against a login form, so a click aimed at "Add Account" hits whatever that form renders in the same place. Runs now detect the redirect and stop before sending any input, with a distinct SignedOutError rather than a generic failure. Two ways out of that state, in order: a firm's `authSteps` run and the failed step is retried, or — when none are defined — the run pauses for signedOutWaitSeconds so a human can sign in, then resumes. Auth steps are verified rather than trusted: they can all "succeed" while the site still rejects the sign-in, so the session is re-checked before the retry, and the run stops with "auth steps ran but the session is still signed out" if it did not take. That check polls for up to 20s instead of reading once. Submitting a login form starts a network round trip and then a redirect, so the tab still shows the login URL for a second or two afterwards; checking immediately failed a sign-in that was merely in flight, killing run #15 nine seconds after it had actually worked. Third instance of the same mistake in this system — reading page state immediately after an action that triggers async navigation. The runner reports its version in the heartbeat and the dashboard blocks the buttons when it is behind. A running Python process does not reload when the source changes, so a stale runner fails on step types it predates; that cost a debugging round when a navigate step reached a runner that had never heard of one. lib/automations.ts carries the Tradeify buy-accounts flow: navigate to the dashboard, open Add Account, pick the account type and size, enter the account name, and work through the challenge widget before submitting. Selectors are authored by hand against the live page. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
b748f95372
commit
36c5b69550
@@ -1,5 +1,5 @@
|
||||
import { claimRun, getSetting } from '@/lib/db';
|
||||
import { findAutomation, resolveSteps } from '@/lib/automations';
|
||||
import { findAutomation, resolveSteps, resolveAuthSteps } from '@/lib/automations';
|
||||
import { corsJson, corsPreflight } from '../../cors';
|
||||
|
||||
/** The Python runner polls this. Returns the run plus the steps to execute, so
|
||||
@@ -24,6 +24,7 @@ export async function POST() {
|
||||
firm: found.firm.label,
|
||||
label: found.automation.label,
|
||||
steps: resolveSteps(found.firm, found.automation),
|
||||
authSteps: resolveAuthSteps(found.firm),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
+1
-10
@@ -301,16 +301,7 @@ export default function AutoBuyer() {
|
||||
? 'Runner offline'
|
||||
: runner.busy ? 'Runner busy' : 'Runner online'}
|
||||
</span>
|
||||
{runner?.online && runner.stale && (
|
||||
<div className="mb-3 rounded-lg border border-red-200 bg-red-50 px-4 py-2.5 text-xs text-red-800">
|
||||
The runner is out of date (reporting v{runner.version ?? 'unknown'}, this
|
||||
dashboard needs v{runner.expectedVersion}). It will fail on step types it
|
||||
predates. Restart it: stop with Ctrl-C and run{' '}
|
||||
<code className="font-mono">python clicker/runner.py</code> again.
|
||||
</div>
|
||||
)}
|
||||
|
||||
{runner?.online && runner.dryRun && (
|
||||
{runner?.online && runner.dryRun && (
|
||||
<span className="ml-1 px-1.5 py-0.5 rounded bg-amber-100 text-amber-700 font-medium">
|
||||
dry run
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user