v3.22.3: the mismatch on_fail, the self-healing move, the pruning reconciliation
Three test-management issues: - an expectation whose command type did not match the pending command hard-coded level 'error', so on_fail "warning" tolerated "no command pending" but not "a different command is pending". The check now honours the step's on_fail - the tolerant form for "the applet either asks X or does Y" (the mismatched command is still fetched and answered). - moving a script between suites could answer 500 and leave two owners: _test_script_move detached only from the suite named by the script's suite_id and appended to the target unconditionally, so a duplicate listing or a stale suite_id (a hand edit, an interrupted move) collided on the attach. It now detaches from every suite that lists the script, takes the on_fail from the explicit owner (suite_id if that suite lists it, else the first lister), updates the script first (a refused validation changes nothing) and re-attaches with a prune; the same-suite no-op only applies when the target really is the only lister. - reconcile_scripts_to_suites() now prunes duplicate listings to the explicit owner (it only adopted before), so those states self-heal at startup and after a bundle import; the "Imported scripts" suite is only created when there are orphans. Docs: the bundle-import note (importing into the source store duplicates the suite and its scripts - the round-trip is not idempotent) and the expectation on_fail clarification. Tests: 839 frontend + 818 Python; sw cache simple-v407.
This commit is contained in:
@@ -1360,6 +1360,63 @@ class TestScriptStoreHttpTests(unittest.TestCase):
|
||||
self.assertEqual(status, 400, resp)
|
||||
self.assertIn('member set changes', resp['error'])
|
||||
|
||||
def test_move_repairs_a_duplicate_listing(self):
|
||||
# v3.22.3: the move detaches the script from EVERY suite that lists
|
||||
# it and re-attaches to the target - an inconsistent state (a partial
|
||||
# move, a stale suite_id) must not answer 500 or leave two owners.
|
||||
a = self._suite(name='a')
|
||||
b = self._suite(name='b')
|
||||
status, resp = self._post('/api/test/scripts', self._script(suite_id=a['id']))
|
||||
self.assertEqual(status, 200, resp)
|
||||
sid = resp['script']['id']
|
||||
# b lists it too: the state a partial move leaves behind
|
||||
self.suites.update(b['id'], {'scripts': [
|
||||
{'script_id': sid, 'role': 'member', 'on_fail': 'continue'}]})
|
||||
status, resp = self._post('/api/test/scripts/update', {
|
||||
'id': sid, 'script': {'name': 'demo', 'suite_id': b['id']}})
|
||||
self.assertEqual(status, 200, resp)
|
||||
self.assertTrue(resp.get('moved'))
|
||||
self.assertEqual(self.suites.get(a['id'])['scripts'], [])
|
||||
self.assertEqual([e['script_id'] for e in self.suites.get(b['id'])['scripts']],
|
||||
[sid])
|
||||
self.assertEqual(self.store.get(sid)['suite_id'], b['id'])
|
||||
# the on_fail comes from the explicit owner (the suite_id named a)
|
||||
self.assertEqual(self.suites.get(b['id'])['scripts'][0]['on_fail'], 'stop')
|
||||
|
||||
def test_move_from_a_stale_owner_repairs_the_listing(self):
|
||||
a = self._suite(name='a')
|
||||
b = self._suite(name='b')
|
||||
status, resp = self._post('/api/test/scripts', self._script(suite_id=a['id']))
|
||||
self.assertEqual(status, 200, resp)
|
||||
sid = resp['script']['id']
|
||||
# the suite_id points at a missing suite while a still lists it
|
||||
self.store.update(sid, {'suite_id': 'f' * 32})
|
||||
status, resp = self._post('/api/test/scripts/update', {
|
||||
'id': sid, 'script': {'name': 'demo', 'suite_id': b['id']}})
|
||||
self.assertEqual(status, 200, resp)
|
||||
self.assertEqual(self.suites.get(a['id'])['scripts'], [])
|
||||
self.assertEqual([e['script_id'] for e in self.suites.get(b['id'])['scripts']],
|
||||
[sid])
|
||||
self.assertEqual(self.store.get(sid)['suite_id'], b['id'])
|
||||
|
||||
def test_move_to_the_same_suite_prunes_a_duplicate(self):
|
||||
a = self._suite(name='a')
|
||||
b = self._suite(name='b')
|
||||
status, resp = self._post('/api/test/scripts', self._script(suite_id=b['id']))
|
||||
self.assertEqual(status, 200, resp)
|
||||
sid = resp['script']['id']
|
||||
# a also lists it; the explicit suite_id names b, whose on_fail stays
|
||||
self.suites.update(a['id'], {'scripts': [
|
||||
{'script_id': sid, 'role': 'member', 'on_fail': 'stop'}]})
|
||||
self.suites.update(b['id'], {'scripts': [
|
||||
{'script_id': sid, 'role': 'member', 'on_fail': 'continue'}]})
|
||||
status, resp = self._post('/api/test/scripts/move', {'id': sid, 'suite_id': b['id']})
|
||||
self.assertEqual(status, 200, resp)
|
||||
self.assertEqual(self.suites.get(a['id'])['scripts'], [])
|
||||
self.assertEqual([e['script_id'] for e in self.suites.get(b['id'])['scripts']],
|
||||
[sid])
|
||||
self.assertEqual(self.suites.get(b['id'])['scripts'][0]['on_fail'], 'continue')
|
||||
|
||||
def test_move_and_copy_between_suites(self):
|
||||
a = self._suite(name='a')
|
||||
b = self._suite(name='b')
|
||||
|
||||
@@ -222,6 +222,50 @@ class MigrationTests(unittest.TestCase):
|
||||
# idempotent: nothing left to attach
|
||||
self.assertEqual(srv.migrate_scripts_to_suites(scripts, suites), 0)
|
||||
|
||||
def test_a_duplicate_listing_is_pruned_to_the_explicit_owner(self):
|
||||
# v3.22.3: the reconciliation keeps a script in the suite its
|
||||
# suite_id names and prunes the other listings (a hand edit or an
|
||||
# interrupted move must not leave two owners).
|
||||
from pysim_simple_server import server as srv
|
||||
from pysim_simple_server import test_scripts
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
scripts = test_scripts.TestScriptStore(pathlib.Path(tmp) / 's.json')
|
||||
suites = test_suites.TestSuiteStore(pathlib.Path(tmp) / 'u.json')
|
||||
step = {'type': 'action', 'kind': 'status', 'params': {'attempts': 1}}
|
||||
a = suites.add({'name': 'A'})
|
||||
b = suites.add({'name': 'B'})
|
||||
s = scripts.add({'name': 'x', 'suite_id': b['id'], 'steps': [step]})
|
||||
for su in (a, b):
|
||||
suites.update(su['id'], {'scripts': [
|
||||
{'script_id': s['id'], 'role': 'member', 'on_fail': 'stop'}]})
|
||||
self.assertEqual(srv.reconcile_scripts_to_suites(scripts, suites), 1)
|
||||
self.assertEqual(suites.get(a['id'])['scripts'], [])
|
||||
self.assertEqual([e['script_id'] for e in suites.get(b['id'])['scripts']],
|
||||
[s['id']])
|
||||
self.assertEqual(scripts.get(s['id'])['suite_id'], b['id'])
|
||||
# idempotent
|
||||
self.assertEqual(srv.reconcile_scripts_to_suites(scripts, suites), 0)
|
||||
|
||||
def test_a_duplicate_listing_with_a_stale_owner_keeps_the_first_lister(self):
|
||||
from pysim_simple_server import server as srv
|
||||
from pysim_simple_server import test_scripts
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
scripts = test_scripts.TestScriptStore(pathlib.Path(tmp) / 's.json')
|
||||
suites = test_suites.TestSuiteStore(pathlib.Path(tmp) / 'u.json')
|
||||
step = {'type': 'action', 'kind': 'status', 'params': {'attempts': 1}}
|
||||
a = suites.add({'name': 'A'})
|
||||
b = suites.add({'name': 'B'})
|
||||
s = scripts.add({'name': 'x', 'suite_id': 'f' * 32, 'steps': [step]})
|
||||
for su in (a, b):
|
||||
suites.update(su['id'], {'scripts': [
|
||||
{'script_id': s['id'], 'role': 'member', 'on_fail': 'stop'}]})
|
||||
# the prune of B plus the adoption of the first lister A
|
||||
self.assertEqual(srv.reconcile_scripts_to_suites(scripts, suites), 2)
|
||||
self.assertEqual([e['script_id'] for e in suites.get(a['id'])['scripts']],
|
||||
[s['id']])
|
||||
self.assertEqual(suites.get(b['id'])['scripts'], [])
|
||||
self.assertEqual(scripts.get(s['id'])['suite_id'], a['id'])
|
||||
|
||||
def test_an_invalid_script_is_still_listed_by_the_reconciliation(self):
|
||||
# The script store keeps an entry that no longer validates (a
|
||||
# tightened rule must not destroy it). Its suite_id write is refused
|
||||
|
||||
@@ -563,6 +563,39 @@ class TestRunnerDialogue(RunnerTestCase):
|
||||
self.assertIn('no proactive command pending',
|
||||
run['steps'][0]['checks'][0]['detail'])
|
||||
|
||||
def test_a_command_mismatch_honours_on_fail(self):
|
||||
# v3.22.3: a different command pending is a check failure at the
|
||||
# step's on_fail level, like every other expectation check - so
|
||||
# on_fail "warning" expresses "the applet either asks X or does Y"
|
||||
# (the mismatched command is still fetched and answered).
|
||||
scc = FakeScc()
|
||||
scc.push('80F2', '', '9102') # STATUS: DISPLAY TEXT pending
|
||||
scc.push('8012', DISPLAY_TEXT_CMD, '9000')
|
||||
scc.push('8014', '', '9000')
|
||||
run = self.run_script(FakeServer(scc), [
|
||||
{'type': 'action', 'kind': 'status', 'params': {'attempts': 2}},
|
||||
{'type': 'expect', 'command': 'SEND SHORT MESSAGE',
|
||||
'respond': {'result': 'ok'}, 'on_fail': 'warning'},
|
||||
])
|
||||
self.assertEqual(run['status'], 'warning', run['steps'])
|
||||
check = run['steps'][1]['checks'][0]
|
||||
self.assertEqual(check['label'], 'Command')
|
||||
self.assertFalse(check['ok'])
|
||||
self.assertEqual(check['level'], 'warning')
|
||||
self.assertIn('DISPLAY TEXT', check['actual'])
|
||||
self.assertTrue(run['steps'][1]['sent'].startswith('TR '))
|
||||
# the default (error) still stops the run
|
||||
scc2 = FakeScc()
|
||||
scc2.push('80F2', '', '9102')
|
||||
scc2.push('8012', DISPLAY_TEXT_CMD, '9000')
|
||||
scc2.push('8014', '', '9000')
|
||||
run2 = self.run_script(FakeServer(scc2), [
|
||||
{'type': 'action', 'kind': 'status', 'params': {'attempts': 2}},
|
||||
{'type': 'expect', 'command': 'SEND SHORT MESSAGE',
|
||||
'respond': {'result': 'ok'}},
|
||||
])
|
||||
self.assertEqual(run2['status'], 'error')
|
||||
|
||||
def test_text_mismatch_fails_the_expectation(self):
|
||||
scc = FakeScc()
|
||||
scc.push('80C2', '', '9105')
|
||||
|
||||
Reference in New Issue
Block a user