fix(upload-automation): harden android and electron failure handling

Updated Android/Electron upload paths to fail deterministically and report consistent stage details, while removing unsafe stage casting and path/package mismatches. This keeps postimages automation behavior intact and makes failures easier to diagnose.
This commit is contained in:
plebeius
2026-02-20 16:52:35 +08:00
parent 15d608764b
commit b20aae8244
12 changed files with 58 additions and 21 deletions
@@ -111,8 +111,9 @@ public class FileUploaderPlugin extends Plugin {
tryProvidersSequentially(uri, providerOrder, call);
} catch (Exception e) {
Log.e(TAG, "Upload failed", e);
if (!call.getData().has("_resolved")) {
try {
call.reject("Upload failed: " + e.getMessage());
} catch (Exception ignored) {
}
}
})
@@ -73,6 +73,9 @@ public class MediaUploadAutomationRunner {
static final String STAGE_SUBMIT_CLICKED = "submit_clicked";
static final String STAGE_SUCCESS_SELECTOR_MATCHED = "success_selector_matched";
static final String STAGE_BLOCKED_DETECTED = "blocked_detected";
static final String STAGE_INPUT_NOT_FOUND = "input_not_found";
static final String STAGE_CHOOSER_NOT_TRIGGERED = "chooser_not_triggered";
static final String STAGE_UPLOAD_TIMED_OUT = "upload_timed_out";
private final Context context;
private final Uri fileUri;
@@ -202,7 +205,7 @@ public class MediaUploadAutomationRunner {
if (finished || fileChooserHandled) return;
long elapsed = elapsedMs();
if (elapsed >= MediaUploadRecipes.FILE_INPUT_TIMEOUT_MS) {
String stage = lastMatchedSelector != null ? "chooser_not_triggered" : "input_not_found";
String stage = lastMatchedSelector != null ? STAGE_CHOOSER_NOT_TRIGGERED : STAGE_INPUT_NOT_FOUND;
String error =
lastMatchedSelector != null
? "File chooser not triggered"
@@ -289,7 +292,7 @@ public class MediaUploadAutomationRunner {
false,
null,
"Upload timeout",
"upload_timed_out",
STAGE_UPLOAD_TIMED_OUT,
elapsed,
lastMatchedSelector));
return;
@@ -302,7 +305,7 @@ public class MediaUploadAutomationRunner {
false,
null,
"File chooser not triggered",
"chooser_not_triggered",
STAGE_CHOOSER_NOT_TRIGGERED,
elapsed,
lastMatchedSelector,
triggerAttemptCount));
@@ -113,12 +113,12 @@ public class MediaUploadRecipesTest {
@Test
public void failureClassification_inputNotFound_stageConstant() {
assertEquals("input_not_found", "input_not_found");
assertEquals(MediaUploadAutomationRunner.STAGE_INPUT_NOT_FOUND, "input_not_found");
}
@Test
public void failureClassification_chooserNotTriggered_stageConstant() {
assertEquals("chooser_not_triggered", "chooser_not_triggered");
assertEquals(MediaUploadAutomationRunner.STAGE_CHOOSER_NOT_TRIGGERED, "chooser_not_triggered");
}
@Test
@@ -128,7 +128,7 @@ public class MediaUploadRecipesTest {
@Test
public void failureClassification_uploadTimedOut_stageConstant() {
assertEquals("upload_timed_out", "upload_timed_out");
assertEquals(MediaUploadAutomationRunner.STAGE_UPLOAD_TIMED_OUT, "upload_timed_out");
}
@Test