Skip to content

Commit df5ed06

Browse files
committed
fix(cli): stop telemetry flag scan at the -- end-of-options sentinel
extractChangedFlagNames kept scanning past a bare --, so test db -- --linked recorded a phantom linked flag in cli_command_executed — but Go's pflag stops parsing flags at --, making --linked a positional arg that changedFlags() never sees. Break on a bare -- (after honoring a pending value skip), mirroring resolveLegacyDbTargetFlags's end-of-options handling.
1 parent 8b0cffb commit df5ed06

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

apps/cli/src/legacy/telemetry/legacy-command-instrumentation.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,19 @@ function extractChangedFlagNames(
8989
const arg = args[index];
9090
if (arg === undefined) continue;
9191

92-
// Skip a token that was consumed as the value of the previous flag.
92+
// Skip a token that was consumed as the value of the previous flag — even
93+
// when that token is `--` (pflag lets a value-taking flag consume `--`).
9394
if (skipNext) {
9495
skipNext = false;
9596
continue;
9697
}
9798

99+
// End-of-options sentinel: pflag stops parsing flags at a bare `--`, so
100+
// everything after it is positional (e.g. `test db -- --linked` makes
101+
// `--linked` a path arg). changedFlags() never sees those, so stop scanning.
102+
// Mirrors resolveLegacyDbTargetFlags's `--` handling.
103+
if (arg === "--") break;
104+
98105
if (arg.startsWith("--")) {
99106
const raw = arg.slice(2);
100107
const eqIdx = raw.indexOf("=");

apps/cli/src/legacy/telemetry/legacy-command-instrumentation.unit.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,4 +595,31 @@ describe("withLegacyCommandInstrumentation", () => {
595595
),
596596
);
597597
});
598+
599+
it.live("stops recording flags at the -- end-of-options sentinel", () => {
600+
// `test db -- --linked`: pflag stops parsing flags at `--`, so `--linked`
601+
// is a positional arg, not a changed flag. changedFlags() never sees it.
602+
const analytics = mockContextualAnalytics();
603+
604+
return Effect.void.pipe(
605+
withLegacyCommandInstrumentation({ flags: {} }),
606+
Effect.provide(analytics.layer),
607+
Effect.provide(mockProcessControl().layer),
608+
Effect.provide(mockOutput({ format: "text" }).layer),
609+
Effect.provide(
610+
Stdio.layerTest({
611+
args: Effect.succeed(["test", "db", "--", "--linked"]),
612+
}),
613+
),
614+
Effect.provide(commandRuntimeLayer(["test", "db"])),
615+
Effect.tap(() =>
616+
Effect.sync(() => {
617+
// No changed flags → the flags map is omitted entirely; `--linked`
618+
// after `--` must never be recorded.
619+
const flags = analytics.captured[0]?.properties.flags;
620+
expect(flags).toBeUndefined();
621+
}),
622+
),
623+
);
624+
});
598625
});

0 commit comments

Comments
 (0)