-
Notifications
You must be signed in to change notification settings - Fork 6
Machine create inherits profile default visibility; status surfaces machine auth #522
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
Merged
realtonyyoung
merged 5 commits into
main
from
tonyyoung/machine-visibility-profile-default
Aug 10, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bb0cb3d
feat: machine create inherits the profile default visibility with pro…
realtonyyoung 78e49ac
feat: kcap status names the machine-auth env vars diverting recording
realtonyyoung 98672dc
fix: address codex review — profile-project fallback, honest incomple…
realtonyyoung 19bcabb
docs: README — machine create inherits profile default visibility; no…
realtonyyoung b6933d6
docs: help-machine.txt — document the project->org_public visibility …
realtonyyoung 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
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
39 changes: 39 additions & 0 deletions
39
test/Capacitor.Cli.Tests.Unit/MachineAuthStatusLineTests.cs
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,39 @@ | ||
| using Capacitor.Cli.Core.Auth; | ||
|
|
||
| namespace Capacitor.Cli.Tests.Unit; | ||
|
|
||
| /// <summary> | ||
| /// `kcap status` warns when machine-credential environment variables are diverting this CLI's auth | ||
| /// off the profile token store. Because <see cref="MachineAuth.Intended"/> triggers on EITHER | ||
| /// variable but <see cref="MachineAuth.TryRead"/> needs BOTH, the message distinguishes the two: | ||
| /// both set means the CLI records as the machine; one set means the credential is incomplete and | ||
| /// nothing records (the diversion still bypasses the token store, so `kcap login` is not the fix). | ||
| /// It names exactly the variable(s) present and says nothing when neither is set. | ||
| /// </summary> | ||
| public class MachineAuthStatusLineTests { | ||
| [Test] | ||
| public async Task Both_variables_present_says_it_records_as_the_machine() { | ||
| var line = MachineAuth.DescribeDiversion(idSet: true, secretSet: true); | ||
| await Assert.That(line).IsNotNull(); | ||
| await Assert.That(line!).Contains("KCAP_CLIENT_ID and KCAP_CLIENT_SECRET set"); | ||
| await Assert.That(line!).Contains("records as the machine, not as your login"); | ||
| } | ||
|
|
||
| [Test] | ||
| [Arguments(true, false, "KCAP_CLIENT_ID is set but KCAP_CLIENT_SECRET is not")] | ||
| [Arguments(false, true, "KCAP_CLIENT_SECRET is set but KCAP_CLIENT_ID is not")] | ||
| public async Task One_variable_present_reports_an_incomplete_credential(bool id, bool secret, string expectedFragment) { | ||
| var line = MachineAuth.DescribeDiversion(id, secret); | ||
| await Assert.That(line).IsNotNull(); | ||
| await Assert.That(line!).Contains("incomplete"); | ||
| await Assert.That(line!).Contains(expectedFragment); | ||
| await Assert.That(line!).Contains("diverted"); | ||
| await Assert.That(line!).DoesNotContain("records as the machine") | ||
| .Because("an incomplete credential does not record — TryRead refuses it"); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Silent_when_neither_variable_is_present() { | ||
| await Assert.That(MachineAuth.DescribeDiversion(false, false)).IsNull(); | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
test/Capacitor.Cli.Tests.Unit/MachineCreateVisibilityTests.cs
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,54 @@ | ||
| using Capacitor.Cli.Commands; | ||
|
|
||
| namespace Capacitor.Cli.Tests.Unit; | ||
|
|
||
| /// <summary> | ||
| /// `kcap machine create` resolves the visibility PRINTED in its setup instructions from the | ||
| /// operator's own configuration instead of steering to private: an explicit --visibility flag wins, | ||
| /// else the active profile's default_visibility (what `kcap setup` wrote), else the product default | ||
| /// org_public for a machine with no profile. Each carries a provenance label so the printed | ||
| /// `kcap config set default_visibility ...` line says where its value came from — and `private` | ||
| /// only ever appears because the flag or the operator's own profile chose it, never as this | ||
| /// command's own suggestion. | ||
| /// </summary> | ||
| public class MachineCreateVisibilityTests { | ||
| [Test] | ||
| public async Task Flag_wins_and_is_labeled_as_flag() { | ||
| var (value, provenance) = MachineCommand.ResolveCreateVisibility("private", "org_public"); | ||
| await Assert.That(value).IsEqualTo("private"); | ||
| await Assert.That(provenance).IsEqualTo("from --visibility"); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Profile_default_is_inherited_and_labeled() { | ||
| var (value, provenance) = MachineCommand.ResolveCreateVisibility(null, "org_public"); | ||
| await Assert.That(value).IsEqualTo("org_public"); | ||
| await Assert.That(provenance).IsEqualTo("your profile default"); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Private_profile_default_is_honored_not_overridden() { | ||
| var (value, provenance) = MachineCommand.ResolveCreateVisibility(null, "private"); | ||
| await Assert.That(value).IsEqualTo("private"); | ||
| await Assert.That(provenance).IsEqualTo("your profile default"); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task No_profile_falls_back_to_product_default() { | ||
| var (value, provenance) = MachineCommand.ResolveCreateVisibility(null, null); | ||
| await Assert.That(value).IsEqualTo("org_public"); | ||
| await Assert.That(provenance).IsEqualTo("product default"); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Project_profile_default_a_machine_cannot_use_falls_back_without_erroring() { | ||
| // 'project' is a valid PROFILE default_visibility (a per-viewer, member-only audience) but a | ||
| // machine is never a project member, so it can't record with it. It must fall back to the | ||
| // product default rather than inherit a value the create-time validation would then reject | ||
| // with a message that falsely blames a --visibility flag the operator never passed. | ||
| var (value, provenance) = MachineCommand.ResolveCreateVisibility(null, "project"); | ||
| await Assert.That(value).IsEqualTo("org_public"); | ||
| await Assert.That(provenance).Contains("project") | ||
| .Because("the operator should see why their profile's value was not used"); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.