Repository navigation
Cursor live hook: honor active profile's default_visibility #580
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 2 commits into
main
from
tonyyoung/ai-783-cursor-default-visibility
Aug 18, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
94 changes: 94 additions & 0 deletions
94
test/Capacitor.Cli.Tests.Integration/CursorSessionStartVisibilityTests.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,94 @@ | ||
| using System.Text.Json.Nodes; | ||
| using Capacitor.Cli.Commands.Harness; | ||
| using Capacitor.Cli.Core.Config; | ||
| using Capacitor.Cli.Core; | ||
| using WireMock.RequestBuilders; | ||
| using WireMock.ResponseBuilders; | ||
| using WireMock.Server; | ||
|
|
||
| namespace Capacitor.Cli.Tests.Integration; | ||
|
|
||
| /// <summary> | ||
| /// A live Cursor <c>sessionStart</c> hook stamps the active profile's <c>default_visibility</c> | ||
| /// onto the payload (mirrors <c>CodexSessionStartVisibilityTests</c>). <c>workspace_roots</c> is | ||
| /// set so the enrichment reserialization actually runs — the round-trip the stamp must survive. | ||
| /// See #579. | ||
| /// </summary> | ||
| public class CursorSessionStartVisibilityTests : IDisposable { | ||
|
qodo-code-review[bot] marked this conversation as resolved.
|
||
| readonly WireMockServer _server = WireMockServer.Start(); | ||
| readonly string _configPath = PathHelpers.ConfigPath("config.json"); | ||
| readonly string? _previousConfig; | ||
|
|
||
| public CursorSessionStartVisibilityTests() { | ||
| _previousConfig = File.Exists(_configPath) ? File.ReadAllText(_configPath) : null; | ||
| } | ||
|
|
||
| public void Dispose() { | ||
| _server.Stop(); | ||
|
|
||
| if (_previousConfig is null) { | ||
| if (File.Exists(_configPath)) File.Delete(_configPath); | ||
| } else { | ||
| File.WriteAllText(_configPath, _previousConfig); | ||
| } | ||
| } | ||
|
|
||
| async Task<JsonNode> RunSessionStartAndCaptureBodyAsync(string defaultVisibility) { | ||
| var config = new ProfileConfig { | ||
| ActiveProfile = "work", | ||
| Profiles = new() { | ||
| ["work"] = new Profile { | ||
| ServerUrl = _server.Url, | ||
| DefaultVisibility = defaultVisibility | ||
| } | ||
| } | ||
| }; | ||
| await ConfigMutator.MutateAsync(_ => config); | ||
|
|
||
| _server.Given(Request.Create().WithPath("/hooks/session-start/cursor").UsingPost()) | ||
| .RespondWith(Response.Create().WithStatusCode(200).WithBody("{}")); | ||
| // Best-effort side calls (memory index, auth) must never fail the test. | ||
| _server.Given(Request.Create().WithPath("/api/*").UsingAnyMethod()) | ||
| .RespondWith(Response.Create().WithStatusCode(404)); | ||
| _server.Given(Request.Create().WithPath("/auth/config").UsingGet()) | ||
| .RespondWith(Response.Create().WithStatusCode(200).WithBody("""{"provider":"None"}""")); | ||
|
|
||
| // workspace_roots present → the enrichment reparse runs (the round-trip the stamp must | ||
| // survive); transcript_path omitted → no watcher spawn. | ||
| using var tmp = new TempDir(); | ||
| var body = | ||
| $$""" | ||
| { | ||
| "hook_event_name": "sessionStart", | ||
| "session_id": "cursorvistestsession", | ||
| "model": "claude-3.5-sonnet", | ||
| "workspace_roots": ["{{tmp.Path.Replace("\\", "\\\\")}}"] | ||
| } | ||
| """; | ||
|
|
||
| using var client = new HttpClient(); | ||
| var spool = new HookSpool(tmp.CreateDir("spool").Path); | ||
|
|
||
| var exit = await CursorHookCommand.HandleCore(client, _server.Url!, new StringReader(body), spool, TimeSpan.FromSeconds(2)); | ||
| await Assert.That(exit).IsEqualTo(0); | ||
|
|
||
| var requests = _server.FindLogEntries(Request.Create().WithPath("/hooks/session-start/cursor").UsingPost()); | ||
| await Assert.That(requests.Count).IsEqualTo(1); | ||
|
|
||
| return JsonNode.Parse(requests[0].RequestMessage.Body!)!; | ||
| } | ||
|
|
||
| [Test, NotInParallel("AppConfig_FileState")] | ||
| public async Task SessionStart_stamps_default_visibility_from_active_profile() { | ||
| var body = await RunSessionStartAndCaptureBodyAsync("private"); | ||
| await Assert.That(body["default_visibility"]?.GetValue<string>()).IsEqualTo("private"); | ||
| } | ||
|
|
||
| [Test, NotInParallel("AppConfig_FileState")] | ||
| public async Task SessionStart_stamps_the_profiles_configured_visibility_value() { | ||
| // Fidelity: the stamped value is the profile's configured visibility, not a hardcoded | ||
| // constant — a different profile value must round-trip verbatim. | ||
| var body = await RunSessionStartAndCaptureBodyAsync("public"); | ||
| await Assert.That(body["default_visibility"]?.GetValue<string>()).IsEqualTo("public"); | ||
| } | ||
| } | ||
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.