Repository navigation
Expand file tree
/
Copy pathcoverage.ts
More file actions
238 lines (218 loc) · 8.69 KB
/
Copy pathcoverage.ts
File metadata and controls
238 lines (218 loc) · 8.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// Coverage audit: walks addresses/*.json, classifies each chain, prints a
// grouped table + per-section gap summary. Read-only. Exit 0 when every
// required slot is populated everywhere; non-zero otherwise.
//
// Slot tiers:
// - required : must be present on every chain
// - optional : chain-scoped absence is fine (deployers.protocolFactory,
// only present on chains deployed via ProtocolFactory)
// - chain-conditional: exists only on specific chains (e.g. memberRegistry
// needs the official ENS, which only mainnet has). Not a gap
// anywhere else: those chains skip the slot entirely.
import { resolve } from "@std/path";
import { AddressBook } from "./schema.ts";
const HERE = import.meta.dirname!;
const ADDRESSES_DIR = resolve(HERE, "..", "addresses");
type SlotSpec = {
path: string;
optional?: boolean;
onlyOn?: number[]; // if set, slot only exists on these chainIds
};
const SLOT_SPECS: SlotSpec[] = [
// OSx core
{ path: "osx.versions[0].core.daoBase" },
{ path: "osx.versions[0].core.daoFactory" },
{ path: "osx.versions[0].core.daoRegistry" },
{ path: "osx.versions[0].core.pluginRepoFactory" },
{ path: "osx.versions[0].core.pluginRepoRegistry" },
{ path: "osx.versions[0].core.pluginSetupProcessor" },
{ path: "osx.versions[0].core.memberRegistry", onlyOn: [1] },
// OSx helpers.
{ path: "osx.versions[0].helpers.globalExecutor" },
// Management
{ path: "management.dao" },
{ path: "management.daoMultisig" },
// ENS — every chain the hub tracks uses Aragon's ENS stack.
{ path: "ens.registry" },
{ path: "ens.daoSubdomainRegistrar" },
{ path: "ens.pluginSubdomainRegistrar" },
{ path: "ens.publicResolver" },
// Plugin repos + at-least-one version each.
{ path: "plugins.admin.repo" },
{ path: "plugins.admin.versions[0]" },
{ path: "plugins.multisig.repo" },
{ path: "plugins.multisig.versions[0]" },
{ path: "plugins.token-voting.repo" },
{ path: "plugins.token-voting.versions[0]" },
{ path: "plugins.spp.repo" },
{ path: "plugins.spp.versions[0]" },
{ path: "plugins.lock-to-vote.repo" },
{ path: "plugins.lock-to-vote.versions[0]" },
// Conditions
{ path: "conditions.factories[0].address" },
// One-shot deployers — optional (older chains predate the concept).
{ path: "deployers.protocolFactory", optional: true },
];
function getPath(obj: unknown, path: string): unknown {
let cur: unknown = obj;
for (const seg of path.split(".")) {
const m = seg.match(/^(.+)\[(\d+)\]$/);
if (m) {
cur = (cur as Record<string, unknown>)?.[m[1]];
cur = Array.isArray(cur) ? cur[Number(m[2])] : undefined;
} else {
cur = (cur as Record<string, unknown>)?.[seg];
}
if (cur === undefined) return undefined;
}
return cur;
}
type PerNetwork = {
network: string;
chainId: number;
status: "complete" | "ok" | "partial" | "invalid" | "deprecated";
missing: string[]; // required slots that are missing
missingOptional: string[]; // optional slots that are missing (real chain-scoped absences)
};
async function main() {
const rows: PerNetwork[] = [];
// Walk addresses/*.json (skipping symlinks).
const seen = new Set<string>();
for await (const entry of Deno.readDir(ADDRESSES_DIR)) {
if (!entry.isFile || !entry.name.endsWith(".json")) continue;
const path = resolve(ADDRESSES_DIR, entry.name);
const real = await Deno.realPath(path);
if (seen.has(real)) continue;
seen.add(real);
let raw: unknown;
try {
raw = JSON.parse(await Deno.readTextFile(real));
} catch {
continue;
}
const parsed = AddressBook.safeParse(raw);
if (!parsed.success) {
rows.push({
network: entry.name,
chainId: Number(entry.name.replace(/\.json$/, "")) || 0,
status: "invalid",
missing: [],
missingOptional: [],
});
continue;
}
const book = parsed.data;
const missing: string[] = [];
const missingOptional: string[] = [];
for (const spec of SLOT_SPECS) {
if (spec.onlyOn && !spec.onlyOn.includes(book.chainId)) continue;
const v = getPath(book, spec.path);
if (v !== undefined) continue;
// Deprecated chains: never required, so missing slots just go to the
// optional bucket and never fail the gate.
const required = !book.deprecated && !spec.optional;
(required ? missing : missingOptional).push(spec.path);
}
const status: PerNetwork["status"] = book.deprecated
? "deprecated"
: missing.length > 0 ? "partial"
: missingOptional.length > 0 ? "ok" : "complete";
rows.push({ network: book.network, chainId: book.chainId, status, missing, missingOptional });
}
rows.sort((a, b) => a.network.localeCompare(b.network));
if (Deno.args.includes("--json")) {
console.log(JSON.stringify(rows, null, 2));
Deno.exit(rows.some(r => r.status === "partial" || r.status === "invalid") ? 1 : 0);
}
// --- grouped console.table view ---
const STATUS_ORDER: PerNetwork["status"][] = ["complete", "ok", "deprecated", "partial", "invalid"];
const STATUS_LABEL: Record<PerNetwork["status"], string> = {
complete: "✓ COMPLETE — every slot present",
ok: "◐ OK — required present, optional gaps are chain-scoped",
deprecated: "⌀ DEPRECATED — chain retired; gaps not enforced",
partial: "⚠ PARTIAL — required slots missing",
invalid: "✗ INVALID — file fails schema",
};
for (const status of STATUS_ORDER) {
const chunk = rows.filter(r => r.status === status);
if (!chunk.length) continue;
console.log(`\n${STATUS_LABEL[status]} (${chunk.length})`);
console.table(chunk.map(r => ({
network: r.network,
chainId: r.chainId,
"req missing": r.missing.length,
"opt missing": r.missingOptional.length,
required: r.missing.map(shorten).join(", ") || "-",
})));
}
const totals = STATUS_ORDER
.map(s => `${rows.filter(r => r.status === s).length} ${s}`)
.join(", ");
console.log(`\n${rows.length} networks: ${totals}`);
// --- per-section gap summary ---
type SlotGap = { slot: string; count: number; optional: boolean };
const bySection = new Map<string, SlotGap[]>();
for (const spec of SLOT_SPECS) {
const count = rows.filter(r =>
(spec.optional ? r.missingOptional : r.missing).includes(spec.path)
).length;
if (!count) continue;
const section = spec.path.split(/\.|\[/)[0];
const arr = bySection.get(section) ?? [];
arr.push({ slot: shorten(spec.path), count, optional: !!spec.optional });
bySection.set(section, arr);
}
if (bySection.size) {
console.log("\nSLOTS MISSING — grouped by section:");
for (const [section, gaps] of bySection) {
const req = gaps.filter(g => !g.optional);
const opt = gaps.filter(g => g.optional);
const parts: string[] = [];
if (req.length) parts.push(req.map(g => `${g.slot}[${g.count}]`).join(", "));
if (opt.length) parts.push(`opt: ${opt.map(g => `${g.slot}[${g.count}]`).join(", ")}`);
console.log(` ${section.padEnd(11)} ${parts.join(" | ")}`);
}
}
// --- --gaps flag: slot-centric inverted view ---
if (Deno.args.includes("--gaps")) {
console.log("");
type Gap = { slot: string; missingOn: string[]; optional: boolean };
const gaps: Gap[] = [];
for (const spec of SLOT_SPECS) {
const missingOn = rows
.filter(r => (spec.optional ? r.missingOptional : r.missing).includes(spec.path))
.map(r => r.network);
if (missingOn.length) gaps.push({ slot: spec.path, missingOn, optional: !!spec.optional });
}
gaps.sort((a, b) => b.missingOn.length - a.missingOn.length);
const required = gaps.filter(g => !g.optional);
const optional = gaps.filter(g => g.optional);
const sep = "─".repeat(80);
if (required.length) {
console.log(sep);
console.log("REQUIRED slots missing on at least one chain:");
console.log(sep);
for (const g of required) {
console.log(` ${g.slot}`);
console.log(` missing on (${g.missingOn.length}): ${g.missingOn.join(", ")}`);
}
} else {
console.log("All required slots populated everywhere.");
}
if (optional.length) {
console.log("");
console.log(sep);
console.log("OPTIONAL slots missing (usually fine — chain-scoped absence):");
console.log(sep);
for (const g of optional) {
console.log(` ${g.slot}`);
console.log(` missing on (${g.missingOn.length}): ${g.missingOn.join(", ")}`);
}
}
}
Deno.exit(rows.some(r => r.status === "partial" || r.status === "invalid") ? 1 : 0);
}
function shorten(path: string): string {
return path.replace(/^osx\.versions\[0\]\./, "osx.").replace(/^plugins\./, "");
}
await main();