From 8a3c8f53b0ae6388eda286a94661c8b214111fdb Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Tue, 24 Nov 2026 01:29:33 +0000 Subject: [PATCH] fix(cli): t3 policy check expands ~ in the policy file path --- apps/server/src/cli/policy.test.ts | 21 +++++++++++++++++++++ apps/server/src/cli/policy.ts | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/apps/server/src/cli/policy.test.ts b/apps/server/src/cli/policy.test.ts index d06998ff42882..04e29808078c1 100644 --- a/apps/server/src/cli/policy.test.ts +++ b/apps/server/src/cli/policy.test.ts @@ -9,6 +9,7 @@ import * as FileSystem from "effect/FileSystem"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; import { Command } from "effect/cli"; +import * as TestConsole from "effect/testing/TestConsole"; import { cli } from "../binCli.ts"; import * as ManagedPolicy from "../policy/ManagedPolicy.ts"; @@ -85,4 +86,24 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))((it) => { ); }), ); + + it.effect("check reads a ~/ policy file from the home directory", () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-policy-check-" }); + const file = path.join(home, "policy.json"); + yield* fs.writeFileString( + file, + JSON.stringify({ schemaVersion: 1, organization: "Tilde Corp" }), + ); + + yield* Command.runWith(cli, { version: "0.0.0" })(["policy", "check", "~/policy.json"]).pipe( + Effect.provideService(HostProcess.HomeDirectory, home), + Effect.provide(NetService.layer), + ); + + assert.include((yield* TestConsole.logLines).join("\n"), `Managed by Tilde Corp (${file}`); + }).pipe(Effect.provide(Layer.fresh(TestConsole.layer))), + ); }); diff --git a/apps/server/src/cli/policy.ts b/apps/server/src/cli/policy.ts index c48e2bc535a6f..e8badd9123615 100644 --- a/apps/server/src/cli/policy.ts +++ b/apps/server/src/cli/policy.ts @@ -96,14 +96,15 @@ const checkCommand = Command.make("check", { Command.withDescription("Validate a policy file before deploying it."), Command.withHandler( Effect.fn("cli.policy.check")(function* ({ file }) { + const policyFile = yield* expandHomePath(file); // Startup treats a missing file as no policy; a draft that is not there checks nothing. - if (!(yield* (yield* FileSystem.FileSystem).exists(file))) { + if (!(yield* (yield* FileSystem.FileSystem).exists(policyFile))) { return yield* new CliError.UserError({ cause: file, userMessage: `No policy file at ${file}.`, }); } - const policy = yield* ManagedPolicy.load(file); + const policy = yield* ManagedPolicy.load(policyFile); yield* Console.log(describePolicy(policy, yield* ManagedPolicy.loadedPolicy(policy))); }), ),