Skip to content

Commit 8e6d52f

Browse files
sahrizviclaude
andcommitted
fix(onboarding): close an unterminated marker block, de-order the launch_id test
The three test failures on this PR predate the last two commits — the same three were red on `a949fdc`. - `telemetry/index.ts` had 35 `altimate_change start` against 34 ends: the "serialize flushes" block opened inside `flush()` and never closed. That is what both `altimate_change marker integrity` and `bridge merge: ... marker integrity` were reporting. - The launch-correlation test needs the REAL `Telemetry.init()`, since the launch id is minted there and nowhere else, but every other describe in that file spies `init` to a no-op to keep the funnel tests off the filesystem. The test was relying on a sibling's `afterEach` to have undone that spy, so its result depended on suite ordering: green when the file ran alone, red in the shared process. It now restores explicitly — before installing its own fetch spy, not after, which would remove it — clears `initPromise` via `shutdown()`, and asserts `isEnabled()` so any future sabotage fails with a cause instead of a mysteriously empty batch. Verified with the full CI command: 11,833 tests across 574 files, 0 fail — matching CI's own counts, so the shared-process condition the failure depends on was actually reproduced. The subprocess pass was already green on CI and touches none of this. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018SLUQF3xgZHsGZHSjxe7vb
1 parent b66bbe9 commit 8e6d52f

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎packages/opencode/src/altimate/telemetry/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,7 @@ export namespace Telemetry {
17301730
// of racing it.
17311731
inFlightFlush = (inFlightFlush ?? Promise.resolve()).then(() => doFlush(timeoutMs)).catch(() => {})
17321732
return inFlightFlush
1733+
// altimate_change end
17331734
}
17341735

17351736
async function doFlush(timeoutMs: number) {

‎packages/opencode/test/altimate/telemetry/onboarding.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ describe("launch correlation id", () => {
354354
})
355355

356356
test("every event in a run carries the same launch_id", async () => {
357+
// Before the fetch spy below, not after: every other describe in this file spies
358+
// Telemetry.init to a no-op to keep the funnel tests off the filesystem, and this is the only
359+
// test that needs the REAL init — the launch id is minted there and nowhere else. Relying on a
360+
// sibling's afterEach to have undone that spy makes this test's result depend on ordering.
361+
mock.restore()
357362
const origDisabled = process.env.ALTIMATE_TELEMETRY_DISABLED
358363
const origCs = process.env.APPLICATIONINSIGHTS_CONNECTION_STRING
359364
// This is the one test in the file that runs the REAL Telemetry.init() — the launch_id is
@@ -376,7 +381,16 @@ describe("launch correlation id", () => {
376381
delete process.env.ALTIMATE_TELEMETRY_DISABLED
377382
process.env.APPLICATIONINSIGHTS_CONNECTION_STRING =
378383
"InstrumentationKey=k;IngestionEndpoint=https://example.invalid"
384+
// Shut down first. init() is `initPromise ??= doInit()`, so a resolved initPromise left by an
385+
// earlier init — including one that ran while telemetry was disabled — is returned as-is and
386+
// doInit() never runs. shutdown() clearing initPromise is the only reset seam the module has.
387+
await Telemetry.shutdown()
388+
Telemetry.resetLaunchIdForTest()
379389
await Telemetry.init()
390+
// Fail here with a clear cause rather than three lines down on a mysteriously empty batch.
391+
// Every way this test can be sabotaged — a surviving init spy, a disabled-telemetry env var,
392+
// an unparseable connection string — shows up as `enabled === false`.
393+
expect(Telemetry.isEnabled()).toBe(true)
380394

381395
Telemetry.track({ type: "onboarding_started", timestamp: 1, session_id: "" })
382396
Telemetry.track({ type: "scan_gate_choice", timestamp: 2, session_id: "ses_1", choice: "scan" })

0 commit comments

Comments
 (0)