Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: reconcile duplicate diagnostic stage revisions

Richie McIlroy532dd674e759
diff --git a/apps/web/__tests__/unit/desktop-log-upload.test.ts b/apps/web/__tests__/unit/desktop-log-upload.test.ts
index 58e66b2d0..62f2d1a77 100644
--- a/apps/web/__tests__/unit/desktop-log-upload.test.ts
+++ b/apps/web/__tests__/unit/desktop-log-upload.test.ts
@@ -137,6 +137,30 @@ describe("desktop diagnostic reconstruction", () => {
expect(
analysis.operations[0].stages.map((stage) => stage.revision),
).toEqual([1, 2, 3]);
+ expect(analysis.operations[0].stages[1]).toEqual({
+ revision: 2,
+ stage: "rendering",
+ elapsedMs: 600,
+ outcome: "in_progress",
+ });
+ });
+
+ it("keeps the newest duplicate stage in either input order", () => {
+ const stale = record({ revision: 2, elapsedMs: 1 });
+ const current = record({ revision: 2, stage: "rendering", elapsedMs: 600 });
+ for (const [snapshot, logged] of [
+ [stale, current],
+ [current, stale],
+ ]) {
+ const analysis = analyzeDesktopDiagnostics(logLine(logged), {
+ operations: { records: [snapshot] },
+ });
+ expect(analysis.operations[0]).toMatchObject({
+ stage: "rendering",
+ elapsedMs: 600,
+ stages: [{ revision: 2, stage: "rendering", elapsedMs: 600 }],
+ });
+ }
});
it("links a failed worker to its parent and retains the build and settings", () => {
diff --git a/apps/web/lib/desktop-diagnostic-analysis.ts b/apps/web/lib/desktop-diagnostic-analysis.ts
index 7a9c9ffce..ba8d7753f 100644
--- a/apps/web/lib/desktop-diagnostic-analysis.ts
+++ b/apps/web/lib/desktop-diagnostic-analysis.ts
@@ -97,8 +97,9 @@ export function analyzeDesktopDiagnostics(log: string, context: unknown) {
) {
operation.latest = record;
}
- if (!operation.stages.has(record.revision)) {
- if (operation.stages.size >= 32) {
+ const previousStage = operation.stages.get(record.revision);
+ if (!previousStage || record.elapsedMs > previousStage.elapsedMs) {
+ if (!previousStage && operation.stages.size >= 32) {
omittedStages++;
} else {
operation.stages.set(record.revision, {