magehand 0.76.2__tar.gz → 0.76.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {magehand-0.76.2 → magehand-0.76.4}/PKG-INFO +3 -3
- {magehand-0.76.2 → magehand-0.76.4}/README.md +2 -2
- {magehand-0.76.2 → magehand-0.76.4}/pyproject.toml +1 -1
- {magehand-0.76.2 → magehand-0.76.4}/src/magehand/cli.py +56 -11
- {magehand-0.76.2 → magehand-0.76.4}/tests/test_cli.py +86 -0
- {magehand-0.76.2 → magehand-0.76.4}/.gitignore +0 -0
- {magehand-0.76.2 → magehand-0.76.4}/LICENSE +0 -0
- {magehand-0.76.2 → magehand-0.76.4}/assets/README.md +0 -0
- {magehand-0.76.2 → magehand-0.76.4}/src/magehand/__init__.py +0 -0
- {magehand-0.76.2 → magehand-0.76.4}/src/magehand/__main__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: magehand
|
|
3
|
-
Version: 0.76.
|
|
3
|
+
Version: 0.76.4
|
|
4
4
|
Summary: The developer CLI for building apps on davidlarrimore's homelab
|
|
5
5
|
Project-URL: Source, https://github.com/davidlarrimore/magehand
|
|
6
6
|
License-Expression: MIT
|
|
@@ -149,7 +149,7 @@ has it as `"next"`. Only commands whose output is the result itself (`guide`,
|
|
|
149
149
|
| `magehand status [APP] [--watch]` | Where the app is: set up, registered, built, on dev and prod |
|
|
150
150
|
| `magehand check [APP] [--ui]` | Check the app against the platform's rules, `build.yaml` exactly the template's included (before every push; `--ui` runs CI's browser check) |
|
|
151
151
|
| `magehand verify` | Run the platform's static checks on what you'll push, as CI does |
|
|
152
|
-
| `magehand api PATH [--prod]` | Call the app's API on dev or production, as you |
|
|
152
|
+
| `magehand api PATH [--prod]` | Call the app's API on dev or production, as you (a write carries the app's own `Origin`, as a browser's does) |
|
|
153
153
|
| `magehand llm usage [--env dev\|prod] [--by kind\|model\|stage\|prompt] [--since D] [--until D]` | The app's LLM tokens and cost from the platform: each llm block, dev and prod apart, the budget and its reset date; a lab agent sees its own key's |
|
|
154
154
|
|
|
155
155
|
**Ship an app**
|
|
@@ -157,7 +157,7 @@ has it as `"next"`. Only commands whose output is the result itself (`guide`,
|
|
|
157
157
|
| Command | What it does |
|
|
158
158
|
| --- | --- |
|
|
159
159
|
| `magehand spec check N / spec verify N` | Ask OpenClaw whether an issue's spec is buildable, or whether a PR meets it |
|
|
160
|
-
| `magehand pr ready [N] / pr watch [N]` | Mark a green PR ready and request OpenClaw's review, then follow it until it needs you or is done (findings, a failed check, or a verify verdict for its head that isn't `met`) |
|
|
160
|
+
| `magehand pr ready [N] / pr watch [N]` | Mark a green PR ready and request OpenClaw's review, then follow it until it needs you or is done (findings, a failed or cancelled check, or a verify verdict for its head that isn't `met`); a check counts by its latest run on the head, as `gh pr checks` shows it |
|
|
161
161
|
| `magehand pr answer [N] [K]` | List the findings of OpenClaw's latest review (answered ones marked), or answer finding K with a PR comment (`-m TEXT`, `--body-file FILE`): the condition of the review's bar it fails and the fact that shows it, or the issue it's parked in. Then `pr ready` again: OpenClaw judges the answers on the same head, with no push and no CI run |
|
|
162
162
|
| `magehand release [APP]` | Cut the app's production release (the next `vX.Y.Z`), only when the owner asks |
|
|
163
163
|
| `magehand job add / rm / ls` | Add, remove and list the app's scheduled jobs (CronJobs) |
|
|
@@ -134,7 +134,7 @@ has it as `"next"`. Only commands whose output is the result itself (`guide`,
|
|
|
134
134
|
| `magehand status [APP] [--watch]` | Where the app is: set up, registered, built, on dev and prod |
|
|
135
135
|
| `magehand check [APP] [--ui]` | Check the app against the platform's rules, `build.yaml` exactly the template's included (before every push; `--ui` runs CI's browser check) |
|
|
136
136
|
| `magehand verify` | Run the platform's static checks on what you'll push, as CI does |
|
|
137
|
-
| `magehand api PATH [--prod]` | Call the app's API on dev or production, as you |
|
|
137
|
+
| `magehand api PATH [--prod]` | Call the app's API on dev or production, as you (a write carries the app's own `Origin`, as a browser's does) |
|
|
138
138
|
| `magehand llm usage [--env dev\|prod] [--by kind\|model\|stage\|prompt] [--since D] [--until D]` | The app's LLM tokens and cost from the platform: each llm block, dev and prod apart, the budget and its reset date; a lab agent sees its own key's |
|
|
139
139
|
|
|
140
140
|
**Ship an app**
|
|
@@ -142,7 +142,7 @@ has it as `"next"`. Only commands whose output is the result itself (`guide`,
|
|
|
142
142
|
| Command | What it does |
|
|
143
143
|
| --- | --- |
|
|
144
144
|
| `magehand spec check N / spec verify N` | Ask OpenClaw whether an issue's spec is buildable, or whether a PR meets it |
|
|
145
|
-
| `magehand pr ready [N] / pr watch [N]` | Mark a green PR ready and request OpenClaw's review, then follow it until it needs you or is done (findings, a failed check, or a verify verdict for its head that isn't `met`) |
|
|
145
|
+
| `magehand pr ready [N] / pr watch [N]` | Mark a green PR ready and request OpenClaw's review, then follow it until it needs you or is done (findings, a failed or cancelled check, or a verify verdict for its head that isn't `met`); a check counts by its latest run on the head, as `gh pr checks` shows it |
|
|
146
146
|
| `magehand pr answer [N] [K]` | List the findings of OpenClaw's latest review (answered ones marked), or answer finding K with a PR comment (`-m TEXT`, `--body-file FILE`): the condition of the review's bar it fails and the fact that shows it, or the issue it's parked in. Then `pr ready` again: OpenClaw judges the answers on the same head, with no push and no CI run |
|
|
147
147
|
| `magehand release [APP]` | Cut the app's production release (the next `vX.Y.Z`), only when the owner asks |
|
|
148
148
|
| `magehand job add / rm / ls` | Add, remove and list the app's scheduled jobs (CronJobs) |
|
|
@@ -938,6 +938,21 @@ def agent_token():
|
|
|
938
938
|
return (token, left) if isinstance(token, str) and token and left > 0 else (None, 0)
|
|
939
939
|
|
|
940
940
|
|
|
941
|
+
def agent_token_problem():
|
|
942
|
+
"""Why there is no agent token, never quoting MAGEHAND_AGENT_TOKEN: it names a file, and a mistake that puts the
|
|
943
|
+
token itself there would otherwise print a credential (#160)."""
|
|
944
|
+
value = AGENT_TOKEN.strip()
|
|
945
|
+
# A JWT (base64url JSON, so 'eyJ', in three parts) or a long opaque string with no path in it.
|
|
946
|
+
if (value.startswith('eyJ') and value.count('.') == 2) or (os.sep not in value and len(value) > 64):
|
|
947
|
+
return ('MAGEHAND_AGENT_TOKEN holds what looks like a token itself: it must name the token file the lab '
|
|
948
|
+
'renews (in an agent\'s VM, /run/homelab-agents/<agent>.json), never the token')
|
|
949
|
+
if not os.path.isfile(value):
|
|
950
|
+
return ("the agent's dev token file (the file MAGEHAND_AGENT_TOKEN names) isn't there: the lab writes it every "
|
|
951
|
+
'5 minutes (homelab-agent-token.timer in its VM); if it stays missing, tell the owner')
|
|
952
|
+
return ("the agent's dev token is unreadable or expired: the lab replaces it every 5 minutes "
|
|
953
|
+
'(homelab-agent-token.timer in its VM); if it stays that way, tell the owner')
|
|
954
|
+
|
|
955
|
+
|
|
941
956
|
def agent_refuses(command, what):
|
|
942
957
|
"""An agent's command that is the owner's alone: exit before anything is sent."""
|
|
943
958
|
if AGENT_TOKEN:
|
|
@@ -1041,8 +1056,7 @@ def api_session_token(below=API_RENEW_BELOW, need=0, failed=None):
|
|
|
1041
1056
|
if AGENT_TOKEN:
|
|
1042
1057
|
token, left = agent_token()
|
|
1043
1058
|
if not token:
|
|
1044
|
-
die(
|
|
1045
|
-
'(homelab-agent-token.timer in its VM); if it stays missing, tell the owner')
|
|
1059
|
+
die(agent_token_problem())
|
|
1046
1060
|
if left < need:
|
|
1047
1061
|
die(f"the agent's dev token has only {minutes(left)} left: the lab replaces it (homelab-agent-token.timer); "
|
|
1048
1062
|
'try again shortly, and if it stays short, tell the owner')
|
|
@@ -1203,6 +1217,11 @@ def cmd_api(a):
|
|
|
1203
1217
|
print(f'magehand: {method} to production: this changes {name}\'s real data, as you', file=sys.stderr)
|
|
1204
1218
|
# Cloudflare (public production hosts) refuses Python's default User-Agent with a 403.
|
|
1205
1219
|
headers = dict({'User-Agent': 'magehand'}, **extra)
|
|
1220
|
+
# Apps refuse a write whose Origin isn't their own host (the platform's CSRF rule), and a browser always sends
|
|
1221
|
+
# one: send the app's own, as a browser on its page would (magehand#158). A caller's -H Origin wins.
|
|
1222
|
+
if method not in ('GET', 'HEAD', 'OPTIONS', 'TRACE') and not any(k.lower() == 'origin' for k in extra):
|
|
1223
|
+
where = urllib.parse.urlsplit(url)
|
|
1224
|
+
headers['Origin'] = f'{where.scheme}://{where.netloc}'
|
|
1206
1225
|
failed = []
|
|
1207
1226
|
token = api_session_token(failed=failed)[0]
|
|
1208
1227
|
started = time.monotonic()
|
|
@@ -1530,11 +1549,28 @@ def failing_checks(rollup):
|
|
|
1530
1549
|
GREEN_CONCLUSIONS = ('SUCCESS', 'NEUTRAL', 'SKIPPED')
|
|
1531
1550
|
|
|
1532
1551
|
|
|
1552
|
+
def latest_checks(rollup):
|
|
1553
|
+
"""A PR's statusCheckRollup with only the latest run of each check, as `gh pr checks` shows it (#161). The
|
|
1554
|
+
rollup keeps every run on the head: a run a newer one superseded (cancelled when a draft was readied, or re-run)
|
|
1555
|
+
is history, not the check's result. A check is its workflow and name (a StatusContext: its context); the latest
|
|
1556
|
+
is the one started last, and one not started yet (no time) is newer than any that has."""
|
|
1557
|
+
latest = {}
|
|
1558
|
+
for i, c in enumerate(rollup or []):
|
|
1559
|
+
key = (c.get('__typename'), c.get('workflowName'), c.get('name') or c.get('context') or '?')
|
|
1560
|
+
when = c.get('startedAt') or c.get('createdAt')
|
|
1561
|
+
rank = (when is None and c.get('status') not in (None, 'COMPLETED'), when or '', -i)
|
|
1562
|
+
if key not in latest or rank > latest[key][0]:
|
|
1563
|
+
latest[key] = (rank, c)
|
|
1564
|
+
keep = {id(c) for _, c in latest.values()}
|
|
1565
|
+
return [c for c in rollup or [] if id(c) in keep]
|
|
1566
|
+
|
|
1567
|
+
|
|
1533
1568
|
def not_green_checks(rollup):
|
|
1534
1569
|
"""'name (result)' for each finished entry of a PR's statusCheckRollup that isn't a pass: a CheckRun whose
|
|
1535
|
-
conclusion isn't in GREEN_CONCLUSIONS, a StatusContext in FAILURE or ERROR.
|
|
1570
|
+
conclusion isn't in GREEN_CONCLUSIONS, a StatusContext in FAILURE or ERROR. Only each check's latest run
|
|
1571
|
+
counts (latest_checks)."""
|
|
1536
1572
|
out = []
|
|
1537
|
-
for c in rollup
|
|
1573
|
+
for c in latest_checks(rollup):
|
|
1538
1574
|
name = c.get('name') or c.get('context') or '?'
|
|
1539
1575
|
if c.get('state') in ('FAILURE', 'ERROR'):
|
|
1540
1576
|
out.append(f'{name} ({c["state"].lower()})')
|
|
@@ -1546,7 +1582,7 @@ def not_green_checks(rollup):
|
|
|
1546
1582
|
def pending_checks(rollup):
|
|
1547
1583
|
"""Names of the entries of a PR's statusCheckRollup that haven't finished: CheckRuns not COMPLETED and
|
|
1548
1584
|
StatusContexts still PENDING or EXPECTED."""
|
|
1549
|
-
return [c.get('name') or c.get('context') or '?' for c in rollup
|
|
1585
|
+
return [c.get('name') or c.get('context') or '?' for c in latest_checks(rollup)
|
|
1550
1586
|
if (c.get('status') and c.get('status') != 'COMPLETED') or c.get('state') in ('PENDING', 'EXPECTED')]
|
|
1551
1587
|
|
|
1552
1588
|
|
|
@@ -2589,8 +2625,8 @@ GITHUB_API = 'https://api.github.com/'
|
|
|
2589
2625
|
# The `gh pr list --json` fields magehand reads, as GraphQL: the same names and shapes gh returns.
|
|
2590
2626
|
PR_LIST_FIELDS = {'number': 'number', 'state': 'state', 'mergedAt': 'mergedAt', 'title': 'title', 'body': 'body',
|
|
2591
2627
|
'statusCheckRollup': 'commits(last: 1) { nodes { commit { statusCheckRollup { contexts(first: 100) '
|
|
2592
|
-
'{ nodes { __typename ... on CheckRun { name status conclusion } '
|
|
2593
|
-
'... on StatusContext { context state } } } } } } }'}
|
|
2628
|
+
'{ nodes { __typename ... on CheckRun { name status conclusion startedAt } '
|
|
2629
|
+
'... on StatusContext { context state createdAt } } } } } } }'}
|
|
2594
2630
|
|
|
2595
2631
|
|
|
2596
2632
|
def github_request(method, path, body=None, accept='application/vnd.github+json'):
|
|
@@ -9222,7 +9258,7 @@ def cmd_pr(a):
|
|
|
9222
9258
|
# needs the agent or the PR is done, then prints what happened and the next step and exits, so an agent that
|
|
9223
9259
|
# runs it in the background (Claude Code wakes when it exits) or in the foreground (Codex) picks the work up.
|
|
9224
9260
|
# Exit 0: done (`result` merged, held, green, reviewed); 1: something to do, `next:` says what (findings,
|
|
9225
|
-
# failed, closed, stalled, unrequested, live-test, timeout). Usage errors exit 2, as everywhere.
|
|
9261
|
+
# failed, cancelled, closed, stalled, unrequested, live-test, timeout). Usage errors exit 2, as everywhere.
|
|
9226
9262
|
|
|
9227
9263
|
WATCH_FIELDS = PR_FIELDS + ',reviews,assignees,labels,files,comments'
|
|
9228
9264
|
# The Requirements Owner's verdict on a head (homelab#742): OpenClaw's comment carries this mark, and a PR that closes
|
|
@@ -9329,6 +9365,12 @@ def watch_step(pr, memory, now, open_threads=lambda: []):
|
|
|
9329
9365
|
return 'merged', 'merged', None
|
|
9330
9366
|
if pr.get('state') == 'CLOSED':
|
|
9331
9367
|
return 'closed', 'closed without merging', 'ask the owner why, if you did not close it'
|
|
9368
|
+
if failing and all(f.endswith(' (cancelled)') for f in failing):
|
|
9369
|
+
# Nothing failed: a run was stopped (a runner went away, someone cancelled it). Re-running it costs no push,
|
|
9370
|
+
# so the head, its review and its live test stay (#161).
|
|
9371
|
+
return 'cancelled', f'checks cancelled on {head[:7]}: {", ".join(failing)}', \
|
|
9372
|
+
(f're-run them (`gh pr checks {n}` links each run; `gh run rerun RUN_ID --failed`), no push needed, '
|
|
9373
|
+
f'then `magehand pr watch {n}`')
|
|
9332
9374
|
if failing:
|
|
9333
9375
|
undo = '' if pr.get('isDraft') else f'`gh pr ready {n} --undo`, '
|
|
9334
9376
|
return 'failed', f'checks failed on {head[:7]}: {", ".join(failing)}', \
|
|
@@ -10492,15 +10534,18 @@ def build_parser():
|
|
|
10492
10534
|
'X-authentik-* headers. A sleeping dev app is woken first (its waiting page is never the answer).\n'
|
|
10493
10535
|
'The body goes to stdout and a status line to stderr; exit 0 on 2xx/3xx, 1 otherwise (--json\n'
|
|
10494
10536
|
'says why: signed_out, asleep, unreachable). Redirects are not followed. In an app\'s checkout it\n'
|
|
10495
|
-
'calls that app only. *.lab hosts need the home network
|
|
10537
|
+
'calls that app only. *.lab hosts need the home network. A write (POST, PUT, PATCH, DELETE)\n'
|
|
10538
|
+
'carries the app\'s own Origin, as a browser on its page would: apps refuse writes without it\n'
|
|
10539
|
+
'(-H "Origin: ..." replaces it).\n\n'
|
|
10496
10540
|
'examples:\n magehand api /api/health\n magehand api -a career-scout /api/jobs --json\n'
|
|
10497
10541
|
" magehand api /api/items -d '{\"name\": \"x\"}' POST, JSON\n"
|
|
10498
10542
|
' magehand api /api/items/7 -X DELETE\n'
|
|
10499
10543
|
' magehand api /api/import -d @items.json --prod production: real data\n\n'
|
|
10500
10544
|
'Your own HTTP client (curl, requests, a test suite): `magehand api token` prints the access\n'
|
|
10501
10545
|
'token (1h, renewed first so 10+ minutes are left; the same for every app). Send it as\n'
|
|
10502
|
-
'`Authorization: Bearer TOKEN` to the app\'s URL (`magehand app` lists them)
|
|
10503
|
-
'when it expires. Keep it out of files, logs
|
|
10546
|
+
'`Authorization: Bearer TOKEN` to the app\'s URL (`magehand app` lists them), and on a write\n'
|
|
10547
|
+
'`Origin: https://APP-HOST` too; get a new token when it expires. Keep it out of files, logs\n'
|
|
10548
|
+
'and commits.\n'
|
|
10504
10549
|
' curl -H "Authorization: Bearer $(magehand api token)" https://APP-dev.lab.davidlarrimore.com/api/x\n'
|
|
10505
10550
|
' magehand api token --json {token, expires_at, seconds_left}')
|
|
10506
10551
|
p.add_argument('path', metavar='PATH', help="the path on the app, from / (with any ?query); or `token`")
|
|
@@ -1623,6 +1623,23 @@ class AgentIdentity(unittest.TestCase):
|
|
|
1623
1623
|
magehand.api_session_token()
|
|
1624
1624
|
self.assertIn('homelab-agent-token', str(caught.exception))
|
|
1625
1625
|
|
|
1626
|
+
def test_a_token_put_in_the_variable_itself_is_never_printed(self):
|
|
1627
|
+
"""#160: MAGEHAND_AGENT_TOKEN names a file. Set to the token by mistake, the error says so without the value."""
|
|
1628
|
+
jwt = 'eyJhbGciOiJSUzI1NiJ9.' + 'eyJzdWIiOiJ0ZXN0In0' * 4 + '.' + 'c2lnbmF0dXJl' * 8
|
|
1629
|
+
for value in (jwt, 'x' * 80):
|
|
1630
|
+
with mock.patch.object(magehand, 'AGENT_TOKEN', value), self.assertRaises(SystemExit) as caught:
|
|
1631
|
+
magehand.api_session_token()
|
|
1632
|
+
self.assertNotIn(value, str(caught.exception))
|
|
1633
|
+
self.assertIn('must name the token file', str(caught.exception))
|
|
1634
|
+
# Missing, expired or unreadable: the value isn't printed either, and the message names the lab's timer.
|
|
1635
|
+
for prepare in (lambda: None, lambda: self.token(left=-5)):
|
|
1636
|
+
self.path.unlink(missing_ok=True)
|
|
1637
|
+
prepare()
|
|
1638
|
+
with self.assertRaises(SystemExit) as caught:
|
|
1639
|
+
magehand.api_session_token()
|
|
1640
|
+
self.assertNotIn(str(self.path), str(caught.exception))
|
|
1641
|
+
self.assertIn('homelab-agent-token', str(caught.exception))
|
|
1642
|
+
|
|
1626
1643
|
def test_dev_requests_carry_the_agents_token(self):
|
|
1627
1644
|
self.token('agent-tok')
|
|
1628
1645
|
calls = []
|
|
@@ -4720,6 +4737,46 @@ class PrWatch(unittest.TestCase):
|
|
|
4720
4737
|
self.assertIn('--undo', self.step(self.pr(checks=self.FAILED))[2])
|
|
4721
4738
|
self.assertNotIn('--undo', self.step(self.pr(checks=self.FAILED, draft=True))[2])
|
|
4722
4739
|
|
|
4740
|
+
def test_only_each_checks_latest_run_counts(self):
|
|
4741
|
+
"""#161 (homelab#895, 2026-11-30): readying the draft started a new run and the workflow's concurrency
|
|
4742
|
+
cancelled the one in progress. The rollup keeps both; only the latest run of each check is its result."""
|
|
4743
|
+
def run(name, started, status='COMPLETED', conclusion=None):
|
|
4744
|
+
return {'__typename': 'CheckRun', 'workflowName': 'Validate homelab', 'name': name, 'status': status,
|
|
4745
|
+
'conclusion': conclusion, 'startedAt': started}
|
|
4746
|
+
superseded = [run('checks / pre-commit', '2026-11-30T21:46:36Z', conclusion='CANCELLED'),
|
|
4747
|
+
run('validate', '2026-11-30T21:47:46Z', conclusion='SUCCESS'),
|
|
4748
|
+
run('checks / pre-commit', '2026-11-30T21:50:39Z', status='QUEUED'),
|
|
4749
|
+
run('validate', '2026-11-30T21:51:14Z', status='IN_PROGRESS')]
|
|
4750
|
+
self.assertEqual(magehand.not_green_checks(superseded), [])
|
|
4751
|
+
self.assertEqual(sorted(magehand.pending_checks(superseded)), ['checks / pre-commit', 'validate'])
|
|
4752
|
+
got, what, _ = self.step(self.pr(checks=superseded, review=[('APPROVED', self.HEAD)]))
|
|
4753
|
+
self.assertIsNone(got, what) # still running, not failed
|
|
4754
|
+
done = superseded[:2] + [run('checks / pre-commit', '2026-11-30T21:50:39Z', conclusion='SUCCESS'),
|
|
4755
|
+
run('validate', '2026-11-30T21:51:14Z', conclusion='SUCCESS')]
|
|
4756
|
+
self.assertEqual(magehand.not_green_checks(done), [])
|
|
4757
|
+
# A newer failure still fails, whatever the older run said; a queued run with no time yet is the newest.
|
|
4758
|
+
self.assertEqual(magehand.failing_checks([run('validate', '2026-11-30T21:00:00Z', conclusion='SUCCESS'),
|
|
4759
|
+
run('validate', '2026-11-30T22:00:00Z', conclusion='FAILURE')]),
|
|
4760
|
+
['validate'])
|
|
4761
|
+
self.assertEqual(magehand.pending_checks([run('validate', '2026-11-30T21:00:00Z', conclusion='CANCELLED'),
|
|
4762
|
+
run('validate', None, status='QUEUED')]), ['validate'])
|
|
4763
|
+
# The same name in another workflow is another check.
|
|
4764
|
+
other = {**run('validate', '2026-11-30T22:00:00Z', conclusion='FAILURE'), 'workflowName': 'Other'}
|
|
4765
|
+
self.assertEqual(magehand.failing_checks(done + [other]), ['validate'])
|
|
4766
|
+
# Rollups without times (older callers): every entry still counts once.
|
|
4767
|
+
self.assertEqual(magehand.failing_checks(self.FAILED), ['tests'])
|
|
4768
|
+
|
|
4769
|
+
def test_a_cancelled_latest_run_is_re_run_not_fixed(self):
|
|
4770
|
+
cancelled = [{'name': 'tests', 'status': 'COMPLETED', 'conclusion': 'CANCELLED'}]
|
|
4771
|
+
got, what, step = self.step(self.pr(checks=cancelled, labels=['live-tested']))
|
|
4772
|
+
self.assertEqual(got, 'cancelled', what)
|
|
4773
|
+
self.assertIn('gh run rerun', step)
|
|
4774
|
+
for wrong in ('--undo', 'push until green', 'remove-label'):
|
|
4775
|
+
self.assertNotIn(wrong, step)
|
|
4776
|
+
# A real failure beside a cancelled run is a failure.
|
|
4777
|
+
mixed = cancelled + [{'name': 'lint', 'status': 'COMPLETED', 'conclusion': 'FAILURE'}]
|
|
4778
|
+
self.assertEqual(self.step(self.pr(checks=mixed))[0], 'failed')
|
|
4779
|
+
|
|
4723
4780
|
def test_a_verify_verdict_that_isnt_met_is_findings(self):
|
|
4724
4781
|
# homelab#742: OpenClaw merges a PR that closes an issue only once its head's latest verdict is `met`.
|
|
4725
4782
|
H = self.HEAD
|
|
@@ -7015,6 +7072,35 @@ class AppApi(unittest.TestCase):
|
|
|
7015
7072
|
self.assertEqual((method, headers['Content-Type'], body), ('POST', 'application/json', b'{"name": "x"}'))
|
|
7016
7073
|
self.assertEqual(json.loads(out)['status'], 201)
|
|
7017
7074
|
|
|
7075
|
+
def test_a_write_sends_the_apps_own_origin(self): # magehand#158: apps refuse a write with no Origin
|
|
7076
|
+
for argv, method, origin in (
|
|
7077
|
+
(('-d', '{}'), 'POST', 'https://demo-dev.lab.davidlarrimore.com'),
|
|
7078
|
+
(('-X', 'put', '-d', '{}'), 'PUT', 'https://demo-dev.lab.davidlarrimore.com'),
|
|
7079
|
+
(('-X', 'patch', '-d', '{}'), 'PATCH', 'https://demo-dev.lab.davidlarrimore.com'),
|
|
7080
|
+
(('-X', 'delete'), 'DELETE', 'https://demo-dev.lab.davidlarrimore.com'),
|
|
7081
|
+
(('-X', 'post', '-H', 'origin: https://example.com'), 'POST', None)):
|
|
7082
|
+
self.calls, self.replies = [], [(200, {}, b'')]
|
|
7083
|
+
code, _, _ = self.run_main('api', '-a', 'demo', '/api/items', *argv)
|
|
7084
|
+
_, sent, headers, _ = self.calls[0]
|
|
7085
|
+
self.assertEqual((code, sent), (0, method))
|
|
7086
|
+
if origin:
|
|
7087
|
+
self.assertEqual(headers['Origin'], origin)
|
|
7088
|
+
else: # the caller's own Origin wins, sent once
|
|
7089
|
+
self.assertEqual([(k, v) for k, v in headers.items() if k.lower() == 'origin'],
|
|
7090
|
+
[('origin', 'https://example.com')])
|
|
7091
|
+
|
|
7092
|
+
def test_a_write_to_production_sends_its_public_origin(self):
|
|
7093
|
+
self.replies = [(200, {}, b'')]
|
|
7094
|
+
with mock.patch.object(magehand, 'file_at', lambda repo, path, ref: ('demo:\n exposure: external\n', None)):
|
|
7095
|
+
code, _, _ = self.run_main('api', '-a', 'demo', '/x', '--prod', '-X', 'post')
|
|
7096
|
+
self.assertEqual((code, self.calls[0][2]['Origin']), (0, 'https://demo.davidlarrimore.com'))
|
|
7097
|
+
|
|
7098
|
+
def test_a_read_sends_no_origin(self):
|
|
7099
|
+
for method in ('get', 'head', 'options'):
|
|
7100
|
+
self.calls, self.replies = [], [(200, {}, b'')]
|
|
7101
|
+
self.run_main('api', '-a', 'demo', '/api/items', '-X', method)
|
|
7102
|
+
self.assertFalse(any(k.lower() == 'origin' for k in self.calls[0][2]), method)
|
|
7103
|
+
|
|
7018
7104
|
def test_a_sleeping_dev_is_woken_not_returned(self):
|
|
7019
7105
|
waiting = (200, {'Content-Type': 'text/html'}, b'<html><head><title>Sablier</title>')
|
|
7020
7106
|
self.replies = [waiting, waiting, (200, {}, b'real')]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|