MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / capture

Function capture

tests/harness/kg_closure_baseline.py:12–61  ·  view source on GitHub ↗
(binary, legacy)

Source from the content-addressed store, hash-verified

10
11
12def capture(binary, legacy):
13 with tempfile.TemporaryDirectory(prefix="atomic-kg-baseline-") as directory:
14 root = Path(directory)
15 env = dict(os.environ, ATOMIC_NO_DAEMON="1")
16
17 def run(*args, json_output=False):
18 result = subprocess.run(
19 [binary, *args], cwd=root, env=env, text=True, capture_output=True
20 )
21 if result.returncode and not (json_output and result.stdout.lstrip().startswith("{")):
22 raise AssertionError(f"{args}: {result.returncode}\n{result.stdout}\n{result.stderr}")
23 return json.loads(result.stdout) if json_output else result.stdout
24
25 run("init", "--view", "main")
26 run("view", "create", "feature", "--draft", "--parent", "main")
27 run("view", "switch", "feature")
28 files = {
29 "src/foundation.rs": "pub fn foundation() -> u32 { 1 }\n",
30 "src/service.rs": "use crate::foundation::foundation;\npub fn service() -> u32 { foundation() }\n",
31 "src/main.rs": "mod foundation;\nmod service;\nfn main() { service::service(); }\n",
32 }
33 for path, source in files.items():
34 (root / path).parent.mkdir(parents=True, exist_ok=True)
35 (root / path).write_text(source)
36 run("add", "src")
37 run("record", "-m", "Add workflow baseline fixture")
38 run("query", "enrich")
39 callers = {}
40 for path, name, line in [
41 ("src/foundation.rs", "foundation", 1),
42 ("src/service.rs", "service", 2),
43 ]:
44 target = f"entity:{path}:{name}:{line}" if legacy else f"{path}#{name}"
45 rows = run("query", "callers", target, "--json", json_output=True)
46 identities = []
47 for row in rows:
48 if "path" in row:
49 identities.append(f"{row['path']}#{row['name']}")
50 else:
51 caller = row["caller_id"].removeprefix("entity:").rsplit(":", 2)
52 identities.append(f"{caller[0]}#{caller[1]}")
53 callers[f"{path}#{name}"] = sorted(set(identities))
54 report = run("triage", "review", "feature", "--into", "main", "--json", json_output=True)
55 layers = [
56 {"title": layer["title"], "files": sorted(
57 path.removeprefix("file:") if legacy else unquote(path.split(":file:", 1)[1])
58 for path in layer["files"])}
59 for layer in report["walkthrough"]
60 ]
61 return {"callers": callers, "layers": layers}
62
63
64if __name__ == "__main__":

Callers 1

Calls 3

setFunction · 0.85
runFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected