Skip to content

Commit feccf3d

Browse files
test-impact: the hook's body-edit command and the per-package TS/JS command share one signature
command_for takes the graph (for Java/C# concrete test classes) and the repository (for each TS/JS file's package and runner): command_for(lang, files, classes, db=None, repo='.'). The edit hooks pass the repository they located, so a TypeScript body edit gets the command its package runs, and a multi-package plan stays on the hook's one line. Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
1 parent f8e6b71 commit feccf3d

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎plugins/axiomcode/hooks/_graphline.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ def _ti():
102102
return _TI or None
103103

104104

105-
def _command_for(lang, files, classes, db=None):
106-
"""the runnable command `axiomcode test-impact` prints, from the same function"""
107-
try: return _ti().command_for(lang, files, classes, db)
105+
def _command_for(lang, files, classes, db=None, repo='.'):
106+
"""the runnable command `axiomcode test-impact` prints, from the same function; a TypeScript/JavaScript selection
107+
can need one command per package and runner, joined with '; ' here because the hook's answer is one line"""
108+
try: cmd = _ti().command_for(lang, files, classes, db, repo)
108109
except Exception: return None
110+
return cmd.replace("\n", "; ") if cmd else cmd
109111

110112

111113
def _concrete(db, classes):
@@ -119,7 +121,7 @@ def _concrete(db, classes):
119121
SHOWN = 6
120122

121123

122-
def body_line(db, results):
124+
def body_line(db, results, repo='.'):
123125
"""ONE line for an edit that changed only bodies: which declarations, how many tests reach them, how to run those.
124126
`results` is [(changed-declaration, impact-json)], the same pairs the blast-radius block is built from."""
125127
names = [d['symbol'] for d, _ in results]
@@ -149,7 +151,7 @@ def body_line(db, results):
149151
fl, cl = sorted(files), sorted(owners)
150152
if lang in ('java', 'csharp') and cl:
151153
cl = sorted(_concrete(db, cl)) # before the cut, so the command and the "+N more" count the same classes
152-
cmd = _command_for(lang, fl[:SHOWN], cl[:SHOWN])
154+
cmd = _command_for(lang, fl[:SHOWN], cl[:SHOWN], None, repo)
153155
more = (len({c.split('.')[-1] for c in cl}) if lang in ('java', 'csharp') and cl else len(fl)) - SHOWN
154156
tail = (f"; run: {cmd}" + (f" (+{more} more: axiomcode test-impact)" if more > 0 else '')) if cmd else "; axiomcode test-impact gives the command"
155157
return f"graph: body edit of {what}: {n} test(s) reach it{tail}"

‎plugins/axiomcode/hooks/changes.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def impact(d):
118118
if len(decls) > 3: lines.append(f" … +{len(decls) - 3} more: axiomcode changed --impact")
119119
if bodies:
120120
lines.append(_graphline.body_line(os.path.join(os.environ.get('AXIOMCODE_GRAPH') or os.path.join(cwd, '.axiomcode'), 'out', 'graph.sqlite'),
121-
bodies + [(d, {}) for d in body[3:]]))
121+
bodies + [(d, {}) for d in body[3:]], cwd))
122122
return lines
123123

124124
def key(d): return f"{d['file']}:{d['symbol']}:{d['kind']}:{d.get('detail', '')}"

‎plugins/axiomcode/hooks/enrich.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def names(xs, k=4): return ', '.join(f"{x['display']} {x['at'].split('/')[-1]}"
231231
for n in ch.get('notes', [])[:2]: lines.append(f" added: {n}")
232232
if bodies:
233233
lines.append(_graphline.body_line(os.path.join(os.environ.get('AXIOMCODE_GRAPH') or os.path.join(cwd, '.axiomcode'), 'out', 'graph.sqlite'),
234-
bodies + [(d, {}) for d in body[3:]]))
234+
bodies + [(d, {}) for d in body[3:]], cwd))
235235
elif tool == 'Read':
236236
fp = _where._abs(inp.get('file_path', ''), scwd); rel = rel_of(fp)
237237
a = int(inp.get('offset') or 1); b = a + int(inp.get('limit') or 100000)

‎tests/test_command.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def tree(files):
103103
# control: nothing configured anywhere, a *.test.ts file still gets the command it always got
104104
d = tree({'src/a.test.ts': ''})
105105
check("nothing configured: a *.test.ts file keeps `npx vitest run` (control)",
106-
ti.command_for('typescript', ['src/a.test.ts'], [], d), 'npx vitest run src/a.test.ts')
106+
ti.command_for('typescript', ['src/a.test.ts'], [], repo=d), 'npx vitest run src/a.test.ts')
107107
shutil.rmtree(d)
108108

109109
# a runner's collection is read the way the runner reads it. Each shape: (files, the file, expected plan)

0 commit comments

Comments
 (0)