fix: surface Battle.net's own reason when it refuses a game folder (#1661)

* fix: surface Battle.net's own reason when it refuses a game folder

watch() treated any "error": <nonzero> in the Agent's status JSON as fatal. The
install form carries nested errors of its own - language.error 704 when the
requested locale is not offered, game_dir.error when the folder is unusable - so
the loop ended before the install started and agent_job reported "exit 0".

A form with a non-zero game_dir.error now fails with that reason (800 reads as
"the game folder already holds a game"); otherwise the wait continues, and only
a top-level error still ends the loop.

* fix: move the form-failure regression out of the crowded test block

Keep the driver behavior unchanged; this only relocates the new regression case so
the branch can be merged with current main without a test-file conflict.

* fix: sync the agent-error change onto current main

Bring the two touched files up to the current main versions and apply the form
failure handling on top. This keeps the PR limited to the driver and its test
without pulling workflow files into the branch.

---------

Co-authored-by: visail <visail@users.noreply.github.com>
Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-15 10:51:05 -05:00
1 parent 605f85b4b9
commit 91a217879f
2 files changed
+22 -1

No files matched your search

@@ -122,6 +122,17 @@ function field(text, name) {
return m ? m[1] : "";
}
function object(text, name) {
var start = new RegExp('"' + name + '"\\s*:\\s*\\{').exec(text);
if (!start) return "";
var from = start.index + start[0].length, depth = 0;
for (var i = from - 1; i < text.length; i++) {
if (text.charAt(i) == "{") depth++;
else if (text.charAt(i) == "}" && --depth == 0) return text.substring(from, i);
}
return "";
}
function job(text) {
if (/"error"\s*:\s*[1-9]/.test(text)) return false;
var bare = text.replace(/"extended_status"\s*:\s*\{[^}]*\}/, "");
@@ -147,7 +158,10 @@ function watch(path) {
for (var i = 0; ; i++) {
var s = call("GET", path);
save(".json", s);
if (/"error"\s*:\s*[1-9]/.test(s)) break;
if (/"form"\s*:\s*\{/.test(s)) {
var refused = /"error"\s*:\s*(\d+)/.exec(object(s, "game_dir"));
if (refused && +refused[1] != 0) throw new Error(+refused[1] == 800 ? "the game folder already holds a game" : "Battle.net refused the game folder (error " + refused[1] + ")");
} else if (/"error"\s*:\s*[1-9]/.test(s)) break;
var state = /"state"\s*:\s*(\d+)/.exec(s.replace(/"extended_status"\s*:\s*\{[^}]*\}/, "")), complete = /"download_complete"\s*:\s*true/.test(s);
state = state ? +state[1] : 0;
if (state == 1000 || state == 1003 || job(s) && !complete) started = true;
+7
View File
@@ -1709,5 +1709,12 @@ class AgentJobTest(Harness):
self.assertEqual(calls, [("install", "gryphon", "gryphon", "/g/Rumble", "enUS", "USA", "US"), ("update", "wow_classic")])
class BattleNetFormTest(Temp):
def test_the_driver_waits_on_the_install_form_and_names_a_folder_that_is_taken(self):
script = BNET["AGENT_SCRIPT"]
self.assertIn(r'if (/"form"\s*:\s*\{/.test(s)) {', script)
self.assertIn("the game folder already holds a game", script)
if __name__ == "__main__":
unittest.main()