-
Notifications
You must be signed in to change notification settings - Fork 0
feat(project): add project update command to edit project metadata
#102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tarik02
wants to merge
3
commits into
master
Choose a base branch
from
codex/github-mention-featproject-update-project-metadata
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "t3code-cli": minor | ||
| --- | ||
|
|
||
| Add `project update` for editing project metadata. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import "vite-plus/test/config"; | ||
|
|
||
| import * as Cause from "effect/Cause"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Exit from "effect/Exit"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| import * as Option from "effect/Option"; | ||
| import { assert, describe, it } from "@effect/vitest"; | ||
| import { Command } from "effect/unstable/cli"; | ||
| import { fromPartial } from "@total-typescript/shoehorn"; | ||
|
|
||
| import { T3Application } from "../../application/service.ts"; | ||
| import { T3Config } from "../../config/config.ts"; | ||
| import { t3CliEnvConfigLayer } from "../../config/env/env.test-utils.ts"; | ||
| import * as CliRuntime from "../runtime/service.ts"; | ||
| import { T3Output } from "../output/service.ts"; | ||
| import { updateProjectCommand } from "./update.ts"; | ||
|
|
||
| const testLayer = Layer.mergeAll( | ||
| Layer.succeed( | ||
| T3Application, | ||
| fromPartial({ updateProject: () => Effect.die("updateProject should not be called") }), | ||
| ), | ||
| Layer.succeed( | ||
| T3Config, | ||
| fromPartial({ | ||
| resolve: () => | ||
| Effect.succeed({ url: "ws://localhost", token: "token", source: "config", local: true }), | ||
| }), | ||
| ), | ||
| Layer.succeed(T3Output, { | ||
| writeStdout: () => Effect.void, | ||
| writeStderr: () => Effect.void, | ||
| printJson: () => Effect.void, | ||
| printNdjson: () => Effect.void, | ||
| printInfo: () => Effect.void, | ||
| }), | ||
| NodeServices.layer, | ||
| CliRuntime.layer, | ||
| t3CliEnvConfigLayer("/tmp/t3cli-test"), | ||
| ); | ||
|
|
||
| describe("updateProjectCommand", () => { | ||
| it.layer(testLayer)("validation", (t) => { | ||
| const run = Command.runWith(updateProjectCommand, { version: "0.0.0-test" }); | ||
|
|
||
| t.effect("requires at least one update", () => | ||
| expectError(run(["--project", "proj-1"]), "MissingUpdateFieldsError"), | ||
| ); | ||
|
|
||
| t.effect("rejects a default model value with its clear flag", () => | ||
| expectError( | ||
| run(["--project", "proj-1", "--model", "gpt-5", "--clear-default-model"]), | ||
| "ConflictingUpdateFlagsError", | ||
| ), | ||
| ); | ||
|
|
||
| t.effect("rejects a favicon value with its clear flag", () => | ||
| expectError( | ||
| run(["--project", "proj-1", "--favicon", "icon.png", "--clear-favicon"]), | ||
| "ConflictingUpdateFlagsError", | ||
| ), | ||
| ); | ||
|
|
||
| t.effect("rejects a thread environment value with its clear flag", () => | ||
| expectError( | ||
| run(["--project", "proj-1", "--thread-env", "local", "--clear-thread-env"]), | ||
| "ConflictingUpdateFlagsError", | ||
| ), | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| function expectError<R>( | ||
| effect: Effect.Effect<unknown, unknown, R>, | ||
| expectedTag: string, | ||
| ) { | ||
| return Effect.gen(function* () { | ||
| const exit = yield* effect.pipe(Effect.exit); | ||
| assert.isTrue(Exit.isFailure(exit)); | ||
| if (Exit.isFailure(exit)) { | ||
| const error = Cause.findErrorOption(exit.cause); | ||
| assert.isTrue(Option.isSome(error)); | ||
| if (Option.isSome(error)) { | ||
| assert.equal((error.value as { readonly _tag?: string })._tag, expectedTag); | ||
|
Check failure on line 86 in src/cli/projects/update.test.ts
|
||
| } | ||
| } | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Option from "effect/Option"; | ||
| import { Command, Flag } from "effect/unstable/cli"; | ||
|
|
||
| import { T3Application } from "../../application/service.ts"; | ||
| import { CliRuntime } from "../runtime/service.ts"; | ||
| import { T3Config } from "../../config/config.ts"; | ||
| import { loadT3CliEnv } from "../../config/env/env.ts"; | ||
| import { extraArgsConfig } from "../extra-args.ts"; | ||
| import { ConflictingUpdateFlagsError, MissingUpdateFieldsError } from "../error.ts"; | ||
| import { formatFlag, modelFlags, projectFlag } from "../flags.ts"; | ||
| import { formatProjectUpdatedHuman } from "../format/project.ts"; | ||
| import { resolveOutputFormat } from "../format/output.ts"; | ||
| import { buildModelOptions } from "../model-options.ts"; | ||
| import { T3Output } from "../output/service.ts"; | ||
| import { requireCommandProjectRef } from "../require.ts"; | ||
|
|
||
| export const updateProjectCommand = Command.make( | ||
| "update", | ||
| { | ||
| project: projectFlag, | ||
| title: Flag.string("title").pipe(Flag.optional), | ||
| workspaceRoot: Flag.string("workspace-root").pipe(Flag.optional), | ||
| provider: Flag.string("provider").pipe(Flag.optional), | ||
| model: Flag.string("model").pipe(Flag.optional), | ||
| ...modelFlags, | ||
| clearDefaultModel: Flag.boolean("clear-default-model").pipe(Flag.optional), | ||
| threadEnv: Flag.choice("thread-env", ["local", "worktree"] as const).pipe(Flag.optional), | ||
| clearThreadEnv: Flag.boolean("clear-thread-env").pipe(Flag.optional), | ||
| favicon: Flag.string("favicon").pipe(Flag.optional), | ||
| clearFavicon: Flag.boolean("clear-favicon").pipe(Flag.optional), | ||
| format: formatFlag, | ||
| ...extraArgsConfig, | ||
| }, | ||
| (flags) => | ||
| Effect.gen(function* () { | ||
| const title = Option.getOrUndefined(flags.title); | ||
| const workspaceRoot = Option.getOrUndefined(flags.workspaceRoot); | ||
| const provider = Option.getOrUndefined(flags.provider); | ||
| const model = Option.getOrUndefined(flags.model); | ||
| const threadEnv = Option.getOrUndefined(flags.threadEnv); | ||
| const favicon = Option.getOrUndefined(flags.favicon); | ||
| const clearDefaultModel = Option.getOrUndefined(flags.clearDefaultModel) === true; | ||
| const clearThreadEnv = Option.getOrUndefined(flags.clearThreadEnv) === true; | ||
| const clearFavicon = Option.getOrUndefined(flags.clearFavicon) === true; | ||
| const options = buildModelOptions(flags); | ||
| const hasModel = provider !== undefined || model !== undefined || options.length > 0; | ||
|
|
||
| if (hasModel && clearDefaultModel) { | ||
| return yield* conflict("model flags and --clear-default-model are mutually exclusive"); | ||
| } | ||
| if (threadEnv !== undefined && clearThreadEnv) { | ||
| return yield* conflict("--thread-env and --clear-thread-env are mutually exclusive"); | ||
| } | ||
| if (favicon !== undefined && clearFavicon) { | ||
| return yield* conflict("--favicon and --clear-favicon are mutually exclusive"); | ||
| } | ||
| if ( | ||
| title === undefined && | ||
| workspaceRoot === undefined && | ||
| !hasModel && | ||
| !clearDefaultModel && | ||
| threadEnv === undefined && | ||
| !clearThreadEnv && | ||
| favicon === undefined && | ||
| !clearFavicon | ||
| ) { | ||
| return yield* Effect.fail( | ||
| new MissingUpdateFieldsError({ | ||
| message: "at least one project metadata update field is required", | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| const application = yield* T3Application; | ||
| const config = yield* T3Config; | ||
| const runtime = yield* CliRuntime; | ||
| const env = yield* loadT3CliEnv; | ||
| const output = yield* T3Output; | ||
| const result = yield* application.updateProject({ | ||
| projectRef: yield* requireCommandProjectRef({ project: flags.project }), | ||
| local: (yield* config.resolve()).local, | ||
| ...(title !== undefined ? { title } : {}), | ||
| ...(workspaceRoot !== undefined ? { workspaceRoot } : {}), | ||
| ...(provider !== undefined ? { provider } : {}), | ||
| ...(model !== undefined ? { model } : {}), | ||
| ...(options.length > 0 ? { options } : {}), | ||
| ...(clearDefaultModel ? { defaultModelSelection: null } : {}), | ||
| ...(clearThreadEnv | ||
| ? { defaultThreadEnvironment: null } | ||
| : threadEnv !== undefined | ||
| ? { defaultThreadEnvironment: threadEnv } | ||
| : {}), | ||
| ...(clearFavicon ? { favicon: null } : favicon !== undefined ? { favicon } : {}), | ||
| }); | ||
| if (resolveOutputFormat(flags.format, runtime, env, "json") === "json") { | ||
| return yield* output.printJson(result.project); | ||
| } | ||
| return yield* output.printInfo(formatProjectUpdatedHuman(result.project)); | ||
| }), | ||
| ).pipe(Command.withDescription("update project metadata")); | ||
|
|
||
| function conflict(message: string) { | ||
| return Effect.fail(new ConflictingUpdateFlagsError({ message })); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a project already defaults to provider B, running
project update --model <slug>passes the partial update throughresolveModelSelection, whose model-only branch selects the first available provider rather than retaining B. This silently changes both fields and can persist a provider/model combination that is incompatible. Partial edits should resolve from the project's existing default selection, as thread metadata updates do, while using the first available provider only when no project default exists.Useful? React with 👍 / 👎.