@afokapu/atdd-bun 0.6.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -3
- package/conventions/coder.bun/coder.bun.telemetry-forbidden-properties.convention.yaml +51 -0
- package/conventions/coder.bun/coder.bun.telemetry-implementation-binding.convention.yaml +45 -0
- package/conventions/coder.bun/coder.bun.telemetry-raw-string-emit.convention.yaml +53 -0
- package/conventions/coder.bun/coder.bun.telemetry-source-binding.convention.yaml +48 -0
- package/conventions/coder.bun/coder.bun.telemetry-vendor-sdk.convention.yaml +51 -0
- package/conventions/planner.telemetry/planner.telemetry.acceptance-decision.convention.yaml +58 -0
- package/conventions/planner.telemetry/planner.telemetry.logical-ownership.convention.yaml +50 -0
- package/conventions/planner.telemetry/planner.telemetry.metric-cardinality.convention.yaml +47 -0
- package/conventions/planner.telemetry/planner.telemetry.tracking-plan-schema.convention.yaml +75 -0
- package/conventions/tester.bun/tester.bun.telemetry-captured-sink.convention.yaml +47 -0
- package/conventions/tester.bun/tester.bun.telemetry-identity-assertion.convention.yaml +44 -0
- package/conventions/tester.bun/tester.bun.telemetry-required-item-coverage.convention.yaml +44 -0
- package/conventions/tester.bun/tester.bun.telemetry-test-binding.convention.yaml +52 -0
- package/conventions/tester.bun/tester.bun.telemetry-timing-semantics.convention.yaml +53 -0
- package/detectors/bun_telemetry_code/atdd.implementation.yaml +24 -0
- package/detectors/bun_telemetry_code/calls.mjs +104 -0
- package/detectors/bun_telemetry_code/checks/t_forbidden_properties.mjs +46 -0
- package/detectors/bun_telemetry_code/checks/t_implementation_binding.mjs +41 -0
- package/detectors/bun_telemetry_code/checks/t_raw_string_emit.mjs +34 -0
- package/detectors/bun_telemetry_code/checks/t_source_binding.mjs +48 -0
- package/detectors/bun_telemetry_code/checks/t_vendor_sdk.mjs +38 -0
- package/detectors/bun_telemetry_code/detect.mjs +50 -0
- package/detectors/bun_telemetry_code/fixtures/clean/plan/commons/E001.yaml +10 -0
- package/detectors/bun_telemetry_code/fixtures/clean/plan/commons/E002.yaml +7 -0
- package/detectors/bun_telemetry_code/fixtures/clean/plan/commons/_commons.yaml +6 -0
- package/detectors/bun_telemetry_code/fixtures/clean/src/wagons/commons/features/ingress/domain/accept-response.ts +8 -0
- package/detectors/bun_telemetry_code/fixtures/clean/src/wagons/commons/features/ingress/infrastructure/otel-adapter.ts +8 -0
- package/detectors/bun_telemetry_code/fixtures/clean/telemetry/commons/response-invocation-accepted/event.be.json +16 -0
- package/detectors/bun_telemetry_code/fixtures/clean/telemetry/commons/response-invocation-accepted/metric.be.duration.json +19 -0
- package/detectors/bun_telemetry_code/fixtures/clean/tests/wagons/commons/features/ingress/unit/accept-response.telemetry.test.ts +13 -0
- package/detectors/bun_telemetry_code/fixtures/clean/tests/wagons/commons/features/ingress/unit/accept-response.test.ts +9 -0
- package/detectors/bun_telemetry_code/fixtures/dirty/plan/commons/E001.yaml +8 -0
- package/detectors/bun_telemetry_code/fixtures/dirty/plan/commons/_commons.yaml +6 -0
- package/detectors/bun_telemetry_code/fixtures/dirty/src/wagons/commons/features/ingress/domain/accept-response.ts +13 -0
- package/detectors/bun_telemetry_code/fixtures/dirty/src/wagons/commons/features/ingress/domain/tracing.ts +3 -0
- package/detectors/bun_telemetry_code/fixtures/dirty/telemetry/commons/response-invocation-accepted/event.be.json +16 -0
- package/detectors/bun_telemetry_code/fixtures/dirty/tests/wagons/commons/features/ingress/unit/probe.test.ts +7 -0
- package/detectors/bun_telemetry_code/registry.mjs +34 -0
- package/detectors/bun_telemetry_test/_shared.mjs +92 -0
- package/detectors/bun_telemetry_test/atdd.implementation.yaml +24 -0
- package/detectors/bun_telemetry_test/checks/t_captured_sink.mjs +35 -0
- package/detectors/bun_telemetry_test/checks/t_identity_assertion.mjs +45 -0
- package/detectors/bun_telemetry_test/checks/t_required_item_coverage.mjs +37 -0
- package/detectors/bun_telemetry_test/checks/t_test_binding.mjs +56 -0
- package/detectors/bun_telemetry_test/checks/t_timing_semantics.mjs +51 -0
- package/detectors/bun_telemetry_test/detect.mjs +50 -0
- package/detectors/bun_telemetry_test/fixtures/clean/plan/commons/E001.yaml +10 -0
- package/detectors/bun_telemetry_test/fixtures/clean/plan/commons/E002.yaml +7 -0
- package/detectors/bun_telemetry_test/fixtures/clean/plan/commons/_commons.yaml +6 -0
- package/detectors/bun_telemetry_test/fixtures/clean/src/wagons/commons/features/ingress/domain/accept-response.ts +8 -0
- package/detectors/bun_telemetry_test/fixtures/clean/telemetry/commons/response-invocation-accepted/event.be.json +16 -0
- package/detectors/bun_telemetry_test/fixtures/clean/telemetry/commons/response-invocation-accepted/metric.be.duration.json +19 -0
- package/detectors/bun_telemetry_test/fixtures/clean/tests/wagons/commons/features/ingress/unit/accept-response.telemetry.test.ts +13 -0
- package/detectors/bun_telemetry_test/fixtures/clean/tests/wagons/commons/features/ingress/unit/accept-response.test.ts +7 -0
- package/detectors/bun_telemetry_test/fixtures/dirty/plan/commons/E001.yaml +10 -0
- package/detectors/bun_telemetry_test/fixtures/dirty/plan/commons/E002.yaml +7 -0
- package/detectors/bun_telemetry_test/fixtures/dirty/plan/commons/_commons.yaml +6 -0
- package/detectors/bun_telemetry_test/fixtures/dirty/src/wagons/commons/features/ingress/domain/accept-response.ts +8 -0
- package/detectors/bun_telemetry_test/fixtures/dirty/telemetry/commons/response-invocation-accepted/event.be.json +16 -0
- package/detectors/bun_telemetry_test/fixtures/dirty/telemetry/commons/response-invocation-accepted/metric.be.duration.json +19 -0
- package/detectors/bun_telemetry_test/fixtures/dirty/tests/wagons/commons/features/ingress/unit/dangling.telemetry.test.ts +9 -0
- package/detectors/bun_telemetry_test/fixtures/dirty/tests/wagons/commons/features/ingress/unit/loose.telemetry.test.ts +11 -0
- package/detectors/bun_telemetry_test/fixtures/dirty/tests/wagons/commons/features/ingress/unit/unbound.telemetry.test.ts +10 -0
- package/detectors/planner_telemetry_plan/atdd.implementation.yaml +22 -0
- package/detectors/planner_telemetry_plan/detect.mjs +9 -0
- package/detectors/planner_telemetry_plan/fixtures/clean/plan/commons/E001.yaml +10 -0
- package/detectors/planner_telemetry_plan/fixtures/clean/plan/commons/E002.yaml +7 -0
- package/detectors/planner_telemetry_plan/fixtures/clean/plan/commons/_commons.yaml +6 -0
- package/detectors/planner_telemetry_plan/fixtures/clean/src/wagons/commons/features/ingress/domain/accept-response.ts +8 -0
- package/detectors/planner_telemetry_plan/fixtures/clean/telemetry/commons/response-invocation-accepted/event.be.json +16 -0
- package/detectors/planner_telemetry_plan/fixtures/clean/telemetry/commons/response-invocation-accepted/metric.be.duration.json +19 -0
- package/detectors/planner_telemetry_plan/fixtures/clean/tests/wagons/commons/features/ingress/unit/accept-response.telemetry.test.ts +13 -0
- package/detectors/planner_telemetry_plan/fixtures/dirty/plan/commons/E001.yaml +9 -0
- package/detectors/planner_telemetry_plan/fixtures/dirty/plan/commons/E002.yaml +4 -0
- package/detectors/planner_telemetry_plan/fixtures/dirty/plan/commons/E003.yaml +7 -0
- package/detectors/planner_telemetry_plan/fixtures/dirty/plan/commons/_commons.yaml +6 -0
- package/detectors/planner_telemetry_plan/fixtures/dirty/telemetry/commons/extra.json +1 -0
- package/detectors/planner_telemetry_plan/fixtures/dirty/telemetry/commons/orphan-artifact/event.be.json +14 -0
- package/detectors/planner_telemetry_plan/fixtures/dirty/telemetry/commons/response-invocation-accepted/event.be.json +16 -0
- package/detectors/planner_telemetry_plan/fixtures/dirty/telemetry/commons/response-invocation-accepted/metric.be.duration.json +22 -0
- package/detectors/planner_telemetry_plan/fixtures/dirty/telemetry/commons/response-invocation-accepted/notes.json +1 -0
- package/integrity.json +94 -11
- package/lib/scan.mjs +37 -0
- package/package.json +1 -1
- package/planner-schemas/acceptance.schema.json +70 -1
- package/planner-schemas/telemetry-plan.schema.json +133 -0
- package/relationships.yaml +174 -0
- package/src/enforce.ts +2 -1
- package/src/index.ts +2 -0
- package/src/integrity.ts +25 -9
- package/src/setup.ts +17 -1
- package/src/telemetry-plan.ts +223 -0
- package/src/topology.ts +3 -1
- package/templates/github/atdd-bun.yml +5 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import Ajv, { type ValidateFunction } from "ajv";
|
|
2
|
+
import addFormats from "ajv-formats";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
5
|
+
import { join, relative, resolve } from "node:path";
|
|
6
|
+
import { loadPlan, type PlanFinding } from "./planner-kernel";
|
|
7
|
+
import { topologyFor } from "./topology";
|
|
8
|
+
|
|
9
|
+
/** The telemetry tracking-plan validator: the plan-side half of the telemetry profile.
|
|
10
|
+
*
|
|
11
|
+
* A tracking plan is the versioned source of truth for what a repository observes. The
|
|
12
|
+
* telemetry/ tree declares concrete items (event / trace / metric / log per plane); wagons
|
|
13
|
+
* own the logical artifacts they realize; every acceptance makes an explicit decision —
|
|
14
|
+
* `required` (with items that must resolve into the tree) or `not-applicable` (with a
|
|
15
|
+
* rationale). The capability is inert until adopted: no telemetry root and no acceptance
|
|
16
|
+
* telemetry declaration means no findings, so upgrading the package changes nothing for a
|
|
17
|
+
* repository that has not opted in. */
|
|
18
|
+
|
|
19
|
+
const KINDS = ["event", "trace", "metric", "log"] as const;
|
|
20
|
+
const PLANES = ["ui", "ux", "be", "nw", "db", "st", "tm", "sc", "au", "fn", "if"] as const;
|
|
21
|
+
const MEASURES = ["latency", "duration", "throughput", "error_rate", "success_rate", "count", "size", "age", "staleness", "freshness"] as const;
|
|
22
|
+
const SEGMENT = "[a-z][a-z0-9-]*";
|
|
23
|
+
export const CONCRETE_URN = new RegExp(`^telemetry:(?:${KINDS.join("|")}):(?:${PLANES.join("|")}):${SEGMENT}:${SEGMENT}(?::(?:${MEASURES.join("|")}))?$`);
|
|
24
|
+
const FILE_NAME = new RegExp(`^(event|trace|metric|log)\\.(${PLANES.join("|")})(?:\\.(${MEASURES.join("|")}))?\\.json$`);
|
|
25
|
+
const SEGMENT_PATTERN = new RegExp(`^${SEGMENT}$`);
|
|
26
|
+
const schemaFile = join(resolve(import.meta.dir, ".."), "planner-schemas", "telemetry-plan.schema.json");
|
|
27
|
+
|
|
28
|
+
export type TelemetryPlanItem = { file: string; data: Record<string, unknown> };
|
|
29
|
+
/** One file under the telemetry root: its place in the tree, its parsed body, or why it would not parse. */
|
|
30
|
+
export type TelemetryFile = { file: string; segments: string[]; data: Record<string, unknown> | null; error?: string };
|
|
31
|
+
|
|
32
|
+
const finding = (rule_id: string, file: string, evidence: string): PlanFinding => ({ rule_id, file, evidence });
|
|
33
|
+
const text = (value: unknown): string => (typeof value === "string" ? value : "");
|
|
34
|
+
const records = (value: unknown): Array<Record<string, unknown>> => (Array.isArray(value) ? value.filter(entry => entry && typeof entry === "object" && !Array.isArray(entry)) : []);
|
|
35
|
+
|
|
36
|
+
async function walk(root: string): Promise<string[]> {
|
|
37
|
+
if (!existsSync(root)) return [];
|
|
38
|
+
const entries = await readdir(root, { withFileTypes: true });
|
|
39
|
+
return (await Promise.all(entries.map(async entry => {
|
|
40
|
+
const path = join(root, entry.name);
|
|
41
|
+
// `_generated` trees are derived material, never authored plan items — same exclusion the
|
|
42
|
+
// plan kernel applies under plan/.
|
|
43
|
+
if (entry.isDirectory() && entry.name === "_generated") return [];
|
|
44
|
+
return entry.isDirectory() ? walk(path) : entry.isFile() && entry.name.endsWith(".json") ? [path] : [];
|
|
45
|
+
}))).flat().sort();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function itemValidator(): Promise<ValidateFunction> {
|
|
49
|
+
const ajv = new Ajv({ allErrors: true, allowUnionTypes: true, strict: false });
|
|
50
|
+
addFormats(ajv);
|
|
51
|
+
return ajv.compile(JSON.parse(await readFile(schemaFile, "utf8")));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Wagon ownership of logical telemetry artifacts, from produce[].telemetry entries (string or list). */
|
|
55
|
+
function telemetryOwners(wagons: Array<{ id: string; data: Record<string, unknown> }>): Map<string, string[]> {
|
|
56
|
+
const owners = new Map<string, string[]>();
|
|
57
|
+
for (const wagon of wagons) {
|
|
58
|
+
const slug = text(wagon.data.wagon) || wagon.id.replace(/^wagon:/, "");
|
|
59
|
+
for (const entry of records(wagon.data.produce)) {
|
|
60
|
+
const declared = entry.telemetry;
|
|
61
|
+
for (const value of Array.isArray(declared) ? declared.map(text) : [text(declared)]) {
|
|
62
|
+
if (value) owners.set(value, [...(owners.get(value) ?? []), slug]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return owners;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The acceptance's telemetry decision: disposition plus the concrete URNs it lists, any shape. */
|
|
70
|
+
export function telemetryDecisionOf(acceptance: { id: string; data: Record<string, unknown> }): { disposition: string; urns: string[] } {
|
|
71
|
+
const decision = acceptance.data.telemetry;
|
|
72
|
+
if (!decision || typeof decision !== "object" || Array.isArray(decision)) return { disposition: "", urns: [] };
|
|
73
|
+
const record = decision as Record<string, unknown>;
|
|
74
|
+
return {
|
|
75
|
+
disposition: text(record.disposition),
|
|
76
|
+
urns: ["events", "metrics", "traces", "logs"].flatMap(key => (Array.isArray(record[key]) ? record[key] : []).map(text)).filter(Boolean),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Load the tracking plan: the adoption gate, every file under the telemetry root (parsed or
|
|
81
|
+
* not), and every acceptance's telemetry decision. Shared by the plan-side validator and both
|
|
82
|
+
* code- and test-side detectors, so all of them judge the same registry. */
|
|
83
|
+
export async function loadTelemetryFiles(root = process.cwd()): Promise<{ adopted: boolean; files: TelemetryFile[]; requiredIds: Set<string>; decisions: Map<string, { disposition: string; urns: string[]; file: string }> }> {
|
|
84
|
+
const absolute = resolve(root), topology = await topologyFor(absolute);
|
|
85
|
+
const telemetryRoot = join(absolute, topology.telemetryRoot);
|
|
86
|
+
const plan = await loadPlan(absolute);
|
|
87
|
+
const acceptances = plan.artifacts.filter(artifact => artifact.kind === "acceptance");
|
|
88
|
+
// Adoption is a positive act: create the telemetry root, or let any acceptance declare a telemetry
|
|
89
|
+
// decision. Until then the capability is inert — an upgraded package must not fail an unadopting repo.
|
|
90
|
+
const adopted = existsSync(telemetryRoot) || acceptances.some(acceptance => acceptance.data.telemetry !== undefined);
|
|
91
|
+
const decisions = new Map<string, { disposition: string; urns: string[]; file: string }>();
|
|
92
|
+
const requiredIds = new Set<string>();
|
|
93
|
+
for (const acceptance of acceptances) {
|
|
94
|
+
const decision = telemetryDecisionOf(acceptance);
|
|
95
|
+
decisions.set(acceptance.id, { ...decision, file: acceptance.file });
|
|
96
|
+
if (decision.disposition === "required") for (const urn of decision.urns) requiredIds.add(urn);
|
|
97
|
+
}
|
|
98
|
+
const files: TelemetryFile[] = [];
|
|
99
|
+
for (const path of await walk(telemetryRoot)) {
|
|
100
|
+
const file = relative(absolute, path).replaceAll("\\", "/");
|
|
101
|
+
const segments = relative(telemetryRoot, path).replaceAll("\\", "/").split("/");
|
|
102
|
+
try {
|
|
103
|
+
const data: unknown = JSON.parse(await readFile(path, "utf8"));
|
|
104
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) { files.push({ file, segments, data: null, error: "tracking-plan item must be a JSON object" }); continue; }
|
|
105
|
+
files.push({ file, segments, data: data as Record<string, unknown> });
|
|
106
|
+
} catch (error) {
|
|
107
|
+
files.push({ file, segments, data: null, error: `could not parse tracking-plan item: ${String(error)}` });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return { adopted, files, requiredIds, decisions };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function validateTelemetryPlan(root = process.cwd()): Promise<PlanFinding[]> {
|
|
114
|
+
const absolute = resolve(root), topology = await topologyFor(absolute);
|
|
115
|
+
const { adopted, files } = await loadTelemetryFiles(absolute);
|
|
116
|
+
if (!adopted) return [];
|
|
117
|
+
|
|
118
|
+
const findings: PlanFinding[] = [], validate = await itemValidator(), items: TelemetryPlanItem[] = [], byId = new Map<string, TelemetryPlanItem>();
|
|
119
|
+
|
|
120
|
+
for (const entry of files) {
|
|
121
|
+
const { file, segments } = entry;
|
|
122
|
+
const name = segments.at(-1) ?? "", match = FILE_NAME.exec(name);
|
|
123
|
+
if (segments.length !== 3 || !match || !SEGMENT_PATTERN.test(segments[0]) || !SEGMENT_PATTERN.test(segments[1])) {
|
|
124
|
+
findings.push(finding("planner.telemetry.tracking-plan-schema", file, `tracking-plan files live at ${topology.telemetryRoot}/<theme>/<artifact>/{event|trace|metric|log}.<plane>[.<measure>].json; found ${file}`));
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (!entry.data) {
|
|
128
|
+
findings.push(finding("planner.telemetry.tracking-plan-schema", file, entry.error ?? "tracking-plan item must be a JSON object"));
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const record = entry.data;
|
|
132
|
+
if (!validate(record)) {
|
|
133
|
+
for (const error of validate.errors ?? []) findings.push(finding(
|
|
134
|
+
"planner.telemetry.tracking-plan-schema", file,
|
|
135
|
+
`${file} violates telemetry-plan.schema.json: ${error.instancePath || "/"} ${error.message ?? error.keyword}`,
|
|
136
|
+
));
|
|
137
|
+
}
|
|
138
|
+
items.push({ file, data: record });
|
|
139
|
+
|
|
140
|
+
// Path mirrors identity: the file's place in the tree is the authority for id, logical artifact,
|
|
141
|
+
// kind, plane and measure. A renamed file or a hand-edited id cannot drift apart silently.
|
|
142
|
+
const [theme, artifact] = segments, kind = match[1], plane = match[2], measure = match[3] ?? null;
|
|
143
|
+
if (text(record.kind) !== kind) findings.push(finding("planner.telemetry.tracking-plan-schema", file, `kind '${text(record.kind) || "<missing>"}' does not match file name ${name}`));
|
|
144
|
+
if (text(record.plane) !== plane) findings.push(finding("planner.telemetry.tracking-plan-schema", file, `plane '${text(record.plane) || "<missing>"}' does not match file name ${name}`));
|
|
145
|
+
if (kind === "metric") {
|
|
146
|
+
if (!measure) findings.push(finding("planner.telemetry.tracking-plan-schema", file, `metric items carry a measure segment: metric.<plane>.<measure>.json (found ${name})`));
|
|
147
|
+
else if (text(record.measure) && text(record.measure) !== measure) findings.push(finding("planner.telemetry.tracking-plan-schema", file, `measure '${text(record.measure)}' does not match file name ${name}`));
|
|
148
|
+
} else if (measure) {
|
|
149
|
+
findings.push(finding("planner.telemetry.tracking-plan-schema", file, `only metric items carry a measure segment (found ${name})`));
|
|
150
|
+
}
|
|
151
|
+
const expectedId = `telemetry:${kind}:${plane}:${theme}:${artifact}${measure ? `:${measure}` : ""}`;
|
|
152
|
+
if (text(record.id) !== expectedId) findings.push(finding("planner.telemetry.tracking-plan-schema", file, `id '${text(record.id) || "<missing>"}' does not mirror its path; expected '${expectedId}'`));
|
|
153
|
+
const expectedLogical = `telemetry:${theme}:${artifact}`;
|
|
154
|
+
if (text(record.logical_artifact) !== expectedLogical) findings.push(finding("planner.telemetry.tracking-plan-schema", file, `logical_artifact '${text(record.logical_artifact) || "<missing>"}' does not mirror its path; expected '${expectedLogical}'`));
|
|
155
|
+
const declared = record.properties && typeof record.properties === "object" && !Array.isArray(record.properties) ? Object.keys(record.properties as Record<string, unknown>) : [];
|
|
156
|
+
for (const name of (Array.isArray(record.required) ? record.required : []).map(text)) {
|
|
157
|
+
if (name && !declared.includes(name)) findings.push(finding("planner.telemetry.tracking-plan-schema", file, `required property '${name}' is not declared in properties`));
|
|
158
|
+
}
|
|
159
|
+
const id = text(record.id), previous = byId.get(id);
|
|
160
|
+
if (id && previous) findings.push(finding("planner.telemetry.tracking-plan-schema", file, `concrete telemetry '${id}' is declared by both ${previous.file} and ${file}`));
|
|
161
|
+
else if (id) byId.set(id, { file, data: record });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const plan = await loadPlan(absolute);
|
|
165
|
+
const acceptances = plan.artifacts.filter(artifact => artifact.kind === "acceptance");
|
|
166
|
+
|
|
167
|
+
// Every concrete item resolves to exactly one wagon-owned logical artifact, and owner names that wagon.
|
|
168
|
+
const owners = telemetryOwners(plan.artifacts.filter(artifact => artifact.kind === "wagon"));
|
|
169
|
+
for (const item of items) {
|
|
170
|
+
const logical = text(item.data.logical_artifact);
|
|
171
|
+
if (!logical) continue; // the schema finding already names it
|
|
172
|
+
const owning = owners.get(logical) ?? [];
|
|
173
|
+
if (!owning.length) findings.push(finding("planner.telemetry.logical-ownership", item.file, `logical artifact ${logical} is produced by no wagon; declare it in exactly one wagon's produce[] telemetry`));
|
|
174
|
+
else if (owning.length > 1) findings.push(finding("planner.telemetry.logical-ownership", item.file, `logical artifact ${logical} is produced by wagons ${owning.join(", ")}`));
|
|
175
|
+
else if (text(item.data.owner) && text(item.data.owner) !== owning[0]) findings.push(finding("planner.telemetry.logical-ownership", item.file, `owner '${text(item.data.owner)}' does not match the owning wagon '${owning[0]}'`));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Every acceptance makes an explicit decision; required items resolve into the tracking plan, and the
|
|
179
|
+
// plan's references back out of the tree resolve to declared acceptances.
|
|
180
|
+
const registryIds = new Set(items.map(item => text(item.data.id)).filter(Boolean));
|
|
181
|
+
const acceptanceIds = new Set(acceptances.map(acceptance => acceptance.id));
|
|
182
|
+
for (const acceptance of acceptances) {
|
|
183
|
+
const block = acceptance.data.telemetry;
|
|
184
|
+
if (!block || typeof block !== "object" || Array.isArray(block)) {
|
|
185
|
+
findings.push(finding("planner.telemetry.acceptance-decision", acceptance.file, `${acceptance.id} declares no telemetry decision; declare telemetry: { disposition: required, events: [...] } or telemetry: { disposition: not-applicable, rationale: ... }`));
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const { disposition, urns } = telemetryDecisionOf(acceptance);
|
|
189
|
+
if (disposition === "required") {
|
|
190
|
+
if (!urns.length) findings.push(finding("planner.telemetry.acceptance-decision", acceptance.file, `${acceptance.id} is disposition: required but declares no telemetry items`));
|
|
191
|
+
for (const urn of urns) {
|
|
192
|
+
if (!urn) { findings.push(finding("planner.telemetry.acceptance-decision", acceptance.file, `${acceptance.id} declares an empty telemetry item`)); continue; }
|
|
193
|
+
if (!CONCRETE_URN.test(urn)) findings.push(finding("planner.telemetry.acceptance-decision", acceptance.file, `${urn} is not a concrete telemetry URN telemetry:{kind}:{plane}:{theme}:{artifact}[:{measure}]`));
|
|
194
|
+
else if (!registryIds.has(urn)) findings.push(finding("planner.telemetry.acceptance-decision", acceptance.file, `${urn} has no tracking-plan entry under ${topology.telemetryRoot}/`));
|
|
195
|
+
}
|
|
196
|
+
} else if (disposition === "not-applicable") {
|
|
197
|
+
const rationale = text((block as Record<string, unknown>).rationale).trim();
|
|
198
|
+
if (rationale.length < 20) findings.push(finding("planner.telemetry.acceptance-decision", acceptance.file, `${acceptance.id} is disposition: not-applicable without a rationale (at least 20 characters)`));
|
|
199
|
+
} else {
|
|
200
|
+
findings.push(finding("planner.telemetry.acceptance-decision", acceptance.file, `${acceptance.id} telemetry.disposition must be required or not-applicable, found '${disposition || "<missing>"}'`));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
for (const item of items) {
|
|
204
|
+
for (const reference of (Array.isArray(item.data.acceptances) ? item.data.acceptances : []).map(text)) {
|
|
205
|
+
if (reference && !acceptanceIds.has(reference)) findings.push(finding("planner.telemetry.acceptance-decision", item.file, `${text(item.data.id) || item.file} references undeclared acceptance ${reference}`));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// High-cardinality identifiers are forbidden as metric labels; they belong in event, log and trace
|
|
210
|
+
// properties where the plan justifies them.
|
|
211
|
+
for (const item of items) {
|
|
212
|
+
if (text(item.data.kind) !== "metric") continue;
|
|
213
|
+
const properties = item.data.properties && typeof item.data.properties === "object" && !Array.isArray(item.data.properties) ? item.data.properties as Record<string, Record<string, unknown>> : {};
|
|
214
|
+
for (const dimension of records(item.data.dimensions)) {
|
|
215
|
+
const name = text(dimension.name);
|
|
216
|
+
if (!name) continue;
|
|
217
|
+
if (text(dimension.cardinality) === "high") findings.push(finding("planner.telemetry.metric-cardinality", item.file, `${text(item.data.id)} dimension '${name}' is high-cardinality; carry the identifier in an event, log or trace property instead`));
|
|
218
|
+
else if (properties[name] && text(properties[name].cardinality) === "high") findings.push(finding("planner.telemetry.metric-cardinality", item.file, `${text(item.data.id)} dimension '${name}' names a property declared cardinality: high`));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return findings;
|
|
223
|
+
}
|
package/src/topology.ts
CHANGED
|
@@ -2,13 +2,14 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
|
|
5
|
-
export type Topology = { planRoot: string; sourceRoot: string; testRoot: string; e2eRoot: string };
|
|
5
|
+
export type Topology = { planRoot: string; sourceRoot: string; testRoot: string; e2eRoot: string; telemetryRoot: string };
|
|
6
6
|
|
|
7
7
|
export const defaultTopology: Topology = {
|
|
8
8
|
planRoot: "plan",
|
|
9
9
|
sourceRoot: "src/wagons",
|
|
10
10
|
testRoot: "tests/wagons",
|
|
11
11
|
e2eRoot: "e2e",
|
|
12
|
+
telemetryRoot: "telemetry",
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
const configuredKeys: Array<[keyof Topology, string]> = [
|
|
@@ -16,6 +17,7 @@ const configuredKeys: Array<[keyof Topology, string]> = [
|
|
|
16
17
|
["sourceRoot", "source_root"],
|
|
17
18
|
["testRoot", "test_root"],
|
|
18
19
|
["e2eRoot", "e2e_root"],
|
|
20
|
+
["telemetryRoot", "telemetry_root"],
|
|
19
21
|
];
|
|
20
22
|
|
|
21
23
|
function safeRelative(value: unknown): string | null {
|
|
@@ -9,6 +9,11 @@ jobs:
|
|
|
9
9
|
atdd-bun:
|
|
10
10
|
name: atdd-bun
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
|
+
env:
|
|
13
|
+
# The policy baseline for every step (the integrity step and the generated integrity test alike): on a push, the
|
|
14
|
+
# pre-push tip, so a multi-commit push is judged as a whole; in the merge queue, the queue's target (GitHub sets
|
|
15
|
+
# no GITHUB_BASE_REF there); on a pull request, GITHUB_BASE_REF.
|
|
16
|
+
ATDD_BASE_REF: ${{ github.event_name == 'push' && github.event.before || github.event_name == 'merge_group' && github.event.merge_group.base_sha || '' }}
|
|
12
17
|
steps:
|
|
13
18
|
- uses: actions/checkout@v4
|
|
14
19
|
with: { fetch-depth: 0 }
|