diff --git a/plugins/axiomcode/skills/axiomcode/scripts/ax_fill.py b/plugins/axiomcode/skills/axiomcode/scripts/ax_fill.py index 23b2da58..03c2955e 100755 --- a/plugins/axiomcode/skills/axiomcode/scripts/ax_fill.py +++ b/plugins/axiomcode/skills/axiomcode/scripts/ax_fill.py @@ -246,12 +246,18 @@ def still_open(rows): return listing, n_all, n_all - n_proj, len(proj) -def worklist(repo, limit=25, every=False): - """(summary dict, [open site]) over every live graph of the repository; limit 0 counts only (no candidates)""" +def worklist(repo, limit=25, every=False, sync=True): + """(summary dict, [open site]) over every live graph of the repository; limit 0 counts only (no candidates). + sync=False reads the graphs as they are and writes nothing: the build's summary line and the once-per-build notice + run while a build may still be finishing, and a re-apply there reads the working tree as it is at that moment""" cands = limit > 0 - # the links file may have changed since the graphs were last given it (edited, pulled, deleted): as before a query - try: ax_links.sync(repo) - except Exception: pass + # the links file may have changed since the graphs were last given it (edited, pulled, deleted): as before a query. + # Only a query does this. The build's summary ran it after the new graph was published but before the build had + # stamped it, so a file edited in that window had its links re-applied against the edited line: a link the next + # listing should call [changed] (edited since the build) was written into the graph as [stale] + if sync: + try: ax_links.sync(repo) + except Exception: pass reader = ax_links.Reader(repo); skips = read_skips(repo) summ = dict(calls=0, project=0, boundary=0, asserted=0, unresolved=0, library=0, open=0, skipped=0, graphs=0) sites = [] @@ -390,7 +396,7 @@ def notice(repo, surface): with open(mark, encoding='utf-8') as fh: if fh.read().strip() == stamp: return '' except OSError: pass - s, _ = worklist(repo, 0) + s, _ = worklist(repo, 0, sync=False) try: with open(mark, 'w', encoding='utf-8') as fh: fh.write(stamp) except OSError: pass @@ -422,7 +428,7 @@ def main(argv): if not os.path.isdir(os.path.join(repo, '.axiomcode')): print(f"axiomcode unresolved: no graph for {repo} — `axiomcode index` builds it", file=sys.stderr); return 2 if only: - s, _ = worklist(repo, 0) + s, _ = worklist(repo, 0, sync=False) print(json.dumps(s) if as_json else summary_line(s)); return 0 return print_worklist(repo, limit, as_json, every) diff --git a/tests/fill.py b/tests/fill.py index 44cf0230..b545107e 100644 --- a/tests/fill.py +++ b/tests/fill.py @@ -152,6 +152,39 @@ def check(ok, what): sh(repo, AX, 'link', '--batch', '-', repo, stdin=f"{site} progress\n") t += 5; os.utime(os.path.realpath(db), (t, t)) check(sh(repo, 'python3', FILL, repo, '--notice', 'hook').stdout.strip() == '', 'notice: silent when nothing is open') + + # A BUILD STILL FINISHING: the graph is published (a waiting query has returned) but not yet stamped with the + # links file it was given, and the linked line is edited in that window. The summary line and the notice read + # the graphs and write nothing, so the listing still calls the link [changed]; written into the graph from + # the edited text it would be [stale] (the nightly's Windows failure on python/asserted-links). A query + # (`unresolved`) still re-applies a links file the graphs were not given: the control + import sqlite3 + dbs = sorted({os.path.realpath(os.path.join(dp, f)) for dp, _d, fs in os.walk(os.path.join(repo, '.axiomcode')) + for f in fs if f == 'graph.sqlite'}) + def unstamp(): + for d in dbs: + with sqlite3.connect(d) as c: c.execute("UPDATE index_meta SET value = '' WHERE key = 'links_sha'") + def stamps(): + out = set() + for d in dbs: + with sqlite3.connect(d) as c: out |= {r[0] for r in c.execute("SELECT value FROM index_meta WHERE key = 'links_sha'")} + return out + def link_status(): + row = [l for l in sh(repo, AX, 'link', repo).stdout.splitlines() if f'app/jobs.py:{CB_LINE}' in l] + return row[0] if row else '' + check('[applied]' in link_status(), f'unstamped: the link is applied before the edit (got {link_status()!r})') + unstamp() + L = JOBS.split('\n'); L[CB_LINE - 1] = L[CB_LINE - 1].replace('cb(i)', 'cb(i + 0)') + open(p, 'w').write('\n'.join(L)) + sh(repo, 'python3', FILL, repo, '--summary') + t += 5; os.utime(os.path.realpath(db), (t, t)) + sh(repo, 'python3', FILL, repo, '--notice', 'hook') + st = link_status() + check('[changed]' in st and '[stale]' not in st, f'unstamped: the summary and the notice write nothing; the edited link is [changed] (got {st!r})') + check(stamps() == {''}, f'unstamped: no graph was re-stamped by the summary or the notice (got {stamps()})') + sh(repo, AX, 'unresolved', repo) + check('' not in stamps(), f'unstamped (control): a query re-applies the links file the graphs were not given (got {stamps()})') + open(p, 'w').write(JOBS) finally: shutil.rmtree(repo, ignore_errors=True)