-
Notifications
You must be signed in to change notification settings - Fork 1
Fix CLI stop for KeepAlive Kanata service #1251
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
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
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /// Shared identity and compatibility contract for the privileged helper. | ||
| public enum KeyPathHelperContract { | ||
| /// Version returned by the helper XPC service and packaged in its Info.plist. | ||
| public static let version = "1.3.0" | ||
| public static let version = "1.3.1" | ||
| } |
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
49 changes: 49 additions & 0 deletions
49
Tests/KeyPathTests/Lint/HelperServiceKeepAliveLifecycleLintTests.swift
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,49 @@ | ||
| import Foundation | ||
| import XCTest | ||
|
|
||
| final class HelperServiceKeepAliveLifecycleLintTests: XCTestCase { | ||
| func testHelperDisablesKeepAliveServiceBeforeStoppingIt() throws { | ||
| let source = try helperServiceSource() | ||
| let stopBody = try functionBody(named: "stopKanataService", in: source) | ||
|
|
||
| let disable = try XCTUnwrap(stopBody.range(of: "[\"disable\", Self.kanataServiceTarget]")) | ||
| let signal = try XCTUnwrap(stopBody.range(of: "[\"kill\", \"SIGTERM\", Self.kanataServiceTarget]")) | ||
| let restore = try XCTUnwrap( | ||
| stopBody.range( | ||
| of: "[\"enable\", Self.kanataServiceTarget]", | ||
| range: signal.upperBound ..< stopBody.endIndex | ||
| ) | ||
| ) | ||
| XCTAssertLessThan(disable.lowerBound, signal.lowerBound) | ||
| XCTAssertLessThan(signal.lowerBound, restore.lowerBound) | ||
| } | ||
|
|
||
| func testHelperReenablesServiceBeforeStartingOrRestartingIt() throws { | ||
| let source = try helperServiceSource() | ||
|
|
||
| for functionName in ["startKanataService", "restartKanataService"] { | ||
| let body = try functionBody(named: functionName, in: source) | ||
| let enable = try XCTUnwrap(body.range(of: "[\"enable\", Self.kanataServiceTarget]")) | ||
| let kickstart = try XCTUnwrap(body.range(of: "[\"kickstart\"")) | ||
| XCTAssertLessThan(enable.lowerBound, kickstart.lowerBound, functionName) | ||
| } | ||
| } | ||
|
|
||
| private func helperServiceSource() throws -> String { | ||
| let testFile = URL(fileURLWithPath: #filePath) | ||
| let repositoryRoot = testFile | ||
| .deletingLastPathComponent() | ||
| .deletingLastPathComponent() | ||
| .deletingLastPathComponent() | ||
| .deletingLastPathComponent() | ||
| let sourceURL = repositoryRoot.appendingPathComponent("Sources/KeyPathHelper/HelperService.swift") | ||
| return try String(contentsOf: sourceURL, encoding: .utf8) | ||
| } | ||
|
|
||
| private func functionBody(named name: String, in source: String) throws -> Substring { | ||
| let start = try XCTUnwrap(source.range(of: "func \(name)(")) | ||
| let remainder = source[start.lowerBound...] | ||
| let nextFunction = remainder.dropFirst().range(of: "\n func ") | ||
| return nextFunction.map { remainder[..<$0.lowerBound] } ?? remainder | ||
| } | ||
| } |
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
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.
launchctl disablerecords a persistent override for this label, but only the helper's CLI start/restart methods issue the correspondingenable. Afterkeypath service stop, ordinary app paths—including Settings, wizard, and auto-start—useServiceLifecycleCoordinator.startKanata()(ServiceLifecycleCoordinator.swift:193-231), whose SMAppService register/kickstart flow never enables the label, so those paths cannot restart Kanata until the user runs a CLI start/restart. Route this transition through the canonical lifecycle coordinator or ensure every start path clears the override.AGENTS.md reference: AGENTS.md:L331-L332
Useful? React with 👍 / 👎.