Skip to content

Commit 7184d06

Browse files
MarcoDotIOclaude
andcommitted
fix(server): t3 auth --json and --token-only print only the result
Resolving the CLI's config sweeps abandoned attachment uploads and logs "Removed expired attachment uploads." at Info. Logs go to stdout, and `quietLogs` only quieted the layers built after config resolution, so the log line landed in front of `t3 auth session issue --token-only`, every `t3 auth ... --json`, `t3 environment list --json` and `t3 connect status --json`, breaking `$(...)` capture and JSON parsing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0070b27 commit 7184d06

5 files changed

Lines changed: 51 additions & 5 deletions

File tree

‎apps/server/src/cli/auth.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const runWithEnvironmentAuth = Effect.fn("auth.runWithEnvironmentAuth")(function
3232
},
3333
) {
3434
const logLevel = yield* GlobalFlag.LogLevel;
35-
const config = yield* resolveCliAuthConfig(flags, logLevel);
35+
const config = yield* resolveCliAuthConfig(flags, logLevel, options);
3636
const minimumLogLevel = options?.quietLogs ? "Error" : config.logLevel;
3737
return yield* Effect.gen(function* () {
3838
const environmentAuth = yield* EnvironmentAuth.EnvironmentAuth;

‎apps/server/src/cli/config.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as LogLevel from "effect/LogLevel";
1515
import * as Option from "effect/Option";
1616
import * as Path from "effect/Path";
1717
import * as Redacted from "effect/Redacted";
18+
import * as References from "effect/References";
1819
import * as Schema from "effect/Schema";
1920
import * as SchemaIssue from "effect/SchemaIssue";
2021
import * as SchemaTransformation from "effect/SchemaTransformation";
@@ -513,8 +514,9 @@ export const resolveServerConfig = Effect.fn("config.resolveServerConfig")(funct
513514
export const resolveCliAuthConfig = (
514515
flags: CliAuthLocationFlags,
515516
cliLogLevel: Option.Option<LogLevel.LogLevel>,
516-
) =>
517-
resolveServerConfig(
517+
options?: { readonly quietLogs?: boolean },
518+
) => {
519+
const resolved = resolveServerConfig(
518520
{
519521
mode: Option.none(),
520522
port: Option.none(),
@@ -531,6 +533,12 @@ export const resolveCliAuthConfig = (
531533
},
532534
cliLogLevel,
533535
);
536+
// Logs go to stdout, where --json and --token-only print, and resolving can
537+
// log, for example when it sweeps abandoned attachment uploads.
538+
return options?.quietLogs === true
539+
? resolved.pipe(Effect.provideService(References.MinimumLogLevel, "Error"))
540+
: resolved;
541+
};
534542

535543
const DurationShorthandPattern = /^(?<value>\d+)(?<unit>ms|s|m|h|d|w)$/i;
536544

‎apps/server/src/cli/connect.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ const runCloudCommand = Effect.fn("cloud.cli.run_cloud_command")(function* <A, E
529529
},
530530
) {
531531
const logLevel = yield* GlobalFlag.LogLevel;
532-
const config = yield* resolveCliAuthConfig(flags, logLevel);
532+
const config = yield* resolveCliAuthConfig(flags, logLevel, options);
533533
const minimumLogLevel = options?.quietLogs ? "Error" : config.logLevel;
534534
const layerRuntime = Layer.mergeAll(
535535
ServerSecretStore.layer,

‎apps/server/src/cli/environment.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const runWithPeerLinks = Effect.fn("environment.runWithPeerLinks")(function* <A,
2929
options?: { readonly quietLogs?: boolean },
3030
) {
3131
const logLevel = yield* GlobalFlag.LogLevel;
32-
const config = yield* resolveCliAuthConfig(flags, logLevel);
32+
const config = yield* resolveCliAuthConfig(flags, logLevel, options);
3333
return yield* PeerLinks.PeerLinks.pipe(
3434
Effect.flatMap(run),
3535
Effect.provide(

‎apps/server/src/cli/pair.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,41 @@ describe("auth pairing create --base-url", () => {
548548
}),
549549
);
550550
});
551+
552+
describe("scripted auth output", () => {
553+
// Live clock: the sweep compares the upload's real mtime with the current time.
554+
it.live.each(
555+
[
556+
["auth", "session", "issue", "--token-only"],
557+
["auth", "session", "list", "--json"],
558+
["auth", "pairing", "list", "--json"],
559+
].map((command) => ({ command, label: command.join(" ") })),
560+
)("prints only the result for $label after removing an abandoned upload", ({ command }) =>
561+
Effect.gen(function* () {
562+
const baseDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-cli-quiet-test-"));
563+
const attachmentsDir = NodePath.join(baseDir, "userdata", "attachments");
564+
NodeFS.mkdirSync(attachmentsDir, { recursive: true });
565+
// An abandoned upload makes config resolution log that it removed it.
566+
const abandoned = NodePath.join(attachmentsDir, "abandoned.part");
567+
NodeFS.writeFileSync(abandoned, "");
568+
const jan2020Seconds = 1_577_836_800;
569+
NodeFS.utimesSync(abandoned, jan2020Seconds, jan2020Seconds);
570+
571+
const lines = yield* provideCliTestLayers(
572+
Effect.gen(function* () {
573+
yield* runCli([...command, "--base-dir", baseDir]);
574+
return yield* TestConsole.logLines;
575+
}),
576+
);
577+
578+
assert.isFalse(NodeFS.existsSync(abandoned));
579+
assert.lengthOf(lines, 1);
580+
const output = String(lines[0]);
581+
if (command.includes("--json")) {
582+
assert.deepEqual(JSON.parse(output), []);
583+
} else {
584+
assert.match(output.trim(), /^[\w-]+\.[\w-]+/);
585+
}
586+
}),
587+
);
588+
});

0 commit comments

Comments
 (0)