Compare commits

...

2 Commits

Author SHA1 Message Date
Jay Kumar 62604023c8 test(coder-utils): add tests for centralized utils directory paths
Add test coverage for the new utils_script_path that nests scripts
under ${module_directory}/${agent_name}-utils/:

- test_scripts_nested_under_utils_directory: verifies mkdir, base64
  write, and execution paths all use the utils subdirectory.
- test_utils_directory_uses_agent_name: verifies the directory name
  includes agent_name to avoid collisions between modules sharing
  the same module_directory.

Also fix mkdir in pre_install and install wrappers to create the
utils directory instead of only the module_directory parent. Without
this, base64 -d would fail at runtime because the intermediate
directory would not exist.

🤖 Generated with [Coder Agents](https://coder.com)
2026-04-23 09:41:57 +00:00
35C4n0r d475551deb feat(coder-utils): update script paths to use a centralized utils directory 2026-04-23 15:02:56 +05:30
2 changed files with 100 additions and 6 deletions
+8 -6
View File
@@ -77,10 +77,12 @@ locals {
post_install_script_name = "${var.agent_name}-post_install_script"
start_script_name = "${var.agent_name}-start_script"
pre_install_path = "${var.module_directory}/pre_install.sh"
install_path = "${var.module_directory}/install.sh"
post_install_path = "${var.module_directory}/post_install.sh"
start_path = "${var.module_directory}/start.sh"
utils_script_path = "${var.module_directory}/${var.agent_name}-utils"
pre_install_path = "${local.utils_script_path}/pre_install.sh"
install_path = "${local.utils_script_path}/install.sh"
post_install_path = "${local.utils_script_path}/post_install.sh"
start_path = "${local.utils_script_path}/start.sh"
pre_install_log_path = "${local.log_directory}/pre_install.log"
install_log_path = "${local.log_directory}/install.log"
@@ -111,7 +113,7 @@ resource "coder_script" "pre_install_script" {
set -o errexit
set -o pipefail
mkdir -p ${var.module_directory}
mkdir -p ${local.utils_script_path}
mkdir -p ${local.log_directory}
trap 'coder exp sync complete ${local.pre_install_script_name}' EXIT
@@ -134,7 +136,7 @@ resource "coder_script" "install_script" {
set -o errexit
set -o pipefail
mkdir -p ${var.module_directory}
mkdir -p ${local.utils_script_path}
mkdir -p ${local.log_directory}
trap 'coder exp sync complete ${local.install_script_name}' EXIT
@@ -578,3 +578,95 @@ run "test_logs_nested_under_module_directory" {
error_message = "install script must mkdir -p the logs/ sub-path"
}
}
# Scripts are written to ${module_directory}/${agent_name}-utils/ so the
# wrapper must mkdir that directory and all script paths must nest under it.
run "test_scripts_nested_under_utils_directory" {
command = plan
variables {
agent_id = "test-agent-id"
agent_name = "test-agent"
module_directory = ".test-module"
pre_install_script = "echo pre"
install_script = "echo install"
post_install_script = "echo post"
start_script = "echo start"
}
# pre_install and install create the utils directory.
assert {
condition = can(regex("mkdir -p .test-module/test-agent-utils", coder_script.pre_install_script[0].script))
error_message = "pre_install script must mkdir -p the utils directory"
}
assert {
condition = can(regex("mkdir -p .test-module/test-agent-utils", coder_script.install_script.script))
error_message = "install script must mkdir -p the utils directory"
}
# Every script writes its file under the utils directory.
assert {
condition = can(regex("base64 -d > .test-module/test-agent-utils/pre_install.sh", coder_script.pre_install_script[0].script))
error_message = "pre_install script must write to the utils directory"
}
assert {
condition = can(regex("base64 -d > .test-module/test-agent-utils/install.sh", coder_script.install_script.script))
error_message = "install script must write to the utils directory"
}
assert {
condition = can(regex("base64 -d > .test-module/test-agent-utils/post_install.sh", coder_script.post_install_script[0].script))
error_message = "post_install script must write to the utils directory"
}
assert {
condition = can(regex("base64 -d > .test-module/test-agent-utils/start.sh", coder_script.start_script[0].script))
error_message = "start script must write to the utils directory"
}
# Every script executes from the utils directory.
assert {
condition = can(regex(".test-module/test-agent-utils/pre_install.sh 2>&1", coder_script.pre_install_script[0].script))
error_message = "pre_install script must execute from the utils directory"
}
assert {
condition = can(regex(".test-module/test-agent-utils/install.sh 2>&1", coder_script.install_script.script))
error_message = "install script must execute from the utils directory"
}
assert {
condition = can(regex(".test-module/test-agent-utils/post_install.sh 2>&1", coder_script.post_install_script[0].script))
error_message = "post_install script must execute from the utils directory"
}
assert {
condition = can(regex(".test-module/test-agent-utils/start.sh 2>&1", coder_script.start_script[0].script))
error_message = "start script must execute from the utils directory"
}
}
# The utils directory name includes agent_name so multiple modules sharing
# the same module_directory do not collide.
run "test_utils_directory_uses_agent_name" {
command = plan
variables {
agent_id = "test-agent-id"
agent_name = "custom-name"
module_directory = ".test-module"
install_script = "echo install"
}
assert {
condition = can(regex("mkdir -p .test-module/custom-name-utils", coder_script.install_script.script))
error_message = "utils directory must include agent_name"
}
assert {
condition = can(regex("base64 -d > .test-module/custom-name-utils/install.sh", coder_script.install_script.script))
error_message = "install script must be written under agent-name-specific utils directory"
}
}