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

Function capture

tests/harness/kg_closure_baseline.py:12–76  ·  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 if legacy:
55 report = run("triage", "review", "feature", "--into", "main", "--json", json_output=True)
56 review_files = {
57 path.removeprefix("file:") if path.startswith("file:") else unquote(path.split(":file:", 1)[1])
58 for layer in report["walkthrough"] for path in layer["files"]
59 }
60 else:
61 report = run("review", "--from", "feature", "--to", "main", "--json", json_output=True)
62 comparison = report["view_comparison"]
63 assert comparison["from"]["view"] == "feature"
64 assert comparison["to"]["view"] == "main"
65 # Paired-view ASTs include inherited context as well as changes.
66 # Select changed name/identity/content pins, not presentation rows
67 # for unchanged tool/vault files whose code analysis is unavailable.
68 changed = [row for row in comparison["files"] if any(
69 row[f"before_{field}"] != row[f"after_{field}"]

Callers 1

Calls 4

setFunction · 0.85
unquoteFunction · 0.85
runFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected