Skip to content

Commit f04c5d3

Browse files
kingpanther13claude
andcommitted
test(internal): sequence /api/settings/info responses for 5xx restart probe
The test_5xx flow hits the info endpoint three times — loadTools init, restartAddon's pre-POST baseline capture, and _probeAddonRestarted after the POST. The old single-response fixture returned the SAME instance_id every time, so the probe never saw the flip and looped until timeout, leaving reloads=0. Adds a `responses: [...]` shape to the harness fetch_map: each match on a URL pattern advances a per-pattern counter; the last entry sticks after exhaustion (matches "the addon came back online and stays online"). Test now provides baseline → baseline → flipped so the probe terminates with restarted=true and the reload fires. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ccf1a34 commit f04c5d3

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

tests/js/harness.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,19 @@ function readStdin() {
6363
}
6464

6565
function buildFetchStub(fetchMap, fetches) {
66+
// Per-pattern call counter for sequenced `responses: [...]` entries.
67+
const counters = new Map();
6668
return async function fetch(url, init) {
6769
const method = (init && init.method) || "GET";
6870
const body = init && init.body != null ? String(init.body) : null;
6971
fetches.push({ url: String(url), method, body });
7072

7173
let entry = null;
74+
let matchedPattern = null;
7275
for (const [pattern, value] of Object.entries(fetchMap)) {
7376
if (String(url).includes(pattern)) {
7477
entry = value;
78+
matchedPattern = pattern;
7579
break;
7680
}
7781
}
@@ -80,6 +84,14 @@ function buildFetchStub(fetchMap, fetches) {
8084
// route get a loud, predictable failure mode.
8185
entry = { status: 404, body: "" };
8286
}
87+
// Sequenced responses: each call advances the index, the last entry
88+
// sticks after exhaustion (matches the "addon comes back online and
89+
// stays online" shape these probe loops need).
90+
if (Array.isArray(entry.responses)) {
91+
const idx = counters.get(matchedPattern) ?? 0;
92+
counters.set(matchedPattern, idx + 1);
93+
entry = entry.responses[Math.min(idx, entry.responses.length - 1)];
94+
}
8395
if (entry.throw) {
8496
throw new TypeError(entry.throw);
8597
}

tests/src/unit/test_settings_ui_js_behavior.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,23 @@ def test_5xx_response_falls_through_to_reload_cycle(
192192
through to the poll-and-reload cycle, not surface the 5xx as a
193193
config error.
194194
"""
195-
# Pre-restart info → baseline; post-restart info → flipped.
196-
# The harness's fetch_map matches by substring on first hit; we
197-
# use a single entry and rely on the JS calling info() again
198-
# after restart fires.
195+
# The script hits /api/settings/info three times in this flow:
196+
# 1. loadTools() at script init (for the is_addon / is_sidecar
197+
# branch in the restart-notice copy)
198+
# 2. restartAddon() pre-POST, to capture the baseline instance_id
199+
# 3. _probeAddonRestarted() after the POST, to detect the flip
200+
# The first two return baseline; the third (and any further probe
201+
# iterations — the last entry sticks) returns the flipped id so
202+
# the probe exits with restarted=true.
199203
fetches = {
200204
**DEFAULT_FETCHES,
201205
"/api/settings/restart": {"status": 503, "body": ""},
202-
# Replace the default info route so the probe sees a NEW
203-
# instance_id and exits the polling loop with restarted=true.
204206
"/api/settings/info": {
205-
"status": 200,
206-
"json": {"instance_id": "new-id-after-restart"},
207+
"responses": [
208+
{"status": 200, "json": {"instance_id": "baseline-id"}},
209+
{"status": 200, "json": {"instance_id": "baseline-id"}},
210+
{"status": 200, "json": {"instance_id": "flipped-id"}},
211+
],
207212
},
208213
}
209214
result = run_script(

0 commit comments

Comments
 (0)