@tryinget/runtime-trace-insights 0.1.0
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/LICENSE +78 -0
- package/README.md +155 -0
- package/package.json +41 -0
- package/src/.gitkeep +1 -0
- package/src/index.mjs +3 -0
- package/src/runtime_record/depdiet_runtime_record_adapter.mjs +80 -0
- package/src/runtime_record/index.mjs +18 -0
- package/src/runtime_record/runtime_record_flow.mjs +1577 -0
- package/src/runtime_trace_bundle/index.mjs +8 -0
- package/src/runtime_trace_bundle/runtime_trace_bundle_builder.mjs +679 -0
- package/src/runtime_trace_bundle/runtime_trace_bundle_flow.mjs +168 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { runRuntimeRecordFlow } from "../runtime_record/index.mjs";
|
|
5
|
+
import {
|
|
6
|
+
RUNTIME_TRACE_BUNDLE_NON_AUTHORITY_NOTE,
|
|
7
|
+
RUNTIME_TRACE_BUNDLE_PROFILES,
|
|
8
|
+
RUNTIME_TRACE_BUNDLE_SCHEMA_VERSION,
|
|
9
|
+
RUNTIME_TRACE_REOBSERVATION_NON_AUTHORITY_NOTE,
|
|
10
|
+
RUNTIME_TRACE_REOBSERVATION_SCHEMA_VERSION,
|
|
11
|
+
buildRuntimeTraceBundle,
|
|
12
|
+
normalizeDiagnosticList,
|
|
13
|
+
} from "./runtime_trace_bundle_builder.mjs";
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
RUNTIME_TRACE_BUNDLE_NON_AUTHORITY_NOTE,
|
|
17
|
+
RUNTIME_TRACE_BUNDLE_SCHEMA_VERSION,
|
|
18
|
+
RUNTIME_TRACE_REOBSERVATION_NON_AUTHORITY_NOTE,
|
|
19
|
+
RUNTIME_TRACE_REOBSERVATION_SCHEMA_VERSION,
|
|
20
|
+
};
|
|
21
|
+
export const DEFAULT_RUNTIME_TRACE_BUNDLE_PATH = "out/runtime-trace-insights/runtime-trace-bundle.json";
|
|
22
|
+
|
|
23
|
+
function asArray(value) {
|
|
24
|
+
return Array.isArray(value) ? value : [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function asNonEmptyString(value) {
|
|
28
|
+
if (typeof value !== "string") {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const normalized = value.trim();
|
|
33
|
+
return normalized.length > 0 ? normalized : null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function toRelativePath(basePath, targetPath) {
|
|
37
|
+
const relative = path.relative(basePath, targetPath);
|
|
38
|
+
return (relative.length > 0 ? relative : ".").replaceAll("\\", "/");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function createDiagnostic({ code, level = "warning", message, details }) {
|
|
42
|
+
const diagnostic = { code, level, source: "runtimeTraceBundle", message };
|
|
43
|
+
if (details !== undefined) {
|
|
44
|
+
diagnostic.details = details;
|
|
45
|
+
}
|
|
46
|
+
return diagnostic;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function hasErrorDiagnostic(entries) {
|
|
50
|
+
return asArray(entries)
|
|
51
|
+
.some((entry) => String(entry?.level ?? "").toLowerCase() === "error");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function createFailureResult({ cwd, generatedAt, diagnostics, code, message }) {
|
|
55
|
+
return {
|
|
56
|
+
ok: false,
|
|
57
|
+
cwd,
|
|
58
|
+
generatedAt,
|
|
59
|
+
bundle: null,
|
|
60
|
+
bundlePath: null,
|
|
61
|
+
recordResult: null,
|
|
62
|
+
diagnostics: [
|
|
63
|
+
createDiagnostic({ code, level: "error", message }),
|
|
64
|
+
...normalizeDiagnosticList(diagnostics, "runtimeTraceBundle"),
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function runRuntimeTraceBundleFlow(options = {}) {
|
|
70
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
71
|
+
const generatedAt = asNonEmptyString(options.traceTimestamp) ?? new Date().toISOString();
|
|
72
|
+
const diagnostics = [];
|
|
73
|
+
|
|
74
|
+
// The record flow's own dep-diet record artifacts (bundle + dep-viz handoff) are not part of this
|
|
75
|
+
// command; the bundle is built below with this command's profile and written to --out.
|
|
76
|
+
const recordResult = runRuntimeRecordFlow({
|
|
77
|
+
...options,
|
|
78
|
+
cwd,
|
|
79
|
+
traceTimestamp: generatedAt,
|
|
80
|
+
emitRecordHandoffArtifacts: false,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
diagnostics.push(...normalizeDiagnosticList(recordResult?.diagnostics, "runtimeRecord"));
|
|
84
|
+
|
|
85
|
+
if (!recordResult || recordResult.ok !== true) {
|
|
86
|
+
return createFailureResult({
|
|
87
|
+
cwd,
|
|
88
|
+
generatedAt,
|
|
89
|
+
diagnostics,
|
|
90
|
+
code: "runtimeTraceBundle.recordFailed",
|
|
91
|
+
message: "Runtime trace bundle creation aborted because the observed command record failed.",
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const projectPathInput = asNonEmptyString(recordResult.command?.projectPath) ?? asNonEmptyString(options.projectPath);
|
|
96
|
+
const projectPathAbsolute = path.resolve(cwd, projectPathInput ?? ".");
|
|
97
|
+
const bundleAbsolutePath = path.resolve(cwd, asNonEmptyString(options.bundlePath) ?? DEFAULT_RUNTIME_TRACE_BUNDLE_PATH);
|
|
98
|
+
const runDirectory = asNonEmptyString(recordResult.artifacts?.runDirectory);
|
|
99
|
+
|
|
100
|
+
const bundle = buildRuntimeTraceBundle({
|
|
101
|
+
profile: RUNTIME_TRACE_BUNDLE_PROFILES.bundleCommand,
|
|
102
|
+
diagnostics,
|
|
103
|
+
options,
|
|
104
|
+
generatedAt,
|
|
105
|
+
runId: recordResult.runId,
|
|
106
|
+
bundleId: options.bundleId,
|
|
107
|
+
projectPathInput,
|
|
108
|
+
projectPathAbsolute,
|
|
109
|
+
observedCommand: recordResult.command?.observedCommand ?? [],
|
|
110
|
+
commandLine: asNonEmptyString(recordResult.trace?.commandLine)
|
|
111
|
+
?? asArray(recordResult.command?.observedCommand).join(" "),
|
|
112
|
+
exitCode: recordResult.trace?.exitCode ?? null,
|
|
113
|
+
durationMs: recordResult.trace?.durationMs ?? null,
|
|
114
|
+
packageAutodiscovery: recordResult.trace?.packageAutodiscovery,
|
|
115
|
+
artifactPaths: {
|
|
116
|
+
runDirectoryAbsolute: runDirectory ? path.resolve(cwd, runDirectory) : null,
|
|
117
|
+
runtimeTraceManifestAbsolutePath: asNonEmptyString(recordResult.artifacts?.runtimeTraceManifest?.absolutePath),
|
|
118
|
+
bundleAbsolutePath,
|
|
119
|
+
},
|
|
120
|
+
references: [
|
|
121
|
+
{ kind: "runtime-trace", path: recordResult.artifacts?.runtimeTrace?.path },
|
|
122
|
+
{ kind: "setup-guidance", path: recordResult.artifacts?.setupGuidance?.path },
|
|
123
|
+
{ kind: "package-autodiscovery-log", path: recordResult.artifacts?.packageAutodiscovery?.logPath },
|
|
124
|
+
],
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
fs.mkdirSync(path.dirname(bundleAbsolutePath), { recursive: true });
|
|
129
|
+
fs.writeFileSync(bundleAbsolutePath, `${JSON.stringify(bundle, null, 2)}\n`, "utf8");
|
|
130
|
+
} catch (error) {
|
|
131
|
+
return createFailureResult({
|
|
132
|
+
cwd,
|
|
133
|
+
generatedAt,
|
|
134
|
+
diagnostics: [
|
|
135
|
+
...diagnostics,
|
|
136
|
+
createDiagnostic({
|
|
137
|
+
code: "runtimeTraceBundle.writeFailed",
|
|
138
|
+
level: "error",
|
|
139
|
+
message: "Failed to write runtime trace bundle artifact.",
|
|
140
|
+
details: {
|
|
141
|
+
bundleAbsolutePath,
|
|
142
|
+
error: error instanceof Error ? error.message : String(error),
|
|
143
|
+
},
|
|
144
|
+
}),
|
|
145
|
+
],
|
|
146
|
+
code: "runtimeTraceBundle.writeFailed",
|
|
147
|
+
message: "Runtime trace bundle creation failed while writing the bundle artifact.",
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const normalizedDiagnostics = normalizeDiagnosticList(diagnostics, "runtimeTraceBundle");
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
ok: !hasErrorDiagnostic(normalizedDiagnostics),
|
|
155
|
+
cwd,
|
|
156
|
+
generatedAt,
|
|
157
|
+
bundle,
|
|
158
|
+
bundlePath: toRelativePath(cwd, bundleAbsolutePath),
|
|
159
|
+
bundlePathAbsolute: bundleAbsolutePath,
|
|
160
|
+
recordResult,
|
|
161
|
+
summary: {
|
|
162
|
+
observedPackageCount: bundle.observedPackages.length,
|
|
163
|
+
commandExitCode: recordResult.trace?.exitCode ?? null,
|
|
164
|
+
commandDurationMs: recordResult.trace?.durationMs ?? null,
|
|
165
|
+
},
|
|
166
|
+
diagnostics: normalizedDiagnostics,
|
|
167
|
+
};
|
|
168
|
+
}
|