-
Notifications
You must be signed in to change notification settings - Fork 141
feat(coder/modules/agentapi): add state persistence #736
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 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1435939
feat(registry/coder/modules/agentapi): add state persistence
mafredri d0cbc01
fix: change state file name
mafredri d871ce8
agentapi: default enable_state_persistence to false
mafredri 389955d
fix: change default in scripts too
mafredri a817fa8
agentapi: update README for default false state persistence
mafredri e7233b3
agentapi: clarify arithmetic exit status in version_at_least
mafredri aa27b0b
agentapi: fix unbound tmpdir in shutdown EXIT trap
mafredri 695efbb
fix: increase fetch timeout
mafredri ed51abe
Merge branch 'main' into agentapi-state-4nzp
DevelopmentCats 112aca5
Merge branch 'main' into agentapi-state-4nzp
mafredri 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| mock_provider "coder" {} | ||
|
|
||
| variables { | ||
| agent_id = "test-agent" | ||
| web_app_icon = "/icon/test.svg" | ||
| web_app_display_name = "Test" | ||
| web_app_slug = "test" | ||
| cli_app_display_name = "Test CLI" | ||
| cli_app_slug = "test-cli" | ||
| start_script = "echo test" | ||
| module_dir_name = ".test-module" | ||
| } | ||
|
|
||
| run "default_values" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = var.enable_state_persistence == false | ||
| error_message = "enable_state_persistence should default to false" | ||
| } | ||
|
|
||
| assert { | ||
| condition = var.state_file_path == "" | ||
| error_message = "state_file_path should default to empty string" | ||
| } | ||
|
|
||
| assert { | ||
| condition = var.pid_file_path == "" | ||
| error_message = "pid_file_path should default to empty string" | ||
| } | ||
|
|
||
| # Verify start script contains state persistence ARG_ vars. | ||
| assert { | ||
| condition = can(regex("ARG_ENABLE_STATE_PERSISTENCE", coder_script.agentapi.script)) | ||
| error_message = "start script should contain ARG_ENABLE_STATE_PERSISTENCE" | ||
| } | ||
|
|
||
| assert { | ||
| condition = can(regex("ARG_STATE_FILE_PATH", coder_script.agentapi.script)) | ||
| error_message = "start script should contain ARG_STATE_FILE_PATH" | ||
| } | ||
|
|
||
| assert { | ||
| condition = can(regex("ARG_PID_FILE_PATH", coder_script.agentapi.script)) | ||
| error_message = "start script should contain ARG_PID_FILE_PATH" | ||
| } | ||
|
|
||
| # Verify shutdown script contains PID-related ARG_ vars. | ||
| assert { | ||
| condition = can(regex("ARG_PID_FILE_PATH", coder_script.agentapi_shutdown.script)) | ||
| error_message = "shutdown script should contain ARG_PID_FILE_PATH" | ||
| } | ||
|
|
||
| assert { | ||
| condition = can(regex("ARG_MODULE_DIR_NAME", coder_script.agentapi_shutdown.script)) | ||
| error_message = "shutdown script should contain ARG_MODULE_DIR_NAME" | ||
| } | ||
|
|
||
| assert { | ||
| condition = can(regex("ARG_ENABLE_STATE_PERSISTENCE", coder_script.agentapi_shutdown.script)) | ||
| error_message = "shutdown script should contain ARG_ENABLE_STATE_PERSISTENCE" | ||
| } | ||
| } | ||
|
|
||
| run "state_persistence_disabled" { | ||
| command = plan | ||
|
|
||
| variables { | ||
| enable_state_persistence = false | ||
| } | ||
|
|
||
| assert { | ||
| condition = var.enable_state_persistence == false | ||
| error_message = "enable_state_persistence should be false" | ||
| } | ||
|
|
||
| # Even when disabled, the ARG_ vars should still be in the script | ||
| # (the shell script handles the conditional logic). | ||
| assert { | ||
| condition = can(regex("ARG_ENABLE_STATE_PERSISTENCE='false'", coder_script.agentapi.script)) | ||
| error_message = "start script should contain ARG_ENABLE_STATE_PERSISTENCE='false'" | ||
| } | ||
| } | ||
|
|
||
| run "custom_paths" { | ||
| command = plan | ||
|
|
||
| variables { | ||
| state_file_path = "/custom/state.json" | ||
| pid_file_path = "/custom/agentapi.pid" | ||
| } | ||
|
|
||
| assert { | ||
| condition = can(regex("/custom/state.json", coder_script.agentapi.script)) | ||
| error_message = "start script should contain custom state_file_path" | ||
| } | ||
|
|
||
| assert { | ||
| condition = can(regex("/custom/agentapi.pid", coder_script.agentapi.script)) | ||
| error_message = "start script should contain custom pid_file_path" | ||
| } | ||
|
|
||
| # Verify custom paths also appear in shutdown script. | ||
| assert { | ||
| condition = can(regex("/custom/agentapi.pid", coder_script.agentapi_shutdown.script)) | ||
| error_message = "shutdown script should contain custom pid_file_path" | ||
| } | ||
| } |
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.