Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,9 @@ def cli(argv):
sys.exit(code)
import contextlib, io, json
buf = io.StringIO()
with contextlib.redirect_stdout(buf): code = main(argv)
with contextlib.redirect_stdout(buf):
try: code = main(argv)
except SystemExit as e: code = e.code if isinstance(e.code, int) else (0 if e.code is None else 1) # a refusal keeps its prose
RESULT['prose'] = buf.getvalue().rstrip('\n').split('\n')
ax_evidence.annotate('context', RESULT, repo)
print(json.dumps(RESULT, indent=2))
Expand Down
6 changes: 5 additions & 1 deletion plugins/axiomcode/skills/axiomcode/scripts/axiomcode-path
Original file line number Diff line number Diff line change
Expand Up @@ -2359,8 +2359,12 @@ if __name__ == '__main__':
sys.exit(code)
# the prose goes to a buffer, not to the caller: one code path produces both, and `prose` is
# carried in the document so a machine answer is never LESS than the human one.
# a refusal (an endpoint nothing declares, a bad argument) leaves answer() through SystemExit: catch it inside
# the redirect, or the JSON and the prose it carries are both lost and the caller sees nothing at all
buf = io.StringIO()
with contextlib.redirect_stdout(buf): code = answer()
with contextlib.redirect_stdout(buf):
try: code = answer()
except SystemExit as e: code = e.code if isinstance(e.code, int) else (0 if e.code is None else 1)
RESULT['prose'] = buf.getvalue().rstrip('\n').split('\n')
ax_evidence.annotate('path', RESULT, (RESULT.get('query') or {}).get('repo') or '.')
print(json.dumps(RESULT, indent=2))
Expand Down
45 changes: 45 additions & 0 deletions tests/cases/python/a-refused-endpoint-is-said/case.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"lang": "python",
"src": "src",
"checks": [
{
"why": "path with an endpoint nothing declares says so; the refusal reached the caller as nothing at all once the front door asked for --json",
"run": [
"path",
"main",
"NoSuchName"
],
"expect_error": true,
"want": [
"nothing named 'NoSuchName'"
],
"env": {
"AXIOMCODE_FRONT": "1"
}
},
{
"why": "the same refusal from the raw verb",
"run": [
"path",
"main",
"NoSuchName"
],
"expect_error": true,
"want": [
"nothing named 'NoSuchName'"
]
},
{
"why": "control: a path between two declared functions still answers",
"run": [
"path",
"main",
"helper"
],
"want": [
"main \u2192 helper",
"\u2192 [known_edge"
]
}
]
}
6 changes: 6 additions & 0 deletions tests/cases/python/a-refused-endpoint-is-said/src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def helper():
return 1


def main():
return helper()
Loading